Example usage for org.eclipse.jface.viewers ISelectionProvider setSelection

List of usage examples for org.eclipse.jface.viewers ISelectionProvider setSelection

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ISelectionProvider setSelection.

Prototype

public void setSelection(ISelection selection);

Source Link

Document

Sets the current selection for this selection provider.

Usage

From source file:clojure.lang.ide.SourceLocationHyperlink.java

License:Open Source License

public void open() {
    if (to == null) {
        return;//from www .j a v  a 2 s  .com
    }

    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();

    if (win == null && wb.getWorkbenchWindowCount() != 0) {
        win = wb.getWorkbenchWindows()[0];
    }

    if (win != null) {
        final IWorkbenchPage page = win.getActivePage();

        if (page != null) {
            Display.getDefault().asyncExec(new Runnable() {
                public void run() {
                    try {
                        IEditorDescriptor desc = null;
                        //                     if (TermLanguageRegistry.getInstance().getLanguage(to) != null) {
                        //                        desc = PlatformUI.getWorkbench().getEditorRegistry().findEditor(UniversalEditor.EDITOR_ID);
                        //                     } 
                        //                     else {
                        //                        desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(to.getURI().getPath());
                        //                     }
                        IEditorPart part;

                        if (desc != null) {
                            IEditorInput editorInput = getEditorInput(to.getURI());
                            part = page.openEditor(editorInput, desc.getId());
                            ISelectionProvider sp = part.getEditorSite().getSelectionProvider();
                            if (sp != null) {
                                sp.setSelection(new TextSelection(to.getOffset(), to.getLength()));
                            } else {
                                //                           Activator.getInstance().logException("no selection provider", new RuntimeException());
                            }
                        } else {
                            IFileStore fileStore = EFS.getLocalFileSystem().getStore(to.getURI());
                            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                                    .getActivePage();
                            part = IDE.openEditorOnFileStore(page, fileStore);
                        }

                        if (part != null) {
                            IRegionSelectionService ss = (IRegionSelectionService) part
                                    .getAdapter(IRegionSelectionService.class);
                            ss.selectAndReveal(to.getOffset(), to.getLength());
                        }
                    } catch (PartInitException e) {
                        //                     Activator.getInstance().logException("failed to open editor for source loc:" + to, e);
                    }
                }

                private IEditorInput getEditorInput(URI uri) {
                    String scheme = uri.getScheme();

                    if (scheme.equals("project")) {
                        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(uri.getHost());

                        if (project != null) {
                            return new FileEditorInput(project.getFile(uri.getPath()));
                        }

                        //                     Activator.getInstance().logException("project " + uri.getHost() + " does not exist", new RuntimeException());
                    } else if (scheme.equals("file")) {
                        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
                        IFile[] cs = root.findFilesForLocationURI(uri);

                        if (cs != null && cs.length > 0) {
                            return new FileEditorInput(cs[0]);
                        }

                        //                     Activator.getInstance().logException("file " + uri + " not found", new RuntimeException());
                    } else if (scheme.equals("rascal-library")) {
                        IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri);
                        if (files.length > 0) {
                            return new FileEditorInput(files[0]);
                        }
                    } else if (scheme.equals("std")) {
                        // TODO: this design is wrong, we should rethink the way we want
                        // to tie the Rascal schemes into Eclipse.
                        try {
                            uri = new URI(uri.toString().replaceFirst("std:///", "rascal-library://rascal/"));
                            return getEditorInput(uri);
                        } catch (URISyntaxException e) {
                            // Do nothing, fall through and return null
                        }
                    }

                    //                  Activator.getInstance().logException("scheme " + uri.getScheme() + " not supported", new RuntimeException());
                    return null;
                }
            });
        }
    }
}

From source file:com.android.ide.eclipse.adt.internal.assetstudio.CreateAssetSetWizard.java

License:Open Source License

private void selectFiles(IProject project, List<? extends IResource> createdFiles) {
    // Attempt to select the newly created files in the Package Explorer
    IWorkbench workbench = AdtPlugin.getDefault().getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    IViewPart viewPart = page.findView(JavaUI.ID_PACKAGES);
    if (viewPart != null) {
        IWorkbenchPartSite site = viewPart.getSite();
        IJavaProject javaProject = null;
        try {/*from  w  ww .j ava  2  s.c  om*/
            javaProject = BaseProjectHelper.getJavaProject(project);
        } catch (CoreException e) {
            AdtPlugin.log(e, null);
        }
        final ISelectionProvider provider = site.getSelectionProvider();
        if (provider != null) {
            List<TreePath> pathList = new ArrayList<TreePath>();
            for (IResource file : createdFiles) {
                // Create a TreePath for the given file,
                // which should be the JavaProject, followed by the folders down to
                // the final file.
                List<Object> segments = new ArrayList<Object>();
                segments.add(file);
                IContainer folder = file.getParent();
                if (folder != null && !(folder instanceof IProject)) {
                    segments.add(folder);
                    // res folder
                    folder = folder.getParent();
                    if (folder != null && !(folder instanceof IProject)) {
                        segments.add(folder);
                    }
                }
                // project
                segments.add(javaProject);

                Collections.reverse(segments);
                TreePath path = new TreePath(segments.toArray());
                pathList.add(path);

                // IDEA: Maybe normalize the files backwards (IFile objects aren't unique)
                // by maybe using the package explorer icons instead
            }

            TreePath[] paths = pathList.toArray(new TreePath[pathList.size()]);
            final TreeSelection selection = new TreeSelection(paths);

            provider.setSelection(selection);

            // Workaround: The above doesn't always work; it will frequently select
            // some siblings of the real files. I've tried a number of workarounds:
            // normalizing the IFile objects by looking up the canonical ones via
            // their relative paths from the project; deferring execution with
            // Display.asyncRun; first calling select on the parents, etc.
            // However, it turns out a simple workaround works best: Calling this
            // method TWICE. The first call seems to expand all the necessary parents,
            // and the second call ensures that the correct children are selected!
            provider.setSelection(selection);

            viewPart.setFocus();
        }
    }
}

From source file:com.aptana.editor.findbar.impl.FindBarDecorator.java

License:Open Source License

private void replace(boolean newFind) {
    ISelectionProvider selectionProvider = this.textEditor.getSelectionProvider();
    ISelection selection = selectionProvider.getSelection();
    if (!(selection instanceof ITextSelection)) {
        FindBarPlugin.log(new AssertionError("Expected text editor selection to be an ITextSelection. Was: " //$NON-NLS-1$
                + selection));//from www . j  a  v a  2 s .  c  om
        return;
    }
    ITextSelection textSelection = (ITextSelection) selection;
    String comboText = textFind.getText();
    if (comboText.length() == 0) {
        return;
    }
    setFindText(comboText);
    setFindTextOnReplace(getReplaceText());

    selectionProvider.setSelection(new TextSelection(
            this.textEditor.getDocumentProvider().getDocument(this.textEditor.getEditorInput()),
            textSelection.getOffset(), 0));

    // Do initial search before replace (always forward search as we just selected the initial offset).
    if (!findBarFinder.find(true, false, false)) {
        return; // The messages (why the find didn't work) should be set already.
    }
    try {
        getFindReplaceDialog().replaceSelection(getReplaceText(), getConfiguration().getRegularExpression());
        showCountTotal();
    } catch (Exception e1) {
        statusLineManager.setMessage(true,
                MessageFormat.format(Messages.FindBarDecorator_ReplaceError, e1.getMessage()), null);
        FindBarPlugin.log(e1);
        return;
    }

    if (newFind) {
        if (getConfiguration().getSearchBackward()) {
            findBarFinder.find(false);
        } else {
            findBarFinder.find(true);
        }
    } else {
        statusLineManager.setMessage(false, StringUtil.EMPTY, null);
    }
}

From source file:com.cisco.yangide.editor.EditorUtility.java

License:Open Source License

/**
 * Selects and reveals the given offset and length in the given editor part.
 *
 * @param editor the editor part//ww w.  ja  v a 2s  .  c o  m
 * @param offset the offset
 * @param length the length
 */
public static void revealInEditor(IEditorPart editor, final int offset, final int length) {
    if (editor instanceof IYangEditor) {
        ((IYangEditor) editor).selectAndReveal(offset, length);
        return;
    }

    if (editor != null && editor.getEditorSite().getSelectionProvider() != null) {
        IEditorSite site = editor.getEditorSite();
        if (site == null) {
            return;
        }

        ISelectionProvider provider = editor.getEditorSite().getSelectionProvider();
        if (provider == null) {
            return;
        }

        provider.setSelection(new TextSelection(offset, length));
    }
}

From source file:com.ebmwebsoucing.petals.repositories.explorer.RepositoryExplorerActionProvider.java

License:Open Source License

@Override
public void init(final ICommonActionExtensionSite aSite) {

    ICommonViewerSite site = aSite.getViewSite();
    if (!(site instanceof ICommonViewerWorkbenchSite))
        return;/* www.j a v a  2  s .  co  m*/

    final ISelectionProvider provider = ((ICommonViewerWorkbenchSite) site).getSelectionProvider();

    //
    // Remove action
    this.deleteRepositoryAction = new Action() {
        @Override
        public void run() {
            Repository rep = getSelectedRepository(provider);
            if (rep != null)
                RepositoryManager.getInstance().removeRepository(rep);
        }

        @Override
        public boolean isEnabled() {
            return getSelectedRepository(provider) != null;
        }
    };

    this.deleteRepositoryAction.setText("Delete");
    this.deleteRepositoryAction.setToolTipText("Delete this service repository");
    this.deleteRepositoryAction.setDescription("Delete this service repository.");
    ImageDescriptor desc = PetalsRepositoriesPlugin.getImageDescriptor("icons/obj16/delete.gif");
    this.deleteRepositoryAction.setImageDescriptor(desc);

    //
    // New repository action
    this.addRepositoryAction = new Action() {
        @Override
        public void run() {

            IWorkbench workbench = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getWorkbench();
            RepositoryNewWizard wizard = new RepositoryNewWizard();

            final Display display = PlatformUI.getWorkbench().getDisplay();
            WizardDialog dlg = new WizardDialog(new Shell(display), wizard) {
                @Override
                protected Control createContents(Composite parent) {

                    Control c = super.createContents(parent);

                    Rectangle rect = display.getBounds();
                    Point shellPoint = getShell().getSize();
                    int x = (rect.width - shellPoint.x) / 2 + rect.x;
                    int y = (rect.height - shellPoint.y) / 2 + rect.y;
                    getShell().setLocation(x, y);

                    return c;
                }
            };

            workbench.saveAllEditors(true);
            dlg.setPageSize(400, 300);
            dlg.open();
        }

        @Override
        public boolean isEnabled() {
            return true;
        }
    };

    this.addRepositoryAction.setText("New Repository");
    this.addRepositoryAction.setToolTipText("Add a new service repository");
    this.addRepositoryAction.setDescription("Add a new service repository.");
    desc = PetalsRepositoriesPlugin.getImageDescriptor("icons/obj16/petals_service.png");
    this.addRepositoryAction.setImageDescriptor(desc);

    //
    // Properties action
    this.propertiesAction = new Action() {
        @Override
        public boolean isEnabled() {
            return getSelectedRepository(provider) != null;
        }

        @Override
        public void run() {

            Repository rep = getSelectedRepository(provider);
            try {
                // Show properties view
                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                page.showView("org.eclipse.ui.views.PropertySheet"); //$NON-NLS-1$

                // Show the Petals service explorer
                page.showView("com.ebmwebsourcing.petals.repositories.view"); //$NON-NLS-1$

                // Select the previous selection in the outline.
                provider.setSelection(new StructuredSelection(rep));
            } catch (Exception e) {
                PetalsRepositoriesPlugin.log(e, IStatus.ERROR);
            }
        }
    };

    this.propertiesAction.setText("Properties");
    this.propertiesAction.setToolTipText("Show properties");
    this.propertiesAction.setDescription("Show the properties of the selected element.");
    desc = PetalsRepositoriesPlugin.getImageDescriptor("icons/obj16/properties.gif");
    this.propertiesAction.setImageDescriptor(desc);
}

From source file:com.ebmwebsourcing.petals.services.explorer.ServiceExplorerActionProvider.java

License:Open Source License

@Override
public void init(final ICommonActionExtensionSite aSite) {

    ICommonViewerSite site = aSite.getViewSite();
    if (!(site instanceof ICommonViewerWorkbenchSite))
        return;//from www  . ja  v  a  2s  .co  m

    final ISelectionProvider provider = ((ICommonViewerWorkbenchSite) site).getSelectionProvider();

    //
    // Workspace Folder Source
    this.addWorkspaceFolderSourceAction = new Action() {
        @Override
        public void run() {

            DirectoryDialog dlg = new DirectoryDialog(aSite.getViewSite().getShell());
            dlg.setText("External workspace");
            dlg.setMessage("Find Petals services in an external workspace.");
            String result = dlg.open();

            if (result != null) {
                EndpointSource source = new ExternalWorkspaceSource(new File(result));
                SourceManager.getInstance().addSource(source);
            }
        }
    };

    this.addWorkspaceFolderSourceAction.setText("Workspace Folder");
    this.addWorkspaceFolderSourceAction.setToolTipText("New workspace folder source");
    this.addWorkspaceFolderSourceAction
            .setDescription("Find the Petals services in contained in another workspace folder.");
    ImageDescriptor desc = PetalsServicesPlugin.getImageDescriptor("icons/obj16/EndpointProjectClosed.gif");
    this.addWorkspaceFolderSourceAction.setImageDescriptor(desc);

    //
    // SA Folder Source
    this.addSaFolderAction = new Action() {
        @Override
        public void run() {
            DirectoryDialog dlg = new DirectoryDialog(aSite.getViewSite().getShell());
            dlg.setText("Service Assembly folder");
            dlg.setMessage("Find Petals services in a directory of service assemblies.");
            String result = dlg.open();

            if (result != null) {
                EndpointSource source = new SaDirectorySource(new File(result), false, false);
                SourceManager.getInstance().addSource(source);
            }
        }
    };

    this.addSaFolderAction.setText("SA Folder");
    this.addSaFolderAction.setToolTipText("New SA folder source");
    this.addSaFolderAction
            .setDescription("Find the Petals services in contained in a folder of service assemblies.");
    desc = PetalsServicesPlugin.getImageDescriptor("icons/obj16/EndpointFolderClosed.gif");
    this.addSaFolderAction.setImageDescriptor(desc);

    //    //
    //   // Workspace Folder Source
    //   this.addServerSourceAction = new Action() {
    //      @Override
    //      public void run() {
    //         // TODO
    //      }
    //   };
    //
    //   this.addServerSourceAction.setText( "Petals Server" );
    //   this.addServerSourceAction.setToolTipText( "New server source" );
    //   this.addServerSourceAction.setDescription( "Browse the end-points contained in a Petals server." );
    //   desc = PetalsServicesPlugin.getImageDescriptor( "icons/obj16/EndpointServer.gif" );
    //   this.addServerSourceAction.setImageDescriptor( desc );

    //
    // Refresh action
    this.refreshAction = new Action() {
        @Override
        public void run() {
            final EndpointSource source = getEndpointSource(provider);
            if (source != null)
                SourceManager.getInstance().updateSource(source);
        }

        @Override
        public boolean isEnabled() {
            return getEndpointSource(provider) != null;
        }
    };

    this.refreshAction.setText("Refresh");
    this.refreshAction.setAccelerator(SWT.F5);
    this.refreshAction.setToolTipText("Refresh the list of Petals services");
    this.refreshAction.setDescription("Refresh the list of Petals services.");
    desc = PetalsServicesPlugin.getImageDescriptor("icons/obj16/refresh.gif");
    this.refreshAction.setImageDescriptor(desc);

    //
    // Remove action
    this.deleteAction = new Action() {
        @Override
        public void run() {
            EndpointSource source = getEndpointSource(provider);
            if (source != null)
                SourceManager.getInstance().removeSource(source);
        }

        @Override
        public boolean isEnabled() {
            EndpointSource edptSource = getEndpointSource(provider);
            return edptSource != null && !(edptSource instanceof CurrentWorkspaceSource);
        }
    };

    this.deleteAction.setText("Delete");
    this.deleteAction.setToolTipText("Delete this source of Petals services");
    this.deleteAction.setDescription("Delete this source of Petals services.");
    desc = PetalsServicesPlugin.getImageDescriptor("icons/obj16/delete.gif");
    this.deleteAction.setImageDescriptor(desc);

    //
    // Properties action
    this.propertiesAction = new Action() {
        @Override
        public boolean isEnabled() {
            return getEndpointSource(provider) != null || getEndpointBean(provider) != null;
        }

        @Override
        public void run() {
            Object object = getEndpointSource(provider);
            if (object == null)
                object = getEndpointBean(provider);

            try {
                // Show properties view
                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                page.showView("org.eclipse.ui.views.PropertySheet"); //$NON-NLS-1$

                // Show the Petals service explorer
                page.showView("com.ebmwebsourcing.petals.services.explorer"); //$NON-NLS-1$

                // Select the previous selection in the outline.
                provider.setSelection(new StructuredSelection(object));
            } catch (Exception e) {
                PetalsServicesPlugin.log(e, IStatus.ERROR);
            }
        }
    };

    this.propertiesAction.setText("Properties");
    this.propertiesAction.setToolTipText("Show properties");
    this.propertiesAction.setDescription("Show the properties of the selected element.");
    desc = PetalsServicesPlugin.getImageDescriptor("icons/obj16/properties.gif");
    this.propertiesAction.setImageDescriptor(desc);

    //
    // Open WSDL action
    this.openWsdlAction = new Action() {

        @Override
        public boolean isEnabled() {
            EndpointBean edptBean = getEndpointBean(provider);

            if (edptBean != null) {
                if (edptBean.getServiceUnit().isWsdlContainerLocationComputed()) {
                    URI uri = edptBean.getWsdlUri();
                    return uri != null && new File(uri).exists();
                }

                return edptBean.getWsdlLocation() != null;
            }

            return false;
        }

        @Override
        public boolean isHandled() {
            EndpointBean edptBean = getEndpointBean(provider);
            return edptBean != null;
        }

        @Override
        public void run() {
            final EndpointBean edptBean = getEndpointBean(provider);
            try {
                URI wsdlUri = edptBean.getWsdlUri();

                // WSDL not null: open it
                File f = null;
                if (wsdlUri != null && (f = new File(wsdlUri)).exists()) {
                    IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(f.getAbsolutePath()));
                    if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
                        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                                .getActivePage();
                        IDE.openEditorOnFileStore(page, fileStore);
                    }
                }

                // WSDL URI is null or points to a nonexistent file
                /*
                 * Can only happen when this URI is computed for the first time.
                 * Then, isEnabled() prevents this from happening.
                 * 
                 * Refreshing the source of the end-point will have for consequence
                 * a new computation of the WSDL URI.
                 */
                else if (f != null) {
                    MessageDialog.openInformation(aSite.getViewSite().getShell(), "Nonexistent WSDL",
                            "The WSDL file " + f.getAbsolutePath() + " does not exist.");
                } else {
                    MessageDialog.openInformation(aSite.getViewSite().getShell(), "No WSDL to open",
                            "No WSDL could be found for this service.");
                }

            } catch (Exception e) {
                MessageDialog.openError(aSite.getViewSite().getShell(), "Failure in opening the WSDL",
                        "The service WSDL could not be opened. See the log for more details.");
                PetalsServicesPlugin.log(e, IStatus.ERROR);
            }
        }
    };

    this.openWsdlAction.setText("Open WSDL");
    this.openWsdlAction.setToolTipText("Show the service interface in the WSDL editor");
    this.openWsdlAction.setDescription("Show the service interface in the WSDL editor.");
}

From source file:com.google.dart.tools.ui.internal.text.editor.EditorUtility.java

License:Open Source License

/**
 * Selects and reveals the given offset and length in the given editor part.
 *///from   ww  w . j  av  a2  s.  c  o  m
public static void revealInEditor(IEditorPart editor, final int offset, final int length) {
    if (editor instanceof ITextEditor) {
        ((ITextEditor) editor).selectAndReveal(offset, length);
        return;
    }

    // Support for non-text editor - try IGotoMarker interface
    if (editor instanceof IGotoMarker) {
        final IEditorInput input = editor.getEditorInput();
        if (input instanceof IFileEditorInput) {
            final IGotoMarker gotoMarkerTarget = (IGotoMarker) editor;
            WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
                @Override
                protected void execute(IProgressMonitor monitor) throws CoreException {
                    IMarker marker = null;
                    try {
                        marker = ((IFileEditorInput) input).getFile().createMarker(IMarker.TEXT);
                        marker.setAttribute(IMarker.CHAR_START, offset);
                        marker.setAttribute(IMarker.CHAR_END, offset + length);

                        gotoMarkerTarget.gotoMarker(marker);

                    } finally {
                        if (marker != null) {
                            marker.delete();
                        }
                    }
                }
            };

            try {
                op.run(null);
            } catch (InvocationTargetException ex) {
                // reveal failed
            } catch (InterruptedException e) {
                Assert.isTrue(false, "this operation can not be canceled"); //$NON-NLS-1$
            }
        }
        return;
    }

    /*
     * Workaround: send out a text selection XXX: Needs to be improved, see
     * https://bugs.eclipse.org/bugs/show_bug.cgi?id=32214
     */
    if (editor != null && editor.getEditorSite().getSelectionProvider() != null) {
        IEditorSite site = editor.getEditorSite();
        if (site == null) {
            return;
        }

        ISelectionProvider provider = editor.getEditorSite().getSelectionProvider();
        if (provider == null) {
            return;
        }

        provider.setSelection(new TextSelection(offset, length));
    }
}

From source file:com.google.dart.tools.ui.web.yaml.PubspecYamlEditor.java

License:Open Source License

private void setFont(ISourceViewer sourceViewer, Font font) {

    if (sourceViewer.getDocument() != null) {
        ISelectionProvider provider = sourceViewer.getSelectionProvider();
        ISelection selection = provider.getSelection();
        int topIndex = sourceViewer.getTopIndex();

        StyledText styledText = sourceViewer.getTextWidget();
        Control parent = styledText;
        if (sourceViewer instanceof ITextViewerExtension) {
            ITextViewerExtension extension = (ITextViewerExtension) sourceViewer;
            parent = extension.getControl();
        }//from   w w w.  ja va  2  s  . c  o m
        parent.setRedraw(false);
        styledText.setFont(font);

        if (getVerticalRuler() instanceof IVerticalRulerExtension) {
            IVerticalRulerExtension e = (IVerticalRulerExtension) getVerticalRuler();
            e.setFont(font);
        }

        provider.setSelection(selection);
        sourceViewer.setTopIndex(topIndex);

        if (parent instanceof Composite) {
            Composite composite = (Composite) parent;
            composite.layout(true);
        }
        parent.setRedraw(true);
    } else {
        StyledText styledText = sourceViewer.getTextWidget();
        styledText.setFont(font);
        if (getVerticalRuler() instanceof IVerticalRulerExtension) {
            IVerticalRulerExtension e = (IVerticalRulerExtension) getVerticalRuler();
            e.setFont(font);
        }
    }
}

From source file:com.knitml.dsl.ui.editor.MultiPageSelectionProvider.java

License:Open Source License

public void setSelection(ISelection selection) {
    IEditorPart activeEditor = multiPageEditor.getActiveEditor();
    if (activeEditor != null) {
        ISelectionProvider selectionProvider = activeEditor.getSite().getSelectionProvider();
        if (selectionProvider != null) {
            selectionProvider.setSelection(selection);
        }/*from ww  w  .j ava2s . c  om*/
    }
}

From source file:com.misc.common.moplaf.emf.editor.action.CommandAction.java

License:Open Source License

/**
 * This executes the command./*from   w  w  w  .  j ava 2s  .  c  o  m*/
 */
@Override
public void run() {
    // this guard is for extra security, but should not be necessary
    if (editingDomain != null && command != null) {
        // use up the command
        editingDomain.getCommandStack().execute(command);
    }

    // re-set the selection
    //    this is done to trigger a "SelectionChanged" event
    //    so that the action are recreated
    //    actions enablements need te be recalculated
    //    as they may be different after running this action 
    if (this.workbenchPart instanceof ISelectionProvider) {
        ISelectionProvider provider = (ISelectionProvider) this.workbenchPart;
        provider.setSelection(selection);
    }
}