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:com.wdev91.eclipse.copyright.actions.ApplyCopyrightAction.java

License:Open Source License

protected IStructuredSelection getSelection() {
    if (selection == null) {
        selection = StructuredSelection.EMPTY;
    }
    return selection;
}

From source file:com.xse.optstack.persconftool.ui.resources.ResourcesTable.java

License:Open Source License

@Override
protected TableColumn[] getColumns() {
    final ComboBoxViewerCellEditor comboBoxViewerCellEditor = new ComboBoxViewerCellEditor(this.getTable(),
            SWT.READ_ONLY);//  www . j a va 2  s .com
    comboBoxViewerCellEditor.setContentProvider(new IStructuredContentProvider() {
        @Override
        public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(final Object inputElement) {
            final Object[] vals = new Object[EInstallException.values().length + 1];
            int i = 0;
            for (final EInstallException eInstallException : EInstallException.values()) {
                vals[i++] = eInstallException;
            }
            vals[i] = StructuredSelection.EMPTY;
            return vals;
        }
    });
    comboBoxViewerCellEditor.setLabelProvider(new AbstractBaseLabelProvider() {
        @Override
        public String getText(final Object element) {
            if (element instanceof EInstallException) {
                return ((EInstallException) element).getName();
            } else {
                return "";
            }
        }

        @Override
        public Image getImage(final Object element) {
            return null;
        }
    });
    comboBoxViewerCellEditor.setInput(new Object());

    final TableColumn installationRuleColumn = new TableColumn("Installation Exception", 140);
    installationRuleColumn.setEditingSupport(new EditingSupport(this.getViewer()) {
        @Override
        protected void setValue(final Object element, final Object value) {
            if (element instanceof EResource) {
                if (value instanceof EInstallException) {
                    ((EResource) element).setInstallException((EInstallException) value);
                } else {
                    ((EResource) element).setInstallException(null);
                }
                this.getViewer().refresh(element);
            }
        }

        @Override
        protected Object getValue(final Object element) {
            if (element instanceof EResource) {
                final EResource res = (EResource) element;
                if (res.getInstallException() != null) {
                    return res.getInstallException();
                } else {
                    return StructuredSelection.EMPTY;
                }
            }
            return null;
        }

        @Override
        protected CellEditor getCellEditor(final Object element) {
            return comboBoxViewerCellEditor;
        }

        @Override
        protected boolean canEdit(final Object element) {
            return element instanceof EResource;
        }
    });

    return new TableColumn[] { new TableColumn("Name", 180), installationRuleColumn };
}

From source file:com.yoursway.hello.debug.ui.internal.HelloDebugUIPlugin.java

License:Open Source License

public static IStructuredSelection getCurrentSelection() {
    IWorkbenchWindow window = getDefault().getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            IWorkbenchPart part = page.getActivePart();
            if (part instanceof IEditorPart) {
                return new StructuredSelection(part);
            } else if (part != null) {
                IWorkbenchSite site = part.getSite();
                if (site != null) {
                    ISelectionProvider provider = site.getSelectionProvider();
                    if (provider != null) {
                        ISelection selection = provider.getSelection();
                        if (selection instanceof IStructuredSelection) {
                            return (IStructuredSelection) provider.getSelection();
                        }/* w  w w  .  j a  v  a  2  s . c  o m*/
                    }
                }
            }
        }
    }
    return StructuredSelection.EMPTY;
}

From source file:company.ui.properties.CompanyLabelProvider.java

License:Open Source License

/**
 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
 *//*w ww .  j  ava  2s.c  o m*/
public Image getImage(Object element) {
    if (element == null || element.equals(StructuredSelection.EMPTY)) {
        return null;
    }
    if (element instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) element;
        if (areDifferentTypes(structuredSelection)) {
            return null;
        }
        element = structuredSelection.getFirstElement();
    }
    if (element instanceof EObject || element instanceof Resource) {
        return getAdapterFactoryLabelProvider().getImage(element);
    }
    return null;
}

From source file:company.ui.properties.CompanyLabelProvider.java

License:Open Source License

/**
 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
 *///from  ww w. j a va 2  s  .c  o  m
public String getText(Object element) {
    if (element == null || element.equals(StructuredSelection.EMPTY)) {
        return null;
    }
    int size = 1;
    if (element instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) element;
        if (areDifferentTypes(structuredSelection)) {
            return structuredSelection.size() + " items selected";//$NON-NLS-1$
        }
        element = structuredSelection.getFirstElement();
        size = structuredSelection.size();
    }
    if (element instanceof EObject) {
        String split[] = getAdapterFactoryLabelProvider().getText(element).split(" ");//$NON-NLS-1$
        StringBuffer type = new StringBuffer();
        StringBuffer name = new StringBuffer();
        for (int i = 0; i < split.length; i++) {
            if (i == 0) {
                type.append('\u00AB');
                type.append(split[i]);
                if (!(element instanceof Employee)) {
                    type.append('\u00BB');
                }
            } else if ((i == 1 && (element instanceof Employee))) {
                type.append(' ');
                type.append(split[i]);
                type.append('\u00BB');
            } else {
                name.append(split[i]);
                name.append(' ');
            }
        }
        if (size == 1) {
            type.append(' ');
            type.append(name);
        } else {
            type.append(' ');
            type.append(Integer.toString(size));
            type.append(" selected");//$NON-NLS-1$
        }
        return type.toString();
    } else if (element instanceof Resource) {
        return "\u00ABResource\u00BB";//$NON-NLS-1$
    }
    return null;
}

From source file:crosswalk.diagram.navigator.CrosswalkNavigatorLinkHelper.java

License:Apache License

/**
 * @generated/*from w  w w.j  a v  a  2s  .  co m*/
 */
public IStructuredSelection findSelection(IEditorInput anInput) {
    IDiagramDocument document = CrosswalkDiagramEditorPlugin.getInstance().getDocumentProvider()
            .getDiagramDocument(anInput);
    if (document == null) {
        return StructuredSelection.EMPTY;
    }
    Diagram diagram = document.getDiagram();
    if (diagram == null || diagram.eResource() == null) {
        return StructuredSelection.EMPTY;
    }
    IFile file = WorkspaceSynchronizer.getFile(diagram.eResource());
    if (file != null) {
        CrosswalkNavigatorItem item = new CrosswalkNavigatorItem(diagram, file, false);
        return new StructuredSelection(item);
    }
    return StructuredSelection.EMPTY;
}

From source file:crosswalk.diagram.part.CrosswalkDiagramEditor.java

License:Apache License

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

From source file:crosswalk.diagram.part.CrosswalkNewDiagramFileWizard.java

License:Apache License

/**
 * @generated/*  w  w  w.jav a  2s  .co  m*/
 */
public CrosswalkNewDiagramFileWizard(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.CrosswalkNewDiagramFileWizard_CreationPageName,
            StructuredSelection.EMPTY);
    myFileCreationPage.setTitle(Messages.CrosswalkNewDiagramFileWizard_CreationPageTitle);
    myFileCreationPage.setDescription(NLS.bind(Messages.CrosswalkNewDiagramFileWizard_CreationPageDescription,
            EditingContainerEditPart.MODEL_ID));
    IPath filePath;
    String fileName = URI.decode(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(CrosswalkDiagramEditorUtil.getUniqueFileName(filePath, fileName, "crosswalk")); //$NON-NLS-1$

    diagramRootElementSelectionPage = new DiagramRootElementSelectionPage(
            Messages.CrosswalkNewDiagramFileWizard_RootSelectionPageName);
    diagramRootElementSelectionPage.setTitle(Messages.CrosswalkNewDiagramFileWizard_RootSelectionPageTitle);
    diagramRootElementSelectionPage
            .setDescription(Messages.CrosswalkNewDiagramFileWizard_RootSelectionPageDescription);
    diagramRootElementSelectionPage.setModelElement(diagramRoot);

    myEditingDomain = editingDomain;
}

From source file:de.dfki.iui.mmds.core.graphiti.diagram.dialogue.navigator.EditorLinkHelper.java

License:Open Source License

/**
 * Return a selection that contains the file that the given editor input
 * represent. The {@link StructuredSelection} will be compared with nodes in
 * the tree. See also extension point// w ww . j a  v  a 2  s  . c  o  m
 * {@code "org.eclipse.ui.navigator.linkHelper"}.
 */
public IStructuredSelection findSelection(IEditorInput editorInput) {
    if (editorInput instanceof DiagramEditorInput) {
        if (editorInput.exists()) {
            DiagramEditorInput diagramEditorInput = (DiagramEditorInput) editorInput;
            final IFile file = getFile(diagramEditorInput.getUri());
            if (file != null) {
                return new StructuredSelection(file);
            }
        }

    }
    return StructuredSelection.EMPTY;
}

From source file:de.dfki.iui.mmds.sdk.editors.grammar_rules.RulesEditor.java

License:Creative Commons License

/**
 * This makes sure that one content viewer, either for the current page or
 * the outline view, if it has focus, is the current one. <!--
 * begin-user-doc --> <!-- end-user-doc -->
 * //www  .j  av a 2s  .  co m
 * @generated
 */
public void setCurrentViewer(Viewer viewer) {
    // If it is changing...
    //
    if (currentViewer != viewer) {
        if (selectionChangedListener == null) {
            // Create the listener on demand.
            //

            selectionChangedListener = new ISelectionChangedListener() {
                // This just notifies those things that are affected by the
                // section.
                //
                @Override
                public void selectionChanged(SelectionChangedEvent selectionChangedEvent) {
                    setSelection(selectionChangedEvent.getSelection());
                }
            };
        }

        // Stop listening to the old one.
        //
        if (currentViewer != null) {
            currentViewer.removeSelectionChangedListener(selectionChangedListener);
        }

        // Start listening to the new one.
        //
        if (viewer != null) {
            viewer.addSelectionChangedListener(selectionChangedListener);
        }

        // Remember it.
        //
        currentViewer = viewer;

        // Set the editors selection based on the current viewer's
        // selection.
        //

        setSelection(currentViewer == null ? StructuredSelection.EMPTY : currentViewer.getSelection());
    }
}