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:org.celllife.idart.gui.packaging.NewPatientPackaging.java

License:Open Source License

private void lstWaitingPatientsWidgetSelected() {
    clearForm();/*  w ww  .  j  a va 2  s.c o m*/
    Runnable longJob = new Runnable() {
        @Override
        public void run() {
            StructuredSelection selection = (StructuredSelection) lstWaitingPatients.getSelection();
            if (selection != null && !selection.isEmpty()) {
                populatePatientDetails(((PatientIdAndName) selection.getFirstElement()).getId());
                cmbWeeksSupplyChanged();
            }
        }
    };
    BusyIndicator.showWhile(getShell().getDisplay(), longJob);
}

From source file:org.cropinformatics.ui.viewers.list.AbstractSingleListStructuredViewer.java

License:Apache License

@SuppressWarnings("unchecked")
protected final void handleStructuredSelection(StructuredSelection structuredSelection) {
    if (ConfigurationUtils.isMultipleSelectionInUse(getConfiguration())) {
        // for large selections it may be necessary just to trap what is de-selected and what is selected
        List<T> oldValue = selectedItems;

        selectedItems = new LinkedList<T>();

        if (!structuredSelection.isEmpty()) {
            @SuppressWarnings("rawtypes")
            Iterator iterator = structuredSelection.iterator();

            while (iterator.hasNext())
                selectedItems.add((T) iterator.next());
        }//from   w  ww  .j  av  a2  s .c  o m

        handleInternalPropertyChange(SELECTION_PROPERTY, oldValue, getSelectedItems());
    } else {
        selectedItems.clear();

        T oldValue = getSelectedItem();

        if (!structuredSelection.isEmpty())
            selectedItems.add((T) structuredSelection.getFirstElement());

        handleInternalPropertyChange(SELECTION_PROPERTY, oldValue, getSelectedItem());
    }

    updateButtons();
}

From source file:org.dawb.common.ui.wizard.ResourceChoosePage.java

License:Open Source License

protected List<String> getSelectedFiles() {

    if (selectedFiles != null)
        return selectedFiles;
    try {//from   w  w w  .  j  a  v a 2s .  c  o  m
        ISelection selection = EclipseUtils.getActivePage().getSelection();
        StructuredSelection s = (StructuredSelection) selection;
        if (s.isEmpty())
            return null;
        if (s.toArray() == null)
            return null;

        final Object[] oa = s.size() > 1 ? s.toArray() : getObjects(s.getFirstElement());

        final List<String> ret = new ArrayList<String>(oa.length);
        for (final Object object : oa) {
            final File file = FileUtils.getFile(object);
            if (!file.isFile())
                continue;
            ret.add(file.getAbsolutePath());
        }
        return ret.size() > 0 ? ret : null;
    } catch (Throwable ignored) {
        return null;
    }
}

From source file:org.eclipse.birt.report.designer.internal.ui.editors.breadcrumb.EditorBreadcrumb.java

License:Open Source License

private boolean doReveal(ISelection selection) {
    if (!(selection instanceof StructuredSelection))
        return false;

    StructuredSelection structuredSelection = (StructuredSelection) selection;
    if (structuredSelection.isEmpty())
        return false;

    return reveal(structuredSelection.getFirstElement());

}

From source file:org.eclipse.birt.report.designer.ui.dialogs.CascadingParametersDialog.java

License:Open Source License

private void updateDynamicTableButtons() {
    StructuredSelection selection = (StructuredSelection) defaultValueViewer.getSelection();
    boolean enable = (selection.size() == 1);
    editValueBtn.setEnabled(enable);/* w w w.j a  v a  2  s  .  c  om*/
    delValueBtn.setEnabled(!selection.isEmpty());
    delAllValuesBtn.setEnabled(defaultValueViewer.getTable().getItemCount() > 0);

    Expression expression = ExpressionButtonUtil.getExpression(defaultValueChooser);
    if (defaultValueChooser.getText().trim().length() == 0) {
        addValueButton.setEnabled(false);
    } else {
        if (defaultValueList != null && defaultValueList.contains(expression))
            addValueButton.setEnabled(false);
        else
            addValueButton.setEnabled(true);
    }
}

From source file:org.eclipse.birt.report.designer.ui.dialogs.ParameterDialog.java

License:Open Source License

private void updateDynamicTableButtons() {
    StructuredSelection selection = (StructuredSelection) defaultValueViewer.getSelection();
    boolean enable = (selection.size() == 1);
    editBtn.setEnabled(enable);/*w  w  w . j a v a  2 s .  c  o m*/
    delBtn.setEnabled(!selection.isEmpty());
    delAllBtn.setEnabled(defaultValueViewer.getTable().getItemCount() > 0);

    String type = (String) defaultValueChooser.getData(ExpressionButtonUtil.EXPR_TYPE);
    String value = UIUtil.convertToModelString(defaultValueChooser.getText(), false);
    if (value != null) {
        if (value.equals(EMPTY_VALUE))
            value = ""; //$NON-NLS-1$
        else if (value.equals(NULL_VALUE))
            value = null;
    }
    Expression expression = null;
    if (value != null)
        expression = new Expression(value, type);

    if (defaultValueChooser.getText().trim().length() == 0) {
        addButton.setEnabled(false);
    } else {
        if (defaultValueList != null && defaultValueList.contains(expression))
            addButton.setEnabled(false);
        else
            addButton.setEnabled(true);
    }
    updateMessageLine();
}

From source file:org.eclipse.bpel.ui.BPELEditor.java

License:Open Source License

/**
 * @see org.eclipse.gef.ui.parts.GraphicalEditor#initializeGraphicalViewer()
 *//* w ww .  j  a  v a 2  s.c o  m*/
@Override
protected void initializeGraphicalViewer() {
    ///FIXME moved to multi
    //initializeFileChangeListener();
    //initializeRefactoringListeners();

    getGraphicalViewer().setEditPartFactory(new BPELEditPartFactory());

    BPELUIPlugin.INSTANCE.getPreferenceStore().setValue(IBPELUIConstants.PREF_SHOW_FREEFORM_FLOW, true);
    GraphicalViewer viewer = getGraphicalViewer();
    viewer.setContents(getProcess());

    viewer.addDropTargetListener(new FileDropTargetListener(viewer, this));
    viewer.addDropTargetListener(new TextDropTargetListener(viewer, this));
    viewer.addDropTargetListener(new BPELTextTransferDropTargetListener(viewer, this));
    viewer.addDropTargetListener(new BPELTemplateTransferDropTargetListener(viewer));

    this.selectionChangeListener = new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            // if this is a multi-selection we should not present anything on the details area
            if (selection.size() > 1) {
                // TODO: This doesn't work
                //               getBPELDetailsEditor().getDetailsArea().setInput(null);
            } else {
                final Object o = selection.getFirstElement();
                if (o instanceof EditPart) {
                    // CAREFUL: must setInput() on the DetailsArea *before* we remember
                    // the lastSelectedEditPart (because setInput() might execute a pending
                    // command for an IOngoingChange whose wrapper will not execute correctly
                    // unless lastSelectedEditPart has its old value).
                    lastSelectedEditPart = (EditPart) o;
                }
            }
        }
    };
    this.traySelectionChangeListener = new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            // if this is a multi-selection we should not present anything on the details area
            if (selection.size() > 1) {
                // TODO: This doesn't work.
                //               getBPELDetailsEditor().getDetailsArea().setInput(null);
            } else {
                final Object o = selection.getFirstElement();
                if (o instanceof EditPart) {
                    // CAREFUL: must setInput() on the DetailsArea *before* we remember
                    // the lastSelectedEditPart (because setInput() might execute a pending
                    // command for an IOngoingChange whose wrapper will not execute correctly
                    // unless lastSelectedEditPart has its old value).
                    lastSelectedEditPart = (EditPart) o;
                }
            }
        }
    };
    getGraphicalViewer().addSelectionChangedListener(this.selectionChangeListener);
    arrangeEditParts(getGraphicalViewer());
}

From source file:org.eclipse.datatools.enablement.sybase.asa.actions.ProfileASAMultiDBAction.java

License:Open Source License

public void run(IAction action) {
    StructuredSelection ssel = (StructuredSelection) this.mSelection;
    if (!ssel.isEmpty()) {
        Object element = ssel.getFirstElement();
        if (element instanceof IConnectionProfile) {
            IConnectionProfile profile = (IConnectionProfile) element;
            MultiASADialog dlg = new MultiASADialog(this.mShell);
            dlg.setProfile(profile);/*from w  w  w  .jav a2 s  .  c  o m*/
            int rtn = dlg.open();
            if (rtn == Window.OK) {
                performFinish(profile, dlg.getDBNames());
            }
        }
    }
}

From source file:org.eclipse.e4.demio.views.nav.ResourceNavigator.java

License:Open Source License

/**
 * Selects and reveals the specified elements.
 *//*from www  .j a va2 s .co  m*/
public void selectReveal(ISelection selection) {
    StructuredSelection ssel = convertSelection(selection);
    if (!ssel.isEmpty()) {
        getViewer().getControl().setRedraw(false);
        getViewer().setSelection(ssel, true);
        getViewer().getControl().setRedraw(true);
    }
}

From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet007ColorLabelProvider.java

License:Open Source License

/**
 * @param args/*from   w ww .j a  va 2s .  c  om*/
 */
public static void main(String[] args) {
    final List persons = new ArrayList();
    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 gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
            table.setLayoutData(gridData);
            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.
            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:
                public String getColumnText(Object element, int index) {
                    if (index == 0) {
                        return Integer.toString(persons.indexOf(element) + 1);
                    }
                    return ((Person) element).getName();
                }

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

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

                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(300, 400);
            shell.open();

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