Commit af9ab62a authored by Sebastian Pretscher's avatar Sebastian Pretscher
Browse files

Some fixes to avoid a blocking graphview as long as possible

parent 9cd4a522
......@@ -58,6 +58,7 @@ import org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.HorizontalShift;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
import org.omg.CORBA.REBIND;
import de.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.LALRResult;
......@@ -74,13 +75,18 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
// Some Constants
private static final int BUTTON_WIDTH = 120;
public GraphViewer graphViewer;
private Model parseModel;
private ParserNodeModelContentProvider nodeModel;
private Composite graphComposite;
private Composite parentComposite;
public static final Object modelBuildLock = new Object();
private boolean isVisible = false;
private boolean shouldRebuildWhenVisible = false;
public CupReduceGraphView(Composite parent, IDocument doc) {
this.parseModel = Model.getInstanceForDocument(doc);
this.parseModel.registerModelObserver(this);
......@@ -135,7 +141,7 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
}
}
});
Button colorEndStates = new Button(this.parentComposite, SWT.CHECK);
colorEndStates.setText("Mark final states");
colorEndStates.setLayoutData(new GridData(BUTTON_WIDTH, 20));
......@@ -155,7 +161,7 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
}
}
});
Button colorStartState = new Button(this.parentComposite, SWT.CHECK);
colorStartState.setText("Mark start states");
colorStartState.setLayoutData(new GridData(BUTTON_WIDTH, 20));
......@@ -174,11 +180,12 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
break;
}
}
});
});
}
public void willBecomeVisible() {
System.out.println("CupGraphView will become visible.");
isVisible = true;
LayoutAlgorithm layout = new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING, new LayoutAlgorithm[] {
......@@ -190,22 +197,23 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
LayoutStyles.NO_LAYOUT_NODE_RESIZING) });
graphViewer.setLayoutAlgorithm(layout, true);
graphViewer.applyLayout();
synchronized(CupReduceGraphView.modelBuildLock) {
graphViewer.refresh();
}
}
public void becameHidden() {
System.out.println("CupGraphView became hidden.");
isVisible = false;
}
@Override
public void ModelChange(Model model) {
LALRResult lalrResult = model.getLaLrResult();
CupContext lalrContext = model.getLaLrContext();
System.out.println(lalrResult.getReduceTable().toString());
// if(isVisible) {
nodeModel.rebuildModel(model, lalrResult, lalrContext);
graphViewer.refresh();
// graphViewer.refresh();
}
public AbstractZoomableViewer getGraphViewer() {
......@@ -282,6 +290,8 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
private List<ParserReduceNode> nodes;
private HashMap<Integer, ParserReduceNode> nodeMap;
private ModelRebuildJob rebuildJob;
LALRResult lalrResult;
CupContext lalrContext;
......@@ -304,53 +314,46 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
this.lalrContext = lalrContext;
this.lalrResult = lalrResult;
connections.clear();
nodes.clear();
nodeMap.clear();
parse_reduce_table reduceTable = this.lalrResult.getReduceTable();
lalr_state gotoState = null;
lalr_state.lalr_state_shared sharedState = lalr_state
.getShared(lalrContext);
Enumeration allEnum = sharedState.all();
List<lalr_state> allStates = new ArrayList<lalr_state>();
while (allEnum.hasMoreElements()) {
Object o = allEnum.nextElement();
if (o instanceof lalr_state) {
allStates.add((lalr_state) o);
}
}
for (lalr_state state : allStates) {
ParserReduceNode n = new ParserReduceNode(state.index(),
"State: " + state.index());
n.setDescription(state.toString());
nodes.add(n);
nodeMap.put(state.index(), n);
}
for (lalr_state state : allStates) {
// List<lalr_transition> transitions = new
// LinkedList<lalr_transition>();
lalr_transition trans = state.transitions();
if (trans != null) {
while (trans != null) {
// transitions.add(trans);
ParserReduceNode first = nodeMap.get(state.index());
ParserReduceNode seccond = nodeMap.get(trans.to_state()
.index());
ParserReduceConnection con = new ParserReduceConnection(
trans.toString(), trans.on_symbol().name(),
first, seccond);
first.getConnectedTo().add(seccond);
connections.add(con);
trans = trans.next();
}
if (rebuildJob == null || (rebuildJob.getState() != Job.RUNNING)) {
if (rebuildJob != null) {
rebuildJob.cancel();
}
rebuildJob = new ModelRebuildJob(model, lalrResult,
lalrContext, connections, nodes, nodeMap);
rebuildJob.setSystem(true);
rebuildJob.schedule();
}
/*
* connections.clear(); nodes.clear(); nodeMap.clear();
*
* parse_reduce_table reduceTable =
* this.lalrResult.getReduceTable(); lalr_state gotoState = null;
*
* lalr_state.lalr_state_shared sharedState = lalr_state
* .getShared(lalrContext); Enumeration allEnum = sharedState.all();
* List<lalr_state> allStates = new ArrayList<lalr_state>(); while
* (allEnum.hasMoreElements()) { Object o = allEnum.nextElement();
* if (o instanceof lalr_state) { allStates.add((lalr_state) o); } }
*
* for (lalr_state state : allStates) { ParserReduceNode n = new
* ParserReduceNode(state.index(), "State: " + state.index());
* n.setDescription(state.toString()); nodes.add(n);
* nodeMap.put(state.index(), n); }
*
* for (lalr_state state : allStates) { // List<lalr_transition>
* transitions = new // LinkedList<lalr_transition>();
* lalr_transition trans = state.transitions(); if (trans != null) {
* while (trans != null) { // transitions.add(trans);
* ParserReduceNode first = nodeMap.get(state.index());
* ParserReduceNode seccond = nodeMap.get(trans.to_state()
* .index());
*
* ParserReduceConnection con = new ParserReduceConnection(
* trans.toString(), trans.on_symbol().name(), first, seccond);
* first.getConnectedTo().add(seccond); connections.add(con); trans
* = trans.next(); } } }
*/
/*
* for (int stateRow = 0; stateRow < reduceTable.num_states();
* stateRow++) { ParserReduceNode n = new ParserReduceNode(stateRow,
......@@ -380,6 +383,87 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
}
static class ModelRebuildJob extends Job {
private Model model;
private LALRResult lalrResult;
private CupContext lalrContext;
private List<ParserReduceConnection> connections;
private List<ParserReduceNode> nodes;
private HashMap<Integer, ParserReduceNode> nodeMap;
public ModelRebuildJob(Model model, LALRResult lalrResult,
CupContext lalrContext,
List<ParserReduceConnection> connections,
List<ParserReduceNode> nodes,
HashMap<Integer, ParserReduceNode> nodeMap) {
super("Model Rebuild Job");
this.model = model;
this.lalrResult = lalrResult;
this.lalrContext = lalrContext;
this.connections = connections;
this.nodes = nodes;
this.nodeMap = nodeMap;
}
@Override
protected IStatus run(IProgressMonitor monitor) {
synchronized (CupReduceGraphView.modelBuildLock) {
connections.clear();
nodes.clear();
nodeMap.clear();
parse_reduce_table reduceTable = this.lalrResult
.getReduceTable();
lalr_state gotoState = null;
lalr_state.lalr_state_shared sharedState = lalr_state
.getShared(lalrContext);
Enumeration allEnum = sharedState.all();
List<lalr_state> allStates = new ArrayList<lalr_state>();
while (allEnum.hasMoreElements()) {
Object o = allEnum.nextElement();
if (o instanceof lalr_state) {
allStates.add((lalr_state) o);
}
}
for (lalr_state state : allStates) {
ParserReduceNode n = new ParserReduceNode(state.index(),
"State: " + state.index());
n.setDescription(state.toString());
nodes.add(n);
nodeMap.put(state.index(), n);
}
for (lalr_state state : allStates) {
// List<lalr_transition> transitions = new
// LinkedList<lalr_transition>();
lalr_transition trans = state.transitions();
if (trans != null) {
while (trans != null) {
// transitions.add(trans);
ParserReduceNode first = nodeMap.get(state.index());
ParserReduceNode seccond = nodeMap.get(trans
.to_state().index());
ParserReduceConnection con = new ParserReduceConnection(
trans.toString(), trans.on_symbol().name(),
first, seccond);
first.getConnectedTo().add(seccond);
connections.add(con);
trans = trans.next();
}
}
}
}
return Status.OK_STATUS;
}
}
static class GraphNodeContentProvider extends ArrayContentProvider
implements IGraphEntityContentProvider {
......@@ -459,7 +543,8 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
@Override
public Color getBackgroundColour(Object entity) {
// TODO Auto-generated method stub
if ((showColordEndStates || showColordStartState) && entity instanceof ParserReduceNode) {
if ((showColordEndStates || showColordStartState)
&& entity instanceof ParserReduceNode) {
ParserReduceNode n = (ParserReduceNode) entity;
if (showColordStartState && n.id == 0) {
Device device = Display.getCurrent();
......
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