Search in sources :

Example 26 with SubMonitor

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

the class PreloadingRepositoryHandler method doExecuteAndLoad.

void doExecuteAndLoad() {
    if (preloadRepositories()) {
        // cancel any load that is already running
        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, getProgressTaskName(), 1000);
                IStatus status = super.runModal(sub.newChild(500));
                if (status.getSeverity() == IStatus.CANCEL)
                    return status;
                if (status.getSeverity() != IStatus.OK) {
                    // 记录检查错误
                    checkStatus[0] = status;
                    return Status.OK_STATUS;
                }
                try {
                    doPostLoadBackgroundWork(sub.newChild(500));
                } catch (OperationCanceledException e) {
                    return Status.CANCEL_STATUS;
                }
                return status;
            }
        };
        setLoadJobProperties(loadJob);
        loadJob.setName(P2UpdateUtil.CHECK_UPDATE_JOB_NAME);
        if (waitForPreload()) {
            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_CHECK);
                                        return;
                                    }
                                    doExecute(loadJob);
                                }
                            });
                        }
                }
            });
            loadJob.setUser(true);
            loadJob.schedule();
        } else {
            loadJob.setSystem(true);
            loadJob.setUser(false);
            loadJob.schedule();
            doExecute(null);
        }
    } else {
        doExecute(null);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) SubMonitor(org.eclipse.core.runtime.SubMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) LoadMetadataRepositoryJob(org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob)

Example 27 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor 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 28 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor in project generator by mybatis.

the class GeneratorAntTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.apache.tools.ant.Task#execute()
     */
@Override
public void execute() throws BuildException {
    if (!StringUtility.stringHasValue(configfile)) {
        throw new BuildException("configfile is a required parameter");
    }
    List<String> warnings = new ArrayList<String>();
    File configurationFile = new File(configfile);
    if (!configurationFile.exists()) {
        throw new BuildException("configfile " + configfile + " does not exist");
    }
    Set<String> fullyqualifiedTables = new HashSet<String>();
    if (StringUtility.stringHasValue(fullyQualifiedTableNames)) {
        //$NON-NLS-1$
        StringTokenizer st = new StringTokenizer(fullyQualifiedTableNames, ",");
        while (st.hasMoreTokens()) {
            String s = st.nextToken().trim();
            if (s.length() > 0) {
                fullyqualifiedTables.add(s);
            }
        }
    }
    Set<String> contexts = new HashSet<String>();
    if (StringUtility.stringHasValue(contextIds)) {
        //$NON-NLS-1$
        StringTokenizer st = new StringTokenizer(contextIds, ",");
        while (st.hasMoreTokens()) {
            String s = st.nextToken().trim();
            if (s.length() > 0) {
                contexts.add(s);
            }
        }
    }
    IProgressMonitor monitor = (IProgressMonitor) getProject().getReferences().get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR);
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    try {
        SubMonitor subMonitor = SubMonitor.convert(monitor, 1000);
        subMonitor.beginTask("Generating MyBatis/iBATIS Artifacts:", 1000);
        subMonitor.subTask("Parsing Configuration");
        Properties p = propertyset == null ? null : propertyset.getProperties();
        ConfigurationParser cp = new ConfigurationParser(p, warnings);
        Configuration config = cp.parseConfiguration(configurationFile);
        subMonitor.worked(50);
        monitor.subTask("Generating Files from Database Tables");
        MyBatisGenerator generator = new MyBatisGenerator(config, new EclipseShellCallback(), warnings);
        EclipseProgressCallback progressCallback = new EclipseProgressCallback(subMonitor.newChild(950));
        generator.generate(progressCallback, contexts, fullyqualifiedTables);
    } catch (XMLParserException e) {
        for (String error : e.getErrors()) {
            log(error, Project.MSG_ERR);
        }
        throw new BuildException(e.getMessage());
    } catch (SQLException e) {
        throw new BuildException(e.getMessage());
    } catch (IOException e) {
        throw new BuildException(e.getMessage());
    } catch (InvalidConfigurationException e) {
        throw new BuildException(e.getMessage());
    } catch (InterruptedException e) {
        throw new BuildException("Cancelled by user");
    } finally {
        monitor.done();
    }
    for (String warning : warnings) {
        log("WARNING: " + warning, Project.MSG_WARN);
    }
}
Also used : EclipseShellCallback(org.mybatis.generator.eclipse.core.callback.EclipseShellCallback) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Configuration(org.mybatis.generator.config.Configuration) XMLParserException(org.mybatis.generator.exception.XMLParserException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) SubMonitor(org.eclipse.core.runtime.SubMonitor) IOException(java.io.IOException) Properties(java.util.Properties) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) StringTokenizer(java.util.StringTokenizer) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) EclipseProgressCallback(org.mybatis.generator.eclipse.core.callback.EclipseProgressCallback) ConfigurationParser(org.mybatis.generator.config.xml.ConfigurationParser) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) HashSet(java.util.HashSet) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator)

Example 29 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor in project generator by mybatis.

the class RunGeneratorThread method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.core.resources.IWorkspaceRunnable#run(org.eclipse.core.runtime.IProgressMonitor)
     */
public void run(IProgressMonitor monitor) throws CoreException {
    SubMonitor subMonitor = SubMonitor.convert(monitor, 1000);
    subMonitor.beginTask("Generating MyBatis/iBATIS Artifacts:", 1000);
    setClassLoader();
    try {
        subMonitor.subTask("Parsing Configuration");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(inputFile.getLocation().toFile());
        subMonitor.worked(50);
        MyBatisGenerator mybatisGenerator = new MyBatisGenerator(config, new EclipseShellCallback(), warnings);
        monitor.subTask("Generating Files from Database Tables");
        SubMonitor spm = subMonitor.newChild(950);
        mybatisGenerator.generate(new EclipseProgressCallback(spm));
    } catch (InterruptedException e) {
        throw new OperationCanceledException();
    } catch (SQLException e) {
        Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
        Activator.getDefault().getLog().log(status);
        throw new CoreException(status);
    } catch (IOException e) {
        Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
        Activator.getDefault().getLog().log(status);
        throw new CoreException(status);
    } catch (XMLParserException e) {
        List<String> errors = e.getErrors();
        MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "XML Parser Errors\n  See Details for more Information", null);
        Iterator<String> iter = errors.iterator();
        while (iter.hasNext()) {
            Status message = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, iter.next(), null);
            multiStatus.add(message);
        }
        throw new CoreException(multiStatus);
    } catch (InvalidConfigurationException e) {
        List<String> errors = e.getErrors();
        MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "Invalid Configuration\n  See Details for more Information", null);
        Iterator<String> iter = errors.iterator();
        while (iter.hasNext()) {
            Status message = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, iter.next(), null);
            multiStatus.add(message);
        }
        throw new CoreException(multiStatus);
    } finally {
        monitor.done();
        restoreClassLoader();
    }
}
Also used : EclipseShellCallback(org.mybatis.generator.eclipse.core.callback.EclipseShellCallback) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Configuration(org.mybatis.generator.config.Configuration) SQLException(java.sql.SQLException) XMLParserException(org.mybatis.generator.exception.XMLParserException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) MultiStatus(org.eclipse.core.runtime.MultiStatus) IOException(java.io.IOException) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) EclipseProgressCallback(org.mybatis.generator.eclipse.core.callback.EclipseProgressCallback) CoreException(org.eclipse.core.runtime.CoreException) ConfigurationParser(org.mybatis.generator.config.xml.ConfigurationParser) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator)

Example 30 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor in project mechanoid by robotoworks.

the class MechanoidLibsInstaller method install.

public void install(IJavaProject javaProject, IProgressMonitor progressMonitor) throws IOException, URISyntaxException {
    try {
        SubMonitor progress = SubMonitor.convert(progressMonitor, 2);
        installLibs(javaProject, progress.newChild(1));
    } catch (Exception e) {
        MechanoidUiPlugin.getPlugin().getLog().log(new Status(Status.ERROR, MechanoidUiPlugin.PLUGIN_ID, Status.OK, Messages.MechanoidLibsInstaller_Message_Failed_To_Add_Libs, e));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) SubMonitor(org.eclipse.core.runtime.SubMonitor) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

SubMonitor (org.eclipse.core.runtime.SubMonitor)61 CoreException (org.eclipse.core.runtime.CoreException)27 IStatus (org.eclipse.core.runtime.IStatus)25 Status (org.eclipse.core.runtime.Status)24 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)15 IOException (java.io.IOException)12 IFile (org.eclipse.core.resources.IFile)10 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)10 InputStream (java.io.InputStream)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 IPath (org.eclipse.core.runtime.IPath)9 IProject (org.eclipse.core.resources.IProject)8 File (java.io.File)7 MultiStatus (org.eclipse.core.runtime.MultiStatus)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 IContainer (org.eclipse.core.resources.IContainer)4 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 URI (java.net.URI)3