Search in sources :

Example 86 with ExecTaskWithProgress

use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.

the class EditFunctionAction method run.

/**
	 * Open the EditFunctionDialog and edit function
	 */
public void run() {
    Object[] objArr = this.getSelectedObj();
    if (!isSupported(objArr)) {
        this.setEnabled(false);
        return;
    }
    Shell shell = getShell();
    CubridDatabase database = null;
    ISchemaNode node = null;
    if (objArr[0] instanceof ISchemaNode && NodeType.STORED_PROCEDURE_FUNCTION.equals(((ISchemaNode) objArr[0]).getType())) {
        node = (ISchemaNode) objArr[0];
        database = node.getDatabase();
    }
    if (database == null || node == null) {
        CommonUITool.openErrorBox(shell, Messages.errSelectProcedure);
        return;
    }
    final GetSPInfoListTask task = new GetSPInfoListTask(database.getDatabaseInfo());
    task.setSpName(node.getName());
    TaskExecutor taskExcutor = new CommonTaskExec(getText());
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    List<SPInfo> list = task.getSPInfoList();
    if (list.size() > 1) {
        CommonUITool.openErrorBox(shell, Messages.errDuplicateName);
        return;
    }
    if (list.isEmpty()) {
        CommonUITool.openErrorBox(shell, Messages.errNotExistName);
        return;
    }
    EditFunctionDialog dlg = new EditFunctionDialog(shell);
    dlg.setDatabase(database);
    dlg.setNewFlag(false);
    dlg.setSpInfo(list.get(0));
    if (dlg.open() == IDialogConstants.OK_ID) {
        ActionManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) SPInfo(com.cubrid.cubridmanager.core.cubrid.sp.model.SPInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) EditFunctionDialog(com.cubrid.common.ui.cubrid.procedure.dialog.EditFunctionDialog) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetSPInfoListTask(com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask)

Example 87 with ExecTaskWithProgress

use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.

the class EditProcedureDialog method execute.

/**
	 * Execute tasks
	 *
	 * @param buttonId the button id
	 * @param tasks the tasks array
	 */
public void execute(final int buttonId, final ITask[] tasks) {
    TaskExecutor taskExcutor = new CommonTaskExec(null);
    taskExcutor.setTask(tasks);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (taskExcutor.isSuccess() && buttonId >= 0) {
        setReturnCode(buttonId);
        close();
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)

Example 88 with ExecTaskWithProgress

use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress 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)

Example 89 with ExecTaskWithProgress

use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.

the class SchemaCompareDialog method buttonPressed.

/**
	 * Call this method when the button in button bar is pressed
	 *
	 * @param buttonId
	 *            the button id
	 */
protected void buttonPressed(int buttonId) {
    isCanceled = false;
    if (buttonId == COMPARE_ID) {
        if (!isSelectedAllSideDatabases()) {
            CommonUITool.openWarningBox(com.cubrid.common.ui.compare.Messages.errNeedSelectCompareDb);
            return;
        }
        if (isSelectedSameDatabases()) {
            CommonUITool.openWarningBox(com.cubrid.common.ui.compare.Messages.errSelectSameCompareDb);
            return;
        }
        final List<String> origDbLabel = new ArrayList<String>();
        for (int i = 0; i < selections.size(); i++) {
            origDbLabel.add(leftCombo.getItem(i));
        }
        final int leftIndex = leftCombo.getSelectionIndex();
        final int rightIndex = rightCombo.getSelectionIndex();
        final List<String> rightDbLabel = new ArrayList<String>();
        final List<CubridDatabase> sourceDBList = new ArrayList<CubridDatabase>();
        final List<CubridDatabase> targetDBList = new ArrayList<CubridDatabase>();
        final List<TableSchemaCompareEditorInput> editorInput = new ArrayList<TableSchemaCompareEditorInput>();
        ITask reportBugTask = new AbstractUITask() {

            public void cancel() {
                isCanceled = true;
            }

            public void finish() {
            }

            public boolean isCancel() {
                return isCanceled;
            }

            public boolean isSuccess() {
                return true;
            }

            public void execute(IProgressMonitor monitor) {
                // FIXME logic code move to core module
                CubridDatabase leftDb = (CubridDatabase) selections.get(leftIndex);
                sourceDBList.add(leftDb);
                List<TableDetailInfo> leftDbTableInfoList = TableSchemaCompareUtil.getTableInfoList(leftDb);
                TableSchemaCompareRunner thread = null;
                CubridDatabase rightDb = (CubridDatabase) selections.get(rightIndex);
                targetDBList.add(rightDb);
                rightDbLabel.add(origDbLabel.get(rightIndex));
                thread = new TableSchemaCompareRunner(SchemaCompareDialog.this, leftDb, rightDb, leftDbTableInfoList);
                thread.start();
                try {
                    thread.join();
                } catch (InterruptedException e) {
                    LOGGER.error(e.getMessage(), e);
                }
                TableSchemaCompareEditorInput input = thread.getInput();
                editorInput.add(input);
            }
        };
        TaskExecutor taskExecutor = new CommonTaskExec(Messages.titleSchemaComparison);
        taskExecutor.addTask(reportBugTask);
        new ExecTaskWithProgress(taskExecutor).exec();
        if (taskExecutor.isSuccess()) {
            for (int i = 0; i < rightDbLabel.size(); i++) {
                if (isCanceled) {
                    return;
                }
                showSchemaCompareEditor(editorInput.get(i));
            }
            if (isCanceled) {
                return;
            }
            super.buttonPressed(IDialogConstants.OK_ID);
        }
    }
    super.buttonPressed(buttonId);
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) ArrayList(java.util.ArrayList) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) TableSchemaCompareEditorInput(com.cubrid.common.ui.compare.schema.control.TableSchemaCompareEditorInput) 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) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) TableSchemaCompareRunner(com.cubrid.common.ui.compare.schema.TableSchemaCompareRunner)

Example 90 with ExecTaskWithProgress

use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.

the class ExportERwinAction method run.

public void run() {
    // FIXME logic code move to core module
    int selected = 0;
    int logined = 0;
    Object[] objects = getSelectedObj();
    if (objects instanceof Object[]) {
        for (Object object : objects) {
            if (object instanceof CubridDatabase) {
                selected++;
                CubridDatabase database = (CubridDatabase) object;
                if (database.isLogined()) {
                    logined++;
                }
            }
        }
    }
    if (selected > 1) {
        CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectLeastOneDb);
        return;
    }
    if (selected <= 0) {
        CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectExportDb);
        return;
    }
    if (logined <= 0) {
        CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectLoginedDb);
        return;
    }
    FileDialog dialog = new FileDialog(getShell(), SWT.SAVE | SWT.APPLICATION_MODAL);
    dialog.setFilterExtensions(new String[] { "*.xml" });
    String filename = dialog.open();
    if (filename == null) {
        return;
    }
    if (filename.trim().equals("")) {
        CommonUITool.openErrorBox(Messages.errFileNameIsEmpty);
        return;
    }
    for (Object obj : objects) {
        if (!(obj instanceof CubridDatabase)) {
            continue;
        }
        CubridDatabase database = (CubridDatabase) obj;
        final Map<String, SchemaInfo> allSchemaInfos = new HashMap<String, SchemaInfo>();
        TaskExecutor executor = new TaskExecutor() {

            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();
                    } else if (task instanceof GetAllSchemaTask) {
                        monitor.beginTask(Messages.msgGenerateInfo, 100);
                        GetAllSchemaTask gTask = (GetAllSchemaTask) task;
                        gTask.execute();
                        if (task.getErrorMsg() == null) {
                            allSchemaInfos.putAll(gTask.getSchemas());
                        }
                        if (allSchemaInfos.size() == 0) {
                            continue;
                        }
                    }
                }
                return true;
            }
        };
        ExportSchemaTask task = new ExportSchemaTask(allSchemaInfos, filename);
        GetAllSchemaTask schemaTask = new GetAllSchemaTask(database.getDatabaseInfo());
        executor.addTask(schemaTask);
        executor.addTask(task);
        new ExecTaskWithProgress(executor).busyCursorWhile();
        if (executor.isSuccess()) {
            CommonUITool.openInformationBox(Messages.titleExportSchema, Messages.msgExportSuccess);
        }
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) HashMap(java.util.HashMap) JAXBException(javax.xml.bind.JAXBException) ExportSchemaTask(com.cubrid.common.ui.cubrid.database.erwin.task.ExportSchemaTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) GetAllSchemaTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllSchemaTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) FileDialog(org.eclipse.swt.widgets.FileDialog) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)155 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)124 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)106 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)40 TreeViewer (org.eclipse.jface.viewers.TreeViewer)39 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)37 ITask (com.cubrid.common.core.task.ITask)35 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)30 ArrayList (java.util.ArrayList)29 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)26 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)25 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)23 Shell (org.eclipse.swt.widgets.Shell)15 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)14 HashMap (java.util.HashMap)13 Map (java.util.Map)13 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)13 DefaultCubridNode (com.cubrid.common.ui.spi.model.DefaultCubridNode)12 IEditorPart (org.eclipse.ui.IEditorPart)12 LogInfo (com.cubrid.cubridmanager.core.logs.model.LogInfo)11