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

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

Introduction

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

Prototype

@Override
public Iterator iterator();

Source Link

Document

Returns an iterator over the elements of this selection.

Usage

From source file:com.mentor.nucleus.bp.core.ui.BinaryFormalizeOnR_RELWizard.java

License:Open Source License

/**
 * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
 *//*  www .  j  a v  a 2  s  .com*/
public void init(IWorkbench workbench, IStructuredSelection selection, Viewer viewer) {
    this.m_workbench = workbench;
    this.m_selection = selection;
    this.m_viewer = viewer;
    for (Iterator iterator = selection.iterator(); iterator.hasNext();) {
        Object context = iterator.next();
        if (context instanceof Association_c) {
            v_rel = (Association_c) context;
        }
    }
}

From source file:com.mentor.nucleus.bp.core.ui.DefaultValueInputValidator.java

License:Open Source License

public static String isValueValid(String newValue) {
    if (newValue.isEmpty()) {
        return "";
    } else {//  w  w w  .  j  a  va2 s .  com
        IStructuredSelection currentSelection = Selection.getInstance().getStructuredSelection();
        Object context = currentSelection.iterator().next();
        if (context instanceof Attribute_c) {
            DataType_c dt = DataType_c.getOneS_DTOnR114((Attribute_c) context);
            return InputValueValidator.isValid(dt, newValue);
        } else if (context instanceof UserDataType_c) {
            DataType_c dt = DataType_c.getOneS_DTOnR17((UserDataType_c) context);
            return InputValueValidator.isValid(dt, newValue);
        } else if (context instanceof EnumerationDataType_c) {
            DataType_c dt = DataType_c.getOneS_DTOnR17((EnumerationDataType_c) context);
            return InputValueValidator.isValid(dt, newValue);
        } else {
            return "Unexpected selected input context.";
        }
    }
}

From source file:com.mentor.nucleus.bp.core.ui.NewDomainWizard.java

License:Open Source License

public void init(IWorkbench workbench, IStructuredSelection selection) {
    if (!selection.isEmpty()) {
        Object context = selection.iterator().next();
        if (context instanceof SystemModel_c) {
            m_sys = (SystemModel_c) context;
        }/*from   www . j  a  va2 s .c  om*/
    }
    m_creationPage = new WizardNewDomainCreationPage("newxtUMLDomainCreationPage");//$NON-NLS-1$
    m_creationPage.setTitle("New xtUML Model");
    m_creationPage.setDescription("Create a new xtUML Model");
    setWindowTitle("New xtUML Model");
    setNeedsProgressMonitor(true);
    this.addPage(m_creationPage);
}

From source file:com.mentor.nucleus.bp.debug.ui.actions.AuditRealizedCodeAction.java

License:Open Source License

/**
 * @see IActionDelegate#run(IAction)/*w ww  .j a va  2 s. c  o m*/
 */
public void run(IAction action) {
    IStructuredSelection selection = (IStructuredSelection) Selection.getInstance().getSelection();
    Iterator<?> it = selection.iterator();
    String result = "";
    while (it.hasNext()) {
        Object selectedElem = it.next();
        if (selectedElem instanceof Component_c) {
            result += VerifierInvocationAuditor.performRealizedCodeAudit((Component_c) selectedElem);
        } else if (selectedElem instanceof Package_c) {
            result += VerifierInvocationAuditor.performRealizedCodeAudit((Package_c) selectedElem);
        }
    }
    UIUtil.openScrollableTextDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), false,
            "Audit Complete", result, "The following checks were made:", null, null, true);
}

From source file:com.mentor.nucleus.bp.debug.ui.launch.LaunchVerifierAction.java

License:Open Source License

public void run(IAction action) {
    IStructuredSelection selection = (IStructuredSelection) Selection.getInstance().getStructuredSelection();

    if ((selection == null) || selection.isEmpty()) {
        return;//  w w  w  . j av a 2  s.  c o  m
    }

    if (selection.size() == 1) {
        Object context = selection.getFirstElement();

        if (context instanceof SystemModel_c) {
            IProject prj = (IProject) ((SystemModel_c) context).getAdapter(IProject.class);
            launchProject(prj);
        } else {
            if (context instanceof Domain_c || context instanceof ComponentReference_c) {
                launchMultipleModel(new NonRootModelElement[] { (NonRootModelElement) context });
            }

            if (context instanceof Component_c) {
                Component_c component = (Component_c) context;
                List<NonRootModelElement> list = new ArrayList<NonRootModelElement>();
                list.add(component);
                NonRootModelElement[] children = BPDebugUtils.getComponentChildren(component);
                for (int i = 0; i < children.length; i++) {
                    list.add(children[i]);
                }
                launchMultipleModel(list.toArray(new NonRootModelElement[list.size()]));
            }

            if (context instanceof ComponentPackage_c) {
                NonRootModelElement[] componentPackageChildren = BPDebugUtils
                        .getComponentPackageChildren((ComponentPackage_c) context);
                launchMultipleModel(componentPackageChildren);
            }
            if (context instanceof Package_c) {
                NonRootModelElement[] packageChildren = BPDebugUtils.getPackageChildren((Package_c) context);
                launchMultipleModel(packageChildren);
            }
        }
    } else {
        Vector<NonRootModelElement> model = null;
        Iterator ite = selection.iterator();

        while (ite.hasNext()) {
            Object o = ite.next();

            if (o instanceof Domain_c) {
                if (model == null) {
                    model = new Vector<NonRootModelElement>();
                }
                model.add((NonRootModelElement) o);
            } else if (o instanceof Component_c) {
                if (model == null) {
                    model = new Vector<NonRootModelElement>();
                }
                model.add((NonRootModelElement) o);
                NonRootModelElement[] children = BPDebugUtils.getComponentChildren((Component_c) o);
                for (int i = 0; i < children.length; i++) {
                    model.add(children[i]);
                }
            } else if (o instanceof ComponentReference_c) {
                if (model == null) {
                    model = new Vector<NonRootModelElement>();
                }
                Component_c component = Component_c.getOneC_COnR4201((ComponentReference_c) o);
                model.add(component);
                NonRootModelElement[] children = BPDebugUtils.getComponentChildren(component);
                for (int i = 0; i < children.length; i++) {
                    model.add(children[i]);
                }
            } else if (o instanceof ComponentPackage_c) {
                if (model == null) {
                    model = new Vector<NonRootModelElement>();
                }
                ComponentPackage_c compPackage = (ComponentPackage_c) o;
                NonRootModelElement[] children = BPDebugUtils.getComponentPackageChildren(compPackage);
                for (int i = 0; i < children.length; i++) {
                    model.add(children[i]);
                }
            } else if (o instanceof Package_c) {
                if (model == null) {
                    model = new Vector<NonRootModelElement>();
                }
                Package_c pkg = (Package_c) o;
                NonRootModelElement[] children = BPDebugUtils.getPackageChildren(pkg);
                for (int i = 0; i < children.length; i++) {
                    model.add(children[i]);
                }
            }
        }

        if (model != null) {
            launchMultipleModel(model.toArray(new NonRootModelElement[model.size()]));
        }
    }
}

From source file:com.mentor.nucleus.bp.model.compare.contentmergeviewer.ModelContentMergeViewer.java

License:Open Source License

public List<TreeDifference> getSelectedDifferences(boolean left, boolean ignoreSelection) {
    if (ignoreSelection && left) {
        return differencer.getLeftDifferences();
    }// www  .  j av  a 2 s  .co  m
    if (ignoreSelection && !left) {
        return differencer.getRightDifferences();
    }
    SynchronizedTreeViewer viewer = leftTreeViewer;
    List<TreeDifference> differences = new ArrayList<TreeDifference>();
    if (!left) {
        viewer = rightTreeViewer;
    }
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
        Object next = iterator.next();
        List<TreeDifference> located = differencer.getDifferences(next, left);
        if (located.isEmpty()) {
            // walk the hierarchy up to see if we find a difference that
            // includes children
            Object parent = ((ITreeContentProvider) viewer.getContentProvider()).getParent(next);
            while (parent != null) {
                located = differencer.getDifferences(parent, left);
                if (!located.isEmpty()) {
                    if (located.size() == 1) {
                        if (located.get(0).getIncludeChildren() && located.get(0).getElement() != null) {
                            differences.addAll(located);
                            break;
                        } else {
                            parent = ((ITreeContentProvider) viewer.getContentProvider()).getParent(parent);
                        }
                    } else {
                        // do not continue
                        break;
                    }
                } else {
                    parent = ((ITreeContentProvider) viewer.getContentProvider()).getParent(parent);
                }
            }
            // next see if this is a non-expanded parent that contains
            // differences and include all of them
            differences.addAll(SynchronizedTreeViewer.scanChildrenForDifferences(next, differencer,
                    (ITreeContentProvider) viewer.getContentProvider(), viewer == getLeftViewer()));
        } else {
            differences.addAll(located);
        }
    }
    return differences;
}

From source file:com.mentor.nucleus.bp.model.compare.contentmergeviewer.SynchronizedTreeViewer.java

License:Open Source License

protected Object handleOpen() {
    if (mergeViewer.getAncestorTree() == this) {
        return null;
    }/*from  w  w  w .  java  2  s . c  o  m*/
    IStructuredSelection sel = (IStructuredSelection) getSelection();
    if (sel.isEmpty()) {
        return null;
    }
    Object current = sel.iterator().next();
    // if the current selection has an Action_Semantics field
    // the grab the necessary object element to open that, failing
    // that look for a description attribute
    if (current instanceof NonRootModelElementComparable) {
        NonRootModelElement nrme = (NonRootModelElement) ((NonRootModelElementComparable) current)
                .getRealElement();
        if (nrme instanceof StateMachineState_c || nrme instanceof Transition_c) {
            // we need to navigate to the Action element
            // for the activity and description attributes
            Object[] children = ((ITreeContentProvider) getContentProvider()).getChildren(current);
            for (Object child : children) {
                if (child instanceof NonRootModelElementComparable) {
                    current = child;
                    break;
                }
            }
        }
        ObjectElement actionObjEle = null;
        ObjectElement descripObjEle = null;
        Object[] children = ((ITreeContentProvider) getContentProvider()).getChildren(current);
        for (Object child : children) {
            if (child instanceof ObjectElementComparable) {
                ObjectElementComparable comparable = (ObjectElementComparable) child;
                ObjectElement objElement = (ObjectElement) comparable.getRealElement();
                if (objElement.getName().equals("Action_Semantics")) {
                    actionObjEle = objElement;
                } else {
                    if (objElement.getName().equals("Descrip")) {
                        descripObjEle = objElement;
                    }
                }
            }
        }
        if (actionObjEle != null) {
            current = ComparableProvider.getComparableTreeObject(actionObjEle);
        } else {
            if (descripObjEle != null) {
                current = ComparableProvider.getComparableTreeObject(descripObjEle);
            }
        }
    }
    if (current instanceof ObjectElementComparable) {
        ObjectElementComparable comparable = (ObjectElementComparable) current;
        ObjectElement objElement = (ObjectElement) comparable.getRealElement();
        if (objElement.getName().equals("Descrip") || objElement.getName().equals("Action_Semantics")) {
            Object leftInput = getMergeViewer().getLeftViewer().getInput();
            Object rightInput = getMergeViewer().getRightViewer().getInput();
            TreeItem rightMatch = getMatchingItem(comparable, synchronizedViewers.get(0));
            TreeItem ancestorMatch = null;
            if (synchronizedViewers.size() == 2) {
                ancestorMatch = getMatchingItem(comparable, synchronizedViewers.get(1));
            }
            Object leftElement = comparable.getRealElement();
            Object rightElement = null;
            Object ancestor = null;
            if (ancestorMatch != null) {
                ancestor = ((ComparableTreeObject) ancestorMatch.getData()).getRealElement();
            }
            if (rightMatch != null) {
                rightElement = ((ComparableTreeObject) rightMatch.getData()).getRealElement();
            }
            if (mergeViewer.getLeftViewer() != this) {
                if (rightMatch == null) {
                    leftElement = null;
                } else {
                    leftElement = rightMatch.getData();
                    leftElement = ((ComparableTreeObject) leftElement).getRealElement();
                }
                rightElement = comparable.getRealElement();
            }
            // create a compare dialog, using the text compare
            final CompareConfiguration compareConfiguration = new CompareConfiguration();
            boolean leftEditable = leftInput instanceof IEditableContent
                    && ((IEditableContent) leftInput).isEditable();
            boolean rightEditable = rightInput instanceof IEditableContent
                    && ((IEditableContent) rightInput).isEditable();
            // if this is a single file compare, do not allow editing
            // at this time as there is no easy way to place the content
            // changes back into the file
            if (ComparePlugin.getDefault().getModelCacheManager()
                    .isInputReadonly(ModelCacheManager.getLeftKey(mergeViewer.getInput()))) {
                compareConfiguration.setLeftEditable(false);
                compareConfiguration.setRightEditable(false);
            } else {
                compareConfiguration.setLeftEditable(leftEditable);
                compareConfiguration.setRightEditable(rightEditable);
            }
            final TextualAttributeCompareEditorInput compareInput = new TextualAttributeCompareEditorInput(
                    compareConfiguration, (ObjectElement) leftElement, (ObjectElement) rightElement,
                    (ObjectElement) ancestor, SynchronizedTreeViewer.this);
            if (CompareUIPlugin.getDefault().compareResultOK(compareInput, null)) {
                Runnable runnable = new Runnable() {
                    public void run() {
                        CompareDialog dialog = new CompareDialog(
                                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), compareInput) {

                            @Override
                            protected Button createButton(Composite parent, int id, String label,
                                    boolean defaultButton) {
                                if (id == IDialogConstants.CANCEL_ID) {
                                    return null;
                                } else {
                                    return super.createButton(parent, id, label, defaultButton);
                                }
                            }

                        };
                        dialog.open();
                    }
                };
                if (Display.getCurrent() == null) {
                    Display.getDefault().syncExec(runnable);
                } else {
                    runnable.run();
                }
            }
            return null;
        }
    }

    return null;

}

From source file:com.mentor.nucleus.bp.ui.explorer.test.ExplorerTest.java

License:Open Source License

public void testSystemSelectionUpdatedWhenExplorerViewActivated() throws CoreException {
    m_bp_view.setLinkWithEditor(true);/* w  w  w  . j  a  va2  s .c om*/

    ensureAvailableAndLoaded(packageName, testModelName, false, false, "Package");

    ModelClass_c disk = getModelClassByName(modelRoot, "Disk");
    ModelClass_c drive = getModelClassByName(modelRoot, "Drive");
    ModelClass_c slot = getModelClassByName(modelRoot, "Slot");

    // set the active part to something other than explorer
    IViewReference[] viewReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getViewReferences();
    for (int i = 0; i < viewReferences.length; i++) {
        if (viewReferences[i].getPart(false) != m_bp_view) {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                    .activate(viewReferences[i].getPart(false));
            break;
        }
    }
    // get the structured selection
    IStructuredSelection selection = new StructuredSelection(new Object[] { disk, drive, slot });
    Selection.getInstance().setSelection(selection);

    m_bp_view.setLinkWithEditor(false);

    // open the Odms package
    Package_c odmspkg = Package_c.PackageInstance(modelRoot, new ClassQueryInterface_c() {

        public boolean evaluate(Object candidate) {
            if (((Package_c) candidate).getName().equals("Odms"))
                return true;
            else
                return false;
        }
    });
    CanvasTestUtils.openPackageCanvasEditor(odmspkg);

    GraphicalEditor ce = ((ModelEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getActiveEditor()).getGraphicalEditor();

    // get the center point of the robot class
    Shape_c shape = CanvasTestUtilities.getModelClassShape(modelRoot, "Robot");
    Point center = CanvasUtilities.getShapeCenter(shape);
    center = CanvasTestUtilities.convertToMouseCoor(center, ce.getModel());

    // select the shape found above
    CanvasTestUtilities.doMouseMove(center.x, center.y);
    CanvasTestUtilities.doMousePress(center.x, center.y);
    CanvasTestUtilities.doMouseRelease(center.x, center.y);

    // now activate the model explorer view
    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(m_bp_view);

    // verify that the current system selection
    // equals that of what was selected above before
    // the canvas selection was made
    BaseTest.dispatchEvents(0);

    Iterator<?> iterator = selection.iterator();
    while (iterator.hasNext()) {
        ModelClass_c clazz = (ModelClass_c) iterator.next();
        if (!Selection.getInstance().contains(clazz))
            fail("System selection was not updated when model explorer was activated.");
    }

}

From source file:com.mentor.nucleus.bp.ui.explorer.test.ExplorerTest.java

License:Open Source License

public void testSystemSelectionNotUpdatedWhenExplorerViewActivated() {
    // turn on link with editor
    m_bp_view.setLinkWithEditor(true);/*w w w  .ja  va 2  s.c  o  m*/

    ModelClass_c disk = getModelClassByName(modelRoot, "Disk");
    ModelClass_c drive = getModelClassByName(modelRoot, "Drive");
    ModelClass_c slot = getModelClassByName(modelRoot, "Slot");

    // get the structured selection
    IStructuredSelection selection = new StructuredSelection(new Object[] { disk, drive, slot });
    Selection.getInstance().setSelection(selection);

    // open the Odms package
    Package_c odmspkg = Package_c.PackageInstance(modelRoot, new ClassQueryInterface_c() {

        public boolean evaluate(Object candidate) {
            if (((Package_c) candidate).getName().equals("Odms"))
                return true;
            else
                return false;
        }
    });
    CanvasTestUtils.openPackageCanvasEditor(odmspkg);

    GraphicalEditor ce = ((ModelEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getActiveEditor()).getGraphicalEditor();

    // get the center point of the robot class
    Shape_c shape = CanvasTestUtilities.getModelClassShape(modelRoot, "Robot");
    Point center = CanvasUtilities.getShapeCenter(shape);
    center = CanvasTestUtilities.convertToMouseCoor(center, ce.getModel());

    // select the shape found above
    CanvasTestUtilities.doMouseMove(center.x, center.y);
    CanvasTestUtilities.doMousePress(center.x, center.y);
    CanvasTestUtilities.doMouseRelease(center.x, center.y);

    // now activate the model explorer view
    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(m_bp_view);

    // verify that the current system selection
    // equals that of what was selected above before
    // the canvas selection was made
    BaseTest.dispatchEvents(0);

    Iterator<?> iterator = selection.iterator();
    while (iterator.hasNext()) {
        ModelClass_c clazz = (ModelClass_c) iterator.next();
        if (Selection.getInstance().contains(clazz))
            fail("System selection was updated when model explorer was activated.");
    }
}

From source file:com.mentor.nucleus.bp.ui.explorer.test.I634ExplorerEmptySelectionTest.java

License:Open Source License

public void testOpenOnLoadedModelInExplorer() throws Throwable {
    ExplorerTest.restoreProject();/*w  w  w  .jav a  2s  .  c  om*/
    ensureAvailableAndLoaded("small", false);

    IStructuredSelection sel = (IStructuredSelection) Selection.getInstance().getSelection();
    if (!sel.isEmpty()) {
        Selection.getInstance().removeFromSelection(sel.iterator().next());
    }
    assertTrue((Selection.getInstance().getSelection()).isEmpty());
    sendEventAndCheckLog(ExplorerUtil.getTreeViewer().getTree(), SWT.DefaultSelection, new Event());
}