org.eclipse.equinox.p2.operations.UpdateOperation Java Examples

The following examples show how to use org.eclipse.equinox.p2.operations.UpdateOperation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpdatePolicy.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean continueWorkingWithOperation(ProfileChangeOperation operation, Shell shell) {

	Assert.isTrue(operation.getResolutionResult() != null);
	IStatus status = operation.getResolutionResult();
	// user cancelled
	if (status.getSeverity() == IStatus.CANCEL)
		return false;

	// Special case those statuses where we would never want to open a wizard
	if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
		MessageDialog.openInformation(shell, P2UpdateUtil.CHECK_UPDATE_JOB_NAME, P2UpdateUtil.UPDATE_PROMPT_INFO_NO_UPDATE);
		return false;
	}

	// there is no plan, so we can't continue. Report any reason found
	if (operation.getProvisioningPlan() == null && !status.isOK()) {
		StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW);
		return false;
	}

	// Allow the wizard to open otherwise.
	return true;
}
 
Example #2
Source File: AutomaticUpdate.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
private void doUpdate() {
	if (operation == null) {
		return;
	}
	IStatus status = operation.getResolutionResult();
	// user cancelled
	if (status.getSeverity() == IStatus.CANCEL)
		return;

	// Special case those statuses where we would never want to open a wizard
	if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {		
		return;
	}
	
	if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
		UpdateWizard wizard = new UpdateWizard(getProvisioningUI(), operation, operation.getSelectedUpdates());
		TSWizardDialog dialog = new TSWizardDialog(getShell(), wizard);
		dialog.create();
		dialog.open();
	}
}
 
Example #3
Source File: UpdatePolicy.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean continueWorkingWithOperation(ProfileChangeOperation operation, Shell shell) {

	Assert.isTrue(operation.getResolutionResult() != null);
	IStatus status = operation.getResolutionResult();
	// user cancelled
	if (status.getSeverity() == IStatus.CANCEL)
		return false;

	// Special case those statuses where we would never want to open a wizard
	if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
		MessageDialog.openInformation(shell, P2UpdateUtil.CHECK_UPDATE_JOB_NAME, P2UpdateUtil.UPDATE_PROMPT_INFO_NO_UPDATE);
		return false;
	}

	// there is no plan, so we can't continue. Report any reason found
	if (operation.getProvisioningPlan() == null && !status.isOK()) {
		StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW);
		return false;
	}

	// Allow the wizard to open otherwise.
	return true;
}
 
Example #4
Source File: AutomaticUpdate.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private void doUpdate() {
	if (operation == null) {
		return;
	}
	IStatus status = operation.getResolutionResult();
	// user cancelled
	if (status.getSeverity() == IStatus.CANCEL)
		return;

	// Special case those statuses where we would never want to open a wizard
	if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {		
		return;
	}
	
	if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
		UpdateWizard wizard = new UpdateWizard(getProvisioningUI(), operation, operation.getSelectedUpdates());
		TSWizardDialog dialog = new TSWizardDialog(getShell(), wizard);
		dialog.create();
		dialog.open();
	}
}
 
Example #5
Source File: UpdateHandler.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
protected void doExecute(LoadMetadataRepositoryJob job){
	if (hasNoRepos) {
		return;
	}
	UpdateOperation operation = getProvisioningUI().getUpdateOperation(null, null);
	// check for updates
	operation.resolveModal(null);
	if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
		if (UpdateSingleIUWizard.validFor(operation)) {
			// Special case for only updating a single root
			UpdateSingleIUWizard wizard =
				new UpdateSingleIUWizard(getProvisioningUI(), operation);
			WizardDialog dialog = new WizardDialog(getShell(), wizard);
			dialog.create();
			dialog.open();
		} else {
			// Open the normal version of the update wizard
			getProvisioningUI().openUpdateWizard(false, operation, job);
		}
	}
}
 
Example #6
Source File: UpdateDescriptionPage.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * root 参数未使用
 * @param operation
 * @param root
 * @param ui
 */
protected UpdateDescriptionPage(UpdateOperation operation, IUElementListRoot root, ProvisioningUI ui) {
	super("MyUpdsateDescriptionPage");
	setTitle(P2UpdateUtil.UI_WIZARD_DESC_PAGE_TITLE);
	setDescription(P2UpdateUtil.UI_WIZARD_DESC_PAGE_DESC);
	this.ui = ui;
	this.root = root;
	this.operation = operation;
}
 
Example #7
Source File: UpdateWizardPage.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
protected UpdateWizardPage(UpdateOperation operation,IUElementListRoot root, ProvisioningUI ui) {
	super("MyUpdasteWizardPage1", ui, null);
	this.ui = ui;
	this.operation = operation;
	this.input = root;
	setTitle(P2UpdateUtil.UI_WIZARD_PAGE_TITLE);
	setDescription(P2UpdateUtil.UI_WIZARD_PAGE_DESC);
}
 
Example #8
Source File: UpdateWizardPage.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void updateCaches(IUElementListRoot newRoot,
		ProfileChangeOperation op) {
	operation = (UpdateOperation) op;
	if (newRoot != null) {
		setDrilldownElements(newRoot, operation);
		if (treeViewer != null) {
			if (input != newRoot)
				treeViewer.setInput(newRoot);
			else
				treeViewer.refresh();
		}
		input = newRoot;
	}
}
 
Example #9
Source File: UpdateWizard.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public UpdateWizard(ProvisioningUI ui, UpdateOperation operation, Object[] initialSelections) {
	Assert.isLegal(operation.hasResolved(), "Cannot create an update wizard on an unresolved operation"); //$NON-NLS-1$
	setWindowTitle(P2UpdateUtil.UI_WIZARD_DIALOG_TITLE);
	// setDefaultPageImageDescriptor(ProvUIImages.getImageDescriptor(ProvUIImages.WIZARD_BANNER_UPDATE));
	this.operation = operation;
	// this.initialSelections = (Update[]) initialSelections;
	this.ui = ui;
	// initializeResolutionModelElements(initialSelections);
	setNeedsProgressMonitor(true);
}
 
Example #10
Source File: UpdateDescriptionPage.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * root 参数未使用
 * @param operation
 * @param root
 * @param ui
 */
protected UpdateDescriptionPage(UpdateOperation operation, IUElementListRoot root, ProvisioningUI ui) {
	super("MyUpdsateDescriptionPage");
	setTitle(P2UpdateUtil.UI_WIZARD_DESC_PAGE_TITLE);
	setDescription(P2UpdateUtil.UI_WIZARD_DESC_PAGE_DESC);
	this.ui = ui;
	this.root = root;
	this.operation = operation;
}
 
Example #11
Source File: UpdateWizardPage.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
protected UpdateWizardPage(UpdateOperation operation,IUElementListRoot root, ProvisioningUI ui) {
	super("MyUpdasteWizardPage1", ui, null);
	this.ui = ui;
	this.operation = operation;
	this.input = root;
	setTitle(P2UpdateUtil.UI_WIZARD_PAGE_TITLE);
	setDescription(P2UpdateUtil.UI_WIZARD_PAGE_DESC);
}
 
Example #12
Source File: UpdateWizardPage.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void updateCaches(IUElementListRoot newRoot,
		ProfileChangeOperation op) {
	operation = (UpdateOperation) op;
	if (newRoot != null) {
		setDrilldownElements(newRoot, operation);
		if (treeViewer != null) {
			if (input != newRoot)
				treeViewer.setInput(newRoot);
			else
				treeViewer.refresh();
		}
		input = newRoot;
	}
}
 
Example #13
Source File: UpdateWizard.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public UpdateWizard(ProvisioningUI ui, UpdateOperation operation, Object[] initialSelections) {
	Assert.isLegal(operation.hasResolved(), "Cannot create an update wizard on an unresolved operation"); //$NON-NLS-1$
	setWindowTitle(P2UpdateUtil.UI_WIZARD_DIALOG_TITLE);
	// setDefaultPageImageDescriptor(ProvUIImages.getImageDescriptor(ProvUIImages.WIZARD_BANNER_UPDATE));
	this.operation = operation;
	// this.initialSelections = (Update[]) initialSelections;
	this.ui = ui;
	// initializeResolutionModelElements(initialSelections);
	setNeedsProgressMonitor(true);
}
 
Example #14
Source File: P2Util.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check for application updates.
 * 
 * @param agent
 * @param monitor
 * @return
 * @throws OperationCanceledException
 */
public static IStatus checkForUpdates(IProvisioningAgent agent, IProgressMonitor monitor)
	throws OperationCanceledException{
	System.out.println(">> checkForUpdates");
	ProvisioningSession session = new ProvisioningSession(agent);
	UpdateOperation operation = new UpdateOperation(session);
	SubMonitor sub = SubMonitor.convert(monitor, "Checking for application updates...", 200);
	return operation.resolveModal(sub.newChild(100));
}
 
Example #15
Source File: P2Util.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Download and install application updates.
 * 
 * @param agent
 * @param monitor
 * @return
 * @throws OperationCanceledException
 */
public static IStatus installUpdates(IProvisioningAgent agent, IProgressMonitor monitor)
	throws OperationCanceledException{
	ProvisioningSession session = new ProvisioningSession(agent);
	UpdateOperation operation = new UpdateOperation(session);
	SubMonitor sub = SubMonitor.convert(monitor, "Installing updates ...", 200);
	operation.resolveModal(sub.newChild(100));
	ProvisioningJob job = operation.getProvisioningJob(monitor);
	return job.runModal(sub.newChild(100));
}
 
Example #16
Source File: UpdateManager.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
/**
 * Install selected updates in to developer studio. Note: call
 * {@link #setSelectedUpdates(List) setSelectedUpdates} first.
 * 
 * @param monitor
 */
public void installSelectedUpdates(IProgressMonitor monitor) {
	SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_26, 2);
	URI[] repos = new URI[] { getDevStudioUpdateSite() };
	session = new ProvisioningSession(p2Agent);
	updateOperation = new UpdateOperation(session);
	updateOperation.getProvisioningContext().setArtifactRepositories(repos);
	updateOperation.getProvisioningContext().setMetadataRepositories(repos);

	updateOperation.setSelectedUpdates(selectedUpdates);
	IStatus status = updateOperation.resolveModal(progress.newChild(1));
	if (status.getSeverity() == IStatus.CANCEL) {
		throw new OperationCanceledException();
	} else if (status.getSeverity() == IStatus.ERROR) {
		String message = status.getChildren()[0].getMessage();
		UpdateMetaFileReaderJob.promptUserError(message, Messages.UpdateManager_27);
		log.error(Messages.UpdateManager_27 + message);
	} else {
		final ProvisioningJob provisioningJob = updateOperation.getProvisioningJob(progress.newChild(1));
		if (provisioningJob != null) {
			provisioningJob.addJobChangeListener(new JobChangeAdapter() {
				@Override
				public void done(IJobChangeEvent arg0) {
					Display.getDefault().syncExec(new Runnable() {
						@Override
						public void run() {
							boolean restart = MessageDialog.openQuestion(Display.getDefault().getActiveShell(),
									Messages.UpdateManager_28,
									Messages.UpdateManager_29 + Messages.UpdateManager_30);
							if (restart) {
								PlatformUI.getWorkbench().restart();
							}
						}
					});
				}
			});
			provisioningJob.schedule();
			Display.getDefault().syncExec(new Runnable() {
				@Override
				public void run() {
					try {
						PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
								.showView(IProgressConstants.PROGRESS_VIEW_ID);
					} catch (PartInitException e) {
						log.error(e);
					}
				}
			});
		} else {
			log.error(Messages.UpdateManager_31);
		}
	}
}