Search in sources :

Example 1 with PartAdapter2

use of net.heartsome.cat.common.ui.listener.PartAdapter2 in project translationstudio8 by heartsome.

the class ApplicationWorkbenchWindowAdvisor method addViewPartVisibleListener.

private void addViewPartVisibleListener(final IWorkbenchWindow window) {
    final ICommandService commandService = (ICommandService) window.getService(ICommandService.class);
    window.getActivePage().addPartListener(new PartAdapter2() {

        private void setStates(String partId) {
            if ("net.heartsome.cat.common.ui.navigator.view".equals(partId)) {
                commandService.refreshElements("net.heartsome.cat.common.ui.navigator.command.OpenNavigatorView", null);
            } else if ("net.heartsome.cat.ts.ui.views.DocumentPropertiesViewPart".equals(partId)) {
                commandService.refreshElements("net.heartsome.cat.ts.ui.handlers.OpenDocumentPropertiesViewCommand", null);
            } else if ("net.heartsome.cat.ts.ui.translation.view.matchview".equals(partId)) {
                commandService.refreshElements("net.heartsome.cat.ts.ui.translation.menu.command.openMatchView", null);
            } else if ("net.heartsome.cat.ts.ui.term.view.termView".equals(partId)) {
                commandService.refreshElements("net.heartsome.cat.ts.ui.term.command.openTermView", null);
            } else if ("net.heartsome.cat.ts.ui.qa.views.QAResultViewPart".equals(partId)) {
                commandService.refreshElements("net.heartsome.cat.ts.ui.qa.handlers.OpenQAResultViewCommand", null);
            } else if ("net.heartsome.cat.ts.websearch.ui.view.BrowserViewPart".equals(partId)) {
                commandService.refreshElements("net.heartsome.cat.ts.websearch.showOrHideView", null);
            }
        }

        /**
			 * 视图打开时
			 * @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
			 */
        public void partOpened(final IWorkbenchPartReference partRef) {
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    setStates(partRef.getId());
                }
            });
        }

        /**
			 * 视图关闭时
			 * @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
			 */
        public void partClosed(IWorkbenchPartReference partRef) {
            if (!partRef.getPage().getWorkbenchWindow().getWorkbench().isClosing()) {
                setStates(partRef.getId());
            }
            // 关闭时,根据是否是合并打开的文件,如果是,标识其是否被存储--robert
            if ("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor".equals(partRef.getId())) {
                if (partRef.getPage().getWorkbenchWindow().getWorkbench().isClosing()) {
                    IXliffEditor xlfEditor = (IXliffEditor) partRef.getPart(true);
                    xlfEditor.setStore(true);
                }
            }
        }
    });
}
Also used : PartAdapter2(net.heartsome.cat.common.ui.listener.PartAdapter2) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) ICommandService(org.eclipse.ui.commands.ICommandService) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 2 with PartAdapter2

use of net.heartsome.cat.common.ui.listener.PartAdapter2 in project translationstudio8 by heartsome.

the class MatchViewPart method init.

@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"));
}
Also used : PartAdapter2(net.heartsome.cat.common.ui.listener.PartAdapter2) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference)

Example 3 with PartAdapter2

use of net.heartsome.cat.common.ui.listener.PartAdapter2 in project translationstudio8 by heartsome.

the class TerminologyViewPart method init.

@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"));
}
Also used : PartAdapter2(net.heartsome.cat.common.ui.listener.PartAdapter2) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference)

Aggregations

PartAdapter2 (net.heartsome.cat.common.ui.listener.PartAdapter2)3 IWorkbenchPartReference (org.eclipse.ui.IWorkbenchPartReference)3 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 ICommandService (org.eclipse.ui.commands.ICommandService)1