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.nextep.designer.vcs.ui.compare.ComparisonEditorProvidersItems.java

License:Open Source License

/**
 * Fills the given menu with items representing available comparison editor providers. This
 * method is used for both the menu contribution and the drop down button menu.
 * //from  w  w  w .  j  ava  2s . c  o m
 * @param menu a {@link Menu} to fill with comparison editor providers proposals
 */
protected void fillComparisonEditorProviderMenuItems(Menu menu, int style, SelectionListener listener) {
    ISelection s = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
    IElementType selectedType = null;
    if (s instanceof IStructuredSelection) {
        final IStructuredSelection sel = (IStructuredSelection) s;
        if (sel.size() == 1) {
            Object o = sel.getFirstElement();
            if (o instanceof ITypedObject) {
                selectedType = ((ITypedObject) o).getType();
            }
        }
    }
    final List<IComparisonEditorProvider> providers = VCSUIPlugin.getComparisonUIManager()
            .getAvailableComparisonEditorProviders(selectedType);
    for (final IComparisonEditorProvider provider : providers) {
        MenuItem menuItem = new MenuItem(menu, style);
        menuItem.setText(provider.getLabel());
        menuItem.setImage(provider.getIcon());
        menuItem.setData(PROVIDER_KEY, provider);
        menuItem.setSelection(
                provider == VCSUIPlugin.getComparisonUIManager().getComparisonEditorProvider(selectedType));
        menuItem.addSelectionListener(listener);
    }
}

From source file:com.nextep.designer.vcs.ui.handlers.CopyHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection s = HandlerUtil.getCurrentSelection(event);
    if (!s.isEmpty() && s instanceof IStructuredSelection) {
        final IStructuredSelection sel = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
        if (sel.size() == 1 && sel.getFirstElement() instanceof IVersionable<?>) {
            final IVersionable<?> o = (IVersionable<?>) sel.getFirstElement();
            // Prompting for new name
            final RenameConnector connector = new RenameConnector((IObservable) o);
            GUIWrapper wrapper = new GUIWrapper(connector, VCSUIMessages.getString("handler.copy.title"), //$NON-NLS-1$
                    300, 120);//from  ww w .  j  a v  a 2s.  co m
            wrapper.invoke();
            if (!wrapper.isCancelled()) {
                String newName = connector.getNewName();
                if (newName == null || "".equals(newName.trim())) { //$NON-NLS-1$
                    MessageDialog.openWarning(wrapper.getShell(),
                            VCSUIMessages.getString("handler.rename.invalidTitle"), //$NON-NLS-1$
                            VCSUIMessages.getString("handler.rename.invalidMsg")); //$NON-NLS-1$
                } else if (newName.equals(o.getName())) {
                    MessageDialog.openWarning(wrapper.getShell(),
                            VCSUIMessages.getString("handler.copy.invalidTitle"), //$NON-NLS-1$
                            VCSUIMessages.getString("handler.copy.invalidMsg")); //$NON-NLS-1$
                } else {
                    final IVersionable<?> copy = VersionableFactory.copy(o);
                    copy.setName(newName);
                    copy.setVersion(VersionFactory.getUnversionedInfo(
                            new Reference(copy.getType(), copy.getName(), copy),
                            Activity.getDefaultActivity()));
                    // Assigning fresh new references to contained elements
                    final Map<IReference, IReferenceable> refMap = copy.getReferenceMap();
                    for (IReference r : refMap.keySet()) {
                        final IReferenceable referenceable = refMap.get(r);
                        referenceable.setReference(new Reference(r.getType(),
                                ((INamedObject) referenceable).getName(), referenceable));
                    }
                    // Adding to container
                    o.getContainer().addVersionable(copy, new ImportPolicyAddOnly());
                    return newName;
                }
            }
        }
    }
    return null;
}

From source file:com.nextep.designer.vcs.ui.handlers.OpenTypedObjectAction.java

License:Open Source License

@Override
public boolean isEnabled() {
    final ISelection sel = selectionProvider.getSelection();
    if (!sel.isEmpty()) {
        final IStructuredSelection selection = (IStructuredSelection) sel;
        return selection.size() == 1 && selection.getFirstElement() instanceof ITypedObject
                && !(selection.getFirstElement() instanceof ITypedNode);
    }/* w  ww  .j  av  a  2s.  co m*/
    return false;
}

From source file:com.nextep.designer.vcs.ui.handlers.OpenTypedObjectAction.java

License:Open Source License

@Override
public void run() {
    final IStructuredSelection sel = (IStructuredSelection) selectionProvider.getSelection();
    if (!sel.isEmpty()) {
        // Warning before opening too many editors
        if (sel.size() > WARN_DIALOG_ABOVE) {
            final boolean confirmed = MessageDialog.openConfirm(page.getWorkbenchWindow().getShell(),
                    MessageFormat.format(UIMessages.getString("editItemWarnCountTitle"), sel.size()), //$NON-NLS-1$
                    MessageFormat.format(UIMessages.getString("editItemWarnCount"), sel.size(), sel.size())); //$NON-NLS-1$
            if (!confirmed) {
                return;
            }//  ww w .java2 s.com
        }
        // If OK, we open everything
        final Iterator<?> selIt = sel.iterator();
        while (selIt.hasNext()) {
            final Object o = selIt.next();
            if ((o instanceof ITypedObject) && !(o instanceof IConnector<?, ?>)) {
                final ITypedObject t = (ITypedObject) o;
                UIControllerFactory.getController(t.getType()).defaultOpen(t);
            }
        }
    }
}

From source file:com.nextep.designer.vcs.ui.navigators.NavigatorLinkHelper.java

License:Open Source License

@Override
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    if (aSelection.size() == 1) {
        if (aSelection.getFirstElement() instanceof ITypedObject) {
            final ITypedObject o = (ITypedObject) aSelection.getFirstElement();
            if (!(o instanceof ITypedNode)) {
                final ITypedObjectUIController controller = UIControllerFactory.getController(o);
                // final String editorId = controller.getEditorId();
                final IEditorInput input = controller.getEditorInput(o);
                IEditorPart part = aPage.findEditor(input);
                if (part != null) {
                    aPage.bringToTop(part);
                }//from w w  w .  j av  a  2s  . c om
            }
        }
    }

}

From source file:com.nokia.carbide.cdt.internal.builder.ui.CarbideBuildConfigurationsPage.java

License:Open Source License

private void addEnvironementTableSelectionListener() {
    envVarsTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {

            if (event.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                if (selection.size() == 1) {
                    IEnvironmentVariable envVar = (IEnvironmentVariable) selection.getFirstElement();
                    editEnvVarButton.setEnabled(true);
                    removeEnvVarButton.setEnabled(true);
                    varUseCombo.setEnabled(true);
                    setVariableUseCombo(envVar);

                } else {
                    editEnvVarButton.setEnabled(false);
                    removeEnvVarButton.setEnabled(false);
                    varUseCombo.setEnabled(false);
                }/*from  w  ww  .  ja  v a  2s.c om*/
            }
        }
    });
}

From source file:com.nokia.carbide.cdt.internal.builder.ui.SisFilesBlock.java

License:Open Source License

private void removeFiles() {
    IStructuredSelection selection = (IStructuredSelection) fFileList.getSelection();
    ISISBuilderInfo[] files = new ISISBuilderInfo[selection.size()];
    Iterator iter = selection.iterator();
    int i = 0;// w  w  w .  ja  va 2  s . c o m
    while (iter.hasNext()) {
        files[i] = (ISISBuilderInfo) iter.next();
        i++;
    }
    removeFiles(files);
}

From source file:com.nokia.carbide.cpp.debug.kernelaware.ui.SymbianOSView.java

License:Open Source License

public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    if (!(selection instanceof IStructuredSelection))
        return;// w  ww.  j  ava2 s.c o m

    IStructuredSelection structSel = (IStructuredSelection) selection;
    if (structSel.size() != 1)
        return;

    Object sel = structSel.getFirstElement();

    // Allow StackFrame & thread for now.
    // If we hornor selection of CDebugTarget, debugger may freeze on start
    // when the OS View is open before debugger starts.
    // Figure out a solution later..... 11/29/06
    // Not a problem any more in Eclipse 3.3 + CDT4.0....... 11/15/07
    //
    if (!(sel instanceof ICStackFrame || sel instanceof ICThread || sel instanceof ICDebugTarget))
        return;

    Session newSession = Session.getSessionFromDebugContext(sel);

    if (newSession == null) // how come ?
        return;

    /* A terminated session, or a special case:
     * Start the first debug session while the OS View is open, the
     * CDT Target (process) is created and auto selected in Debug View
     * but corresponding CWProcess is not created yet. In such case
     * we should not try to refresh. Part of fix to bug 5320.. 12/04/07
     */
    if (!newSession.isActive())
        return;

    /*
     * If user just selects a different item (stackframe, thread, process)
     * in the same session, and the session's OS data is not dirty, don't
     * bother to update.
     */
    boolean refresh = false;

    if (m_currentSession == null) {
        refresh = true;
    } else if (!m_currentSession.equals(newSession))
        // Different session is selected (by user).
        refresh = true;
    else {
        // The same session is selected (by user or automatically done when debuggee
        // is suspended). Refresh only when data is dirty and AutoRefresh is
        // turned on.
        if (newSession.getOSDataManager().isDataDirty() && m_autoRefresh) {
            refresh = true;

            // Check this for stop mode debug. Fix bug 3467...03/28/07
            if (newSession.isSystemModeDebug() && newSession.isSystemRunning())
                refresh = false;
        }
    }

    if (refresh) {
        try {
            showDataForDevice(newSession);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.nokia.carbide.cpp.internal.builder.utils.handlers.PreprocessHandler.java

License:Open Source License

/**
 * If the selected file is a translation unit, bld.inf or mmp file, returns
 * the IFile, otherwise returns null//  www .  j  av a 2  s .c om
 * @param selection the selection
 * @return the IFile, or null
 */
public static IFile getFileToPreprocess(ISelection selection) {

    IFile selectedFile = null;

    if (selection instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) selection;
        if (ss.size() == 1) {
            Object selectionItem = ss.getFirstElement();
            if (selectionItem instanceof ITranslationUnit) {
                ITranslationUnit tu = (ITranslationUnit) selectionItem;
                if (tu.isSourceUnit() && tu.getResource() instanceof IFile) {
                    selectedFile = (IFile) tu.getResource();
                }
            } else {
                IFile file = null;
                if (selectionItem instanceof IFile) {
                    file = (IFile) selectionItem;
                } else if (selectionItem instanceof IAdaptable) {
                    file = (IFile) ((IAdaptable) selectionItem).getAdapter(IFile.class);
                }

                if (file != null) {
                    ITranslationUnit tu = CoreModelUtil.findTranslationUnit(file);
                    if (tu != null && tu.isSourceUnit()) {
                        selectedFile = file;
                    } else {
                        String filename = file.getName().toLowerCase();
                        if (filename.endsWith(MMP_EXTENSION) || filename.endsWith(INF_EXTENSION)) {
                            selectedFile = file;
                        }
                    }
                }
            }
        }
    } else if (selection instanceof ITextSelection) {
        IWorkbenchWindow window = Activator.getActiveWorkbenchWindow();
        if (window != null) {
            IWorkbenchPage page = window.getActivePage();
            if (page != null) {
                IWorkbenchPart part = page.getActivePart();
                if (part instanceof IEditorPart) {
                    IEditorPart epart = (IEditorPart) part;
                    IResource resource = (IResource) epart.getEditorInput().getAdapter(IResource.class);
                    ICElement element = CoreModel.getDefault().create(resource);
                    if (element instanceof ITranslationUnit) {
                        ITranslationUnit tu = (ITranslationUnit) element;
                        if (tu.isSourceUnit() && tu.getResource() instanceof IFile) {
                            selectedFile = (IFile) tu.getResource();
                        }
                    } else {
                        if (resource instanceof IFile) {
                            IFile file = (IFile) resource;
                            String filename = file.getName().toLowerCase();
                            if (filename.endsWith(MMP_EXTENSION) || filename.endsWith(INF_EXTENSION)) {
                                selectedFile = file;
                            }
                        }
                    }
                }
            }
        }
    }

    return selectedFile;
}

From source file:com.nokia.carbide.cpp.internal.pi.save.SaveSamplesPage.java

License:Open Source License

/**
 * Tests if the current workbench selection is a suitable container to use.
 *//*from   ww w .  j  av  a  2s  .  co m*/

private void initialize() {
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() > 1)
            return;
    }
    fileText.setText("new_file.csv"); //$NON-NLS-1$
}