Search in sources :

Example 1 with RuntimeTableLabelProvider

use of org.eclipse.wst.server.ui.internal.viewers.RuntimeTableLabelProvider in project webtools.servertools by eclipse.

the class ServerClasspathContainerPage method createControl.

public void createControl(Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    comp.setLayout(layout);
    Label label = new Label(comp, SWT.NONE);
    label.setText(Messages.classpathContainerRuntimeList);
    Table table = new Table(comp, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
    table.setLayoutData(new GridData(GridData.FILL_BOTH));
    table.setHeaderVisible(false);
    TableViewer tableViewer = new TableViewer(table);
    tableViewer.setContentProvider(new IStructuredContentProvider() {

        public Object[] getElements(Object inputElement) {
            Object[] obj = runtimeMap.keySet().toArray();
            return obj;
        }

        public void dispose() {
        // ignore
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        // ignore
        }
    });
    tableViewer.setLabelProvider(new RuntimeTableLabelProvider());
    tableViewer.setInput("root");
    if (selection != null) {
        Set<IRuntime> set = runtimeMap.keySet();
        IRuntime rt;
        for (Iterator<IRuntime> i = set.iterator(); i.hasNext(); ) {
            rt = i.next();
            if (runtimeMap.get(rt).getPath().equals(selection.getPath())) {
                tableViewer.setSelection(new StructuredSelection(new Object[] { rt }));
                setPageComplete(true);
                break;
            }
        }
    }
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            try {
                IStructuredSelection sel = (IStructuredSelection) event.getSelection();
                selection = runtimeMap.get(sel.getFirstElement());
                setPageComplete(true);
            } catch (Exception e) {
                selection = null;
                setPageComplete(false);
            }
        }
    });
    if (tableViewer.getTable().getItemCount() != 0)
        tableViewer.getTable().setFocus();
    setControl(comp);
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IRuntime(org.eclipse.wst.server.core.IRuntime) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) RuntimeTableLabelProvider(org.eclipse.wst.server.ui.internal.viewers.RuntimeTableLabelProvider)

Aggregations

ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Table (org.eclipse.swt.widgets.Table)1 IRuntime (org.eclipse.wst.server.core.IRuntime)1 RuntimeTableLabelProvider (org.eclipse.wst.server.ui.internal.viewers.RuntimeTableLabelProvider)1