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

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

Introduction

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

Prototype

@Override
    public int size() 

Source Link

Usage

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

License:Open Source License

/**
 * @generated/*from   ww  w.j a  v  a  2  s .  co m*/
 */
public void setInput(IWorkbenchPart part, ISelection selection) {
    if (selection.isEmpty() || false == selection instanceof StructuredSelection) {
        super.setInput(part, selection);
        return;
    }
    final StructuredSelection structuredSelection = ((StructuredSelection) selection);
    ArrayList transformedSelection = new ArrayList(structuredSelection.size());
    for (Iterator it = structuredSelection.iterator(); it.hasNext();) {
        Object r = transformSelection(it.next());
        if (r != null) {
            transformedSelection.add(r);
        }
    }
    super.setInput(part, new StructuredSelection(transformedSelection));
}

From source file:ac.soton.eventb.roseEditor.propertySections.abstracts.AbstractEventBPropertySection.java

License:Open Source License

@Override
public void setInput(final IWorkbenchPart part, final ISelection selection) {
    owner = null;//from  w  ww  . j ava2  s. co  m
    if (selection.isEmpty() || false == selection instanceof StructuredSelection) {
        super.setInput(part, selection);
        return;
    }
    final StructuredSelection structuredSelection = (StructuredSelection) selection;
    ArrayList<Object> transformedSelection = new ArrayList<Object>(structuredSelection.size());
    for (Object object : structuredSelection.toList()) {
        if (owner == null && object instanceof EventBElement) {
            owner = (EventBElement) object;
        }
        if (object != null) {
            transformedSelection.add(object);
        }
    }
    super.setInput(part, new StructuredSelection(transformedSelection));
}

From source file:bndtools.MakeBundle.java

License:Open Source License

@SuppressWarnings("unchecked")
IFile[] getLocations(ISelection selection) {
    if (selection != null && (selection instanceof StructuredSelection)) {
        StructuredSelection ss = (StructuredSelection) selection;
        IFile[] result = new IFile[ss.size()];
        int n = 0;
        for (Iterator<IFile> i = ss.iterator(); i.hasNext();) {
            result[n++] = i.next();//from   w w  w  .  j  ava  2s. c o  m
        }
        return result;
    }
    return null;
}

From source file:bndtools.release.ReleaseAction.java

License:Open Source License

static IFile[] getLocations(ISelection selection) {
    if (selection != null && (selection instanceof StructuredSelection)) {
        StructuredSelection ss = (StructuredSelection) selection;
        IFile[] result = new IFile[ss.size()];
        int n = 0;
        for (@SuppressWarnings("unchecked")
        Iterator<IFile> i = ss.iterator(); i.hasNext();) {
            result[n++] = i.next();//from   w  ww.  j  a  va2  s.c o  m
        }
        return result;
    }
    return null;
}

From source file:ca.uwaterloo.gp.fmp.constraints.ui.ConstraintsViewDropAdapter.java

License:Open Source License

public boolean performDrop(Object data) {
    // TODO Auto-generated method stub
    StructuredSelection structuredSelection = (StructuredSelection) data;

    // dropping only 1 feature is allowed
    if (structuredSelection.size() == 1) {
        Object toBeDroppedObj = structuredSelection.getFirstElement();

        // check the type of the feature to be dropped
        if (toBeDroppedObj instanceof Feature && !(toBeDroppedObj instanceof Node)) //to be changed
        {/*  w  w w .j  a va  2s  .co  m*/
            Feature toBeDroppedFeature = (Feature) toBeDroppedObj;

            // Get the constraint to be dropped onto
            Object target = getCurrentTarget();

            // if it is confirmed that the feature will be dropped onto an existing constraint
            if (target != null && target instanceof Constraint && ((Constraint) target).getText() != null) {
                Constraint constraintToBeModified = (Constraint) target;
                String featureName = toBeDroppedFeature.getName() == null ? "unnamed feature"
                        : toBeDroppedFeature.getName();
                constraintToBeModified.setText(constraintToBeModified.getText() + featureName);

                // update the view
                ((TreeViewer) getViewer()).update(target, null);
            }
        }
    }

    return true;
}

From source file:ch.elexis.core.ui.util.viewers.CommonViewer.java

License:Open Source License

/**
 * @return the {@link #getViewerWidget()} current selections first element or <code>null</code>
 * @since 3.2.0/*from   ww  w  . j  a  v a  2 s. c  om*/
 */
public Object getViewerWidgetFirstSelection() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    if (selection == null || selection.size() == 0) {
        return null;
    }
    return selection.getFirstElement();
}

From source file:com.amazonaws.eclipse.explorer.actions.ConfigurationActionProvider.java

License:Apache License

@Override
public void fillContextMenu(IMenuManager menu) {
    StructuredSelection selection = (StructuredSelection) getActionSite().getStructuredViewer().getSelection();

    if (selection.getFirstElement() instanceof ExplorerNode && selection.size() == 1) {
        ExplorerNode node = (ExplorerNode) selection.getFirstElement();

        if (node.getOpenAction() != null) {
            menu.add(node.getOpenAction());
            menu.add(new Separator());
        }/*from  w ww  .  j a  v  a 2  s  .  com*/
    }
}

From source file:com.amazonaws.eclipse.explorer.cloudformation.CloudFormationExplorerActionProvider.java

License:Apache License

@Override
public void fillContextMenu(IMenuManager menu) {
    StructuredSelection selection = (StructuredSelection) getActionSite().getStructuredViewer().getSelection();
    if (selection.size() != 1)
        return;//from  www .  ja  v a2s  . co m

    menu.add(new CreateStackAction());

    Object firstElement = selection.getFirstElement();
    if (firstElement instanceof StackNode) {
        menu.add(new Separator());
        menu.add(new SaveStackTemplateAction((StackNode) firstElement));
        menu.add(new CancelStackUpdateAction((StackNode) firstElement));
        menu.add(new UpdateStackAction((StackNode) firstElement));
    }
}

From source file:com.amazonaws.eclipse.explorer.identitymanagement.IdentityManagementExplorerActionProvider.java

License:Apache License

@Override
public void fillContextMenu(IMenuManager menu) {
    StructuredSelection selection = (StructuredSelection) getActionSite().getStructuredViewer().getSelection();
    if (selection.size() != 1)
        return;//from   w w w  .  java2 s  .  co m
    if (selection.getFirstElement() instanceof IdentityManagementRootElement
            || selection.getFirstElement() instanceof UserNode) {
        menu.add(new CreateUserAction());
    }
    if (selection.getFirstElement() instanceof IdentityManagementRootElement
            || selection.getFirstElement() instanceof GroupNode) {
        menu.add(new CreateGroupAction());
    }
    if (selection.getFirstElement() instanceof IdentityManagementRootElement
            || selection.getFirstElement() instanceof RoleNode) {
        menu.add(new CreateRoleAction());
    }
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle1.UiContentOutlinePage.java

License:Apache License

public UiContentOutlinePage(GraphicalLayoutEditor editor, final EditPartViewer viewer) {
    super(viewer);
    mEditor = editor;/*ww  w .j  av a 2s . co m*/
    IconFactory factory = IconFactory.getInstance();

    mAddAction = new Action("Add...") {
        @Override
        public void run() {
            List<UiElementNode> nodes = getModelSelections();
            UiElementNode node = nodes != null && nodes.size() > 0 ? nodes.get(0) : null;

            mUiActions.doAdd(node, viewer.getControl().getShell());
        }
    };
    mAddAction.setToolTipText("Adds a new element.");
    mAddAction.setImageDescriptor(factory.getImageDescriptor("add")); //$NON-NLS-1$

    mDeleteAction = new Action("Remove...") {
        @Override
        public void run() {
            List<UiElementNode> nodes = getModelSelections();

            mUiActions.doRemove(nodes, viewer.getControl().getShell());
        }
    };
    mDeleteAction.setToolTipText("Removes an existing selected element.");
    mDeleteAction.setImageDescriptor(factory.getImageDescriptor("delete")); //$NON-NLS-1$

    mUpAction = new Action("Up") {
        @Override
        public void run() {
            List<UiElementNode> nodes = getModelSelections();

            mUiActions.doUp(nodes);
        }
    };
    mUpAction.setToolTipText("Moves the selected element up");
    mUpAction.setImageDescriptor(factory.getImageDescriptor("up")); //$NON-NLS-1$

    mDownAction = new Action("Down") {
        @Override
        public void run() {
            List<UiElementNode> nodes = getModelSelections();

            mUiActions.doDown(nodes);
        }
    };
    mDownAction.setToolTipText("Moves the selected element down");
    mDownAction.setImageDescriptor(factory.getImageDescriptor("down")); //$NON-NLS-1$

    // all actions disabled by default.
    mAddAction.setEnabled(false);
    mDeleteAction.setEnabled(false);
    mUpAction.setEnabled(false);
    mDownAction.setEnabled(false);

    addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();

            // the selection is never empty. The least it'll contain is the
            // UiDocumentTreeEditPart object.
            if (selection instanceof StructuredSelection) {
                StructuredSelection structSel = (StructuredSelection) selection;

                if (structSel.size() == 1 && structSel.getFirstElement() instanceof UiDocumentTreeEditPart) {
                    mDeleteAction.setEnabled(false);
                    mUpAction.setEnabled(false);
                    mDownAction.setEnabled(false);
                } else {
                    mDeleteAction.setEnabled(true);
                    mUpAction.setEnabled(true);
                    mDownAction.setEnabled(true);
                }

                // the "add" button is always enabled, in order to be able to set the
                // initial root node
                mAddAction.setEnabled(true);
            }
        }
    });
}