Search in sources :

Example 11 with TaskExecutor

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

the class CreateTriggerDialog method executeByJDBC.

/**
	 *
	 * Execute to add or alter trigger by JDBC
	 *
	 * @param buttonId int
	 */
private void executeByJDBC(int buttonId) {
    // FIXME move this logic to core module
    String createSQL = generateSqlText().toString();
    if (StringUtil.isEmpty(createSQL)) {
        return;
    }
    String taskName = null;
    String message = null;
    if (buttonId == IDialogConstants.OK_ID) {
        taskName = Messages.bind(Messages.addTriggerTaskName, triggerName);
        message = Messages.newTriggerSuccess;
    } else if (buttonId == ALTER_TRIGGER_OK_ID) {
        createSQL = createSQL.substring(createSQL.indexOf("ALTER TRIGGER "));
        message = Messages.alterTriggerSuccess;
        taskName = Messages.bind(Messages.alterTriggerTaskName, triggerName);
    }
    // add or alter triggers by JDBC
    JDBCSqlExecuteTask jdbcTask = new JDBCSqlExecuteTask(taskName, database.getDatabaseInfo(), createSQL);
    TaskExecutor taskExecutor = new CommonTaskExec(taskName);
    taskExecutor.addTask(jdbcTask);
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    if (taskExecutor.isSuccess()) {
        triggerName = triggerNameText.getText();
        setReturnCode(buttonId);
        close();
        CommonUITool.openInformationBox(Messages.msgInformation, message);
    }
}
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) JDBCSqlExecuteTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCSqlExecuteTask)

Example 12 with TaskExecutor

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

the class BLOBCellPopupDialog method exportData.

/**
	 *
	 * Export data to file
	 *
	 * @param isOpenProgram boolean
	 * @param filePath String
	 */
private boolean exportData(final String filePath, final boolean isOpenProgram) {
    final String charsetName = fileCharsetCombo.getText();
    if (currValue instanceof String) {
        try {
            "".getBytes(charsetName);
        } catch (UnsupportedEncodingException e) {
            CommonUITool.openErrorBox(Messages.errCharset);
            return false;
        }
    }
    AbstractUITask task = new AbstractUITask() {

        boolean isSuccess = false;

        public void execute(final IProgressMonitor monitor) {
            BufferedWriter writer = null;
            FileOutputStream out = null;
            InputStream in = null;
            try {
                if (currValue instanceof String) {
                    String content = (String) currValue;
                    if (DBAttrTypeFormatter.isBinaryString(content)) {
                        content = DBAttrTypeFormatter.getInnerString(content);
                        byte[] bytes = DBAttrTypeFormatter.getBytes(content, 2);
                        content = new String(bytes, charsetName);
                    } else if (DBAttrTypeFormatter.isHexString(content)) {
                        content = DBAttrTypeFormatter.getInnerString(content);
                        byte[] bytes = DBAttrTypeFormatter.getBytes(content, 16);
                        content = new String(bytes, charsetName);
                    }
                    writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), charsetName));
                    writer.write(content);
                    writer.flush();
                } else if (currValue instanceof File) {
                    out = new FileOutputStream(filePath);
                    in = new FileInputStream((File) currValue);
                    byte[] bytes = new byte[1024];
                    int len = 0;
                    while ((len = in.read(bytes)) != -1) {
                        out.write(bytes, 0, len);
                    }
                    out.flush();
                } else if (currValue instanceof byte[]) {
                    out = new FileOutputStream(filePath);
                    byte[] bytes = (byte[]) currValue;
                    out.write(bytes, 0, bytes.length);
                    out.flush();
                }
                isSuccess = true;
            } catch (Exception e) {
                errorMsg = e.getMessage();
            } finally {
                if (writer != null) {
                    try {
                        writer.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
            }
        }

        public void cancel() {
        //empty
        }

        public void finish() {
        //empty
        }

        public boolean isCancel() {
            return false;
        }

        public boolean isSuccess() {
            return isSuccess;
        }
    };
    TaskExecutor taskExecutor = new CommonTaskExec(Messages.msgExportFieldData);
    taskExecutor.addTask(task);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (taskExecutor.isSuccess()) {
        if (isOpenProgram) {
            return true;
        }
        CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgExportSuccess);
        return true;
    }
    return false;
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) FileOutputStream(java.io.FileOutputStream) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Example 13 with TaskExecutor

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

the class PropertyAction method run.

/**
	 * Open property dialog,view and set property
	 */
public void run() {
    final Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        return;
    }
    final ICubridNode node = (ICubridNode) obj[0];
    String type = node.getType();
    if (CubridNodeType.SERVER.equals(type) || CubridNodeType.DATABASE_FOLDER.equals(type) || CubridNodeType.DATABASE.equals(type) || CubridNodeType.BROKER_FOLDER.equals(type) || CubridNodeType.BROKER.equals(type)) {
        TaskExecutor taskExcutor = new GetPropertyExecutor(node, getShell());
        ServerInfo serverInfo = node.getServer().getServerInfo();
        GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
        GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(serverInfo);
        GetCMConfParameterTask getCMConfParameterTask = new GetCMConfParameterTask(serverInfo);
        if (CubridNodeType.SERVER.equals(type)) {
            taskExcutor.addTask(getCubridConfParameterTask);
            taskExcutor.addTask(getBrokerConfParameterTask);
            taskExcutor.addTask(getCMConfParameterTask);
            if (CompatibleUtil.isSupportNewHAConfFile(serverInfo)) {
                GetHAConfParameterTask getHAConfParameterTask = new GetHAConfParameterTask(serverInfo);
                taskExcutor.addTask(getHAConfParameterTask);
            }
        }
        if (CubridNodeType.DATABASE_FOLDER.equals(type) || CubridNodeType.DATABASE.equals(type)) {
            taskExcutor.addTask(getCubridConfParameterTask);
        }
        if (CubridNodeType.BROKER_FOLDER.equals(type) || CubridNodeType.BROKER.equals(type)) {
            taskExcutor.addTask(getBrokerConfParameterTask);
        }
        new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    }
    if (!isCancel) {
        Dialog dialog = PreferenceUtil.createPropertyDialog(getShell(), node);
        dialog.open();
    }
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) GetHAConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetHAConfParameterTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) Dialog(org.eclipse.jface.dialogs.Dialog) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask)

Example 14 with TaskExecutor

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

the class StopServiceAction method doRun.

/**
	 * Perform do run
	 * 
	 * @param servers
	 */
public void doRun(CubridServer[] servers) {
    CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
    final TreeViewer viewer = view.getViewer();
    if (servers.length > 0) {
        CubridServer server = servers[0];
        if (isSupported(server)) {
            final JobFamily jobFamily = new JobFamily();
            final String serverName = server.getName();
            String dbName = JobFamily.ALL_DB;
            jobFamily.setServerName(serverName);
            jobFamily.setDbName(dbName);
            Job[] jobs = Job.getJobManager().find(jobFamily);
            if (jobs.length > 0) {
                CommonUITool.openWarningBox(Messages.bind(Messages.msgStopServiceWithJob, serverName));
                return;
            }
            TaskExecutor taskExcutor = new StopServiceExecutor(server, getShell(), viewer);
            ServerInfo serverInfo = server.getServerInfo();
            GetCubridConfParameterTask task = new GetCubridConfParameterTask(serverInfo);
            taskExcutor.addTask(task);
            new ExecTaskWithProgress(taskExcutor).exec();
        }
    }
//		for(CubridServer server : servers) {
//			final JobFamily jobFamily = new JobFamily();
//			final String serverName = server.getName();
//			String dbName = JobFamily.ALL_DB;
//			jobFamily.setServerName(serverName);
//			jobFamily.setDbName(dbName);
//			Job[] jobs = Job.getJobManager().find(jobFamily);
//			if (jobs.length > 0) {
//				CommonUITool.openWarningBox(Messages.bind(
//						Messages.msgStopServiceWithJob, serverName));
//				return;
//			}
//
//			TaskExecutor taskExcutor = new StopServiceExecutor(server, getShell(),
//					viewer);
//			ServerInfo serverInfo = server.getServerInfo();
//			GetCubridConfParameterTask task = new GetCubridConfParameterTask(
//					serverInfo);
//			taskExcutor.addTask(task);
//			new ExecTaskWithProgress(taskExcutor).exec();
//		}
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) Job(org.eclipse.core.runtime.jobs.Job)

Example 15 with TaskExecutor

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

the class RestartBrokerAction method run.

public void run() {
    final Object[] obj = this.getSelectedObj();
    DefaultCubridNode selection = (DefaultCubridNode) obj[0];
    if (selection == null || selection.getServer() == null) {
        return;
    }
    ServerInfo serverInfo = selection.getServer().getServerInfo();
    if (serverInfo == null) {
        return;
    }
    //stop first
    StopBrokerTask stopTask = new StopBrokerTask(serverInfo);
    stopTask.setBrokerName(selection.getLabel());
    //then start again
    StartBrokerTask startTask = new StartBrokerTask(serverInfo);
    startTask.setBrokerName(selection.getLabel());
    final String taskName = Messages.bind(Messages.restartBrokerTaskName, selection.getLabel());
    TaskExecutor taskExecutor = new CommonTaskExec(taskName);
    taskExecutor.addTask(stopTask);
    taskExecutor.addTask(startTask);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (!taskExecutor.isSuccess()) {
        return;
    }
    TreeViewer treeViewer = (TreeViewer) this.getSelectionProvider();
    CommonUITool.refreshNavigatorTree(treeViewer, selection.getParent());
    ActionManager.getInstance().fireSelectionChanged(getSelection());
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) DefaultCubridNode(com.cubrid.common.ui.spi.model.DefaultCubridNode) StartBrokerTask(com.cubrid.cubridmanager.core.broker.task.StartBrokerTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) StopBrokerTask(com.cubrid.cubridmanager.core.broker.task.StopBrokerTask)

Aggregations

ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)124 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)124 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)81 TreeViewer (org.eclipse.jface.viewers.TreeViewer)38 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)37 ITask (com.cubrid.common.core.task.ITask)35 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)29 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)25 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)24 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)23 ArrayList (java.util.ArrayList)23 Shell (org.eclipse.swt.widgets.Shell)15 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)14 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 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9