Java Code Examples for org.eclipse.core.runtime.IStatus#getChildren()

The following examples show how to use org.eclipse.core.runtime.IStatus#getChildren() . 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: StatusUtil.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a string representation of a given status by collecting all the messages and put each one in a line of
 * its own. Note that this is most useful when dealing with {@link MultiStatus} instances.<br>
 * The class recursively drill down and collect all messages. Even from a nested {@link MultiStatus} children of the
 * given status.
 * 
 * @param status
 * @return A string representation containing all the statuses messages.
 */
public static String toString(IStatus status)
{
	StringBuilder builder = new StringBuilder(status.getMessage());
	IStatus[] children = status.getChildren();
	if (!ArrayUtil.isEmpty(children))
	{
		builder.append(FileUtil.NEW_LINE);
		for (IStatus child : children)
		{
			if (child.isMultiStatus())
			{
				// make a recursive call
				builder.append(toString(child));
			}
			else
			{
				builder.append(child.getMessage());
			}
			builder.append(FileUtil.NEW_LINE);
		}
	}
	return builder.toString();
}
 
Example 2
Source File: ResourceDropAdapterAssistant.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Opens an error dialog if necessary. Takes care of complex rules necessary
 * for making the error dialog look nice.
 */
private void openError(IStatus status) {
	if (status == null) {
		return;
	}

	String genericTitle = WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_title;
	int codes = IStatus.ERROR | IStatus.WARNING;

	// simple case: one error, not a multistatus
	if (!status.isMultiStatus()) {
		ErrorDialog
				.openError(getShell(), genericTitle, null, status, codes);
		return;
	}

	// one error, single child of multistatus
	IStatus[] children = status.getChildren();
	if (children.length == 1) {
		ErrorDialog.openError(getShell(), status.getMessage(), null,
				children[0], codes);
		return;
	}
	// several problems
	ErrorDialog.openError(getShell(), genericTitle, null, status, codes);
}
 
Example 3
Source File: AbstractLiveValidationMarkerConstraint.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private static Set<EObject> collectTargetElements(final IStatus status,
        final Set<EObject> targetElementCollector, final List allConstraintStatuses) {
    if (status instanceof IConstraintStatus) {
        targetElementCollector
                .add(((IConstraintStatus) status).getTarget());
        allConstraintStatuses.add(status);
    }
    if (status.isMultiStatus()) {
        final IStatus[] children = status.getChildren();
        for (int i = 0; i < children.length; i++) {
            collectTargetElements(children[i], targetElementCollector,
                    allConstraintStatuses);
        }
    }
    return targetElementCollector;
}
 
Example 4
Source File: StatusUtil.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Return a simplified status by discarding all OK child statuses.
 */
public static IStatus filter(IStatus status) {
  if (!status.isMultiStatus()) {
    return status;
  } else if (status.isOK()) {
    // return OK_STATUS to avoids oddities like Progress View showing the MultiStatus's
    // error message
    return Status.OK_STATUS;
  }
  MultiStatus newStatus = new MultiStatus(status.getPlugin(), status.getCode(),
      status.getMessage(), status.getException());
  for (IStatus child : status.getChildren()) {
    if (!child.isOK()) {
      newStatus.add(filter(child));
    }
  }
  return newStatus;
}
 
Example 5
Source File: ModelEditor.java    From tlaplus with MIT License 6 votes vote down vote up
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 6
Source File: ExpressionViewerValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected IStatus updateMessage(final IStatus status) {
    String message = status.getMessage();
    if (!status.isOK()) {
        if (status instanceof MultiStatus) {
            final StringBuilder sb = new StringBuilder();
            for (final IStatus statusChild : status.getChildren()) {
                sb.append(statusChild.getMessage());
                sb.append("\n");
            }
            if (sb.length() > 0) {
                sb.delete(sb.length() - 1, sb.length());
            }
            message = sb.toString();
            return ValidationStatus.error(message);
        }
    }
    return status;

}
 
Example 7
Source File: ExportBarWizard.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private boolean statusContainsError(IStatus validationStatus) {
	if(validationStatus != null){
		if(validationStatus.getChildren().length > 0){
			for(IStatus s : validationStatus.getChildren()){
				if(s.getSeverity() == IStatus.WARNING || s.getSeverity() == IStatus.ERROR){
					return true;
				}
			}
		}else{
			return validationStatus.getSeverity() == IStatus.WARNING || validationStatus.getSeverity() == IStatus.ERROR;
		}
	}
	return false;
}
 
Example 8
Source File: BatchValidationHandler.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private boolean statusContainsError(final IStatus validationStatus) {
    if (validationStatus != null) {
        for (final IStatus s : validationStatus.getChildren()) {
            if (s.getSeverity() == IStatus.ERROR) {
                return true;
            }
        }
    }
    return false;
}
 
Example 9
Source File: ExchangeException.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
static public void printChildren(IStatus status, PrintStream output){
	IStatus[] children = status.getChildren();
	if (children == null || children.length == 0)
		return;
	for (int i = 0; i < children.length; i++) {
		output.println("Contains: " + children[i].getMessage()); //$NON-NLS-1$
		Throwable exception = children[i].getException();
		if (exception != null)
			exception.printStackTrace(output);
		printChildren(children[i], output);
	}
}
 
Example 10
Source File: ExceptionDetailsDialog.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Append CommandStatus.
 * 
 * @param writer
 *            the writer
 * @param CommandStatus
 *            the CommandStatus
 * @param nesting
 *            the nesting
 */
private static void appendCommandStatus(final PrintWriter writer, final IStatus CommandStatus, final int nesting) {
	for (int i = 0; i < nesting; i++) {
		writer.print("  ");
	}
	writer.println(CommandStatus.getMessage());
	final IStatus[] children = CommandStatus.getChildren();
	for (int i = 0; i < children.length; i++) {
		appendCommandStatus(writer, children[i], nesting + 1);
	}
}
 
Example 11
Source File: URIsInEcoreFilesXtendTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void appendLeafs(IStatus status, StringBuilder result) {
	if (status.isOK()) {
		return;
	}
	result.append(status.getMessage()).append('\n');
	IStatus[] children = status.getChildren();
	for(IStatus child: children) {
		appendLeafs(child, result);
	}
}
 
Example 12
Source File: AbstractPortableURIsTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void appendLeafs(IStatus status, StringBuilder result) {
	if (status.isOK()) {
		return;
	}
	result.append(status.getMessage()).append('\n');
	IStatus[] children = status.getChildren();
	for(IStatus child: children) {
		appendLeafs(child, result);
	}
}
 
Example 13
Source File: ValidationMarkerProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private static Set<EObject> collectTargetElements(final IStatus status,
        final Set<EObject> targetElementCollector, final List allConstraintStatuses) {
    if (status instanceof IConstraintStatus) {
        targetElementCollector.add(((IConstraintStatus) status).getTarget());
        allConstraintStatuses.add(status);
    }
    if (status.isMultiStatus()) {
        final IStatus[] children = status.getChildren();
        for (int i = 0; i < children.length; i++) {
            collectTargetElements(children[i], targetElementCollector, allConstraintStatuses);
        }
    }
    return targetElementCollector;
}
 
Example 14
Source File: PersistenceException.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
static public void printChildren(IStatus status, PrintWriter output){
	IStatus[] children = status.getChildren();
	if (children == null || children.length == 0)
		return;
	for (int i = 0; i < children.length; i++) {
		output.println("Contains: " + children[i].getMessage()); //$NON-NLS-1$
		output.flush(); // call to synchronize output
		Throwable exception = children[i].getException();
		if (exception != null)
			exception.printStackTrace(output);
		printChildren(children[i], output);
	}
}
 
Example 15
Source File: ValidationTestBase.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void collectStatuses(final IStatus status, final List<IStatus> statuses) {
    if (status.isMultiStatus()) {
        final IStatus[] children = status.getChildren();

        for (final IStatus element : children) {
            collectStatuses(element, statuses);
        }
    } else {
        statuses.add(status);
    }
}
 
Example 16
Source File: ScriptingException.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
static public void printChildren(IStatus status, PrintWriter output){
	IStatus[] children = status.getChildren();
	if (children == null || children.length == 0)
		return;
	for (int i = 0; i < children.length; i++) {
		output.println("Contains: " + children[i].getMessage()); //$NON-NLS-1$
		output.flush(); // call to synchronize output
		Throwable exception = children[i].getException();
		if (exception != null)
			exception.printStackTrace(output);
		printChildren(children[i], output);
	}
}
 
Example 17
Source File: ValidateAction.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
private static Set<EObject> collectTargetElements(IStatus status, Set<EObject> targetElementCollector,
		List allConstraintStatuses) {
	if (status instanceof IConstraintStatus) {
		targetElementCollector.add(((IConstraintStatus) status).getTarget());
		allConstraintStatuses.add(status);
	}
	if (status.isMultiStatus()) {
		IStatus[] children = status.getChildren();
		for (int i = 0; i < children.length; i++) {
			collectTargetElements(children[i], targetElementCollector, allConstraintStatuses);
		}
	}
	return targetElementCollector;
}
 
Example 18
Source File: NpmLogger.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Dispatches given status with {@link Logger#error} and to the {@code STD_ERR} of used output stream. If provided
 * status {@link IStatus#getChildren() has children} it will log them recursively.
 */
public void logError(final IStatus status) {
	logError(status.getMessage(), status.getException());
	final IStatus[] children = status.getChildren();
	if (!Arrays2.isEmpty(children)) {
		for (final IStatus child : children) {
			logError(child);
		}
	}
}
 
Example 19
Source File: CtfTmfTraceTrimmingTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Test setup
 *
 * @throws IOException
 *             failed to load the file
 * @throws TmfTraceException
 *             failed to load the trace
 */
@Before
public void setup() throws IOException, TmfTraceException {
    fOriginalTrace = CtfTmfTestTraceUtils.getTrace(fTestTrace);
    openTrace(fOriginalTrace);

    TmfTimeRange traceCutRange = getTraceCutRange(fOriginalTrace);
    assertNotNull(traceCutRange);
    fRequestedTraceCutRange = traceCutRange;

    ITmfTimestamp requestedTraceCutEnd = traceCutRange.getEndTime();
    ITmfTimestamp requestedTraceCutStart = traceCutRange.getStartTime();
    assertTrue(fOriginalTrace.getTimeRange().contains(traceCutRange));

    TmfTimeRange range = new TmfTimeRange(
            requestedTraceCutStart,
            requestedTraceCutEnd);
    try {
        /* Perform the trim to create the new trace */
        Path newTracePath = Files.createTempDirectory("trimmed-trace-test" + fTestTrace.name());
        fNewTracePath = newTracePath;
        assertNotNull(newTracePath);
        fNewTracePath.toFile().delete();
        fOriginalTrace.trim(range, newTracePath, new NullProgressMonitor());

        /* Initialize the new trace */
        fNewTrace = new CtfTmfTrace();
        fNewTrace.initTrace(null, newTracePath.toString(), CtfTmfEvent.class);
        openTrace(fNewTrace);

    } catch (CoreException e) {
        /*
         * CoreException are more or less useless, all the interesting stuff is in their
         * "status" objects.
         */
        String msg;
        IStatus status = e.getStatus();
        IStatus[] children = status.getChildren();
        if (children == null) {
            msg = status.getMessage();
        } else {
            msg = Arrays.stream(children)
                    .map(IStatus::getMessage)
                    .collect(Collectors.joining("\n"));
        }
        fail(msg);
    }
}
 
Example 20
Source File: SVNAction.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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));
}