Eclipse layout for table and two buttons - eclipse

I am trying to lay out a form for an Eclipse editor and running into a few problems.
The idea is to have a page which contains 2 sections - the left hand section contains a table and two buttons. The table should line up with the top of the section and expand right to the bottom. I want the buttons to sit to the right of the table in the section with each button under the other and for them to align with the top of the table.
Does anyone know what settings for GridLayouts I need to make this work? I've tried every combination I can think of with no luck.
The closest I can get ends up with the second button at the bottom of the page.
Here is an excerpt of my code so far:-
Section section = toolkit.createSection(sashForm, ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.NO_TITLE_FOCUS_BOX);
section.setText("All Items");
Composite client = toolkit.createComposite(section);
section.setClient(client);
client.setLayout(new GridLayout(2, false));
Table table = toolkit.createTable(client, SWT.NULL);
table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
TableViewer viewer = new TableViewer(table);
Button addButton = toolkit.createButton(client, "Add", SWT.PUSH);
addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
Button removeButton = toolkit.createButton(client, "Remove", SWT.PUSH);
removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));

Have a look at SWT Layout Tutorials it has a good section on GridLayout.
You will want to use the GridData.verticalSpan for the table to get it to cover two rows. That should put the two buttons on the right. But then the buttons will take the same space as the table which is probably not what you want, so you may need to give vertical size hint to the table.

Related

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.

Create Table in Itext Pdf in java

I am creating a table in PDF in java using itext. I want to place it in top right corner.
Here is my code snippet. When I execute the below code, table is aligned in the bottom right of pdf but i want it on Top right corner.
PdfPTable table = new PdfPTable(1);
table.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.setWidthPercentage(160 / 5.23f);
PdfPCell cell = new PdfPCell(new Phrase(" Date" , NORMAL));
cell.setBackgroundColor(BaseColor.BLACK);
cell.setBorderWidth(2f);
table.addCell(cell);
PdfPCell cellTwo = new PdfPCell(new Phrase("10/01/2015"));
cellTwo.setBorderWidth(2f);
table.addCell(cellTwo);
You have omitted the line that actually adds the table to the document.
Suppose that you have:
document.add(table);
In that case, iText will add it at the current position of the cursor. If no content was added yet, the table will be added at the top right. The top right is determined by the top margin and the right margin, but if those aren't 0, you may have the impression that the table isn't added at the top right.
You could also have:
PdfContentByte canvas = writer.getDirectContent();
table.writeSelectedRows(0, -1, document.right() - tablewidth, document.top(), canvas);
However, in that case you'd have to define the width of the table differently:
table.setTotalWidth(tableWidth);
I don't know how wide you want your table. You're using a rather odd formula to define the width percentage.
If this doesn't answer your question, please clarify by updating your question. Currently, it isn't entirely clear what you're doing. Your problem can't be reproduced. See the RightCornerTable example:
If my eyes don't fool me, the table is shown in the top-right corner when I use your code snippet and not in the bottom right as you claim...

GWT SimplePager - not displaying buttons

I have a DataGrid that I want to add pagination to. Following the example from the docs, I have:
dataProvider.addDataDisplay(resultsGrid);
// Create a Pager to control the table.
SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
pager = new SimplePager(TextLocation.CENTER, pagerResources,true, 50, true);
pager.setDisplay(resultsGrid);
However, I get neither the 'forward' nor 'fast forward' buttons:
Is there something I"m missing? Do I need to do something when the DataProvider changes?
Judging by your previous question and screenshot, the remaining pager buttons on the right are simply hidden under the west pane.

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. :)