Search in sources :

Example 1 with JDBCGetAllDbUserTask

use of com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask in project cubrid-manager by CUBRID.

the class EditTableAction method doRun.

private void doRun(ISchemaNode table, int type) {
    final DatabaseInfo databaseInfo = NodeUtil.findDatabaseInfo(table);
    if (databaseInfo == null) {
        return;
    }
    final String tableName = table.getName();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            databaseInfo.removeSchema(tableName);
            SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(tableName);
            if (schemaInfo == null) {
                openErrorBox(shell, databaseInfo.getErrorMessage(), monitor);
                return false;
            }
            return true;
        }
    };
    boolean supportCharset = CompatibleUtil.isSupportCreateDBByCharset(databaseInfo);
    JDBCGetAllDbUserTask allUserTask = new JDBCGetAllDbUserTask(databaseInfo);
    taskExcutor.addTask(allUserTask);
    GetCollations collationTask = null;
    if (supportCharset) {
        collationTask = new GetCollations(databaseInfo);
        taskExcutor.addTask(collationTask);
    }
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    List<String> dbUserList = allUserTask.getDbUserList();
    SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(tableName);
    TableEditorInput input = new TableEditorInput(table.getDatabase(), false, schemaInfo, table, type);
    input.setDbUserList(dbUserList);
    if (supportCharset) {
        List<Collation> collations = collationTask.getCollations();
        input.setCollationList(collations);
    }
    try {
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
        //If true, active opened editor of it and return, else open new editor.
        for (IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
            IEditorPart oldEditor = editorRef.getEditor(true);
            if (oldEditor.getEditorInput() instanceof TableEditorInput) {
                TableEditorInput oldInput = (TableEditorInput) oldEditor.getEditorInput();
                ISchemaNode oldTable = oldInput.getEditedTableNode();
                if (oldTable != null && oldTable.equals(table)) {
                    workbenchWindow.getActivePage().activate(oldEditor);
                    return;
                }
            }
        }
        workbenchWindow.getActivePage().openEditor(input, TableEditorPart.ID);
    } catch (Exception ignore) {
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) IEditorPart(org.eclipse.ui.IEditorPart) GetCollations(com.cubrid.cubridmanager.core.cubrid.table.task.GetCollations) Collation(com.cubrid.cubridmanager.core.cubrid.database.model.Collation) IWorkbench(org.eclipse.ui.IWorkbench) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IEditorReference(org.eclipse.ui.IEditorReference) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 2 with JDBCGetAllDbUserTask

use of com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask 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 3 with JDBCGetAllDbUserTask

use of com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask in project cubrid-manager by CUBRID.

the class CreateViewAction method run.

public void run(CubridDatabase database) {
    TaskExecutor taskExcutor = new CommonTaskExec(null);
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    JDBCGetAllDbUserTask task = new JDBCGetAllDbUserTask(databaseInfo);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    List<String> dbUserList = task.getDbUserList();
    CreateViewDialog dialog = new CreateViewDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), database, true);
    dialog.setDbUserList(dbUserList);
    ISelectionProvider provider = getSelectionProvider();
    if (dialog.open() == IDialogConstants.OK_ID && (provider instanceof TreeViewer)) {
        TreeViewer treeViewer = (TreeViewer) provider;
        ICubridNode folderNode = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridViewsFolderLoader.VIEWS_FOLDER_ID);
        if (folderNode == null || !folderNode.getLoader().isLoaded()) {
            return;
        }
        String viewName = dialog.getNewViewName();
        String owner = dialog.getOwner();
        String id = folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + viewName;
        ClassInfo newClassInfo = new ClassInfo(viewName, owner, ClassType.VIEW, false, false);
        ICubridNode newNode = CubridViewsFolderLoader.createUserViewNode(id, newClassInfo);
        CommonUITool.addNodeToTree(treeViewer, folderNode, newNode);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, folderNode);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(newNode, CubridNodeChangedEventType.NODE_ADD));
    } else {
        canceledTask = true;
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) CreateViewDialog(com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 4 with JDBCGetAllDbUserTask

use of com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask in project cubrid-manager by CUBRID.

the class EditViewAction method run.

/**
	 * run edit view
	 * @param ISchemaNode viewNode
	 * @param database CubridDatabase
	 */
public int run(CubridDatabase database, ISchemaNode node) {
    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 IDialogConstants.CANCEL_ID;
    }
    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);
    if (dialog.open() == IDialogConstants.OK_ID) {
        String viewName = node.getName();
        String newViewName = dialog.getNewViewName();
        String owner = dialog.getOwner();
        node.getDatabase().getDatabaseInfo().removeSchema(viewName);
        ISelectionProvider provider = getSelectionProvider();
        TreeViewer treeViewer = (TreeViewer) provider;
        if (!viewName.equals(newViewName)) {
            ClassInfo newClassInfo = (ClassInfo) node.getAdapter(ClassInfo.class);
            newClassInfo.setClassName(newViewName);
            newClassInfo.setOwnerName(owner);
            node.setId(node.getParent().getId() + ICubridNodeLoader.NODE_SEPARATOR + newViewName);
            node.setLabel(newViewName);
            treeViewer.refresh(node, true);
        }
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, node.getParent());
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        /*Broadcast the view changed*/
        QueryEditorUtil.fireSchemaNodeChanged(node);
        return IDialogConstants.OK_ID;
    }
    return IDialogConstants.CANCEL_ID;
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) 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) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 5 with JDBCGetAllDbUserTask

use of com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask in project cubrid-manager by CUBRID.

the class NewTableAction method doRun.

private void doRun(ISchemaNode node) {
    CubridDatabase database = node.getDatabase();
    TaskExecutor taskExcutor = new CommonTaskExec(null);
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    boolean supportCharset = CompatibleUtil.isSupportCreateDBByCharset(databaseInfo);
    JDBCGetAllDbUserTask allUserTask = new JDBCGetAllDbUserTask(databaseInfo);
    taskExcutor.addTask(allUserTask);
    GetCollations collationTask = null;
    if (supportCharset) {
        collationTask = new GetCollations(databaseInfo);
        taskExcutor.addTask(collationTask);
    }
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    TableEditorInput input = new TableEditorInput(database, true, null, null, EditTableAction.MODE_TABLE_EDIT);
    List<String> dbUserList = allUserTask.getDbUserList();
    input.setDbUserList(dbUserList);
    if (supportCharset) {
        List<Collation> collations = collationTask.getCollations();
        input.setCollationList(collations);
    }
    try {
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
        workbenchWindow.getActivePage().openEditor(input, TableEditorPart.ID);
    } catch (Exception ignore) {
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) GetCollations(com.cubrid.cubridmanager.core.cubrid.table.task.GetCollations) Collation(com.cubrid.cubridmanager.core.cubrid.database.model.Collation) IWorkbench(org.eclipse.ui.IWorkbench) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

JDBCGetAllDbUserTask (com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask)5 CreateViewDialog (com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog)3 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)3 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)3 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)3 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)3 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)2 TableEditorInput (com.cubrid.common.ui.cubrid.table.editor.TableEditorInput)2 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)2 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)2 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)2 Collation (com.cubrid.cubridmanager.core.cubrid.database.model.Collation)2 GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)2 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)2 GetCollations (com.cubrid.cubridmanager.core.cubrid.table.task.GetCollations)2 GetViewAllColumnsTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask)2 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 IWorkbench (org.eclipse.ui.IWorkbench)2