Skip to content

Commit

Permalink
Resolved github issue #772
Browse files Browse the repository at this point in the history
  • Loading branch information
rensink committed Jun 25, 2024
1 parent 80e9ce3 commit 3cc71b5
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 87 deletions.
2 changes: 1 addition & 1 deletion launch/GROOVE - build maven artifact.launch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<booleanAttribute key="M2_OFFLINE" value="false"/>
<stringAttribute key="M2_PROFILES" value=""/>
<listAttribute key="M2_PROPERTIES">
<listEntry value="revision=${string_prompt:Build version}"/>
<listEntry value="revision=${string_prompt:Build version:x.y.z}"/>
</listAttribute>
<stringAttribute key="M2_RUNTIME" value="EMBEDDED"/>
<booleanAttribute key="M2_SKIP_TESTS" value="false"/>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<version>1.7.0</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ void notifyWillRebuild() {

/** Adds a control program-related error. */
private void addPartError(FormatError error) {
QualName key = error.getResourceKind() == CONTROL
? error.getResourceName()
: null;
getPartErrors(key).add(error);
error.getResourceNames().forEach(k -> getPartErrors(k).add(error));
}

/** Collects and returns all errors found in the partial control models. */
Expand Down
41 changes: 28 additions & 13 deletions src/main/java/nl/utwente/groove/grammar/model/GrammarModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -220,21 +221,35 @@ public String getText(ResourceKind kind, QualName name) {
: resource.getSource();
}

/** Returns the list of active graphs of a given resource kind, alphabetically ordered by (qualified) name. */
public List<AspectGraph> getActiveGraphs(ResourceKind kind) {
List<AspectGraph> result = new ArrayList<>();
getActiveNames(kind).stream().map(n -> getGraph(kind, n)).forEach(result::add);
return result;
}

/** Returns the list of active texts of a given resource kind, alphabetically ordered by (qualified) name. */
public List<String> getActiveTexts(ResourceKind kind) {
List<String> result = new ArrayList<>();
getActiveNames(kind).stream().map(n -> getText(kind, n)).forEach(result::add);
return result;
}

/**
* Returns the set of resource names of the active resources of a given kind.
* These are the names stored as active, but can be overridden locally in
* the grammar model.
* @see #setLocalActiveNames(ResourceKind, Collection)
*/
public Set<QualName> getActiveNames(ResourceKind kind) {
public SortedSet<QualName> getActiveNames(ResourceKind kind) {
// first check for locally stored names
Set<QualName> result = this.localActiveNamesMap.get(kind);
SortedSet<QualName> result = this.localActiveNamesMap.get(kind);
if (result == null) {
// if there are none, check for active names in the store
result = this.storedActiveNamesMap.get(kind);
}
result.retainAll(getNames(kind));
return Collections.unmodifiableSet(result);
return Collections.unmodifiableSortedSet(result);
}

/**
Expand Down Expand Up @@ -374,14 +389,9 @@ public TypeGraph getTypeGraph() {
* @return the start graph model, or <code>null</code> if no start graph is
* set.
*/

public HostModel getStartGraphModel() {
if (this.startGraphModel == null) {
TreeMap<QualName,AspectGraph> graphMap = new TreeMap<>();
for (QualName name : getActiveNames(HOST)) {
graphMap.put(name, getStore().getGraphs(HOST).get(name));
}
AspectGraph startGraph = AspectGraph.mergeGraphs(graphMap.values());
AspectGraph startGraph = AspectGraph.mergeGraphs(getActiveGraphs(HOST));
if (startGraph != null) {
this.startGraphModel = new HostModel(this, startGraph);
}
Expand Down Expand Up @@ -537,8 +547,9 @@ private Grammar computeGrammar() throws FormatException {
errors.addAll(e.getErrors());
}
// set start graph
if (getStartGraphModel() == null) {
Set<QualName> startGraphNames = getActiveNames(HOST);
var startGraphNames = getActiveNames(HOST);
var startGraphModel = getStartGraphModel();
if (startGraphModel == null) {
if (startGraphNames.isEmpty()) {
errors.add("No start graph set");
} else {
Expand All @@ -547,14 +558,18 @@ private Grammar computeGrammar() throws FormatException {
} else {
FormatErrorSet startGraphErrors;
try {
HostGraph startGraph = getStartGraphModel().toResource();
HostGraph startGraph = startGraphModel.toResource();
result.setStartGraph(startGraph);
startGraphErrors = startGraph.getErrors();
} catch (FormatException exc) {
startGraphErrors = exc.getErrors();
}
String prefix = startGraphNames.size() > 1
? "combined start graph"
: "start graph '" + startGraphModel.getName() + "'";
var activeHostGraphs = getActiveGraphs(HOST);
for (FormatError error : startGraphErrors) {
errors.add(error, getStartGraphModel().getSource());
errors.add("Error in %s: %s", prefix, error, activeHostGraphs);
}
}
// Set the Prolog environment.
Expand Down
45 changes: 23 additions & 22 deletions src/main/java/nl/utwente/groove/gui/Simulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@

import apple.dts.samplecode.osxadapter.OSXAdapter;
import nl.utwente.groove.grammar.GrammarKey;
import nl.utwente.groove.grammar.QualName;
import nl.utwente.groove.grammar.model.GrammarModel;
import nl.utwente.groove.grammar.model.ResourceKind;
import nl.utwente.groove.gui.SimulatorModel.Change;
Expand All @@ -86,7 +85,6 @@
import nl.utwente.groove.gui.display.GraphTab;
import nl.utwente.groove.gui.display.JGraphPanel;
import nl.utwente.groove.gui.display.ResourceDisplay;
import nl.utwente.groove.gui.display.ResourceTab;
import nl.utwente.groove.gui.display.TextTab;
import nl.utwente.groove.gui.jgraph.AspectJGraph;
import nl.utwente.groove.gui.jgraph.JGraph;
Expand Down Expand Up @@ -434,31 +432,34 @@ public void propertyChange(PropertyChangeEvent evt) {
*/
private void selectDisplayPart(SelectableListEntry entry) {
ResourceKind resource = entry.getResourceKind();
QualName name = entry.getResourceName();
var names = entry.getResourceNames();
Display display = getDisplaysPanel().getDisplayFor(resource);
if (resource == ResourceKind.PROPERTIES) {
assert names.size() == 1;
var name = names.first();
GrammarKey key = GrammarKey.getKey(name.toString()).get();
Display display = getDisplaysPanel().getDisplayFor(resource);
ListPanel panel = display.getListPanel();
getDisplaysPanel().getUpperListsPanel().setSelectedComponent(panel);
((PropertiesTable) panel.getList()).setSelected(key);
} else if (resource != null) {
getModel().doSelect(resource, name);
ResourceDisplay display = (ResourceDisplay) getDisplaysPanel().getDisplayFor(resource);
ResourceTab resourceTab = display.getSelectedTab();
if (resource.isGraphBased()) {
AspectJGraph jGraph;
if (resourceTab.isEditor()) {
jGraph = ((GraphEditorTab) resourceTab).getJGraph();
} else {
jGraph = ((GraphTab) resourceTab).getJGraph();
}
// select the error cell and switch to the panel
jGraph.setSelectionCells(entry.getElements());
} else if (entry instanceof FormatError error) {
if (error.getNumbers().size() > 1) {
int line = error.getNumbers().get(0);
int column = error.getNumbers().get(1);
((TextTab) resourceTab).select(line, column);
} else if (resource != null && display instanceof ResourceDisplay resourceDisplay) {
getModel().doSelectSet(resource, names);
var resourceTab = resourceDisplay.getSelectedTab();
if (resourceTab != null) {
if (resource.isGraphBased()) {
AspectJGraph jGraph;
if (resourceTab.isEditor()) {
jGraph = ((GraphEditorTab) resourceTab).getJGraph();
} else {
jGraph = ((GraphTab) resourceTab).getJGraph();
}
// select the error cell and switch to the panel
jGraph.setSelectionCells(entry.getElements());
} else if (entry instanceof FormatError error) {
if (error.getNumbers().size() > 1) {
int line = error.getNumbers().get(0);
int column = error.getNumbers().get(1);
((TextTab) resourceTab).select(line, column);
}
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/nl/utwente/groove/gui/SimulatorModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1075,12 +1075,10 @@ public final Set<QualName> getSelectSet(ResourceKind kind) {

/** Changes the selection of a given resource kind. */
public final boolean doSelect(ResourceKind kind, QualName name) {
start();
changeSelected(kind, name);
if (isSelected(kind) || kind == ResourceKind.HOST && hasState()) {
changeDisplay(DisplayKind.toDisplay(kind));
}
return finish();
var names = name == null
? Collections.<QualName>emptySet()
: Collections.singleton(name);
return doSelectSet(kind, names);
}

/**
Expand All @@ -1092,6 +1090,9 @@ public final boolean doSelectSet(ResourceKind kind, Collection<QualName> names)
changeMatch(null);
changeTransition(null);
}
if (isSelected(kind) || kind == ResourceKind.HOST && hasState()) {
changeDisplay(DisplayKind.toDisplay(kind));
}
return finish();
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/nl/utwente/groove/gui/list/ListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.beans.PropertyChangeListener;
import java.util.Collection;
import java.util.Collections;
import java.util.SortedSet;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
Expand Down Expand Up @@ -207,7 +208,7 @@ public interface SelectableListEntry {
public ResourceKind getResourceKind();

/** Returns the resource name for which this entry occurs. */
public QualName getResourceName();
public SortedSet<QualName> getResourceNames();

/** Returns the list of elements in which the entry occurs. May be empty. */
public Collection<Element> getElements();
Expand Down
41 changes: 28 additions & 13 deletions src/main/java/nl/utwente/groove/gui/list/SearchResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

import nl.utwente.groove.grammar.QualName;
import nl.utwente.groove.grammar.aspect.AspectGraph;
Expand Down Expand Up @@ -55,8 +57,8 @@ public SearchResult(String message, Object... pars) {
private void addContext(Object par) {
if (par instanceof AspectGraph) {
this.graph = (AspectGraph) par;
this.resourceName = this.graph.getQualName();
this.resourceKind = ResourceKind.toResource(this.graph.getRole());
this.resourceNames.add(this.graph.getQualName());
setResourceKind(ResourceKind.toResource(this.graph.getRole()));
} else if (par instanceof Element) {
this.elements.add((Element) par);
} else if (par instanceof Object[]) {
Expand Down Expand Up @@ -88,38 +90,51 @@ public String toString() {
return this.message;
}

/** The result message. */
private final String message;

/** Returns the graph in which the error occurs. May be {@code null}. */
public final AspectGraph getGraph() {
return this.graph;
}

/** The graph in which the result occurs. */
private AspectGraph graph;

/** Returns the list of elements in which the error occurs. May be empty. */
@Override
public final Collection<Element> getElements() {
return this.elements;
}

/** List of result elements. */
private final List<Element> elements = new ArrayList<>();

/**
* Sets the resource kind field, checking if the new value is not not in conflict
* with any existing value.
*/
private final void setResourceKind(ResourceKind kind) {
assert this.resourceKind == null || this.resourceKind == kind;
this.resourceKind = kind;
}

/** Returns the resource kind for which this error occurs. */
@Override
public final ResourceKind getResourceKind() {
return this.resourceKind;
}

/** The resource kind for which the result occurs. May be {@code null}. */
private ResourceKind resourceKind;

/** Returns the resource name for which this error occurs. */
@Override
public final QualName getResourceName() {
return this.resourceName;
public final SortedSet<QualName> getResourceNames() {
return this.resourceNames;
}

/** The graph in which the result occurs. */
private AspectGraph graph;
/** The resource kind for which the result occurs. May be {@code null}. */
private ResourceKind resourceKind;
/** The name of the resource on which the result occurs. May be {@code null}. */
private QualName resourceName;
/** List of result elements. */
private final List<Element> elements = new ArrayList<>();
/** The result message. */
private final String message;
private final SortedSet<QualName> resourceNames = new TreeSet<>();

}
6 changes: 3 additions & 3 deletions src/main/java/nl/utwente/groove/gui/tree/ResourceTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ public void update(SimulatorModel source, SimulatorModel oldModel, Set<Change> c
refresh(source.getState());
}
} else if (changes.contains(Change.toChange(getResourceKind()))) {
var model = source.getResource(getResourceKind()).getQualName();
for (int i = 0; i < getRowCount(); i++) {
var model = source.getResource(getResourceKind());
for (int i = 0; model != null && i < getRowCount(); i++) {
TreePath path = getPathForRow(i);
TreeNode node = (TreeNode) path.getLastPathComponent();
if (node instanceof ResourceTreeNode rnode
&& rnode.getQualName().equals(model)) {
&& rnode.getQualName().equals(model.getQualName())) {
setSelectionPath(path);
break;
}
Expand Down
Loading

0 comments on commit 3cc71b5

Please sign in to comment.