下面列出了怎么用org.eclipse.ui.IWorkbenchPartReference的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* This function is called whenever a Workbench part gains focus. Here, we
* are only interested if the part is an ICEFormEditor. A call to this
* function will occur prior to a part being closed, so just keep track of
* that form's id.
*
* @param partRef
* The workbench part calling this function.
*
* @see IPartListener2#partActivated(IWorkbenchPartReference)
*/
@Override
public void partActivated(IWorkbenchPartReference partRef) {
logger.info("MeshElementTreeView Message: Called partActivated("
+ partRef.getId() + ")");
if (partRef.getId().equals(ICEFormEditor.ID)) {
// Get the activated editor
ICEFormEditor activeEditor = (ICEFormEditor) partRef.getPart(false);
// Pull the form from the editor
Form activeForm = ((ICEFormInput) activeEditor.getEditorInput())
.getForm();
// Record the ID of this form
lastFormItemID = activeForm.getItemID();
}
return;
}
@Override
public void partOpened(IWorkbenchPartReference partRef) {
if (Constants.cryslEditorID.equals(partRef.getId())) {
IResource file = partRef.getPage().getActiveEditor().getEditorInput().getAdapter(IResource.class);
if (Constants.cryslFileEnding.substring(1).equals(file.getFileExtension())) {
IProject projectOfOpenedFile = file.getProject();
try {
if (!CrySLBuilderUtils.hasCrySLBuilder(projectOfOpenedFile)) {
CrySLBuilderUtils.addCrySLBuilderToProject(projectOfOpenedFile);
}
}
catch (CoreException e) {
Activator.getDefault().logError(e);
}
}
}
}
public void partActivated(IWorkbenchPartReference partRef)
{
if (partRef instanceof IViewReference)
{
IViewReference viewRef = (IViewReference) partRef;
String id = viewRef.getId();
if ("org.eclipse.ui.console.ConsoleView".equals(id) || "org.eclipse.jdt.ui.TypeHierarchy".equals(id) //$NON-NLS-1$ //$NON-NLS-2$
|| "org.eclipse.jdt.callhierarchy.view".equals(id)) //$NON-NLS-1$
{
final IViewPart part = viewRef.getView(false);
Display.getCurrent().asyncExec(new Runnable()
{
public void run()
{
hijackView(part, false);
}
});
return;
}
}
if (partRef instanceof IEditorReference)
{
hijackOutline();
}
}
public void partClosed(IWorkbenchPartReference partRef)
{
if (partRef instanceof IEditorReference)
{
IEditorPart part = (IEditorPart) partRef.getPart(false);
if (part instanceof MultiPageEditorPart)
{
MultiPageEditorPart multi = (MultiPageEditorPart) part;
if (pageListener != null)
{
multi.getSite().getSelectionProvider().removeSelectionChangedListener(pageListener);
}
}
}
// If it's a search view, remove any query listeners for it!
else if (partRef instanceof IViewReference)
{
IViewPart view = (IViewPart) partRef.getPart(false);
if (queryListeners.containsKey(view))
{
NewSearchUI.removeQueryListener(queryListeners.remove(view));
}
}
}
/**
* This function is called whenever a Workbench part is closed. If the
* current {@link #editor} is closed, then we need to clear the view's
* contents.
*/
@Override
public void partClosed(IWorkbenchPartReference partRef) {
// If the closed editor is the known active ICEFormEditor, call the
// method to clear the currently active editor and related UI pieces.
IWorkbenchPart part = partRef.getPart(false);
if (part != null && part instanceof ICEFormEditor) {
ICEFormEditor activeEditor = (ICEFormEditor) partRef.getPart(false);
if (activeEditor == editor) {
setActiveEditor(null);
}
}
return;
}
@Override
public void partDeactivated(final IWorkbenchPartReference partRef) {
ThreadUtils.runSafeSync(
log,
new Runnable() {
@Override
public void run() {
toForwardTo.partDeactivated(partRef);
}
});
}
/**
* Maximize a workbench part and wait for one of its controls to be resized.
* Calling this a second time will "un-maximize" the part.
*
* @param partReference
* the {@link IWorkbenchPartReference} which contains the control
* @param controlBot
* a control that should be resized
*/
public static void maximize(IWorkbenchPartReference partReference, AbstractSWTBotControl<?> controlBot) {
final AtomicBoolean controlResized = new AtomicBoolean();
Control control = controlBot.widget;
assertNotNull(control);
UIThreadRunnable.syncExec(new VoidResult() {
@Override
public void run() {
control.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
control.removeControlListener(this);
controlResized.set(true);
}
});
}
});
IWorkbenchPart part = partReference.getPart(false);
assertNotNull(part);
maximize(part);
new SWTBot().waitUntil(new DefaultCondition() {
@Override
public boolean test() throws Exception {
return controlResized.get();
}
@Override
public String getFailureMessage() {
return "Control was not resized";
}
});
}
/**
* This updates the error view. If the error view is not open,
* then the user may have closed it, so nothing is done.
* If the error view is open but the model editor being switched
* to has no errors, then the error view is cleared but not closed.
* If the model editor made visible does have errors, then the error
* view is updated with these errors.
*/
public void partVisible(final IWorkbenchPartReference partRef) {
final IWorkbenchPart part = partRef.getPart(false);
if ((part != null) && (part instanceof ModelEditor)) {
final ModelEditor editor = (ModelEditor) part;
final TLCModelLaunchDataProvider provider;
final Model model = editor.getModel();
if (model.isOriginalTraceShown()) {
provider = TLCOutputSourceRegistry.getModelCheckSourceRegistry().getProvider(model);
} else {
provider = TLCOutputSourceRegistry.getTraceExploreSourceRegistry().getProvider(model);
}
final TLCErrorView errorView = (TLCErrorView) UIHelper.findView(TLCErrorView.ID);
if ((errorView != null) && (provider != null)) {
if (provider.getErrors().size() > 0) {
// Tell the TLCErrorView update function to not open the
// TLCErrorView iff the ModelEditor and the TLCErrorView
// would open in the same part stack (on top of each other).
// This prevents a stackoverflow that results from cyclic
// focus activation when the ModelEditor triggers the
// TLCErrorView to be opened while ModelEditor itself
// becomes visible (see partVisible()).
//
// The steps to reproduce were:
// 0) Open model with errors trace
// 1) Drag the model editor on top of the TLC error view
// 2) Change focus from model editor, to TLC error and spec editor a couple of times
// 3) Run the model
// 4) Cycle focus
// 5) Bam!
TLCErrorView.updateErrorView(editor, !UIHelper.isInSameStack(editor, TLCErrorView.ID));
} else {
errorView.clear();
}
}
}
}
public void partDeactivated(IWorkbenchPartReference partRef)
{
if (partRef instanceof IEditorReference)
{
hijackOutline();
}
}
@Override
public void init(IViewSite site, IMemento memento) throws PartInitException {
init(site);
site.getPage().addPostSelectionListener(this);
site.getPage().addPartListener(new PartAdapter2() {
@Override
public void partClosed(IWorkbenchPartReference partRef) {
if (gridTable == null || gridTable.isDisposed()) {
getSite().getPage().removePartListener(this); // 关闭视图后,移除此监听
} else {
if ("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor".equals(partRef.getId())) {
IEditorReference[] editorReferences = getSite().getPage().getEditorReferences();
if (editorReferences.length == 0) { // 所有编辑器全部关闭的情况下。
synchronized (matchDataContainer) {
matchDataContainer.clear();
if (matcherThread != null) {
matcherThread.interrupt();
}
}
manualTranslationThread.interruptCurrentTask();
tmMatcher.clearDbResources();
copyEnable.resetSelection();
gridTable.removeAll();
sourceText.setText("");
setMatchMessage(null, "", "");
setProcessMessage(null, "", "");
}
}
}
}
});
site.getActionBars().getStatusLineManager().setMessage(Messages.getString("view.MatchViewPart.statusLine"));
}
@Override
public void partClosed(final IWorkbenchPartReference partRef) {
ThreadUtils.runSafeSync(
log,
new Runnable() {
@Override
public void run() {
toForwardTo.partClosed(partRef);
}
});
}
@Override
public void partActivated(final IWorkbenchPartReference partRef) {
ThreadUtils.runSafeSync(
log,
new Runnable() {
@Override
public void run() {
toForwardTo.partActivated(partRef);
}
});
}
@Override
public void partDeactivated(IWorkbenchPartReference partRef) {
IWorkbenchPart fPart= fEditor.getEditorSite().getPart();
if (fPopup != null && ! fPopup.isDisposed() && partRef.getPart(false) == fPart) {
fPopup.setVisible(false);
}
}
@Override
public void partInputChanged(IWorkbenchPartReference ref) {
if (!ref.getId().equals(getSite().getId())) {
IWorkbenchPart workbenchPart = ref.getPart(false);
ISelectionProvider provider = workbenchPart.getSite().getSelectionProvider();
if (provider == null) {
return;
}
ISelection selection = provider.getSelection();
if (selection == null || selection.isEmpty()) {
return;
}
computeAndSetInput(new DefaultWorkbenchPartSelection(ref.getPart(false), selection));
}
}
@Override
public void partDeactivated(IWorkbenchPartReference partRef) {
if (partRef.getId().equals(ICEFormEditor.ID)) {
logger.info("EMFTreeCompositeViewer message: "
+ "EMFFormEditor part deactivated.");
// If the active editor closed, reset the active editor reference.
if (partRef == activeEditorRef) {
activeEditorRef = null;
}
}
return;
}
@Override
public void partHidden(IWorkbenchPartReference partRef) {
IWorkbenchPart part = partRef.getPart(false);
if (part != null && part == AbstractTimeGraphView.this) {
Display.getDefault().asyncExec(() -> {
if (fTimeEventFilterDialog != null) {
fTimeEventFilterDialog.close();
}
});
}
}
@Override
public void partDeactivated(IWorkbenchPartReference partRef) {
IWorkbenchPart fPart = editor.getEditorSite().getPart();
if (popup != null && !popup.isDisposed() && partRef.getPart(false) == fPart) {
popup.setVisible(false);
}
}
@Override
public void init(IViewSite site, IMemento memento) throws PartInitException {
init(site);
final IWorkbenchPage page = site.getPage();
page.addPostSelectionListener(this);
page.addPartListener(new PartAdapter2() {
@Override
public void partClosed(IWorkbenchPartReference partRef) {
if (gridTable == null || gridTable.isDisposed()) {
page.removePartListener(this); // 关闭视图后,移除此监听
} else {
if ("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor".equals(partRef.getId())) {
IEditorReference[] editorReferences = page.getEditorReferences();
if (editorReferences.length == 0) { // 所有编辑器全部关闭的情况下。
matcher.clearResources();
firstAction.setEnabled(false);
copyEnable.resetSelection();
gridTable.removeAll();
}
}
}
}
});
site.getActionBars().getStatusLineManager()
.setMessage(Messages.getString("view.TerminologyViewPart.statusLine"));
}
@Override
public void partHidden(IWorkbenchPartReference partRef) {
IWorkbenchPart part= partRef.getPart(false);
if (part instanceof ContentOutline) {
isViewVisible= false;
}
}
public void partOpened(IWorkbenchPartReference ref) {
}
public void partClosed(IWorkbenchPartReference partRef) {
// nothing to do
}
/**
* {@inheritDoc}
*/
@Override
public void partDeactivated(IWorkbenchPartReference partRef) {
// NOOP
}
public void partHidden(IWorkbenchPartReference partRef) {
}
@Override
public void partOpened(IWorkbenchPartReference partRef) {
// nothing to do
}
/**
* {@inheritDoc}
*/
@Override
public void partVisible(IWorkbenchPartReference partRef) {
// NOOP
}
public void windowActivated(IWorkbenchWindow window) {
IWorkbenchPartReference ref= window.getPartService().getActivePartReference();
if (isJavaEditor(ref) && !isActiveEditor(ref))
activeJavaEditorChanged(ref.getPart(true));
}
@Override
public void partActivated(final IWorkbenchPartReference partRef) {
// Does nothing by default.
}
public void partClosed(IWorkbenchPartReference partRef) {
//
}
@Override
public void partClosed(final IWorkbenchPartReference partRef) {
// Does nothing by default.
}
public void partClosed(IWorkbenchPartReference partRef) {
// ignored
}