Search in sources :

Example 1 with TaskJobExecutor

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

the class PstmtSQLDialog method updateData.

/**
	 * Update the data
	 *
	 * @param parameterList List<PstmtParameter>
	 */
private void updateData(List<List<PstmtParameter>> jobList) {
    beginTimestamp = System.currentTimeMillis();
    String jobName = Messages.executeSqlJobName;
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getServerInfo().getServerName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    TaskJobExecutor taskExec = new CommonTaskJobExec(this);
    for (int i = 0; i < jobList.size(); i++) {
        List<PstmtParameter> parameterList = jobList.get(i);
        PstmtDataTask task = new PstmtDataTask(sqlTxt.getText(), database, parameterList, null, i + 1);
        taskExec.addTask(task);
    }
    taskExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) Point(org.eclipse.swt.graphics.Point)

Example 2 with TaskJobExecutor

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

the class ObjectInfoComposite method init.

public void init() {
    /*Tool bar composite*/
    Composite toolBarComposite = new Composite(this, SWT.NONE);
    RowLayout rowLayout = new RowLayout();
    toolBarComposite.setLayout(rowLayout);
    toolBarComposite.setLayoutData(CommonUITool.createGridData(-1, -1, -1, 25));
    dataTabButton = new Button(toolBarComposite, SWT.None);
    dataTabButton.setText(Messages.tabTitleData);
    dataTabButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            if (objInfoFolder == null) {
                return;
            }
            objInfoFolder.setSelection(0);
        }
    });
    ddlTabButton = new Button(toolBarComposite, SWT.None);
    ddlTabButton.setText(Messages.tabTitleDDL);
    ddlTabButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            if (objInfoFolder == null) {
                return;
            }
            objInfoFolder.setSelection(1);
        }
    });
    columnTabButton = new Button(toolBarComposite, SWT.None);
    columnTabButton.setText(Messages.tabTitleColumn);
    columnTabButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            if (objInfoFolder == null) {
                return;
            }
            objInfoFolder.setSelection(2);
        }
    });
    indexTabButton = new Button(toolBarComposite, SWT.None);
    indexTabButton.setText(Messages.tabTitleIndex);
    indexTabButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            if (objInfoFolder == null) {
                return;
            }
            objInfoFolder.setSelection(3);
        }
    });
    new Label(toolBarComposite, SWT.None).setText("  ");
    /*Select * button*/
    selectButton = new Button(toolBarComposite, SWT.None);
    selectButton.setText(Messages.txtSelect);
    selectButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            processSelectAction();
        }
    });
    /*Select column button*/
    selectColumnButton = new Button(toolBarComposite, SWT.None);
    selectColumnButton.setText(Messages.txtSelectColumn);
    selectColumnButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            processSelectColumnAction();
        }
    });
    /*Insert Button*/
    insertButton = new Button(toolBarComposite, SWT.None);
    insertButton.setText(Messages.txtInsert);
    insertButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            processInsertAction();
        }
    });
    /*Update button*/
    updateButton = new Button(toolBarComposite, SWT.None);
    updateButton.setText(Messages.txtUpdate);
    updateButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            processUpdateAction();
        }
    });
    /*Delete button*/
    deleteButton = new Button(toolBarComposite, SWT.None);
    deleteButton.setText(Messages.txtDelete);
    deleteButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            processDeleteAction();
        }
    });
    /*Database object information*/
    objInfoFolder = new CTabFolder(this, SWT.BOTTOM);
    objInfoFolder.setSimple(false);
    objInfoFolder.setUnselectedImageVisible(true);
    objInfoFolder.setUnselectedCloseVisible(true);
    objInfoFolder.setSelectionBackground(CombinedQueryEditorComposite.BACK_COLOR);
    objInfoFolder.setSelectionForeground(ResourceManager.getColor(SWT.COLOR_BLACK));
    objInfoFolder.setLayout(new GridLayout(1, true));
    objInfoFolder.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, -1, -1, -1, -1));
    /*Demo data tab item*/
    initDataTabItem();
    /*DDL tab item*/
    initDDLTabItem();
    /*Column tab item*/
    initColumnTabItem();
    /*If is table, create index tab item*/
    if (isTable) {
        initIndexTabItem();
    }
    /*Initial the data*/
    TaskJobExecutor taskExec = new CommonTaskJobExec() {

        public IStatus exec(IProgressMonitor monitor) {
            IStatus status = super.exec(monitor);
            if (Status.CANCEL_STATUS == status) {
                return status;
            }
            return Status.OK_STATUS;
        }

        public void done(IJobChangeEvent event) {
            getInfoDataTask = null;
        }
    };
    GetInfoDataTask getInfoDataTask = new GetInfoDataTask(Messages.getInfoJobName, this, schemaNode, isTable);
    taskExec.addTask(getInfoDataTask);
    /*Get data job*/
    TaskJob job = new TaskJob(Messages.bind(Messages.getInfoJobName, schemaNode.getName()), taskExec);
    job.setPriority(Job.LONG);
    job.setUser(false);
    job.schedule();
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) IStatus(org.eclipse.core.runtime.IStatus) CTabFolder(org.eclipse.swt.custom.CTabFolder) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) TaskJob(com.cubrid.common.ui.spi.progress.TaskJob) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Button(org.eclipse.swt.widgets.Button) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with TaskJobExecutor

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

the class DatabaseDashboardEditor method showLogView.

/**
	 * show sql log view at broker table
	 *
	 * @param type sql type
	 */
public void showLogView(String type) {
    try {
        int i = brokerInfoTable.getSelectionIndex();
        if (i < 0) {
            return;
        }
        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (window == null) {
            return;
        }
        String brokerName = brokerInfoTable.getItem(i).getText(0);
        String serverId = brokerInfoTable.getItem(i).getText(1);
        //get all log infor
        BrokerLogInfos brokerLogInfos = new BrokerLogInfos();
        final CommonQueryTask<BrokerLogInfos> task = new CommonQueryTask<BrokerLogInfos>(database.getDatabaseInfo().getServerInfo(), CommonSendMsg.getGetBrokerLogFileInfoMSGItems(), brokerLogInfos);
        task.setBroker(brokerName);
        task.execute();
        brokerLogInfos = task.getResultModel();
        String logFileName = brokerName + "_" + serverId + "." + type + ".log";
        sqlLogViewPartName = logFileName + "@" + database.getServer().getLabel() + ":" + database.getServer().getMonPort();
        List<LogInfo> logInfoList = brokerLogInfos == null ? null : brokerLogInfos.getBrokerLogInfoList().getLogFileInfoList();
        task.finish();
        //get the current log
        LogInfo logInfo = null;
        if (logInfoList != null && !logInfoList.isEmpty()) {
            for (LogInfo logInfoInlist : logInfoList) {
                if (logFileName.equals(logInfoInlist.getName())) {
                    logInfo = logInfoInlist;
                    break;
                }
            }
        }
        if (logInfo == null) {
            String msg = Messages.bind(com.cubrid.cubridmanager.ui.logs.Messages.errLogFileNoExist, logFileName);
            LOGGER.error(msg);
            //CommonUITool.openErrorBox(msg);
            return;
        }
        final String filePath = logInfo.getPath();
        TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {

            public IStatus exec(IProgressMonitor monitor) {
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                for (ITask task : taskList) {
                    task.execute();
                    final String msg = task.getErrorMsg();
                    if (monitor.isCanceled()) {
                        return Status.CANCEL_STATUS;
                    }
                    if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                        return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                    }
                    if (task instanceof CheckFileTask) {
                        CheckFileTask checkFileTask = (CheckFileTask) task;
                        final String[] files = checkFileTask.getExistFiles();
                        if (files == null || files.length == 0) {
                            return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, Messages.bind(com.cubrid.cubridmanager.ui.logs.Messages.errLogFileNoExist, filePath));
                        }
                    } else if (task instanceof GetLogListTask) {
                        GetLogListTask getLogListTask = (GetLogListTask) task;
                        final LogContentInfo logContentInfo = (LogContentInfo) getLogListTask.getLogContent();
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                try {
                                    ICubridNode logInfoNode = new DefaultCubridNode("", "", "");
                                    IEditorPart editor = window.getActivePage().openEditor(logInfoNode, LogEditorPart.ID);
                                    ((LogEditorPart) editor).setTableInfo(logContentInfo, true);
                                    ((LogEditorPart) editor).setShowLogPartName(sqlLogViewPartName);
                                } catch (PartInitException e) {
                                    LOGGER.error(e.getMessage(), e);
                                }
                            }
                        });
                    }
                    if (monitor.isCanceled()) {
                        return Status.CANCEL_STATUS;
                    }
                    task.finish();
                }
                return Status.OK_STATUS;
            }
        };
        CheckFileTask checkFileTask = new CheckFileTask(cubridNode.getServer().getServerInfo());
        checkFileTask.setFile(new String[] { filePath });
        taskJobExecutor.addTask(checkFileTask);
        GetLogListTask getLogListTask = new GetLogListTask(cubridNode.getServer().getServerInfo());
        getLogListTask.setPath(filePath);
        getLogListTask.setStart("1");
        getLogListTask.setEnd("100");
        taskJobExecutor.addTask(getLogListTask);
        String jobName = com.cubrid.cubridmanager.ui.logs.Messages.viewLogJobName + " - " + cubridNode.getName() + "@" + cubridNode.getServer().getName();
        taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
    } catch (Exception e) {
        LOGGER.error(Messages.exportDashboardOpenSQLLogErrMsg, e);
    //			CommonUITool.openErrorBox(Messages.exportDashboardOpenSQLLogErrMsg);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITask(com.cubrid.common.core.task.ITask) DefaultCubridNode(com.cubrid.common.ui.spi.model.DefaultCubridNode) LogInfo(com.cubrid.cubridmanager.core.logs.model.LogInfo) BrokerLogInfos(com.cubrid.cubridmanager.core.logs.model.BrokerLogInfos) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) LogContentInfo(com.cubrid.cubridmanager.core.logs.model.LogContentInfo) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) GetLogListTask(com.cubrid.cubridmanager.core.logs.task.GetLogListTask) PartInitException(org.eclipse.ui.PartInitException) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) LogEditorPart(com.cubrid.cubridmanager.ui.logs.editor.LogEditorPart)

Example 4 with TaskJobExecutor

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

the class AddVolumeDialog method performTask.

/**
	 * perform the task
	 * 
	 * @param addVolumeDbInfo AddVolumeDbInfo
	 */
private void performTask(AddVolumeDbInfo addVolumeDbInfo) {
    // Checks the path
    String sPathText = pathText.getText().trim();
    ServerInfo serverInfo = selection.getServer().getServerInfo();
    CheckDirTask checkDirTask = new CheckDirTask(serverInfo);
    checkDirTask.setDirectory(new String[] { sPathText });
    CubridDatabase database = selection.getDatabase();
    AddVolumeDbTask addVolumeTask = new AddVolumeDbTask(database.getServer().getServerInfo());
    addVolumeTask.setDbname(database.getName());
    addVolumeTask.setVolname(addVolumeDbInfo.getVolname());
    addVolumeTask.setPurpose(addVolumeDbInfo.getPurpose());
    addVolumeTask.setPath(addVolumeDbInfo.getPath());
    addVolumeTask.setNumberofpages(addVolumeDbInfo.getNumberofpage());
    addVolumeTask.setSizeNeedMb(addVolumeDbInfo.getSize_need_mb());
    // Gets the database space info
    DbSpaceInfoList dbSpaceInfo = new DbSpaceInfoList();
    final CommonQueryTask<DbSpaceInfoList> dbSpaceInfoTask = new CommonQueryTask<DbSpaceInfoList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), dbSpaceInfo);
    dbSpaceInfoTask.setDbName(database.getLabel());
    JobFamily jobFamily = new JobFamily();
    String serverName = selection.getServer().getName();
    String dbName = selection.getDatabase().getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    jobName = Messages.msgAddVolRearJobName + " - " + dbName + "@" + serverName;
    TaskJobExecutor taskExec = new CommonTaskJobExec(this);
    taskExec.addTask(checkDirTask);
    taskExec.addTask(addVolumeTask);
    taskExec.addTask(dbSpaceInfoTask);
    taskExec.schedule(dbName, jobFamily, true, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) AddVolumeDbTask(com.cubrid.cubridmanager.core.cubrid.dbspace.task.AddVolumeDbTask) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)

Example 5 with TaskJobExecutor

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

the class VolumeFolderInfoEditor method loadData.

/**
	 * load the editor data
	 *
	 * @return boolean
	 */
public boolean loadData() {
    TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {

        @SuppressWarnings("unchecked")
        @Override
        public IStatus exec(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            for (ITask t : taskList) {
                t.execute();
                final String msg = t.getErrorMsg();
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                    return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                } else {
                    final DbSpaceInfoList model = ((CommonQueryTask<? extends DbSpaceInfoList>) t).getResultModel();
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            database.getDatabaseInfo().setDbSpaceInfoList(model);
                            if (scrolledComp == null || scrolledComp.isDisposed()) {
                                return;
                            }
                            initialize();
                            paintComp();
                            scrolledComp.setContent(parentComp);
                            scrolledComp.setExpandHorizontal(true);
                            scrolledComp.setExpandVertical(true);
                        }
                    });
                }
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
            }
            return Status.OK_STATUS;
        }
    };
    CommonQueryTask<? extends DbSpaceInfoList> task = DbSpaceInfoList.useOld(database.getServer().getServerInfo().getEnvInfo()) ? new CommonQueryTask<DbSpaceInfoListOld>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoListOld()) : new CommonQueryTask<DbSpaceInfoListNew>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoListNew());
    task.setDbName(database.getName());
    taskJobExecutor.addTask(task);
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    String jobName = Messages.viewVolumeInfoJobName + " - " + volumeFolderName + "@" + dbName + "@" + serverName;
    taskJobExecutor.schedule(jobName, null, false, Job.LONG);
    return true;
}
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) DbSpaceInfoListOld(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoListOld) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DbSpaceInfoListNew(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoListNew) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask)

Aggregations

TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)41 IStatus (org.eclipse.core.runtime.IStatus)29 ITask (com.cubrid.common.core.task.ITask)28 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)24 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)24 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)18 Status (org.eclipse.core.runtime.Status)15 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)12 ArrayList (java.util.ArrayList)12 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)11 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)10 List (java.util.List)8 CheckDirTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)6 CheckFileTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask)6 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)6 BrokerInfoList (com.cubrid.cubridmanager.core.broker.model.BrokerInfoList)4 IEditorPart (org.eclipse.ui.IEditorPart)4 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)4 PartInitException (org.eclipse.ui.PartInitException)4 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)3