Search in sources :

Example 26 with JobChangeAdapter

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

the class AutomaticUpdate method checkForUpdates.

public void checkForUpdates() throws OperationCanceledException {
    // 检查 propfile
    String profileId = getProvisioningUI().getProfileId();
    IProvisioningAgent agent = getProvisioningUI().getSession().getProvisioningAgent();
    IProfile profile = null;
    if (agent != null) {
        IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
        if (registry != null) {
            profile = registry.getProfile(profileId);
        }
    }
    if (profile == null) {
        // Inform the user nicely
        P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
        return;
    }
    // 开始检查前先确定是否有repository
    RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();
    if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
        P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
        return;
    }
    final IStatus[] checkStatus = new IStatus[1];
    Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
    final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI()) {

        public IStatus runModal(IProgressMonitor monitor) {
            SubMonitor sub = SubMonitor.convert(monitor, P2UpdateUtil.CHECK_UPDATE_TASK_NAME, 1000);
            // load repository
            IStatus status = super.runModal(sub.newChild(500));
            if (status.getSeverity() == IStatus.CANCEL) {
                return status;
            }
            if (status.getSeverity() != Status.OK) {
                // load repository error
                checkStatus[0] = status;
            }
            operation = getProvisioningUI().getUpdateOperation(null, null);
            // check for updates
            IStatus resolveStatus = operation.resolveModal(sub.newChild(500));
            if (resolveStatus.getSeverity() == IStatus.CANCEL) {
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    loadJob.setName(P2UpdateUtil.ATUO_CHECK_UPDATE_JOB_NAME);
    loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));
    loadJob.addJobChangeListener(new JobChangeAdapter() {

        public void done(IJobChangeEvent event) {
            if (PlatformUI.isWorkbenchRunning())
                if (event.getResult().isOK()) {
                    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                        public void run() {
                            if (checkStatus[0] != null) {
                                // 提示连接异常
                                P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
                                return;
                            }
                            doUpdate();
                        }
                    });
                }
        }
    });
    loadJob.setUser(true);
    loadJob.schedule();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) SubMonitor(org.eclipse.core.runtime.SubMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProfileRegistry(org.eclipse.equinox.p2.engine.IProfileRegistry) IProfile(org.eclipse.equinox.p2.engine.IProfile) LoadMetadataRepositoryJob(org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob) RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker)

Example 27 with JobChangeAdapter

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

the class TMX2TXTConverterDialog method convert.

/**
	 * 开始转换
	 */
private void convert() {
    final String tmxLocation = tmxTxt.getText();
    if (tmxLocation.equals("")) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg1"));
        return;
    }
    final String txtLocation = txtTxt.getText();
    if (txtLocation.equals("")) {
        //$NON-NLS-1$
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg2"));
        return;
    }
    File txtFile = new File(txtLocation);
    if (txtFile.exists()) {
        boolean response = MessageDialog.openConfirm(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle2"), MessageFormat.format(Messages.getString("dialog.TMX2TXTConverterDialog.msg3"), txtLocation));
        if (!response) {
            return;
        }
    } else if (!txtFile.getParentFile().exists()) {
        txtFile.getParentFile().mkdirs();
    }
    Job job = new Job(Messages.getString("dialog.TMX2TXTConverterDialog.job")) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            monitor.beginTask(Messages.getString("dialog.TMX2TXTConverterDialog.task"), 10);
            // 先解析文件,花费一格
            int openResult = openFile(tmxLocation, monitor);
            if (openResult == 0) {
                return Status.CANCEL_STATUS;
            } else if (openResult == -2) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg4"));
                    }
                });
                return Status.CANCEL_STATUS;
            } else if (openResult == -1) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg5"));
                    }
                });
                return Status.CANCEL_STATUS;
            }
            if (!validVersion(tmxLocation)) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg6"));
                    }
                });
                return Status.CANCEL_STATUS;
            }
            if ((tuNodesCount = getTUCount(tmxLocation)) <= 0) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TMX2TXTConverterDialog.msgTitle"), Messages.getString("dialog.TMX2TXTConverterDialog.msg7"));
                    }
                });
                return Status.CANCEL_STATUS;
            }
            try {
                output = new FileOutputStream(txtLocation);
                byte[] bom = new byte[3];
                bom[0] = (byte) 0xEF;
                bom[1] = (byte) 0xBB;
                bom[2] = (byte) 0xBF;
                output.write(bom);
                writeHeader();
                monitor.worked(1);
                IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 8, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
                return processTU(tmxLocation, txtLocation, subMonitor);
            } catch (Exception e) {
                e.printStackTrace();
                LOGGER.error("", e);
            }
            monitor.done();
            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();
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) NavException(com.ximpleware.NavException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileOutputStream(java.io.FileOutputStream) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Example 28 with JobChangeAdapter

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

the class ResultSetViewer method runDataPump.

private synchronized boolean runDataPump(@NotNull final DBSDataContainer dataContainer, @Nullable final DBDDataFilter dataFilter, final int offset, final int maxRows, final int focusRow, final boolean saveHistory, final boolean scroll, @Nullable final Runnable finalizer) {
    if (dataPumpJob != null) {
        UIUtils.showMessageBox(viewerPanel.getShell(), "Data read", "Data read is in progress - can't run another", SWT.ICON_WARNING);
        return false;
    }
    // Read data
    final DBDDataFilter useDataFilter = dataFilter != null ? dataFilter : (dataContainer == getDataContainer() ? model.getDataFilter() : null);
    Composite progressControl = viewerPanel;
    if (activePresentation.getControl() instanceof Composite) {
        progressControl = (Composite) activePresentation.getControl();
    }
    final Object presentationState = savePresentationState();
    dataPumpJob = new ResultSetJobDataRead(dataContainer, useDataFilter, this, getExecutionContext(), progressControl);
    dataPumpJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void aboutToRun(IJobChangeEvent event) {
            model.setUpdateInProgress(true);
            model.setStatistics(null);
            DBeaverUI.syncExec(new Runnable() {

                @Override
                public void run() {
                    filtersPanel.enableFilters(false);
                }
            });
        }

        @Override
        public void done(IJobChangeEvent event) {
            ResultSetJobDataRead job = (ResultSetJobDataRead) event.getJob();
            final Throwable error = job.getError();
            if (job.getStatistics() != null) {
                model.setStatistics(job.getStatistics());
            }
            final Control control = getControl();
            if (control.isDisposed()) {
                return;
            }
            DBeaverUI.syncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        final Control control = getControl();
                        if (control.isDisposed()) {
                            return;
                        }
                        final Shell shell = control.getShell();
                        final boolean metadataChanged = model.isMetadataChanged();
                        if (error != null) {
                            setStatus(error.getMessage(), DBPMessageType.ERROR);
                            UIUtils.showErrorDialog(shell, "Error executing query", "Query execution failed", error);
                        } else {
                            if (!metadataChanged && focusRow >= 0 && focusRow < model.getRowCount() && model.getVisibleAttributeCount() > 0) {
                                // Seems to be refresh
                                // Restore original position
                                curRow = model.getRow(focusRow);
                                restorePresentationState(presentationState);
                            }
                        }
                        activePresentation.updateValueView();
                        updatePanelsContent(false);
                        if (!scroll) {
                            // Add new history item
                            if (saveHistory && error == null) {
                                setNewState(dataContainer, dataFilter);
                            }
                            if (dataFilter != null) {
                                model.updateDataFilter(dataFilter);
                                // New data filter may have different columns visibility
                                redrawData(true, false);
                            }
                        }
                        model.setUpdateInProgress(false);
                        if (error == null) {
                            // Update status (update execution statistics)
                            updateStatusMessage();
                        }
                        updateFiltersText(error == null);
                        updateToolbar();
                        fireResultSetLoad();
                    } finally {
                        if (finalizer != null) {
                            try {
                                finalizer.run();
                            } catch (Throwable e) {
                                log.error(e);
                            }
                        }
                        dataPumpJob = null;
                    }
                }
            });
        }
    });
    dataPumpJob.setOffset(offset);
    dataPumpJob.setMaxRows(maxRows);
    dataPumpJob.schedule();
    return true;
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 29 with JobChangeAdapter

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

the class ObjectListControl method addLazyObject.

private synchronized void addLazyObject(OBJECT_TYPE object, ObjectColumn column) {
    if (lazyObjects == null) {
        lazyObjects = new LinkedHashMap<>();
    }
    List<ObjectColumn> objectColumns = lazyObjects.get(object);
    if (objectColumns == null) {
        objectColumns = new ArrayList<>();
        lazyObjects.put(object, objectColumns);
    }
    if (!objectColumns.contains(column)) {
        objectColumns.add(column);
    }
    if (lazyLoadingJob == null) {
        lazyLoadingJob = new LazyLoaderJob();
        lazyLoadingJob.addJobChangeListener(new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent event) {
                synchronized (ObjectListControl.this) {
                    if (lazyObjects == null || lazyObjects.isEmpty()) {
                        lazyLoadingJob = null;
                    } else {
                        lazyLoadingJob.schedule(LAZY_LOAD_DELAY);
                    }
                }
            }
        });
        lazyLoadingJob.schedule(LAZY_LOAD_DELAY);
    }
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 30 with JobChangeAdapter

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

the class ObjectListControl method loadData.

public void loadData(boolean lazy) {
    if (this.loadingJob != null) {
        try {
            for (int i = 0; i < 20; i++) {
                Thread.sleep(200);
                if (this.loadingJob == null) {
                    break;
                }
            }
        } catch (InterruptedException e) {
        // interrupted
        }
        if (loadingJob != null) {
            UIUtils.showMessageBox(getShell(), "Load", "Service is busy", SWT.ICON_WARNING);
            return;
        }
        return;
    }
    getListPropertySource();
    clearLazyCache();
    this.lazyLoadCanceled = false;
    if (lazy) {
        // start loading service
        synchronized (this) {
            this.loadingJob = createLoadService();
            if (this.loadingJob != null) {
                this.loadingJob.addJobChangeListener(new JobChangeAdapter() {

                    @Override
                    public void done(IJobChangeEvent event) {
                        loadingJob = null;
                    }
                });
                this.loadingJob.schedule(LAZY_LOAD_DELAY);
            }
        }
    } else {
        // Load data synchronously
        final LoadingJob<Collection<OBJECT_TYPE>> loadService = createLoadService();
        if (loadService != null) {
            loadService.syncRun();
        }
    }
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

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