Search in sources :

Example 1 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class EditFunctionDialog method buttonPressed.

/**
	 * When press button,call it
	 *
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == BUTTON_ADD_ID) {
        Map<String, String> model = new HashMap<String, String>();
        try {
            AddFuncParamsDialog addDlg = new AddFuncParamsDialog(getShell(), model, sqlTypeMap, javaTypeMap, true, funcParamsListData, database);
            if (addDlg.open() == IDialogConstants.OK_ID) {
                // add
                funcParamsListData.add(model);
                funcParamsTableViewer.refresh();
                for (int i = 0; i < funcParamsTableViewer.getTable().getColumnCount(); i++) {
                    funcParamsTableViewer.getTable().getColumn(i).pack();
                }
            }
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    } else if (buttonId == BUTTON_EDIT_ID) {
        // edit
        int index = funcParamsTable.getSelectionIndex();
        if (index < 0) {
            return;
        }
        Map<String, String> map = funcParamsListData.get(index);
        AddFuncParamsDialog editDlg = new AddFuncParamsDialog(getShell(), map, sqlTypeMap, javaTypeMap, false, funcParamsListData, database);
        if (editDlg.open() == IDialogConstants.OK_ID) {
            funcParamsTableViewer.refresh();
            for (int i = 0; i < funcParamsTableViewer.getTable().getColumnCount(); i++) {
                funcParamsTableViewer.getTable().getColumn(i).pack();
            }
        }
    } else if (buttonId == BUTTON_UP_ID) {
        // up
        int index = funcParamsTable.getSelectionIndex();
        if (index <= 0) {
            return;
        }
        Map<String, String> map = funcParamsListData.get(index);
        Map<String, String> preMap = funcParamsListData.get(index - 1);
        funcParamsListData.set(index - 1, map);
        funcParamsListData.set(index, preMap);
        funcParamsTableViewer.refresh();
    } else if (buttonId == BUTTON_DOWN_ID) {
        // down
        int index = funcParamsTable.getSelectionIndex();
        if (index < 0 || index >= funcParamsListData.size() - 1) {
            return;
        }
        Map<String, String> map = funcParamsListData.get(index);
        Map<String, String> nextMap = funcParamsListData.get(index + 1);
        funcParamsListData.set(index + 1, map);
        funcParamsListData.set(index, nextMap);
        funcParamsTableViewer.refresh();
    } else if (buttonId == BUTTON_DROP_ID) {
        // drop
        int index = funcParamsTable.getSelectionIndex();
        if (index < 0) {
            return;
        }
        funcParamsListData.remove(index);
        funcParamsTableViewer.refresh();
        getButton(BUTTON_EDIT_ID).setEnabled(false);
        getButton(BUTTON_UP_ID).setEnabled(false);
        getButton(BUTTON_DOWN_ID).setEnabled(false);
        getButton(BUTTON_DROP_ID).setEnabled(false);
    } else if (buttonId == IDialogConstants.OK_ID) {
        if (valid()) {
            CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
            functionName = funcNameText.getText();
            if (!newFlag) {
                String dropSql = "DROP FUNCTION " + QuerySyntax.escapeKeyword(funcNameText.getText());
                task.addSqls(dropSql);
            }
            task.addSqls(getSQLScript());
            execute(IDialogConstants.OK_ID, new ITask[] { task });
        }
        return;
    }
    super.buttonPressed(buttonId);
}
Also used : ITask(com.cubrid.common.core.task.ITask) HashMap(java.util.HashMap) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 2 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class TableSchemaCompareInfoPart method showTopButtons.

private void showTopButtons() {
    final Composite buttonsComposite = new Composite(topSash, SWT.NONE);
    buttonsComposite.setLayout(new GridLayout(5, false));
    buttonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    if (compareRealDatabase) {
        showTopButtonsForRealDatabase(buttonsComposite);
    }
    final Button viewComparisonBtn = new Button(buttonsComposite, SWT.NONE);
    viewComparisonBtn.setText(Messages.viewEntireSchemaComparison);
    viewComparisonBtn.setToolTipText(Messages.aboutViewEntireSchemaComparison);
    viewComparisonBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent event) {
            final List<String> sourceDBSchema = new ArrayList<String>();
            final List<String> targetDBSchema = new ArrayList<String>();
            viewComparisonBtn.setEnabled(false);
            ITask reportBugTask = new AbstractUITask() {

                public void cancel() {
                }

                public void finish() {
                }

                public boolean isCancel() {
                    return false;
                }

                public boolean isSuccess() {
                    return true;
                }

                public void execute(IProgressMonitor monitor) {
                    Map<String, SchemaInfo> source = compareModel.getSourceSchemas();
                    Map<String, SchemaInfo> target = compareModel.getTargetSchemas();
                    List<SchemaInfo> commonTables = new LinkedList<SchemaInfo>();
                    for (SchemaInfo sourceTable : source.values()) {
                        if (target.containsKey(sourceTable.getClassname())) {
                            commonTables.add(sourceTable);
                        }
                    }
                    Collections.sort(commonTables);
                    String s_schema = getDBSchema(sourceDB, source, commonTables);
                    sourceDBSchema.add(s_schema);
                    String t_schema = getDBSchema(targetDB, target, commonTables);
                    targetDBSchema.add(t_schema);
                }
            };
            TaskExecutor taskExecutor = new CommonTaskExec(Messages.loadEntireSchemaComparison);
            taskExecutor.addTask(reportBugTask);
            new ExecTaskWithProgress(taskExecutor).exec();
            if (taskExecutor.isSuccess()) {
                String targetDbName = "";
                if (targetDB.isVirtual()) {
                    targetDbName = Messages.targetDatabase;
                    if (StringUtil.isNotEmpty(targetDB.getName())) {
                        targetDbName += " : " + targetDB.getName();
                    }
                } else {
                    targetDbName = Messages.targetDatabase + ": " + targetDB.getDatabaseInfo().getBrokerIP() + "@" + targetDB.getName();
                }
                String sourceBrokerIp = sourceDB.getDatabaseInfo().getBrokerIP();
                String sourceDbName = sourceDB.getName();
                showEntireSchemaCompareEditor(Messages.sourceDatabase + ": " + sourceBrokerIp + "@" + sourceDbName, Messages.targetDatabase + ": " + targetDbName, sourceDBSchema.get(0), targetDBSchema.get(0));
            }
            viewComparisonBtn.setEnabled(true);
        }
    });
    Button copyAlterFromSourceBtn = new Button(buttonsComposite, SWT.NONE);
    copyAlterFromSourceBtn.setText(Messages.copyWholeSchemaAlter + "[" + Messages.fromSourceToTargetLabel + "]");
    copyAlterFromSourceBtn.setToolTipText(Messages.aboutCopyAlterSource);
    copyAlterFromSourceBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent event) {
            copyTableAlterDDL(sourceDB, targetDB, true);
        }
    });
    Button copyAlterFromTargetBtn = new Button(buttonsComposite, SWT.NONE);
    copyAlterFromTargetBtn.setText(Messages.copyWholeSchemaAlter + "[" + Messages.fromTargetToSourceLabel + "]");
    copyAlterFromTargetBtn.setToolTipText(Messages.aboutCopyAlterTarget);
    copyAlterFromTargetBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent event) {
            copyTableAlterDDL(targetDB, sourceDB, false);
        }
    });
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 3 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class ImportERwinAction method createCompareModel.

/**
	 *
	 * @param tableSchema
	 * @param schemaInfos
	 */
private void createCompareModel(final String modelName, final Map<String, TableSchema> tableSchema, final Map<String, ERWinSchemaInfo> schemaInfos) {
    final List<TableSchemaCompareModelInputLazy> input = new ArrayList<TableSchemaCompareModelInputLazy>();
    ITask reportBugTask = new AbstractUITask() {

        private boolean success = false;

        public void cancel() {
        }

        public void finish() {
        }

        public boolean isCancel() {
            return false;
        }

        public boolean isSuccess() {
            return success;
        }

        public void execute(IProgressMonitor monitor) {
            List<TableDetailInfo> leftDbTableInfoList = TableSchemaCompareUtil.getTableInfoList(database);
            final CubridDatabase virtualDb = new CubridDatabase(modelName, modelName);
            virtualDb.setVirtual(true);
            DatabaseInfo info = database.getDatabaseInfo();
            virtualDb.setDatabaseInfo(info);
            WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info);
            Map<String, SchemaInfo> dbSchemaInfos = new HashMap<String, SchemaInfo>();
            Collection<ERWinSchemaInfo> erwinSchemas = schemaInfos.values();
            for (ERWinSchemaInfo erwinSchema : erwinSchemas) {
                SchemaInfo schemaInfo = (SchemaInfo) erwinSchema;
                dbSchemaInfos.put(schemaInfo.getClassname(), schemaInfo);
            }
            wrappedDatabaseInfo.addSchemaInfos(dbSchemaInfos);
            wrappedDatabaseInfo.addTableSchemas(tableSchema);
            ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
            TableSchemaModel leftModel = TableSchemaCompareUtil.createTableSchemaModel(leftDbTableInfoList);
            TableSchemaModel rightModel = new TableSchemaModel();
            rightModel.getTableSchemaMap().putAll(tableSchema);
            TableSchemaComparator comparator = new TableSchemaComparator(database, virtualDb);
            TableSchemaCompareModel model = comparator.compare(leftModel, rightModel);
            model.setSourceDB(database);
            model.setTargetDB(virtualDb);
            // TODO rename class to ErwinCompareModelInput
            input.add(new TableSchemaCompareModelInputLazy(model));
            success = true;
        }
    };
    TaskExecutor taskExecutor = new CommonTaskExec(Messages.titleSchemaComparison);
    taskExecutor.addTask(reportBugTask);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (taskExecutor.isSuccess()) {
        try {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input.get(0), TableSchemaCompareInfoPart.ID);
        } catch (Exception e) {
        }
    }
}
Also used : TableSchemaCompareModelInputLazy(com.cubrid.common.ui.compare.schema.control.TableSchemaCompareModelInputLazy) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) HashMap(java.util.HashMap) TableSchemaComparator(com.cubrid.common.ui.compare.schema.TableSchemaComparator) ArrayList(java.util.ArrayList) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) TableSchemaModel(com.cubrid.common.ui.compare.schema.model.TableSchemaModel) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)

Example 4 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class DeleteSerialAction method run.

/**
	 * Delete the selected serials
	 */
public void run(ISchemaNode[] nodeArray) {
    if (nodeArray == null) {
        LOGGER.error("The nodeArray parameter is a null.");
        return;
    }
    final List<String> serialNameList = new ArrayList<String>();
    final StringBuffer serialNames = new StringBuffer();
    for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
        if (!isSupported(nodeArray[i])) {
            setEnabled(false);
            return;
        }
        ISchemaNode schemaNode = (ISchemaNode) nodeArray[i];
        if (i == 0) {
            serialNames.append(schemaNode.getLabel());
        }
        serialNameList.add(schemaNode.getLabel());
    }
    if (nodeArray.length > 1) {
        serialNames.append(", ...");
    }
    String cfmMsg = Messages.bind(Messages.msgConfirmDelSerial, serialNames.toString(), nodeArray.length);
    boolean isDelete = CommonUITool.openConfirmBox(getShell(), cfmMsg);
    if (!isDelete) {
        return;
    }
    final Shell shell = getShell();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            String taskName = Messages.bind(Messages.delSerialTaskName, serialNames.toString());
            monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                if (task instanceof DeleteSerialTask) {
                    DeleteSerialTask deleteSerialTask = (DeleteSerialTask) task;
                    String[] serialNames = new String[serialNameList.size()];
                    deleteSerialTask.deleteSerial(serialNameList.toArray(serialNames));
                }
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            return true;
        }
    };
    ISchemaNode schemaNode = (ISchemaNode) nodeArray[0];
    CubridDatabase database = schemaNode.getDatabase();
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    DeleteSerialTask deleteSerialTask = new DeleteSerialTask(databaseInfo);
    taskExcutor.addTask(deleteSerialTask);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    ISelectionProvider provider = this.getSelectionProvider();
    ICubridNode parent = schemaNode.getParent();
    if (provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
            parent.removeChild((ICubridNode) nodeArray[i]);
        }
        viewer.remove(parent, nodeArray);
        viewer.setSelection(new StructuredSelection(parent), true);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DeleteSerialTask(com.cubrid.cubridmanager.core.cubrid.serial.task.DeleteSerialTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 5 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class EditSerialAction method run.

/**
	 * Open the editSerial dialog and edit serial
	 */
public int run(CubridDatabase database, final ISchemaNode node) {
    final Shell shell = getShell();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(Messages.loadSerialTaskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                SerialInfo serialInfo = null;
                if (task instanceof GetSerialInfoTask) {
                    GetSerialInfoTask getSerialInfoTask = (GetSerialInfoTask) task;
                    serialInfo = getSerialInfoTask.getSerialInfo(node.getLabel());
                }
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                if (serialInfo == null) {
                    openErrorBox(shell, Messages.errNameNotExist, monitor);
                    return false;
                }
                node.setModelObj(serialInfo);
            }
            return true;
        }
    };
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    GetSerialInfoTask task = new GetSerialInfoTask(databaseInfo);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return IDialogConstants.CANCEL_ID;
    }
    boolean isEditorAble = ActionSupportUtil.isSupportSinSelCheckDbUser(node, NodeType.SERIAL);
    CreateOrEditSerialDialog dialog = new CreateOrEditSerialDialog(getShell(), isEditorAble);
    dialog.setEditedNode(node);
    dialog.setDatabase(database);
    if (dialog.open() == IDialogConstants.OK_ID) {
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        return IDialogConstants.OK_ID;
    }
    return IDialogConstants.CANCEL_ID;
}
Also used : CreateOrEditSerialDialog(com.cubrid.common.ui.cubrid.serial.dialog.CreateOrEditSerialDialog) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) SerialInfo(com.cubrid.common.core.common.model.SerialInfo) GetSerialInfoTask(com.cubrid.cubridmanager.core.cubrid.serial.task.GetSerialInfoTask)

Aggregations

ITask (com.cubrid.common.core.task.ITask)85 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)49 IStatus (org.eclipse.core.runtime.IStatus)37 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)35 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)35 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)28 ArrayList (java.util.ArrayList)27 Status (org.eclipse.core.runtime.Status)23 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)20 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)17 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)15 Map (java.util.Map)15 Display (org.eclipse.swt.widgets.Display)15 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)14 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)14 List (java.util.List)14 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)13 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)13 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)12 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)11