Commit c8a7aebe authored by Johannes Roith's avatar Johannes Roith

Merge branch 'master' of github.com:jroith/cup-eclipse

parents 8083baf1 b01744c9
......@@ -3,6 +3,7 @@ package de.tum.in.www2.cupplugin.editors;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedList;
......@@ -73,14 +74,19 @@ import de.in.tum.www2.cup.internal.lalr_state;
import de.in.tum.www2.cup.internal.lalr_transition;
import de.in.tum.www2.cup.internal.parse_reduce_row;
import de.in.tum.www2.cup.internal.parse_reduce_table;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.controller.RegisterForControllerChanges;
import de.tum.in.www2.cupplugin.model.CupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupReduceGraphView implements CupParserLaLrChangeObserver,
IZoomableWorkbenchPart, CupEditorPageVisibility {
IZoomableWorkbenchPart, CupEditorPageVisibility,
RegisterForControllerChanges {
// 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;
......@@ -94,17 +100,24 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
private boolean isVisible = false;
private boolean shouldRebuildWhenVisible = false;
public CupReduceGraphView(Composite parent, IDocument doc) {
private CupTextEditor editor;
public CupReduceGraphView(Composite parent, CupTextEditor editor) {
this.editor = editor;
Controller.getInstance(editor).registerObserver(this);
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
this.parseModel = Model.getInstanceForDocument(doc);
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();
......@@ -114,9 +127,9 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
ParserReduceLabelProvider labelProvider = new ParserReduceLabelProvider(
nodeModel.getConnections());
graphViewer.setLabelProvider(labelProvider);
//graphViewer.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
// graphViewer.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
graphViewer.setInput(nodeModel.getNodes());
LayoutAlgorithm layout = new CompositeLayoutAlgorithm(
......@@ -204,17 +217,21 @@ 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();
String[] levels = zoomManager.getZoomLevelsAsText();
combo.setItems(levels);
combo.select(0);
combo.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
if (e.widget instanceof Combo) {
Combo c = (Combo)e.widget;
Combo c = (Combo) e.widget;
int idx = c.getSelectionIndex();
String s = levels[idx];
zoomManager.setZoomAsText(levels[idx]);
......@@ -229,21 +246,29 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
public void willBecomeVisible() {
System.out.println("CupGraphView will become visible.");
isVisible = true;
if (!Controller.getInstance(editor).requestJobRun()) {
// TODO: Handle no rerun!!
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
ModelChange(Model.getInstanceForDocument(doc));
}
}
public void reloadGraph() {
LayoutAlgorithm layout = new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING, new LayoutAlgorithm[] {
new GridLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING)//,
//new GridLayoutAlgorithm(
// LayoutStyles.NO_LAYOUT_NODE_RESIZING)
});
LayoutStyles.NO_LAYOUT_NODE_RESIZING) // ,
// new GridLayoutAlgorithm(
// LayoutStyles.NO_LAYOUT_NODE_RESIZING)
});
graphViewer.setLayoutAlgorithm(layout, true);
graphViewer.applyLayout();
synchronized (CupReduceGraphView.modelBuildLock) {
graphViewer.refresh();
}
}
}
@Override
......@@ -254,9 +279,12 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
@Override
public void ModelChange(Model model) {
if (!isVisible) {
return;
}
LALRResult lalrResult = model.getLaLrResult();
CupContext lalrContext = model.getLaLrContext();
nodeModel.rebuildModel(model, lalrResult, lalrContext);
nodeModel.rebuildModel(model, lalrResult, lalrContext, this);
}
public AbstractZoomableViewer getGraphViewer() {
......@@ -353,7 +381,7 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
}
public void rebuildModel(Model model, LALRResult lalrResult,
CupContext lalrContext) {
CupContext lalrContext, CupReduceGraphView reduceGraphView) {
this.lalrContext = lalrContext;
this.lalrResult = lalrResult;
......@@ -362,7 +390,7 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
rebuildJob.cancel();
}
rebuildJob = new ModelRebuildJob(model, lalrResult,
lalrContext, connections, nodes, nodeMap);
lalrContext, connections, nodes, nodeMap, reduceGraphView);
rebuildJob.setSystem(true);
rebuildJob.schedule();
}
......@@ -435,12 +463,14 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
private List<ParserReduceConnection> connections;
private List<ParserReduceNode> nodes;
private HashMap<Integer, ParserReduceNode> nodeMap;
private CupReduceGraphView reduceGraphView;
public ModelRebuildJob(Model model, LALRResult lalrResult,
CupContext lalrContext,
List<ParserReduceConnection> connections,
List<ParserReduceNode> nodes,
HashMap<Integer, ParserReduceNode> nodeMap) {
HashMap<Integer, ParserReduceNode> nodeMap,
CupReduceGraphView reduceGraphView) {
super("Model Rebuild Job");
this.model = model;
......@@ -449,6 +479,7 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
this.connections = connections;
this.nodes = nodes;
this.nodeMap = nodeMap;
this.reduceGraphView = reduceGraphView;
}
@Override
......@@ -502,6 +533,27 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
}
}
}
ModelRebuildJobFinished job = new ModelRebuildJobFinished(reduceGraphView);
job.setSystem(true);
job.schedule();
return Status.OK_STATUS;
}
}
static class ModelRebuildJobFinished extends UIJob {
private CupReduceGraphView reduceGraphView;
public ModelRebuildJobFinished(CupReduceGraphView reduceGraphView) {
super("Model Rebuild Job Finished UI Job");
this.reduceGraphView = reduceGraphView;
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
reduceGraphView.reloadGraph();
return Status.OK_STATUS;
}
......@@ -806,4 +858,13 @@ public class CupReduceGraphView implements CupParserLaLrChangeObserver,
public AbstractZoomableViewer getZoomableViewer() {
return getGraphViewer();
}
@Override
public EnumSet<JobsToDo> getRequiredJobs() {
EnumSet<JobsToDo> requestedJobs = EnumSet.noneOf(JobsToDo.class);
if (isVisible) {
requestedJobs = EnumSet.of(JobsToDo.buildTable, JobsToDo.parseCode);
}
return requestedJobs;
}
}
......@@ -85,7 +85,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
graphReduceView = new CupReduceGraphView(composite, doc);
graphReduceView = new CupReduceGraphView(composite, getEditor());
int index = addPage(composite);
setPageText(index, "Automaton View (costly)");
......
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