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);
Related
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.
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)
Is there a way to achieve a view in following screenshot by Gtk?
I have tried treeview, but it doesn't automatically filtered out the group.
KDELibs equivalent is KCategorizedView.
Edit:
My use case it like:
for example like the screen shot, if I type Mythology, AOE and AOE III will not be shown, since there is no match under that group.
If I try to use treeview, the parent node not cannot be easily filtered, since the filtermodel cannot easily depends on the filtered result.
you can use a GtkTreeView with a GtkTreeStore, but there is no stock widget that has the appearance of the KDE widget.
alternatively, you can have different GtkTreeView instances, each inside a GtkFrame and each using a GtkTreeModelFilter to apply a filter to the same GtkListStore or GtkTreeStore, so that you can keep that data inside a single storage.
the layout would look like:
GtkBox
+---- GtkFrame
| +---- GtkTreeView
|
+---- GtkFrame
| +---- GtkTreeView
|
+---- GtkFrame
| +---- GtkTreeView
|
...
the GtkTreeModelFilter can be set to filter all rows inside the source GtkListStore or GtkTreeStore that match the "category" you want.
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.
I have UI requirement shown below:
|------------------------|
|Header-1 |
| Checkbox1[] |
| Checkbox2[] |
| Checkbox3[] |
|------------------------|
|Header-2 |
| Checkbox1 [] |
| Checkbox2 [] |
| Checkbox3 [] |
and so on clicking below button.
BUTTON -> clicking on this button on bottom will create header and 3 checkbox everytime. How can i achieve this? This is very urgent. I can not take these in XML laypout as these need to be added dynamically on runtime.
If possible, Please provide any sample code and guide me.
Thanks,
Rachana
You should create a listView containing rows defined by a layout having :
a linear layout containing a textView with Header-1 (and so on) as text
another linearLayout containing three checkboxes.
You will create an arrayAdapter with a list of strings representing different values for Header-1 (I guess checkboxes will have same values all the time).
Adding a click listener (onClickListener) on your button. This listener will add an item to the arrayList used by the adapter to add new items in /remove items from your listview when your arrayList is modified (calling notifyDataSetChanged()) to refresh the listView.