Search in sources :

Example 86 with IWorkbenchPage

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

the class MonitorReplicationPerfAction method run.

/**
	 * monitor replication performance
	 */
public void run() {
    Object[] obj = this.getSelectedObj();
    if (obj == null || obj.length == 0 || !isSupported(obj[0])) {
        return;
    }
    ICubridNode cubridNode = (ICubridNode) obj[0];
    try {
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IViewPart viewPart = LayoutUtil.getViewPart(cubridNode, ReplicationMonitorViewPart.ID);
        if (viewPart == null) {
            IWorkbenchPage page = window.getActivePage();
            String secondId = cubridNode.getServer().getLabel() + "_" + cubridNode.getLabel();
            viewPart = page.showView(ReplicationMonitorViewPart.ID, secondId, IWorkbenchPage.VIEW_CREATE);
            window.getActivePage().bringToTop(viewPart);
        } else {
            window.getActivePage().bringToTop(viewPart);
        }
        if (viewPart != null) {
            LayoutManager.getInstance().getTitleLineContrItem().changeTitleForViewOrEditPart(cubridNode, viewPart);
            LayoutManager.getInstance().getStatusLineContrItem().changeStuatusLineForViewOrEditPart(cubridNode, viewPart);
        }
    } catch (PartInitException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) PartInitException(org.eclipse.ui.PartInitException)

Example 87 with IWorkbenchPage

use of org.eclipse.ui.IWorkbenchPage 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 88 with IWorkbenchPage

use of org.eclipse.ui.IWorkbenchPage 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 89 with IWorkbenchPage

use of org.eclipse.ui.IWorkbenchPage 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 90 with IWorkbenchPage

use of org.eclipse.ui.IWorkbenchPage in project bndtools by bndtools.

the class OpenExtConfigsContributionItem method getContributionItems.

@Override
protected IContributionItem[] getContributionItems() {
    try {
        IFile buildFile = Central.getWorkspaceBuildFile();
        if (buildFile == null)
            return EMPTY;
        IContainer cnfDir = buildFile.getParent();
        IFolder extDir = cnfDir.getFolder(new Path("ext"));
        if (extDir == null || !extDir.exists())
            return EMPTY;
        IResource[] extFiles = extDir.members();
        List<IContributionItem> result = new ArrayList<IContributionItem>(extFiles.length);
        for (final IResource extFile : extFiles) {
            if (extFile.getType() == IResource.FILE && "bnd".equalsIgnoreCase(extFile.getFileExtension())) {
                Action action = new Action() {

                    @Override
                    public void run() {
                        try {
                            FileEditorInput input = new FileEditorInput((IFile) extFile);
                            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                            page.openEditor(input, "bndtools.bndWorkspaceConfigEditor", true);
                        } catch (PartInitException e) {
                            ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", "Unable to open editor", e.getStatus());
                        }
                    }
                };
                action.setText("Open " + extFile.getProjectRelativePath());
                action.setImageDescriptor(extFileImg);
                result.add(new ActionContributionItem(action));
            }
        }
        return result.toArray(new IContributionItem[0]);
    } catch (Exception e) {
        logger.logError("Unable to find default config files", e);
        return EMPTY;
    }
}
Also used : Path(org.eclipse.core.runtime.Path) Action(org.eclipse.jface.action.Action) IFile(org.eclipse.core.resources.IFile) IContributionItem(org.eclipse.jface.action.IContributionItem) ArrayList(java.util.ArrayList) PartInitException(org.eclipse.ui.PartInitException) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)294 IEditorPart (org.eclipse.ui.IEditorPart)126 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)102 PartInitException (org.eclipse.ui.PartInitException)96 IFile (org.eclipse.core.resources.IFile)63 IViewPart (org.eclipse.ui.IViewPart)58 IEditorReference (org.eclipse.ui.IEditorReference)40 IWorkbench (org.eclipse.ui.IWorkbench)32 CoreException (org.eclipse.core.runtime.CoreException)31 ArrayList (java.util.ArrayList)30 IViewReference (org.eclipse.ui.IViewReference)29 IEditorInput (org.eclipse.ui.IEditorInput)28 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)27 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)22 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)18 Path (org.eclipse.core.runtime.Path)18 FileEditorInput (org.eclipse.ui.part.FileEditorInput)17 IOException (java.io.IOException)16 IProject (org.eclipse.core.resources.IProject)16 ISelection (org.eclipse.jface.viewers.ISelection)16