Search in sources :

Example 61 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project yamcs-studio by yamcs.

the class ScrollLockHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
    CommandHistoryView view = (CommandHistoryView) part;
    ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    Command command = service.getCommand("org.yamcs.studio.commanding.cmdhist.scrollLockCommand");
    boolean oldState = HandlerUtil.toggleCommandState(command);
    view.enableScrollLock(!oldState);
    return null;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Command(org.eclipse.core.commands.Command) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 62 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project yamcs-studio by yamcs.

the class ShowCommandHistoryEntryDetailsHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
    CommandHistoryView view = (CommandHistoryView) part;
    ISelection sel = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
    if (sel != null && sel instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) sel;
        Iterator<?> it = selection.iterator();
        if (it.hasNext()) {
            CommandHistoryRecord rec = (CommandHistoryRecord) it.next();
            Shell shell = HandlerUtil.getActiveShellChecked(event);
            CommandHistoryEntryDetailsDialog dialog = new CommandHistoryEntryDetailsDialog(shell, view, rec);
            dialog.create();
            dialog.open();
        }
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 63 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project yamcs-studio by yamcs.

the class AnnotateArchiveHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
    SwingUtilities.invokeLater(() -> {
        ArchiveView view = (ArchiveView) part;
        view.archivePanel.getDataViewer().tagSelectedRange();
    });
    return null;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart)

Example 64 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project erlide_eclipse by erlang.

the class NewErlangProjectWizard method selectAndReveal.

/**
 * Attempts to select and reveal the specified resource in all parts within the
 * supplied workbench window's active page.
 * <p>
 * Checks all parts in the active page to see if they implement
 * <code>ISetSelectionTarget</code>, either directly or as an adapter. If so, tells
 * the part to select and reveal the specified resource.
 * </p>
 *
 * @param resource
 *            the resource to be selected and revealed
 * @param window
 *            the workbench window to select and reveal the resource
 *
 * @see ISetSelectionTarget
 */
public static void selectAndReveal(final IResource resource, final IWorkbenchWindow window) {
    // validate the input
    if (window == null || resource == null) {
        return;
    }
    final IWorkbenchPage page = window.getActivePage();
    if (page == null) {
        return;
    }
    // get all the view and editor parts
    final List<IWorkbenchPart> parts = Lists.newArrayList();
    IWorkbenchPartReference[] refs = page.getViewReferences();
    for (IWorkbenchPartReference ref1 : refs) {
        final IWorkbenchPart part = ref1.getPart(false);
        if (part != null) {
            parts.add(part);
        }
    }
    refs = page.getEditorReferences();
    for (IWorkbenchPartReference ref : refs) {
        if (ref.getPart(false) != null) {
            parts.add(ref.getPart(false));
        }
    }
    final ISelection selection = new StructuredSelection(resource);
    for (IWorkbenchPart part : parts) {
        // get the part's ISetSelectionTarget implementation
        ISetSelectionTarget target = null;
        if (part instanceof ISetSelectionTarget) {
            target = (ISetSelectionTarget) part;
        } else {
            target = part.getAdapter(ISetSelectionTarget.class);
        }
        if (target != null) {
            // select and reveal resource
            final ISetSelectionTarget finalTarget = target;
            window.getShell().getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    finalTarget.selectReveal(selection);
                }
            });
        }
    }
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISetSelectionTarget(org.eclipse.ui.part.ISetSelectionTarget) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference)

Example 65 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project erlide_eclipse by erlang.

the class ErlangEditor method getActivePart.

private IWorkbenchPart getActivePart() {
    final IWorkbenchWindow window = getSite().getWorkbenchWindow();
    final IPartService service = window.getPartService();
    final IWorkbenchPart part = service.getActivePart();
    return part;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IPartService(org.eclipse.ui.IPartService)

Aggregations

IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)289 ISelection (org.eclipse.jface.viewers.ISelection)113 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)112 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)72 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)69 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)59 IEditorPart (org.eclipse.ui.IEditorPart)57 IFile (org.eclipse.core.resources.IFile)52 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)44 IResource (org.eclipse.core.resources.IResource)42 PartInitException (org.eclipse.ui.PartInitException)41 ArrayList (java.util.ArrayList)36 ISetSelectionTarget (org.eclipse.ui.part.ISetSelectionTarget)35 FileEditorInput (org.eclipse.ui.part.FileEditorInput)33 HashMap (java.util.HashMap)32 EObject (org.eclipse.emf.ecore.EObject)31 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)31 URI (org.eclipse.emf.common.util.URI)30 MissingResourceException (java.util.MissingResourceException)29 Resource (org.eclipse.emf.ecore.resource.Resource)29