Example usage for org.eclipse.jface.viewers IStructuredSelection isEmpty

List of usage examples for org.eclipse.jface.viewers IStructuredSelection isEmpty

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection isEmpty.

Prototype

public boolean isEmpty();

Source Link

Document

Returns whether this selection is empty.

Usage

From source file:com.nokia.tools.vct.confml.editor.view.ViewsEditor.java

License:Open Source License

private void createViewTreeViewer(Composite parent) {
    viewTv = new ViewTreeViewer(parent, SWT.MULTI | SWT.BORDER);
    viewTv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    viewTv.setContentProvider(new ViewTreeViewerContentProvider());
    ViewTreeViewerLabelProvider labelProvider = new ViewTreeViewerLabelProvider();
    labelProvider.setViewer(viewTv);/*from w  ww.j  a  va 2s  .  com*/
    viewTv.setLabelProvider(new DecoratingLabelProvider(labelProvider,
            PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));

    viewTv.setAutoExpandLevel(2);
    viewTv.getTree().addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            switch (e.keyCode) {
            case SWT.DEL:
                // do not use action here...

                IStructuredSelection selection = (IStructuredSelection) viewTv.getSelection();
                if (selection.isEmpty()) {
                    return;
                }
                Object[] selected = selection.toArray();

                List<EObject> list = new ArrayList<EObject>();
                for (Object o : selected) {
                    if (isFromRootView((EObject) o) && (o instanceof EGroup || o instanceof ESettingRef)) {
                        list.add((EObject) o);
                    } else if (isViewUnderRoot((EObject) o) && o instanceof EView) {
                        list.add((EObject) o);
                    }
                }
                if (!list.isEmpty()) {
                    DeleteCommand dc = new DeleteCommand(ViewsEditor.this, list);
                    getCommandStack().execute(dc);
                }

                break;
            default:
                break;
            }
        }
    });

    viewTv.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            ISelection selection = event.getSelection();
            if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
                return;
            }

            Object selected = ((IStructuredSelection) selection).getFirstElement();
            if (selected == null) {
                return;
            }
            if (selected instanceof ESettingRef) {
                selected = ((ESettingRef) selected).getTarget();
            }
            if (selected instanceof EResourceLocator) {
                // URI uri = ((EResourceLocator) selected).getResourceUri();
                // EConfMLResource res =
                // EditorUtils.getConfMLResource((EObject)selected);
                // EditorUtils.openEditor(uri, null);
            } else {
                return;
            }
        }
    });

}

From source file:com.nokia.trace.eventview.TraceEventView.java

License:Open Source License

/**
 * Adds menu listener to popup menu/*from  w ww  .ja  v  a2  s  .  c om*/
 */
private void hookContextMenu() {

    // Create menumanager
    MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown(true);

    // Create the menu when event is received
    menuMgr.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            IStructuredSelection selection = (IStructuredSelection) table.getSelection();
            if (!selection.isEmpty()) {
                EventListEntry entry = (EventListEntry) selection.getFirstElement();
                removeEventAction.setEntry(entry);
                manager.add(removeAllEventsAction);
                manager.add(removeEventAction);
                if (entry.hasSourceActions()) {
                    manager.add(new Separator());
                    entry.addSourceActions(manager);
                }
                manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
            }
        }
    });

    // Set the menu in to the table
    Menu menu = menuMgr.createContextMenu(table.getControl());
    table.getControl().setMenu(menu);
    getSite().registerContextMenu(menuMgr, table);
}

From source file:com.nokia.tracebuilder.eventhandler.EventListSelectionListener.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    if (!selection.isEmpty()) {
        EventListEntry entry = (EventListEntry) selection.getFirstElement();
        if (entry instanceof EventListEntryTraceObject) {
            TraceBuilderGlobals.getTraceBuilder()
                    .traceObjectSelected(((EventListEntryTraceObject) entry).getObject(), true, false);
        } else if (entry instanceof EventListEntryTraceLocation) {
            TraceLocation location = ((EventListEntryTraceLocation) entry).getTraceLocation();
            if (!location.isDeleted()) {
                TraceBuilderGlobals.getTraceBuilder().locationSelected(location.getLocationList(), location,
                        true);/*from   ww  w.  jav a  2s  .c  o m*/
            }
        } else if (entry instanceof EventListEntrySourceLocation) {
            SourceLocation location = ((EventListEntrySourceLocation) entry).getLocation();
            location.selectFromSource();
        }
    }
}

From source file:com.osp.ide.internal.ui.wizards.classwizard.NewClassWizardUtil.java

License:Open Source License

/**
 * Returns the C Element which corresponds to the given selection.
 * //  www  .j a va  2  s.  c om
 * @param selection the selection to be inspected
 * @return a C element matching the selection, or <code>null</code>
 * if no C element exists in the given selection
 */
public static ICElement getCElementFromSelection(IStructuredSelection selection) {
    ICElement celem = null;
    if (selection != null && !selection.isEmpty()) {
        Object selectedElement = selection.getFirstElement();
        if (selectedElement instanceof IAdaptable) {
            IAdaptable adaptable = (IAdaptable) selectedElement;

            celem = (ICElement) adaptable.getAdapter(ICElement.class);
            if (celem == null) {
                IResource resource = (IResource) adaptable.getAdapter(IResource.class);
                if (resource != null && resource.getType() != IResource.ROOT) {
                    while (celem == null && resource.getType() != IResource.PROJECT) {
                        celem = (ICElement) resource.getAdapter(ICElement.class);
                        resource = resource.getParent();
                    }
                    if (celem == null) {
                        celem = CoreModel.getDefault().create(resource); // c project
                    }
                }
            }
        }
    }
    return celem;
}

From source file:com.osp.ide.internal.ui.wizards.filewizard.AbstractFileCreationWizardPage.java

License:Open Source License

/**
 * Utility method to inspect a selection to find a C element. 
 * /*from w ww . ja v a2 s.  com*/
 * @param selection the selection to be inspected
 * @return a C element to be used as the initial selection, or <code>null</code>,
 * if no C element exists in the given selection
 */
protected ICElement getInitialCElement(IStructuredSelection selection) {
    ICElement celem = null;
    if (selection != null && !selection.isEmpty()) {
        Object selectedElement = selection.getFirstElement();
        if (selectedElement instanceof IAdaptable) {
            IAdaptable adaptable = (IAdaptable) selectedElement;

            celem = (ICElement) adaptable.getAdapter(ICElement.class);
            if (celem == null) {
                IResource resource = (IResource) adaptable.getAdapter(IResource.class);
                if (resource != null && resource.getType() != IResource.ROOT) {
                    while (celem == null && resource.getType() != IResource.PROJECT) {
                        celem = (ICElement) resource.getAdapter(ICElement.class);
                        resource = resource.getParent();
                    }
                    if (celem == null) {
                        celem = CoreModel.getDefault().create(resource); // c project
                    }
                }
            }
        }
    }
    if (celem == null) {
        IWorkbenchPart part = CUIPlugin.getActivePage().getActivePart();
        if (part instanceof ContentOutline) {
            part = CUIPlugin.getActivePage().getActiveEditor();
        }

        if (part instanceof IViewPartInputProvider) {
            Object elem = ((IViewPartInputProvider) part).getViewPartInput();
            if (elem instanceof ICElement) {
                celem = (ICElement) elem;
            }
        }

        if (celem == null && part instanceof CEditor) {
            IEditorInput input = ((IEditorPart) part).getEditorInput();
            if (input != null) {
                final IResource res = (IResource) input.getAdapter(IResource.class);
                if (res != null && res instanceof IFile) {
                    celem = CoreModel.getDefault().create((IFile) res);
                }
            }
        }
    }

    if (celem == null || celem.getElementType() == ICElement.C_MODEL) {
        try {
            ICProject[] projects = CoreModel.create(getWorkspaceRoot()).getCProjects();
            if (projects.length == 1) {
                celem = projects[0];
            }
        } catch (CModelException e) {
            CUIPlugin.log(e);
        }
    }
    return celem;
}

From source file:com.predic8.plugin.membrane.dialogs.rule.AddInterceptorDialog.java

License:Apache License

@Override
protected void okPressed() {
    IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
    if (selection == null || selection.isEmpty())
        close();//  w  ww . ja v  a2 s .  co m

    interceptorComposite.addNewInterceptor((Interceptor) selection.getFirstElement());

    super.okPressed();
}

From source file:com.predic8.plugin.membrane.dialogs.rule.composites.ProxyInterceptorTabComposite.java

License:Apache License

private TableViewer createTableViewer(Composite listComposite) {
    final TableViewer viewer = new TableViewer(listComposite,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    createColumns(viewer);/*from  w  ww.j  a  v  a  2 s .  c  o m*/
    viewer.setContentProvider(new InterceptorTableViewerContentProvider());
    viewer.setLabelProvider(new InterceptorTableViewerLabelProvider());

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            if (selection == null || selection.isEmpty()) {
                controlsComposite.enableDependentButtons(false);
                return;
            }
            controlsComposite.enableDependentButtons(true);
            selectedInterceptor = (Interceptor) selection.getFirstElement();
        }

    });

    GridData gData = new GridData();
    gData.widthHint = 330;
    gData.heightHint = 270;
    viewer.getTable().setLayoutData(gData);
    return viewer;
}

From source file:com.predic8.plugin.membrane.views.ExchangesView.java

License:Apache License

private TableViewer createTableViewer(Composite composite) {
    final TableViewer viewer = new TableViewer(composite,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL);
    createColumns(viewer);/*  w w w. ja v  a  2 s.  c  o  m*/

    viewer.setContentProvider(new ExchangesViewLazyContentProvider(viewer));
    viewer.setUseHashlookup(true);

    viewer.setLabelProvider(new ExchangesViewLabelProvider());

    GridData gData = new GridData(GridData.FILL_BOTH);
    gData.grabExcessVerticalSpace = true;
    gData.grabExcessHorizontalSpace = true;
    viewer.getTable().setLayoutData(gData);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
            MembraneUIPlugin.PLUGIN_ID + "ExchangesOverview");

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {

            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            if (selection.isEmpty()) {
                updateRequestResponseViews(null);
            }

            if (selection.getFirstElement() instanceof Exchange) {
                Exchange exc = (Exchange) selection.getFirstElement();
                updateRequestResponseViews(exc);
                enableStopMenu(exc);
            }
        }

        private void updateRequestResponseViews(Exchange exc) {
            setInputForMessageView(exc, ResponseView.VIEW_ID);
            setInputForMessageView(exc, RequestView.VIEW_ID);
            canShowBody = true;
        }
    });
    return viewer;
}

From source file:com.predic8.plugin.membrane.views.ProxiesView.java

License:Apache License

private ISelectionChangedListener createSelectionChangeListener() {
    return new ISelectionChangedListener() {
        @Override/*from   w  ww.  j ava2s . c o m*/
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            if (selection == null || selection.isEmpty()) {
                controlsComposite.enableDependentButtons(false);
                return;
            }
            controlsComposite.enableDependentButtons(true);

            setSelectedProxy((Rule) selection.getFirstElement());
        }

        private void setSelectedProxy(Rule selectedProxy) {
            for (AbstractProxyAction action : actions) {
                action.setSelectedProxy(selectedProxy);
            }
            controlsComposite.setSelectedProxy(selectedProxy);
            updateDetailsViewIfVisible(selectedProxy);
        }

    };
}

From source file:com.predic8.plugin.membrane.views.RulesView.java

License:Apache License

private TableViewer createTableViewer(Composite composite) {
    final TableViewer tableViewer = new TableViewer(composite,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    createColumns(tableViewer);//from w ww . ja  v a 2 s  .  co  m
    tableViewer.setContentProvider(new RulesViewContentProvider());

    tableViewer.setLabelProvider(new RulesViewLabelProvider());

    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.grabExcessVerticalSpace = true;
    gridData.grabExcessHorizontalSpace = true;
    tableViewer.getTable().setLayoutData(gridData);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, MembraneUIPlugin.PLUGIN_ID + "RuleStatistics");

    setCellEditorForTableViewer(tableViewer);

    tableViewer.setColumnProperties(new String[] { "name" });

    cellEditorModifier = new RuleNameCellEditorModifier();
    cellEditorModifier.setTableViewer(tableViewer);
    tableViewer.setCellModifier(cellEditorModifier);

    TableViewerEditor.create(tableViewer, new ColumnViewerEditorActivationStrategy(tableViewer) {
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    }, ColumnViewerEditor.DEFAULT);

    tableViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            Object selectedItem = selection.getFirstElement();
            if (selectedItem instanceof Rule) {
                tableViewer.editElement(selectedItem, 0);
            }
        }
    });

    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            if (selection == null || selection.isEmpty()) {
                controlsComposite.enableDependentButtons(false);
                return;
            }
            controlsComposite.enableDependentButtons(true);

            setSelectedRule((Rule) selection.getFirstElement());

        }

        private void setSelectedRule(Rule selectedRule) {
            removeRuleAction.setSelectedRule(selectedRule);
            editRuleAction.setSelectedRule(selectedRule);
            removeAllExchangesAction.setSelectedRule(selectedRule);
            showRuleDetailsAction.setSelectedRule(selectedRule);
            controlsComposite.setSelectedRule(selectedRule);

            updatedetailsViewIfVisible(selectedRule);
        }

    });

    return tableViewer;
}