diff --git a/plugins/contracts/org.polarsys.chess.contracts.profile/src/org/polarsys/chess/contracts/profile/chesscontract/util/EntityUtil.java b/plugins/contracts/org.polarsys.chess.contracts.profile/src/org/polarsys/chess/contracts/profile/chesscontract/util/EntityUtil.java index 4e427c70e03301d45fcd90f64622697f330b2f45..1f72d3090ac97a559d25291cdf67b4b362e4e1a5 100644 --- a/plugins/contracts/org.polarsys.chess.contracts.profile/src/org/polarsys/chess/contracts/profile/chesscontract/util/EntityUtil.java +++ b/plugins/contracts/org.polarsys.chess.contracts.profile/src/org/polarsys/chess/contracts/profile/chesscontract/util/EntityUtil.java @@ -1836,6 +1836,14 @@ public class EntityUtil { return transitions; } + public EList<Transition> getOutgoingTransitions(Vertex state) { + return state.getOutgoings(); + } + + public EList<Transition> getIncomingTransitions(Vertex state) { + return state.getIncomings(); + } + public String getSignalEventName(Trigger trigger) { if (trigger.getEvent() instanceof SignalEvent) { diff --git a/plugins/org.polarsys.chess.service/src/org/polarsys/chess/service/gui/utils/ReportProblemsUtil.java b/plugins/org.polarsys.chess.service/src/org/polarsys/chess/service/gui/utils/ReportProblemsUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..c28272cdb26dc96e58b6e5ccc0bcc3a262b45cdb --- /dev/null +++ b/plugins/org.polarsys.chess.service/src/org/polarsys/chess/service/gui/utils/ReportProblemsUtil.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (C) 2020 Fondazione Bruno Kessler. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Luca Cristoforetti - initial API and implementation + ******************************************************************************/ +package org.polarsys.chess.service.gui.utils; + +import java.util.HashMap; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; + +/** + * An utility class to post messages to the Problems tab. + * + * @author cristofo + * + */ +public class ReportProblemsUtil { + + /** + * Deletes all markers on this resource. + * @param resource the resource + * @throws CoreException + */ + public static void cleanResource(IResource resource) throws CoreException { + resource.deleteMarkers(null, true, IResource.DEPTH_INFINITE); + } + + /** + * Reports a warning in the Problems tab. + * @param resource the resource + * @param msg the message to display + * @param lineNumber the line to select (or 0) + * @param charStart the start of selection (or 0) + * @param charEnd the end of seletion (or 0) + * @return the created IMarker + * @throws CoreException + * @throws NullPointerException + */ + public static IMarker reportWarning(IResource resource, String msg, int lineNumber, + int charStart, int charEnd) throws CoreException, NullPointerException { + return reportMessage(resource, msg, lineNumber, charStart, charEnd, + IMarker.PROBLEM, IMarker.SEVERITY_WARNING); + } + + /** + * Reports an error in the Problems tab. + * @param resource the resource + * @param msg the message to display + * @param lineNumber the line to select (or 0) + * @param charStart the start of selection (or 0) + * @param charEnd the end of seletion (or 0) + * @return the created IMarker + * @throws CoreException + * @throws NullPointerException + */ + public static IMarker reportError(IResource resource, String msg, int lineNumber, + int charStart, int charEnd) throws CoreException, NullPointerException { + return reportMessage(resource, msg, lineNumber, charStart, charEnd, + IMarker.PROBLEM, IMarker.SEVERITY_ERROR); + } + + /** + * Reports an info in the Problems tab. + * @param resource the resource + * @param msg the message to display + * @param lineNumber the line to select (or 0) + * @param charStart the start of selection (or 0) + * @param charEnd the end of seletion (or 0) + * @return the created IMarker + * @throws CoreException + * @throws NullPointerException + */ + public static IMarker reportInfo(IResource resource, String msg, int lineNumber, + int charStart, int charEnd) throws CoreException, NullPointerException { + return reportMessage(resource, msg, lineNumber, charStart, charEnd, + IMarker.PROBLEM, IMarker.SEVERITY_INFO); + } + + private static IMarker reportMessage(IResource resource, String msg, int lineNumber, int charStart, + int charEnd, String type, int severity) throws CoreException, NullPointerException { + if (resource == null) { + throw new NullPointerException("Resource is null"); + } + + IMarker m = resource.createMarker(type); + + HashMap<String, Object> attributes = new HashMap<String, Object>(); + attributes.put(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_HIGH)); + attributes.put(IMarker.SEVERITY, new Integer(severity)); + if (lineNumber > 0) attributes.put(IMarker.LINE_NUMBER, new Integer(lineNumber)); + attributes.put(IMarker.MESSAGE, msg); + if (charStart > 0) attributes.put(IMarker.CHAR_START, new Integer(charStart)); // Note: this value is from the beginning of the document + if (charEnd > 0) attributes.put(IMarker.CHAR_END, new Integer(charEnd)); // Note: this value is from the beginning of the document +// m.setAttribute(IMarker.LOCATION, "whole file"); // This is a generic info about location + + m.setAttributes(attributes); + return m; + } +}