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

The following examples show how to use org.eclipse.ui.IWorkbenchPage#addPartListener() . 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: CodeRecommendationController.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void init() {
	super.init();

	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	activeEditorOnPageListener = new ActiveEditorOnPageListener(page);
	page.addPartListener(activeEditorOnPageListener);
	activeEditorOnPageListener.checkEditorInWindow();

	CodeRecommendationResultsModel model = new CodeRecommendationResultsModel();
	CodeRecommendationResultsView view = new CodeRecommendationResultsView();
	CodeRecommendationResultsController controller = new CodeRecommendationResultsController(this, model, view);
	controller.init();

	getView().showResults(view);
}
 
Example 2
Source File: OpenDocumentTracker.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Inject(optional=true)
protected void initialize(final IWorkbench workbench) {
	Assert.isNotNull(Display.getCurrent());
	partListener = new PartListener();
	pageListener = new PageListener();
	for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
		window.addPageListener(pageListener);
		for (IWorkbenchPage page : window.getPages()) {
			page.addPartListener(partListener);
			for (IEditorReference editorRef : page.getEditorReferences()) {
				Pair<URI, IXtextDocument> entry = getEntry(editorRef);
				if (entry != null) {
					resourceUri2document.put(entry.getFirst(), entry.getSecond());
				}
			}
		}
	}
}
 
Example 3
Source File: PackageExplorerPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void setLinkingEnabled(boolean enabled) {
	fLinkingEnabled= enabled;
	saveDialogSettings();

	IWorkbenchPage page= getSite().getPage();
	if (enabled) {
		page.addPartListener(fLinkWithEditorListener);

		IEditorPart editor = page.getActiveEditor();
		if (editor != null)
			editorActivated(editor);
	} else {
		page.removePartListener(fLinkWithEditorListener);
	}
	fOpenAndLinkWithEditorHelper.setLinkWithEditor(enabled);
}
 
Example 4
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Makes sure that the editor's folding state is correct the next time
 * it becomes visible. If it already is visible, it toggles the folding
 * state. If not, it either registers a part listener to toggle folding
 * when the editor becomes visible, or cancels an already registered
 * runner.
 */
public void runWhenNextVisible() {
	// if there is one already: toggling twice is the identity
	if (fFoldingRunner != null) {
		fFoldingRunner.cancel();
		return;
	}
	IWorkbenchPartSite site= getSite();
	if (site != null) {
		IWorkbenchPage page= site.getPage();
		if (!page.isPartVisible(JavaEditor.this)) {
			// if we're not visible - defer until visible
			fPage= page;
			fFoldingRunner= this;
			page.addPartListener(this);
			return;
		}
	}
	// we're visible - run now
	toggleFolding();
}
 
Example 5
Source File: AllInOneWorkbenchListener.java    From typescript.java with MIT License 5 votes vote down vote up
private void hookListeners(IWorkbenchPage page) {
	IPerspectiveDescriptor perspective = page.getPerspective();
	if (perspective != null) {
		perspectiveActivated(page, perspective);
	}
	page.addPartListener(this);
}
 
Example 6
Source File: JSDTEditorTracker.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public void pageOpened(IWorkbenchPage page) {
	IEditorReference[] rs = page.getEditorReferences();
	for (IEditorReference r : rs) {
		IEditorPart part = r.getEditor(false);
		if (part != null) {
			editorOpened(part);
		}
	}
	page.addPartListener(this);
}
 
Example 7
Source File: EditorBoundViewPart.java    From depan with Apache License 2.0 5 votes vote down vote up
@Override
public void createPartControl(Composite parentComposite) {
  IWorkbenchPage parentPage = getViewSite().getPage();
  editor = getAcceptableEditor(parentPage.getActiveEditor());
  createGui(parentComposite);
  parentPage.addPartListener(partListener);
}
 
Example 8
Source File: OccurrencesSearchResultPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void install(IWorkbenchPage page) {
	page.addPartListener(this);
	fIsVisible= page.isPartVisible(getViewPart());
	if (fIsVisible) {
		installOnActiveEditor(page);
	}
}
 
Example 9
Source File: BasicJavaEditorActionContributor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void init(IActionBars bars, IWorkbenchPage page) {
	fToggleBreadcrumbAction= new ToggleBreadcrumbAction(page);
	Iterator<RetargetAction> e= fPartListeners.iterator();
	while (e.hasNext())
		page.addPartListener(e.next());

	super.init(bars, page);

	bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
	bars.setGlobalActionHandler(IJavaEditorActionDefinitionIds.TOGGLE_MARK_OCCURRENCES, fToggleMarkOccurrencesAction);
	bars.setGlobalActionHandler(IJavaEditorActionDefinitionIds.TOGGLE_BREADCRUMB, fToggleBreadcrumbAction);
}
 
Example 10
Source File: TerminologyViewPart.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@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"));
}
 
Example 11
Source File: TerminologyViewPart.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@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"));
}
 
Example 12
Source File: CompletionMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.minibuffer.HistoryMinibuffer#addOtherListeners(IWorkbenchPage, ISourceViewer, StyledText)
 */
@Override
protected void addOtherListeners(IWorkbenchPage page, ISourceViewer viewer, StyledText widget) {
	if (page != null) {
		page.addPartListener(this);
	}
	super.addOtherListeners(page, viewer, widget);
}
 
Example 13
Source File: CoolbarToolControl.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void loadContributions(IWorkbenchPage page) {
    contributions.stream().map(CustomToolItem::getContributionItem).filter(IPartListener.class::isInstance)
            .forEach(partListener -> page.removePartListener((IPartListener) partListener));
    contributions.clear();

    final IConfigurationElement[] elements = BonitaStudioExtensionRegistryManager.getInstance()
            .getConfigurationElements(
                    "org.bonitasoft.studio.coolbarContributionItem");
    if (elements.length >= MAX_CONTRIBUTION_SIZE) {
        throw new RuntimeException("Too many coolbar contributions defined");
    }
    for (int i = 0; i < MAX_CONTRIBUTION_SIZE; i++) {
        final IConfigurationElement element = findContributionForPosition(i, elements);
        if (element != null) {
            try {
                final IBonitaContributionItem item = (IBonitaContributionItem) element
                        .createExecutableExtension(CLASS);
                if (contributions.size() > i && item instanceof SeparatorCoolbarItem) {
                    final IBonitaContributionItem previousItem = contributions.get(i - 1).getContributionItem();
                    if (previousItem instanceof SeparatorCoolbarItem) {
                        item.setVisible(false);
                    }
                }
                if (item.isVisible()) {
                    if (item instanceof SaveCoolbarItem) {
                        page.addPartListener((IPartListener) item);
                        ((SaveCoolbarItem) item).partOpened(page.getActivePart());
                    }
                    contributions.add(new CustomToolItem(item));
                }
            } catch (final CoreException e) {
                BonitaStudioLog.error(e);
            }
        }
    }
}
 
Example 14
Source File: OpenDocumentTracker.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void pageOpened(IWorkbenchPage page) {
	page.addPartListener(partListener);
}
 
Example 15
Source File: EditorTracker.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void pageOpened(IWorkbenchPage page) {
	page.addPartListener(this);
}
 
Example 16
Source File: TecoRegister.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
public void addListener(IPartListener2 listener) {
	IWorkbenchPage page = EmacsPlusUtils.getWorkbenchPage(); 
	if (page != null) {
		page.addPartListener(listener);
	}
}