Search in sources :

Example 6 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.

the class RenameTableAction method doRun.

/**
	 * Perform rename Table
	 * 
	 * @param cubridDatabase
	 * @param table
	 */
private void doRun(CubridDatabase cubridDatabase, ISchemaNode table) {
    boolean isTable = false;
    String type = table.getType();
    if (NodeType.USER_TABLE.equals(type) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(type)) {
        isTable = true;
    } else if (NodeType.USER_VIEW.equals(type)) {
        isTable = false;
    }
    String tableName = table.getName();
    CubridDatabase db = table.getDatabase();
    DatabaseInfo dbInfo = db.getDatabaseInfo();
    GetTablesTask getTableTask = new GetTablesTask(dbInfo);
    List<String> tableList = getTableTask.getAllTableAndViews();
    RenameTableDialog dlg = new RenameTableDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), tableName, isTable, tableList, true);
    int ret = dlg.open();
    if (ret == IDialogConstants.OK_ID) {
        String newName = dlg.getNewName();
        RenameTableOrViewTask task = new RenameTableOrViewTask(dbInfo);
        task.setOldClassName(tableName);
        task.setNewClassName(newName);
        task.setTable(isTable);
        String taskName = Messages.bind(com.cubrid.common.ui.cubrid.table.Messages.renameTableTaskName, new String[] { tableName, newName });
        TaskExecutor taskExecutor = new CommonTaskExec(taskName);
        taskExecutor.addTask(task);
        new ExecTaskWithProgress(taskExecutor).exec();
        if (taskExecutor.isSuccess()) {
            ISelectionProvider provider = this.getSelectionProvider();
            final TreeViewer viewer = (TreeViewer) provider;
            //remove the old table schema information
            table.getDatabase().getDatabaseInfo().removeSchema(tableName);
            DefaultSchemaNode cloneTable = null;
            try {
                cloneTable = ((DefaultSchemaNode) table).clone();
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(cloneTable, CubridNodeChangedEventType.NODE_REMOVE));
            } catch (CloneNotSupportedException ex) {
                LOGGER.error(ex.getMessage());
            }
            ClassInfo classInfo = (ClassInfo) table.getAdapter(ClassInfo.class);
            classInfo.setClassName(newName);
            table.setId(table.getParent().getId() + ICubridNodeLoader.NODE_SEPARATOR + newName);
            table.setLabel(newName);
            viewer.refresh(table, true);
            LayoutManager.getInstance().getWorkbenchContrItem().reopenEditorOrView(table);
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(table, CubridNodeChangedEventType.NODE_ADD));
            ActionManager.getInstance().fireSelectionChanged(getSelection());
            /*Broadcast the view changed*/
            QueryEditorUtil.fireSchemaNodeChanged(table);
            /*For bug TOOLS-3118: close opened TableEditorPart about dropped table*/
            IWorkbench workbench = PlatformUI.getWorkbench();
            IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
            for (IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
                IEditorPart editor = editorRef.getEditor(true);
                if (editor.getEditorInput() instanceof TableEditorInput) {
                    TableEditorInput input = (TableEditorInput) editor.getEditorInput();
                    ISchemaNode tableOfEditor = input.getEditedTableNode();
                    if (tableOfEditor.equals(table)) {
                        workbenchWindow.getActivePage().closeEditor(editor, false);
                        break;
                    }
                }
            }
        }
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) RenameTableOrViewTask(com.cubrid.cubridmanager.core.cubrid.table.task.RenameTableOrViewTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) IEditorPart(org.eclipse.ui.IEditorPart) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) IWorkbench(org.eclipse.ui.IWorkbench) RenameTableDialog(com.cubrid.common.ui.cubrid.table.dialog.RenameTableDialog) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IEditorReference(org.eclipse.ui.IEditorReference) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetTablesTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetTablesTask) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 7 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.

the class PropertyViewAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    ISchemaNode node = (ISchemaNode) obj[0];
    CubridDatabase database = node.getDatabase();
    CreateViewDialog dialog = new CreateViewDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), database, false);
    GetAllClassListTask getAllClassListTask = new GetAllClassListTask(database.getDatabaseInfo());
    getAllClassListTask.setTableName(node.getName());
    GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(database.getDatabaseInfo());
    getAllDBVclassTask.setClassName(node.getName());
    GetAllAttrTask getAllAttrTask = new GetAllAttrTask(database.getDatabaseInfo());
    getAllAttrTask.setClassName(node.getName());
    JDBCGetAllDbUserTask getAllDbUserTask = new JDBCGetAllDbUserTask(database.getDatabaseInfo());
    dialog.execTask(-1, new ITask[] { getAllClassListTask, getAllDBVclassTask, getAllAttrTask, getAllDbUserTask }, true, getShell());
    if (getAllClassListTask.getErrorMsg() != null || getAllDBVclassTask.getErrorMsg() != null || getAllAttrTask.getErrorMsg() != null || getAllDbUserTask.getErrorMsg() != null || getAllClassListTask.isCancel() || getAllDBVclassTask.isCancel() || getAllAttrTask.isCancel() || getAllDbUserTask.isCancel()) {
        return;
    }
    ClassInfo classInfo = getAllClassListTask.getClassInfo();
    List<String> vclassList = getAllDBVclassTask.getAllVclassList();
    List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
    List<String> dbUserList = getAllDbUserTask.getDbUserList();
    dialog.setAttrList(attrList);
    dialog.setClassInfo(classInfo);
    dialog.setVclassList(vclassList);
    dialog.setDbUserList(dbUserList);
    dialog.setPropertyQuery(true);
    dialog.open();
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CreateViewDialog(com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog) GetViewAllColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 8 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.

the class ColumnViewerSorter method setInputs.

public void setInputs() {
    tableListView.setInput(tableList);
    tableListView.refresh();
    Connection connection = null;
    try {
        connection = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
        isSchemaCommentInstalled = SchemaCommentHandler.isInstalledMetaTable(database.getDatabaseInfo(), connection);
        TableDashboardComposite tableComp = new TableDashboardComposite(tabFolder, SWT.NONE);
        tableComp.initialize();
        if (database.getDatabaseInfo().getUserTableInfoList().size() > 0) {
            ClassInfo classInfo = database.getDatabaseInfo().getUserTableInfoList().get(0);
            SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(connection, classInfo.getClassName());
            IDatabaseSpec dbSpec = database.getDatabaseInfo();
            if (schemaInfo != null && SchemaCommentHandler.isInstalledMetaTable(dbSpec, connection)) {
                Map<String, SchemaComment> comments = SchemaCommentHandler.loadDescription(dbSpec, connection, classInfo.getClassName());
                if (comments != null) {
                    SchemaCommentHandler.bindSchemaInfo(comments, schemaInfo);
                }
            }
            tableComp.setInput(schemaInfo, database.getDatabaseInfo(), isSchemaCommentInstalled);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    } finally {
        QueryUtil.freeQuery(connection);
    }
    if (isSchemaCommentInstalled) {
        new TableEditButtonSupport(tableListView, this, 1);
    }
}
Also used : TableEditButtonSupport(com.cubrid.common.ui.spi.table.button.TableEditButtonSupport) IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) Connection(java.sql.Connection) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 9 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.

the class TableEditorPart method completeAll.

public void completeAll() {
    CommonUITool.openInformationBox(Messages.titleSuccess, Messages.bind(Messages.msgNull2DefComplete, jobName));
    if (this.isNewTableFlag) {
        ICubridNode node = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridTablesFolderLoader.TABLES_FOLDER_ID);
        if (node == null || !node.getLoader().isLoaded()) {
            return;
        }
        String id = node.getId() + ICubridNodeLoader.NODE_SEPARATOR + tableName;
        boolean isPartition = newSchemaInfo.getPartitionList() != null && newSchemaInfo.getPartitionList().size() > 0;
        ClassInfo newClassInfo = new ClassInfo(tableName, owner, ClassType.NORMAL, false, isPartition);
        ICubridNode newNode = CubridTablesFolderLoader.createUserTableNode(node, id, newClassInfo, node.getLoader().getLevel(), new NullProgressMonitor());
        if (CubridNavigatorView.findNavigationView() == null) {
            getSite().getWorkbenchWindow().getActivePage().closeEditor(editor, false);
            return;
        }
        TreeViewer treeViewer = CubridNavigatorView.findNavigationView().getViewer();
        if (treeViewer == null || treeViewer.getTree() == null || treeViewer.getTree().isDisposed()) {
            getSite().getWorkbenchWindow().getActivePage().closeEditor(editor, false);
            return;
        }
        CommonUITool.addNodeToTree(treeViewer, node, newNode);
        // refresh table folder count label
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, node);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(newNode, CubridNodeChangedEventType.NODE_ADD));
    } else {
        if (database == null) {
            return;
        }
        database.getDatabaseInfo().removeSchema(tableName);
        if (oldPartitionInfoList.isEmpty() && !partitionInfoList.isEmpty()) {
            editedTableNode.setIconPath("icons/navigator/schema_table_partition.png");
            editedTableNode.setType(NodeType.USER_PARTITIONED_TABLE_FOLDER);
            editedTableNode.setLoader(new CubridPartitionedTableLoader());
        } else if (!oldPartitionInfoList.isEmpty() && partitionInfoList.isEmpty()) {
            editedTableNode.setIconPath("icons/navigator/schema_table_item.png");
            editedTableNode.setType(NodeType.USER_TABLE);
            editedTableNode.setLoader(new CubridUserTableLoader());
        }
        TreeViewer treeViewer = CubridNavigatorView.findNavigationView().getViewer();
        if (treeViewer == null || treeViewer.getTree() == null || treeViewer.getTree().isDisposed()) {
            getSite().getWorkbenchWindow().getActivePage().closeEditor(editor, false);
            return;
        }
        CommonUITool.refreshNavigatorTree(treeViewer, editedTableNode);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(editedTableNode, CubridNodeChangedEventType.NODE_REFRESH));
        /* Broadcast the view changed */
        QueryEditorUtil.fireSchemaNodeChanged(editedTableNode);
    }
    getSite().getWorkbenchWindow().getActivePage().closeEditor(editor, false);
}
Also used : CubridPartitionedTableLoader(com.cubrid.common.ui.spi.model.loader.schema.CubridPartitionedTableLoader) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridUserTableLoader(com.cubrid.common.ui.spi.model.loader.schema.CubridUserTableLoader) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 10 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.

the class CubridViewsFolderLoader 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) {
            database.getDatabaseInfo().setUserViewInfoList(null);
            database.getDatabaseInfo().setSysViewInfoList(null);
            database.getDatabaseInfo().clearSchemas();
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        final GetAllClassListTask task = new GetAllClassListTask(databaseInfo);
        monitorCancel(monitor, new ITask[] { task });
        List<ClassInfo> allClassInfoList = task.getSchema(true, false);
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            parent.removeAllChild();
            openErrorBox(errorMsg);
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        // add system view folder
        String systemViewFolderId = parent.getId() + NODE_SEPARATOR + SYSTEM_VIEW_FOLDER_ID;
        ICubridNode systemViewFolder = parent.getChild(systemViewFolderId);
        parent.removeAllChild();
        if (systemViewFolder == null) {
            systemViewFolder = new DefaultSchemaNode(systemViewFolderId, SYSTEM_VIEW_FOLDER_NAME, "icons/navigator/folder_sys.png");
            systemViewFolder.setType(NodeType.SYSTEM_VIEW_FOLDER);
            systemViewFolder.setContainer(true);
            ICubridNodeLoader loader = new CubridSystemViewFolderLoader();
            loader.setLevel(getLevel());
            systemViewFolder.setLoader(loader);
            parent.addChild(systemViewFolder);
            if (getLevel() == DEFINITE_LEVEL) {
                systemViewFolder.getChildren(monitor);
            }
        } else {
            parent.addChild(systemViewFolder);
            if (systemViewFolder.getLoader() != null && systemViewFolder.getLoader().isLoaded()) {
                systemViewFolder.getLoader().setLoaded(false);
                systemViewFolder.getChildren(monitor);
            }
        }
        if (allClassInfoList != null) {
            for (ClassInfo classInfo : allClassInfoList) {
                String id = parent.getId() + NODE_SEPARATOR + classInfo.getClassName();
                ICubridNode classNode = createUserViewNode(id, classInfo);
                parent.addChild(classNode);
            }
        }
        database.getDatabaseInfo().setUserViewInfoList(allClassInfoList);
        database.getDatabaseInfo().clearSchemas();
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) 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) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Aggregations

ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)29 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)10 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)10 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)9 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)8 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)8 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)7 SQLException (java.sql.SQLException)6 Map (java.util.Map)6 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)5 ClassAuthorizations (com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations)5 GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)5 GetViewAllColumnsTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask)5 TreeViewer (org.eclipse.jface.viewers.TreeViewer)5 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)4 ClassType (com.cubrid.cubridmanager.core.utils.ModelUtil.ClassType)4 CreateViewDialog (com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog)3