How to access standard eclipse icons - java

I am building a tree table using Nebula nattable and am trying to style it like a swt tree table. The issue now is I am trying to use the same icons for decorators as an swt table and can't find them.
The current icons are selected with the following:
TreeImagePainter treeImagePainter =
new TreeImagePainter(
false,
GUIHelper.getImage("right"), //$NON-NLS-1$
GUIHelper.getImage("right_down"), //$NON-NLS-1$
GUIHelper.getImage("leaf")); // This is an empty image acting as a placeholder to match the
// indentation
I would like to replace them with the icons shown in this image:
A is the desired icons, B is the current icons.
Is there a relativity easy way to achieve this?

These icons are coming from the operating system and afaik there is no easy way to access them. At least I have not yet found a way which is the reason for having those icons in NatTable itself.

Related

How to handle Windows shell icons in JFace LabelProviders?

I would like to display files and folders in a TreeViewer with the associated Windows shell icons. I use the SHGetFileInfo function to get the icons, and then I convert them to org.eclipse.swt.graphics.Image.
It works great, but when I display a large number of files I get an error: "org.eclipse.swt.SWTError: No more handles". SWT is right, I created too many images. Because I must return them from org.eclipse.jface.viewers.LabelProvider.getImage(Object).
How should I handle this situation?
(I can't "cache" the images, because the icons can be dynamic, and even different for every folder.)
You do need to work out a way to identify the different unique images you get from SHGetFileInfo and only create one Image for each. You must also keep track of the images you create because you must also dispose of them.
You may be able to use org.eclipse.jface.resource.ImageRegistry to help manage the images. This requires a string key to identify each image. It looks like SHGetFileInfo gives you an index number that could be used as a unique key.

Eclipse Plugin - TreeViewer display large amount of Text

I am currently writing on a Plugin that uses a view with a TreeViewer. The thing is, as content for my Nodes I get plain HTML. I would like to display the HTML styled or, if not possible, the simple plain text without any HTML. But the issue I run into is that the TreeViewer is not displaying enough text.
As you can see the HTML is not completly displayed and that everyting is only one line is not pretty aswell. I would like to have a box or something that can display the text (doesnt matter if the box does not support the HTML-styling, I can do this from hand).
Currently I'm using a LabelProvider that is returning the Text of a Node as string (and from what I can see this is the only possible Option with a LabelProvider).
As workaround I could only think of cutting the text into serval nodes but I would like to know if there are better options out there ;)
If it's your own LabelProvider, you can truncate or manipulate the text shown however you wish. Since it ultimately ends up as a native control, you're basically stuck with text label with a single image (plus whatever IColorLabelProvider offers) as long as you're using a tree control.
You could experiment with the Figures from the GEF project or the Nebula CompositeTable as alternatives.
you can use a editor to show the content, this would be appropriate with your requirement. View can also be think for it. tableviewer clould also be least choice. TreeViewer generaly use to deal with hierarchical data.
There are several label providers available in Eclipse in the org.eclipse.jface.viewers package. You can choose to implement your own or extend one of them to choose your need.
Looking at the image, I would recommend to display only few words in the tree and the entire content of the node could be in a different pane/tool tip.

JAVA How to get SWT or JFace internal images

Does anybody know where are and how can I obtain internal images which are used by SWT/JFace, like WARNING, ERROR or INFORMATION icons and others...? Where are they situated and how to get them into my code ?
Some parts of JFace uses images from JFaceResources rather than SWT. You find these as
Image i = JFaceResources.getImage(...);
Unfortunately, everybody can install new images into the resource manager, so there are no way to predict the names of images. Some general images are installed in JFaceResources.initializeDefaultImages().
(If you have images, font or colors you use multiple times across your application, then look into JFaceResources.)
Also - if you are using Eclipse RCP - you can find a number of images using
Image i = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages...);
You can find additional constants in org.eclipse.ui.ide.IDE.SharedImages and org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages (for IDEs).
You can use the getSystemImage() method of Display to get those images.
For example:
Display d = Display.getCurrent();
Image img = d.getSystemImage(SWT.ICON_WARNING);
Hope that helps

How to create something similar to JFileChooser in Java?

I am trying to make a frame similar to a JFileChooser. I have a scrollpane and 2 toggle buttons, one for list view, and other for icons view. I will be using CardLayout on the scrollpane. However, I don't know where to begin. I would like to know a good approach on this matter. How do I design the 2 panels that will be put over the scrollpane?
Something similar is the GroupBox in C# forms.
If you want to create "something similar to JFileChooser" why not to take a look on code of JFileChooser itself? You can find JDK source in file src.zip under your JDK directory.
See File Browser GUI for some tips.
I need to know how to create custom views. For example, for the listView option, I will be able to create a Jlist(i think) that will be spread out horizontally on multiple columns. For iconsView i will have some thumbnails that will be displayed vretically on multiple rows, etc.
For the detail view I'd tend to use a JTable. 'horizontally in multiple columns' can be done using a list and setLayoutOrientation(int).

TreeViewer with a Composite as content

I want to build a Tree with a custom bunch of widgets as content. So not only a simple label, but something more complex arranged in a Composite. Is this possible in current SWT/JFace (3.7)? If yes, how do I do that? TreeViewer does only allow me to set a LabelProvider, that has only a getImage() and getText() method. Or am I limited to just that, an image and a simple label without any markup?
You aren't quite that limited -- there is CellLabelProvider, which lets you do things like draw graphics inside cell -- but as far as I know, there is no way to put arbitrary controls inside table or tree cells. This is unsurprising, because SWT generally can only do something if it is supported on all OSes and window systems where SWT is available.

Categories

Resources