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.nokia.s60tools.remotecontrol.ftp.ui.view.FtpView.java

License:Open Source License

/**
 * Is selected item a single folder/*from   w  ww. java  2 s.  c  o m*/
 * @return True if single folder else false
 */
private boolean isSelectionSingleFolder() {
    boolean retVal = false;
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    Object selectedObject = selection.getFirstElement();

    if (selection.size() == 1) {
        if (selectedObject != null) {
            if (FtpFolderObject.class.isInstance(selectedObject)) {
                retVal = true;
            }
        }
    }
    return retVal;
}

From source file:com.nokia.s60tools.stif.configeditor.wizards.NewStifConfigWizardPage.java

License:Open Source License

/**
 * Tests if the current workbench selection is a suitable container to use.
 *//*from   w  ww  . ja  va  2 s  .  com*/
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("TestFramework.ini");
}

From source file:com.nokia.sdt.component.symbian.actionFilter.BaseComponentActionFilterDelegate.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    // this filters whether the action is enabled for the given selection
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        if (structuredSelection.size() == 1) {
            Object firstElement = structuredSelection.getFirstElement();
            if (firstElement instanceof IAdaptable) {
                IAdaptable adaptable = (IAdaptable) firstElement;
                IComponentInstance instance = (IComponentInstance) adaptable
                        .getAdapter(IComponentInstance.class);
                if (instance != null) {
                    EObject eObject = instance.getEObject();
                    this.selected = eObject;
                    if (firstElement instanceof GraphicalEditPart) {
                        this.editPart = (GraphicalEditPart) firstElement;
                        this.shell = editPart.getViewer().getControl().getShell();
                    }//  w w  w.j  ava2 s.co  m
                    updateActionForSelectedObject(action, eObject);
                    return;
                }
            }
        }
    }

    this.editPart = null;
    this.selected = null;
    action.setEnabled(false);
}

From source file:com.nokia.sdt.component.symbian.actions.SwitchVisibleChildActionDelegate.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    // this filters whether the action is enabled for the given selection
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        if (structuredSelection.size() == 1) {
            Object firstElement = structuredSelection.getFirstElement();
            if (firstElement instanceof IAdaptable) {
                IAdaptable adaptable = (IAdaptable) firstElement;
                IComponentInstance instance = (IComponentInstance) adaptable
                        .getAdapter(IComponentInstance.class);
                if (instance != null) {
                    container = findSwitchableContainerWantingMenu(instance.getEObject());
                    updateActionForContainer(action, container);
                    return;
                }/* w  ww . j  a  va2s .  c  om*/
            }
        }
    }

    this.container = null;
    action.setEnabled(false);
}

From source file:com.nokia.sdt.component.symbian.actions.VerticalMoveActionDelegate.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        if (structuredSelection.size() == 1) {
            Object firstElement = structuredSelection.getFirstElement();
            if (firstElement instanceof IAdaptable) {
                IAdaptable adaptable = (IAdaptable) firstElement;
                IComponentInstance instance = (IComponentInstance) adaptable
                        .getAdapter(IComponentInstance.class);
                if (instance != null) {
                    EObject object = instance.getEObject();
                    EObject parent = instance.getParent();
                    if (EditorUtils.canReorderChildren(parent,
                            getEObjectListFromSelection(structuredSelection))) {
                        IComponentInstance parentInstance = Utilities.getComponentInstance(parent);
                        EObject[] children = removeTemporaryObjects(parentInstance.getChildren());
                        if (isApplicableForDirection(object, children)) {
                            this.object = object;
                            action.setEnabled(true);
                            return;
                        }//w  ww .j ava  2s. c  om
                    }
                }
            }
        }
    }

    this.object = null;
    action.setEnabled(false);
}

From source file:com.nokia.testfw.codegen.ui.preferences.TESTFWTemplatePreferencePage.java

License:Open Source License

protected boolean canEdit() {
    IStructuredSelection selection = (IStructuredSelection) iTreeViewer.getSelection();

    return (selection.size() == 1 && (((PathNode) selection.getFirstElement()).getData() != null));
}

From source file:com.nokia.testfw.codegen.ui.preferences.TESTFWTemplatePreferencePage.java

License:Open Source License

protected boolean canRemove() {
    IStructuredSelection selection = (IStructuredSelection) iTreeViewer.getSelection();

    if (selection.size() == 1 && (((PathNode) selection.getFirstElement()).getData() != null)) {
        TemplatePersistenceData data = (TemplatePersistenceData) ((PathNode) selection.getFirstElement())
                .getData();/*w  w  w. j  a va  2s. co m*/
        return data.isUserAdded();
    } else {
        return false;
    }
}

From source file:com.nokia.testfw.codegen.ui.preferences.TESTFWTemplatePreferencePage.java

License:Open Source License

/**
 * Updates the pattern viewer.//from   ww w .j  a va  2 s .  c  o m
 */
protected void updateViewerInput() {
    if (iPatternViewer == null || iPatternViewer.getTextWidget().isDisposed())
        return;
    IStructuredSelection selection = (IStructuredSelection) iTreeViewer.getSelection();

    if (selection.size() == 1 && (((PathNode) selection.getFirstElement()).getData() != null)) {
        TemplatePersistenceData data = (TemplatePersistenceData) ((PathNode) selection.getFirstElement())
                .getData();
        Template template = data.getTemplate();
        TemplateContextType type = CUIPlugin.getDefault().getCodeTemplateContextRegistry()
                .getContextType(template.getContextTypeId());
        if (type == null) {
            type = CodegenUIPlugin.getDefault().getContextTypeRegistry()
                    .getContextType(template.getContextTypeId());
        }
        iTemplateProcessor.setContextType(type);
        reconfigurePatternViewer();
        iPatternViewer.getDocument().set(template.getPattern());
    } else {
        iPatternViewer.getDocument().set("");
    }

}

From source file:com.nokia.testfw.codegen.ui.preferences.TESTFWTemplatePreferencePage.java

License:Open Source License

/**
 * Updates the buttons.//from   w  ww.j  a v  a2s .  com
 */
protected void updateButtons() {
    IStructuredSelection selection = (IStructuredSelection) iTreeViewer.getSelection();
    int selectionCount = selection.size();
    boolean canRestore = getTemplateStore().getTemplateData(true).length != getTemplateStore()
            .getTemplateData(false).length;
    boolean canRevert = false;
    TemplatePersistenceData data = null;
    for (Iterator<?> it = selection.iterator(); it.hasNext();) {
        data = (TemplatePersistenceData) ((PathNode) it.next()).getData();
        if (data != null && data.isModified()) {
            canRevert = true;
            break;
        }
    }

    iEditButton.setEnabled(selectionCount == 1 && data != null);
    iExportButton.setEnabled(selectionCount > 0);
    iRemoveButton.setEnabled(selectionCount > 0);
    iRestoreButton.setEnabled(canRestore);
    iRevertButton.setEnabled(canRevert);
}

From source file:com.nokia.testfw.stf.configeditor.wizards.NewStifConfigWizardPage.java

License:Open Source License

/**
 * Tests if the current workbench selection is a suitable container to use.
 *//*from www. j  a  v  a 2s. c om*/
private void initialize() {
    IStructuredSelection ssel = (IStructuredSelection) selection;
    Object obj = null;
    String projectname = null;
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {

        if (ssel.size() > 1)
            return;
        obj = ssel.getFirstElement();
        if (obj instanceof IResource) {
            IContainer container;
            if (obj instanceof IContainer)
                container = (IContainer) obj;
            else
                container = ((IResource) obj).getParent();
            projectname = container.getProject().getName();
            containerText.setText(container.getFullPath().toString());
        }
        if (obj instanceof ISourceRoot) {
            projectname = ((ISourceRoot) obj).getCProject().toString();
            containerText.setText(((ISourceRoot) obj).getPath().toString());
        }
        if (obj instanceof ICElement) {
            projectname = ((ICElement) obj).getElementName();
            containerText.setText(((ICElement) obj).getPath().toString());
        }

    }
    if (obj == null || projectname == null) {
        fileText.setText(filenamepre);
        return;
    }

    if (projectname.length() > 0) {
        fileText.setText(filenamepre + projectname);
    }
}