Commit 9a0cb463 authored by Sebastian Pretscher's avatar Sebastian Pretscher

Improvements on ConflictView

parent d0e782b8
......@@ -16,11 +16,16 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
......@@ -61,25 +66,29 @@ import de.tum.in.www2.cupplugin.model.CupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupConflictGraphView implements CupParserLaLrChangeObserver,
IZoomableWorkbenchPart, CupEditorPageVisibility, RegisterForControllerChanges {
IZoomableWorkbenchPart, CupEditorPageVisibility,
RegisterForControllerChanges {
private static final int BUTTON_WIDTH = 120;
private static final int LABEL_WIDTH = 40;
private CupTextEditor editor;
public GraphViewer graphViewer;
private Model parseModel;
private ParserConflictNodeModelContentProvider nodeModel;
private Composite graphComposite;
private Composite parentComposite;
private Label symbolLabel;
private final ScrolledComposite scroll;
// private final Composite scrollSubContent;
private Combo zoomCombo;
private ZoomManager zoomManager;
private Combo nodeSelection;
private Listener nodeSelectionListener;
private boolean isVisible = false;
private boolean shouldRebuildWhenVisible = false;
private HashMap<Integer, lalr_state> stateHashMap;
......@@ -91,7 +100,7 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
Controller.getInstance(editor).registerObserver(this);
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
this.parseModel = Model.getInstanceForDocument(doc);
this.parseModel.registerModelObserver(this);
this.parentComposite = parent;
......@@ -100,12 +109,12 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
this.searchStack = new Stack<CupConflictGraphView.DFSNode>();
this.visitedStates = new HashSet<lalr_state>();
GridLayout parentLayout = new GridLayout(5, false);
GridLayout parentLayout = new GridLayout(7, false);
this.parentComposite.setLayout(parentLayout);
this.graphComposite = new Composite(parent, SWT.NONE);
this.graphComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true, 5, 1));
true, true, 7, 1));
this.graphComposite.setLayout(new FillLayout());
nodeModel = new ParserConflictNodeModelContentProvider();
......@@ -118,21 +127,32 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
graphViewer.setInput(nodeModel.getNodes());
LayoutAlgorithm layout = new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING, new LayoutAlgorithm[] {
new SpringLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new GridLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) });
graphViewer.setLayoutAlgorithm(layout, true);
graphViewer.applyLayout();
// Setup search Result Label
symbolLabel = new Label(this.parentComposite, SWT.WRAP);
symbolLabel.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, true,
false, 5, 1));
scroll = new ScrolledComposite(this.parentComposite, SWT.BORDER
| SWT.V_SCROLL);
GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false, 7, 1);
data.minimumHeight = 60;
data.heightHint = 60;
scroll.setLayoutData(data);
scroll.setLayout(new FillLayout());
scroll.setExpandHorizontal(true);
scroll.setExpandVertical(true);
symbolLabel = new Label(scroll, SWT.WRAP);
// symbolLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
// false, 1, 1));
// symbolLabel.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, true,
// false, 7, 1));
scroll.setContent(symbolLabel);
scroll.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle r = scroll.getClientArea();
scroll.setMinSize(symbolLabel.computeSize(r.width, SWT.DEFAULT));
}
});
// Setup Buttons to enable/disable some features
Button labelDisplayButton = new Button(this.parentComposite, SWT.CHECK);
......@@ -208,13 +228,16 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
e1.printStackTrace();
}
if (zoomManager != null) {
Combo combo = new Combo(this.parentComposite, SWT.READ_ONLY);
combo.setLayoutData(new GridData(BUTTON_WIDTH, 20));
Label zoomLabel = new Label(this.parentComposite, SWT.WRAP);
zoomLabel.setLayoutData(new GridData(LABEL_WIDTH, 20));
zoomLabel.setText("Zoom:");
zoomCombo = new Combo(this.parentComposite, SWT.READ_ONLY);
zoomCombo.setLayoutData(new GridData(BUTTON_WIDTH, 20));
String[] levels = zoomManager.getZoomLevelsAsText();
combo.setItems(levels);
zoomCombo.setItems(levels);
combo.select(0);
combo.addListener(SWT.Selection, new Listener() {
zoomCombo.select(0);
zoomCombo.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
if (e.widget instanceof Combo) {
......@@ -225,7 +248,11 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
}
});
}
Label stateLabel = new Label(this.parentComposite, SWT.WRAP);
stateLabel.setLayoutData(new GridData(LABEL_WIDTH, 20));
stateLabel.setText("State:");
nodeSelection = new Combo(this.parentComposite, SWT.READ_ONLY);
nodeSelection.setLayoutData(new GridData(BUTTON_WIDTH, 20));
}
public AbstractZoomableViewer getGraphViewer() {
......@@ -272,12 +299,14 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
Combo c = (Combo) event.widget;
int idx = c.getSelectionIndex();
String[] parts = c.getItem(idx).split(" ");
setModelForDFSAfterState(stateHashMap.get(Integer.parseInt(parts[1])));
setModelForDFSAfterState(stateHashMap.get(Integer
.parseInt(parts[1])));
// System.out.println("Selected state: "+state.index());
}
}
};
nodeSelection.addListener(SWT.Selection, nodeSelectionListener);
nodeSelection.select(0);
}
private void setModelForDFSAfterState(lalr_state state) {
......@@ -289,12 +318,13 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
searchStack.push(firstState);
boolean found = DFSSearch(firstState, state.index());
String resultString = "Way to state " + state.index() + ": ";
if (found) {
nodeModel.rebuildModel(searchStack);
LayoutAlgorithm layout = new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING, new LayoutAlgorithm[] {
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new SpringLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
......@@ -303,7 +333,7 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
LayoutStyles.NO_LAYOUT_NODE_RESIZING) });
graphViewer.setLayoutAlgorithm(layout, true);
graphViewer.applyLayout();
graphViewer.refresh();
for (DFSNode n : searchStack) {
if (n.predecessor != null) {
......@@ -318,9 +348,17 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
// symbolLabel.redraw();
// parentComposite.layout();
symbolLabel.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, true,
false, 5, 1));
parentComposite.layout(true, true);
// symbolLabel.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM,
// false,
// false, 5, 1));
// symbolLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
// false, 1, 1));
// Setup the new Content Layout and zoom the graph to the selected
// level
scroll.layout(true, true);
Rectangle r = scroll.getClientArea();
scroll.setMinSize(symbolLabel.computeSize(r.width, SWT.DEFAULT));
}
}
......@@ -328,16 +366,15 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
if (state.getState().index() == searchIndex) {
// TODO: Want to only end with nonTerminals?
/*
if(state.predecessor != null && !state.predTransition.on_symbol().is_non_term()) {
return true;
}
return false;
*/
* if(state.predecessor != null &&
* !state.predTransition.on_symbol().is_non_term()) { return true; }
* return false;
*/
return true;
}
visitedStates.add(state.getState());
lalr_transition trans = state.getState().transitions();
//System.out.println("Trans Symbol is non term: "+trans.on_symbol().is_non_term());
// System.out.println("Trans Symbol is non term: "+trans.on_symbol().is_non_term());
while (trans != null) {
if (visitedStates.contains(trans.to_state())
|| trans.on_symbol().is_non_term()) {
......@@ -378,7 +415,7 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
public void willBecomeVisible() {
// this.graphViewer.refresh();
isVisible = true;
if(!Controller.getInstance(editor).requestJobRun()) {
if (!Controller.getInstance(editor).requestJobRun()) {
// TODO: Handle no rerun!!
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
......@@ -522,23 +559,28 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
public List<ParserConflictNode> getNodes() {
return nodes;
}
public void rebuildModel(Stack<DFSNode> foundNodes) {
connections.clear();
nodes.clear();
nodeMap.clear();
ParserConflictNode old = null;
int counter = 0;
for(DFSNode dfsNode : foundNodes) {
if(old == null) {
old = new ParserConflictNode(dfsNode.getState().index(), "State "+dfsNode.getState().index());
for (DFSNode dfsNode : foundNodes) {
if (old == null) {
old = new ParserConflictNode(dfsNode.getState().index(),
"State " + dfsNode.getState().index());
nodes.add(old);
continue;
}
ParserConflictNode n = new ParserConflictNode(dfsNode.getState().index(), "State "+dfsNode.getState().index());
ParserConflictNode n = new ParserConflictNode(dfsNode
.getState().index(), "State "
+ dfsNode.getState().index());
nodes.add(n);
ParserConflictConnection con = new ParserConflictConnection(""+counter, dfsNode.getPredTransition().on_symbol().toString(), old, n);
ParserConflictConnection con = new ParserConflictConnection(""
+ counter, dfsNode.getPredTransition().on_symbol()
.toString(), old, n);
old.getConnectedTo().add(n);
connections.add(con);
old = n;
......@@ -598,7 +640,7 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
}
return "";
}
@Override
public Color getNodeHighlightColor(Object entity) {
Device device = Display.getCurrent();
......@@ -683,7 +725,7 @@ public class CupConflictGraphView implements CupParserLaLrChangeObserver,
@Override
public EnumSet<JobsToDo> getRequiredJobs() {
EnumSet<JobsToDo> requestedJobs = EnumSet.noneOf(JobsToDo.class);
if(isVisible) {
if (isVisible) {
requestedJobs = EnumSet.of(JobsToDo.buildTable, JobsToDo.parseCode);
}
return requestedJobs;
......
......@@ -81,6 +81,7 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
// Some Constants
private static final int BUTTON_WIDTH = 120;
private static final int LABEL_WIDTH = 40;
public static final Object modelBuildLock = new Object();
public GraphViewer graphViewer;
......@@ -99,12 +100,12 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
this.parseModel.registerModelObserver(this);
this.parentComposite = parent;
GridLayout parentLayout = new GridLayout(4, false);
GridLayout parentLayout = new GridLayout(5, false);
this.parentComposite.setLayout(parentLayout);
this.graphComposite = new Composite(parent, SWT.NONE);
this.graphComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true, 4, 1));
true, true, 5, 1));
this.graphComposite.setLayout(new FillLayout());
nodeModel = new ParserNodeModelContentProvider();
......@@ -204,6 +205,9 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
e1.printStackTrace();
}
if (zoomManager != null) {
org.eclipse.swt.widgets.Label zoomLabel = new org.eclipse.swt.widgets.Label(this.parentComposite, SWT.WRAP);
zoomLabel.setLayoutData(new GridData(LABEL_WIDTH, 20));
zoomLabel.setText("Zoom:");
Combo combo = new Combo(this.parentComposite, SWT.READ_ONLY);
combo.setLayoutData(new GridData(BUTTON_WIDTH, 20));
String[] levels = zoomManager.getZoomLevelsAsText();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment