Search in sources :

Example 1 with TaskJob

use of com.cubrid.common.ui.spi.progress.TaskJob 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 2 with TaskJob

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

the class ImportDataFromFileDialog method updateData.

/**
	 *
	 * Update data
	 *
	 * @param parameterList List<PstmtParameter>
	 */
private void updateData(List<PstmtParameter> parameterList) {
    taskList.clear();
    String fileName = fileNameTxt.getText();
    String charset = fileCharsetCombo.getText();
    int threadCount = threadCountSpinner.getSelection();
    int commitedLineOnce = commitLineSpinner.getSelection();
    int totalLine = Integer.parseInt(totalLinesText.getText());
    int threadLine = totalLine / threadCount;
    int line = totalLine % threadCount;
    int startRow = 0;
    int totalProgress = 0;
    boolean isIgnoreError = importErrorControl.isIgoreOrBreak();
    if (isIgnoreError) {
        errorLogDir = PstmtDataTask.makeErrorLogDir();
    } else {
        errorLogDir = null;
    }
    if (importFileHandler == null) {
        importFileHandler = ImportFileHandlerFactory.getHandler(fileName, charset);
    }
    for (int i = 0; i < threadCount; i++) {
        // FIXME move this logic to core module
        int rowCount = threadLine;
        if (i == threadCount - 1) {
            rowCount = threadLine + line;
        }
        int commitCount = rowCount / commitedLineOnce + (rowCount % commitedLineOnce > 0 ? 1 : 0);
        int taskProgress = commitCount * PstmtDataTask.PROGRESS_COMMIT + rowCount * PstmtDataTask.PROGRESS_ROW;
        totalProgress = totalProgress + taskProgress + PstmtDataTask.PROGRESS_ROW;
        PstmtDataTask task = new PstmtDataTask(sqlTxt.getText(), database, fileNameTxt.getText(), parameterList, startRow, rowCount, commitedLineOnce, charset, firstRowAsColumnBtn.getSelection(), isIgnoreError, errorLogDir, importFileHandler);
        task.setTotalProgress(taskProgress);
        taskList.add(task);
        startRow += rowCount;
    }
    getShell().setVisible(false);
    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);
    final IProgressMonitor pmGroup = Job.getJobManager().createProgressGroup();
    pmGroup.beginTask(jobName, totalProgress);
    setStartShowResult(false);
    final CountDownLatch cdl = new CountDownLatch(taskList.size());
    final List<PstmtDataTask> threadTaskList = taskList;
    for (PstmtDataTask task : taskList) {
        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) {
                if (event.getResult() == Status.CANCEL_STATUS) {
                    for (PstmtDataTask task : threadTaskList) {
                        if (!task.isCancel()) {
                            task.cancel();
                        }
                    }
                }
                countDownAndAwait(cdl);
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        pmGroup.done();
                        finish();
                    }
                });
            }
        };
        taskExec.addTask(task);
        TaskJob job = new TaskJob(jobName, taskExec);
        if (jobFamily != null) {
            job.setJobFamily(jobFamily);
        }
        job.setPriority(Job.LONG);
        job.setUser(false);
        job.setProgressGroup(pmGroup, task.getTotalProgress());
        job.schedule();
        try {
            Thread.sleep(30);
        } catch (InterruptedException e) {
        }
        pmGroup.worked(PstmtDataTask.PROGRESS_ROW);
    }
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) IStatus(org.eclipse.core.runtime.IStatus) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) CountDownLatch(java.util.concurrent.CountDownLatch) TaskJob(com.cubrid.common.ui.spi.progress.TaskJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec)

Example 3 with TaskJob

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

the class ConnectionManager method connectDatabaseInJob.

/**
	 * 
	 * Connect database
	 * 
	 * @param dbNode The DatabaseNode
	 */
public static void connectDatabaseInJob(DatabaseNode dbNode) {
    HostNode hostNode = dbNode.getParent();
    if (hostNode.isConnecting() || dbNode.isConnecting() || dbNode.isConnected()) {
        return;
    }
    ServerInfo serverInfo = hostNode.getServerInfo();
    if (serverInfo == null) {
        serverInfo = new ServerInfo();
        serverInfo.setServerName(hostNode.getIp());
        serverInfo.setHostAddress(hostNode.getIp());
        serverInfo.setHostMonPort(Integer.parseInt(hostNode.getPort()));
        serverInfo.setHostJSPort(Integer.parseInt(hostNode.getPort()) + 1);
        serverInfo.setUserName(hostNode.getUserName());
        serverInfo.setUserPassword(hostNode.getPassword());
        serverInfo.setJdbcDriverVersion(ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION);
    }
    TaskJob job = new TaskJob(Messages.bind(Messages.jobConnectDatabase, dbNode.getDbName()));
    if (!hostNode.isConnected()) {
        hostNode.setConnecting(true);
        ConnectHostJobExecutor connectHostJobExecutor = new ConnectHostJobExecutor(hostNode, serverInfo, false);
        job.addTaskJobExecutor(connectHostJobExecutor);
    }
    dbNode.setConnecting(true);
    ConnectDatabaseNodeJobExecutor dbJobExecutor = new ConnectDatabaseNodeJobExecutor(dbNode, serverInfo);
    job.addTaskJobExecutor(dbJobExecutor);
    JobFamily jobFamily = new JobFamily();
    jobFamily.setServerName(serverInfo.getServerName());
    jobFamily.setDbName(dbNode.getDbName());
    job.setJobFamily(jobFamily);
    job.setPriority(Job.SHORT);
    job.setUser(false);
    job.schedule();
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) HostNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.HostNode) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) TaskJob(com.cubrid.common.ui.spi.progress.TaskJob)

Example 4 with TaskJob

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

the class ConnectionManager method connectHostInJob.

/**
	 * 
	 * Connect Host
	 * 
	 * @param hostNode The HostNode
	 * @param isConnectChild The boolean
	 * @param isPing The boolean
	 */
public static void connectHostInJob(HostNode hostNode, boolean isConnectChild, boolean isPing) {
    if (hostNode.isConnected() || hostNode.isConnecting()) {
        return;
    }
    ServerInfo serverInfo = hostNode.getServerInfo();
    if (serverInfo == null) {
        serverInfo = new ServerInfo();
        serverInfo.setServerName(hostNode.getIp());
        serverInfo.setHostAddress(hostNode.getIp());
        serverInfo.setHostMonPort(Integer.parseInt(hostNode.getPort()));
        serverInfo.setHostJSPort(Integer.parseInt(hostNode.getPort()) + 1);
        serverInfo.setUserName(hostNode.getUserName());
        serverInfo.setUserPassword(hostNode.getPassword());
        serverInfo.setJdbcDriverVersion(ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION);
    }
    TaskJob job = new TaskJob(Messages.bind(Messages.jobConnectHost, serverInfo.getHostAddress()));
    hostNode.setConnecting(true);
    ConnectHostJobExecutor executor = new ConnectHostJobExecutor(hostNode, serverInfo, isPing);
    job.addTaskJobExecutor(executor);
    if (isConnectChild) {
        List<DatabaseNode> dbNodeList = hostNode.getDbNodeList();
        for (DatabaseNode dbNode : dbNodeList) {
            if (dbNode.isConnecting() || dbNode.isConnected()) {
                continue;
            }
            dbNode.setConnecting(true);
            ConnectDatabaseNodeJobExecutor dbJobExecutor = new ConnectDatabaseNodeJobExecutor(dbNode, serverInfo);
            job.addTaskJobExecutor(dbJobExecutor);
        }
    }
    JobFamily jobFamily = new JobFamily();
    jobFamily.setServerName(serverInfo.getServerName());
    jobFamily.setDbName(JobFamily.ALL_DB);
    job.setJobFamily(jobFamily);
    job.setPriority(Job.SHORT);
    job.setUser(false);
    job.schedule();
}
Also used : DatabaseNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) TaskJob(com.cubrid.common.ui.spi.progress.TaskJob)

Aggregations

TaskJob (com.cubrid.common.ui.spi.progress.TaskJob)4 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)3 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)2 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)2 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 DatabaseNode (com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode)1 HostNode (com.cubrid.cubridmanager.ui.mondashboard.editor.model.HostNode)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1