Commit e62c83e2 authored by Sebastian Pretscher's avatar Sebastian Pretscher

commit to resolve conflicts...

parent 29371b34
......@@ -165,7 +165,7 @@ public class DocumentDidChangeJob extends Job {
e.printStackTrace();
}
if (lalrResult != null) {
LaLrResultJob resultLaLrModelJob = new LaLrResultJob(lalrResult, revNumber);
LaLrResultJob resultLaLrModelJob = new LaLrResultJob(lalrResult, revNumber, context);
resultLaLrModelJob.setSystem(true);
resultLaLrModelJob.schedule();
} else {
......@@ -232,13 +232,15 @@ public class DocumentDidChangeJob extends Job {
class LaLrResultJob extends UIJob {
LALRResult lalrReult;
LALRResult lalrResult;
long lalrResulRevisionNumber;
CupContext lalrContext;
public LaLrResultJob(LALRResult result, long revisionNumber) {
public LaLrResultJob(LALRResult result, long revisionNumber, CupContext context) {
super("LaLr Result UI Job");
this.lalrReult = result;
this.lalrResult = result;
this.lalrResulRevisionNumber = revisionNumber;
this.lalrContext = context;
}
@Override
......@@ -249,7 +251,7 @@ public class DocumentDidChangeJob extends Job {
.getEditorInput());
if (document != null) {
Model model = Model.getInstanceForDocument(document);
model.setLaLrResultModel(this.lalrReult, lalrResulRevisionNumber);
model.setLaLrResultModel(this.lalrResult, lalrResulRevisionNumber, lalrContext);
return Status.OK_STATUS;
}
}
......
package de.tum.in.www2.cupplugin.editors;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.progress.UIJob;
import org.eclipse.zest.core.viewers.AbstractZoomableViewer;
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.core.viewers.IGraphEntityContentProvider;
import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.layouts.LayoutAlgorithm;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
import de.tum.in.www2.cupplugin.model.CupGraphModelObserver;
import de.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.internal.lalr_state;
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.model.CupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupGraphView implements CupGraphModelObserver {
public class CupGraphView implements CupParserLaLrChangeObserver {
private GraphViewer graphViewer;
private Model parseModel;
private ParserNodeModelContentProvider nodeModel;
private Composite graphComposite;
private Graph g;
public CupGraphView(Composite parent, IDocument doc) {
this.parseModel = Model.getInstanceForDocument(doc);
this.parseModel.registerModelObserver(this);
this.graphComposite = parent;
org.eclipse.swt.layout.FillLayout layout = new FillLayout();
this.graphComposite.setLayout(layout);
FillLayout parentLayout = new FillLayout();
this.graphComposite.setLayout(parentLayout);
g = new Graph(parent, SWT.NONE);
for (int i = 0; i<5; i++) {
GraphNode hello = new GraphNode(g, SWT.NONE, "Hello");
GraphNode world = new GraphNode(g, SWT.NONE, "World");
new GraphConnection(g, SWT.NONE, hello, world);
}
g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
}
graphViewer = new GraphViewer(graphComposite, SWT.NONE);
graphViewer.setContentProvider(new GraphNodeContentProvider());
graphViewer.setLabelProvider(new ParserReduceLabelProvider());
public void modelChanged(Model model) {
// TODO Auto-generated method stub
nodeModel = new ParserNodeModelContentProvider();
graphViewer.setInput(nodeModel.getNodes());
LayoutAlgorithm layout = new TreeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING);
graphViewer.setLayoutAlgorithm(layout, true);
graphViewer.applyLayout();
}
public void willBecomeVisible() {
System.out.println("CupGraphView will become visible.");
LayoutAlgorithm layout = new TreeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING);
graphViewer.setLayoutAlgorithm(layout, true);
graphViewer.applyLayout();
}
public void becameHidden() {
System.out.println("CupGraphView became hidden.");
}
@Override
public void ModelChange(Model model) {
LALRResult lalrResult = model.getLaLrResult();
CupContext lalrContext = model.getLaLrContext();
nodeModel.rebuildModel(model, lalrResult, lalrContext);
graphViewer.refresh();
}
public AbstractZoomableViewer getGraphViewer() {
return graphViewer;
}
/*
* ContentProviderStuff for Zest
*/
static class ParserReduceNode {
private final int id;
private final String name;
private List<ParserReduceNode> connections;
public ParserReduceNode(int id, String name) {
this.id = id;
this.name = name;
this.connections = new ArrayList<ParserReduceNode>();
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public List<ParserReduceNode> getConnectedTo() {
return connections;
}
}
static class ParserReduceConnection {
final String id;
final String label;
final ParserReduceNode source;
final ParserReduceNode destination;
public ParserReduceConnection(String id, String label,
ParserReduceNode source, ParserReduceNode destination) {
this.id = id;
this.label = label;
this.source = source;
this.destination = destination;
}
public String getLabel() {
return label;
}
public ParserReduceNode getSource() {
return source;
}
public ParserReduceNode getDestination() {
return destination;
}
}
static class ParserNodeModelContentProvider {
private List<ParserReduceConnection> connections;
private List<ParserReduceNode> nodes;
LALRResult lalrResult;
CupContext lalrContext;
public ParserNodeModelContentProvider() {
connections = new ArrayList<CupGraphView.ParserReduceConnection>();
nodes = new ArrayList<CupGraphView.ParserReduceNode>();
}
public void rebuildModel(Model model, LALRResult lalrResult,
CupContext lalrContext) {
this.lalrContext = lalrContext;
this.lalrResult = lalrResult;
connections.clear();
nodes.clear();
parse_reduce_table reduceTable = this.lalrResult.getReduceTable();
lalr_state gotoState = null;
for (int stateRow = 0; stateRow < reduceTable.num_states(); stateRow++) {
ParserReduceNode n = new ParserReduceNode(stateRow, "State: "
+ stateRow);
nodes.add(n);
}
int columSize = parse_reduce_row.size(this.lalrContext);
for (int stateRow = 0; stateRow < reduceTable.num_states(); stateRow++) {
for (int stateColum = 0; stateColum < columSize; stateColum++) {
gotoState = reduceTable.under_state[stateRow].under_non_term[stateColum];
if (gotoState != null) {
ParserReduceNode first = nodes.get(stateRow);
ParserReduceNode seccond = nodes.get(gotoState.index());
ParserReduceConnection con = new ParserReduceConnection(
"From: " + first.getId() + " to: "
+ seccond.getId(), "Non term "
+ stateColum, first, seccond);
first.getConnectedTo().add(seccond);
connections.add(con);
}
}
}
}
public List<ParserReduceNode> getNodes() {
return nodes;
}
}
static class GraphNodeContentProvider extends ArrayContentProvider
implements IGraphEntityContentProvider {
@Override
public Object[] getConnectedTo(Object entity) {
if (entity instanceof ParserReduceNode) {
ParserReduceNode node = (ParserReduceNode) entity;
return node.getConnectedTo().toArray();
}
return null;
}
}
static class ParserReduceLabelProvider extends LabelProvider {
public String getText(Object element) {
if (element instanceof ParserReduceNode) {
ParserReduceNode node = (ParserReduceNode) element;
return node.getName();
}
if (element instanceof ParserReduceConnection) {
ParserReduceConnection con = (ParserReduceConnection) element;
return con.getLabel();
}
return "";
}
}
}
......@@ -8,6 +8,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
......@@ -17,10 +18,14 @@ import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.ide.IDE;
import org.eclipse.zest.core.viewers.AbstractZoomableViewer;
import org.eclipse.zest.core.viewers.IGraphEntityContentProvider;
import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart;
import org.eclipse.zest.core.viewers.ZoomContributionViewItem;
import de.tum.in.www2.cupplugin.controller.Controller;
public class MultiPageEditor extends MultiPageEditorPart implements IResourceChangeListener{
public class MultiPageEditor extends MultiPageEditorPart implements IResourceChangeListener, IZoomableWorkbenchPart {
private CupTextEditor editor;
private CupGraphView graphView;
......@@ -152,7 +157,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements IResourceCha
}
switch (newPageIndex) {
case OVERVIEW_PAGE_INDEX: overviewView.willBecomeVisible(); break;
case GRAPH_PAGE_INDEX: graphView.willBecomeVisible(); break;
case GRAPH_PAGE_INDEX: graphView.willBecomeVisible(); fillToolBar(); break;
case ACTION_TABLE_PAGE_INDEX: actionTableView.willBecomeVisible(); break;
case REDUCE_TABLE_PAGE_INDEX: reduceTableView.willBecomeVisible(); break;
}
......@@ -191,6 +196,18 @@ public class MultiPageEditor extends MultiPageEditorPart implements IResourceCha
return true;
}
@Override
public AbstractZoomableViewer getZoomableViewer() {
if(graphView!=null) {
return graphView.getGraphViewer();
}
return null;
}
private void fillToolBar() {
ZoomContributionViewItem toolbarZoomContributionViewItem = new ZoomContributionViewItem(this);
IActionBars bars = getEditorSite().getActionBars();
bars.getMenuManager().add(toolbarZoomContributionViewItem);
}
}
......@@ -6,6 +6,7 @@ import java.util.WeakHashMap;
import org.eclipse.jface.text.IDocument;
import de.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.ast.ParserResult;
......@@ -18,6 +19,7 @@ public class Model {
private LALRResult lalrModel;
private long lalrModelRevisionNumber;
private CupContext lalrContext;
private final Object parserModelLock = new Object();
private final Object lalrModellock = new Object();
......@@ -120,11 +122,23 @@ public class Model {
}
}
public void setLaLrResultModel(LALRResult result, long revisionNumber) {
public void setLaLrResultModel(LALRResult result, long revisionNumber, CupContext lalrContext) {
synchronized (lalrModellock) {
this.lalrModel = result;
this.lalrModelRevisionNumber = revisionNumber;
//TODO: NotifyKram....
this.lalrContext = lalrContext;
for(Object observer : modelObservers) {
if (observer instanceof CupParserLaLrChangeObserver) {
((CupParserLaLrChangeObserver)observer).ModelChange(this);
}
}
//System.out.println(lalrModel.getReduceTable().toString());
}
}
public CupContext getLaLrContext() {
synchronized (lalrModellock) {
return this.lalrContext;
}
}
......
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