Search in sources :

Example 1 with TruncateTableTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.TruncateTableTask in project cubrid-manager by CUBRID.

the class TruncateTableAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    StringBuilder sb = new StringBuilder();
    int len = obj.length;
    final List<String> tableList = new ArrayList<String>();
    CubridDatabase database = null;
    for (int i = 0; i < len; i++) {
        ISchemaNode table = (ISchemaNode) obj[i];
        database = table.getDatabase();
        final String tableName = table.getName();
        tableList.add(tableName);
        if (i < 100) {
            if (sb.length() > 0) {
                sb.append(", ");
            }
            sb.append(tableName);
        }
    }
    if (len > 100) {
        sb.append("...");
    }
    String message = Messages.bind(Messages.confirmTableDeleteWarn, sb.toString());
    if (!CommonUITool.openConfirmBox(message)) {
        return;
    }
    final TruncateTableTask task = new TruncateTableTask(database.getDatabaseInfo());
    TaskJobExecutor taskExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            CommonUITool.openInformationBox(Messages.msg_information, Messages.resultTableDeleteInformantion);
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    String[] tableNames = new String[tableList.size()];
    tableNames = tableList.toArray(tableNames);
    task.setTableName(tableNames);
    taskExec.addTask(task);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgTruncateTableJobName + " - " + tableList.toString() + "@" + dbName + "@" + serverName;
    taskExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ArrayList(java.util.ArrayList) TruncateTableTask(com.cubrid.cubridmanager.core.cubrid.table.task.TruncateTableTask) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) 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 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)1 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)1 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)1 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)1 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)1 TruncateTableTask (com.cubrid.cubridmanager.core.cubrid.table.task.TruncateTableTask)1 ArrayList (java.util.ArrayList)1 IStatus (org.eclipse.core.runtime.IStatus)1