Search in sources :

Example 6 with ProvisioningUI

use of org.eclipse.equinox.p2.ui.ProvisioningUI in project knime-core by knime.

the class InvokeUpdateAction method openWizard.

@Override
protected void openWizard(final LoadMetadataRepositoryJob job, final ProvisioningUI provUI) {
    final UpdateOperation operation = provUI.getUpdateOperation(null, null);
    // check for updates
    operation.resolveModal(null);
    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

        @Override
        public void run() {
            Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
            if (!operation.hasResolved()) {
                MessageDialog.openInformation(shell, "Update KNIME...", "No updates were found");
            } else if (provUI.getPolicy().continueWorkingWithOperation(operation, shell)) {
                if (UpdateSingleIUWizard.validFor(operation)) {
                    // Special case for only updating a single root
                    UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(provUI, operation);
                    WizardDialog dialog = new WizardDialog(shell, wizard);
                    dialog.create();
                    if (dialog.open() == 0) {
                        clearOsgiAreaBeforeRestart();
                    }
                } else {
                    // Open the normal version of the update wizard
                    if (provUI.openUpdateWizard(false, operation, job) == 0) {
                        clearOsgiAreaBeforeRestart();
                    }
                }
            }
        }
    });
}
Also used : Shell(org.eclipse.swt.widgets.Shell) UpdateOperation(org.eclipse.equinox.p2.operations.UpdateOperation) UpdateSingleIUWizard(org.eclipse.equinox.internal.p2.ui.dialogs.UpdateSingleIUWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 7 with ProvisioningUI

use of org.eclipse.equinox.p2.ui.ProvisioningUI in project knime-core by knime.

the class KNIMEApplication method checkForUpdates.

private boolean checkForUpdates() {
    final IPreferenceStore prefStore = ProductPlugin.getDefault().getPreferenceStore();
    if (prefStore.getBoolean(JUSTUPDATED)) {
        prefStore.setValue(JUSTUPDATED, false);
        return false;
    }
    final ProvisioningUI provUI = ProvisioningUI.getDefaultUI();
    if (provUI.getRepositoryTracker() == null) {
        LogHelper.log(new Status(IStatus.WARNING, ProductPlugin.getDefault().getBundle().getSymbolicName(), "Updating is not possible of KNIME is started from " + "within the IDE."));
        return false;
    }
    final IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper.getService(ProductPlugin.getDefault().getBundle().getBundleContext(), IProvisioningAgent.SERVICE_NAME);
    if (agent == null) {
        LogHelper.log(new Status(IStatus.ERROR, ProductPlugin.getDefault().getBundle().getSymbolicName(), "No provisioning agent found. This application is " + "not set up for updates."));
    }
    final MutableBoolean restart = new MutableBoolean(false);
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            ProvisioningSession session = new ProvisioningSession(agent);
            UpdateOperation operation = new UpdateOperation(session);
            SubMonitor sub = SubMonitor.convert(monitor, "Checking for application updates...", 200);
            IStatus status = operation.resolveModal(sub.newChild(100));
            if (status.getSeverity() == IStatus.CANCEL) {
                throw new OperationCanceledException();
            } else if (status.getSeverity() != IStatus.ERROR) {
                ProvisioningJob job = operation.getProvisioningJob(null);
                status = job.runModal(sub.newChild(100));
                if (status.getSeverity() == IStatus.CANCEL) {
                    throw new OperationCanceledException();
                }
                if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
                    // ok, just proceed
                    LogHelper.log(new Status(IStatus.INFO, ProductPlugin.getDefault().getBundle().getSymbolicName(), "No updates found."));
                } else if (status.getSeverity() != IStatus.ERROR) {
                    prefStore.setValue(JUSTUPDATED, true);
                    restart.setValue(true);
                } else {
                    LogHelper.log(status);
                }
            } else {
                LogHelper.log(status);
            }
        }
    };
    try {
        new ProgressMonitorDialog(null).run(true, true, runnable);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
    }
    return restart.booleanValue();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ProvisioningSession(org.eclipse.equinox.p2.operations.ProvisioningSession) IStatus(org.eclipse.core.runtime.IStatus) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) MutableBoolean(org.knime.core.util.MutableBoolean) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) SubMonitor(org.eclipse.core.runtime.SubMonitor) ProvisioningJob(org.eclipse.equinox.p2.operations.ProvisioningJob) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProvisioningUI(org.eclipse.equinox.p2.ui.ProvisioningUI) UpdateOperation(org.eclipse.equinox.p2.operations.UpdateOperation) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

ProvisioningUI (org.eclipse.equinox.p2.ui.ProvisioningUI)6 UpdateOperation (org.eclipse.equinox.p2.operations.UpdateOperation)3 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)2 RepositoryTracker (org.eclipse.equinox.p2.operations.RepositoryTracker)2 LoadMetadataRepositoryJob (org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob)2 File (java.io.File)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1