Commit 9e971a39 authored by Sebastian Pretscher's avatar Sebastian Pretscher
Browse files

Tooltips for graph and some refactoring

parent ede1d6df
......@@ -7,6 +7,7 @@ import java.util.Stack;
import de.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.ErrorSource;
import de.in.tum.www2.cup.internal.production.production_shared;
/** This class represents a state in the LALR viable prefix recognition machine.
* A state consists of an LALR item set and a set of transitions to other
......@@ -160,6 +161,10 @@ public class lalr_state {
return stat.number();
}
public static lalr_state_shared getShared(CupContext context) {
lalr_state_shared stat = context.getForContext(lalr_state_shared.class);
return stat;
}
/*-----------------------------------------------------------*/
......
package de.tum.in.www2.cupplugin.editors;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
......@@ -8,16 +9,20 @@ 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.draw2d.IFigure;
import org.eclipse.draw2d.Label;
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.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
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.IEntityStyleProvider;
import org.eclipse.zest.core.viewers.IGraphEntityContentProvider;
import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart;
import org.eclipse.zest.core.widgets.Graph;
......@@ -29,20 +34,21 @@ import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
import de.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.internal.lalr_item;
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 CupParserLaLrChangeObserver, IZoomableWorkbenchPart {
public class CupReduceGraphView implements CupParserLaLrChangeObserver, IZoomableWorkbenchPart {
private GraphViewer graphViewer;
private Model parseModel;
private ParserNodeModelContentProvider nodeModel;
private Composite graphComposite;
public CupGraphView(Composite parent, IDocument doc) {
public CupReduceGraphView(Composite parent, IDocument doc) {
this.parseModel = Model.getInstanceForDocument(doc);
this.parseModel.registerModelObserver(this);
this.graphComposite = parent;
......@@ -70,6 +76,7 @@ public class CupGraphView implements CupParserLaLrChangeObserver, IZoomableWorkb
LayoutStyles.NO_LAYOUT_NODE_RESIZING);
graphViewer.setLayoutAlgorithm(layout, true);
graphViewer.applyLayout();
}
public void becameHidden() {
......@@ -81,6 +88,8 @@ public class CupGraphView implements CupParserLaLrChangeObserver, IZoomableWorkb
LALRResult lalrResult = model.getLaLrResult();
CupContext lalrContext = model.getLaLrContext();
System.out.println(lalrResult.getReduceTable().toString());
nodeModel.rebuildModel(model, lalrResult, lalrContext);
graphViewer.refresh();
}
......@@ -96,11 +105,13 @@ public class CupGraphView implements CupParserLaLrChangeObserver, IZoomableWorkb
private final int id;
private final String name;
private List<ParserReduceNode> connections;
private String description;
public ParserReduceNode(int id, String name) {
this.id = id;
this.name = name;
this.connections = new ArrayList<ParserReduceNode>();
this.description = "";
}
public int getId() {
......@@ -114,6 +125,14 @@ public class CupGraphView implements CupParserLaLrChangeObserver, IZoomableWorkb
public List<ParserReduceNode> getConnectedTo() {
return connections;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
static class ParserReduceConnection {
......@@ -151,8 +170,8 @@ public class CupGraphView implements CupParserLaLrChangeObserver, IZoomableWorkb
CupContext lalrContext;
public ParserNodeModelContentProvider() {
connections = new ArrayList<CupGraphView.ParserReduceConnection>();
nodes = new ArrayList<CupGraphView.ParserReduceNode>();
connections = new ArrayList<CupReduceGraphView.ParserReduceConnection>();
nodes = new ArrayList<CupReduceGraphView.ParserReduceNode>();
}
public void rebuildModel(Model model, LALRResult lalrResult,
......@@ -166,9 +185,27 @@ public class CupGraphView implements CupParserLaLrChangeObserver, IZoomableWorkb
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 (int stateRow = 0; stateRow < reduceTable.num_states(); stateRow++) {
ParserReduceNode n = new ParserReduceNode(stateRow, "State: "
+ stateRow);
//lalr_state currentState = reduceTable.
lalr_state current = null;
for(lalr_state state:allStates) {
if (state.index()==stateRow) {
current = state;
}
}
n.setDescription(current.toString());
nodes.add(n);
}
......@@ -177,6 +214,7 @@ public class CupGraphView implements CupParserLaLrChangeObserver, IZoomableWorkb
for (int stateColum = 0; stateColum < columSize; stateColum++) {
gotoState = reduceTable.under_state[stateRow].under_non_term[stateColum];
if (gotoState != null) {
//System.out.println(gotoState.toString());
ParserReduceNode first = nodes.get(stateRow);
ParserReduceNode seccond = nodes.get(gotoState.index());
ParserReduceConnection con = new ParserReduceConnection(
......@@ -210,7 +248,7 @@ public class CupGraphView implements CupParserLaLrChangeObserver, IZoomableWorkb
}
static class ParserReduceLabelProvider extends LabelProvider {
static class ParserReduceLabelProvider extends LabelProvider implements IEntityStyleProvider {
public String getText(Object element) {
if (element instanceof ParserReduceNode) {
......@@ -225,6 +263,61 @@ public class CupGraphView implements CupParserLaLrChangeObserver, IZoomableWorkb
return "";
}
@Override
public Color getNodeHighlightColor(Object entity) {
// TODO Auto-generated method stub
return null;
}
@Override
public Color getBorderColor(Object entity) {
// TODO Auto-generated method stub
return null;
}
@Override
public Color getBorderHighlightColor(Object entity) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getBorderWidth(Object entity) {
// TODO Auto-generated method stub
return 0;
}
@Override
public Color getBackgroundColour(Object entity) {
// TODO Auto-generated method stub
return null;
}
@Override
public Color getForegroundColour(Object entity) {
// TODO Auto-generated method stub
return null;
}
@Override
public IFigure getTooltip(Object entity) {
Label description = null;
if(entity instanceof ParserReduceNode) {
ParserReduceNode n = (ParserReduceNode)entity;
description = new Label(n.getDescription());
return description;
}
description = new Label("");
return description;
}
@Override
public boolean fisheyeNode(Object entity) {
// TODO Auto-generated method stub
return false;
}
}
@Override
......
......@@ -33,10 +33,10 @@ public class MultiPageEditor extends MultiPageEditorPart implements
IResourceChangeListener {
private CupTextEditor editor;
private CupGraphView graphView;
private CupReduceGraphView graphReduceView;
// Zoom for the GraphView
private ZoomContributionViewItem graphZoomContribution;
private IMenuManager graphMenu;
private ZoomContributionViewItem graphReduceZoomContribution;
private IMenuManager graphReduceMenu;
private CupOverviewView overviewView;
private CupActionTableView actionTableView;
......@@ -83,10 +83,10 @@ public class MultiPageEditor extends MultiPageEditorPart implements
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
graphView = new CupGraphView(composite, doc);
graphReduceView = new CupReduceGraphView(composite, doc);
int index = addPage(composite);
setPageText(index, "Visualization");
setPageText(index, "Visualization Reduce Graph");
}
void createOverviewPage() {
......@@ -169,16 +169,17 @@ public class MultiPageEditor extends MultiPageEditorPart implements
overviewView.becameHidden();
break;
case GRAPH_PAGE_INDEX:
graphView.becameHidden();
removeObjectsWithMenuFromToolbar(graphZoomContribution, graphMenu);
graphZoomContribution = null;
graphMenu = null;
graphReduceView.becameHidden();
removeObjectsWithMenuFromToolbar(graphReduceZoomContribution, graphReduceMenu);
graphReduceZoomContribution = null;
graphReduceMenu = null;
break;
case ACTION_TABLE_PAGE_INDEX:
actionTableView.becameHidden();
break;
case REDUCE_TABLE_PAGE_INDEX:
reduceTableView.becameHidden();
break;
}
switch (newPageIndex) {
......@@ -186,8 +187,8 @@ public class MultiPageEditor extends MultiPageEditorPart implements
overviewView.willBecomeVisible();
break;
case GRAPH_PAGE_INDEX:
graphView.willBecomeVisible();
addZoomContributionForCupGraphView(graphView);
graphReduceView.willBecomeVisible();
addZoomContributionForCupGraphView(graphReduceView);
break;
case ACTION_TABLE_PAGE_INDEX:
actionTableView.willBecomeVisible();
......@@ -244,16 +245,16 @@ public class MultiPageEditor extends MultiPageEditorPart implements
private void addZoomContributionForCupGraphView(
IZoomableWorkbenchPart viewPart) {
graphZoomContribution = new ZoomContributionViewItem(viewPart);
graphReduceZoomContribution = new ZoomContributionViewItem(viewPart);
/*
* IActionBars bars = getEditorSite().getActionBars();
* bars.getMenuManager().add(toolbarZoomContributionViewItem);
* bars.updateActionBars();
*/
IMenuManager manager = getEditorSite().getActionBars().getMenuManager();
graphMenu = new MenuManager("Graph &Menu");
manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, graphMenu);
graphMenu.add(graphZoomContribution);
graphReduceMenu = new MenuManager("Graph &Menu");
manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, graphReduceMenu);
graphReduceMenu.add(graphReduceZoomContribution);
getEditorSite().getActionBars().updateActionBars();
}
......
Supports Markdown
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