Commit 596a488b authored by Johannes Roith's avatar Johannes Roith

Add counters.

parent 8419c9ac
package de.tum.in.www2.cupplugin.editors;
import java.util.EnumSet;
import java.util.HashMap;
import org.eclipse.core.resources.IMarker;
......@@ -23,8 +24,17 @@ import org.eclipse.ui.ide.IDE;
import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart;
import org.eclipse.zest.core.viewers.ZoomContributionViewItem;
import de.in.tum.www2.cup.ConflictManager;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.internal.parse_action_table;
import de.in.tum.www2.cup.internal.parse_reduce_table;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.controller.IRegisterForControllerChanges;
import de.tum.in.www2.cupplugin.controller.JobStatus;
import de.tum.in.www2.cupplugin.debug.Debugger;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
import de.tum.in.www2.cupplugin.views.CupActionTableView;
import de.tum.in.www2.cupplugin.views.CupConflictGraphView;
import de.tum.in.www2.cupplugin.views.CupConflictsView;
......@@ -32,8 +42,10 @@ import de.tum.in.www2.cupplugin.views.CupOverviewView;
import de.tum.in.www2.cupplugin.views.CupReduceGraphView;
import de.tum.in.www2.cupplugin.views.CupReduceTableView;
public class MultiPageEditor extends MultiPageEditorPart implements
IResourceChangeListener {
public class MultiPageEditor extends MultiPageEditorPart
implements IRegisterForControllerChanges,
ICupParserLaLrChangeObserver,
IResourceChangeListener {
private CupTextEditor editor;
private ZoomContributionViewItem graphReduceZoomContribution;
......@@ -70,7 +82,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements
return conflictGraphView;
}
void setCounter(int pageIndex, int counter) {
private void setCounter(int pageIndex, int counter) {
boolean update = false;
if (counters.containsKey(pageIndex)) {
if (counters.get(pageIndex) == counter)
......@@ -84,7 +96,8 @@ public class MultiPageEditor extends MultiPageEditorPart implements
oldText = oldText.substring(0, index);
} else
oldText += " ";
setPageText(pageIndex, oldText + "(" + counter + ")");
String counterString = (counter == -1) ? "?" : "" + counter;
setPageText(pageIndex, oldText + "(" + counterString + ")");
}
void createEditorPage(Jumper jumper) {
......@@ -155,10 +168,15 @@ public class MultiPageEditor extends MultiPageEditorPart implements
addPage(CONFLICT_GRAPH_PAGE_INDEX, composite);
setPageText(CONFLICT_GRAPH_PAGE_INDEX, "Conflict Graph");
}
protected void createPages() {
Jumper jumper = new Jumper(this);
createEditorPage(jumper);
// only register after editor has been created.
Controller.getInstance(getEditor()).registerObserver(this);
Model.getInstanceForDocument(getEditor().getDocument()).registerModelObserver(this);
createOverviewPage(jumper);
createConflictsPage(jumper);
createGraphPage(jumper);
......@@ -324,4 +342,43 @@ public class MultiPageEditor extends MultiPageEditorPart implements
menu.remove(contItem);
//manager.remove(contItem);
}
@Override
public EnumSet<JobsToDo> getRequiredJobs() {
// We do only observe jobs, never request them!
return EnumSet.noneOf(JobsToDo.class);
}
@Override
public void jobStatusChanged(JobStatus status) {
if (status.getAffectedJob() == JobsToDo.buildTable) {
if (status.hasFailed()) {
setCounter(CONFLICTS_PAGE_INDEX, -1);
setCounter(GRAPH_PAGE_INDEX, -1);
// setCounter(ACTION_TABLE_PAGE_INDEX, -1);
// setCounter(REDUCE_TABLE_PAGE_INDEX, -1);
}
}
}
@Override
public void modelChanged(Model model) {
LALRResult result = model.getLaLrResult();
if (result == null)
return;
ConflictManager cm = result.getContext().getConflictManager();
setCounter(CONFLICTS_PAGE_INDEX, cm.getConflicts().size());
parse_action_table actionTable = result.getActionTable();
setCounter(GRAPH_PAGE_INDEX, actionTable.num_states());
/* parse_action_table actionTable = result.getActionTable();
if (actionTable != null)
setCounter(ACTION_TABLE_PAGE_INDEX, actionTable.num_states());
parse_reduce_table reduceTable = result.getReduceTable();
if (reduceTable != null)
setCounter(REDUCE_TABLE_PAGE_INDEX, reduceTable.num_states());
*/
}
}
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