Search in sources :

Example 1 with ISelectionAction

use of com.cubrid.common.ui.spi.action.ISelectionAction 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 2 with ISelectionAction

use of com.cubrid.common.ui.spi.action.ISelectionAction in project cubrid-manager by CUBRID.

the class CubridWorkbenchContrItem method processDoubleClickNavigatorEvent.

public void processDoubleClickNavigatorEvent(DoubleClickEvent event) {
    ISelection selection = event.getSelection();
    if (selection == null || selection.isEmpty()) {
        return;
    }
    Object obj = ((IStructuredSelection) selection).getFirstElement();
    if (!(obj instanceof ICubridNode)) {
        return;
    }
    // open the monitor dashboard view
    ICubridNode cubridNode = (ICubridNode) obj;
    if (CubridNodeType.MONITOR_DASHBOARD.equals(cubridNode.getType())) {
        ISelectionAction action = (ISelectionAction) ActionManager.getInstance().getAction(OpenMonitorDashboardAction.ID);
        if (action != null && action.isSupported(cubridNode)) {
            action.run();
            return;
        }
    }
    /*[TOOLS-3668] - MonitorStatistic node*/
    if (CubridNodeType.MONITOR_STATISTIC_PAGE.equals(cubridNode.getType())) {
        ISelectionAction action = (ISelectionAction) ActionManager.getInstance().getAction(OpenMonitorStatisticPageAction.ID);
        if (action != null && action.isSupported(cubridNode)) {
            action.run();
            return;
        }
    }
    /*CubridServer node*/
    if (cubridNode instanceof CubridServer) {
        CubridServer cubridServer = (CubridServer) cubridNode;
        if (cubridServer.isConnected()) {
            ServerInfo serverInfo = cubridServer.getServerInfo();
            //open host dashboard
            if (serverInfo != null && serverInfo.isConnected()) {
                openHostDashboard(serverInfo);
            }
        } else if (connectHost(cubridServer.getServerInfo(), true)) {
            refreshAfterConnected(cubridServer);
        } else {
            EditHostAction action = (EditHostAction) ActionManager.getInstance().getAction(EditHostAction.ID);
            if (action == null) {
                LOGGER.error("The EditHostAction is a null.");
            } else {
                action.run();
            }
        }
        return;
    }
    CubridServer server = cubridNode.getServer();
    if (server == null || !server.isConnected()) {
        return;
    }
    /*CubridDatabase node*/
    if (cubridNode instanceof CubridDatabase) {
        CubridDatabase database = (CubridDatabase) cubridNode;
        if (database.isLogined()) {
            openEditorOrView(database);
            return;
        }
        LoginDatabaseAction loginDatabaseAction = (LoginDatabaseAction) ActionManager.getInstance().getAction(LoginDatabaseAction.ID);
        loginDatabaseAction.doRun(new CubridDatabase[] { database });
        return;
    }
    /*Other node*/
    if (!LayoutManager.getInstance().isUseClickOnce()) {
        boolean useSelectQuery = ActionSupportUtil.isSupportMultiSelection(obj, new String[] { NodeType.USER_TABLE, NodeType.USER_VIEW, NodeType.SYSTEM_TABLE, NodeType.SYSTEM_VIEW, NodeType.USER_PARTITIONED_TABLE_FOLDER }, false);
        if (useSelectQuery) {
            openSelectQuery(selection);
        } else {
            openEditorOrView(cubridNode);
        }
    }
    boolean useExpandFolder = NodeType.contains(cubridNode.getType(), new String[] { NodeType.TABLE_FOLDER, NodeType.VIEW_FOLDER, NodeType.TRIGGER_FOLDER, NodeType.SERIAL_FOLDER, NodeType.USER_FOLDER, CubridNodeType.JOB_FOLDER });
    if (useExpandFolder) {
        CubridDatabase database = (CubridDatabase) cubridNode.getParent();
        CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
        TreeViewer treeViewer = view.getViewer();
        if (cubridNode.getType() == NodeType.TABLE_FOLDER) {
            // if not expand, expand the node and wait until all children be added
            int sleepCount = 0;
            if (!treeViewer.getExpandedState(cubridNode)) {
                treeViewer.expandToLevel(cubridNode, 1);
                while (cubridNode.getChildren().size() == 0) {
                    try {
                        Thread.sleep(500);
                        sleepCount++;
                        if (sleepCount > 5) {
                            break;
                        }
                    } catch (Exception e) {
                        LOGGER.debug("", e);
                    }
                }
            }
            openTablesDetailInfoPart(database);
            return;
        }
        //if not open child node ,edit serial from dashboard can not open edit dialog
        if (!treeViewer.getExpandedState(cubridNode)) {
            treeViewer.expandToLevel(cubridNode, 1);
        }
        if (StringUtil.isEqual(cubridNode.getType(), NodeType.VIEW_FOLDER)) {
            openViewsDetailInfoPart(database);
        } else if (StringUtil.isEqual(cubridNode.getType(), NodeType.TRIGGER_FOLDER)) {
            openTriggersDetailInfoPart(database);
        } else if (StringUtil.isEqual(cubridNode.getType(), NodeType.SERIAL_FOLDER)) {
            openSerialsDetailInfoPart(database);
        } else if (StringUtil.isEqual(cubridNode.getType(), CubridNodeType.JOB_FOLDER)) {
            openJobsDetailInfoPart(database);
        } else if (StringUtil.isEqual(cubridNode.getType(), NodeType.USER_FOLDER)) {
            openUsersDetailInfoPart(database);
        }
    }
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) LoginDatabaseAction(com.cubrid.cubridmanager.ui.cubrid.database.action.LoginDatabaseAction) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) PartInitException(org.eclipse.ui.PartInitException) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) ISelection(org.eclipse.jface.viewers.ISelection) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) ISelectionAction(com.cubrid.common.ui.spi.action.ISelectionAction) EditHostAction(com.cubrid.cubridmanager.ui.host.action.EditHostAction)

Aggregations

ISelectionAction (com.cubrid.common.ui.spi.action.ISelectionAction)2 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 PartInitException (org.eclipse.ui.PartInitException)2 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)1 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)1 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)1 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)1 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 LoginDatabaseAction (com.cubrid.cubridmanager.ui.cubrid.database.action.LoginDatabaseAction)1 EditHostAction (com.cubrid.cubridmanager.ui.host.action.EditHostAction)1 LogViewAction (com.cubrid.cubridmanager.ui.logs.action.LogViewAction)1 ManagerLogViewAction (com.cubrid.cubridmanager.ui.logs.action.ManagerLogViewAction)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IViewPart (org.eclipse.ui.IViewPart)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1