use of org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob 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();
}
use of org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob in project knime-core by knime.
the class AbstractP2Action method startLoadJob.
/**
* Starts the repository load job. After the repositories have been loaded,
* {@link #openWizard(LoadMetadataRepositoryJob, ProvisioningUI)} is called.
*/
protected final void startLoadJob() {
final ProvisioningUI provUI = ProvisioningUI.getDefaultUI();
Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(provUI);
loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));
loadJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(final IJobChangeEvent event) {
if (PlatformUI.isWorkbenchRunning() && event.getResult().isOK()) {
openWizard(loadJob, provUI);
}
}
});
loadJob.setUser(true);
loadJob.schedule();
}
use of org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob 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();
}
}
}
}
});
}
Aggregations