Search in sources :

Example 1 with UnloadDatabaseTask

use of com.cubrid.cubridmanager.core.cubrid.database.task.UnloadDatabaseTask in project cubrid-manager by CUBRID.

the class UnloadDatabaseDialog method unloadDatabase.

/**
	 * 
	 * Execute task and unload database
	 * 
	 * @param buttonId the button id
	 */
private void unloadDatabase(final int buttonId) {
    isCanFinished = true;
    TaskJobExecutor taskExcutor = new TaskJobExecutor() {

        private List<String> unloadResultList = null;

        public IStatus exec(final IProgressMonitor monitor) {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    getShell().setVisible(false);
                }
            });
            if (monitor.isCanceled()) {
                cancel();
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        setReturnCode(buttonId);
                        close();
                    }
                });
                isCanFinished = true;
                return Status.CANCEL_STATUS;
            }
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (monitor.isCanceled()) {
                    cancel();
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            setReturnCode(buttonId);
                            close();
                        }
                    });
                    isCanFinished = true;
                    return Status.CANCEL_STATUS;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            getShell().setVisible(true);
                        }
                    });
                    isCanFinished = false;
                    return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                }
                if (isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                if (task instanceof CheckDirTask) {
                    CheckDirTask checkDirTask = (CheckDirTask) task;
                    final String[] dirs = checkDirTask.getNoExistDirectory();
                    if (dirs != null && dirs.length > 0) {
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                CreateDirDialog dialog = new CreateDirDialog(getShell());
                                dialog.setDirs(dirs);
                                if (dialog.open() != IDialogConstants.OK_ID) {
                                    isCanFinished = false;
                                    getShell().setVisible(true);
                                }
                            }
                        });
                    }
                } else if (task instanceof CheckFileTask) {
                    CheckFileTask checkFileTask = (CheckFileTask) task;
                    final String[] files = checkFileTask.getExistFiles();
                    if (files != null && files.length > 0) {
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                OverrideFileDialog dialog = new OverrideFileDialog(getShell());
                                dialog.setFiles(files);
                                if (dialog.open() != IDialogConstants.OK_ID) {
                                    isCanFinished = false;
                                    getShell().setVisible(true);
                                }
                            }
                        });
                    }
                } else if (task instanceof UnloadDatabaseTask) {
                    UnloadDatabaseTask unloadDatabaseTask = (UnloadDatabaseTask) task;
                    if (!isSchemaOnly) {
                        unloadResultList = unloadDatabaseTask.getUnloadDbResult();
                    }
                }
                if (!isCanFinished) {
                    return Status.CANCEL_STATUS;
                }
                if (monitor.isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            setReturnCode(buttonId);
                            close();
                        }
                    });
                    return Status.CANCEL_STATUS;
                }
            }
            return Status.OK_STATUS;
        }

        /**
			 * Notification that a job has completed execution,
			 * 
			 * @param event the event details
			 */
        public void done(IJobChangeEvent event) {
            if (event.getResult() == Status.OK_STATUS) {
                if (isSchemaOnly) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgSuccessUnload);
                            setReturnCode(buttonId);
                            close();
                        }
                    });
                } else {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            UnloadDatabaseResultDialog dialog = new UnloadDatabaseResultDialog(getShell());
                            dialog.setUnloadResulList(unloadResultList);
                            dialog.open();
                            setReturnCode(buttonId);
                            close();
                        }
                    });
                }
            }
        }
    };
    CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
    CheckFileTask checkFileTask = new CheckFileTask(database.getServer().getServerInfo());
    final UnloadDatabaseTask unloadDatabaseTask = new UnloadDatabaseTask(database.getServer().getServerInfo(), database.getDatabaseInfo().getCharSet());
    fillTask(taskExcutor, checkDirTask, checkFileTask, unloadDatabaseTask);
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    String jobName = Messages.msgUnloadDbRearJobName + " - " + dbName + "@" + serverName;
    JobFamily jobFamily = new JobFamily();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    taskExcutor.schedule(jobName, jobFamily, true, Job.SHORT);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITask(com.cubrid.common.core.task.ITask) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) List(java.util.List) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) UnloadDatabaseTask(com.cubrid.cubridmanager.core.cubrid.database.task.UnloadDatabaseTask)

Aggregations

ITask (com.cubrid.common.core.task.ITask)1 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)1 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)1 CheckDirTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)1 CheckFileTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask)1 UnloadDatabaseTask (com.cubrid.cubridmanager.core.cubrid.database.task.UnloadDatabaseTask)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1