Search in sources :

Example 11 with ExecTaskWithProgress

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

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

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

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

the class BrokerParameterPropertyPage method performOk.

/**
	 * Save the page content
	 * 
	 * @return <code>true</code> if it saved successfully;<code>false</code>
	 *         otherwise
	 */
public boolean performOk() {
    // execute set parameter task
    String[][] brokerParameters = ConfConstants.getBrokerParameters(serverInfo);
    if (isTableChange()) {
        Map<String, String> paraMap = confParaMap.get(node.getLabel());
        //compare the default value, if equal default value and delete it from map
        for (String[] brokerPara : brokerParameters) {
            if (brokerPara[0].equals(ConfConstants.APPL_SERVER_PORT)) {
                String serverPort = paraMap.get(ConfConstants.APPL_SERVER_PORT);
                if (null != serverPort) {
                    int serverPortValue = Integer.parseInt(paraMap.get(ConfConstants.BROKER_PORT)) + 1;
                    if (serverPort.equalsIgnoreCase(Integer.toString(serverPortValue))) {
                        paraMap.remove(ConfConstants.APPL_SERVER_PORT);
                    }
                }
            } else if (brokerPara[0].equals(ConfConstants.LONG_QUERY_TIME)) {
                if (isQueryOrTransTimeUseMs) {
                    int intValue = Integer.parseInt(brokerPara[2]) * 1000;
                    if (Integer.toString(intValue).equals(paraMap.get(ConfConstants.LONG_QUERY_TIME))) {
                        paraMap.remove(ConfConstants.LONG_QUERY_TIME);
                    } else {
                        String sVal = paraMap.get(ConfConstants.LONG_QUERY_TIME);
                        double dVal = Double.parseDouble(sVal) / 1000;
                        paraMap.put(ConfConstants.LONG_QUERY_TIME, String.valueOf(dVal));
                    }
                } else {
                    if (brokerPara[2].equals(paraMap.get(ConfConstants.LONG_QUERY_TIME))) {
                        paraMap.remove(ConfConstants.LONG_QUERY_TIME);
                    }
                }
            } else if (brokerPara[0].equals(ConfConstants.LONG_TRANSACTION_TIME)) {
                if (isQueryOrTransTimeUseMs) {
                    int intValue = Integer.parseInt(brokerPara[2]) * 1000;
                    if (Integer.toString(intValue).equals(paraMap.get(ConfConstants.LONG_TRANSACTION_TIME))) {
                        paraMap.remove(ConfConstants.LONG_TRANSACTION_TIME);
                    } else {
                        String sVal = paraMap.get(ConfConstants.LONG_TRANSACTION_TIME);
                        double dVal = Double.parseDouble(sVal) / 1000;
                        paraMap.put(ConfConstants.LONG_TRANSACTION_TIME, String.valueOf(dVal));
                    }
                } else {
                    if (brokerPara[2].equals(paraMap.get(ConfConstants.LONG_TRANSACTION_TIME))) {
                        paraMap.remove(ConfConstants.LONG_TRANSACTION_TIME);
                    }
                }
            } else if (brokerPara[2].equals(paraMap.get(brokerPara[0]))) {
                paraMap.remove(brokerPara[0]);
            }
        }
        SetBrokerConfParameterTask setBrokerConfParameterTask = new SetBrokerConfParameterTask(serverInfo);
        setBrokerConfParameterTask.setConfParameters(confParaMap);
        String taskName = Messages.bind(Messages.setBrokerConfParameterTaskName, this.node.getName());
        CommonTaskExec taskExec = new CommonTaskExec(taskName);
        taskExec.addTask(setBrokerConfParameterTask);
        new ExecTaskWithProgress(taskExec).exec();
        if (taskExec.isSuccess()) {
            CommonUITool.openInformationBox(com.cubrid.cubridmanager.ui.common.Messages.titleSuccess, Messages.restartBrokerMsg);
        } else {
            return true;
        }
    }
    // refresh tap
    if (isSettingChange()) {
        boolean isOn = refreshBtn.getSelection();
        String interval = intervalTxt.getText();
        String serverName = node.getServer().getLabel();
        String nodeName = node.getLabel();
        BrokerIntervalSetting newSetting = new BrokerIntervalSetting(serverName, nodeName, interval, isOn);
        BrokerIntervalSettingManager manager = BrokerIntervalSettingManager.getInstance();
        manager.removeBrokerIntervalSetting(serverName, brokerName);
        manager.setBrokerInterval(newSetting);
    }
    return true;
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) BrokerIntervalSettingManager(com.cubrid.cubridmanager.ui.broker.editor.internal.BrokerIntervalSettingManager) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) SetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.SetBrokerConfParameterTask) BrokerIntervalSetting(com.cubrid.cubridmanager.ui.broker.editor.internal.BrokerIntervalSetting)

Example 15 with ExecTaskWithProgress

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

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