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

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

Introduction

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

Prototype

@Override
    public Object getFirstElement() 

Source Link

Usage

From source file:edu.washington.cs.cupid.usage.events.CupidEventBuilder.java

License:Open Source License

public static CupidEventBuilder contextEvent(final Class<?> view, IWorkbenchPart source, ISelection selection,
        final Plugin plugin) {
    Map<String, String> data = Maps.newHashMap();

    data.put("empty", Boolean.toString(selection.isEmpty()));
    data.put("selectionClass", selection.getClass().getName());

    if (!selection.isEmpty() && selection instanceof StructuredSelection) {
        StructuredSelection structured = ((StructuredSelection) selection);
        data.put("size", Integer.toString(structured.size()));

        if (structured.getFirstElement() == null) {
            data.put("dataClass", null);
        } else {/*from   w  w w .j av a  2 s .  com*/
            data.put("dataClass", structured.getFirstElement().getClass().getName());
        }
    }

    data.put("sourceClass", source.getClass().getName());
    data.put("sourceTitle", source.getTitle());

    return new CupidEventBuilder(EventConstants.SELECTION_CONTEXT_WHAT, view, plugin).addData(data);
}

From source file:es.cv.gvcase.gvm.glossary.formseditor.composites.fefem.TableOfTermsComposite.java

License:Open Source License

protected void handleSelectionChanged() {
    MainPage page = ((MainPage) this.getPage());

    StructuredSelection selection = (StructuredSelection) getViewer().getSelection();

    if (page != null && page.getTermDetailsComposite() != null
            && !page.getTermDetailsComposite().isDisposed()) {

        page.getTermDetailsComposite().dispose();
    }/* w w w . j ava 2  s.co  m*/

    if (selection.getFirstElement() instanceof EObject) {
        EObject selectedTerm = (EObject) selection.getFirstElement();
        page.createTermDetails(selectedTerm);

        page.getEditor().getEcoreValidationListener().obtainDiagnostics(selectedTerm);
    }

}

From source file:es.cv.gvcase.ide.navigator.dialogs.NavigatorSearchDialog.java

License:Open Source License

@Override
protected void createButtonsForButtonBar(Composite parent) {
    backButton = createButton(parent, IDialogConstants.BACK_ID, IDialogConstants.BACK_LABEL, false);
    backButton.setEnabled(false);// ww w. j  a  v a 2s  . co m
    backButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ISelection sel = viewer.getSelection();
            if (!(sel instanceof StructuredSelection)) {
                return;
            }
            StructuredSelection ssel = (StructuredSelection) sel;

            int index = matchedObjects.lastIndexOf(ssel.getFirstElement());
            if (index == 0) {
                index = matchedObjects.size() - 1;
            }
            index--;
            if (index < 0) {
                index = 0;
            }
            StructuredSelection ss = new StructuredSelection(matchedObjects.get(index));
            viewer.setSelection(ss, true);
        }
    });

    nextButton = createButton(parent, IDialogConstants.NEXT_ID, IDialogConstants.NEXT_LABEL, false);
    nextButton.setEnabled(false);
    nextButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ISelection sel = viewer.getSelection();
            if (!(sel instanceof StructuredSelection)) {
                return;
            }
            StructuredSelection ssel = (StructuredSelection) sel;

            int index = matchedObjects.lastIndexOf(ssel.getFirstElement());
            if (index == matchedObjects.size() - 1) {
                index = -1;
            }
            index++;
            StructuredSelection ss = new StructuredSelection(matchedObjects.get(index));
            viewer.setSelection(ss, true);
        }
    });

    createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false);
}

From source file:es.cv.gvcase.ide.navigator.view.MOSKittModelNavigator.java

License:Open Source License

/**
 * If linking, propagate the selection in the {@link CommonViewer} to the
 * active {@link IEditorPart}./*from   ww  w.  java 2s.  c  o  m*/
 * 
 * @param event
 *            the event
 */
protected void handleSelectionChangedToDiagram(SelectionChangedEvent event) {
    if (isLinkingEnabled() && startHandlingSelectionChange()) {
        IEditorPart activeEditor = NavigatorUtil.getActiveEditor();
        if (activeEditor instanceof IDiagramWorkbenchPart) {
            // set editor selection; select EditParts
            IDiagramGraphicalViewer viewer = ((IDiagramWorkbenchPart) activeEditor).getDiagramGraphicalViewer();
            if (viewer == null) {
                return;
            }
            List<EditPart> editPartsToSelect = NavigatorUtil.getEditPartsFromSelection(event.getSelection(),
                    viewer);
            StructuredSelection selectedEditParts = new StructuredSelection(editPartsToSelect);
            viewer.setSelection(selectedEditParts);
            if (!selectedEditParts.isEmpty()) {
                EditPart editPart = (EditPart) selectedEditParts.getFirstElement();
                viewer.reveal(editPart);
            }
        }
        endHandlingSelectionChange();
    }
}

From source file:es.cv.gvcase.mdt.common.actions.handlers.ClipboardActionHandler.java

License:Open Source License

protected void setSelectionTo(Collection<EObject> eObjects, IGraphicalEditPart editPart) {
    eObjects = fromViewToEObject(eObjects);
    Collection<IGraphicalEditPart> editParts = getEditPartsFor(eObjects, editPart);
    if (editParts != null && !editParts.isEmpty()) {
        IDiagramGraphicalViewer viewer = ((IDiagramWorkbenchPart) MDTUtil.getActiveEditor())
                .getDiagramGraphicalViewer();
        if (viewer == null) {
            return;
        }//  w w  w  . ja  va 2 s  .  c  o  m
        StructuredSelection selectedEditParts = new StructuredSelection(editParts);
        viewer.setSelection(selectedEditParts);
        if (!selectedEditParts.isEmpty()) {
            EditPart firstEditPart = (EditPart) selectedEditParts.getFirstElement();
            viewer.reveal(firstEditPart);
        }
    }
}

From source file:es.cv.gvcase.mdt.common.actions.OpenUpperDiagramPopupMenuContributionPolicy.java

License:Open Source License

public boolean appliesTo(ISelection selection, IConfigurationElement configuration) {
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getActiveEditor();//  w  w w.j  ava2s  . c  om
    if (activeEditor instanceof CachedResourcesDiagramEditor == false
            && activeEditor instanceof MOSKittMultiPageEditor == false) {
        return false;
    }

    if (selection instanceof StructuredSelection) {
        StructuredSelection ss = (StructuredSelection) selection;
        if (ss.size() <= 0 || ss.size() > 1) {
            return false;
        }
        Object object = ss.getFirstElement();
        if (object instanceof IGraphicalEditPart) {
            if (((IGraphicalEditPart) object).getNotationView() instanceof Diagram) {
                Diagram diagram = (Diagram) ((IGraphicalEditPart) object).getNotationView();
                if (MultiDiagramUtil.getUpperDiagram(diagram) != null) {
                    return true;
                }
            }
        }
    }

    return false;
}

From source file:es.cv.gvcase.mdt.common.composites.CreateButtonInfo.java

License:Open Source License

/**
 * Check if the Button will be available for the specified selection
 *//*ww w. j  av a2 s  .co m*/
public boolean isEnabledFor(ISelection selection) {
    if (customCheck(selection)) {
        return true;
    }

    if (!(selection instanceof StructuredSelection)) {
        return false;
    }

    StructuredSelection ss = (StructuredSelection) selection;
    if (!(ss.getFirstElement() instanceof EObject)) {
        return false;
    }

    EObject eo = (EObject) ss.getFirstElement();
    return isEnabledFor(eo);
}

From source file:es.cv.gvcase.mdt.common.composites.RefresheableComposite.java

License:Open Source License

/**
 * Check if the current Composite is available for the given selection in
 * the Tree. By default, it checks is it's a StructuredSelection and if the
 * first selected element is an EObject. In this case, checks if this
 * composite is available for its eClass.
 *//*from w  w w  . j a  va 2  s  . c  om*/
public boolean isEnabledFor(ISelection selection) {
    if (!(selection instanceof StructuredSelection)) {
        return false;
    }

    StructuredSelection ss = (StructuredSelection) selection;
    if (!(ss.getFirstElement() instanceof EObject)) {
        return false;
    }

    EObject eo = (EObject) ss.getFirstElement();
    return isEnabledFor(eo.eClass());
}

From source file:es.cv.gvcase.mdt.common.part.DiagramElementsSelectionPage.java

License:Open Source License

/**
 * Handle add button selected./*from w  ww  .j a  v a 2 s  .c  om*/
 */
protected void handleAddButtonSelected() {
    StructuredSelection selection = getCandidateElementsSelection();
    if (selection == null) {
        return;
    }

    if (selection.size() == 1) {
        Object element = selection.getFirstElement();
        if (element instanceof EObject) {
            addToMemberElements((EObject) element);
        }
    } else {
        for (Object element : selection.toList()) {
            if (element instanceof EObject) {
                addToMemberElements((EObject) element);
            }
        }
    }

    refreshMembersViewer();
    refreshCandidatesViewer();
    // enable add buttons depending on candidate elements selected
    selection = getCandidateElementsSelection();
    enableAddButtons(selection != null && selection.size() > 0);
}

From source file:es.cv.gvcase.mdt.common.part.DiagramElementsSelectionPage.java

License:Open Source License

/**
 * Handle add referenced elements button selected.
 *///  w  w w.  j  a va  2s  . c om
protected void handleAddReferencedElementsButtonSelected() {
    StructuredSelection selection = getCandidateElementsSelection();
    if (selection == null) {
        return;
    }

    if (selection.size() == 1) {
        if (!(selection.getFirstElement() instanceof EObject)) {
            return;
        }
        Object element = selection.getFirstElement();
        if (element instanceof EObject) {
            addToMemberElements((EObject) element);
            // Add related elements that have to be drawn on diagram
            addToMemberElements(getReferencedElements((EObject) element));
        }
    } else {
        for (Object element : selection.toList()) {
            if (element instanceof EObject) {
                addToMemberElements((EObject) element);
                // Add related elements that have to be drawn on diagram
                addToMemberElements(getReferencedElements((EObject) element));
            }
        }
    }

    refreshMembersViewer();
    refreshCandidatesViewer();
    // enable add buttons depending on candidate elements selected
    selection = getCandidateElementsSelection();
    enableAddButtons(selection != null && selection.size() > 0);
}