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

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

Introduction

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

Prototype

StructuredSelection EMPTY

To view the source code for org.eclipse.jface.viewers StructuredSelection EMPTY.

Click Source Link

Document

The canonical empty selection.

Usage

From source file:es.cv.gvcase.fefem.common.composites.EMFContainedCollectionEditionComposite.java

License:Open Source License

/**
 * Creates the a SelectionListener which will invoke the code to remove/delete
 * a selected element from the tree viewer.
 *     //  w w w  .jav  a2  s. c o m
 * @return SelectionListener the {@link SelectionListener} which will
 * remove/delete a selected element from the viewer.
 */
protected SelectionListener getRemoveButtonSelectionListener() {
    SelectionAdapter adapter = new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            TableViewer viewer = getViewer();
            if (viewer.getSelection() instanceof StructuredSelection) {
                StructuredSelection selection = (StructuredSelection) getViewer().getSelection();
                List<?> elementsToDelete = selection.toList();
                if (elementsToDelete.size() > 0) {
                    // We prepare the next selection, based on the element to delete
                    EObject eObject = (EObject) elementsToDelete.get(0);
                    StructuredSelection nextSelection = StructuredSelection.EMPTY;
                    if (modelObservable.size() > 1) { // If we have more than one element
                        int pos = modelObservable.indexOf(eObject);
                        nextSelection = (pos == modelObservable.size() - 1) // If it's the last first level element, we will select the previous sibling
                                ? new StructuredSelection(modelObservable.get(pos - 1))
                                : new StructuredSelection(modelObservable.get(pos + 1)); // otherwise, we will select the next one
                    }

                    EStructuralFeature feature = getFeature();
                    if (feature instanceof EReference // If it's a containment reference we delete the elements from the model
                            && ((EReference) feature).isContainment()) {
                        getEditingDomain().getCommandStack()
                                .execute(DeleteCommand.create(getEditingDomain(), elementsToDelete));
                    } else { // otherwise, we just remove the elements from the obsevableList
                        modelObservable.removeAll(elementsToDelete);
                    }

                    getPage().setDirty(true);
                    getViewer().setSelection(nextSelection);
                }
            }
        }
    };
    return adapter;
}

From source file:es.cv.gvcase.ide.navigator.actions.resource.EditingDomainActions.java

License:Open Source License

/**
 * Update./*  w  w w  .jav a 2  s.com*/
 */
public void update() {
    ISelection selection = null;
    try {
        if (getCommonNavigator() != null && getCommonNavigator().getCommonViewer() != null) {
            selection = getCommonNavigator().getCommonViewer().getSelection();
        }
    } catch (NullPointerException ex) {
        selection = null;
    }
    IStructuredSelection structuredSelection = selection instanceof IStructuredSelection
            ? (IStructuredSelection) selection
            : StructuredSelection.EMPTY;

    if (structuredSelection.isEmpty()) {
        return;
    }

    if (deleteAction != null) {
        deleteAction.updateSelection(structuredSelection);
    }
    if (cutAction != null) {
        cutAction.updateSelection(structuredSelection);
    }
    if (copyAction != null) {
        copyAction.updateSelection(structuredSelection);
    }
    if (pasteAction != null) {
        pasteAction.updateSelection(structuredSelection);
    }
    if (validateAction != null) {
        validateAction.updateSelection(structuredSelection);
    }
    if (controlAction != null) {
        controlAction.updateSelection(structuredSelection);
    }
    if (undoAction != null) {
        undoAction.update();
    }
    if (redoAction != null) {
        redoAction.update();
    }
    if (loadResourceAction != null) {
        loadResourceAction.update();
    }
}

From source file:es.cv.gvcase.mdt.common.sections.PropertySheetUtils.java

License:Open Source License

/**
 * This method provides a simple way to refresh all the selected Tab,
 * refreshing all the sections contained in this Tab.
 * /*from  w w w.  j av a  2 s  .c  o m*/
 * As the sections couldn't refresh the parent Tab directly or refresh the
 * sibling Sections, the only way to do that is by simulating a deselect and
 * select the current element in the current working editor
 * 
 * @param section
 * @param eObject
 */
public static void refreshTab(AbstractPropertySection section, EObject eObject) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

    if (window == null) {
        return;
    }
    IWorkbenchPage page = window.getActivePage();

    if (page == null) {
        return;
    }
    IViewPart view = page.findView("org.eclipse.ui.views.PropertySheet");

    if (view == null) {
        return;
    }

    if (!(view instanceof PropertySheet)) {
        return;
    }
    IPage ipage = ((PropertySheet) view).getCurrentPage();

    if (!(ipage instanceof TabbedPropertySheetPage)) {
        return;
    }
    IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();

    // if there are any view maximized, get the editor by comparing the
    // current eObject with the contained elements of the diagram element
    if (editor == null) {
        IEditorReference[] editors = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                .getEditorReferences();
        if (editors.length > 0) {
            first: for (int i = 0; i < editors.length; i++) {
                if (!(editors[i].getEditor(true) instanceof MOSKittMultiPageEditor)) {
                    continue;
                }

                MOSKittMultiPageEditor moskittEditor = (MOSKittMultiPageEditor) editors[i].getEditor(true);
                EObject eo = moskittEditor.getDiagram().getElement();
                if (eo.equals(eObject)) {
                    editor = moskittEditor;
                    break first;
                }

                for (TreeIterator<EObject> it = eo.eAllContents(); it.hasNext();) {
                    eo = it.next();
                    if (eo.equals(eObject)) {
                        editor = moskittEditor;
                        break first;
                    }
                }
            }
        }
    }

    if (editor == null) {
        return;
    }
    ((TabbedPropertySheetPage) ipage).selectionChanged(editor, StructuredSelection.EMPTY);
    ((TabbedPropertySheetPage) ipage).selectionChanged(editor, section.getSelection());
}

From source file:es.cv.gvcase.mdt.common.util.MDTUtil.java

License:Open Source License

public static ISelection getSelectionFromActiveEditor() {
    IEditorPart editor = getActiveEditor();
    if (editor instanceof IDiagramWorkbenchPart) {
        return ((IDiagramWorkbenchPart) editor).getDiagramGraphicalViewer().getSelection();
    }/*from   w w w . j  av a  2s  .  c o m*/
    return StructuredSelection.EMPTY;
}

From source file:es.cv.gvcase.mdt.db.diagram.navigator.SqlmodelNavigatorLinkHelper.java

License:Open Source License

/**
 * @generated//from w w w. j av a  2s . com
 */
public IStructuredSelection findSelection(IEditorInput anInput) {

    IDiagramDocument document = SqlmodelDiagramEditorPlugin.getInstance()
            .getDocumentProvider(getEditingDomainID(), anInput).getDiagramDocument(anInput);
    if (document == null) {
        return StructuredSelection.EMPTY;
    }
    Diagram diagram = document.getDiagram();
    IFile file = WorkspaceSynchronizer.getFile(diagram.eResource());
    if (file != null) {
        SqlmodelNavigatorItem item = new SqlmodelNavigatorItem(diagram, file, false);
        return new StructuredSelection(item);
    }
    return StructuredSelection.EMPTY;
}

From source file:es.cv.gvcase.mdt.db.diagram.part.SqlmodelDiagramEditor.java

License:Open Source License

/**
 * @generated/* ww w  .ja va  2  s  . co  m*/
 */
private ISelection getNavigatorSelection() {
    IDiagramDocument document = getDiagramDocument();
    if (document == null) {
        return StructuredSelection.EMPTY;
    }
    Diagram diagram = document.getDiagram();
    IFile file = WorkspaceSynchronizer.getFile(diagram.eResource());
    if (file != null) {
        SqlmodelNavigatorItem item = new SqlmodelNavigatorItem(diagram, file, false);
        return new StructuredSelection(item);
    }
    return StructuredSelection.EMPTY;
}

From source file:es.cv.gvcase.mdt.db.diagram.part.SqlmodelNewDiagramFileWizard.java

License:Open Source License

/**
 * @generated NOT/* w w  w .  j  ava 2s  .  c  o m*/
 */
public SqlmodelNewDiagramFileWizard(String actionId, URI domainModelURI, EObject diagramRoot,
        TransactionalEditingDomain editingDomain) {
    assert domainModelURI != null : "Domain model uri must be specified"; //$NON-NLS-1$
    assert diagramRoot != null : "Doagram root element must be specified"; //$NON-NLS-1$
    assert editingDomain != null : "Editing domain must be specified"; //$NON-NLS-1$

    myFileCreationPage = new WizardNewFileCreationPage(Messages.SqlmodelNewDiagramFileWizard_CreationPageName,
            StructuredSelection.EMPTY);
    myFileCreationPage.setTitle(Messages.SqlmodelNewDiagramFileWizard_CreationPageTitle);
    myFileCreationPage.setDescription(
            NLS.bind(Messages.SqlmodelNewDiagramFileWizard_CreationPageDescription, SchemaEditPart.MODEL_ID));
    IPath filePath;
    String fileName = domainModelURI.trimFileExtension().lastSegment();
    if (domainModelURI.isPlatformResource()) {
        filePath = new Path(domainModelURI.trimSegments(1).toPlatformString(true));
    } else if (domainModelURI.isFile()) {
        filePath = new Path(domainModelURI.trimSegments(1).toFileString());
    } else {
        // TODO : use some default path
        throw new IllegalArgumentException("Unsupported URI: " + domainModelURI); //$NON-NLS-1$
    }
    myFileCreationPage.setContainerFullPath(filePath);
    myFileCreationPage
            .setFileName(SqlmodelDiagramEditorUtil.getUniqueFileName(filePath, fileName, "sqlschema_diagram")); //$NON-NLS-1$

    modelElementSelectionPage = new ModelElementSelectionPage(
            Messages.SqlmodelNewDiagramFileWizard_RootSelectionPageName);
    modelElementSelectionPage.setTitle(Messages.SqlmodelNewDiagramFileWizard_RootSelectionPageTitle);
    modelElementSelectionPage
            .setDescription(Messages.SqlmodelNewDiagramFileWizard_RootSelectionPageDescription);
    modelElementSelectionPage.setModelElement(diagramRoot);

    if (actionId.equals("es.cv.gvcase.mdt.db.diagram.CustomizeDiagramAction")) {
        diagramElementsSelectionPage = new SqlDiagramElementsSelectionPage("Select model elements for diagram",
                "Model objects", "Select model objects that must appear in the diagram");
    } else {
        // fjcano :: adding a page to select which elements are to appear in
        // the new diagram
        IBaseLabelProvider labelProvider = new AdapterFactoryLabelProvider(
                new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE));
        IContentProvider contentProvider = new AdapterFactoryContentProvider(
                new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE));
        diagramElementsSelectionPage = new SelectModelElementsForDiagramDialog(contentProvider, labelProvider);
    }

    myEditingDomain = editingDomain;
}

From source file:es.uah.aut.srg.micobs.library.ui.MICOBSLibraryEditorActionBarContributor.java

License:Open Source License

public void update() {
    ISelectionProvider selectionProvider = activeEditor instanceof ISelectionProvider
            ? (ISelectionProvider) activeEditor
            : activeEditor.getEditorSite().getSelectionProvider();

    if (selectionProvider != null) {
        ISelection selection = selectionProvider.getSelection();
        IStructuredSelection structuredSelection = selection instanceof IStructuredSelection
                ? (IStructuredSelection) selection
                : StructuredSelection.EMPTY;

        deletePackageElementAction.updateSelection(structuredSelection);
        addPackageAction.updateSelection(structuredSelection);
        validateAction.updateSelection(structuredSelection);
    }//  ww w .  j  a v a  2  s .  c  om

    undoAction.update();
    redoAction.update();

}

From source file:etomica.plugin.editors.eclipse.EtomicaPropertyViewer.java

License:Open Source License

/**
 * The <code>PropertySheetViewer</code> implementation of this
 * <code>ISelectionProvider</code> method returns the result as a
 * <code>StructuredSelection</code>.
 * <p>//w w w.  j a  va2  s  .  com
 * Note that this method only includes <code>IPropertySheetEntry</code> in
 * the selection (no categories).
 * </p>
 */
public ISelection getSelection() {
    if (tree.getSelectionCount() == 0)
        return StructuredSelection.EMPTY;
    TreeItem[] sel = tree.getSelection();
    List entries = new ArrayList(sel.length);
    for (int i = 0; i < sel.length; i++) {
        TreeItem ti = sel[i];
        Object data = ti.getData();
        if (data instanceof IPropertySheetEntry)
            entries.add(data);
    }
    return new StructuredSelection(entries);
}

From source file:eu.aniketos.wp1.ststool.diagram.custom.handlers.NewSTSDiagramHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);

    StsToolCreationWizard wizard = new StsToolCreationWizard();
    wizard.init(window.getWorkbench(), StructuredSelection.EMPTY);
    WizardDialog wizardDialog = new WizardDialog(window.getShell(), wizard);
    wizardDialog.open();/*ww  w. j  a v  a2  s .c o  m*/
    return null;
}