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:net.timedoctor.ui.trace.MainViewer.java

License:Open Source License

public ISelection getSelection() {
    if (currentSelectedLine == null) {
        return StructuredSelection.EMPTY;
    }//from ww w  .  ja  v  a  2s  .co  m

    return new StructuredSelection(currentSelectedLine);
}

From source file:net.yatomiya.e4.ui.internal.workbench.renderers.swt.AbstractTableInformationControl.java

License:Open Source License

/**
 * Selects the first element in the table which matches the current filter
 * pattern./*from   w  w  w.  ja  va 2  s. com*/
 */
protected void selectFirstMatch() {
    Table table = fTableViewer.getTable();
    Object element = findElement(table.getItems());
    if (element != null) {
        fTableViewer.setSelection(new StructuredSelection(element), true);
    } else {
        fTableViewer.setSelection(StructuredSelection.EMPTY);
    }
}

From source file:net.yatomiya.e4.ui.util.PostSelectionProvider.java

License:Open Source License

public PostSelectionProvider() {
    listenerList = new ArrayList<ISelectionChangedListener>();
    postListenerList = new ArrayList<ISelectionChangedListener>();
    selection = StructuredSelection.EMPTY;
}

From source file:net.yatomiya.nicherry.ui.bbs.UIBBSUtils.java

License:Open Source License

public static ISelection partIdToSelection(MPart mPart) {
    BBSModelId id = toModelId(mPart);//from  w  ww.ja v a2  s.  c om
    if (id != null)
        return new StructuredSelection(id);
    else
        return StructuredSelection.EMPTY;
}

From source file:net.zehrer.no2.editor.TabelEditorPage.java

License:Open Source License

/**
 * @category ISelectionProvider/*from ww  w.  j a v a  2s.  c  o  m*/
 */
public ISelection getSelection() {
    if (tableViewer == null) {
        return StructuredSelection.EMPTY;
    }
    return tableViewer.getSelection();
}

From source file:nexcore.tool.uml.ui.core.navigator.LinkHelper.java

License:Open Source License

/**
 * @see org.eclipse.ui.navigator.ILinkHelper#findSelection(org.eclipse.ui.IEditorInput)
 *///from   w w  w . j a v a  2s  .c om
@Override
public IStructuredSelection findSelection(IEditorInput anInput) {

    if (anInput instanceof DiagramEditorInput) {

        DiagramEditorInput editorInput = (DiagramEditorInput) anInput;
        EObject eobject = editorInput.getDiagram();

        ITreeNode node = UMLTreeNodeRegistry.getTreeNode(eobject);

        if (null != node) {
            return new StructuredSelection(node);
        }

    } else if (anInput instanceof UMLEditorInput) {

        UMLEditorInput editorInput = (UMLEditorInput) anInput;
        EObject eobject = editorInput.getElement();

        ITreeNode node = UMLTreeNodeRegistry.getTreeNode(eobject);

        if (null != node) {
            return new StructuredSelection(node);
        }
    }

    return StructuredSelection.EMPTY;
}

From source file:no.resheim.elibrarium.epub.ui.reader.TOCOutlinePage.java

License:Open Source License

public ISelection getSelection() {
    if (toc == null) {
        return StructuredSelection.EMPTY;
    }
    return toc.getSelection();
}

From source file:org.activiti.designer.eclipse.property.PropertiesLabelProvider.java

License:Open Source License

/**
 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
 *///from   w w  w . j av  a  2 s  .co m
@Override
public Image getImage(Object objects) {

    if (objects == null || objects.equals(StructuredSelection.EMPTY)) {
        return null;
    }
    final boolean multiple[] = { false };
    Object object = getObject(objects, multiple);
    if (object == null) {
        return null;
    } else {
        if (!(object instanceof EditPart)) {
            return null;
        }
    }
    return null;
}

From source file:org.activiti.designer.eclipse.property.PropertiesLabelProvider.java

License:Open Source License

/**
 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
 *///from w w  w .java2  s.c o  m
@Override
public String getText(Object objects) {
    if (objects == null || objects.equals(StructuredSelection.EMPTY)) {
        return "No items selected";//$NON-NLS-1$
    }
    final boolean multiple[] = { false };
    Object object = getObject(objects, multiple);
    if (object == null || ((IStructuredSelection) objects).size() > 1) {
        return ((IStructuredSelection) objects).size() + " items selected";//$NON-NLS-1$
    } else {
        if (object instanceof EditPart) {
            object = ((EditPart) object).getModel();
        }
        if (object instanceof EObject) {
            EObject robj = (EObject) object;
            if (robj instanceof PictogramElement) {
                PictogramElement pe = (PictogramElement) robj;
                EObject businessObject = Graphiti.getLinkService()
                        .getBusinessObjectForLinkedPictogramElement(pe);
                if (businessObject == null) {
                    businessObject = robj;
                }

                // return the name of the MetamodelClass
                EObject refMetaObject = businessObject.eClass();
                if (refMetaObject instanceof ENamedElement) {
                    return ((ENamedElement) refMetaObject).getName();
                }
                return ""; // no luck //$NON-NLS-1$
            } else {
                return "" + ((EModelElement) robj.eClass()).getClass().getName(); //$NON-NLS-1$
            }
        } else {
            return object.toString();
        }
    }
}

From source file:org.adorsys.plh.pkix.workbench.menu.ContextMenuView.java

License:Open Source License

@PostConstruct
public void init() {
    for (int i = 1; i < 5; i++) {
        createEntry(i);/*w  ww.j a  v  a2  s .  c o m*/
    }

    items.setContentProvider(new ViewContentProvider());
    items.setLabelProvider(new EntryLabelProvider());
    items.setInput(itemModel);
    items.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            selectionService.setSelection(selection);
            if (selection instanceof IStructuredSelection) {
                Entry e = (Entry) ((IStructuredSelection) selection).getFirstElement();
                String text = textMap.get(e);
                info.setText(text == null ? "" : text);
                ArrayList<Tag> list = tagMap.get(e);
                tagList.setInput(list == null ? Collections.EMPTY_LIST : list);
            }
        }
    });

    items.getTree().setLinesVisible(true);
    items.getTree().setHeaderVisible(true);
    items.getTree().layout(true);
    menuService.registerContextMenu(items.getControl(), ITEMS_MENU);

    itemCopyHandler = new CopyHandler(items.getTree().getDisplay(), items);
    items.getTree().addListener(SWT.Activate, new Listener() {
        public void handleEvent(Event event) {
            handlerService.activateHandler("org.eclipse.ui.edit.copy", itemCopyHandler);
        }
    });

    tagList.setContentProvider(new ArrayContentProvider());
    tagList.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof Tag) {
                return ((Tag) element).name;
            }
            return null;
        }
    });
    final MPopupMenu tagPopupMenu = menuService.registerContextMenu(tagList.getControl(), TAGS_MENU);
    tagList.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            ESelectionService srv = tagPopupMenu.getContext().get(ESelectionService.class);
            srv.setSelection(selection);
        }
    });

    tagCopyHandler = new CopyHandler(tagList.getControl().getDisplay(), tagList);
    tagList.getControl().addListener(SWT.Activate, new Listener() {
        public void handleEvent(Event event) {
            handlerService.activateHandler("org.eclipse.ui.edit.copy", tagCopyHandler);
        }
    });

    // with no handler, CTRL+C works because it delegates
    // to the native widget.  But the menu item copy
    // doesn't, since it will not be handled.
    // This will work as a real handler for both situations.
    infoCopyHandler = new Object() {
        @CanExecute
        public boolean canExecute() {
            return info.getSelectionCount() > 0;
        }

        @Execute
        public void execute() {
            info.copy();
        }
    };

    info.addListener(SWT.Activate, new Listener() {
        public void handleEvent(Event event) {
            // just remove 'em both for simplicity
            handlerService.deactivateHandler("org.eclipse.ui.edit.copy", itemCopyHandler);
            handlerService.deactivateHandler("org.eclipse.ui.edit.copy", tagCopyHandler);
            handlerService.activateHandler("org.eclipse.ui.edit.copy", infoCopyHandler);
        }
    });
    final MPopupMenu infoPopupMenu = menuService.registerContextMenu(info, INFO_MENU);
    // we can either publish the Text selection as a
    // org.eclipse.jface.text.TextSelection or set it to an empty selection.
    // I picked empty.
    ESelectionService srv = infoPopupMenu.getContext().get(ESelectionService.class);
    srv.setSelection(StructuredSelection.EMPTY);
}