Search in sources :

Example 16 with JobChangeAdapter

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

the class PaletteSettingPage method okPressed.

protected void okPressed() {
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayUtils.getDefaultShell());
    IRunnableWithProgress rwp = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
            try {
                prf.saveProject(project);
                ShowStandardAction.getInstance().doRun();
                if (needCodeGen) {
                    Job refreshTemplates = CorePlugin.getDefault().getCodeGeneratorService().refreshTemplates();
                    refreshTemplates.addJobChangeListener(new JobChangeAdapter() {

                        @Override
                        public void done(IJobChangeEvent event) {
                            CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
                        }
                    });
                }
            // ComponentUtilities.updatePalette();
            } catch (Exception ex) {
                ExceptionHandler.process(ex);
            }
        }
    };
    try {
        pmd.run(true, false, rwp);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 17 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project bndtools by bndtools.

the class ResolutionView method executeAnalysis.

void executeAnalysis() {
    if (inputLocked)
        return;
    outOfDate = false;
    synchronized (this) {
        Job oldJob = analysisJob;
        if (oldJob != null && oldJob.getState() != Job.NONE)
            oldJob.cancel();
        if (!loaders.isEmpty()) {
            final AnalyseBundleResolutionJob job = new AnalyseBundleResolutionJob("importExportAnalysis", loaders);
            job.setSystem(true);
            job.addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void aboutToRun(IJobChangeEvent event) {
                    if (display != null && !display.isDisposed()) {
                        Runnable update = new Runnable() {

                            @Override
                            public void run() {
                                setContentDescription("Working...");
                            }
                        };
                        if (display.getThread() == Thread.currentThread())
                            update.run();
                        else
                            display.asyncExec(update);
                    }
                }

                @Override
                public void done(IJobChangeEvent event) {
                    IStatus result = job.getResult();
                    if (result != null && result.isOK()) {
                        if (display != null && !display.isDisposed())
                            display.asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    setInput(loaders, job.getCapabilities(), job.getRequirements());
                                }
                            });
                    }
                }
            });
            analysisJob = job;
            analysisJob.schedule(500);
        } else {
            analysisJob = null;
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) AnalyseBundleResolutionJob(bndtools.tasks.AnalyseBundleResolutionJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) AnalyseBundleResolutionJob(bndtools.tasks.AnalyseBundleResolutionJob) Job(org.eclipse.core.runtime.jobs.Job)

Example 18 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project bndtools by bndtools.

the class IndexerWizardPage method updateInputs.

private void updateInputs() {
    if (updateInputFilesJob != null) {
        updateInputFilesJob.cancel();
    }
    inputPaths = Collections.emptyList();
    setPageComplete(false);
    vwrInputs.setInput(inputPaths);
    lblInputCount.setText(String.format("%d resources found", inputPaths.size()));
    lblInputCount.getParent().layout(new Control[] { lblInputCount });
    final String resourcePattern = this.resourcePattern;
    final Display display = getShell().getDisplay();
    if (baseDir == null)
        return;
    updateInputFilesJob = new SearchFilesJob(baseDir, resourcePattern);
    updateInputFilesJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            final IStatus status = updateInputFilesJob.getSearchResult();
            display.syncExec(new Runnable() {

                @Override
                public void run() {
                    inputPaths = updateInputFilesJob.getPaths();
                    if (inputPaths == null)
                        inputPaths = Collections.emptyList();
                    if (status.isOK())
                        vwrInputs.setInput(updateInputFilesJob.getPaths());
                    else
                        // The error/warning status is displayed in the table instead of the path list
                        vwrInputs.setInput(Collections.singleton(status));
                    lblInputCount.setText(String.format("%d resources found", inputPaths.size()));
                    lblInputCount.getParent().layout(new Control[] { lblInputCount });
                    validate();
                }
            });
        }
    });
    updateInputFilesJob.setSystem(true);
    updateInputFilesJob.schedule(500);
    vwrInputs.setInput(Collections.singleton(new Status(IStatus.INFO, Plugin.PLUGIN_ID, 0, Messages.IndexerWizardPage_checking, null)));
    lblInputCount.setText("...");
    lblInputCount.getParent().layout(new Control[] { lblInputCount });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Display(org.eclipse.swt.widgets.Display)

Example 19 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project bndtools by bndtools.

the class RepositoriesView method createContextMenu.

void createContextMenu() {
    MenuManager mgr = new MenuManager();
    Menu menu = mgr.createContextMenu(viewer.getControl());
    viewer.getControl().setMenu(menu);
    mgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
    getSite().registerContextMenu(mgr, viewer);
    mgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            try {
                manager.removeAll();
                IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                if (!selection.isEmpty()) {
                    final Object firstElement = selection.getFirstElement();
                    if (firstElement instanceof Actionable) {
                        final RepositoryPlugin rp = getRepositoryPlugin(firstElement);
                        //
                        // Use the Actionable interface to fill the menu
                        // Should extend this to allow other menu entries
                        // from the view, but currently there are none
                        //
                        final Actionable act = (Actionable) firstElement;
                        Map<String, Runnable> actions = act.actions();
                        if (actions != null) {
                            for (final Entry<String, Runnable> e : actions.entrySet()) {
                                String label = e.getKey();
                                boolean enabled = true;
                                boolean checked = false;
                                String description = null;
                                Matcher m = LABEL_PATTERN.matcher(label);
                                if (m.matches()) {
                                    if (m.group(1) != null)
                                        enabled = false;
                                    if (m.group(2) != null)
                                        checked = true;
                                    label = m.group(3);
                                    description = m.group(4);
                                }
                                Action a = new Action(label.replace("&", "&&")) {

                                    @Override
                                    public void run() {
                                        Job backgroundJob = new Job("Repository Action '" + getText() + "'") {

                                            @Override
                                            protected IStatus run(IProgressMonitor monitor) {
                                                try {
                                                    e.getValue().run();
                                                    if (rp != null && rp instanceof Refreshable)
                                                        Central.refreshPlugin((Refreshable) rp);
                                                } catch (final Exception e) {
                                                    IStatus status = new Status(IStatus.ERROR, Plugin.PLUGIN_ID, "Error executing: " + getName(), e);
                                                    Plugin.getDefault().getLog().log(status);
                                                }
                                                monitor.done();
                                                return Status.OK_STATUS;
                                            }
                                        };
                                        backgroundJob.addJobChangeListener(new JobChangeAdapter() {

                                            @Override
                                            public void done(IJobChangeEvent event) {
                                                if (event.getResult().isOK()) {
                                                    viewer.getTree().getDisplay().asyncExec(new Runnable() {

                                                        @Override
                                                        public void run() {
                                                            viewer.refresh();
                                                        }
                                                    });
                                                }
                                            }
                                        });
                                        backgroundJob.setUser(true);
                                        backgroundJob.setPriority(Job.SHORT);
                                        backgroundJob.schedule();
                                    }
                                };
                                a.setEnabled(enabled);
                                if (description != null)
                                    a.setDescription(description);
                                a.setChecked(checked);
                                manager.add(a);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    });
}
Also used : Action(org.eclipse.jface.action.Action) IStatus(org.eclipse.core.runtime.IStatus) Matcher(java.util.regex.Matcher) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) Actionable(aQute.bnd.service.Actionable) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryEntry(bndtools.model.repo.RepositoryEntry) Entry(java.util.Map.Entry) GroupMarker(org.eclipse.jface.action.GroupMarker) Menu(org.eclipse.swt.widgets.Menu) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Job(org.eclipse.core.runtime.jobs.Job) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Refreshable(aQute.bnd.service.Refreshable) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Map(java.util.Map)

Example 20 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project translationstudio8 by heartsome.

the class ExportTmxDialog method okPressed.

@Override
protected void okPressed() {
    String encoding = "UTF-8";
    if (hasChangedCodingCbtn.getSelection()) {
        encoding = this.encodingComboViewer.getCombo().getText();
    }
    String exportPath = this.tmxFileText.getText();
    boolean isTopLevelTmx = this.isTopLevelTmxCbtn.getSelection();
    boolean isTagLevelTmx = this.isTagCbtn.getSelection();
    ExportFilterBean filterBean = null;
    if (this.hasfilterCbtn.getSelection()) {
        IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
        filterBean = (ExportFilterBean) sel.getFirstElement();
        if (filterBean.equals(filterList.get(0))) {
            filterBean = null;
        }
    }
    if (this.dbList.size() == 0) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg3"));
        return;
    }
    for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
        ExportDatabaseBean dbBean = iterator.next();
        String dbType = dbBean.getDbBean().getDbType();
        String name = dbBean.getDbBean().getDatabaseName();
        if (dbBean.getHasSelectedLangs().size() < 2) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg4"), dbType, name));
            return;
        }
        if (dbBean.getSrcLang().equals("")) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg5"), dbType, name));
            return;
        }
    }
    if (exportPath == null || exportPath.equals("")) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg6"));
        return;
    }
    if (this.dbList.size() > 1) {
        File f = new File(exportPath);
        if (!f.isDirectory()) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg8"));
            return;
        }
    }
    if (this.dbList.size() == 1) {
        File f = new File(exportPath);
        if (f.isDirectory()) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg9"));
            return;
        }
    }
    if (this.dbList.size() == 1) {
        dbList.get(0).setExportFilePath(exportPath);
        File file = new File(exportPath);
        if (file.exists()) {
            if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg7"), exportPath))) {
                return;
            }
        }
    } else {
        for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
            ExportDatabaseBean db = iterator.next();
            String databaseName = db.getDbBean().getDatabaseName();
            String path = exportPath + System.getProperty("file.separator") + databaseName + db.getDbBean().getDbType() + ".tmx";
            File file = new File(path);
            if (file.exists()) {
                if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTmxDialog.msg7"), path))) {
                    return;
                }
            }
            db.setExportFilePath(path);
        }
    }
    final ExportAbstract tmxExport = new ExportTmxImpl(this.dbList, filterBean, encoding, isTopLevelTmx, isTagLevelTmx);
    Job job = new Job(Messages.getString("dialog.ExportTmxDialog.job")) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            final String result = DatabaseService.executeExport(tmxExport, monitor);
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), result);
                }
            });
            return Status.OK_STATUS;
        }
    };
    // 当程序退出时,检测当前 job 是否正常关闭
    CommonFunction.jobCantCancelTip(job);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void running(IJobChangeEvent event) {
            ProgressIndicatorManager.displayProgressIndicator();
            super.running(event);
        }

        @Override
        public void done(IJobChangeEvent event) {
            ProgressIndicatorManager.hideProgressIndicator();
            super.done(event);
        }
    });
    job.setUser(true);
    job.schedule();
    super.okPressed();
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ExportFilterBean(net.heartsome.cat.database.bean.ExportFilterBean) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) ExportTmxImpl(net.heartsome.cat.document.ExportTmxImpl) ExportDatabaseBean(net.heartsome.cat.database.bean.ExportDatabaseBean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExportAbstract(net.heartsome.cat.document.ExportAbstract) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Aggregations

IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)44 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)44 Job (org.eclipse.core.runtime.jobs.Job)17 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)16 IStatus (org.eclipse.core.runtime.IStatus)11 IFile (org.eclipse.core.resources.IFile)7 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)6 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 QAXmlHandler (net.heartsome.cat.ts.core.qa.QAXmlHandler)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 IOException (java.io.IOException)3 QATUDataBean (net.heartsome.cat.ts.core.qa.QATUDataBean)3 Status (org.eclipse.core.runtime.Status)3 DataSourceJob (org.jkiss.dbeaver.runtime.jobs.DataSourceJob)3 AnalyseBundleResolutionJob (bndtools.tasks.AnalyseBundleResolutionJob)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ExportDatabaseBean (net.heartsome.cat.database.bean.ExportDatabaseBean)2 ExportFilterBean (net.heartsome.cat.database.bean.ExportFilterBean)2