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.netxforge.screens.editing.base.AbstractScreenImpl.java

License:Open Source License

/**
 * We are the {@link ISelectionProvider} for non IStructuredSelection. As
 * non-structured viewer selections do not implement the JFace
 * ISelectionProvider interface. </br> Clients should call
 * {@link #registerFocus(Control)} to make sure
 * //from   w ww.j av a  2 s. c  o  m
 */
public ISelection getSelection() {
    if (currentFocusWidget instanceof Text) {
        Text t = (Text) currentFocusWidget;
        t.getSelectionText();
    }

    ISelectionProvider currentSelectionProvider = this.resolveSelectionProviderFromWidget(currentFocusWidget);
    if (currentSelectionProvider != null) {
        return currentSelectionProvider.getSelection();
    }
    return StructuredSelection.EMPTY;
}

From source file:com.netxforge.screens.editing.base.AbstractScreensViewPart.java

License:Open Source License

/**
 * Call from which ever screen with multiple viewers which can/should
 * provide selection./*  ww  w  .  ja  v  a 2 s  .  c  o  m*/
 * 
 * @param viewer
 */
public void setCurrentScreen(IScreen screen) {

    if (selectionChangedListener == null) {
        // Create the listener on demand.
        //
        selectionChangedListener = new ISelectionChangedListener() {
            // This just notifies those things that are affected by the
            // section.
            //
            public void selectionChanged(SelectionChangedEvent selectionChangedEvent) {
                setSelection(selectionChangedEvent);
            }
        };
    }

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

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

    // Set the editors selection based on the current screen's
    // selection.
    setSelection(screen == null ? StructuredSelection.EMPTY : screen.getSelection());

    Viewer viewer = screen.getViewer();
    if (viewer instanceof StructuredViewer) {
        // Don't do that yet, as we have no facility to learn the
        // existing menu items.
        augmentContextMenuFor((StructuredViewer) viewer);
    }

    // Install a menu on the active viewers.
    // for (Viewer v : screen.getViewers()) {
    // // Install a context menu, for all possible viewers, note
    // // all actions will be installed, we don't differentiate which
    // // actions are added to which viewer.
    // if (v instanceof StructuredViewer) {
    // // Don't do that yet, as we have no facility to learn the
    // // existing menu items.
    // augmentContextMenuFor((StructuredViewer) v);
    // }
    // }
}

From source file:com.netxforge.screens.editing.base.AbstractScreensViewPart.java

License:Open Source License

/**
 * Call from which ever screen with a view which can/should provide
 * selection.// w  w w .  j  av  a  2 s.  co m
 * 
 * @param viewer
 * @deprecated Use setCurrentScreen instead.
 */
public void setCurrentViewer(Viewer viewer) {
    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.
                //
                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());

        // Install a context menu.
        if (currentViewer instanceof StructuredViewer) {
            // Don't do that yet, as we have no facility to learn the
            // existing menu items.
            augmentContextMenuFor((StructuredViewer) viewer);
        }
    }
}

From source file:com.netxforge.screens.editing.base.actions.BaseSelectionListenerAction.java

License:Open Source License

/**
 * The <code>BaseSelectionListenerAction</code> implementation of this
 * <code>ISelectionChangedListener</code> method calls
 * <code>selectionChanged(IStructuredSelection)</code> assuming the
 * selection is a structured one. Subclasses should override the
 * <code>updateSelection</code> method to react to selection changes.
 */// ww w.ja v  a 2s .c  om
public void selectionChanged(SelectionChangedEvent event) {
    this.event = event;
    ISelection selection = event.getSelection();
    if (selection instanceof IStructuredSelection) {
        selectionChanged((IStructuredSelection) selection);
    } else {
        selectionChanged(StructuredSelection.EMPTY);
    }
}

From source file:com.nextep.designer.vcs.ui.navigators.NavigatorLinkHelper.java

License:Open Source License

@Override
public IStructuredSelection findSelection(IEditorInput anInput) {
    if (anInput instanceof IModelOriented<?>) {
        IStructuredSelection s = new StructuredSelection(((IModelOriented<?>) anInput).getModel());
        return s;
    }//from w w  w. j  a v a 2  s .  c o m
    return StructuredSelection.EMPTY;
}

From source file:com.nextep.designer.vcs.ui.views.DiffPreviewView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    tree = new Tree(parent, SWT.FULL_SELECTION);
    tree.addListener(SWT.MouseDoubleClick, this);
    tree.setHeaderVisible(true);/*from w w  w  . j  a v  a 2  s  .com*/
    final TreeColumn objCol = new TreeColumn(tree, SWT.NONE);
    objCol.setText(VCSUIMessages.getString("comparison.view.colObjectName"));
    objCol.setWidth(250);
    final TreeColumn diffType = new TreeColumn(tree, SWT.NONE);
    diffType.setText(VCSUIMessages.getString("comparison.view.colDiffType"));
    diffType.setWidth(50);
    diffType.setAlignment(SWT.CENTER);
    final TreeColumn diffTarget = new TreeColumn(tree, SWT.NONE);
    diffTarget.setText(VCSUIMessages.getString("comparison.view.colTargetName"));
    diffTarget.setWidth(250);

    initializeTree();
    selectionProvider = new AbstractSelectionProvider() {

        @Override
        public ISelection getSelection() {
            TreeItem[] selItems = tree.getSelection();
            if (selItems.length > 0) {
                final Object o = selItems[0].getData();
                if (o instanceof IModelOriented<?>) {
                    return new StructuredSelection(((IModelOriented<?>) o).getModel());
                } else {
                    return new StructuredSelection(o);
                }
            }
            return StructuredSelection.EMPTY;
        }
    };
    tree.addSelectionListener(selectionProvider);
    registerContextMenu();
    getSite().setSelectionProvider(selectionProvider);
}

From source file:com.nokia.carbide.internal.discovery.ui.extension.AbstractDiscoveryPortalPageLayer.java

License:Open Source License

protected IAction[] makeActions(final IEditorPart part) {
    this.part = part;
    selectionListeners = new ArrayList<ISelectionChangedListener>();
    List<IAction> actions = new ArrayList<IAction>();
    IAction action;//  www .ja v a2  s.co m

    // install
    action = new BaseSelectionListenerAction(Messages.AbstractDiscoveryPortalPageLayer_InstallActionLabel) {
        public void run() {
            installCatalogItems(viewer.getCheckedItems());
        };

        protected boolean updateSelection(IStructuredSelection selection) {
            scheduleUpdateAllActionUIs();
            return !selection.isEmpty();
        };
    };
    action.setToolTipText(Messages.AbstractDiscoveryPortalPageLayer_InstallActionTooltip);
    action.setId(INSTALL_ACTION_ID);
    selectionListeners.add((ISelectionChangedListener) action);
    actions.add(action);

    // refresh
    action = new Action(Messages.AbstractDiscoveryPortalPageLayer_RefreshActionLabel) {
        public void run() {
            viewer.setSelection(StructuredSelection.EMPTY);
            viewer.updateCatalog();
            viewer.refresh();
        }
    };
    action.setId(REFRESH_ACTION_ID);
    actions.add(action);

    // check all
    action = new BaseSelectionListenerAction(Messages.AbstractDiscoveryPortalPageLayer_CheckAllActionLabel) {
        public void run() {
            viewer.setSelection(StructuredSelection.EMPTY);
            viewer.setSelection(getAllItemsSelection());
            viewer.refresh();
        }

        private IStructuredSelection getAllItemsSelection() {
            List<CatalogItem> catalogItems = new ArrayList<CatalogItem>();
            for (CatalogItem catalogItem : viewer.getCatalog().getItems()) {
                if (!catalogItem.isInstalled())
                    catalogItems.add(catalogItem);
            }
            return new StructuredSelection(catalogItems);
        }

        protected boolean updateSelection(IStructuredSelection selection) {
            scheduleUpdateAllActionUIs();
            return !getAllItemsSelection().equals(selection);
        }
    };
    action.setId(CHECK_ALL_ACTION_ID);
    selectionListeners.add((ISelectionChangedListener) action);
    actions.add(action);

    // uncheck all
    action = new BaseSelectionListenerAction(Messages.AbstractDiscoveryPortalPageLayer_UncheckAllActionLabel) {
        public void run() {
            viewer.setSelection(StructuredSelection.EMPTY);
            viewer.refresh();
        };

        protected boolean updateSelection(IStructuredSelection selection) {
            scheduleUpdateAllActionUIs();
            return !selection.isEmpty();
        };
    };
    action.setId(UNCHECK_ALL_ACTION_ID);
    selectionListeners.add((ISelectionChangedListener) action);
    actions.add(action);

    // advanced install
    action = new Action(Messages.AbstractDiscoveryPortalPageLayer_AdvancedInstallActionLabel) {
        public void run() {
            showInstallWizard();
        }
    };
    action.setId(ADV_INSTALL_ACTION_ID);
    actions.add(action);

    ISelectionChangedListener selectionListener = new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            IActionBars bars = part.getEditorSite().getActionBars();
            bars.getStatusLineManager()
                    .setMessage(selection.isEmpty() ? null
                            : MessageFormat.format(
                                    Messages.AbstractDiscoveryPortalPageLayer_CheckedItemsStatusMessage,
                                    selection.size()));
        }
    };
    selectionListeners.add(selectionListener);

    return (IAction[]) actions.toArray(new IAction[actions.size()]);
}

From source file:com.nokia.carbide.internal.discovery.ui.view.InstallExtensionsPortalExtension.java

License:Open Source License

private void showWizard(IWorkbenchWizard wizard) {
    wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
    WizardDialog dialog = new WizardDialog(part.getEditorSite().getShell(), wizard);
    dialog.setMinimumPageSize(550, 250);
    dialog.create();/*from  ww w.  j ava 2s  .c  om*/
    dialog.open();
}

From source file:com.nokia.carbide.trk.support.connection.SerialConnectionFactory.java

License:Open Source License

private void putSettingsToUI() {
    Map<String, String> map = settings.getSettings();
    for (String key : map.keySet()) {
        ComboViewer viewer = viewers.get(key);
        if (viewer != null) {
            String element = map.get(key);
            viewer.setSelection(element != null ? new StructuredSelection(element) : StructuredSelection.EMPTY);
        }//  w  w  w.java 2  s  .  c om
    }
}

From source file:com.nokia.s60ct.cenrep.gui.Actions.NewRepositoryAction.java

License:Open Source License

public void run(IAction action) {
    NewRepositoryWizard wizard = new NewRepositoryWizard();
    wizard.init(getWindow().getWorkbench(), StructuredSelection.EMPTY);
    WizardDialog wizardDialog = new WizardDialog(getWindow().getShell(), wizard);
    wizardDialog.open();// w  w w  .  j ava2  s.c  o m
}