Search in sources :

Example 26 with DefaultSchemaNode

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

the class UpdateStatisticsAction method run.

public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    // FIXME move this logic to core module
    List<String> sqlList = new ArrayList<String>();
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < obj.length; i++) {
        ISchemaNode schemaNode = (ISchemaNode) obj[i];
        String tableName = schemaNode.getParent().getName();
        int partitionNameLoc = schemaNode.getName().lastIndexOf("__p__");
        if (partitionNameLoc == -1) {
            continue;
        }
        partitionNameLoc += 5;
        String partitionName = schemaNode.getName().substring(partitionNameLoc);
        String sql = "ALTER TABLE " + QuerySyntax.escapeKeyword(tableName) + " ANALYZE PARTITION " + QuerySyntax.escapeKeyword(partitionName);
        sqlList.add(sql);
        buffer.append(",");
        buffer.append(schemaNode.getName());
    }
    String str = buffer.toString().replaceFirst(",", "");
    if (CommonUITool.openConfirmBox(Messages.bind(Messages.msgConfirmUpdateStatis, str))) {
        DefaultSchemaNode node = (DefaultSchemaNode) obj[0];
        String taskName = Messages.bind(Messages.updateStatisTaskName, node.getName());
        TaskExecutor executor = new CommonTaskExec(taskName);
        UpdateStatisticsTask task = new UpdateStatisticsTask(node.getDatabase().getDatabaseInfo());
        task.setSqlList(sqlList);
        executor.addTask(task);
        new ExecTaskWithProgress(executor).exec();
        if (executor.isSuccess()) {
            CommonUITool.openInformationBox(Messages.titleSuccess, Messages.msgSuccessUpdateStatis);
        }
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ArrayList(java.util.ArrayList) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) UpdateStatisticsTask(com.cubrid.cubridmanager.core.cubrid.table.task.UpdateStatisticsTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)

Example 27 with DefaultSchemaNode

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

the class MakeCloneQueryAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    final Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    final DefaultSchemaNode tableNode = (DefaultSchemaNode) obj[0];
    CubridDatabase db = tableNode.getDatabase();
    DatabaseInfo dbInfo = db.getDatabaseInfo();
    GetTablesTask getTableTask = new GetTablesTask(dbInfo);
    List<String> tableList = getTableTask.getAllTableAndViews();
    String tableName = null;
    if (NodeType.USER_TABLE.equals(tableNode.getType())) {
        tableName = tableNode.getName();
    }
    final CloneTableDialog dialog = new CloneTableDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), tableList, tableName);
    if (IDialogConstants.OK_ID == dialog.open()) {
        targetName = dialog.getTargetName();
        ICubridNode[] nodeArray = { tableNode };
        super.doRun(nodeArray);
    }
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CloneTableDialog(com.cubrid.common.ui.cubrid.table.dialog.CloneTableDialog) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetTablesTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetTablesTask)

Example 28 with DefaultSchemaNode

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

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

the class ImportSettingExcelPage method validate.

public boolean validate() {
    setErrorMessage(null);
    setPageComplete(false);
    ImportConfig importConfig = getImportDataWizard().getImportConfig();
    List<DefaultSchemaNode> result = mappingComposite.getSelectedTableNode();
    if (result.size() == 0) {
        setErrorMessage(Messages.errNoSelectedTable);
        return false;
    }
    for (DefaultSchemaNode node : result) {
        Object value = node.getData(ImportObjectLabelProvider.IS_MAPPED);
        if (value == null || !Boolean.parseBoolean(value.toString())) {
            setErrorMessage(Messages.bind(Messages.errTableSetting, node.getName()));
            return false;
        }
        TableConfig tableConfig = importConfig.getTableConfig(node.getName());
        if (tableConfig != null) {
            String filePath = tableConfig.getFilePath();
            if (!StringUtil.isEmpty(filePath)) {
                File file = new File(filePath);
                if (!file.exists()) {
                    setErrorMessage(Messages.bind(Messages.errFileNotExist, filePath));
                    return false;
                }
            }
        }
    }
    setPageComplete(true);
    return true;
}
Also used : DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) File(java.io.File)

Example 30 with DefaultSchemaNode

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

the class ERSchemaTableNodesLoader method getAllUserTablesInfo.

/**
	 * Get all the user tables node infos
	 * 
	 * @return List<SchemaInfo>
	 */
public List<SchemaInfo> getAllUserTablesInfo() {
    List<DefaultSchemaNode> tableNodes = getAllTablesNode();
    List<SchemaInfo> tables = new ArrayList<SchemaInfo>();
    for (DefaultSchemaNode node : tableNodes) {
        SchemaInfo table = dbNode.getDatabaseInfo().getSchemaInfo(node.getName());
        if (null != table) {
            tables.add(table);
        }
    }
    return tables;
}
Also used : ArrayList(java.util.ArrayList) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)88 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)62 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)33 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)22 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)21 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)18 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)17 ArrayList (java.util.ArrayList)15 TreeViewer (org.eclipse.jface.viewers.TreeViewer)10 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)9 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)9 Display (org.eclipse.swt.widgets.Display)9 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)8 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)7 File (java.io.File)5 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)4 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)4 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)4 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)4 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)4