Search in sources :

Example 1 with CreateOrEditSerialTask

use of com.cubrid.cubridmanager.core.cubrid.serial.task.CreateOrEditSerialTask in project cubrid-manager by CUBRID.

the class CreateOrEditSerialDialog method createSerial.

/**
	 * Execute task and create serial
	 *
	 * @param buttonId the button id
	 */
private void createSerial(final int buttonId) {
    // FIXME move this logic to core module
    serialName = serialNameText.getText();
    final String startVal = startValText.getText();
    final String incrementVal = incrementValText.getText();
    final String minVal = minValText.getText();
    final String maxVal = maxValText.getText();
    final boolean isNoMinValue = noMinValueBtn.getSelection();
    final boolean isNoMaxValue = noMaxValueBtn.getSelection();
    final boolean isCycle = cycleButton.getSelection();
    final String cacheCount = isSupportCache ? cacheCountText.getText().trim() : null;
    final boolean isNoCache = isSupportCache ? noCacheBtn.getSelection() : false;
    if (editedNode == null) {
        taskName = Messages.bind(Messages.createSerialTaskName, serialName);
    } else {
        taskName = Messages.bind(Messages.editSerialTaskName, serialName);
    }
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                if (task instanceof CreateOrEditSerialTask) {
                    CreateOrEditSerialTask createSerialTask = (CreateOrEditSerialTask) task;
                    if (editedNode == null) {
                        createSerialTask.createSerial(serialName, startVal, incrementVal, maxVal, minVal, isCycle, isNoMinValue, isNoMaxValue, cacheCount, isNoCache);
                    } else {
                        createSerialTask.editSerial(serialName, startVal, incrementVal, maxVal, minVal, isCycle, isNoMinValue, isNoMaxValue, cacheCount, isNoCache);
                    }
                }
                final String msg = task.getErrorMsg();
                if (monitor.isCanceled()) {
                    return false;
                }
                if (openErrorBox(getShell(), msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            return true;
        }
    };
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    CreateOrEditSerialTask task = new CreateOrEditSerialTask(databaseInfo);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (taskExcutor.isSuccess()) {
        setReturnCode(buttonId);
        close();
    }
}
Also used : 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) CreateOrEditSerialTask(com.cubrid.cubridmanager.core.cubrid.serial.task.CreateOrEditSerialTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)

Aggregations

ITask (com.cubrid.common.core.task.ITask)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1 CreateOrEditSerialTask (com.cubrid.cubridmanager.core.cubrid.serial.task.CreateOrEditSerialTask)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1