Search in sources :

Example 61 with CubridDatabase

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

the class DatabaseQueryNewAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    Object[] obj = this.getSelectedObj();
    CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
    if (cubridDatabases.length == 0) {
        return;
    }
    /*Limit max number one time*/
    if (cubridDatabases.length > LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM) {
        CommonUITool.openConfirmBox(Messages.bind(Messages.msgMaxOpenNum, LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM));
        List<CubridDatabase> list = new ArrayList<CubridDatabase>(LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM);
        for (int i = 0; i < LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM; i++) {
            list.add(cubridDatabases[i]);
        }
        cubridDatabases = new CubridDatabase[LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM];
        list.toArray(cubridDatabases);
    }
    // [TOOLS-2425]Support shard broker
    // it is used in order to check first shard database when you open several editor of databases.
    int count = cubridDatabases.length;
    for (CubridDatabase database : cubridDatabases) {
        QueryUnit queryUnit = new QueryUnit();
        queryUnit.setDatabase(database);
        // [TOOLS-2425]Support shard broker
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        if (dbInfo == null) {
            continue;
        }
        int shardId = 0;
        int shardVal = 0;
        int shardQueryType = DatabaseInfo.SHARD_QUERY_TYPE_VAL;
        if (count == 1) {
            // [TOOLS-2425]Support shard broker
            if (dbInfo != null && dbInfo.isShard()) {
                ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
                dialog.setDatabaseInfo(dbInfo);
                dialog.setShardId(shardId);
                dialog.setShardVal(shardVal);
                dialog.setShardQueryType(shardQueryType);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    shardId = dialog.getShardId();
                    shardVal = dialog.getShardVal();
                    shardQueryType = dialog.getShardQueryType();
                }
            }
        }
        try {
            IEditorPart editor = window.getActivePage().openEditor(queryUnit, QueryEditorPart.ID);
            if (editor != null && database != null) {
                QueryEditorPart editorPart = (QueryEditorPart) editor;
                editorPart.connect(database);
                // [TOOLS-2425]Support shard broker
                if (dbInfo.isShard()) {
                    editorPart.setShardId(shardId);
                    editorPart.setShardVal(shardVal);
                    editorPart.setShardQueryType(shardQueryType);
                    editorPart.changeQueryEditorPartNameWithShard();
                }
            }
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList) ShardIdSelectionDialog(com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog) IEditorPart(org.eclipse.ui.IEditorPart) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 62 with CubridDatabase

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

the class DatabaseQueryNewAction method handleSelectionObj.

/**
	 * handleSelectionObj
	 * @param objs
	 * @return
	 */
private CubridDatabase[] handleSelectionObj(Object[] objs) {
    List<CubridDatabase> returnArray = new ArrayList<CubridDatabase>();
    CubridDatabase database = null;
    for (Object obj : objs) {
        if (obj instanceof ISchemaNode) {
            database = ((ISchemaNode) obj).getDatabase();
            if (database != null) {
                //if multiple selection ,only open a query editor with one database
                if (!returnArray.contains(database)) {
                    returnArray.add(database);
                }
            }
        }
    }
    return returnArray.toArray(new CubridDatabase[0]);
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ArrayList(java.util.ArrayList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 63 with CubridDatabase

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

the class CubridSPFolderLoader 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.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        // add function folder
        String functionFolderId = parent.getId() + NODE_SEPARATOR + FUNCTION_FOLDER_ID;
        ICubridNode functionFolder = parent.getChild(functionFolderId);
        if (functionFolder == null) {
            functionFolder = new DefaultSchemaNode(functionFolderId, FUNCTION_FOLDER_NAME, "icons/navigator/folder.png");
            functionFolder.setType(NodeType.STORED_PROCEDURE_FUNCTION_FOLDER);
            functionFolder.setContainer(true);
            ICubridNodeLoader loader = new CubridFunctionFolderLoader();
            loader.setLevel(getLevel());
            functionFolder.setLoader(loader);
            parent.addChild(functionFolder);
            if (getLevel() == DEFINITE_LEVEL) {
                functionFolder.getChildren(monitor);
            }
        } else {
            if (functionFolder.getLoader() != null && functionFolder.getLoader().isLoaded()) {
                functionFolder.getLoader().setLoaded(false);
                functionFolder.getChildren(monitor);
            }
        }
        // add procedure folder
        String procedureFolderId = parent.getId() + NODE_SEPARATOR + PROCEDURE_FOLDER_ID;
        ICubridNode procedureFolder = parent.getChild(procedureFolderId);
        if (procedureFolder == null) {
            procedureFolder = new DefaultSchemaNode(procedureFolderId, PROCEDURE_FOLDER_NAME, "icons/navigator/folder.png");
            procedureFolder.setType(NodeType.STORED_PROCEDURE_PROCEDURE_FOLDER);
            procedureFolder.setContainer(true);
            ICubridNodeLoader loader = new CubridProcedureFolderLoader();
            loader.setLevel(getLevel());
            procedureFolder.setLoader(loader);
            parent.addChild(procedureFolder);
            if (getLevel() == DEFINITE_LEVEL) {
                procedureFolder.getChildren(monitor);
            }
        } else {
            if (procedureFolder.getLoader() != null && procedureFolder.getLoader().isLoaded()) {
                procedureFolder.getLoader().setLoaded(false);
                procedureFolder.getChildren(monitor);
            }
        }
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode)

Example 64 with CubridDatabase

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

the class CubridUserTableColumnLoader 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.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        if (columns == null && !getColumns(parent, monitor, database)) {
            return;
        }
        if (monitor.isCanceled()) {
            columns = null;
            setLoaded(true);
            return;
        }
        parent.removeAllChild();
        String parentId = parent.getId();
        if (columns != null && !columns.isEmpty()) {
            for (TableColumn column : columns) {
                String label = column.getColumnName() + ",";
                label += FieldHandlerUtils.getComleteType(column.getTypeName(), column.getSubElementTypeName(), column.getPrecision(), column.getScale());
                String nodeId = parentId + NODE_SEPARATOR + column.getColumnName();
                ICubridNode node = new DefaultSchemaNode(nodeId, label, "icons/navigator/table_column_item.png");
                if (column.isPrimaryKey()) {
                    node.setIconPath("icons/primary_key.png");
                }
                node.setType(NodeType.TABLE_COLUMN);
                node.setModelObj(column);
                node.setContainer(false);
                parent.addChild(node);
            }
        }
        columns = null;
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) TableColumn(com.cubrid.cubridmanager.core.cubrid.table.model.TableColumn)

Example 65 with CubridDatabase

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

the class CubridUserTableIndexLoader 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.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        final GetUserClassIndexesTask task = new GetUserClassIndexesTask(databaseInfo);
        monitorCancel(monitor, new ITask[] { task });
        String tableName = parent.getParent().getLabel();
        List<TableIndex> indexes = task.getIndexesNames(tableName);
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            parent.removeAllChild();
            Display display = Display.getDefault();
            display.syncExec(new Runnable() {

                public void run() {
                    CommonUITool.openErrorBox(errorMsg);
                }
            });
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        parent.removeAllChild();
        String parentId = parent.getId();
        if (indexes != null && !indexes.isEmpty()) {
            for (TableIndex index : indexes) {
                String indexName = index.getIndexName();
                String nodeId = parentId + NODE_SEPARATOR + indexName;
                String label = indexName;
                List<String> dependColumns = index.getColumns();
                if (dependColumns != null && !dependColumns.isEmpty()) {
                    String keyAttrName = index.getColumns().toString();
                    label += keyAttrName.replace('[', '(').replace(']', ')');
                }
                ICubridNode node = new DefaultSchemaNode(nodeId, label, "icons/navigator/table_index_item.png");
                if (index.isPrimaryKey()) {
                    node.setIconPath("icons/primary_key.png");
                }
                node.setType(NodeType.TABLE_INDEX);
                node.setModelObj(index);
                node.setContainer(false);
                parent.addChild(node);
            }
        }
        Collections.sort(parent.getChildren());
        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) TableIndex(com.cubrid.cubridmanager.core.cubrid.table.model.TableIndex) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) GetUserClassIndexesTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetUserClassIndexesTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) Display(org.eclipse.swt.widgets.Display)

Aggregations

CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)278 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)104 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)79 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)67 ArrayList (java.util.ArrayList)45 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)43 TreeViewer (org.eclipse.jface.viewers.TreeViewer)42 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)36 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)33 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)30 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)29 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)28 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)25 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)22 Shell (org.eclipse.swt.widgets.Shell)22 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)19 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)18 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)18 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)18 ITask (com.cubrid.common.core.task.ITask)17