Search in sources :

Example 61 with ITask

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

the class EditUserDialog method execTask.

public boolean execTask(final int buttonId, final ITask[] tasks, Shell shell) {
    final Display display = Display.getCurrent();
    TaskExecutor taskExecutor = new TaskExecutor() {

        public boolean exec(IProgressMonitor monitor) {
            for (ITask task : tasks) {
                if (task instanceof GetAllClassListTask) {
                    setAllClassInfoList(((GetAllClassListTask) task).getAllClassInfoList());
                } else {
                    task.execute();
                }
                if (openErrorBox(null, task.getErrorMsg(), monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            if (!monitor.isCanceled()) {
                display.syncExec(new Runnable() {

                    public void run() {
                        if (buttonId > 0) {
                            setReturnCode(buttonId);
                            close();
                        }
                    }
                });
            }
            return true;
        }
    };
    for (ITask task : tasks) {
        taskExecutor.addTask(task);
    }
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    return taskExecutor.isSuccess();
}
Also used : TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) Display(org.eclipse.swt.widgets.Display)

Example 62 with ITask

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

the class CreateTriggerDialog method executeBySocket.

/**
	 *
	 * Execute to add or alter trigger by socket
	 *
	 * @param buttonId int
	 */
private void executeBySocket(int buttonId) {
    // FIXME remove
    String taskName = null;
    String message = null;
    ITask executedTask = null;
    if (buttonId == IDialogConstants.OK_ID) {
        String eventType = getEventType();
        String triggerEventTargetTable = triggerTargetTableCombo.getText().trim();
        String triggerEventTargetColumn = triggerTargetColumnCombo.getText().trim();
        AddTriggerTask task = new AddTriggerTask(database.getServer().getServerInfo());
        task.setDbName(database.getName());
        task.setTriggerName("\"" + triggerName + "\"");
        String eventTime = getEventTime();
        task.setConditionTime(TriggerConditionTime.eval(eventTime));
        task.setEventType(TriggerEvent.eval(eventType));
        String triggerActionType = getActionType();
        String triggerAction = triggerActionText.getText().trim();
        String crChar = "\r";
        String nlChar = "\n";
        triggerAction = triggerAction.replaceAll(crChar, "");
        triggerAction = triggerAction.replaceAll(nlChar, " ");
        task.setAction(Trigger.TriggerAction.eval(triggerActionType), triggerAction);
        if (triggerEventTargetTable.length() > 0) {
            if (triggerEventTargetColumn.length() > 0) {
                task.setEventTarget("\"" + triggerEventTargetTable + "\"(\"" + triggerEventTargetColumn + "\")");
            } else {
                task.setEventTarget("\"" + triggerEventTargetTable + "\"");
            }
        }
        String actionTime = getActionTime();
        if (!actionTime.equals(Messages.actionTimeDefault)) {
            // action time selected
            task.setActionTime(TriggerActionTime.eval(actionTime));
        }
        String triggerCondition = triggerConditionText.getText().trim();
        triggerCondition = triggerCondition.replaceAll(crChar, "");
        triggerCondition = triggerCondition.replaceAll(nlChar, " ");
        task.setCondition(triggerCondition);
        String triggerStatus = this.getStatus();
        task.setStatus(TriggerStatus.eval(triggerStatus));
        String strPriority = triggerPriorityText.getText();
        task.setPriority(strPriority);
        taskName = Messages.bind(Messages.addTriggerTaskName, triggerName);
        message = Messages.newTriggerSuccess;
        executedTask = task;
    } else if (buttonId == ALTER_TRIGGER_OK_ID) {
        AlterTriggerTask task = new AlterTriggerTask(database.getServer().getServerInfo());
        task.setDbName(database.getName());
        task.setTriggerName(trigger.getName());
        String triggerStatus = this.getStatus();
        task.setStatus(TriggerStatus.eval(triggerStatus));
        String strPriority = triggerPriorityText.getText();
        task.setPriority(strPriority);
        taskName = Messages.bind(Messages.alterTriggerTaskName, trigger.getName());
        message = Messages.alterTriggerSuccess;
        executedTask = task;
    }
    TaskExecutor taskExecutor = new CommonTaskExec(taskName);
    taskExecutor.addTask(executedTask);
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    if (taskExecutor.isSuccess()) {
        setReturnCode(buttonId);
        close();
        CommonUITool.openInformationBox(Messages.msgInformation, message);
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ITask(com.cubrid.common.core.task.ITask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) AddTriggerTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.AddTriggerTask) AlterTriggerTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.AlterTriggerTask)

Example 63 with ITask

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

the class TruncateTableAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    StringBuilder sb = new StringBuilder();
    int len = obj.length;
    final List<String> tableList = new ArrayList<String>();
    CubridDatabase database = null;
    for (int i = 0; i < len; i++) {
        ISchemaNode table = (ISchemaNode) obj[i];
        database = table.getDatabase();
        final String tableName = table.getName();
        tableList.add(tableName);
        if (i < 100) {
            if (sb.length() > 0) {
                sb.append(", ");
            }
            sb.append(tableName);
        }
    }
    if (len > 100) {
        sb.append("...");
    }
    String message = Messages.bind(Messages.confirmTableDeleteWarn, sb.toString());
    if (!CommonUITool.openConfirmBox(message)) {
        return;
    }
    final TruncateTableTask task = new TruncateTableTask(database.getDatabaseInfo());
    TaskJobExecutor taskExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            CommonUITool.openInformationBox(Messages.msg_information, Messages.resultTableDeleteInformantion);
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    String[] tableNames = new String[tableList.size()];
    tableNames = tableList.toArray(tableNames);
    task.setTableName(tableNames);
    taskExec.addTask(task);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgTruncateTableJobName + " - " + tableList.toString() + "@" + dbName + "@" + serverName;
    taskExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ArrayList(java.util.ArrayList) TruncateTableTask(com.cubrid.cubridmanager.core.cubrid.table.task.TruncateTableTask) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 64 with ITask

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

the class ExportERwinDataController method exportData.

public boolean exportData(Shell parentShell, boolean isDirectSave) {
    String fileFullName;
    if (!isDirectSave || latestFileFullName == null) {
        FileDialog dialog = new FileDialog(parentShell, SWT.SAVE | SWT.APPLICATION_MODAL);
        dialog.setFilterExtensions(new String[] { "*.xml" });
        fileFullName = dialog.open();
    } else {
        fileFullName = latestFileFullName;
    }
    if (fileFullName == null) {
        return false;
    }
    if (fileFullName.trim().length() == 0) {
        CommonUITool.openErrorBox(Messages.errFileNameIsEmpty);
        return false;
    }
    TaskExecutor executor = new TaskExecutor() {

        @Override
        public boolean exec(IProgressMonitor monitor) {
            for (ITask task : taskList) {
                if (task instanceof ExportSchemaTask) {
                    ExportSchemaTask eTask = (ExportSchemaTask) task;
                    try {
                        eTask.initMarshaller();
                    } catch (JAXBException e) {
                        e.printStackTrace();
                        eTask.cancel();
                        return false;
                    }
                    monitor.setTaskName(Messages.msgGenerateInfo);
                    monitor.worked(50);
                    eTask.execute();
                    monitor.setTaskName(Messages.msgFinished);
                    monitor.worked(100);
                    monitor.done();
                }
            }
            return true;
        }
    };
    ExportSchemaTask task = new ExportSchemaTask(getERSchema().getAllSchemaInfo(), fileFullName);
    List<ERTable> tables = getERSchema().getTables();
    Map<String, String> tablePLMap = new HashMap<String, String>();
    Map<String, Map<String, List>> tablesPhysicalLogicalMap = new HashMap<String, Map<String, List>>();
    for (ERTable table : tables) {
        tablePLMap.put(table.getName(true), table.getName(false));
        Map<String, List> columnsPLMap = new HashMap<String, List>();
        tablesPhysicalLogicalMap.put(table.getName(true), columnsPLMap);
        List<ERTableColumn> columns = table.getColumns();
        for (ERTableColumn column : columns) {
            List<String> logicalNameAndType = new LinkedList<String>();
            columnsPLMap.put(column.getName(true), logicalNameAndType);
            logicalNameAndType.add(column.getName(false));
            logicalNameAndType.add(column.getShowType(false));
        }
    }
    task.setTablePLMap(tablePLMap);
    task.setTablesPhysicalLogicalMap(tablesPhysicalLogicalMap);
    executor.addTask(task);
    new ExecTaskWithProgress(executor).busyCursorWhile();
    if (executor.isSuccess()) {
        latestFileFullName = fileFullName;
        CommonUITool.openInformationBox(com.cubrid.common.ui.er.Messages.titleExport, Messages.bind(com.cubrid.common.ui.er.Messages.msgExportSuccess, fileFullName));
    }
    return executor.isSuccess();
}
Also used : ITask(com.cubrid.common.core.task.ITask) HashMap(java.util.HashMap) JAXBException(javax.xml.bind.JAXBException) ERTable(com.cubrid.common.ui.er.model.ERTable) ExportSchemaTask(com.cubrid.common.ui.cubrid.database.erwin.task.ExportSchemaTask) LinkedList(java.util.LinkedList) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) List(java.util.List) LinkedList(java.util.LinkedList) FileDialog(org.eclipse.swt.widgets.FileDialog) HashMap(java.util.HashMap) Map(java.util.Map)

Example 65 with ITask

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

the class ExportImportGsonDataController method exportData.

public boolean exportData(Shell parentShell, boolean isDirectSave) {
    String fileFullName;
    if (!isDirectSave || latestFileFullName == null) {
        FileDialog dialog = new FileDialog(parentShell, SWT.SAVE | SWT.APPLICATION_MODAL);
        dialog.setFilterExtensions(new String[] { "*.erd" });
        fileFullName = dialog.open();
    } else {
        fileFullName = latestFileFullName;
    }
    if (fileFullName == null) {
        return false;
    }
    if (fileFullName.trim().length() == 0) {
        CommonUITool.openErrorBox(Messages.errFileNameIsEmpty);
        return false;
    }
    TaskExecutor executor = new TaskExecutor() {

        public boolean exec(IProgressMonitor monitor) {
            for (ITask task : taskList) {
                if (task instanceof ExportGsonDataTask) {
                    ExportGsonDataTask eTask = (ExportGsonDataTask) task;
                    monitor.setTaskName(Messages.msgGenerateInfo);
                    monitor.worked(50);
                    eTask.execute();
                    monitor.setTaskName(Messages.msgFinished);
                    monitor.worked(100);
                    monitor.done();
                }
            }
            return true;
        }
    };
    ExportGsonDataTask task = new ExportGsonDataTask(getERSchema(), fileFullName);
    executor.addTask(task);
    new ExecTaskWithProgress(executor).busyCursorWhile();
    if (executor.isSuccess()) {
        latestFileFullName = fileFullName;
        CommonUITool.openInformationBox(com.cubrid.common.ui.er.Messages.titleExport, Messages.bind(com.cubrid.common.ui.er.Messages.msgExportSuccess, fileFullName));
    }
    return executor.isSuccess();
}
Also used : TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) FileDialog(org.eclipse.swt.widgets.FileDialog)

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