下面列出了org.eclipse.ui.IWorkbenchPage#getActivePart ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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())));
}
@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;
}
/** 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;
}
/**
* @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);
}
}
}
}
/**
* 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;
}
/**
* 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;
}
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();
}
@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);
}
/**
* 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()]));
}
}
}
/**
* 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;
}
@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;
}
@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;
}
private PackageExplorerPart getActivePackageExplorer() {
IWorkbenchPage page= JavaPlugin.getActivePage();
if (page != null) {
IWorkbenchPart activePart= page.getActivePart();
if (activePart instanceof PackageExplorerPart) {
return (PackageExplorerPart) activePart;
}
}
return null;
}
private IWorkbenchSite getSite() {
IWorkbenchPage page= JavaPlugin.getActivePage();
if (page != null) {
IWorkbenchPart part= page.getActivePart();
if (part != null)
return part.getSite();
}
return null;
}
@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()));
}
@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);
}
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;
}
@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);
}
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());
}
public static IWorkbenchPart getActivePart() {
final IWorkbenchPage page = getPage();
if (page != null) { return page.getActivePart(); }
return null;
}