类org.eclipse.ui.part.ShowInContext源码实例Demo

下面列出了怎么用org.eclipse.ui.part.ShowInContext的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: n4js   文件: N4JSEditor.java
/**
 * Provides input so that the Project Explorer can locate the editor's input in its tree.
 */
@Override
public ShowInContext getShowInContext() {
	IEditorInput editorInput = getEditorInput();
	if (editorInput instanceof FileEditorInput) {
		FileEditorInput fei = (FileEditorInput) getEditorInput();
		return new ShowInContext(fei.getFile(), null);
	} else if (editorInput instanceof XtextReadonlyEditorInput) {
		XtextReadonlyEditorInput readOnlyEditorInput = (XtextReadonlyEditorInput) editorInput;
		IStorage storage;
		try {
			storage = readOnlyEditorInput.getStorage();
			return new ShowInContext(storage.getFullPath(), null);
		} catch (CoreException e) {
			// Do nothing
		}
	}
	return new ShowInContext(null, null);
}
 
源代码2 项目: KaiZen-OpenAPI-Editor   文件: QuickOutline.java
protected void handleSelection() {
    ITreeSelection selection = (ITreeSelection) treeViewer.getSelection();

    if (selection != null) {
        Object element = selection.getFirstElement();

        if (element instanceof AbstractNode) {
            Model model = ((AbstractNode) element).getModel();

            if (model.getPath() != null) {
                DocumentUtils.openAndReveal(model.getPath(), selection);
            } else {
                editor.show(new ShowInContext(null, selection));
            }
        }
    }
}
 
源代码3 项目: KaiZen-OpenAPI-Editor   文件: JsonEditor.java
@Override
public boolean show(ShowInContext context) {
    ISelection selection = context.getSelection();

    if (selection instanceof IStructuredSelection) {
        Object selected = ((IStructuredSelection) selection).getFirstElement();

        if (selected instanceof AbstractNode) {
            Position position = ((AbstractNode) selected).getPosition(getSourceViewer().getDocument());
            selectAndReveal(position.getOffset(), position.getLength());
            return true;
        }
    }

    return false;
}
 
public boolean show(ShowInContext context) {
	ISelection selection= context.getSelection();
	if (selection instanceof IStructuredSelection) {
		// fix for 64634 Navigate/Show in/Package Explorer doesn't work
		IStructuredSelection structuredSelection= ((IStructuredSelection) selection);
		if (structuredSelection.size() == 1) {
			int res= tryToReveal(structuredSelection.getFirstElement());
			if (res == IStatus.OK)
				return true;
			if (res == IStatus.CANCEL)
				return false;
		} else if (structuredSelection.size() > 1) {
			selectReveal(structuredSelection);
			return true;
		}
	}

	Object input= context.getInput();
	if (input instanceof IEditorInput) {
		Object elementOfInput= getInputFromEditor((IEditorInput) input);
		return elementOfInput != null && (tryToReveal(elementOfInput) == IStatus.OK);
	}

	return false;
}
 
/**
 * Returns the <code>IShowInTarget</code> for this view.
 *
 * @return the {@link IShowInTarget}
 */
protected IShowInTarget getShowInTarget() {
	return new IShowInTarget() {
		public boolean show(ShowInContext context) {
			ISelection sel= context.getSelection();
			if (sel instanceof ITextSelection) {
				ITextSelection tsel= (ITextSelection) sel;
				int offset= tsel.getOffset();
				IJavaElement element= fEditor.getElementAt(offset);
				if (element != null) {
					setSelection(new StructuredSelection(element));
					return true;
				}
			} else if (sel instanceof IStructuredSelection) {
				setSelection(sel);
				return true;
			}
			return false;
		}
	};
}
 
源代码6 项目: Pydev   文件: PydevPackageExplorer.java
/**
 * Implements the 'show in...' action
 */
@Override
public boolean show(ShowInContext context) {
    Object elementOfInput = null;
    ISelection selection = context.getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = ((IStructuredSelection) selection);
        if (structuredSelection.size() == 1) {
            elementOfInput = structuredSelection.getFirstElement();
        }
    }

    Object input = context.getInput();
    if (input instanceof IEditorInput) {
        elementOfInput = getElementOfInput((IEditorInput) context.getInput());
    }

    return elementOfInput != null && tryToReveal(elementOfInput);
}
 
源代码7 项目: goclipse   文件: LangOutlinePage.java
protected IShowInTarget getShowInTarget() {
	return new IShowInTarget() {
		@Override
		public boolean show(ShowInContext context) {
			StructureElement structureElement = getStructureElementFor(context.getSelection());
			
			if(structureElement != null) {
				setSelection(new StructuredSelection(structureElement));
				return true;
			}
			
			return false;
		}

	};
}
 
public Object getAdapter(Class adapter) {
	if (IShowInTargetList.class.equals(adapter)) {
		return SHOW_IN_TARGET_LIST;
	}

	if (adapter == IShowInSource.class) {
		ISelectionProvider selectionProvider= getSite().getSelectionProvider();
		if (selectionProvider == null)
			return null;

		ISelection selection= selectionProvider.getSelection();
		if (selection instanceof IStructuredSelection) {
			IStructuredSelection structuredSelection= ((StructuredSelection)selection);
			final Set newSelection= new HashSet(structuredSelection.size());
			Iterator iter= structuredSelection.iterator();
			while (iter.hasNext()) {
				Object element= iter.next();
				if (element instanceof LineElement)
					element= ((LineElement)element).getParent();
				newSelection.add(element);
			}

			return new IShowInSource() {
				public ShowInContext getShowInContext() {
					return new ShowInContext(null, new StructuredSelection(new ArrayList(newSelection)));
				}
			};
		}
		return null;
	}

	return null;
}
 
源代码9 项目: KaiZen-OpenAPI-Editor   文件: DocumentUtils.java
/**
 * Opens the editor for the file located at the given path and reveal the selection.
 * 
 * @param path
 * @param selection
 */
public static void openAndReveal(IPath path, ISelection selection) {
    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    final IFile file = root.getFile(path);
    final IEditorPart editor = openEditor(file);

    if (editor instanceof IShowInTarget) {
        IShowInTarget showIn = (IShowInTarget) editor;
        showIn.show(new ShowInContext(null, selection));
    }
}
 
/**
 * Returns the <code>IShowInSource</code> for this view.
 * @return the <code>IShowInSource</code>
 */
protected IShowInSource getShowInSource() {
	return new IShowInSource() {
		public ShowInContext getShowInContext() {
			return new ShowInContext(
				getTreeViewer().getInput(),
				getTreeViewer().getSelection());
		}
	};
}
 
/**
 * @return the <code>IShowInSource</code> for this view.
 */
private IShowInSource getShowInSource() {
	return new IShowInSource() {
		public ShowInContext getShowInContext() {
			return new ShowInContext(null, fSelectionProviderMediator.getSelection());
		}
	};
}
 
/**
 * Returns the <code>IShowInSource</code> for this view.
 *
 * @return the {@link IShowInSource}
 */
protected IShowInSource getShowInSource() {
	return new IShowInSource() {
		public ShowInContext getShowInContext() {
			return new ShowInContext(
				null,
				getSite().getSelectionProvider().getSelection());
		}
	};
}
 
/**
 * @return Returns the <code>IShowInSource</code> for this view.
 */
protected IShowInSource getShowInSource() {
	return new IShowInSource() {
		public ShowInContext getShowInContext() {
			return new ShowInContext(
				null,
			getSite().getSelectionProvider().getSelection());
		}
	};
}
 
/**
 * Returns the <code>IShowInSource</code> for this view.
 * @return returns the <code>IShowInSource</code>
 */
protected IShowInSource getShowInSource() {
	return new IShowInSource() {
		public ShowInContext getShowInContext() {
			return new ShowInContext(
				null,
			getSite().getSelectionProvider().getSelection());
		}
	};
}
 
源代码15 项目: Pydev   文件: AbstractSearchIndexResultPage.java
public Object getAdapter(Class<?> adapter) {
    if (IShowInTargetList.class.equals(adapter)) {
        return SHOW_IN_TARGET_LIST;
    }

    if (adapter == IShowInSource.class) {
        ISelectionProvider selectionProvider = getSite().getSelectionProvider();
        if (selectionProvider == null) {
            return null;
        }

        ISelection selection = selectionProvider.getSelection();
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection structuredSelection = ((StructuredSelection) selection);
            final Set<Object> newSelection = new HashSet<>(structuredSelection.size());
            Iterator<?> iter = structuredSelection.iterator();
            while (iter.hasNext()) {
                Object element = iter.next();
                if (element instanceof ICustomLineElement) {
                    element = ((ICustomLineElement) element).getParent();
                }
                newSelection.add(element);
            }

            return new IShowInSource() {
                @Override
                public ShowInContext getShowInContext() {
                    return new ShowInContext(null, new StructuredSelection(new ArrayList<>(newSelection)));
                }
            };
        }
        return null;
    }

    return null;
}
 
源代码16 项目: scava   文件: CrossflowDiagramEditor.java
/**
* @generated
*/
public ShowInContext getShowInContext() {
	return new ShowInContext(getEditorInput(), getNavigatorSelection());
}
 
源代码17 项目: xtext-xtend   文件: DerivedSourceView.java
@Override
public boolean show(ShowInContext context) {
	selectionChanged(getSite().getPage().getActiveEditor(), context.getSelection());
	return true;
}
 
@Override
public void selectionChanged(SelectionChangedEvent event) {
    super.selectionChanged(event);

    showInTarget.show(new ShowInContext(null, event.getSelection()));
}
 
源代码19 项目: KaiZen-OpenAPI-Editor   文件: JsonEditor.java
@Override
public ShowInContext getShowInContext() {
    return new ShowInContext(getEditorInput(), new StructuredSelection());
}
 
@Override
public Object getAdapter(Class required) {

	if (IContentOutlinePage.class.equals(required)) {
		if (fOutlinePage == null && getSourceViewer() != null && isCalledByOutline())
			fOutlinePage= createOutlinePage();
		return fOutlinePage;
	}

	if (IEncodingSupport.class.equals(required))
		return fEncodingSupport;

	if (required == IShowInTargetList.class) {
		return new IShowInTargetList() {
			public String[] getShowInTargetIds() {
				return new String[] { JavaUI.ID_PACKAGES, IPageLayout.ID_OUTLINE, JavaPlugin.ID_RES_NAV };
			}

		};
	}

	if (required == IShowInSource.class) {
		IJavaElement inputJE= getInputJavaElement();
		if (inputJE instanceof ICompilationUnit && !JavaModelUtil.isPrimary((ICompilationUnit) inputJE))
			return null;

		return new IShowInSource() {
			public ShowInContext getShowInContext() {
				return new ShowInContext(null, null) {
					/*
					 * @see org.eclipse.ui.part.ShowInContext#getInput()
					 * @since 3.4
					 */
					@Override
					public Object getInput() {
						if (isBreadcrumbActive())
							return null;

						return getEditorInput();
					}

					/*
					 * @see org.eclipse.ui.part.ShowInContext#getSelection()
					 * @since 3.3
					 */
					@Override
					public ISelection getSelection() {
						if (isBreadcrumbActive())
							return getBreadcrumb().getSelectionProvider().getSelection();

						try {
							IJavaElement je= SelectionConverter.getElementAtOffset(JavaEditor.this);
							if (je != null)
								return new StructuredSelection(je);
							return null;
						} catch (JavaModelException ex) {
							return null;
						}
					}
				};
			}
		};
	}

	if (required == IJavaFoldingStructureProvider.class)
		return fProjectionModelUpdater;

	if (fProjectionSupport != null) {
		Object adapter= fProjectionSupport.getAdapter(getSourceViewer(), required);
		if (adapter != null)
			return adapter;
	}

	if (required == IContextProvider.class) {
		if (isBreadcrumbActive()) {
			return JavaUIHelp.getHelpContextProvider(this, IJavaHelpContextIds.JAVA_EDITOR_BREADCRUMB);
		} else {
			return JavaUIHelp.getHelpContextProvider(this, IJavaHelpContextIds.JAVA_EDITOR);
		}
	}

	return super.getAdapter(required);
}
 
源代码21 项目: Pydev   文件: BaseOutlinePage.java
@Override
public boolean show(ShowInContext context) {
    linkWithEditor.doLinkOutlinePosition(this.editorView, this,
            EditorUtils.createTextSelectionUtils(this.editorView));
    return true;
}
 
源代码22 项目: bonita-studio   文件: ProcessDiagramEditor.java
/**
* @generated
*/
public ShowInContext getShowInContext() {
	return new ShowInContext(getEditorInput(), getNavigatorSelection());
}
 
 类所在包
 类方法
 同包方法