Search in sources :

Example 1 with RenameDatabaseDialog

use of com.cubrid.cubridmanager.ui.cubrid.database.dialog.RenameDatabaseDialog in project cubrid-manager by CUBRID.

the class RenameDatabaseAction method run.

public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    final CubridDatabase database = (CubridDatabase) obj[0];
    ISelectionProvider provider = this.getSelectionProvider();
    final TreeViewer viewer = (TreeViewer) provider;
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    final String jobName = serverName + "-" + dbName + "-" + Messages.msgRenameDBRearJobName;
    final RenameDatabaseDialog dialog = new RenameDatabaseDialog(getShell(), new ITaskExecutorInterceptor() {

        public void completeAll() {
            QueryOptions.removePref(database.getDatabaseInfo());
            CommonUITool.openInformationBox(Messages.titleSuccess, Messages.bind(Messages.msgRenameDBComplete, jobName));
            CommonUITool.refreshNavigatorTree(viewer, database.getParent());
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    dialog.setDatabase(database);
    final Shell shell = getShell();
    TaskExecutor taskExcutor = new TaskExecutor() {

        @SuppressWarnings("unchecked")
        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(Messages.getDbSpaceInfoTaskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                if (task instanceof CommonQueryTask) {
                    dbSpaceInfo = ((CommonQueryTask<DbSpaceInfoList>) task).getResultModel();
                }
            }
            return true;
        }
    };
    dbSpaceInfo = new DbSpaceInfoList();
    CommonQueryTask<DbSpaceInfoList> task = new CommonQueryTask<DbSpaceInfoList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), dbSpaceInfo);
    task.setDbName(database.getLabel());
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (taskExcutor.isSuccess()) {
        dialog.setDbSpaceInfoList(dbSpaceInfo);
        dialog.open();
    }
}
Also used : ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) RenameDatabaseDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.RenameDatabaseDialog) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

ITask (com.cubrid.common.core.task.ITask)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)1 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)1 RenameDatabaseDialog (com.cubrid.cubridmanager.ui.cubrid.database.dialog.RenameDatabaseDialog)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Shell (org.eclipse.swt.widgets.Shell)1