Search in sources :

Example 41 with IViewPart

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

the class WorkbenchContrItem 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();
    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) {
            window.getActivePage().hideView(viewPart);
        }
    }
    if (editorId != null && editorId.trim().length() > 0) {
        try {
            //if open the table schema editor,firstly load the schema
            if (editorId.equals(SchemaInfoEditorPart.ID) && cubridNode instanceof ISchemaNode) {
                CubridDatabase database = ((ISchemaNode) cubridNode).getDatabase();
                SchemaInfo newSchema = database.getDatabaseInfo().getSchemaInfo(cubridNode.getName());
                if (null == newSchema) {
                    CommonUITool.openErrorBox(database.getDatabaseInfo().getErrorMessage());
                    return;
                }
            }
            window.getActivePage().openEditor(cubridNode, editorId, true, IWorkbenchPage.MATCH_ID & IWorkbenchPage.MATCH_INPUT);
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage());
        }
    } else if (viewId != null && viewId.trim().length() > 0) {
        try {
            window.getActivePage().showView(viewId);
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 42 with IViewPart

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

the class LayoutUtil method closeAllCubridEditorAndView.

/**
	 * 
	 * Close all opened editor and view part related with CUBRID Manager,not
	 * include query editor
	 * 
	 */
public static void closeAllCubridEditorAndView() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    if (workbench == null) {
        return;
    }
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    IWorkbenchPage page = window.getActivePage();
    if (page == null) {
        return;
    }
    IEditorReference[] editorRefArr = page.getEditorReferences();
    if (editorRefArr != null && editorRefArr.length > 0) {
        for (IEditorReference editorRef : editorRefArr) {
            try {
                IEditorInput editorInput = editorRef.getEditorInput();
                if (editorInput instanceof ICubridNode) {
                    window.getActivePage().closeEditor(editorRef.getEditor(false), true);
                }
            } catch (PartInitException e) {
                LOGGER.error(e.getMessage());
            }
        }
    }
    IViewReference[] viewRefArr = page.getViewReferences();
    if (viewRefArr != null && viewRefArr.length > 0) {
        for (IViewReference viewRef : viewRefArr) {
            IViewPart viewPart = viewRef.getView(false);
            if (viewPart instanceof CubridViewPart) {
                page.hideView(viewPart);
            }
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) 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 43 with IViewPart

use of org.eclipse.ui.IViewPart in project gfm_viewer by satyagraha.

the class ViewManager method activateView.

/**
     * Activate a view by id.
     * 
     * @param event
     * @param viewId
     * @throws ExecutionException
     */
public static void activateView(ExecutionEvent event, String viewId) throws ExecutionException {
    try {
        IViewPart view = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(viewId);
        HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().activate(view);
    } catch (PartInitException e) {
        throw new ExecutionException("failed to show view", e);
    }
}
Also used : IViewPart(org.eclipse.ui.IViewPart) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 44 with IViewPart

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

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

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