In the eclipse plugin I am working on, I want to make editable the content of a List (org.eclipse.swt.widgets.List). However, most of the examples I have found show only how to add an item editor to either a swt Table or a Tree. Is it possible to do the same with a list ?, or should I try to replace my list with a single column table ?.
This is how I instantiate the list:
new List (theComposite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL)
Can you use JFace's TableViewer and CellEditors? That's much easier and it already does a lot of stuff for you. You only need to hide the headers and use only a single column, as you already pointed out. Then it should look like a List.
Related
I have used a filtered tree in order to filter the contents.
If filter text is having some text, in this case tree is expanding properly.
But If the filter text is empty, then tree is not expanding at all.
Can some one guide me how to expand the filter tree if I the filter text becomes empty?
Also, In the beginning when Tree is having lot of data and I am expanding it by treeViewer.expandAll() then it takes lot of time to open the dialog.
So, how to handle that performance?
Code Sample
FilteredTree filterTree = new FilteredTree(parent, SWT.VIRTUAL | SWT.BORDER, new PatternFilter());
filterTree.setQuickSelectionMode(true);
treeViewer = filterTree.getViewer();
treeViewer.setContentProvider(contentProvider);
treeViewer.setInput(input);
treeViewer.setLabelProvider(new LabelProvider());
treeViewer.expandAll();
I am trying to make a table with check boxes. I am already provided with a ContributionManager. The manager have an IAction added for each check box, so I hope there is some way I can reuse the actions for my table.
I would hope for something like
TableItem item = new TableItem(table, SWT.Selection);
item.setAction(oneAction);
But I cant find anything like that.
Am I working in the right direction or does someone have any tips for me?
Check boxes in tables are nothing to do with actions and contribution managers.
If you use Table you can specify SWT.CHECK as part of the table style:
Table table = new Table(parent, SWT.CHECK | ... other styles);
Use the addSelectionListener to add a listener for selection events. Check events will have the event detail set to SWT.CHECK.
Or if you use a JFace viewer you can use CheckboxTableViewer. Use the addCheckStateListener to listen for check state events.
Im writing UI in Java, using SWT. I use in some places SWT List.
But when I have items in the list that their length is more than the list default width, I cannot see their whole text. not with End button in the keyboard, and not with anything else.
Here is the code that generates the List:
List lstInputs = new List( shell, SWT.V_SCROLL );
any idea?
basically I am working with a treeviewer in Java (org.eclipse.jface.viewers.TreeViewer).
Now my problem is, that I want to add an childelement/ item to an existing knot.
First of all my tree looks like this:
Knot A
Knot B
Knot C
>child1
>child2
These children(child1, child2) arent added manually, they are generated before I get my hands on the tree itself.
I create the treeviewer:
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL);
I populate the treeviewer:
viewer.setInput(....elements());
which generates the state from above.
viewer.getTree().getItem(0) returns the correct knot A of my tree.
But I cant add a new child to an existing knot.
I tried the following and other things:
TreeItem newItem = new TreeItem(items[0], SWT.NONE); and
viewer.add(items[0], newItem); with a newly created item
viewer.refresh();
Theoretically I could manipulate the arrayList which populates the treeviewer in the first place but that would be really bad I think.
I really do not know what I am doing wrong right now.
I guess it is a quite silly question. If that is the case, then I am sorry.^^
Thank you for your help, I am grateful for every hint that you can offer.
Updating your 'model' (the data you give to setInput) is the correct way to update the tree. Call TreeViewer.refresh() or TreeViewer.refresh(element) to get the tree viewer to update the tree from the model.
When you are using TreeViewer you never create TreeItem objects - the viewer does that. Everything you pass to the refresh, update, add ... methods are objects from your model not TreeItems.
I'm going to make an application (in Swing) that uses a tree to visualize a data structure (JTree). A tree will be on the left side of a window. The user will be able to browse a tree. The parameters of every tree node will be displayed on the right side of the window.
The example windows will be looking like this
===========================
| tree panel | data panel |
| | |
| | |
| | |
---------------------------
The problem arises when a user wants to change that data. when should I validate them ?
The easy approach is to open a new modal dialog (JDialog) and let the user to change this data in it. Validation of data would take place in an "ok" button listener method but this is a little clunky. I would like to allow the user to edit those data right in the data panel. In that case when should I validate them?
Is there a pattern of such solution in Swing?
Or any online tutorial how to do it?
Thanks in advance.
Dialogs are bad.
Immediately discard any complete nonsense input immediately. For instance, typing a letter in the numerical field (use Document filters). Don't beep. Don't require any particular commit step. You may have retain partially entered data.
I'm not totally sure what you're after, but..
You could maybe add this "ok" button (or "commit changes" or whatever) to data panel and when the button would be pressed, you would validate the data and save the changes if the changes are valid?
(So you'd have editable components at the data panel)
Edit: if this wasn't good, could you clarify me a bit:
Is the data panel showing data for one item of the tree at time?
What kind of data is there to change (and to validate)
Anyway, if you want to validate straight the changes made to an edit component (for example JTextField), you can use for example
Formatted text fields, see How to Use Formatted Text Fields
For more general validating, see InputVerifier
More ideas, see Validating Numerical Input in a JTextField (concentrates of numerical input but usable for other purposes also)