Search in sources :

Example 46 with IEditorReference

use of org.eclipse.ui.IEditorReference in project translationstudio8 by heartsome.

the class ImportProjectWizardPage2 method getAllOpenedIFile.

/**
	 * 获取所有已经被打开的文件
	 * @return
	 */
private Map<IFile, IEditorPart> getAllOpenedIFile() {
    Map<IFile, IEditorPart> openedIfileMap = new HashMap<IFile, IEditorPart>();
    IEditorReference[] referenceArray = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    for (IEditorReference reference : referenceArray) {
        IEditorPart editor = reference.getEditor(true);
        // 如果这是一个 nattable 编辑器
        if (XLIFF_EDITOR_ID.equals(editor.getSite().getId())) {
            IXliffEditor xlfEditor = (IXliffEditor) editor;
            if (xlfEditor.isMultiFile()) {
                for (File file : xlfEditor.getMultiFileList()) {
                    openedIfileMap.put(ResourceUtils.fileToIFile(file.getAbsolutePath()), editor);
                }
            } else {
                openedIfileMap.put(((FileEditorInput) editor.getEditorInput()).getFile(), editor);
            }
        } else {
            // 其他情况,直接将文件丢进去就行了
            openedIfileMap.put(((FileEditorInput) editor.getEditorInput()).getFile(), editor);
        }
    }
    return openedIfileMap;
}
Also used : IFile(org.eclipse.core.resources.IFile) IEditorReference(org.eclipse.ui.IEditorReference) HashMap(java.util.HashMap) IEditorPart(org.eclipse.ui.IEditorPart) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 47 with IEditorReference

use of org.eclipse.ui.IEditorReference in project xtext-eclipse by eclipse.

the class OpenDocumentTracker method initialize.

@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());
                }
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPageListener(org.eclipse.ui.IPageListener) URI(org.eclipse.emf.common.util.URI) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Inject(com.google.inject.Inject)

Example 48 with IEditorReference

use of org.eclipse.ui.IEditorReference in project cubrid-manager by CUBRID.

the class CubridWorkbenchContrItem method closeAllEditorAndViewInDatabase.

/**
	 * Close all editor and view part related with this CUBRID Manager database
	 * node,not include query editor
	 *
	 * @param databaseNode the CubridDatabase object
	 * @param eventType CubridNodeChangedEventType
	 */
public void closeAllEditorAndViewInDatabase(CubridDatabase databaseNode, CubridNodeChangedEventType eventType) {
    IWorkbenchPage page = LayoutUtil.getActivePage();
    if (page == null) {
        return;
    }
    IEditorReference[] editorRefArr = page.getEditorReferences();
    for (int i = 0; editorRefArr != null && i < editorRefArr.length; i++) {
        IEditorReference editorRef = editorRefArr[i];
        try {
            IEditorInput editorInput = editorRef.getEditorInput();
            if (!(editorInput instanceof ISchemaNode)) {
                continue;
            }
            ISchemaNode schemaNode = ((ISchemaNode) editorInput);
            ISchemaNode dbNode = schemaNode.getDatabase();
            String type = schemaNode.getType();
            boolean isDbSpaceEditor = NodeType.contains(type, new String[] { CubridNodeType.DATABASE, CubridNodeType.DBSPACE_FOLDER, CubridNodeType.GENERIC_VOLUME_FOLDER, CubridNodeType.GENERIC_VOLUME, CubridNodeType.DATA_VOLUME_FOLDER, CubridNodeType.DATA_VOLUME, CubridNodeType.INDEX_VOLUME_FOLDER, CubridNodeType.INDEX_VOLUME, CubridNodeType.TEMP_VOLUME_FOLDER, CubridNodeType.TEMP_VOLUME, CubridNodeType.LOG_VOLUEM_FOLDER, CubridNodeType.ACTIVE_LOG_FOLDER, CubridNodeType.ACTIVE_LOG, CubridNodeType.ARCHIVE_LOG_FOLDER, CubridNodeType.ARCHIVE_LOG });
            boolean isClose = true;
            if (isDbSpaceEditor) {
                isClose = !databaseNode.isLogined() || CubridNodeChangedEventType.NODE_REMOVE == eventType || CubridNodeChangedEventType.DATABASE_LOGOUT == eventType;
            }
            if (!isClose) {
                continue;
            }
            if (dbNode.getId().equals(databaseNode.getId())) {
                page.closeEditor(editorRef.getEditor(false), true);
            }
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    }
    IViewReference[] viewRefArr = page.getViewReferences();
    if (viewRefArr == null || viewRefArr.length == 0) {
        return;
    }
    for (IViewReference viewRef : viewRefArr) {
        IViewPart viewPart = viewRef.getView(false);
        if (!(viewPart instanceof CubridViewPart)) {
            continue;
        }
        CubridViewPart cubridViewPart = (CubridViewPart) viewPart;
        ICubridNode cubridNode = cubridViewPart.getCubridNode();
        if (!(cubridNode instanceof ISchemaNode)) {
            continue;
        }
        ICubridNode cubridDatabaseNode = ((ISchemaNode) cubridNode).getDatabase();
        if (cubridDatabaseNode.getId().equals(databaseNode.getId())) {
            page.hideView(viewPart);
        }
    }
}
Also used : IViewPart(org.eclipse.ui.IViewPart) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) PartInitException(org.eclipse.ui.PartInitException) IEditorReference(org.eclipse.ui.IEditorReference) CubridViewPart(com.cubrid.common.ui.spi.part.CubridViewPart) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput)

Example 49 with IEditorReference

use of org.eclipse.ui.IEditorReference in project cubrid-manager by CUBRID.

the class CubridWorkbenchContrItem method closeAllEditorAndViewInServer.

/**
	 * Close all editor and view part related with this CUBRID Manager server
	 * node,not include query editor
	 *
	 * @param serverNode the ICubridNode object
	 * @param isSaved the boolean value,if can be saved
	 * @return boolean whether all editors are closed
	 */
public static boolean closeAllEditorAndViewInServer(ICubridNode serverNode, boolean isSaved) {
    boolean isCloseAll = true;
    IWorkbenchPage page = LayoutUtil.getActivePage();
    if (page == null) {
        return isCloseAll;
    }
    IEditorReference[] editorRefArr = page.getEditorReferences();
    if (editorRefArr != null && editorRefArr.length > 0) {
        for (IEditorReference editorRef : editorRefArr) {
            try {
                IEditorInput editorInput = editorRef.getEditorInput();
                if (!(editorInput instanceof ICubridNode)) {
                    continue;
                }
                ICubridNode node = ((ICubridNode) editorInput).getServer();
                if (node != null && node.getId().equals(serverNode.getId())) {
                    boolean isClosed = page.closeEditor(editorRef.getEditor(false), isSaved);
                    if (!isClosed) {
                        isCloseAll = false;
                    }
                }
            } catch (PartInitException e) {
                LOGGER.error("", e);
            }
        }
    }
    IViewReference[] viewRefArr = page.getViewReferences();
    if (viewRefArr != null && viewRefArr.length > 0) {
        for (IViewReference viewRef : viewRefArr) {
            IViewPart viewPart = viewRef.getView(false);
            if (!(viewPart instanceof CubridViewPart)) {
                continue;
            }
            CubridViewPart cubridViewPart = (CubridViewPart) viewPart;
            ICubridNode cubridNode = cubridViewPart.getCubridNode();
            if (cubridNode == null) {
                continue;
            }
            ICubridNode cubridServerNode = cubridNode.getServer();
            if (cubridServerNode.getId().equals(serverNode.getId())) {
                page.hideView(viewPart);
            }
        }
    }
    return isCloseAll;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IEditorReference(org.eclipse.ui.IEditorReference) CubridViewPart(com.cubrid.common.ui.spi.part.CubridViewPart) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 50 with IEditorReference

use of org.eclipse.ui.IEditorReference in project sling by apache.

the class StatusLineUtils method getStatusLineManager.

private static IStatusLineManager getStatusLineManager() {
    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (activeWorkbenchWindow == null) {
        return null;
    }
    IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
    if (activePage == null) {
        return null;
    }
    IEditorPart activeEditor = activePage.getActiveEditor();
    if (activeEditor != null) {
        return activeEditor.getEditorSite().getActionBars().getStatusLineManager();
    }
    IViewReference[] viewRefs = activePage.getViewReferences();
    if (viewRefs != null) {
        for (IViewReference aViewRef : viewRefs) {
            IViewPart view = aViewRef.getView(false);
            if (view != null) {
                return view.getViewSite().getActionBars().getStatusLineManager();
            }
        }
    }
    IEditorReference[] editorRefs = activePage.getEditorReferences();
    if (editorRefs != null) {
        for (IEditorReference anEditorRef : editorRefs) {
            IEditorPart editor = anEditorRef.getEditor(false);
            if (editor != null) {
                return editor.getEditorSite().getActionBars().getStatusLineManager();
            }
        }
    }
    IWorkbenchPart activePart = activePage.getActivePart();
    if (activePart == null) {
        return null;
    }
    IWorkbenchPartSite site = activePart.getSite();
    if (site instanceof IEditorSite) {
        IEditorSite editorSite = (IEditorSite) site;
        return editorSite.getActionBars().getStatusLineManager();
    } else if (site instanceof IViewSite) {
        IViewSite viewSite = (IViewSite) site;
        return viewSite.getActionBars().getStatusLineManager();
    } else {
        return null;
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewSite(org.eclipse.ui.IViewSite) IViewPart(org.eclipse.ui.IViewPart) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) IEditorSite(org.eclipse.ui.IEditorSite)

Aggregations

IEditorReference (org.eclipse.ui.IEditorReference)174 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)83 IEditorPart (org.eclipse.ui.IEditorPart)78 PartInitException (org.eclipse.ui.PartInitException)59 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)55 IFile (org.eclipse.core.resources.IFile)50 IEditorInput (org.eclipse.ui.IEditorInput)49 ArrayList (java.util.ArrayList)34 FileEditorInput (org.eclipse.ui.part.FileEditorInput)28 Item (org.talend.core.model.properties.Item)17 IWorkbench (org.eclipse.ui.IWorkbench)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 IOException (java.io.IOException)12 CoreException (org.eclipse.core.runtime.CoreException)12 ProcessItem (org.talend.core.model.properties.ProcessItem)11 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)10 Path (org.eclipse.core.runtime.Path)10 IProcess2 (org.talend.core.model.process.IProcess2)10