Java Code Examples for org.eclipse.ui.IWorkbenchPage#getActivePart()

The following examples show how to use org.eclipse.ui.IWorkbenchPage#getActivePart() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CopyHandler.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean isEnabled() {
    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    // Get the selection
    IWorkbenchPage page = window.getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (part instanceof FilterView) {
        FilterView tcv = (FilterView) part;
        ISelection selection = tcv.getSite().getSelectionProvider().getSelection();
        // only enable if tree is in focus
        if (!selection.isEmpty() && tcv.isTreeInFocus()) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: PasteHandler.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean isEnabled() {
    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    // Get the selection
    IWorkbenchPage page = window.getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (!(part instanceof FilterView)) {
        return false;
    }
    FilterView v = (FilterView) part;
    ITmfFilterTreeNode sel = v.getSelection();
    if (sel == null) {
        sel = v.getFilterRoot();
    }
    ITmfFilterTreeNode objectToPaste = FilterEditUtils.getTransferredTreeNode();
    return (v.isTreeInFocus() && objectToPaste != null &&
            (sel.getValidChildren().contains(objectToPaste.getNodeName())
                    || TmfFilterNode.NODE_NAME.equals(objectToPaste.getNodeName())));
}
 
Example 3
Source File: PasteHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return null;
    }

    // Get the selection
    IWorkbenchPage page = window.getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (!(part instanceof FilterView)) {
        return null;
    }
    FilterView v = (FilterView) part;

    ITmfFilterTreeNode objectToPaste = FilterEditUtils.getTransferredTreeNode();
    objectToPaste = objectToPaste.clone();
    ITmfFilterTreeNode sel = v.getSelection();
    if (sel == null || TmfFilterNode.NODE_NAME.equals(objectToPaste.getNodeName())) {
        sel = v.getFilterRoot();
    }

    sel.addChild(objectToPaste);
    v.refresh();
    v.setSelection(objectToPaste);
    return null;
}
 
Example 4
Source File: OpenTraceHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {

    // Check if we are closing down
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    // Get the selection
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return false;
    }
    final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    final ISelection selection = selectionProvider.getSelection();

    // Make sure there is only one selection and that it is a trace
    fTrace = null;
    if (selection instanceof TreeSelection) {
        final TreeSelection sel = (TreeSelection) selection;
        // There should be only one item selected as per the plugin.xml
        final Object element = sel.getFirstElement();
        if (element instanceof TmfTraceElement) {
            fTrace = (TmfTraceElement) element;
        }
    }

    // We only enable opening from the Traces folder for now
    return (fTrace != null);
}
 
Example 5
Source File: GoSearchPage.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
private IEditorPart getActiveEditor() {
  IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
  if (activePage != null) {
    IEditorPart activeEditor= activePage.getActiveEditor();
    IWorkbenchPart activePart= activePage.getActivePart();
    if (activeEditor == activePart || isOldSearchView(activePart))
      return activeEditor;
  }
  return null;
}
 
Example 6
Source File: OpenAnalysisOutputHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {
    /* Check if we are closing down */
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    /* Get the selection */
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return false;
    }
    final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    final ISelection selection = selectionProvider.getSelection();

    /* Make sure there is only one selection and that it is an analysis output */
    fOutputElement = null;
    if (selection instanceof TreeSelection) {
        final TreeSelection sel = (TreeSelection) selection;
        // There should be only one item selected as per the plugin.xml
        final Object element = sel.getFirstElement();
        if (element instanceof TmfAnalysisOutputElement) {
            fOutputElement = (TmfAnalysisOutputElement) element;
        }
    }

    return (fOutputElement != null);
}
 
Example 7
Source File: OpenExperimentHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {

    // Check if we are closing down
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    // Get the selection
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return false;
    }
    final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    final ISelection selection = selectionProvider.getSelection();

    // Make sure there is only one selection and that it is an experiment
    fExperiment = null;
    if (selection instanceof TreeSelection) {
        final TreeSelection sel = (TreeSelection) selection;
        // There should be only one item selected as per the plugin.xml
        final Object element = sel.getFirstElement();
        if (element instanceof TmfExperimentElement) {
            fExperiment = (TmfExperimentElement) element;
        }
    }

    // We only enable opening from the Traces folder for now
    return ((fExperiment != null) && (!fExperiment.getTraces().isEmpty()));
}
 
Example 8
Source File: AbstractJavaCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IWorkbenchSite getSite() {
	IWorkbenchPage page= JavaPlugin.getActivePage();
	if (page != null) {
		IWorkbenchPart part= page.getActivePart();
		if (part != null)
			return part.getSite();
	}
	return null;
}
 
Example 9
Source File: NewJavaWorkingSetWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private PackageExplorerPart getActivePackageExplorer() {
	IWorkbenchPage page= JavaPlugin.getActivePage();
	if (page != null) {
		IWorkbenchPart activePart= page.getActivePart();
		if (activePart instanceof PackageExplorerPart) {
			return (PackageExplorerPart) activePart;
		}
	}
	return null;
}
 
Example 10
Source File: CopyHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return null;
    }
    IWorkbenchPage page = window.getActivePage();
    FilterView part = (FilterView) page.getActivePart();
    ISelection selection = getSelection(part);

    LocalSelectionTransfer.getTransfer().setSelection(selection);
    LocalSelectionTransfer.getTransfer().setSelectionSetTime(System.currentTimeMillis());
    return null;
}
 
Example 11
Source File: NewSarlProjectWizard.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the active part in the workbench.
 *
 * @return the active part.
 */
IWorkbenchPart getActivePart() {
	final IWorkbenchWindow activeWindow = getWorkbench().getActiveWorkbenchWindow();
	if (activeWindow != null) {
		final IWorkbenchPage activePage = activeWindow.getActivePage();
		if (activePage != null) {
			return activePage.getActivePart();
		}
	}
	return null;
}
 
Example 12
Source File: HelpHandler.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * the command has been executed, so extract extract the needed information from the application
 * context.
 */
public Object execute(ExecutionEvent event) throws ExecutionException{
	IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
	
	// we use the view's class name as context id
	String contextId = null;
	IWorkbenchPage activePage = window.getActivePage();
	if (activePage != null) {
		IWorkbenchPart activePart = activePage.getActivePart();
		if (activePart != null) {
			contextId = activePart.getClass().getName();
		}
	}
	
	// TODO DEBUG
	System.out.println("DEBUG: " + contextId);
	
	if (contextId != null) {
		// activate view
		try {
			IViewPart view =
				Hub.plugin.getWorkbench().getActiveWorkbenchWindow()
					.getActivePage()
					.showView(WikiView.ID);
			if (view != null && view instanceof WikiView) {
				WikiView wikiView = (WikiView) view;
				wikiView.setPage(contextId);
			}
		} catch (Exception ex) {
			ExHandler.handle(ex);
		}
	}
	
	return null;
}
 
Example 13
Source File: DeleteAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Hides all the working sets in the list from the Package Explorer.
 * 
 * @param selection the selection of working sets 
 * @since 3.8
 */
private void hideWorkingSets(List<IWorkingSet> selection) {
	IWorkbenchPage page= JavaPlugin.getActivePage();
	if (page != null) {
		IWorkbenchPart activePart= page.getActivePart();
		if (activePart instanceof PackageExplorerPart) {
			PackageExplorerPart packagePart= (PackageExplorerPart) activePart;
			WorkingSetModel model= packagePart.getWorkingSetModel();
			List<IWorkingSet> activeWorkingSets= new ArrayList<IWorkingSet>(Arrays.asList(model.getActiveWorkingSets()));
			activeWorkingSets.removeAll(selection);
			model.setActiveWorkingSets(activeWorkingSets.toArray(new IWorkingSet[activeWorkingSets.size()]));
		}
	}
}
 
Example 14
Source File: SelectTracesHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {

    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    // Get the selection
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return false;
    }
    ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    ISelection selection = selectionProvider.getSelection();

    // Make sure there is only one selection and that it is an experiment
    fExperiment = null;
    if (selection instanceof TreeSelection) {
        TreeSelection sel = (TreeSelection) selection;
        // There should be only one item selected as per the plugin.xml
        Object element = sel.getFirstElement();
        if (element instanceof TmfExperimentElement) {
            fExperiment = (TmfExperimentElement) element;
        }
    }

    return (fExperiment != null);
}
 
Example 15
Source File: WorkbenchUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static Shell getActivePartShell() {
      IWorkbenchPage activePage = WorkbenchUtils.getActivePage();
      if (activePage == null) {
      	return null;
      }
IWorkbenchPart activePart = activePage.getActivePart();
if (activePart == null) {
      	return null;
      }
IWorkbenchPartSite site = activePart.getSite();
if (site == null) {
      	return null;
      }
return site.getShell();
  }
 
Example 16
Source File: WorkbenchUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Fetches the active view.
 * 
 * @return the active view or <code>null</code> if no view is active
 */
public static IViewPart getActiveView() {
    IWorkbenchPage page = getActivePage();
    if (page != null) {
        IWorkbenchPart part = page.getActivePart();
        if (part instanceof IViewPart) {
            return (IViewPart) part;
        }
    }
    return null;
}
 
Example 17
Source File: SelectionUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Underlying implementation of <code>getSelectedResources</code>
 * 
 * @return the list of selected <code>IResource</code> objects, or empty list if none.
 */
protected static List<IResource> getSelectedResources0() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    List<IResource> resources = new ArrayList<IResource>();
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            IWorkbenchPart part = page.getActivePart();
            if (part instanceof IEditorPart) {
                IEditorPart epart = (IEditorPart) part;
                IResource adaptee = (IResource) epart.getEditorInput().getAdapter(IResource.class);
                if (adaptee != null) {
                	resources.add(adaptee);
                }
            }
            else if (part != null) {
                IWorkbenchPartSite site = part.getSite();
                if(site != null) {
                    ISelectionProvider provider = site.getSelectionProvider();
                    if (provider != null) {
                        ISelection selection = provider.getSelection();
                        resources = getObjectsFromStructuredSelection(selection, IResource.class);
                    }
                }
            }
        }
    }
    return resources;
}
 
Example 18
Source File: SelectedResourceManager.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow)
 */
public void windowActivated(IWorkbenchWindow window) {
    ISelectionService service = window.getSelectionService(); 
    service.addSelectionListener(this);
    IWorkbenchPage page = window.getActivePage();
    if (page != null) {
        IWorkbenchPart part = page.getActivePart();
        if (part != null) {             
            ISelection selection = service.getSelection();
            if (selection != null) {
                selectionChanged(part, selection);
            }
        }
    }
}
 
Example 19
Source File: WorkbenchHelper.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public static IWorkbenchPart getActivePart() {
	final IWorkbenchPage page = getPage();
	if (page != null) { return page.getActivePart(); }
	return null;
}
 
Example 20
Source File: JavaSearchPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void initSelections() {
	ISelection sel= getContainer().getSelection();

	IWorkbenchPage activePage= JavaPlugin.getActivePage();
	if (activePage != null) {
		IWorkbenchPart activePart= activePage.getActivePart();
		if (activePart instanceof JavaEditor) {
			JavaEditor javaEditor= (JavaEditor) activePart;
			if (javaEditor.isBreadcrumbActive()) {
				sel= javaEditor.getBreadcrumb().getSelectionProvider().getSelection();
			}
		}
	}

	SearchPatternData initData= null;

	if (sel instanceof IStructuredSelection) {
		initData= tryStructuredSelection((IStructuredSelection) sel);
	} else if (sel instanceof ITextSelection) {
		IEditorPart activeEditor= getActiveEditor();
		if (activeEditor instanceof JavaEditor) {
			try {
				IJavaElement[] elements= SelectionConverter.codeResolve((JavaEditor) activeEditor);
				if (elements != null && elements.length > 0) {
					initData= determineInitValuesFrom(elements[0]);
				}
			} catch (JavaModelException e) {
				// ignore
			}
		}
		if (initData == null) {
			initData= trySimpleTextSelection((ITextSelection) sel);
		}
	}
	if (initData == null) {
		initData= getDefaultInitValues();
	}

	fInitialData= initData;
	fJavaElement= initData.getJavaElement();
	fCaseSensitive.setSelection(initData.isCaseSensitive());
	fCaseSensitive.setEnabled(fJavaElement == null);

	setSearchFor(initData.getSearchFor());
	setLimitTo(initData.getSearchFor(), initData.getLimitTo());
	setIncludeMask(initData.getIncludeMask());
	setMatchLocations(initData.getMatchLocations());

	fPattern.setText(initData.getPattern());
}