Search in sources :

Example 81 with ISchemaNode

use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.

the class CubridWorkbenchContrItem method openSelectQuery.

public void openSelectQuery(ISelection selection) {
    final Object obj = ((IStructuredSelection) selection).getFirstElement();
    if (!(obj instanceof ICubridNode)) {
        return;
    }
    ISchemaNode table = (ISchemaNode) obj;
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    boolean existsEditor = false;
    QueryEditorPart editor = null;
    QueryUnit input = new QueryUnit();
    input.setDatabase(table.getDatabase());
    try {
        IEditorPart editorPart = window.getActivePage().getActiveEditor();
        if (editorPart != null && editorPart instanceof QueryEditorPart) {
            QueryEditorPart queryEditorPart = (QueryEditorPart) editorPart;
            if (queryEditorPart.getSelectedDatabase() == input.getDatabase()) {
                editor = (QueryEditorPart) editorPart;
                existsEditor = true;
            }
        }
        if (editor == null) {
            editor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
            editor.connect(table.getDatabase());
        }
        DefaultSchemaNode tableNode = (DefaultSchemaNode) obj;
        String sql = getStmtSQL(tableNode) + StringUtil.NEWLINE + StringUtil.NEWLINE;
        if (existsEditor) {
            editor.newQueryTab(sql, true);
        } else {
            editor.setQuery(sql, false, true, false);
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorPart(org.eclipse.ui.IEditorPart) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) PartInitException(org.eclipse.ui.PartInitException)

Example 82 with ISchemaNode

use of com.cubrid.common.ui.spi.model.ISchemaNode 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 83 with ISchemaNode

use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.

the class CQBDbUsersFolderLoader method load.

/**
	 *
	 * Load children object for parent
	 *
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        CubridDatabase database = ((ISchemaNode) parent).getDatabase();
        if (database.getRunningType() == DbRunningType.STANDALONE) {
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        DbUserInfoList dbUserInfoList = new DbUserInfoList();
        GetUserListTask task = new GetUserListTask(database.getDatabaseInfo());
        parent.removeAllChild();
        try {
            dbUserInfoList = task.getResultModel();
        } catch (Exception e) {
            LOGGER.error("load user failed", e);
        }
        DbUserInfo latestDLoginedbUserInfo = databaseInfo.getAuthLoginedDbUserInfo();
        List<DbUserInfo> dbUserList = dbUserInfoList == null ? null : dbUserInfoList.getUserList();
        formatUserList(dbUserList);
        for (int i = 0; dbUserList != null && dbUserList.size() > i; i++) {
            DbUserInfo dbUserInfo = dbUserList.get(i);
            if (dbUserInfo.getName().equals(latestDLoginedbUserInfo.getName())) {
                dbUserInfo.setDbaAuthority(latestDLoginedbUserInfo.isDbaAuthority());
            // databaseInfo.setAuthLoginedDbUserInfo(dbUserInfo);
            }
            String id = parent.getId() + NODE_SEPARATOR + dbUserInfo.getName();
            ICubridNode dbUserInfoNode = new DefaultSchemaNode(id, dbUserInfo.getName(), "icons/navigator/user_item.png");
            dbUserInfoNode.setType(NodeType.USER);
            dbUserInfoNode.setModelObj(dbUserInfo);
            dbUserInfoNode.setContainer(false);
            dbUserInfoNode.setEditorId(CQBUserEditor.ID);
            parent.addChild(dbUserInfoNode);
        }
        databaseInfo.setDbUserInfoList(dbUserInfoList);
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 84 with ISchemaNode

use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.

the class ChangeShardAction method isSupported.

/**
	 * Return whether this action support this object,if not support,this action
	 * will be disabled
	 * 
	 * @param obj the Object
	 * @return <code>true</code> if support this obj;<code>false</code>
	 *         otherwise
	 */
public boolean isSupported(Object obj) {
    if (obj == null) {
        return false;
    }
    if (!(obj instanceof ICubridNode)) {
        return false;
    }
    ICubridNode cubridNode = (ICubridNode) obj;
    String nodeType = cubridNode.getType();
    if (!NodeType.DATABASE.equals(nodeType)) {
        return false;
    }
    ISchemaNode schemaNode = (ISchemaNode) cubridNode;
    DatabaseInfo dbInfo = schemaNode.getDatabase().getDatabaseInfo();
    if (!schemaNode.getDatabase().isLogined()) {
        return false;
    }
    if (!dbInfo.isShard()) {
        return false;
    }
    return true;
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 85 with ISchemaNode

use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.

the class CubridTitleLineContrItem method getTitleForNavigator.

/**
	 * 
	 * Get title of CUBRID Query application for navigator
	 * 
	 * @param cubridNode the ICubridNode object
	 * @return String
	 */
protected String getTitleForNavigator(ICubridNode cubridNode) {
    if (cubridNode == null) {
        return "";
    }
    StringBuffer titleStrBuffer = new StringBuffer();
    if (cubridNode instanceof ISchemaNode) {
        ISchemaNode schemaNode = (ISchemaNode) cubridNode;
        CubridDatabase database = schemaNode.getDatabase();
        if (database != null) {
            titleStrBuffer.append(database.getLabel() + " / ");
        }
        DatabaseInfo dbInfo = database == null ? null : database.getDatabaseInfo();
        if (dbInfo == null) {
            return "";
        }
        StringBuffer dbInfoStrBuffer = new StringBuffer();
        DbUserInfo dbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
        if (dbUserInfo == null || dbUserInfo.getName() == null || dbUserInfo.getName().trim().length() == 0) {
            dbInfoStrBuffer.append(dbInfo.getDbName());
        } else {
            dbInfoStrBuffer.append(dbUserInfo.getName() + "@" + dbInfo.getDbName());
        }
        String brokerPort = dbInfo.getBrokerPort();
        if (brokerPort != null && brokerPort.trim().length() > 0) {
            dbInfoStrBuffer.append(":").append(brokerPort);
        }
        String charset = dbInfo.getCharSet();
        if (charset != null && charset.trim().length() > 0) {
            dbInfoStrBuffer.append(":charset=").append(charset);
        }
        titleStrBuffer.append(dbInfoStrBuffer);
    } else {
        titleStrBuffer.append(cubridNode.getLabel());
    }
    return titleStrBuffer.toString();
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)158 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)104 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)55 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)30 ArrayList (java.util.ArrayList)28 TreeViewer (org.eclipse.jface.viewers.TreeViewer)27 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)23 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)23 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)22 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)22 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)21 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)21 Shell (org.eclipse.swt.widgets.Shell)16 ITask (com.cubrid.common.core.task.ITask)13 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)13 IEditorPart (org.eclipse.ui.IEditorPart)12 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)12 HashSet (java.util.HashSet)11 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 PartInitException (org.eclipse.ui.PartInitException)10