setTooltipText for TreeItem not defined - java

Greetings fellow Stackoverflownians!
I am building an Eclipse RCP application, and have come across an issue:
I want to set a tooltip text on a TreeItem, but this class does not inherit Control, which is the class that has the setTooltipText
EDIT: It seems that jface is supposed to take care of this seamlessly, through a LabelProvider.
I am using a ColumnLabelProvider with getToolTipText method on each column of a complex TreeViewer, but it isn't working. I wonder why...

The probleme here is that you use the SWT-Tree.
You should use a TreeViewer (JFace) which wraps the tree and gives you more sophisticated options.
Inside the label provider of the TreeViewer, you can define your tooltips.
Learn more about viewers here and here
An code example (tool tip) is here
I strongly recommend you to use the viewers!

With TreeViewer use
ColumnViewerToolTipSupport.enableFor(viewer);
Use a label provider derived for CellLabelProvider or one of it subclasses and override getToolTipText (there are also several other methods to control the font, time out and the like).

Related

Embed custom widget in SWT Tree or Table

Using SWT, Is it possible to create a custom widget and insert it to a Table or Tree as if it was a TreeItem or TableItem?
I tried to create a class and extend TreeItem but I'm getting this warning:
MyClass illegally extends TreeItem
Is there a way to do this?
Most SWT widgets are not designed to be extended and enforce this by checking that the current class is in the org.eclipse.swt.widgets package. This can be worked around but is very strongly discouraged.
Widgets generally contain a lot of platform specific code, an override class might very easily end up using code which will only work on one platform.
There are various other ways to extend tables and trees. Using TableEditor and TreeEditor is one way. Drawing the table/tree yourself using SWT.MeasureItem, SWT.PaintItem and SWT.EraseItem is another.

Swing JTree - How to use the Netbeans GUI to make the tree single selection?

I'm using Netbeans GUI interface for creating the Swing components.
I've added a JTree to the panel. It appears to be multi-select by default.
Anybody know how in Netbeans I change this to a single-select? I'm not seeing anything exposed in the properties.
Full Answer:
Right after "initComponents()" in the constructor, I added the following:
TreeSelectionModel model = jTreeInput.getSelectionModel();
model.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
"jTreeInput" is the name of my jTree.
I don't know how to do it in netbeans, but you could also write a couple of lines of code:
TreeSelectionModel model = yourJTree.getSelectionModel();
model.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
The easiest option is to set it in code:
myJTree.getSelectionModel().setSelectionMode
(TreeSelectionModel.SINGLE_TREE_SELECTION);
In Netbeans, JTree has a selectionModel property for this purpose, but requires you to create a custom class derived from TreeSelectionModel with the selection mode set to SINGLE_TREE_SELECTION.

dynamically change viewpart contents depending on selection

Is it possible to change view part contents depending on selection? I have a view part that is subscribed to selection events and depending on some conditions different set of controls is shown in the view.
This sounds rather like swing cardlayout, however I am not sure if there is an analogue in swt and I do not want to hardcode view contents in java code.
Something like eclipse command framework <visibleWhen> expression is really anticipated.
I think StackLayout is what you're looking for. It's very simple to Swing's CardLayout.
Is it possible to have declarative expression that will chose view part contents? I am trying to achieve something like History view where one view part may contain controls contributed with different plugins (e.g. org.eclipse.egit.ui, org.eclipse.team.ui)
No, you'll need to create your own extension point for that. The good news is that it isn't too hard.

Swing JTable custom rendering

I have this kind of progamming task without JavaFx, instead it's Java Swing. I realized my knowledge is still limited.
I have one single JTable.
But, within this JTable I need a custome Cell Renderer.
The goal is to make this kind of JTable: Example image
My current solutions are: Example Image
Create a Single JTable:
get each Column and set its CellRenderer with a custom Renderer (below).
Create a new Class implements TableCellRenderer:
return different JPanel inside getTableCellRendererComponent
method using switch case (as column counted).
After hours, and hours, I think my current solutions is quite daunting tasks. Thus, My question is:
What are the simplest method of creating this Custom JTable to achieve the main goal as mentioned above?
you have two options
1) JPanel nested another JComponents and solve that by using standard LayoutManagers note scrolling isn't natural nor nice
2) JTable with JPanel can solve that, notice about scrolling inner JScrollPane inside another JScrollPane
I've been facing this problem for a while, and I decided to do it myself. Extending the existing implementation of a table, adding some concepts for what I expect from a table, and writting some editors/listeners for that. All the same, but with a treetable.
I'm working on this project called SUMI.
It contains a java package (ar.com.tellapic.sumi.treetable) that is an extension of a JXTreeTable from SwingLabs.
The project is being developed and I didn't provide any documentation yet. You can do what you want by creating a renderer and if needed, an editor, for lastly attaching actions to each object.
If you decide to use it and you need help, email me, I'll help you without any problem.
Or, you could read the source by your own.
Regards,
EDITED (again):
To clear a little bit this answer, I've just created a wiki page in the project wiki and put the relevant code there. If someone feels that the code should be inserted here, please let me know.
Basically, I try to explain how to find a straight solution to the renderer/editor problems you may find using JTable with your specifics needs by using part of my project, in order to get something like this:
Note that the screenshot was taken after clicking on the respective tick-button.
Once you create a nested panel for one row, as suggested by #mKorbel, you can add any number of them to a GridLayout(0, 1) in a JScrollPane. If rendering many rows becomes an issue, you can adopt the same approach used by JTable, illustrated here.
Even though, JTable can be customized to whatever you desire through cell renderer and cell editors, it is never preferred because you have to do a lot of messy codings for that. Instead, for your problem, I suggest to use JScrollPane and add your component (view panel as your sample jTable ) to its viewPort.
For this implementation, represent each rows with your custom class that extends JPanel. And add the required row components (that may be any components like jlabel, jtextfields or even jpanel too) in it. For the simplicity, you can use null layout for the row panel and add the components at any location you want.
I hope this will help you workout with your problem. If you got any problem in this implementation, feel free you ask again.

What is the Renderer class for UIXIterator

Summary
What is the renderer class for UIXIterator(af:iterator)?
Background
I am writing a component and I am planning to extend UIXIterator just like UIXTable does. My component will basically accept the same kind of data binding as UIXIterator/UIXTable does. The only difference will be in the rendering and the client behavior.
I am conducting some preliminary checks to see if this is feasible and how I will go about doing this. I have already determined that most likely I can just extend the component and tag classes(UIXIterator and UIXIteratorTag respectively). The only thing that I am not able to find is the renderer class for UIXIterator.
There is no default Renderer. It renders himself, unless you did not set rendererType in UIXIterator class.

Categories