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:eu.geclipse.workflow.ui.wizards.WorkflowNewDiagramFileWizard.java

License:Open Source License

/**
 * @generated NOT//w w w. j  av  a2 s  .c om
 */
public WorkflowNewDiagramFileWizard(URI domainModelURI, EObject diagramRoot,
        TransactionalEditingDomain editingDomain) {
    assert domainModelURI != null : "Domain model uri must be specified"; //$NON-NLS-1$
    assert diagramRoot != null : "Diagram root element must be specified"; //$NON-NLS-1$
    assert editingDomain != null : "Editing domain must be specified"; //$NON-NLS-1$
    this.myFileCreationPage = new WizardNewFileCreationPage(
            Messages.getString("WorkflowNewDiagramFileWizard_CreationPageName"), //$NON-NLS-1$
            StructuredSelection.EMPTY);
    this.myFileCreationPage.setTitle(Messages.getString("WorkflowNewDiagramFileWizard_CreationPageTitle")); //$NON-NLS-1$
    this.myFileCreationPage
            .setDescription(NLS.bind(Messages.getString("WorkflowNewDiagramFileWizard_CreationPageDescription"), //$NON-NLS-1$
                    WorkflowEditPart.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$
    }
    this.myFileCreationPage.setContainerFullPath(filePath);
    this.myFileCreationPage
            .setFileName(WorkflowDiagramEditorUtil.getUniqueFileName(filePath, fileName, "workflow")); //$NON-NLS-1$
    this.diagramRootElementSelectionPage = new DiagramRootElementSelectionPage(
            Messages.getString("WorkflowNewDiagramFileWizard_RootSelectionPageName")); //$NON-NLS-1$
    this.diagramRootElementSelectionPage
            .setTitle(Messages.getString("WorkflowNewDiagramFileWizard_RootSelectionPageTitle")); //$NON-NLS-1$
    this.diagramRootElementSelectionPage
            .setDescription(Messages.getString("WorkflowNewDiagramFileWizard_RootSelectionPageDescription")); //$NON-NLS-1$
    this.diagramRootElementSelectionPage.setModelElement(diagramRoot);
    this.myEditingDomain = editingDomain;
}

From source file:eu.indenica.iret.diagram.navigator.IretNavigatorLinkHelper.java

License:Apache License

/**
 * @generated//w  ww .j av a 2 s. c  om
 */
public IStructuredSelection findSelection(IEditorInput anInput) {
    IDiagramDocument document = IretDiagramEditorPlugin.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) {
        IretNavigatorItem item = new IretNavigatorItem(diagram, file, false);
        return new StructuredSelection(item);
    }
    return StructuredSelection.EMPTY;
}

From source file:eu.indenica.iret.diagram.part.IretDiagramEditor.java

License:Apache License

/**
 * @generated/* w w  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) {
        IretNavigatorItem item = new IretNavigatorItem(diagram, file, false);
        return new StructuredSelection(item);
    }
    return StructuredSelection.EMPTY;
}

From source file:eu.indenica.iret.diagram.part.IretNewDiagramFileWizard.java

License:Apache License

/**
 * @generated//  w w w .j  a  v a2  s .c  o m
 */
public IretNewDiagramFileWizard(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.IretNewDiagramFileWizard_CreationPageName,
            StructuredSelection.EMPTY);
    myFileCreationPage.setTitle(Messages.IretNewDiagramFileWizard_CreationPageTitle);
    myFileCreationPage.setDescription(
            NLS.bind(Messages.IretNewDiagramFileWizard_CreationPageDescription, GoalDiagramEditPart.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(IretDiagramEditorUtil.getUniqueFileName(filePath, fileName, "iret_diagram")); //$NON-NLS-1$

    diagramRootElementSelectionPage = new DiagramRootElementSelectionPage(
            Messages.IretNewDiagramFileWizard_RootSelectionPageName);
    diagramRootElementSelectionPage.setTitle(Messages.IretNewDiagramFileWizard_RootSelectionPageTitle);
    diagramRootElementSelectionPage
            .setDescription(Messages.IretNewDiagramFileWizard_RootSelectionPageDescription);
    diagramRootElementSelectionPage.setModelElement(diagramRoot);

    myEditingDomain = editingDomain;
}

From source file:eu.numberfour.n4js.ui.handler.CreateNewN4JSElementInModuleHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    String wizardId = event.getParameter(WIZARD_ID_PARAMETER_ID);

    if (wizardId == null) {
        return null;
    }/*from ww  w .  ja va 2  s .  c o m*/

    boolean isNested = Boolean.parseBoolean(event.getParameter(NESTED_PARAMETER_ID));

    IStructuredSelection selection;

    // Try to get editor file
    IFile editorFile = getActiveEditorFile();

    if (null != editorFile) {
        selection = new StructuredSelection(editorFile);
    } else {
        // Try to get the selection from the project explorer tree view
        IResource resourceTreeFile = getActiveTreeResourceSelection(event);
        if (null != resourceTreeFile) {
            // If it's a tree selection set nested to false
            isNested = false;
            selection = new StructuredSelection(resourceTreeFile);
        } else {
            // If not selection can be retrieved, launch the wizard with an empty selection
            selection = StructuredSelection.EMPTY;
        }
    }

    openWizardForModule(wizardId, selection, isNested);

    return null;
}

From source file:ext.org.eclipse.jdt.internal.ui.browsing.JavaBrowsingPart.java

License:Open Source License

public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    if (!needsToProcessSelectionChanged(part))
        return;/*from   w  w  w.  j a  v  a2s .c o m*/

    if (fToggleLinkingAction.isChecked() && (part instanceof IEditorPart)) {
        setSelectionFromEditor(part, selection);
        return;
    }

    // Set selection
    Object selectedElement = getSingleElementFromSelection(selection);

    if (selectedElement != null && (part == null || part.equals(fPreviousSelectionProvider))
            && selectedElement.equals(fPreviousSelectedElement))
        return;

    fPreviousSelectedElement = selectedElement;

    Object currentInput = getViewer().getInput();
    if (selectedElement != null && selectedElement.equals(currentInput)) {
        IJavaElement elementToSelect = findElementToSelect(selectedElement);
        if (elementToSelect != null
                && getTypeComparator().compare((IJavaElement) selectedElement, elementToSelect) < 0)
            setSelection(new StructuredSelection(elementToSelect), true);
        else if (elementToSelect == null && (this instanceof MembersView)) {
            setSelection(StructuredSelection.EMPTY, true);
            fPreviousSelectedElement = StructuredSelection.EMPTY;
        }
        fPreviousSelectionProvider = part;
        return;
    }

    // Clear input if needed
    if (part != fPreviousSelectionProvider && selectedElement != null && !selectedElement.equals(currentInput)
            && isInputResetBy(selectedElement, currentInput, part)) {
        if (!isAncestorOf(selectedElement, currentInput))
            setInput(null);
        fPreviousSelectionProvider = part;
        return;
    } else if (selection != null && selection.isEmpty() && !isInputResetBy(part)) {
        fPreviousSelectionProvider = part;
        return;
    } else if (selectedElement == null && part == fPreviousSelectionProvider) {
        setInput(null);
        fPreviousSelectionProvider = part;
        return;
    }
    fPreviousSelectionProvider = part;

    // Adjust input and set selection and
    adjustInputAndSetSelection(selectedElement);
}

From source file:ext.org.eclipse.jdt.internal.ui.browsing.JavaBrowsingPart.java

License:Open Source License

void adjustInputAndSetSelection(Object o) {
    if (!(o instanceof IJavaElement)) {
        if (o == null)
            setInput(null);/*from   w  ww. jav a 2s. c o m*/
        setSelection(StructuredSelection.EMPTY, true);
        return;
    }

    IJavaElement je = (IJavaElement) o;
    IJavaElement elementToSelect = findElementToSelect(je);
    IJavaElement newInput = findInputForJavaElement(je);
    IJavaElement oldInput = null;
    if (getInput() instanceof IJavaElement)
        oldInput = (IJavaElement) getInput();

    if (elementToSelect == null && !isValidInput(newInput) && (newInput == null && !isAncestorOf(je, oldInput)))
        // Clear input
        setInput(null);
    else if (mustSetNewInput(elementToSelect, oldInput, newInput)) {
        // Adjust input to selection
        setInput(newInput);
    }

    if (elementToSelect != null && elementToSelect.exists())
        setSelection(new StructuredSelection(elementToSelect), true);
    else
        setSelection(StructuredSelection.EMPTY, true);
}

From source file:ext.org.eclipse.jdt.internal.ui.browsing.PackageViewerWrapper.java

License:Open Source License

@Override
public void setSelection(ISelection selection, boolean reveal) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection sel = (IStructuredSelection) selection;

        //try and give the two a common super class
        IContentProvider provider = getContentProvider();
        if (provider instanceof LogicalPackagesProvider) {
            LogicalPackagesProvider fprovider = (LogicalPackagesProvider) provider;

            Object object = sel.getFirstElement();
            if (object instanceof IPackageFragment) {
                IPackageFragment pkgFragment = (IPackageFragment) object;
                LogicalPackage logicalPkg = fprovider.findLogicalPackage(pkgFragment);
                if (logicalPkg != null)
                    object = logicalPkg;
                else
                    object = pkgFragment;
            }//from w w  w.  j ava 2  s. c  o m
            if (object != null)
                fViewer.setSelection(new StructuredSelection(object), reveal);
            else
                fViewer.setSelection(StructuredSelection.EMPTY, reveal);
        }
    } else
        fViewer.setSelection(selection, reveal);
}

From source file:ext.org.eclipse.jdt.internal.ui.callhierarchy.CallHierarchyUI.java

License:Open Source License

/**
 * Converts an ISelection (containing MethodWrapper instances) to an ISelection
 * with the MethodWrapper's replaced by their corresponding IMembers. If the selection
 * contains elements which are not MethodWrapper instances or not already IMember instances
 * they are discarded./*  w  w  w . j  av a2 s .c o  m*/
 * @param selection The selection to convert.
 * @return An ISelection containing IMember's in place of MethodWrapper instances.
 */
static ISelection convertSelection(ISelection selection) {
    if (selection.isEmpty()) {
        return selection;
    }

    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        List<IMember> javaElements = new ArrayList<IMember>();
        for (Iterator<?> iter = structuredSelection.iterator(); iter.hasNext();) {
            Object element = iter.next();
            if (element instanceof MethodWrapper) {
                IMember member = ((MethodWrapper) element).getMember();
                if (member != null) {
                    javaElements.add(member);
                }
            } else if (element instanceof IMember) {
                javaElements.add((IMember) element);
            } else if (element instanceof CallLocation) {
                IMember member = ((CallLocation) element).getMember();
                javaElements.add(member);
            }
        }
        return new StructuredSelection(javaElements);
    }
    return StructuredSelection.EMPTY;
}

From source file:ext.org.eclipse.jdt.internal.ui.callhierarchy.CallHierarchyViewPart.java

License:Open Source License

/**
 * Returns the current selection./*from  w  w  w .  j  a  v a 2 s  .com*/
 * @return selection
 */
protected ISelection getSelection() {
    StructuredViewer viewerInFocus = fSelectionProviderMediator.getViewerInFocus();
    if (viewerInFocus != null) {
        return viewerInFocus.getSelection();
    }
    return StructuredSelection.EMPTY;
}