Search in sources :

Example 6 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project tdi-studio-se by Talend.

the class InsertionExtensionAction method run.

public void run() {
    if (extension == null) {
        return;
    }
    try {
        final InsertionExtensionJob job = new InsertionExtensionJob(extension);
        job.addJobChangeListener(new JobChangeAdapter() {

            @Override
            public void done(final IJobChangeEvent event) {
                Display.getDefault().asyncExec(new Runnable() {

                    public void run() {
                        updateUI(job, event);
                    }
                });
            }
        });
        ExchangeUtils.scheduleUserJob(job);
    } catch (Throwable e) {
        ExceptionHandler.process(e);
    }
}
Also used : InsertionExtensionJob(org.talend.designer.components.exchange.jobs.InsertionExtensionJob) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 7 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project tdi-studio-se by Talend.

the class RefreshComponenentsAction method run.

public void run(String[] refreshTypes, final String pageToDispaly) {
    List typesToRefresh = null;
    if (refreshTypes == null || refreshTypes.length == 0) {
        typesToRefresh = new ArrayList();
        typesToRefresh.add(REFRESH_ALL);
    } else {
        typesToRefresh = Arrays.asList(refreshTypes);
    }
    if (typesToRefresh.contains(REFRESH_ALL) || typesToRefresh.contains(REFRESH_AVAILABLES)) {
        try {
            final RefreshJob job = new RefreshJob();
            job.addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void done(final IJobChangeEvent event) {
                    Display.getDefault().syncExec(new Runnable() {

                        @Override
                        public void run() {
                            updateUI(job, event);
                            String toDisplay = pageToDispaly == null ? ContentConstants.UL_LIST_AVAILABLE_EXTENSIONS : pageToDispaly;
                            ExchangeManager.getInstance().generateXHTMLPage(toDisplay, new String[] { ContentConstants.INSERT_EXTENSION_DATA });
                        }
                    });
                }
            });
            ExchangeUtils.scheduleUserJob(job);
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
    // Show Installed Extensions
    if (typesToRefresh.contains(REFRESH_ALL) || typesToRefresh.contains(REFRESH_INSTALLED)) {
        try {
            final ShowInstalledExtensionsJob showInstalledJob = new ShowInstalledExtensionsJob();
            showInstalledJob.addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void done(final IJobChangeEvent event) {
                    Display.getDefault().syncExec(new Runnable() {

                        @Override
                        public void run() {
                            updateInstalledUI(showInstalledJob, event);
                            ExchangeManager.getInstance().generateXHTMLPage(pageToDispaly, new String[] { ContentConstants.DOWNLOADEXTENSION_DATA });
                        }
                    });
                }
            });
            ExchangeUtils.scheduleUserJob(showInstalledJob);
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
    // Show Contributed Extensions
    if (typesToRefresh.contains(REFRESH_ALL) || typesToRefresh.contains(REFRESH_MY_EXTENSIONS)) {
        try {
            final ShowContributedExtensionsJob showContributedJob = new ShowContributedExtensionsJob();
            showContributedJob.addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void done(final IJobChangeEvent event) {
                    Display.getDefault().syncExec(new Runnable() {

                        @Override
                        public void run() {
                            updateContributedUI(showContributedJob, event);
                            ExchangeManager.getInstance().generateXHTMLPage(pageToDispaly, new String[] { ContentConstants.LIST_MY_EXTENSION });
                        }
                    });
                }
            });
            ExchangeUtils.scheduleUserJob(showContributedJob);
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
    //
    getVersionRevisionsAndCategorys();
// refreshHTML();
}
Also used : RefreshJob(org.talend.designer.components.exchange.jobs.RefreshJob) ShowInstalledExtensionsJob(org.talend.designer.components.exchange.jobs.ShowInstalledExtensionsJob) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ShowContributedExtensionsJob(org.talend.designer.components.exchange.jobs.ShowContributedExtensionsJob) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 8 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent 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 9 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project cubrid-manager by CUBRID.

the class BackupDatabaseDialog method backupDb.

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

        private String backupVolInfo;

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

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

                    public void run() {
                        setReturnCode(buttonId);
                        close();
                    }
                });
                return Status.CANCEL_STATUS;
            }
            for (ITask task : taskList) {
                if (!(task instanceof GetBackupVolInfoTask) || database.getRunningType() != DbRunningType.CS) {
                    task.execute();
                    final String msg = task.getErrorMsg();
                    if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
                        display.syncExec(new Runnable() {

                            public void run() {
                                getShell().setVisible(true);
                            }
                        });
                        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.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.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 GetBackupVolInfoTask && database.getRunningType() == DbRunningType.STANDALONE) {
                    GetBackupVolInfoTask getBackupVolInfoTask = (GetBackupVolInfoTask) task;
                    backupVolInfo = getBackupVolInfoTask.getDbBackupVolInfo();
                }
                if (!isCanFinished) {
                    return Status.CANCEL_STATUS;
                }
                if (monitor.isCanceled()) {
                    cancel();
                    Display.getDefault().syncExec(new Runnable() {

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

        public void done(IJobChangeEvent event) {
            if (event.getResult() == Status.OK_STATUS) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        if (database.getRunningType() == DbRunningType.CS) {
                            Display.getDefault().syncExec(new Runnable() {

                                public void run() {
                                    CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgBackupSuccess);
                                }
                            });
                        } else {
                            if (backupVolInfo != null && backupVolInfo.length() > 0) {
                                Display.getDefault().syncExec(new Runnable() {

                                    public void run() {
                                        BackupDbVolumeInfoDialog backupDbResultInfoDialog = new BackupDbVolumeInfoDialog(getShell());
                                        backupDbResultInfoDialog.setResultInfoStr(backupVolInfo);
                                        backupDbResultInfoDialog.open();
                                    }
                                });
                            }
                        }
                        close();
                    }
                });
            }
        }
    };
    String backupDir = backupDirText.getText();
    CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
    checkDirTask.setDirectory(new String[] { backupDir });
    CheckFileTask checkFileTask = new CheckFileTask(database.getServer().getServerInfo());
    String fileName = backupDirText.getText() + database.getServer().getServerInfo().getPathSeparator() + volumeNameText.getText();
    checkFileTask.setFile(new String[] { fileName });
    String databaseName = databaseNameText.getText();
    String level = backupLevelCombo.getText().replaceAll("Level", "");
    String volName = volumeNameText.getText();
    boolean isRemoveLog = archiveLogButton.getSelection();
    boolean isCheckDbCons = consistentButton.getSelection();
    boolean isZip = useCompressButton.getSelection();
    boolean isSafeReplication = safeBackupButton.getSelection();
    int threadNum = spnThreadNum.getSelection();
    BackupDbTask backupDbTask = new BackupDbTask(database.getServer().getServerInfo());
    backupDbTask.setDbName(databaseName);
    backupDbTask.setLevel(level);
    backupDbTask.setVolumeName(volName);
    backupDbTask.setBackupDir(backupDir);
    backupDbTask.setRemoveLog(isRemoveLog);
    backupDbTask.setCheckDatabaseConsist(isCheckDbCons);
    backupDbTask.setThreadCount(String.valueOf(threadNum));
    backupDbTask.setZiped(isZip);
    backupDbTask.setSafeReplication(isSafeReplication);
    GetBackupVolInfoTask getBackupVolInfoTask = new GetBackupVolInfoTask(database.getServer().getServerInfo());
    getBackupVolInfoTask.setDbName(databaseName);
    taskExcutor.addTask(checkDirTask);
    taskExcutor.addTask(checkFileTask);
    taskExcutor.addTask(backupDbTask);
    taskExcutor.addTask(getBackupVolInfoTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgBackupDBRearJobName + " - " + dbName + "@" + serverName;
    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) GetBackupVolInfoTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetBackupVolInfoTask) BackupDbTask(com.cubrid.cubridmanager.core.cubrid.database.task.BackupDbTask) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) Display(org.eclipse.swt.widgets.Display)

Example 10 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by serge-rider.

the class NavigatorHandlerRefresh method refreshNavigator.

public static void refreshNavigator(final Collection<? extends DBNNode> refreshObjects) {
    Job refreshJob = new AbstractJob("Refresh navigator object(s)") {

        public Throwable error;

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void done(IJobChangeEvent event) {
                    if (error != null) {
                        UIUtils.showErrorDialog(null, "Refresh", "Error refreshing node", error);
                    }
                }
            });
            Set<DBNNode> refreshedSet = new HashSet<>();
            for (DBNNode node : refreshObjects) {
                if (node.isDisposed() || node.isLocked()) {
                    // Skip locked nodes
                    continue;
                }
                // Check this node was already refreshed
                if (!refreshedSet.isEmpty()) {
                    boolean skip = false;
                    for (DBNNode refreshed : refreshedSet) {
                        if (node == refreshed || node.isChildOf(refreshed)) {
                            skip = true;
                            break;
                        }
                    }
                    if (skip) {
                        continue;
                    }
                }
                setName("Refresh '" + node.getNodeName() + "'...");
                try {
                    DBNNode refreshed = node.refreshNode(monitor, DBNEvent.FORCE_REFRESH);
                    if (refreshed != null) {
                        refreshedSet.add(refreshed);
                    }
                } catch (Throwable ex) {
                    error = ex;
                }
            }
            return Status.OK_STATUS;
        }
    };
    refreshJob.setUser(true);
    refreshJob.schedule();
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob)

Aggregations

IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)166 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)157 Job (org.eclipse.core.runtime.jobs.Job)44 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)43 IStatus (org.eclipse.core.runtime.IStatus)36 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)30 ArrayList (java.util.ArrayList)13 IFile (org.eclipse.core.resources.IFile)13 CoreException (org.eclipse.core.runtime.CoreException)12 DataSourceJob (org.jkiss.dbeaver.runtime.jobs.DataSourceJob)12 Status (org.eclipse.core.runtime.Status)11 IOException (java.io.IOException)10 DBException (org.jkiss.dbeaver.DBException)10 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)10 File (java.io.File)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)8 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 Composite (org.eclipse.swt.widgets.Composite)7 IProject (org.eclipse.core.resources.IProject)6