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

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

Introduction

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

Prototype

public boolean isEmpty();

Source Link

Document

Returns whether this selection is empty.

Usage

From source file:com.mansfield.pde.api.tools.internal.ui.preferencepages.TargetBaselinePreferencePage.java

License:Open Source License

/**
 * @return the current selection from the table viewer
 *///from   ww w  .j  a v  a  2  s .  c  o  m
@SuppressWarnings("unchecked")
protected List<Object> getCurrentSelection() {
    IStructuredSelection ss = (IStructuredSelection) fTableViewer.getSelection();
    if (ss.isEmpty()) {
        return new ArrayList<Object>();
    }
    return (List<Object>) ss.toList();
}

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   w  w w  .j av  a  2 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.BPBreakpointPropertiesAction.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) selection;
        if (ss.isEmpty() || ss.size() > 1) {
            return;
        }/*from  w  w  w .  j a v  a2 s.c o m*/
        Object element = ss.getFirstElement();
        if (element instanceof BPBreakpoint) {
            setBreakpoint((BPBreakpoint) element);
        }
    }
}

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

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) selection;
        if (ss.isEmpty() || ss.size() > 1) {
            return;
        }/*from ww  w.j a v a2s .c  om*/
        Object element = ss.getFirstElement();
        if (element instanceof NonRootModelElement) {
            setElement((NonRootModelElement) element);
        }
        if (determineBreakpoint() == null) {
            action.setText("Set Breakpoint");
        } else {
            action.setText("Remove Breakpoint");
        }
    }
}

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

License:Open Source License

public void launch(ISelection selection, String mode) {
    this.mode = mode;

    if (selection instanceof IStructuredSelection) {
        IStructuredSelection sselect = (IStructuredSelection) selection;

        if (!sselect.isEmpty()) {
            Object context = sselect.getFirstElement();

            if (context instanceof IFile) {
                IFile modelFile = ((IFile) context);
                IContainer folder = modelFile.getParent();

                if (folder instanceof IFolder && folder.getName().equals("models")) { //$NON-NLS-1$

                    if (modelFile.getName().endsWith("xtuml")) { //$NON-NLS-1$
                        selectedProject = modelFile.getProject();
                        launchModelFile(modelFile);
                    } else {
                        selectedProject = modelFile.getProject();

                        if (selectedProject != null) {
                            launchProject(selectedProject);
                        }/*from  ww  w . j  a va  2 s.c  o m*/
                    }
                } else {
                    BPDebugUIPlugin.logError("The selected model is invalid.", null);

                    IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

                    UIUtil.showMessageDialoginLaunch(win.getShell(), "Verifier Launcher",
                            "The selected model is invalid.", UIUtil.BPMessageTypes.ERROR);
                }
            } else if ((context instanceof IProject)) {
                if (context instanceof IProject) {
                    selectedProject = (IProject) context;

                    if (selectedProject != null) {
                        launchProject(selectedProject);
                    }
                }
            }
        }
    }
}

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;/* ww  w.  ja v  a2 s  . c om*/
    }

    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.SynchronizedTreeViewer.java

License:Open Source License

protected Object handleOpen() {
    if (mergeViewer.getAncestorTree() == this) {
        return null;
    }/*w ww.  j  a v  a 2s  . 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.canvas.ModelContentOutlinePage.java

License:Open Source License

/**
 * Fire up an editor/* w  w w  .  j  a  v a  2  s  . co m*/
 */
private void handleOpen() {
    IStructuredSelection sel = Selection.getInstance().getStructuredSelection();
    if (sel.isEmpty()) {
        return;
    }
    Object current = (sel).iterator().next();
    String name = current.getClass().getName();

    // see if the current element should open
    // something other than itself
    current = EditorUtil.getElementToEdit(current);
    //
    // Get the registry
    //
    IExtensionRegistry reg = Platform.getExtensionRegistry();
    //
    // Get all the plugins that have extended this point
    //
    IExtensionPoint extPt = reg.getExtensionPoint("com.mentor.nucleus.bp.core.editors");
    IExtension[] exts = extPt.getExtensions();
    // Repeat for each extension until we find a default editor
    for (int i = 0; i < exts.length; i++) {
        IConfigurationElement[] elems = exts[i].getConfigurationElements();
        for (int j = 0; j < elems.length; j++) {
            // Find the editor elements
            if (elems[j].getName().equals("editor")) {
                IConfigurationElement[] edElems = elems[j].getChildren();
                for (int k = 0; k < edElems.length; k++) {
                    //
                    // Is this editor the default for the current model element ?
                    //
                    if (edElems[k].getName().equals("defaultFor")
                            && edElems[k].getAttribute("class").equals(name)) {
                        try {
                            //
                            // Get the class supplied for the input
                            //
                            Bundle bundle = Platform.getBundle(elems[j].getDeclaringExtension().getNamespace());
                            Class inputClass = bundle.loadClass(elems[j].getAttribute("input")); //$NON-NLS-1$
                            Class[] type = new Class[1];
                            type[0] = Object.class;
                            //
                            // Dynamically get the method createInstance, the supplied class must implement this
                            //
                            Method createInstance = inputClass.getMethod("createInstance", type); //$NON-NLS-1$
                            Object[] args = new Object[1];
                            args[0] = current;
                            //
                            // Invoke the method.
                            // The method is static; no instance is needed, so first argument is null
                            //
                            IEditorInput input = (IEditorInput) createInstance.invoke(null, args);
                            //
                            // pass the input to the Eclipse editor, along with the class name supplied by
                            // the extending plugin.
                            //
                            if (input != null) {
                                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                                        .openEditor(input, elems[j].getAttribute("class")); //$NON-NLS-1$
                            }
                            return;
                        } catch (ClassNotFoundException e) {
                            CanvasPlugin.logError("Input Class not found", e); //$NON-NLS-1$
                        } catch (NoSuchMethodException e) {
                            CanvasPlugin.logError("Class does not implement static method createInstance", e); //$NON-NLS-1$
                        } catch (InvocationTargetException e) {
                            CanvasPlugin.logError(
                                    "Exception occured on invocation of static method createInstance of the Target", //$NON-NLS-1$
                                    e.getTargetException());
                        } catch (IllegalAccessException e) {
                            CanvasPlugin.logError("Target does not support static method createInstance", e); //$NON-NLS-1$
                        } catch (PartInitException e) {
                            CanvasPlugin.logError("Could not activate Editor", e); //$NON-NLS-1$
                        }
                    }
                }
            }
        }
    }
}

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

License:Open Source License

/**
 * Tests to see if a connector in a canvas can be selected
 * while the "Link with Editor" model-explorer button is depressed.
 * Issue 453 fixed a bug where such selections would fail.   
 *//* w w w  .  ja va  2  s . co  m*/
public void testConnectorSelectionInLinkedMode() throws CoreException, IOException {
    // setup the test project and model
    PersistableModelComponent domainComponent = ensureAvailableAndLoaded(packageName, testModelName, false,
            false, "Package");
    modelRoot = (Ooaofooa) domainComponent.getRootModelElement().getModelRoot();

    // make the link-with-editor button (on the explorer view) depressed
    ExplorerUtil.setLinkWithEditor(true);

    // open the package that contains the class diagram
    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;
        }
    });
    GraphicalEditor editor = CanvasTestUtils.openPackageCanvasEditor(odmspkg);

    // zoom all contents
    editor.zoomAll();
    BaseTest.dispatchEvents(0);

    // get a handle to the R4 relationship
    Ooaofgraphics graphicsModelRoot = Ooaofgraphics.getInstance(modelRoot.getId());
    CanvasTestUtils util = new CanvasTestUtils();
    Association_c r4 = Association_c.AssociationInstance(modelRoot, util.new Association_by_numb_c(4));

    // detm the mouse coordinates of an (arbitrary) point on R4's connector    
    Connector_c connector = Connector_c.ConnectorInstance(graphicsModelRoot,
            util.new Connector_by_ooaid_c(r4.getRel_id(), 24));
    LineSegment_c segment = LineSegment_c.getOneGD_LSOnR6(connector);
    Point segmentCenter = CanvasTestUtils.getSegmentCenter(segment);
    Point mouseCoords = CanvasTestUtils.convertToMouseCoor(segmentCenter, editor.getModel());

    // do a mouse click on the point on R4 detm'd above 
    CanvasTestUtils.createMouseEvent(mouseCoords.x, mouseCoords.y, "MouseDown");
    CanvasTestUtils.createMouseEvent(mouseCoords.x, mouseCoords.y, "MouseUp");

    // check that R4 is the currently selected model element, 
    // even though the model explorer's selection is linked to
    // the canvas editor 
    IStructuredSelection selection = Selection.getInstance().getStructuredSelection();
    assertTrue("Selection is empty", !selection.isEmpty());
    Object selected = selection.getFirstElement();
    assertTrue("Selection is not R4", selected == r4);
}

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

License:Open Source License

public void testOpenOnLoadedModelInExplorer() throws Throwable {
    ExplorerTest.restoreProject();/*from  www.  j  ava2  s .  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());
}