Java Code Examples for org.eclipse.core.runtime.IStatus#getCode()
The following examples show how to use
org.eclipse.core.runtime.IStatus#getCode() .
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: ModelEditor.java From tlaplus with MIT License | 6 votes |
private static IStatus shortenStatusMessage(IStatus status) { if (status.isMultiStatus()) { final IStatus[] convertedChildren = new Status[status.getChildren().length]; // convert nested status objects. final IStatus[] children = status.getChildren(); for (int i = 0; i < children.length; i++) { final IStatus child = children[i]; convertedChildren[i] = new Status(child.getSeverity(), child.getPlugin(), child.getCode(), substring(child.getMessage()), child.getException()); } return new MultiStatus(status.getPlugin(), status.getCode(), convertedChildren, substring(status.getMessage()), status.getException()); } else { return new Status(status.getSeverity(), status.getPlugin(), status.getCode(), substring(status.getMessage()), status.getException()); } }
Example 2
Source File: JavaDocLocations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Handles the exception thrown from JDT Core when the attached Javadoc * cannot be retrieved due to accessibility issues or location URL issue. This exception is not * logged but the exceptions occurred due to other reasons are logged. * * @param e the exception thrown when retrieving the Javadoc fails * @return the String message for why the Javadoc could not be retrieved * @since 3.9 */ public static String handleFailedJavadocFetch(CoreException e) { IStatus status= e.getStatus(); if (JavaCore.PLUGIN_ID.equals(status.getPlugin())) { Throwable cause= e.getCause(); int code= status.getCode(); // See bug 120559, bug 400060 and bug 400062 if (code == IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC_TIMEOUT || (code == IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC && (cause instanceof FileNotFoundException || cause instanceof SocketException || cause instanceof UnknownHostException || cause instanceof ProtocolException))) return CorextMessages.JavaDocLocations_error_gettingAttachedJavadoc; } JavaPlugin.log(e); return CorextMessages.JavaDocLocations_error_gettingJavadoc; }
Example 3
Source File: UpdatePolicy.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
@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 translationstudio8 with GNU General Public License v2.0 | 6 votes |
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: AutomaticUpdate.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
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 6
Source File: StatusUtil.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
public static IStatus merge(IStatus status, IStatus newStatus) { if (status == null) { return newStatus; } else { if (status instanceof MultiStatus) { ((MultiStatus) status).merge(newStatus); return status; } else { MultiStatus merged = new MultiStatus(status.getPlugin(), status.getCode(), status.getMessage(), status.getException()); merged.merge(newStatus); return merged; } } }
Example 7
Source File: UpdatePolicy.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
@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 8
Source File: ClassFile.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public IBuffer getBuffer() throws JavaModelException { IStatus status = validateClassFile(); if (status.isOK()) { return super.getBuffer(); } else { switch (status.getCode()) { case IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH: // don't throw a JavaModelException to be able to open .class file outside the classpath (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=138507 ) case IJavaModelStatusConstants.INVALID_ELEMENT_TYPES: // don't throw a JavaModelException to be able to open .class file in proj==src case without source (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=221904 ) return null; default: throw new JavaModelException((IJavaModelStatus) status); } } }
Example 9
Source File: ValidationTestBase.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * Helper method to convert the specified <code>status</code> to an array * of statuses for uniform treatment of scalar and multi-statuses. As a * special case, the scalar status indicating success because no constraints * were evaluated results in an empty array being returned. * * @param status * the status, which may be multi or not * @return all of the statuses represented by the incoming <code>status</code> */ public IStatus[] getStatuses(final IStatus status) { if (status.getCode() == EMFModelValidationStatusCodes.NO_CONSTRAINTS_EVALUATED) { return new IStatus[0]; } final List<IStatus> result = new java.util.ArrayList<>(); collectStatuses(status, result); return result.toArray(new IStatus[result.size()]); }
Example 10
Source File: RequirementsUtility.java From thym with Eclipse Public License 1.0 | 5 votes |
/** * Checks if the Cordova requirements are available. * Returns one of the error codes from {@link CordovaCLIErrors}. * * @param project * @return error code or 0 */ private static int doCheckCordovaRequirements() { try { CordovaCLI cli = new CordovaCLI(); ErrorDetectingCLIResult cordovaResult = cli.version(new NullProgressMonitor()) .convertTo(ErrorDetectingCLIResult.class); IStatus cordovaStatus = cordovaResult.asStatus(); if (cordovaStatus.isOK()) { return 0; } if (cordovaStatus.getCode() == CordovaCLIErrors.ERROR_COMMAND_MISSING) { // check if node.js is missing as well IStatus nodeStatus = cli.nodeVersion(new NullProgressMonitor()) .convertTo(ErrorDetectingCLIResult.class) .asStatus(); if(nodeStatus.getCode() == CordovaCLIErrors.ERROR_COMMAND_MISSING){ return CordovaCLIErrors.ERROR_NODE_COMMAND_MISSING; } return CordovaCLIErrors.ERROR_CORDOVA_COMMAND_MISSING; } Version cVer = Version.parseVersion(cordovaResult.getMessage()); Version mVer = Version.parseVersion(MIN_CORDOVA_VERSION); if(cVer.compareTo(mVer) < 0 ){ return CordovaCLIErrors.ERROR_CORDOVA_VERSION_OLD; } return 0; } catch (CoreException e) { return CordovaCLIErrors.ERROR_GENERAL; } }
Example 11
Source File: MessageLine.java From birt with Eclipse Public License 1.0 | 5 votes |
private Image findImage( IStatus status ) { if ( status.isOK( ) ) { return null; } else if ( status.getCode( ) == IStatus.ERROR ) { return ReportPlatformUIImages.getImage( IReportGraphicConstants.ICON_STATUS_ERROR ); //$NON-NLS-1$ } return null; }
Example 12
Source File: SVNException.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public static SVNException wrapException(CoreException e) { IStatus status = e.getStatus(); // If the exception is not a multi-status, wrap the exception to keep the original stack trace. // If the exception is a multi-status, the interesting stack traces should be in the childen already if ( ! status.isMultiStatus()) { status = new SVNStatus(status.getSeverity(), status.getCode(), status.getMessage(), e); } return new SVNException(status); }
Example 13
Source File: ExceptionHandler.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * @param e * @return */ @SuppressWarnings("unused") private boolean isInvalidResouceName(CoreException e) { IStatus status = e.getStatus(); if (status == null) { return false; } if (!ResourcesPlugin.PI_RESOURCES.equals(status.getPlugin())) { return false; } if (status.isMultiStatus()) { final IStatus[] children = status.getChildren(); for (int i = 0; i < children.length; ++i) { final IStatus child = children[i]; if (!(ResourcesPlugin.PI_RESOURCES.equals(status.getPlugin()) && child.getCode() == IResourceStatus.INVALID_RESOURCE_NAME)) { return false; } } return true; } else { if (status.getCode() == IResourceStatus.INVALID_RESOURCE_NAME) { return true; } } return false; }
Example 14
Source File: CrySLBuilderUtils.java From CogniCrypt with Eclipse Public License 2.0 | 5 votes |
public static void addCrySLBuilderToProject(IProject project) { try { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = CrySLNature.NATURE_ID; // validate the natures IWorkspace workspace = ResourcesPlugin.getWorkspace(); IStatus status = workspace.validateNatureSet(newNatures); // only apply new nature, if the status is ok if (status.getCode() == IStatus.OK) { description.setNatureIds(newNatures); } ICommand[] buildSpec = description.getBuildSpec(); ICommand command = description.newCommand(); command.setBuilderName(CrySLBuilder.BUILDER_ID); ICommand[] newbuilders = new ICommand[buildSpec.length + 1]; System.arraycopy(buildSpec, 0, newbuilders, 0, buildSpec.length); newbuilders[buildSpec.length] = command; description.setBuildSpec(newbuilders); project.setDescription(description, null); } catch (CoreException e) { Activator.getDefault().logError(e); } }
Example 15
Source File: N4JSResource.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * * Discards the current content of the resource, sets the parser result as first slot, installs derived state (this * will build up the second slot again) and sends notifications that proxies have been resolved. The resource will * be even loaded if its already marked as loaded. * * If the second slot, that is the TModule, was already loaded and we just resolved the AST, then the existing * TModule is kept in the resource and rewired to the resolved AST. * * @param object * the object which resource should be loaded * @return the loaded/resolved object */ private EObject demandLoadResource(EObject object) { TModule oldModule = null; EObject oldScript = null; ModuleAwareContentsList myContents = ((ModuleAwareContentsList) contents); try { oldModule = discardStateFromDescription(false); if (!myContents.isEmpty()) { oldScript = myContents.basicGet(0); myContents.sneakyClear(); } // now everything is removed from the resource and contents is empty // stop sending notifications eSetDeliver(false); if (isLoaded) { // Loads the resource even its marked as being already loaded isLoaded = false; } superLoad(null); // manually send the notification eSetDeliver(true); EObject result = getParseResult().getRootASTElement(); if (myContents.isEmpty()) { myContents.sneakyAdd(0, result); if (oldModule != null) { myContents.sneakyAdd(oldModule); } forceInstallDerivedState(false); } else { if (myContents.size() == 1) { if (oldModule != null) { myContents.sneakyAdd(oldModule); } } installDerivedState(false); } if (oldScript != null) { notifyProxyResolved(0, oldScript); } fullyPostProcessed = false; return result; } catch (IOException | IllegalStateException ioe) { if (myContents.isEmpty()) { myContents.sneakyAdd(oldScript); myContents.sneakyAdd(oldModule); } Throwable cause = ioe.getCause(); if (cause instanceof CoreException) { IStatus status = ((CoreException) cause).getStatus(); if (IResourceStatus.RESOURCE_NOT_FOUND == status.getCode()) { return object; } } logger.error("Error in demandLoadResource for " + getURI(), ioe); return object; } }
Example 16
Source File: SourceAttachmentPropertyPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private Control createPageContent(Composite composite) { try { fContainerPath= null; fEntry= null; fRoot= getJARPackageFragmentRoot(); if (fRoot == null || fRoot.getKind() != IPackageFragmentRoot.K_BINARY) { return createMessageContent(composite, PreferencesMessages.SourceAttachmentPropertyPage_noarchive_message, null); } IPath containerPath= null; IJavaProject jproject= fRoot.getJavaProject(); IClasspathEntry entry= JavaModelUtil.getClasspathEntry(fRoot); boolean canEditEncoding= true; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { containerPath= entry.getPath(); ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0)); IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject); if (initializer == null || container == null) { return createMessageContent(composite, Messages.format(PreferencesMessages.SourceAttachmentPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)), fRoot); } String containerName= container.getDescription(); IStatus status= initializer.getSourceAttachmentStatus(containerPath, jproject); if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) { return createMessageContent(composite, Messages.format(PreferencesMessages.SourceAttachmentPropertyPage_not_supported, containerName), null); } if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) { return createMessageContent(composite, Messages.format(PreferencesMessages.SourceAttachmentPropertyPage_read_only, containerName), fRoot); } IStatus attributeStatus= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING); canEditEncoding= !(attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED || attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY); entry= JavaModelUtil.findEntryInContainer(container, fRoot.getPath()); } fContainerPath= containerPath; fEntry= entry; fSourceAttachmentBlock= new SourceAttachmentBlock(this, entry, canEditEncoding); return fSourceAttachmentBlock.createControl(composite); } catch (CoreException e) { JavaPlugin.log(e); return createMessageContent(composite, PreferencesMessages.SourceAttachmentPropertyPage_noarchive_message, null); } }
Example 17
Source File: ClassFileEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void createSourceAttachmentControls(Composite composite, IPackageFragmentRoot root) throws JavaModelException { IClasspathEntry entry; try { entry= JavaModelUtil.getClasspathEntry(root); } catch (JavaModelException ex) { if (ex.isDoesNotExist()) entry= null; else throw ex; } IPath containerPath= null; if (entry == null || root.getKind() != IPackageFragmentRoot.K_BINARY) { createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSource, BasicElementLabels.getFileName( fFile))); return; } IJavaProject jproject= root.getJavaProject(); boolean canEditEncoding= true; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { containerPath= entry.getPath(); ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0)); IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject); if (initializer == null || container == null) { createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_cannotconfigure, BasicElementLabels.getPathLabel(containerPath, false))); return; } String containerName= container.getDescription(); IStatus status= initializer.getSourceAttachmentStatus(containerPath, jproject); if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) { createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_notsupported, containerName)); return; } if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) { createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_readonly, containerName)); return; } IStatus attributeStatus= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING); canEditEncoding= !(attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED || attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY); entry= JavaModelUtil.findEntryInContainer(container, root.getPath()); Assert.isNotNull(entry); } Button button; IPath path= entry.getSourceAttachmentPath(); if (path == null || path.isEmpty()) { String rootLabel= JavaElementLabels.getElementLabel(root, JavaElementLabels.ALL_DEFAULT); createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSourceAttachment, rootLabel)); createLabel(composite, JavaEditorMessages.SourceAttachmentForm_message_pressButtonToAttach); createLabel(composite, null); button= createButton(composite, JavaEditorMessages.SourceAttachmentForm_button_attachSource); } else { createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSourceInAttachment, BasicElementLabels.getFileName(fFile))); createLabel(composite, JavaEditorMessages.SourceAttachmentForm_message_pressButtonToChange); createLabel(composite, null); button= createButton(composite, JavaEditorMessages.SourceAttachmentForm_button_changeAttachedSource); } button.addSelectionListener(getButtonListener(entry, containerPath, jproject, canEditEncoding)); }
Example 18
Source File: SVNAction.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * Method that implements generic handling of an exception. * * Thsi method will also use any accumulated status when determining what * information (if any) to show the user. * * @param exception the exception that occured (or null if none occured) * @param status any status accumulated by the action before the end of * the action or the exception occured. */ protected void handle(Exception exception) { if (exception instanceof SVNException) { if (((SVNException)exception).operationInterrupted()) { return; } } // Get the non-OK statii List problems = new ArrayList(); IStatus[] status = getAccumulatedStatus(); if (status != null) { for (int i = 0; i < status.length; i++) { IStatus iStatus = status[i]; if ( ! iStatus.isOK() || iStatus.getCode() == SVNStatus.SERVER_ERROR) { problems.add(iStatus); } } } // Handle the case where there are no problem statii if (problems.size() == 0) { if (exception == null) return; handle(exception, getErrorTitle(), null); return; } // For now, display both the exception and the problem status // Later, we can determine how to display both together if (exception != null) { handle(exception, getErrorTitle(), null); } String message = null; IStatus statusToDisplay = getStatusToDisplay((IStatus[]) problems.toArray(new IStatus[problems.size()])); if (statusToDisplay.isOK()) return; if (statusToDisplay.isMultiStatus() && statusToDisplay.getChildren().length == 1) { message = statusToDisplay.getMessage(); statusToDisplay = statusToDisplay.getChildren()[0]; } String title; if (statusToDisplay.getSeverity() == IStatus.ERROR) { title = getErrorTitle(); } else { title = getWarningTitle(); } SVNUIPlugin.openError(getShell(), title, message, new SVNException(statusToDisplay)); }
Example 19
Source File: ElexisStatus.java From elexis-3-core with Eclipse Public License 1.0 | 4 votes |
public ElexisStatus(IStatus status){ super(status.getSeverity(), status.getPlugin(), status.getCode(), status.getMessage(), status.getException()); }
Example 20
Source File: NewFolderDialogOfHs.java From translationstudio8 with GNU General Public License v2.0 | votes |
/** * Update the dialog's status line to reflect the given status. It is safe to call * this method before the dialog has been opened. */ protected void updateStatus(IStatus status) { if (firstLinkCheck && status != null) { // don't show the first validation result as an error. // fixes bug 29659 Status newStatus = new Status(IStatus.OK, status.getPlugin(), status.getCode(), status.getMessage(), status .getException()); super.updateStatus(newStatus); } else { super.updateStatus(status); } }