Search in sources :

Example 1 with SocketTask

use of com.cubrid.cubridmanager.core.common.socket.SocketTask in project cubrid-manager by CUBRID.

the class DatabaseStatusEditor method execTask.

/**
	 *
	 * Execute the tasks
	 *
	 * @param buttonId the button id
	 * @param tasks the tasks array
	 * @param cancelable whether can be cancelled
	 */
public void execTask(final int buttonId, final SocketTask[] tasks, boolean cancelable) {
    final Shell shell = parentComp.getShell();
    final Display display = shell.getDisplay();
    isRunning = false;
    try {
        new ProgressMonitorDialog(shell).run(true, cancelable, new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(com.cubrid.common.ui.spi.Messages.msgRunning, IProgressMonitor.UNKNOWN);
                if (monitor.isCanceled()) {
                    return;
                }
                isRunning = true;
                Thread thread = new Thread() {

                    public void run() {
                        while (!monitor.isCanceled() && isRunning) {
                            try {
                                sleep(1);
                            } catch (InterruptedException e) {
                            }
                        }
                        if (monitor.isCanceled()) {
                            for (SocketTask t : tasks) {
                                if (t != null) {
                                    t.cancel();
                                }
                            }
                        }
                    }
                };
                thread.start();
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                for (SocketTask task : tasks) {
                    if (task != null) {
                        task.execute();
                        final String msg = task.getErrorMsg();
                        if (monitor.isCanceled()) {
                            isRunning = false;
                            return;
                        }
                        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                            display.syncExec(new Runnable() {

                                public void run() {
                                    CommonUITool.openErrorBox(shell, msg);
                                }
                            });
                            isRunning = false;
                            return;
                        }
                    }
                    if (monitor.isCanceled()) {
                        isRunning = false;
                        return;
                    }
                }
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                isRunning = false;
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SocketTask(com.cubrid.cubridmanager.core.common.socket.SocketTask) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Display(org.eclipse.swt.widgets.Display) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 2 with SocketTask

use of com.cubrid.cubridmanager.core.common.socket.SocketTask in project cubrid-manager by CUBRID.

the class VolumeInformationEditor method execTask.

/**
	 * execute the task
	 *
	 * @param buttonId int
	 * @param tasks SocketTask[]
	 * @param cancelable boolean
	 */
public void execTask(final int buttonId, final SocketTask[] tasks, boolean cancelable) {
    final Shell shell = parentComp.getShell();
    final Display display = shell.getDisplay();
    isRunning = false;
    try {
        new ProgressMonitorDialog(shell).run(true, cancelable, new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(com.cubrid.common.ui.spi.Messages.msgRunning, IProgressMonitor.UNKNOWN);
                if (monitor.isCanceled()) {
                    return;
                }
                isRunning = true;
                Thread thread = new Thread() {

                    public void run() {
                        while (!monitor.isCanceled() && isRunning) {
                            try {
                                sleep(1);
                            } catch (InterruptedException e) {
                            }
                        }
                        if (monitor.isCanceled()) {
                            for (SocketTask t : tasks) {
                                if (t != null) {
                                    t.cancel();
                                }
                            }
                        }
                    }
                };
                thread.start();
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                for (SocketTask task : tasks) {
                    if (task != null) {
                        task.execute();
                        final String msg = task.getErrorMsg();
                        if (monitor.isCanceled()) {
                            isRunning = false;
                            return;
                        }
                        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                            display.syncExec(new Runnable() {

                                public void run() {
                                    CommonUITool.openErrorBox(shell, msg);
                                }
                            });
                            isRunning = false;
                            return;
                        }
                    }
                    if (monitor.isCanceled()) {
                        isRunning = false;
                        return;
                    }
                }
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                isRunning = false;
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SocketTask(com.cubrid.cubridmanager.core.common.socket.SocketTask) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Display(org.eclipse.swt.widgets.Display) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 3 with SocketTask

use of com.cubrid.cubridmanager.core.common.socket.SocketTask in project cubrid-manager by CUBRID.

the class BackupErrLogDialog method connect.

/**
	 * connect
	 * 
	 * @param buttonId int
	 * @param tasks SocketTask[]
	 * @param cancelable boolean
	 * @param shell Shell
	 */
public void connect(final int buttonId, final SocketTask[] tasks, boolean cancelable, Shell shell) {
    final Display display = shell.getDisplay();
    isRunning = false;
    try {
        new ProgressMonitorDialog(getShell()).run(true, cancelable, new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(com.cubrid.common.ui.spi.Messages.msgRunning, IProgressMonitor.UNKNOWN);
                if (monitor.isCanceled()) {
                    return;
                }
                isRunning = true;
                Thread thread = new Thread() {

                    public void run() {
                        while (!monitor.isCanceled() && isRunning) {
                            try {
                                sleep(1);
                            } catch (InterruptedException e) {
                            }
                        }
                        if (monitor.isCanceled()) {
                            for (SocketTask t : tasks) {
                                if (t != null) {
                                    t.cancel();
                                }
                            }
                        }
                    }
                };
                thread.start();
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                for (SocketTask task : tasks) {
                    if (task != null) {
                        task.execute();
                        final String msg = task.getErrorMsg();
                        if (monitor.isCanceled()) {
                            isRunning = false;
                            return;
                        }
                        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                            display.syncExec(new Runnable() {

                                public void run() {
                                    CommonUITool.openErrorBox(msg);
                                }
                            });
                            isRunning = false;
                            return;
                        }
                    }
                    if (monitor.isCanceled()) {
                        isRunning = false;
                        return;
                    }
                }
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                if (!monitor.isCanceled()) {
                    display.syncExec(new Runnable() {

                        public void run() {
                            if (buttonId > 0) {
                                setReturnCode(buttonId);
                                close();
                            }
                        }
                    });
                }
                isRunning = false;
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SocketTask(com.cubrid.cubridmanager.core.common.socket.SocketTask) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Display(org.eclipse.swt.widgets.Display) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 4 with SocketTask

use of com.cubrid.cubridmanager.core.common.socket.SocketTask in project cubrid-manager by CUBRID.

the class CopyDatabaseDialog method execTask.

/**
	 * Execute tasks
	 * 
	 * @param buttonId the button id
	 * @param tasks the task array
	 * @param cancelable whether can be canceled
	 * @param shell the shell
	 */
public void execTask(final int buttonId, final SocketTask[] tasks, boolean cancelable, Shell shell) {
    final Display display = shell.getDisplay();
    isRunning = false;
    try {
        new ProgressMonitorDialog(getShell()).run(true, cancelable, new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(com.cubrid.common.ui.spi.Messages.msgRunning, IProgressMonitor.UNKNOWN);
                if (monitor.isCanceled()) {
                    return;
                }
                isRunning = true;
                Thread thread = new Thread() {

                    public void run() {
                        while (!monitor.isCanceled() && isRunning) {
                            try {
                                sleep(1);
                            } catch (InterruptedException e) {
                            }
                        }
                        if (monitor.isCanceled()) {
                            for (SocketTask t : tasks) {
                                if (t != null) {
                                    t.cancel();
                                }
                            }
                        }
                    }
                };
                thread.start();
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                for (SocketTask task : tasks) {
                    if (task != null) {
                        task.execute();
                        final String msg = task.getErrorMsg();
                        if (monitor.isCanceled()) {
                            isRunning = false;
                            return;
                        }
                        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                            display.syncExec(new Runnable() {

                                public void run() {
                                    CommonUITool.openErrorBox(getShell(), msg);
                                }
                            });
                            isRunning = false;
                            return;
                        }
                    }
                    if (monitor.isCanceled()) {
                        isRunning = false;
                        return;
                    }
                }
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                if (!monitor.isCanceled()) {
                    display.syncExec(new Runnable() {

                        public void run() {
                            if (buttonId > 0) {
                                setReturnCode(buttonId);
                                close();
                            }
                        }
                    });
                }
                isRunning = false;
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SocketTask(com.cubrid.cubridmanager.core.common.socket.SocketTask) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Display(org.eclipse.swt.widgets.Display) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 5 with SocketTask

use of com.cubrid.cubridmanager.core.common.socket.SocketTask in project cubrid-manager by CUBRID.

the class CopyDatabaseDialog method okPressed.

/**
	 * When ok button press,call this method
	 */
protected void okPressed() {
    if (!verify()) {
        return;
    }
    destDbName = destinationDBNameText.getText();
    if (!CommonUITool.openConfirmBox(parentComp.getShell(), Messages.warnYesNoCopyDb)) {
        return;
    }
    SocketTask checkTask = getCheckDirsTask();
    SocketTask copyTask = getCopyDbTask();
    TaskJobExecutor taskExec = new CommonTaskJobExec(this);
    taskExec.addTask(checkTask);
    taskExec.addTask(copyTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    jobName = Messages.msgCopyDbRearJobName + " - " + dbName + "@" + serverName;
    taskExec.schedule(jobName, jobFamily, true, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) SocketTask(com.cubrid.cubridmanager.core.common.socket.SocketTask) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily)

Aggregations

SocketTask (com.cubrid.cubridmanager.core.common.socket.SocketTask)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)8 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)8 Display (org.eclipse.swt.widgets.Display)8 Shell (org.eclipse.swt.widgets.Shell)3 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)1 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)1 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)1