Skip to content

Commit

Permalink
Functionality to switch to an erroneous graph property (gh issue #783)
Browse files Browse the repository at this point in the history
  • Loading branch information
rensink committed Jul 10, 2024
1 parent 9b303a8 commit e529eb0
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 38 deletions.
6 changes: 4 additions & 2 deletions src/main/java/nl/utwente/groove/graph/GraphProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public CheckerMap getCheckers(final AspectGraph graph) {
try {
return key.check(graph, key.parse(v));
} catch (FormatException exc) {
return exc.getErrors();
return exc.getErrors().extend(key);
}
};
result.put(key, checker);
Expand Down Expand Up @@ -295,7 +295,9 @@ default public FormatErrorSet check(AspectGraph graph, Entry value) {
try {
String.format(formatString, args);
} catch (IllegalFormatException exc) {
result.add("Format '%s' expects more than %s parameters", formatString, maxPar, g);
result
.add("Rule has %s parameters, but format string '%s' expects more", maxPar,
formatString, g);
}
return result;
};
Expand Down
1 change: 1 addition & 0 deletions src/main/java/nl/utwente/groove/gui/Simulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ private void selectDisplayPart(SelectableListEntry entry) {
}
// select the error cell and switch to the panel
jGraph.setSelectionCells(entry.getElements());
resourceTab.setPropertyKey(entry.getPropertyKey());
} else if (entry instanceof FormatError error) {
if (error.getNumbers().size() > 1) {
int line = error.getNumbers().get(0);
Expand Down
42 changes: 27 additions & 15 deletions src/main/java/nl/utwente/groove/gui/display/GraphEditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import javax.swing.event.UndoableEditEvent;
import javax.swing.undo.UndoableEdit;

import org.eclipse.jdt.annotation.NonNull;
import org.jgraph.event.GraphModelEvent;
import org.jgraph.event.GraphModelEvent.GraphModelChange;
import org.jgraph.event.GraphModelListener;
Expand All @@ -73,6 +74,7 @@
import nl.utwente.groove.graph.EdgeRole;
import nl.utwente.groove.graph.GraphInfo;
import nl.utwente.groove.graph.GraphProperties;
import nl.utwente.groove.graph.GraphProperties.Key;
import nl.utwente.groove.graph.GraphRole;
import nl.utwente.groove.gui.Icons;
import nl.utwente.groove.gui.LongToolTipAdapter;
Expand Down Expand Up @@ -324,13 +326,12 @@ private void loadProperties(AspectGraph newGraph, boolean updatePropertiesPanel)
}

@Override
public boolean setResource(QualName name) {
throw new UnsupportedOperationException();
}

@Override
public boolean removeResource(QualName name) {
throw new UnsupportedOperationException();
public void setPropertyKey(Key propertyKey) {
var upperInfoPanel = getUpperInfoPanel();
if (upperInfoPanel != null && propertyKey != null) {
upperInfoPanel.setSelectedComponent(getPropertiesScrollPanel());
getPropertiesPanel().setSelected(propertyKey);
}
}

@Override
Expand Down Expand Up @@ -455,13 +456,10 @@ protected JTabbedPane getUpperInfoPanel() {
this.upperInfoPanel = result = new JTabbedPane();
result.add(getLabelPanel());
if (getResourceKind().hasProperties()) {
JComponent propertiesPanel = getPropertiesPanel();
JScrollPane scrollPanel = new JScrollPane(propertiesPanel);
scrollPanel.setName(propertiesPanel.getName());
scrollPanel.getViewport().setBackground(propertiesPanel.getBackground());
result.add(scrollPanel);
int index = result.indexOfComponent(scrollPanel);
this.propertiesHeader.setText(scrollPanel.getName());
var propertiesPanel = getPropertiesScrollPanel();
result.add(propertiesPanel);
int index = result.indexOfComponent(propertiesPanel);
this.propertiesHeader.setText(propertiesPanel.getName());
result.setTitleAt(index, null);
result.setTabComponentAt(index, this.propertiesHeader);
updatePropertiesNotable();
Expand Down Expand Up @@ -503,7 +501,7 @@ private TypeTree getLabelTree() {

private TypeTree labelTree;

private PropertiesTable getPropertiesPanel() {
private @NonNull PropertiesTable getPropertiesPanel() {
PropertiesTable result = this.propertiesPanel;
if (result == null) {
final var panel = new PropertiesTable(GraphProperties.Key.class, true);
Expand All @@ -525,6 +523,20 @@ private PropertiesTable getPropertiesPanel() {

/** Properties panel of this tab. */
private PropertiesTable propertiesPanel;

private @NonNull JScrollPane getPropertiesScrollPanel() {
var result = this.propertiesScrollPanel;
if (result == null) {
var propertiesPanel = getPropertiesPanel();
this.propertiesScrollPanel = result = new JScrollPane(propertiesPanel);
result.setName(propertiesPanel.getName());
result.getViewport().setBackground(propertiesPanel.getBackground());
}
return result;
}

private JScrollPane propertiesScrollPanel;

/** Flag indicating if table changes should be propagated to the graph properties. */
private boolean listenToPropertiesPanel;

Expand Down
37 changes: 29 additions & 8 deletions src/main/java/nl/utwente/groove/gui/display/GraphTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultGraphModel.GraphModelEdit;
Expand All @@ -24,6 +25,7 @@
import nl.utwente.groove.grammar.model.GrammarModel;
import nl.utwente.groove.grammar.model.ResourceKind;
import nl.utwente.groove.graph.GraphProperties;
import nl.utwente.groove.graph.GraphProperties.Key;
import nl.utwente.groove.gui.Icons;
import nl.utwente.groove.gui.Options;
import nl.utwente.groove.gui.dialog.PropertiesTable;
Expand Down Expand Up @@ -120,19 +122,16 @@ final public boolean isEditor() {
}

@Override
protected JComponent getUpperInfoPanel() {
protected JTabbedPane getUpperInfoPanel() {
JTabbedPane result = this.upperInfoPanel;
if (result == null) {
this.upperInfoPanel = result = new JTabbedPane();
result.add(getLabelPanel());
if (getResourceKind().hasProperties()) {
JComponent propertiesPanel = getPropertiesPanel();
JScrollPane scrollPanel = new JScrollPane(propertiesPanel);
scrollPanel.setName(propertiesPanel.getName());
scrollPanel.getViewport().setBackground(propertiesPanel.getBackground());
result.add(scrollPanel);
int index = result.indexOfComponent(scrollPanel);
this.propertiesHeader.setText(scrollPanel.getName());
var propertiesPanel = getPropertiesScrollPanel();
result.add(propertiesPanel);
int index = result.indexOfComponent(propertiesPanel);
this.propertiesHeader.setText(propertiesPanel.getName());
result.setTitleAt(index, null);
result.setTabComponentAt(index, this.propertiesHeader);
updatePropertiesNotable();
Expand Down Expand Up @@ -175,6 +174,19 @@ private PropertiesTable getPropertiesPanel() {
/** Properties panel of this tab. */
private PropertiesTable propertiesPanel;

private @NonNull JScrollPane getPropertiesScrollPanel() {
var result = this.propertiesScrollPanel;
if (result == null) {
var propertiesPanel = getPropertiesPanel();
this.propertiesScrollPanel = result = new JScrollPane(propertiesPanel);
result.setName(propertiesPanel.getName());
result.getViewport().setBackground(propertiesPanel.getBackground());
}
return result;
}

private JScrollPane propertiesScrollPanel;

/** Tab component of the properties tab in the upper info panel. */
private final JLabel propertiesHeader = new JLabel();

Expand Down Expand Up @@ -292,6 +304,15 @@ public boolean removeResource(QualName name) {
return result;
}

@Override
public void setPropertyKey(Key propertyKey) {
var upperInfoPanel = getUpperInfoPanel();
if (upperInfoPanel != null && propertyKey != null) {
upperInfoPanel.setSelectedComponent(getPropertiesScrollPanel());
getPropertiesPanel().setSelected(propertyKey);
}
}

/**
* Notifies the tab that the grammar has changed.
* This resets the internal data structures, and informs the
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/nl/utwente/groove/gui/display/ResourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import nl.utwente.groove.grammar.model.NamedResourceModel;
import nl.utwente.groove.grammar.model.ResourceKind;
import nl.utwente.groove.grammar.model.ResourceModel;
import nl.utwente.groove.graph.GraphProperties.Key;
import nl.utwente.groove.gui.Icons;
import nl.utwente.groove.gui.Options;
import nl.utwente.groove.gui.Simulator;
Expand All @@ -50,6 +51,7 @@
import nl.utwente.groove.gui.action.SimulatorAction;
import nl.utwente.groove.gui.list.ErrorListPanel;
import nl.utwente.groove.gui.list.ListPanel;
import nl.utwente.groove.util.Exceptions;
import nl.utwente.groove.util.parse.FormatErrorSet;

/**
Expand Down Expand Up @@ -219,7 +221,9 @@ final public ResourceKind getResourceKind() {
* exists (and so the main tab was not changed)
* @throws UnsupportedOperationException if this is an editor tab
*/
abstract public boolean setResource(QualName name);
public boolean setResource(QualName name) {
throw Exceptions.unsupportedOp();
}

/**
* Removes a resource that is currently being edited from the
Expand All @@ -229,7 +233,15 @@ final public ResourceKind getResourceKind() {
* @return {@code true} if this was the currently displayed resource
* @throws UnsupportedOperationException if this is an editor tab
*/
abstract public boolean removeResource(QualName name);
public boolean removeResource(QualName name) {
throw Exceptions.unsupportedOp();
}

/** Selects a given property key to be displayed.
*/
public void setPropertyKey(Key propertyKey) {
throw Exceptions.unsupportedOp();
}

/**
* Indicates if this tab is an editor tab.
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/nl/utwente/groove/gui/list/ListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import nl.utwente.groove.grammar.QualName;
import nl.utwente.groove.grammar.model.ResourceKind;
import nl.utwente.groove.graph.Element;
import nl.utwente.groove.graph.GraphProperties.Key;
import nl.utwente.groove.gui.look.Values;
import nl.utwente.groove.gui.look.Values.Mode;
import nl.utwente.groove.io.HTMLConverter;
Expand Down Expand Up @@ -205,13 +209,18 @@ public Component getListCellRendererComponent(JList list, Object value, int inde
/** Interface for entries of the list. */
public interface SelectableListEntry {
/** Returns the resource kind for which this entry occurs. */
public ResourceKind getResourceKind();
public @Nullable ResourceKind getResourceKind();

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

/** Returns the list of elements in which the entry occurs. May be empty. */
public Collection<Element> getElements();
public @NonNull Collection<Element> getElements();

/** Returns the property key in which the entry occurs. May be {@code null}. */
default public @Nullable Key getPropertyKey() {
return null;
}
}

/** Name of a list selection event. */
Expand Down
1 change: 0 additions & 1 deletion src/main/java/nl/utwente/groove/gui/list/SearchResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,4 @@ public final SortedSet<QualName> getResourceNames() {

/** The name of the resource on which the result occurs. May be {@code null}. */
private final SortedSet<QualName> resourceNames = new TreeSet<>();

}
29 changes: 22 additions & 7 deletions src/main/java/nl/utwente/groove/util/parse/FormatError.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import nl.utwente.groove.graph.EdgeComparator;
import nl.utwente.groove.graph.Element;
import nl.utwente.groove.graph.GraphMap;
import nl.utwente.groove.graph.GraphProperties.Key;
import nl.utwente.groove.graph.Node;
import nl.utwente.groove.graph.NodeComparator;
import nl.utwente.groove.gui.list.ListPanel.SelectableListEntry;
Expand Down Expand Up @@ -78,6 +79,8 @@ private void addContext(Object par) {
c.forEach(this::addContext);
} else if (par instanceof FormatError e) {
e.getArguments().forEach(this::addContext);
} else if (par instanceof Key k) {
this.key = k;
} else if (par instanceof GraphState s) {
this.state = s;
} else if (par instanceof AspectGraph g) {
Expand Down Expand Up @@ -174,39 +177,45 @@ public int compareTo(FormatError other) {
}

/** Returns the control view in which the error occurs. May be {@code null}. */
public final ControlModel getControl() {
public final @Nullable ControlModel getControl() {
return this.control;
}

/** The control view in which the error occurs. */
private ControlModel control;

/** Returns the prolog view in which the error occurs. May be {@code null}. */
public final PrologModel getProlog() {
public final @Nullable PrologModel getProlog() {
return this.prolog;
}

/** The prolog view in which the error occurs. */
private PrologModel prolog;

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

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

/** Returns the state in which the error occurs. May be {@code null}. */
public final GraphState getState() {
public final @Nullable GraphState getState() {
return this.state;
}

/** The state in which the error occurs. */
/** The (possibly {@code null}) state in which the error occurs. */
private GraphState state;

/** List of erroneous elements. */
private final Set<Element> elements = new LinkedHashSet<>();
/** Returns the property key in which the error occurs. May be {@code null}. */
@Override
public final @Nullable Key getPropertyKey() {
return this.key;
}

/** The (possibly {@code null}) key in which the error occurs. */
private Key key;

/** Returns the list of elements in which the error occurs, together
* with its projections. May be empty. */
Expand All @@ -229,6 +238,9 @@ public Collection<Element> getElements() {
return result;
}

/** List of erroneous elements. */
private final Set<Element> elements = new LinkedHashSet<>();

/** Returns a list of numbers associated with the error; typically,
* line and column numbers. May be empty. */
public final List<Integer> getNumbers() {
Expand Down Expand Up @@ -307,6 +319,9 @@ private List<Object> getArguments() {
if (this.state != null) {
result.add(this.state);
}
if (this.key != null) {
result.add(this.key);
}
return result;
}

Expand Down

0 comments on commit e529eb0

Please sign in to comment.