Import org. Eclipse jface. Dialogs. Dialog;
Import org. Eclipse jface. Dialogs. IDialogConstants;
Import org. Eclipse SWT. Graphics. Point;
Import the email.composite org.eclipse.swt.widgets.Com;
Import org. Eclipse SWT. Widgets. The Control;
Import org. Eclipse SWT. Widgets. Shell;
The import org. Eclipse. Wb. SWT. The ResourceManager;
The import swing2swt. Layout. BorderLayout.
Import org. Eclipse SWT. Widgets. The List;
Import org. Eclipse jface. Viewers. ListViewer;
Import org. Eclipse SWT. SWT;
Import org. Eclipse SWT. Graphics. Image;
Import org. Eclipse SWT. Graphics. Device;
Import the Java. IO. InputStream;
import java.util.ArrayList;
Import org. Eclipse jface. Viewers. IStructuredContentProvider;
Import org. Eclipse jface. Viewers. The Viewer;
Import org. Eclipse jface. Viewers.'s;
Public class tt extends Dialog {
Private static Shell Shell=null;
Public static void main (String [] args) {
Tt t=new tt (shell);
T.o pen ();
}
Private static class ViewerLabelProvider extends's {
@ Override
Public String getText (Object element) {
The return element. The toString ();
}
@ Override
Public Image getImage (Object element) {
Image Image=null;
Image=the ResourceManager. GetPluginImage (" com. Test ", "the ICONS/Class. PNG");
Return the image;
}
}
Private static class ContentProvider implements IStructuredContentProvider {
@ Override
Public void the dispose () {
//TODO Auto - generated method stub
}
@ Override
Public void inputChanged (Viewer arg0, Object arg1, Object arg2) {
//TODO Auto - generated method stub
}
@ Override
Public Object [] getElements (Object element) {
System. The out. Println (element. GetClass ());
If (element instanceof Java. Util. ArrayList) {
Return ((Java. Util. List
} else {
The return of new Object [0];
}
}
}
/* *
* Create the dialog.
* @ param parentShell
*/
Public tt (Shell parentShell) {
Super (parentShell);
}
/* *
* Create contents of the dialog.
* @ param parent
*/
@ Override
Protected Control createDialogArea (Composite parent) {
The Composite container=(Composite) super. CreateDialogArea (parent);
Container. SetLayout (new BorderLayout (0, 0));
ListViewer ListViewer=new ListViewer (container, SWT. BORDER | SWT. V_SCROLL);
List the List=listViewer. GetList ();
List. SetLayoutData (BorderLayout. CENTER);
ListViewer. SetLabelProvider (new ViewerLabelProvider ());
ListViewer. SetContentProvider (new ContentProvider ());
Java. Util. List
L.A. dd (" 1 ");
L.A. dd (" 2 ");
ListViewer. SetInput (l);
Return the container;
}
/* *
* Create contents of the button bar.
* @ param parent
*/
@ Override
Protected void createButtonsForButtonBar (Composite parent) {
CreateButton (parent, IDialogConstants OK_ID, IDialogConstants OK_LABEL, true);
CreateButton (parent, IDialogConstants CANCEL_ID, IDialogConstants CANCEL_LABEL, false);
}
/* *
* Return the initial size of the dialog.
*/
@ Override
Protected Point getInitialSize () {
Shell=getShell ();
Return new Point (450, 300);
}
}
Use this code can handle treetableviewer icon
CodePudding user response: