Example usage for org.eclipse.jface.viewers IStructuredSelection size

List of usage examples for org.eclipse.jface.viewers IStructuredSelection size

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection size.

Prototype

public int size();

Source Link

Document

Returns the number of elements selected in this selection.

Usage

From source file:com.minres.scviewer.e4.application.handlers.AddWaveformHandler.java

License:Open Source License

@Execute
public void execute(@Named(PARAM_WHERE_ID) String where, @Named(PARAM_ALL_ID) String all,
        EPartService partService,/* w  ww. ja  va 2s. c o  m*/
        @Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection) {
    if (designBrowser == null)
        designBrowser = getListPart(partService);
    if (designBrowser != null && selection.size() > 0) {
        List<?> sel = selection.toList();
        designBrowser.getActiveWaveformViewerPart().addStreamsToList(sel.toArray(new IWaveform<?>[] {}),
                "before".equalsIgnoreCase(where));
    }
}

From source file:com.minres.scviewer.e4.application.internal.status.WaveStatusBarControl.java

License:Open Source License

/**
 * Sets the selection.//w  ww  .j a  v a  2 s  .com
 *
 * @param selection the new selection
 */
@Inject
public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection) {
    if (manager != null && selection != null) {
        switch (selection.size()) {
        case 0:
            manager.setMessage("");
            break;
        case 1:
            manager.setMessage(selection.getFirstElement().getClass().getSimpleName() + " selected");
            break;
        default:
            manager.setMessage("" + selection.size() + " Elements");
            break;
        }
    }
}

From source file:com.minres.scviewer.e4.application.parts.DesignBrowser.java

License:Open Source License

/**
 * Sets the focus./*from w w  w.  ja  va2 s .  co  m*/
 */
@Focus
public void setFocus() {
    txTableViewer.getTable().setFocus();
    IStructuredSelection selection = (IStructuredSelection) txTableViewer.getSelection();
    if (selection.size() == 0) {
        appendItem.setEnabled(false);
    }
    selectionService.setSelection(selection);
    thisSelectionCount = selection.toList().size();
    updateButtons();
}

From source file:com.minres.scviewer.e4.application.parts.WaveformViewer.java

License:Open Source License

/**
 * Adds the streams to list./*from w w  w.j  av  a2  s  . c om*/
 *
 * @param iWaveforms the i waveforms
 * @param insert the insert
 */
public void addStreamsToList(IWaveform<? extends IWaveformEvent>[] iWaveforms, boolean insert) {
    List<TrackEntry> streams = new LinkedList<>();
    for (IWaveform<? extends IWaveformEvent> stream : iWaveforms)
        streams.add(new TrackEntry(stream));
    IStructuredSelection selection = (IStructuredSelection) waveformPane.getSelection();
    if (selection.size() == 0) {
        waveformPane.getStreamList().addAll(streams);
    } else {
        Object first = selection.getFirstElement();
        IWaveform<?> stream = (first instanceof ITx) ? ((ITx) first).getStream() : (IWaveform<?>) first;
        TrackEntry trackEntry = waveformPane.getEntryForStream(stream);
        int index = waveformPane.getStreamList().indexOf(trackEntry);
        if (!insert)
            index++;
        waveformPane.getStreamList().addAll(index, streams);
    }
}

From source file:com.misc.common.moplaf.emf.editor.tentative.AbstractAction.java

License:Open Source License

protected Object getSelectedObject() {
    ISelection selection = this.selection;

    if (!(selection instanceof IStructuredSelection)) {
        return null;
    }/*  w w  w .ja  v  a 2s  .  c om*/
    IStructuredSelection structuredselection = (IStructuredSelection) selection;

    if (structuredselection.size() != 1) {
        return null;
    }

    return structuredselection.getFirstElement();
}

From source file:com.misc.common.moplaf.emf.editor.tentative.AbstractAction3.java

License:Open Source License

protected Object getSelectedObject() {
    ISelection selection = this.getSelection();

    if (!(selection instanceof IStructuredSelection)) {
        return null;
    }/*  w  ww . ja  v a 2s .c  o  m*/
    IStructuredSelection structuredselection = (IStructuredSelection) selection;

    if (structuredselection.size() != 1) {
        return null;
    }

    return structuredselection.getFirstElement();
}

From source file:com.mmkarton.mx7.reportgenerator.wizards.BIRTReportWizardPage.java

License:Open Source License

/**
 * Tests if the current workbench selection is a suitable container to use.
 *//* w w w .j ava  2s. c  om*/

private void initialize() {
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() > 1)
            return;
        Object obj = ssel.getFirstElement();
        if (obj instanceof IResource) {
            IContainer container;
            if (obj instanceof IContainer)
                container = (IContainer) obj;
            else
                container = ((IResource) obj).getParent();
            containerText.setText(container.getFullPath().toString());
        }
    }
    fileText.setText("mm_new_report.rptdesign");
}

From source file:com.mobilesorcery.sdk.profiles.ui.DeviceFilterComposite.java

License:Open Source License

private void updateUI(final boolean updateCount) {
    filterTable.getControl().getDisplay().asyncExec(new Runnable() {
        @Override/*from ww  w  .  j av  a 2 s.  com*/
        public void run() {
            boolean noFilters = filter == null || filter.getFilters().length == 0;
            filterTable.setInput(
                    noFilters ? new String[] { Messages.DeviceFilterComposite_NoFilter } : filter.getFilters());

            remove.setEnabled(!noFilters);

            IStructuredSelection selection = (IStructuredSelection) filterTable.getSelection();
            edit.setEnabled(selection.size() == 1 && selection.getFirstElement() instanceof IDeviceFilter
                    && isEditable((IDeviceFilter) selection.getFirstElement()) && !noFilters);
            if (updateCount) {
                updateDeviceCount();
            }
        }
    });
}

From source file:com.mobilesorcery.sdk.profiles.ui.internal.ProfilesView.java

License:Open Source License

private void initMenu(Control control) {
    final MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {
        @Override/*ww  w  . j  a v  a2 s .  c o m*/
        public void menuAboutToShow(IMenuManager manager) {
            IStructuredSelection selection = (IStructuredSelection) profileTree.getSelection();
            if (selection.size() == 1 && selection.getFirstElement() instanceof IProfile) {
                menuMgr.add(setTargetAction);
                menuMgr.add(buildForProfile);
                menuMgr.add(new Separator());
                menuMgr.add(showProfileInfo);
            }
        }
    });

    control.setMenu(menuMgr.createContextMenu(control));
}

From source file:com.motorola.studio.android.command.CleanProjects.java

License:Apache License

public Object execute(ExecutionEvent event) throws ExecutionException {

    // Retrieve the selection used in the command
    IWorkbench workbench = PlatformUI.getWorkbench();
    if ((workbench != null) && !workbench.isClosing()) {
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        if (window != null) {
            ISelection selection = window.getSelectionService().getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection sselection = (IStructuredSelection) selection;
                Iterator<?> it = sselection.iterator();

                // Construct a list of valid projects to be cleaned
                List<IProject> projectList = new ArrayList<IProject>(sselection.size());

                while (it.hasNext()) {
                    Object resource = it.next();

                    // Check if the selected item is a project
                    if (resource instanceof IProject) {
                        projectList.add(((IProject) resource));
                    } else if (resource instanceof IAdaptable) {
                        IAdaptable adaptable = (IAdaptable) resource;
                        projectList.add((IProject) adaptable.getAdapter(IProject.class));

                    }/*  w  w  w. j  a  va  2s.  c o m*/

                }

                // Instantiate the clean job and schedule it.
                if (projectList.size() > 0) {
                    CleanProjectsJob job = new CleanProjectsJob(projectList);
                    job.schedule();
                }

            }
        }
    }
    return null;
}