Search in sources :

Example 46 with IViewPart

use of org.eclipse.ui.IViewPart 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 47 with IViewPart

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

the class CubridWorkbenchContrItem method openEditorOrView.

/**
	 * Open and reopen the editor or view part of this CUBRID node
	 *
	 * @param cubridNode the ICubridNode object
	 */
public void openEditorOrView(ICubridNode cubridNode) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    if (cubridNode instanceof ISchemaNode) {
        ISchemaNode schemaNode = (ISchemaNode) cubridNode;
        if (schemaNode.getDatabase() != null && !schemaNode.getDatabase().isLogined()) {
            return;
        }
    }
    //close the editor part that has been open
    String editorId = cubridNode.getEditorId();
    String viewId = cubridNode.getViewId();
    IWorkbenchPart workbenchPart = null;
    if (editorId != null && editorId.trim().length() > 0) {
        IEditorPart editorPart = LayoutUtil.getEditorPart(cubridNode, editorId);
        if (editorPart != null) {
            window.getActivePage().closeEditor(editorPart, false);
        }
    } else if (viewId != null && viewId.trim().length() > 0) {
        IViewPart viewPart = LayoutUtil.getViewPart(cubridNode, viewId);
        if (viewPart != null) {
            // monitor view part do not need to close and then open
            if (MONITOR_VIEWID_LST.contains(viewId)) {
                workbenchPart = viewPart;
                window.getActivePage().bringToTop(viewPart);
            } else {
                window.getActivePage().hideView(viewPart);
            }
        }
    }
    String nodeType = cubridNode.getType();
    ISelectionAction logViewAction = null;
    if (NodeType.contains(nodeType, new String[] { CubridNodeType.BROKER_SQL_LOG, CubridNodeType.LOGS_BROKER_ACCESS_LOG, CubridNodeType.LOGS_BROKER_ERROR_LOG, CubridNodeType.LOGS_BROKER_ADMIN_LOG, CubridNodeType.LOGS_SERVER_DATABASE_LOG })) {
        logViewAction = (ISelectionAction) ActionManager.getInstance().getAction(LogViewAction.ID);
        ((LogViewAction) logViewAction).setCubridNode(cubridNode);
    } else if (NodeType.contains(nodeType, new String[] { CubridNodeType.LOGS_MANAGER_ACCESS_LOG, CubridNodeType.LOGS_MANAGER_ERROR_LOG })) {
        logViewAction = (ISelectionAction) ActionManager.getInstance().getAction(ManagerLogViewAction.ID);
        ((ManagerLogViewAction) logViewAction).setCubridNode(cubridNode);
    }
    if (logViewAction != null && logViewAction.isSupported(cubridNode)) {
        logViewAction.run();
        return;
    }
    if (!StringUtil.isEmpty(editorId)) {
        try {
            if (cubridNode instanceof ISchemaNode) {
                CubridDatabase database = ((ISchemaNode) cubridNode).getDatabase();
                // Judge database is started and open DatabaseDashboardEditor
                if (StringUtil.isEqual(editorId, DatabaseDashboardEditor.ID)) {
                    if (!DbRunningType.CS.equals(database.getRunningType())) {
                        return;
                    }
                }
                // if open the table schema editor,firstly load the schema
                if (StringUtil.isEqual(editorId, SchemaInfoEditorPart.ID)) {
                    SchemaInfo newSchema = database.getDatabaseInfo().getSchemaInfo(cubridNode.getName());
                    if (newSchema == null) {
                        CommonUITool.openErrorBox(database.getDatabaseInfo().getErrorMessage());
                        return;
                    }
                }
            }
            workbenchPart = window.getActivePage().openEditor(cubridNode, editorId, true, IWorkbenchPage.MATCH_ID & IWorkbenchPage.MATCH_INPUT);
        } catch (PartInitException e) {
            LOGGER.error("", e);
        }
    } else if (viewId != null && viewId.trim().length() > 0) {
        try {
            if (MONITOR_VIEWID_LST.contains(viewId)) {
                if (workbenchPart == null) {
                    String secondId = LayoutUtil.getViewSecondId(cubridNode);
                    workbenchPart = window.getActivePage().showView(viewId, secondId, IWorkbenchPage.VIEW_CREATE | IWorkbenchPage.VIEW_ACTIVATE | IWorkbenchPage.VIEW_VISIBLE);
                    window.getActivePage().bringToTop(workbenchPart);
                }
            } else {
                workbenchPart = window.getActivePage().showView(viewId);
            }
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    }
    if (workbenchPart != null) {
        LayoutManager.getInstance().getTitleLineContrItem().changeTitleForViewOrEditPart(cubridNode, workbenchPart);
        LayoutManager.getInstance().getStatusLineContrItem().changeStuatusLineForViewOrEditPart(cubridNode, workbenchPart);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ManagerLogViewAction(com.cubrid.cubridmanager.ui.logs.action.ManagerLogViewAction) LogViewAction(com.cubrid.cubridmanager.ui.logs.action.LogViewAction) IViewPart(org.eclipse.ui.IViewPart) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) ISelectionAction(com.cubrid.common.ui.spi.action.ISelectionAction) PartInitException(org.eclipse.ui.PartInitException) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 48 with IViewPart

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

the class CubridTitleLineContrItem method getTitleForViewOrEdit.

/**
	 * 
	 * Get the title of view or editor(not including query editor)
	 * 
	 * @param cubridNode the ICubridNode object
	 * @param workbenchPart the IWorkbenchPart object
	 * @return String
	 */
protected String getTitleForViewOrEdit(ICubridNode cubridNode, IWorkbenchPart workbenchPart) {
    StringBuffer titleStrBuffer = new StringBuffer();
    if (cubridNode instanceof ISchemaNode) {
        ISchemaNode schemaNode = (ISchemaNode) cubridNode;
        CubridDatabase database = schemaNode.getDatabase();
        titleStrBuffer.append(database.getLabel());
    }
    String partTitle = "";
    if (workbenchPart == null) {
        if (null != cubridNode.getViewId()) {
            IViewPart viewPart = LayoutUtil.getViewPart(cubridNode, cubridNode.getViewId());
            if (viewPart != null) {
                partTitle = viewPart.getTitle();
            }
        }
        if (null != cubridNode.getEditorId()) {
            IEditorPart editorPart = LayoutUtil.getEditorPart(cubridNode, cubridNode.getEditorId());
            if (editorPart != null) {
                partTitle = editorPart.getTitle();
            }
        }
    } else {
        partTitle = workbenchPart.getTitle();
    }
    if (partTitle != null && partTitle.trim().length() > 0) {
        titleStrBuffer.append(" / " + partTitle);
    }
    return titleStrBuffer.toString();
}
Also used : IViewPart(org.eclipse.ui.IViewPart) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) IEditorPart(org.eclipse.ui.IEditorPart) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 49 with IViewPart

use of org.eclipse.ui.IViewPart 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)

Example 50 with IViewPart

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

the class PackageExplorerOpenActionProvider method init.

@Override
public void init(ICommonActionExtensionSite site) {
    super.init(site);
    action = new OpenFileAction(getActivePage());
    ICommonViewerWorkbenchSite workbenchSite = null;
    if (site.getViewSite() instanceof ICommonViewerWorkbenchSite)
        workbenchSite = (ICommonViewerWorkbenchSite) site.getViewSite();
    if (workbenchSite != null) {
        if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) {
            IViewPart viewPart = (IViewPart) workbenchSite.getPart();
            if (site.getStructuredViewer() instanceof TreeViewer) {
                treeViewer = (TreeViewer) site.getStructuredViewer();
                treeViewer.addSelectionChangedListener(action);
            }
            fInViewPart = true;
        }
    }
}
Also used : OpenFileAction(org.eclipse.ui.actions.OpenFileAction) IViewPart(org.eclipse.ui.IViewPart) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICommonViewerWorkbenchSite(org.eclipse.ui.navigator.ICommonViewerWorkbenchSite)

Aggregations

IViewPart (org.eclipse.ui.IViewPart)104 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)58 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)39 IEditorPart (org.eclipse.ui.IEditorPart)34 PartInitException (org.eclipse.ui.PartInitException)28 IViewReference (org.eclipse.ui.IViewReference)26 ArrayList (java.util.ArrayList)16 IFile (org.eclipse.core.resources.IFile)15 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)15 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)15 IEditorInput (org.eclipse.ui.IEditorInput)13 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)13 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)10 ITermViewPart (net.heartsome.cat.ts.ui.view.ITermViewPart)10 Shell (org.eclipse.swt.widgets.Shell)9 IEditorReference (org.eclipse.ui.IEditorReference)9 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)8 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)8 IProject (org.eclipse.core.resources.IProject)8