Search in sources :

Example 56 with CommonTaskExec

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

the class DeleteFunctionAction method run.

public void run() {
    // FIXME logic code move to core module
    Object[] objects = this.getSelectedObj();
    if (objects == null || !isSupported(objects)) {
        setEnabled(false);
        return;
    }
    Shell shell = getShell();
    CubridDatabase database = null;
    ISchemaNode node = null;
    if (objects[0] instanceof ISchemaNode && NodeType.STORED_PROCEDURE_FUNCTION.equals(((ISchemaNode) objects[0]).getType())) {
        node = (ISchemaNode) objects[0];
        database = node.getDatabase();
    }
    if (database == null || node == null) {
        CommonUITool.openErrorBox(shell, Messages.errSelectFunction);
        return;
    }
    if (!CommonUITool.openConfirmBox(shell, Messages.msgSureDropFunction)) {
        return;
    }
    CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
    for (Object object : objects) {
        node = (ISchemaNode) object;
        String sql = "DROP FUNCTION " + QuerySyntax.escapeKeyword(node.getName());
        task.addSqls(sql);
    }
    TaskExecutor taskExcutor = new CommonTaskExec(getText());
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    ISelectionProvider provider = this.getSelectionProvider();
    ICubridNode parent = node.getParent();
    if (provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        for (int i = 0; objects != null && i < objects.length; i++) {
            parent.removeChild((ISchemaNode) objects[i]);
        }
        viewer.remove(parent, objects);
        viewer.setSelection(new StructuredSelection(parent), true);
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 57 with CommonTaskExec

use of com.cubrid.common.ui.spi.progress.CommonTaskExec 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 58 with CommonTaskExec

use of com.cubrid.common.ui.spi.progress.CommonTaskExec 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 59 with CommonTaskExec

use of com.cubrid.common.ui.spi.progress.CommonTaskExec 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 60 with CommonTaskExec

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

the class CreateViewAction method run.

public void run(CubridDatabase database) {
    TaskExecutor taskExcutor = new CommonTaskExec(null);
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    JDBCGetAllDbUserTask task = new JDBCGetAllDbUserTask(databaseInfo);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    List<String> dbUserList = task.getDbUserList();
    CreateViewDialog dialog = new CreateViewDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), database, true);
    dialog.setDbUserList(dbUserList);
    ISelectionProvider provider = getSelectionProvider();
    if (dialog.open() == IDialogConstants.OK_ID && (provider instanceof TreeViewer)) {
        TreeViewer treeViewer = (TreeViewer) provider;
        ICubridNode folderNode = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridViewsFolderLoader.VIEWS_FOLDER_ID);
        if (folderNode == null || !folderNode.getLoader().isLoaded()) {
            return;
        }
        String viewName = dialog.getNewViewName();
        String owner = dialog.getOwner();
        String id = folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + viewName;
        ClassInfo newClassInfo = new ClassInfo(viewName, owner, ClassType.VIEW, false, false);
        ICubridNode newNode = CubridViewsFolderLoader.createUserViewNode(id, newClassInfo);
        CommonUITool.addNodeToTree(treeViewer, folderNode, newNode);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, folderNode);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(newNode, CubridNodeChangedEventType.NODE_ADD));
    } else {
        canceledTask = true;
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) CreateViewDialog(com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Aggregations

CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)106 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)106 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)81 TreeViewer (org.eclipse.jface.viewers.TreeViewer)31 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)24 ArrayList (java.util.ArrayList)24 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)23 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)18 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)14 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)13 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)13 DefaultCubridNode (com.cubrid.common.ui.spi.model.DefaultCubridNode)12 LogInfo (com.cubrid.cubridmanager.core.logs.model.LogInfo)11 IEditorPart (org.eclipse.ui.IEditorPart)11 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)9 HashMap (java.util.HashMap)9 AbstractUITask (com.cubrid.common.core.task.AbstractUITask)8 Map (java.util.Map)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)8