Java Code Examples for org.eclipse.core.runtime.IStatus#CANCEL

The following examples show how to use org.eclipse.core.runtime.IStatus#CANCEL . 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: 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 2
Source File: ProcessMarkerNavigationProvider.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
* @generated
*/
public static IMarker addMarker(IFile file, String elementId, String location, String message, int statusSeverity) {
	IMarker marker = null;
	try {
		marker = file.createMarker(MARKER_TYPE);
		marker.setAttribute(IMarker.MESSAGE, message);
		marker.setAttribute(IMarker.LOCATION, location);
		marker.setAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, elementId);
		int markerSeverity = IMarker.SEVERITY_INFO;
		if (statusSeverity == IStatus.WARNING) {
			markerSeverity = IMarker.SEVERITY_WARNING;
		} else if (statusSeverity == IStatus.ERROR || statusSeverity == IStatus.CANCEL) {
			markerSeverity = IMarker.SEVERITY_ERROR;
		}
		marker.setAttribute(IMarker.SEVERITY, markerSeverity);
	} catch (CoreException e) {
		ProcessDiagramEditorPlugin.getInstance().logError("Failed to create validation marker", e); //$NON-NLS-1$
	}
	return marker;
}
 
Example 3
Source File: ExpressionViewer.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void validateExternalDatabindingContextTargets(final DataBindingContext dbc) {
    if (dbc != null) {
        final IObservableList validationStatusProviders = dbc.getValidationStatusProviders();
        final Iterator iterator = validationStatusProviders.iterator();
        while (iterator.hasNext()) {
            final ValidationStatusProvider validationStatusProvider = (ValidationStatusProvider) iterator.next();
            final IObservableValue validationStatus = validationStatusProvider.getValidationStatus();
            if (!(validationStatus instanceof UnmodifiableObservableValue)) {
                final IStatus status = (IStatus) validationStatus.getValue();
                if (status != null) {
                    if (status.getSeverity() == IStatus.OK) {
                        validationStatus.setValue(ValidationStatus.ok());
                    } else if (status.getSeverity() == IStatus.WARNING) {
                        validationStatus.setValue(ValidationStatus.warning(status.getMessage()));
                    } else if (status.getSeverity() == IStatus.INFO) {
                        validationStatus.setValue(ValidationStatus.info(status.getMessage()));
                    } else if (status.getSeverity() == IStatus.ERROR) {
                        validationStatus.setValue(ValidationStatus.error(status.getMessage()));
                    } else if (status.getSeverity() == IStatus.CANCEL) {
                        validationStatus.setValue(ValidationStatus.cancel(status.getMessage()));
                    }
                }
            }
        }
    }
}
 
Example 4
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 5
Source File: ServerStatus.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
private String getSeverityString() {
	//note the severity string should not be translated
	switch (getSeverity()) {
		case IStatus.ERROR :
			return SEVERITY_ERROR;
		case IStatus.WARNING :
			return SEVERITY_WARNING;
		case IStatus.INFO :
			return SEVERITY_INFO;
		case IStatus.CANCEL :
			return SEVERITY_CANCEL;
		case IStatus.OK :
			return SEVERITY_OK;
	}
	return null;
}
 
Example 6
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 7
Source File: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 6 votes vote down vote up
public IStatus runInUIThread(IProgressMonitor monitor) {

			if (!progressLabel.isDisposed())
				progressLabel.setText(progressMonitor != null ? progressMonitor
						.getMessage() : EMPTY_STRING);

			if (progressMonitor == null || progressMonitor.isDone()) {
				return new Status(IStatus.CANCEL, PlatformUI.PLUGIN_ID,
						IStatus.CANCEL, EMPTY_STRING, null);
			}

			// Schedule cyclical with 500 milliseconds delay
			schedule(500);

			return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK,
					EMPTY_STRING, null);
		}
 
Example 8
Source File: TestEditor.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
protected void validateState(IEditorInput input) {

		IDocumentProvider provider = getDocumentProvider();
		if (!(provider instanceof IDocumentProviderExtension))
			return;

		IDocumentProviderExtension extension = (IDocumentProviderExtension) provider;

		try {

			extension.validateState(input, getSite().getShell());

		} catch (CoreException x) {
			IStatus status = x.getStatus();
			if (status == null || status.getSeverity() != IStatus.CANCEL) {
				Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
				ILog log = Platform.getLog(bundle);
				log.log(x.getStatus());

				Shell shell = getSite().getShell();
				String title = "EditorMessages.Editor_error_validateEdit_title";
				String msg = "EditorMessages.Editor_error_validateEdit_message";
				ErrorDialog.openError(shell, title, msg, x.getStatus());
			}
			return;
		}

		if (fSourceViewer != null)
			fSourceViewer.setEditable(isEditable());

	}
 
Example 9
Source File: TestEditor.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
protected void validateState(final IEditorInput input) {

        final IDocumentProvider provider = getDocumentProvider();
        if (!(provider instanceof IDocumentProviderExtension))
            return;

        final IDocumentProviderExtension extension = (IDocumentProviderExtension) provider;

        try {

            extension.validateState(input, getSite().getShell());

        } catch (final CoreException x) {
            final IStatus status = x.getStatus();
            if (status == null || status.getSeverity() != IStatus.CANCEL) {
                final Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
                final ILog log = Platform.getLog(bundle);
                log.log(x.getStatus());

                final Shell shell = getSite().getShell();
                final String title = "EditorMessages.Editor_error_validateEdit_title";
                final String msg = "EditorMessages.Editor_error_validateEdit_message";
                ErrorDialog.openError(shell, title, msg, x.getStatus());
            }
            return;
        }

        if (fSourceViewer != null)
            fSourceViewer.setEditable(isEditable());

    }
 
Example 10
Source File: ServerStatus.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts a status into a server status.
 */
public static ServerStatus convert(IStatus status) {
	int httpCode = 200;
	if (status.getSeverity() == IStatus.ERROR || status.getSeverity() == IStatus.CANCEL)
		httpCode = 500;
	return convert(status, httpCode);
}
 
Example 11
Source File: PreloadingRepositoryHandler.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
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);
	}
}
 
Example 12
Source File: NegotiationHandler.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected IStatus run(IProgressMonitor monitor) {
  try {
    SessionNegotiation.Status status =
        negotiation.start(ProgressMonitorAdapterFactory.convert(monitor));

    switch (status) {
      case CANCEL:
        return Status.CANCEL_STATUS;
      case ERROR:
        return new Status(IStatus.ERROR, Saros.PLUGIN_ID, negotiation.getErrorMessage());
      case OK:
        break;
      case REMOTE_CANCEL:
        SarosView.showNotification(
            Messages.NegotiationHandler_canceled_invitation,
            MessageFormat.format(Messages.NegotiationHandler_canceled_invitation_text, peer));

        return new Status(
            IStatus.CANCEL,
            Saros.PLUGIN_ID,
            MessageFormat.format(Messages.NegotiationHandler_canceled_invitation_text, peer));

      case REMOTE_ERROR:
        SarosView.showNotification(
            Messages.NegotiationHandler_error_during_invitation,
            MessageFormat.format(
                Messages.NegotiationHandler_error_during_invitation_text,
                peer,
                negotiation.getErrorMessage()));

        return new Status(
            IStatus.ERROR,
            Saros.PLUGIN_ID,
            MessageFormat.format(
                Messages.NegotiationHandler_error_during_invitation_text,
                peer,
                negotiation.getErrorMessage()));
    }
  } catch (Exception e) {
    log.error("This exception is not expected here: ", e);
    return new Status(IStatus.ERROR, Saros.PLUGIN_ID, e.getMessage(), e);
  }

  sessionManager.startSharingReferencePoints(negotiation.getPeer());

  return Status.OK_STATUS;
}
 
Example 13
Source File: UpdateManager.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
/**
 * Install selected features in to developer studio. Note: call
 * {@link #setSelectedFeaturesToInstall(List) setSelectedFeaturesToInstall}
 * first.
 * 
 * @param monitor
 */
public void installSelectedFeatures(IProgressMonitor monitor) {
	SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_32, 2);

	URI[] repos = new URI[] { getDevStudioReleaseSite() };
	session = new ProvisioningSession(p2Agent);
	installOperation = new InstallOperation(session, selectedFeatures);
	installOperation.getProvisioningContext().setArtifactRepositories(repos);
	installOperation.getProvisioningContext().setMetadataRepositories(repos);
	IStatus status = installOperation.resolveModal(progress.newChild(1));
	if (status.getSeverity() == IStatus.CANCEL || progress.isCanceled()) {
		throw new OperationCanceledException();
	} else if (status.getSeverity() == IStatus.ERROR) {
		String message = status.getChildren()[0].getMessage();
		log.error(Messages.UpdateManager_33 + message);
		UpdateMetaFileReaderJob.promptUserError(message, Messages.UpdateManager_33);
	} else {
		ProvisioningJob provisioningJob = installOperation.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_34,
									Messages.UpdateManager_35 + Messages.UpdateManager_36);
							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_37);
		}
	}
}
 
Example 14
Source File: EmptyInputValidator.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public Builder cancelLevel() {
    this.severity = IStatus.CANCEL;
    return this;
}
 
Example 15
Source File: PathValidator.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public Builder cancelLevel() {
    this.severity = IStatus.CANCEL;
    return this;
}
 
Example 16
Source File: IOUtil.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Recursively copy one directory to a new destination directory while showing progress. If a file is passed in
 * instead of a directory, this method will delegate to copyFile to perform the copy. Various tests for existence,
 * readability, and writability are performed before copying. If any of these tests fail, the copy be aborted. Note
 * that this means that if a failure occurs somewhere in a descendant file/directory, all files up to that point
 * will exist, but no files after that point will be copied.
 * 
 * @param source
 * @param destination
 * @param monitor
 * @param count
 * @param updateSize
 * @param cancelable
 * @throws IOException
 */
private static IStatus copyDirectory(File source, File destination, IProgressMonitor monitor, int[] count,
		int updateSize, boolean cancelable) throws IOException
{
	if (monitor != null)
	{
		if (cancelable && monitor.isCanceled())
		{
			return new Status(IStatus.CANCEL, CorePlugin.PLUGIN_ID, IStatus.CANCEL, StringUtil.EMPTY, null);
		}

		count[0]++;
		if (updateSize < 2 || count[0] % updateSize == 0)
		{
			monitor.setTaskName(MessageFormat.format(Messages.IOUtil_Copy_Label, destination.toString()));
			monitor.worked(1);
		}
	}

	if (source.isDirectory())
	{
		String error = null;

		// make sure we can read the source directory and that we have a
		// writable destination directory
		if (source.canRead() == false)
		{
			error = Messages.IOUtil_Source_Directory_Not_Readable;
		}
		else if (destination.exists() == false)
		{
			if (destination.mkdir() == false)
			{
				error = Messages.IOUtil_Destination_Directory_Uncreatable;
			}
		}
		else if (destination.isDirectory() == false)
		{
			error = Messages.IOUtil_Destination_Is_Not_A_Directory;
		}
		else if (destination.canWrite() == false)
		{
			error = Messages.IOUtil_Destination_Directory_Not_Writable;
		}

		if (error == null)
		{
			// copy all files in the source directory
			for (String filename : source.list())
			{
				IStatus status = copyDirectory(new File(source, filename), new File(destination, filename),
						monitor, count, updateSize, cancelable);
				if (status != null && !status.isOK())
				{
					return status;
				}
			}
		}
		else
		{
			String message = MessageFormat.format( //
					Messages.IOUtil_Unable_To_Copy_Because, //
					source, //
					destination, //
					error //
					);

			IdeLog.logError(CorePlugin.getDefault(), message);

			return new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, IStatus.ERROR, message, null);
		}
	}
	else
	{
		IFileStore src = EFS.getLocalFileSystem().fromLocalFile(source);
		try
		{
			src.copy(EFS.getLocalFileSystem().fromLocalFile(destination), EFS.OVERWRITE, new NullProgressMonitor());
		}
		catch (CoreException e)
		{
			return new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
		}
	}

	return Status.OK_STATUS;
}
 
Example 17
Source File: AutomaticUpdate.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example 18
Source File: TypeInfoViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private IStatus canceled(Exception e, boolean removePendingItems) {
	fViewer.searchJobCanceled(fTicket, removePendingItems);
	return new Status(IStatus.CANCEL, JavaPlugin.getPluginId(), IStatus.CANCEL, JavaUIMessages.TypeInfoViewer_job_cancel, e);
}
 
Example 19
Source File: AutomaticUpdate.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example 20
Source File: ProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
* @generated
*/
protected void performSaveAs(IProgressMonitor progressMonitor) {
	Shell shell = getSite().getShell();
	IEditorInput input = getEditorInput();
	SaveAsDialog dialog = new SaveAsDialog(shell);
	IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
	if (original != null) {
		dialog.setOriginalFile(original);
	}
	dialog.create();
	IDocumentProvider provider = getDocumentProvider();
	if (provider == null) {
		// editor has been programmatically closed while the dialog was open
		return;
	}
	if (provider.isDeleted(input) && original != null) {
		String message = NLS.bind(Messages.ProcessDiagramEditor_SavingDeletedFile, original.getName());
		dialog.setErrorMessage(null);
		dialog.setMessage(message, IMessageProvider.WARNING);
	}
	if (dialog.open() == Window.CANCEL) {
		if (progressMonitor != null) {
			progressMonitor.setCanceled(true);
		}
		return;
	}
	IPath filePath = dialog.getResult();
	if (filePath == null) {
		if (progressMonitor != null) {
			progressMonitor.setCanceled(true);
		}
		return;
	}
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	IFile file = workspaceRoot.getFile(filePath);
	final IEditorInput newInput = new FileEditorInput(file);
	// Check if the editor is already open
	IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
	IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
			.getEditorReferences();
	for (int i = 0; i < editorRefs.length; i++) {
		if (matchingStrategy.matches(editorRefs[i], newInput)) {
			MessageDialog.openWarning(shell, Messages.ProcessDiagramEditor_SaveAsErrorTitle,
					Messages.ProcessDiagramEditor_SaveAsErrorMessage);
			return;
		}
	}
	boolean success = false;
	try {
		provider.aboutToChange(newInput);
		getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
				getDocumentProvider().getDocument(getEditorInput()), true);
		success = true;
	} catch (CoreException x) {
		IStatus status = x.getStatus();
		if (status == null || status.getSeverity() != IStatus.CANCEL) {
			ErrorDialog.openError(shell, Messages.ProcessDiagramEditor_SaveErrorTitle,
					Messages.ProcessDiagramEditor_SaveErrorMessage, x.getStatus());
		}
	} finally {
		provider.changed(newInput);
		if (success) {
			setInput(newInput);
		}
	}
	if (progressMonitor != null) {
		progressMonitor.setCanceled(!success);
	}
}