TableViewer shrinks to a single row with a scroll bar when new input is set - eclipse

I am implementing a plug-in in eclipse, which reads a set of values from a database and displays it in a TableViewer inside a ViewPart. The TableViewer uses an ArrayContentProvider as shown
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
...
viewer.setContentProvider(new ArrayContentProvider());
I also have a handler which has access to the TableViewer instance for importing data from an XML file. When the importer imports data, I create a ModelProvider instance which generates a list of objects whose data is displayed by TableViewer.
The handler then sets the input:
viewer.setInput(new ModelProvider(Data.getDocs()).getTableRows());
When I test this application, with this ViewPart already open (and the TableViewer being empty) and invoke the handler for importing data, the data is imported succesfully but the TableViewer shows only a single row and the scroll bar. Only when I drag the ViewPart to some other location on the Workbench, then all the rows are shown.
I have even tried:
viewer.setInput(new ModelProvider(Data.getDocs()).getTableRows());
viewer.refresh();
and
viewer.setInput(null);
viewer.setInput(new ModelProvider(Data.getDocs()).getTableRows());
viewer.refresh();
but nothing works. How do I make all the rows display as soon as new input is set?

I don't think you have a table problem, but a layout problem.
If your viewer's parent has a GridLayout, then do:
viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
OR you can just set a FillLayout on the parent, and that's it.
(if you think I misunderstood your question, please post a screenshot)

Related

How do I add second toolbar to Eclipse Application UI?

Eclipse e4 Application (Eclipse 2018-12).
I have developed a custom PerspectiveSwitcher class extending Composite. This class builds an UI to display - (1) user information using Label, (2) quick group change drop down combo box using Combo, and (3) tabbed perspective switcher using CTabFolder.
I want to add PerspectiveSwitcher UI as a second toolbar on the separate line, like in the image below:
However,
I want the "Company and App LOGO" to be placed on the right side (as pointed to by the red arrow). I tried several combinations of GridData parameters, but none worked.
When I stretch the application window horizontally long enough, the icon toolbar and my custom toolbar merge, as below:
Here is my Application.e4xmi is as follows. The first Tool Control adds the "Company and App LOGO", while the second Tool Control adds the PerspectiveSwitcher UI.
The first Tool Control class is:
public class TrimLogoControl
{
#PostConstruct
public void createPartControl(final Composite parent)
{
final Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
final Label logoLabel1 = new Label(composite, SWT.NONE);
logoLabel1.setImage(PlugIn.createImage("icons/company_logo.png"));
logoLabel1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final Label logoLabel2 = new Label(composite, SWT.NONE);
logoLabel2.setImage(Plugin.createImage("icons/app_logo.png"));
logoLabel2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
}
}
The second Tool Control class is:
public class PerspectiveSwitcherControl
{
#PostConstruct
public void createPartControl(final Composite parent)
{
final Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
new PerspectiveSwitcher(composite, SWT.NONE); // Custom class
}
}
I would very much appreciate, if someone can answer - how to move logos to the right, and how to keep the PerspectiveSwitcher toolbar on the separate line?
I tried adding another Tool Control before the first Tool Control and setting it to FillLayout as explained in How to add Perspective Bar Switcher to pure eclipse 4 rcp application. But that did not work.
I also checked the thread Eclipse e4 tool Control in trimbars, but that did not help either.
To align controls at the right of a trim bar add a separate ToolControl with a tag of stretch. This control will grab any available space in the bar giving right alignment for the result of the bar.
The code for the control can just be an empty Composite with a FillLayout.
I don't know if it possible to force things on to a separate line.

Selecting multiple rows on CheckboxTreeViewer without using the 'ctrl' button

I have created a checkboxtreeviewer using the JFace library. I have created the tree viewer as below
Tree tree = new Tree(parent,SWT.CHECK | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI);
CheckboxTreeViewer checkboxTreeViewer = new CheckboxTreeViewer(tree);
The SWT.MULTI allows me to select(highlight) multiple rows of the tree using the 'CTRL key.
Is there a way we can select multiple rows without using the ctrl key. One way i know of is using the setSelection() method, which cannot be used since that causes a flickering effect when the user goes from one row to another , the Tree.java would deselect all the existing rows and then highlight the rows that are called in the setSelection method.
I feel the code here is causing a deselect to all rows and then a select on the row selected by the user.
You can turn off redrawing of the tree until you have finished setting the selection, this should reduce flickering:
checkboxTreeViewer.getControl().setRedraw(false);
checkboxTreeViewer.setSelection(....);
checkboxTreeViewer.getControl().setRedraw(true);

MPart toolbar too small for text ToolControl

I added a search text ToolControl to a MPart toolbar as described here:
Eclipse e4 tool Control in trimbars
http://www.vogella.com/tutorials/EclipseRCP/article.html#toolbar_advanced_toolcontrols
My problem is:
When I have another item (e.g. handled tool item with icon) in the toolbar, I can see most of the text, but not all. When there is no other item, I see just the upper line of the text.
The toolbar height seems not to be adapted to my control,
Whould be great if anyone can help me.
Christin
The basic problem is that although the ToolBar control allows controls as children it doesn't take their depth in to account when calculating the tool bar depth.
The Vogella example (which is intended for the window trim bar rather than a part tool bar) is using a default GridLayout which adds a margin above the search text. You could try using:
Composite comp = new Composite(parent, SWT.NONE);
// GridLayout with no margins
comp.setLayout(GridLayoutFactory.fillDefaults().create());
Text text = new Text(comp, SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL | SWT.BORDER);
text.setMessage("Search");
GridDataFactory.fillDefaults().hint(130, SWT.DEFAULT).applyTo(text);
That is using a GridLayout with no margins.

Disable JFace TableViwer single row

Does anyone know how to disable a single row of a JFace TableViwer? I have a TableViwer constructed as follows:
TableViwer tv = new TableViwer(composite, SWT.NONE| SWT.FULL_SELECTION | SWT.BORDER);
tv can have many rows, but I am adding a particular unique row to the table dynamically(when an external button is clicked) and I need to make only that row disabled (grayed out and not selectable. Not selectable can also be achieved through existing handler, if there is no other option).
I searched in google but did not get much information. I am new to SWT/JFace, so any help would be appreciated.
You would have to do something in the selection listener to reject selection of the row.
To make the row gray you can make your Label Provider implement IColorProvider which lets you define the two methods:
public Color getForeground(Object element);
public Color getBackground(Object element);
which can color the row.
You could also use a label provider derived from StyledCellLabelProvider which lets you define more complex coloring.

RowSelectionModel shows all Column Header cells

I have created a NatTable with a RowSelectionModel and a RowSelectionProvider:
dataProvider = new ListDataProvider<>(rowData, columnAccessor);
bodyDataLayer = new DataLayer(dataProvider);
glazedListEventsLayer = new GlazedListsEventLayer<>(bodyDataLayer, rowData);
columnReorderLayer = new ColumnReorderLayer(glazedListEventsLayer);
columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
selectionLayer = new SelectionLayer(columnHideShowLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
selectionProvider = new RowSelectionProvider<>(selectionLayer, dataProvider, true);
selectionLayer.setSelectionModel(new RowSelectionModel<>(selectionLayer, dataProvider, idAccessor, false));
Basically, the table does what I want it to do. There is but one exception:
The table looks like this:
As intended, the table shows the row as selected (1). Also it highlights the actually selected cell (2), which is very nice. But, it renders the whole table column header as selected (3). I don't want that. I want either not highlight the header cells at all, or (even better:) I'd like only the column header cell of the cursor-cell (2) to be highlighted.
I thought that maybe there is a configuration label attached to the column header cells which results in the highlighting (so I could just change the style for this kind of label to get rid of the highlighting), but COLUMN_HEADER is the only configuration label, I can see when debugging.
So, I am bit stuck now. What causes the header cells to be highlighted and how can I change this behavior? Is it possible to highlight only the header of the cursor cell (as is done with the selected row's cursor cell (2))?
It is not the label you need to check, for selection it is the DisplayMode. So to not render the column header highlighted if you select a row you need to register the same style configuration for DisplayMode.SELECT as you register for DisplayMode.NORMAL.
If you only want to highlight the selection anchor in the column header you will need to register a custom IConfigLabelAccumulator to the DataLayer of the column header that is connected to the SelectionLayer and adds a custom label in case the cell in the column header is in the same column as the selection anchor.
For only highlighting the selection anchor, there is no default in NatTable itself. Although it should be easy to add. Feel free to create an enhancement ticket for this and even contribute. :)