Search in sources :

Example 46 with ITask

use of com.cubrid.common.core.task.ITask 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)

Example 47 with ITask

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

the class EditProcedureDialog 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, procParamsListData, database);
            if (addDlg.open() == IDialogConstants.OK_ID) {
                // add
                procParamsListData.add(model);
                procParamsTableViewer.refresh();
                for (int i = 0; i < procParamsTableViewer.getTable().getColumnCount(); i++) {
                    procParamsTableViewer.getTable().getColumn(i).pack();
                }
            }
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    } else if (buttonId == BUTTON_EDIT_ID) {
        // edit
        int index = procParamsTable.getSelectionIndex();
        if (index < 0) {
            return;
        }
        Map<String, String> map = procParamsListData.get(index);
        AddFuncParamsDialog editDlg = new AddFuncParamsDialog(getShell(), map, sqlTypeMap, javaTypeMap, false, procParamsListData, database);
        if (editDlg.open() == IDialogConstants.OK_ID) {
            procParamsTableViewer.refresh();
            for (int i = 0; i < procParamsTableViewer.getTable().getColumnCount(); i++) {
                procParamsTableViewer.getTable().getColumn(i).pack();
            }
        }
    } else if (buttonId == BUTTON_UP_ID) {
        // up
        int index = procParamsTable.getSelectionIndex();
        if (index <= 0) {
            return;
        }
        Map<String, String> map = procParamsListData.get(index);
        Map<String, String> preMap = procParamsListData.get(index - 1);
        procParamsListData.set(index - 1, map);
        procParamsListData.set(index, preMap);
        procParamsTableViewer.refresh();
    } else if (buttonId == BUTTON_DOWN_ID) {
        // down
        int index = procParamsTable.getSelectionIndex();
        if (index < 0 || index >= procParamsListData.size() - 1) {
            return;
        }
        Map<String, String> map = procParamsListData.get(index);
        Map<String, String> nextMap = procParamsListData.get(index + 1);
        procParamsListData.set(index + 1, map);
        procParamsListData.set(index, nextMap);
        procParamsTableViewer.refresh();
    } else if (buttonId == BUTTON_DROP_ID) {
        // drop
        int index = procParamsTable.getSelectionIndex();
        if (index < 0) {
            return;
        }
        procParamsListData.remove(index);
        procParamsTableViewer.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()) {
            procedureName = procNameText.getText();
            CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
            if (!newFlag) {
                String dropSql = "DROP PROCEDURE " + QuerySyntax.escapeKeyword(procNameText.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) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 48 with ITask

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

the class CreateViewDialog method buttonPressed.

protected void buttonPressed(int buttonId) {
    if (buttonId == BUTTON_ADD_ID) {
        // add
        AddQueryDialog addDlg = new AddQueryDialog(parentComp.getShell(), true, -1, this);
        if (addDlg.open() == IDialogConstants.OK_ID) {
            queryTableViewer.getTable().setSelection(queryTableViewer.getTable().getItemCount() - 1);
            querydescText.setText(formatSql(queryTableViewer.getTable().getItem(queryTableViewer.getTable().getItemCount() - 1).getText()));
        }
        queryTableViewer.getTable().getColumn(0).setWidth(200);
        setButtonStatus();
        valid();
        return;
    } else if (buttonId == BUTTON_DROP_ID) {
        // delete
        int index = queryTableViewer.getTable().getSelectionIndex();
        queryListData.remove(index);
        queryTableViewer.refresh();
        if (queryListData.size() > index) {
            queryTableViewer.getTable().setSelection(index);
            querydescText.setText(formatSql(queryTableViewer.getTable().getItem(index).getText()));
        } else if (index > 0) {
            queryTableViewer.getTable().setSelection(index - 1);
            querydescText.setText(formatSql(queryTableViewer.getTable().getItem(index - 1).getText()));
        } else {
            queryTableViewer.getTable().setSelection(index - 1);
            querydescText.setText("");
        }
        validateResult(null, false, -1);
        setButtonStatus();
        valid();
        return;
    } else if (buttonId == BUTTON_EDIT_ID) {
        StringBuffer sb = new StringBuffer();
        int index = queryTableViewer.getTable().getSelectionIndex();
        sb.append(queryListData.get(index).get("0"));
        AddQueryDialog addDlg = new AddQueryDialog(parentComp.getShell(), false, index, this);
        if (addDlg.open() == IDialogConstants.OK_ID) {
            // add
            queryTableViewer.getTable().setSelection(index);
            String sql = queryTableViewer.getTable().getItem(index).getText();
            querydescText.setText(formatSql(sql));
        }
        setButtonStatus();
        valid();
        return;
    } else if (buttonId == IDialogConstants.OK_ID) {
        if (!valid()) {
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        owner = ownerCombo.getText();
        Map<String, ClassAuthorizations> authMap = getDropViewAuthorizations();
        CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
        String dropSql = makeDropSQLScript();
        if (dropSql.length() > 0) {
            dropSql = DatabaseInfo.wrapShardQuery(databaseInfo, dropSql);
            task.addSqls(dropSql);
        }
        String sql = makeCreateSQLScript();
        sql = DatabaseInfo.wrapShardQuery(databaseInfo, sql);
        task.addSqls(sql);
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        String ownerOld = dbInfo.getAuthLoginedDbUserInfo().getName();
        String ownerNew = ownerCombo.getText();
        boolean isSameOwner = StringUtil.isEqualIgnoreCase(ownerOld, ownerNew);
        if (!isSameOwner) {
            sql = makeChangeOwnerSQLScript();
            sql = DatabaseInfo.wrapShardQuery(databaseInfo, sql);
            task.addCallSqls(sql);
        }
        addGrantAuthSQLScriptToTask(authMap, tableText.getText(), task);
        execTask(-1, new ITask[] { task }, true, getParentShell());
        if (task.getErrorMsg() != null) {
            return;
        }
        String title = com.cubrid.common.ui.common.Messages.titleSuccess;
        String message = isNewTableFlag ? Messages.msgSuccessCreateView : Messages.msgSuccessEditView;
        CommonUITool.openInformationBox(title, message);
    }
    viewName = tableText.getText();
    super.buttonPressed(buttonId);
}
Also used : ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) Map(java.util.Map) HashMap(java.util.HashMap)

Example 49 with ITask

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

the class CubridTriggerFolderLoader method load.

/**
	 * 
	 * Load children object for parent
	 * 
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        CubridDatabase database = ((ISchemaNode) parent).getDatabase();
        if (!database.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
            database.getDatabaseInfo().setTriggerList(null);
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        ITask task = null;
        if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
            task = new GetTriggerListTask(parent.getServer().getServerInfo());
            ((GetTriggerListTask) task).setDbName(database.getLabel());
        } else {
            task = new JDBCGetTriggerListTask(databaseInfo);
        }
        monitorCancel(monitor, new ITask[] { task });
        task.execute();
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            parent.removeAllChild();
            openErrorBox(errorMsg);
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        parent.removeAllChild();
        List<Trigger> triggerList = null;
        if (task instanceof GetTriggerListTask) {
            triggerList = ((GetTriggerListTask) task).getTriggerInfoList();
        } else if (task instanceof JDBCGetTriggerListTask) {
            triggerList = ((JDBCGetTriggerListTask) task).getTriggerInfoList();
        }
        if (triggerList != null && !triggerList.isEmpty()) {
            for (Trigger trigger : triggerList) {
                String id = parent.getId() + NODE_SEPARATOR + trigger.getName();
                ICubridNode triggerNode = createTriggerNode(id, trigger);
                parent.addChild(triggerNode);
            }
        }
        databaseInfo.setTriggerList(triggerList);
        Collections.sort(parent.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) Trigger(com.cubrid.common.core.common.model.Trigger) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) JDBCGetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerListTask) GetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.GetTriggerListTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) JDBCGetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerListTask)

Example 50 with ITask

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

the class OpenTriggerDetailInfoPartProgress method run.

public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    ITask task = null;
    if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
        task = new GetTriggerListTask(database.getServer().getServerInfo());
        ((GetTriggerListTask) task).setDbName(database.getLabel());
    } else {
        task = new JDBCGetTriggerListTask(databaseInfo);
    }
    task.execute();
    if (!task.isSuccess()) {
        LOGGER.error(task.getErrorMsg());
        return;
    }
    if (task instanceof GetTriggerListTask) {
        triggerList = ((GetTriggerListTask) task).getTriggerInfoList();
    } else if (task instanceof JDBCGetTriggerListTask) {
        triggerList = ((JDBCGetTriggerListTask) task).getTriggerInfoList();
    }
    success = true;
}
Also used : ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) JDBCGetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerListTask) GetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.GetTriggerListTask) JDBCGetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerListTask)

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