Example usage for org.eclipse.jface.viewers StructuredSelection isEmpty

List of usage examples for org.eclipse.jface.viewers StructuredSelection isEmpty

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection isEmpty.

Prototype

@Override
    public boolean isEmpty() 

Source Link

Usage

From source file:gov.redhawk.explorer.wizard.SelectDomainPage.java

License:Open Source License

@Override
public void createControl(final Composite parent) {
    final Composite container = new Composite(parent, SWT.NULL);
    final GridLayout layout = new GridLayout(3, false);
    container.setLayout(layout);//w  w  w .j  ava2s  .  c  o  m

    this.patternFilter = new MyPatternFilter();
    this.domainList = new FormFilteredTree(container, SWT.SINGLE | SWT.V_SCROLL, this.patternFilter);
    this.domainList.setBackground(container.getBackground());
    this.domainList.setLayoutData(
            GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(2, 1).create());
    this.domainList.getViewer().setContentProvider(new AdapterFactoryContentProvider(getAdapterFactory()));
    this.domainList.getViewer().setLabelProvider(new AdapterFactoryLabelProvider(getAdapterFactory()) {
        @Override
        public String getText(final Object object) {
            String text = super.getText(object);
            if (object instanceof ScaDomainManager) {
                text += " (" + ((ScaDomainManager) object).getState().getLiteral().toUpperCase() + ")";
            }
            return text;
        }
    });
    this.domainList.getViewer().setFilters(createDomainViewerFilter());
    this.domainList.getViewer().setInput(ScaPlugin.getDefault().getDomainManagerRegistry());
    this.domainList.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            boolean domainSelected = false;
            boolean appsRunning = false;
            final StructuredSelection selection = (StructuredSelection) event.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof ScaDomainManager) {
                if (connect(selection)) {
                    domainSelected = true;
                    try {
                        appsRunning = SelectDomainPage.this.mgr.applications().length > 0;
                    } catch (final Exception e) {
                        // PASS - You can connect to a domain that isn't up but is in the NameService
                    }
                }
            }
            SelectDomainPage.this.setPageComplete(domainSelected);
            SelectDomainPage.this.parent.appsRunning(appsRunning);
        }
    });

    final Composite buttonBox = new Composite(container, SWT.NULL);
    buttonBox.setLayoutData(
            GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.FILL).grab(false, true).create());
    final GridLayout l = new GridLayout();
    l.marginWidth = 0;
    buttonBox.setLayout(l);
    final Button newButton = new Button(buttonBox, SWT.PUSH);
    newButton.setText(" New... ");
    newButton.setLayoutData(GridDataFactory.fillDefaults().create());
    newButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final ScaDomainManagerRegistry registry = ScaPlugin.getDefault().getDomainManagerRegistry();
            final DomainEntryWizard wizard = new DomainEntryWizard();
            wizard.setShowExtraSettings(false);
            wizard.setRegistry(registry);
            wizard.setWindowTitle("Add Domain Manager");
            final WizardDialog dialog = new WizardDialog(getShell(), wizard);
            if (dialog.open() == IStatus.OK) {
                final Map<String, String> connectionProperties = Collections
                        .singletonMap(ScaDomainManager.NAMING_SERVICE_PROP, wizard.getNameServiceInitRef());
                ScaModelCommand.execute(registry, new ScaModelCommand() {
                    @Override
                    public void execute() {
                        registry.createDomain(wizard.getDomainName(), false, connectionProperties);
                    }
                });
            }
        }
    });

    setControl(container);
}

From source file:info.novatec.inspectit.rcp.preferences.page.CmrRepositoryPreferencePage.java

/**
 * Updates the state of the remove and license info buttons depending on the current table
 * selection.//w ww  . ja  v  a  2  s . co m
 */
private void updateButtonsState() {
    StructuredSelection structuredSelection = (StructuredSelection) tableViewer.getSelection();
    if (structuredSelection.isEmpty()) {
        removeButton.setEnabled(false);
        manageLabelsButton.setEnabled(false);
    } else {
        removeButton.setEnabled(true);
        if (structuredSelection.size() == 1 && ((CmrRepositoryDefinition) structuredSelection.getFirstElement())
                .getOnlineStatus() == OnlineStatus.ONLINE) {
            manageLabelsButton.setEnabled(true);
        } else {
            manageLabelsButton.setEnabled(false);
        }
    }
}

From source file:name.schedenig.eclipse.grepconsole.view.items.ItemsTreePanel.java

License:Open Source License

/**
 * Returns the currently selected element. If multiple elements are selected,
 * the first one is returned./*from w w  w  .j a va  2s . c o  m*/
 * 
 * @return Element. May be <code>null</code>.
 */
public AbstractGrepModelElement getSelectedElement() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();

    if (selection.isEmpty()) {
        return null;
    }

    return (AbstractGrepModelElement) selection.getFirstElement();
}

From source file:name.schedenig.eclipse.grepconsole.view.items.ItemsTreePanel.java

License:Open Source License

/**
 * Returns the set of currently selected element. If no element is selected,
 * <code>null</code> is returned.
 * /*from  w ww. j ava 2 s .  c  o m*/
 * @return Selected elements, or <code>null</code>.
 */
public Set<AbstractGrepModelElement> getSelectedElements() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();

    if (selection.isEmpty()) {
        return null;
    }

    @SuppressWarnings("unchecked")
    LinkedHashSet<AbstractGrepModelElement> elements = new LinkedHashSet<AbstractGrepModelElement>(
            selection.toList());

    return elements;
}

From source file:net.efano.sandbox.jface.snippets.TableViewerColors.java

License:Open Source License

/**
 * @param args//from w  w  w .  ja  v a  2  s.  com
 */
public static void main(String[] args) {
    final List<Person> persons = new ArrayList<Person>();
    persons.add(new Person("Fiona Apple", Person.FEMALE));
    persons.add(new Person("Elliot Smith", Person.MALE));
    persons.add(new Person("Diana Krall", Person.FEMALE));
    persons.add(new Person("David Gilmour", Person.MALE));

    final Display display = new Display();
    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            Shell shell = new Shell(display);
            shell.setText("Gender Bender");
            shell.setLayout(new GridLayout());

            Table table = new Table(shell, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
            GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, false);
            gd_table.heightHint = 352;
            table.setLayoutData(gd_table);
            table.setHeaderVisible(true);
            table.setLinesVisible(true);
            TableColumn column = new TableColumn(table, SWT.NONE);
            column.setText("No");
            column.setWidth(20);
            column = new TableColumn(table, SWT.NONE);
            column.setText("Name");
            column.setWidth(100);
            final TableViewer viewer = new TableViewer(table);

            IObservableList observableList = Observables.staticObservableList(persons);
            ObservableListContentProvider contentProvider = new ObservableListContentProvider();

            viewer.setContentProvider(contentProvider);

            // this does not have to correspond to the columns in the table,
            // we just list all attributes that affect the table content.

            IObservableSet oset = contentProvider.getKnownElements();

            IObservableMap[] attributes = BeansObservables.observeMaps(contentProvider.getKnownElements(),
                    Person.class, new String[] { "name", "gender" });

            class ColorLabelProvider extends ObservableMapLabelProvider implements ITableColorProvider {
                Color male = display.getSystemColor(SWT.COLOR_BLUE);

                Color female = new Color(display, 255, 192, 203);

                ColorLabelProvider(IObservableMap[] attributes) {
                    super(attributes);
                }

                // to drive home the point that attributes does not have to
                // match
                // the columns
                // in the table, we change the column text as follows:
                @Override
                public String getColumnText(Object element, int index) {
                    if (index == 0) {
                        return Integer.toString(persons.indexOf(element) + 1);
                    }
                    return ((Person) element).getName();
                }

                @Override
                public Color getBackground(Object element, int index) {
                    return null;
                }

                @Override
                public Color getForeground(Object element, int index) {
                    if (index == 0)
                        return null;
                    Person person = (Person) element;
                    return (person.getGender() == Person.MALE) ? male : female;
                }

                @Override
                public void dispose() {
                    super.dispose();
                    female.dispose();
                }
            }
            viewer.setLabelProvider(new ColorLabelProvider(attributes));

            viewer.setInput(observableList);

            table.getColumn(0).pack();

            Button button = new Button(shell, SWT.PUSH);
            button.setText("Toggle Gender");
            button.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent arg0) {
                    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
                    if (selection != null && !selection.isEmpty()) {
                        Person person = (Person) selection.getFirstElement();
                        person.setGender((person.getGender() == Person.MALE) ? Person.FEMALE : Person.MALE);
                    }
                }
            });

            shell.setSize(380, 713);

            Button btnAddRow = new Button(shell, SWT.NONE);
            btnAddRow.setText("Add Row");

            newRowNameText = new Text(shell, SWT.BORDER);
            newRowNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

            Composite composite = new Composite(shell, SWT.NONE);
            composite.setLayout(new FillLayout(SWT.HORIZONTAL));
            GridData gd_composite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
            gd_composite.widthHint = 129;
            gd_composite.heightHint = 26;
            composite.setLayoutData(gd_composite);

            Button maleRadioButton = new Button(composite, SWT.RADIO);
            maleRadioButton.setText("Male");

            Button femaleRadioButton = new Button(composite, SWT.RADIO);
            femaleRadioButton.setText("Female");
            shell.open();

            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        }
    });
    display.dispose();
}

From source file:net.karlmartens.ui.widget.GridChooser.java

License:Apache License

private static int minSelectionOrder(TableViewer viewer) {
    final StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return -1;

    final GridChooserItem[] items = new GridChooserItem[selection.size()];
    System.arraycopy(selection.toArray(), 0, items, 0, selection.size());

    int index = items[0].getSelectionOrder();
    for (int i = 1; i < items.length; i++) {
        final int candidate = items[i].getSelectionOrder();
        if (index > candidate) {
            index = candidate;/* ww w  .  j  a v a 2 s.c  om*/
        }
    }
    return index;
}

From source file:net.karlmartens.ui.widget.GridChooser.java

License:Apache License

private static int maxSelectionOrder(TableViewer viewer) {
    final StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return -1;

    final GridChooserItem[] items = new GridChooserItem[selection.size()];
    System.arraycopy(selection.toArray(), 0, items, 0, selection.size());

    int index = items[0].getSelectionOrder();
    for (int i = 1; i < items.length; i++) {
        final int candidate = items[i].getSelectionOrder();
        if (index < candidate) {
            index = candidate;/*from   ww  w  .  ja v  a 2  s.  co  m*/
        }
    }
    return index;
}

From source file:net.refractions.udig.catalog.internal.wmt.ui.view.WMTZoomLevelSwitcher.java

License:Open Source License

private int getSelectedZoomLevel() {
    StructuredSelection selection = (StructuredSelection) cvZoomLevels.getSelection();

    if (selection.isEmpty()) {
        return zoomLevels[0];
    } else {/*from   w  w w .j a  v a 2s .  co  m*/
        return (Integer) selection.getFirstElement();
    }
}

From source file:net.refractions.udig.catalog.internal.wmt.ui.view.WMTZoomLevelSwitcher.java

License:Open Source License

private ILayer getSelectedLayer() {
    StructuredSelection selection = (StructuredSelection) cvLayers.getSelection();

    if (selection.isEmpty()) {
        return null;
    } else {//from   ww w. j av a2s.  c  o m
        return (ILayer) selection.getFirstElement();
    }
}

From source file:net.rim.ejde.internal.menu.DebugConfigurationsCommandHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event);
    if (selection != null && !selection.isEmpty()) {
        AbstractLaunchShortcut ls = new FledgeLaunchShortcut();
        ls.openLaunchConfiguration(selection, "debug");
    } else {//from  w  ww  .  j ava2  s  .  co m
        DebugUITools.openLaunchConfigurationDialog(Display.getDefault().getShells()[0],
                StructuredSelection.EMPTY, "debug");
    }
    return null;
}