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:ac.soton.eventb.classdiagrams.diagram.part.ClassdiagramsDiagramUpdateCommand.java

License:Open Source License

/**
 * @generated//from   w w w  . j a v  a  2s. c  o  m
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService()
            .getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        if (structuredSelection.size() != 1) {
            return null;
        }
        if (structuredSelection.getFirstElement() instanceof EditPart
                && ((EditPart) structuredSelection.getFirstElement()).getModel() instanceof View) {
            EObject modelElement = ((View) ((EditPart) structuredSelection.getFirstElement()).getModel())
                    .getElement();
            List editPolicies = CanonicalEditPolicy.getRegisteredEditPolicies(modelElement);
            for (Iterator it = editPolicies.iterator(); it.hasNext();) {
                CanonicalEditPolicy nextEditPolicy = (CanonicalEditPolicy) it.next();
                nextEditPolicy.refresh();
            }

        }
    }
    return null;
}

From source file:ac.soton.eventb.classdiagrams.diagram.part.ModelElementSelectionPage.java

License:Open Source License

/**
 * @generated/*  ww  w .  j  a  v  a2  s  . co  m*/
 */
protected void updateSelection(IStructuredSelection selection) {
    selectedModelElement = null;
    if (selection.size() == 1) {
        Object selectedElement = selection.getFirstElement();
        if (selectedElement instanceof IWrapperItemProvider) {
            selectedElement = ((IWrapperItemProvider) selectedElement).getValue();
        }
        if (selectedElement instanceof FeatureMap.Entry) {
            selectedElement = ((FeatureMap.Entry) selectedElement).getValue();
        }
        if (selectedElement instanceof EObject) {
            selectedModelElement = (EObject) selectedElement;
        }
    }
    setPageComplete(validatePage());
}

From source file:ac.soton.eventb.classdiagrams.diagram.sheet.custom.ConstraintsPropertySection.java

License:Open Source License

@Override
protected ISelection getEditorSelection(Object object) {
    DiagramEditor editor = (DiagramEditor) getPart();
    IStructuredSelection selection = (IStructuredSelection) editor.getDiagramGraphicalViewer().getSelection();
    if (selection != null && selection.size() == 1) {
        GraphicalEditPart selectedPart = (GraphicalEditPart) selection.getFirstElement();
        EditPart part = selectedPart.findEditPart(null, (EObject) object);
        if (part != null)
            return new StructuredSelection(part);
        if (selectedPart.getParent() != null) {
            part = ((GraphicalEditPart) selectedPart.getParent()).findEditPart(null, (EObject) object);
            if (part != null)
                return new StructuredSelection(part);
        }// w  w  w .  j a v  a2 s .  c  om
    }
    return null;
}

From source file:ac.soton.eventb.roseEditor.properties.ElementLabelProvider.java

License:Open Source License

/**
 * Determine if a multiple object selection has been passed to the label
 * provider. If the objects is a IStructuredSelection, see if all the
 * objects in the selection are the same and if so, we want to provide
 * labels for the common selected element.
 *
 * @param objects/*from   w  ww.  j ava  2s. c om*/
 *            a single object or a IStructuredSelection.
 * @param multiple
 *            first element in the array is true if there is multiple
 *            unequal selected elements in a IStructuredSelection.
 * @return the object to get labels for.
 */
private Object getObject(final Object objects, final boolean multiple[]) {
    Assert.isNotNull(objects);
    Object object = null;
    if (objects instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) objects;
        object = selection.getFirstElement();
        if (selection.size() == 1) {
            // one element selected
            multiple[0] = false;
            return object;
        }
        // multiple elements selected
        multiple[0] = true;
        Class<?> firstClass = typeMapper.mapType(object);
        // determine if all the objects in the selection are the same type
        for (Object next : selection.toArray()) {
            //= i.next();
            Class<?> nextClass = typeMapper.mapType(next);
            if (!nextClass.equals(firstClass)) {
                // two elements not equal == multiple selected unequal
                multiple[0] = false;
                object = null;
                break;
            }
        }
    } else {
        multiple[0] = false;
        object = objects;
    }
    return object;
}

From source file:ac.soton.eventb.statemachines.diagram.sheet.custom.InvariantsPropertySection.java

License:Open Source License

@Override
protected ISelection getEditorSelection(Object object) {
    StatemachinesDiagramEditor editor = (StatemachinesDiagramEditor) getPart();
    IStructuredSelection selection = (IStructuredSelection) editor.getDiagramGraphicalViewer().getSelection();
    if (selection != null && selection.size() == 1) {
        GraphicalEditPart selectedPart = (GraphicalEditPart) selection.getFirstElement();
        EditPart part = selectedPart.findEditPart(null, (EObject) object);
        if (part != null)
            return new StructuredSelection(part);
        if (selectedPart.getParent() != null) {
            part = ((GraphicalEditPart) selectedPart.getParent()).findEditPart(null, (EObject) object);
            if (part != null)
                return new StructuredSelection(part);
        }/*from www.  j ava2 s  . c  om*/
    }
    return null;
}

From source file:ac.soton.xeventb.internal.ui.XTextConvertHandler.java

License:Open Source License

/**
 * Get the current only selected object. If more than one objects are
 * selected, return <code>null</code>.
 * /*from  ww  w . j  a va 2 s.  com*/
 * @param event
 *          the execution event
 * @return the only selected object.
 * @throws ExecutionException
 *          if some unexpected error occurs.
 */
private Object getCurrentSelectedObject(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    if ((selection instanceof IStructuredSelection)) {
        IStructuredSelection ssel = ((IStructuredSelection) selection);
        int _size = ssel.size();
        boolean _tripleEquals = (_size == 1);
        if (_tripleEquals) {
            return ssel.getFirstElement();
        }
    }
    return null;
}

From source file:actions.RenameAction.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    selectedObject = null;/*w  w  w. j a va  2  s.  co  m*/
    selectedNameAttribute = null;
    selectedROAttribute = null;
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structedSelection = (IStructuredSelection) selection;
        if (structedSelection.size() > 0 && ALLOWED_TYPES != null
                && isSupportedType(structedSelection.getFirstElement())) {
            selectedObject = (EObject) structedSelection.getFirstElement();
        }
    }
    if (selectedObject != null && ALLOWED_TYPES != null && !isObjectReadOnly(selectedObject)) {
        action.setEnabled(true);
    } else
        action.setEnabled(false);

}

From source file:algsymboleditor.wizards.NewFencedWizardPage.java

License:Open Source License

/**
 * Checks the current workbench selection for suitability, and then
 * initializes the wizard page.// w  w w.jav a2s  .  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("new_file.algfenced");
}

From source file:algsymboleditor.wizards.NewQuotientWizardPage.java

License:Open Source License

/**
 * Checks the current workbench selection for suitability, and then
 * initializes the wizard page.//  w  w  w  . j av a  2 s.  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("new_file.algquotient");
}

From source file:algsymboleditor.wizards.NewSymbolWizardPage.java

License:Open Source License

/**
 * Checks the current workbench selection for suitability, and then
 * initializes the wizard page./*from   w  ww  . j  av  a  2  s.co  m*/
 */
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("new_file.algsymbol");
}