I'm trying to edit values of individual columns of a Tree containing TreeColumns:
private Composite composite;
private Composite treeCompositeNdal;
private Tree treeNdalEditor;
private TreeColumn treeNameColumn ;
private TreeColumn treeValueColumn ;
[...]
treeCompositeNdal = new Composite(composite, SWT.BOTTOM);
treeCompositeNdal.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
treeCompositeNdal.setLayout(createNoMarginLayout(1, true));
treeCompositeNdal.setVisible(false);
treeNdalEditor = new Tree (treeCompositeNdal, SWT.BOTTOM|SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
treeNdalEditor.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
treeNdalEditor.setRedraw(true);
treeNdalEditor.setVisible(true);
treeNameColumn = new TreeColumn(treeNdalEditor, 0);
treeValueColumn = new TreeColumn(treeNdalEditor, 0);
treeNameColumn.setText("Name"); treeNameColumn.pack();
treeValueColumn.setText("Value"); treeValueColumn.pack();
I have added the selection listener available here.
As I understand, this will only account for the editing of the first column, which is the behavior I'm experiencing. I cannot modify the value column. Does anybody have any experience with this, or any documentation which I might use?
Thank you.
If JFace is an option for you, you should consider a TreeViewer with EditingSupport for your columns.
Ram's Blog shows you how to do that.
Additionally you should be aware of the following:
Users setting up an editable tree with more than 1 column have to pass the SWT.FULL_SELECTION style bit.
(see Eclipse Help)
Related
I'm building a plugin for eclipse and have the following code to put a tabfolder in my view:
private void constructViewWindow(Composite parent){
final TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
terminologyTab = new TabItem(tabFolder, SWT.NONE);
grammarTab = new TabItem(tabFolder, SWT.NONE);
styleTab = new TabItem(tabFolder, SWT.NONE);
xmlTab = new TabItem(tabFolder, SWT.NONE);
terminologyTable = new Table(tabFolder, SWT.BORDER);
grammarTable = new Table(tabFolder, SWT.BORDER);
styleTable = new Table(tabFolder, SWT.BORDER);
xmlTable = new Table(tabFolder, SWT.BORDER);
addTableColumns(terminologyTable);
addTableColumns(grammarTable);
addTableColumns(styleTable);
addTableColumns(xmlTable);
terminologyTab.setControl(terminologyTable);
grammarTab.setControl(grammarTable);
styleTab.setControl(styleTable);
xmlTab.setControl(xmlTable);
}
which results in the following window:
which is very nice. But I now want to add a description/some additional information to this, something that ends up in the same spot as the '0 items' text in the Tasks view:
Since I'm not sure what this would be called, googling is a bit difficult (e.g. I've tried "add header to table", but a header is obviously something else. "Description" didn't really do the trick either). I guess one could find this in the eclipse source code somewhere, but as I'm new to Java, and diving in the eclipse sources and finding what I need will take quite some time (at least for me), anyone any ideas on how to add this additional line of text above my TabFolder?
Just add a Label to the composite before the tab folder.
private void constructViewWindow(Composite parent){
label = new Label(parent, SWT.LEFT);
// TODO set layout on the layout
label.setText("0 items");
final TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
You may need to set Layout Data on the label to make sure it is wide enough for the text.
Another way is to use the ViewForm class which lets you put controls at the corners of the page.
I'm having trouble displaying a Tree which contains column definitions:
private Composite composite;
private Composite treeCompositeNdal;
private Tree treeNdalEditor;
private TreeColumn treeNameColumn ;
private TreeColumn treeValueColumn ;
[...]
treeCompositeNdal = new Composite(composite, SWT.BOTTOM);
treeCompositeNdal.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
treeCompositeNdal.setLayout(createNoMarginLayout(1, true));
treeCompositeNdal.setVisible(false);
treeNdalEditor = new Tree (treeCompositeNdal, SWT.BOTTOM|SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
treeNdalEditor.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
treeNdalEditor.setRedraw(true);
treeNdalEditor.setVisible(true);
treeNameColumn = new TreeColumn(treeNdalEditor, 0);
treeValueColumn = new TreeColumn(treeNdalEditor, 0);
treeNameColumn.setText("Name");
treeValueColumn.setText("Value");
The Tree displays fine if I comment out the treeNameColumn and treeValueColumn lines. What am I doing wrong?
Try calling TreeColumn#pack() on both columns after filling in your content. This will force the TreeColumns to resize according to their content.
Every second line is coloured on the table in the view.
I have the same table twice on the editor, but it doesn't show this separation:
My code of the lower table in the editor:
table1 = new Table(c, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION
| SWT.V_SCROLL);
TableLayout layout1 = new TableLayout();
table1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
layout1.addColumnData(new ColumnWeightData(20, 50, true));
layout1.addColumnData(new ColumnWeightData(20, 50, true));
layout1.addColumnData(new ColumnWeightData(20, 50, true));
layout1.addColumnData(new ColumnWeightData(20, 50, true));
table1.setLayout(layout1);
table1.setLinesVisible(true);
table1.setHeaderVisible(true);
TableColumn colReihe = new TableColumn(table1, SWT.LEFT);
colReihe.setText("Reihe");
TableColumn colPlatz = new TableColumn(table1, SWT.LEFT);
colPlatz.setText("Platz");
TableColumn colPreis = new TableColumn(table1, SWT.LEFT);
colPreis.setText("Preis");
TableColumn colStatus = new TableColumn(table1, SWT.LEFT);
colStatus.setText("verkauft");
this.tableViewer2 = new TableViewer(table1);
this.tableViewer2.setContentProvider(new ArrayContentProvider());
this.tableViewer2.setLabelProvider(new ITableLabelProvider() {
....some more code here....
this.toolkit.adapt(table1, true, true);
I don't really understand your question. Do you expect the table on the lower right of your screenshot to look like the table on the left? If that's the question, check, whether you call toolkit.adapt(table, true, true); with the left table as well, or try to remove that call with the right table. The FormToolkit sets a lot of colors and styles on widgets.
This must be obvious, but I have searched for ages and can find no mention of it anywhere.
I'm creating an SWT TableViewer, and I want to have borders around my cells. How do I do this? No matter what I try, my cells are always borderless and it's difficult to tell where one cell ends and another begins. My code:
TableViewer outputViewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
outputViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
TableViewerColumn col = new TableViewerColumn(outputViewer, SWT.LEFT | SWT.BORDER);
col.getColumn().setWidth(200);
col.getColumn().setText("Output");
col.getColumn().setResizable(true);
col.setLabelProvider(new ColumnLabelProvider());
outputViewer.getTable().setLinesVisable(true);
i try to use an org.eclipse.jface.viewers.CheckboxTableViewer, as a component of a org.eclipse.jface.wizard.WizardPage. I created it this way:
public void createControl(Composite parent) {
composite = new Composite(parent, SWT.NULL);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
composite.setLayout(gridLayout);
setControl(composite);
/* CheckboxTableViewer */
viewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
final Table table = viewer.getTable();
GridData data1 = new GridData();
data1.grabExcessHorizontalSpace = true;
data1.grabExcessVerticalSpace = true;
data1.horizontalSpan = 2;
data1.horizontalAlignment = SWT.FILL;
data1.verticalAlignment = SWT.FILL;
table.setLayoutData(data1);
table.setHeaderVisible(true);
table.setLinesVisible(true);
checkboxColumn = new TableColumn(table, SWT.LEFT);
...
the content of the viewer is inserted dynamically by a contentprovider. Everything works fine on gnome. While testing this on windows 7 (64 and 32 bit also), i am not able to select any entries of that view. Mouseclicks just seems to have no impact on the view.
I added a mouselistener to the table, and the mouseUp-/Down event is fired, selectionChanged and doubleClick on the viewer is not fired. Anyone who can explain this behaviour to me?
thx in advance,
hage
(i already posted this question in the eclipse forum without any response yet: http://www.eclipse.org/forums/index.php/t/250953/ )
You have to add another style flag while creating the CheckboxTableViewer: SWT.FULL_SELECTION
viewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION);
You can now select rows in the table by a single clicking.