Commit 79cd1699 authored by Johannes Roith's avatar Johannes Roith

- Add a FailableView base class that allows views to replace their content...

- Add a FailableView base class that allows views to replace their content with an error/status message.
- Make existing views "failable".
- Some changes in Conflicts view.
parent 96af5d5e
......@@ -35,7 +35,7 @@ import de.tum.in.www2.cupplugin.editors.Jumper;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupActionTableView implements ICupEditorPageVisibility,
public class CupActionTableView extends FailableView implements ICupEditorPageVisibility,
ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
private CupTextEditor editor;
......@@ -44,7 +44,10 @@ public class CupActionTableView implements ICupEditorPageVisibility,
private boolean isVisible = false;
private List<ActionNode> stateList;
public CupActionTableView(Composite parent, Jumper jumper, CupTextEditor editor) {
public CupActionTableView(Composite realParent, Jumper jumper, CupTextEditor editor) {
super(realParent);
Composite parent = getMain();
this.editor = editor;
this.doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
......
......@@ -81,7 +81,8 @@ import de.tum.in.www2.cupplugin.editors.Jumper;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
public class CupConflictGraphView extends FailableView
implements ICupParserLaLrChangeObserver,
IZoomableWorkbenchPart, ICupEditorPageVisibility,
IRegisterForControllerChanges {
......@@ -113,8 +114,11 @@ public class CupConflictGraphView implements ICupParserLaLrChangeObserver,
private HashSet<lalr_state> visitedStates;
private ConflictResolutionManager conflictResolutionManager;
public CupConflictGraphView(Composite parent, Jumper jumper,
public CupConflictGraphView(Composite realParent, Jumper jumper,
CupTextEditor editor) {
super(realParent);
Composite parent = getMain();
this.editor = editor;
Controller.getInstance(editor).registerObserver(this);
IDocument doc = editor.getDocumentProvider().getDocument(
......
......@@ -40,10 +40,11 @@ import de.tum.in.www2.cupplugin.controller.IRegisterForControllerChanges;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.ICupEditorPageVisibility;
import de.tum.in.www2.cupplugin.editors.Jumper;
import de.tum.in.www2.cupplugin.editors.RevisionManager;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupConflictsView implements ICupEditorPageVisibility,
public class CupConflictsView extends FailableView implements ICupEditorPageVisibility,
ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
private static final int OUTER_MARGIN = 10; // TODO: share between panels.
private static final int INNER_MARGIN = 5;
......@@ -60,7 +61,7 @@ public class CupConflictsView implements ICupEditorPageVisibility,
private static final int BASE_HEIGHT = 90;
private static final int COLUMNS = 3;
private static final int HEADING_FONT_SIZE = 14;
private static final int SIZE_INCREASE_PER_LINE = 8;
private static final int SIZE_INCREASE_PER_LINE = 11;
private Conflict conflict;
......@@ -102,7 +103,7 @@ public class CupConflictsView implements ICupEditorPageVisibility,
this.conflictTypeLabel = new Label(this, SWT.NONE);
FontData[] fD = conflictTypeLabel.getFont().getFontData();
fD[0].setHeight(HEADING_FONT_SIZE);
conflictTypeLabel.setFont( new Font(Display.getCurrent(),fD[0]));
conflictTypeLabel.setFont(new Font(Display.getCurrent(),fD[0]));
this.symbolLabel = new Label(this, SWT.NONE);
this.stateLabel = new Link(this, SWT.NONE);
......@@ -317,8 +318,12 @@ public class CupConflictsView implements ICupEditorPageVisibility,
}
public CupConflictsView(Composite parent, Jumper jumper,
public CupConflictsView(Composite realParent, Jumper jumper,
CupTextEditor editor) {
super(realParent);
Composite parent = getMain();
this.editor = editor;
this.jumper = jumper;
this.conflictPanels = new ArrayList<ConflictPanel>();
......@@ -345,7 +350,7 @@ public class CupConflictsView implements ICupEditorPageVisibility,
gl.numColumns = 1;
gl.makeColumnsEqualWidth = true;
list.setLayout(gl);
refreshScrolledLayout();
}
......@@ -386,20 +391,43 @@ public class CupConflictsView implements ICupEditorPageVisibility,
System.out.println("CupConflictsView disposed!");
}
private void handleModelUpdate(Model model) {
LALRResult result = model.getLaLrResult();
if (result != null) {
if (model.getLaLrRevisionNumber() == RevisionManager.get(editor.getDocument())) {
ConflictResolutionManager crm = new ConflictResolutionManager(result.getContext());
updateConflicts(crm);
showMain();
} else {
showError("Parse Tables do not match the current document.");
}
} else {
showError("Parse Tables currently not available.");
matchPanelNumber(0);
}
}
@Override
public void willBecomeVisible() {
this.isVisible = true;
if (!Controller.getInstance(editor).requestJobRun()) {
// the requested job won't run.
System.out.println("NO RERUN!!!"); // TODO
Model model = Model.getInstanceForDocument(editor.getDocument());
LALRResult result = model.getLaLrResult();
if (result != null) {
ConflictResolutionManager crm = new ConflictResolutionManager(result.getContext());
updateConflicts(crm);
}
handleModelUpdate(model);
} else {
showError("Requested job run ...");
}
}
@Override
public void modelChanged(Model model) {
handleModelUpdate(model);
}
@Override
public void becameHidden() {
this.isVisible = false;
......@@ -413,15 +441,4 @@ public class CupConflictsView implements ICupEditorPageVisibility,
return requestedJobs;
}
@Override
public void modelChanged(Model model) {
LALRResult result = model.getLaLrResult();
if (result != null) {
ConflictResolutionManager crm = new ConflictResolutionManager(result.getContext());
updateConflicts(crm);
} else {
matchPanelNumber(0);
}
}
}
......@@ -27,7 +27,7 @@ import de.tum.in.www2.cupplugin.model.ICupParserASTChangeObserver;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupOverviewView implements IRegisterForControllerChanges,
public class CupOverviewView extends FailableView implements IRegisterForControllerChanges,
ICupEditorPageVisibility, ICupParserLaLrChangeObserver,
ICupParserASTChangeObserver {
private static final int OUTER_MARGIN = 10;
......@@ -55,8 +55,12 @@ public class CupOverviewView implements IRegisterForControllerChanges,
private CupTextEditor myEditor;
HashSet<Composite> sections = new HashSet<Composite>();
public CupOverviewView(Composite parent, Jumper jumper, IDocument doc,
public CupOverviewView(Composite realParent, Jumper jumper, IDocument doc,
String title, CupTextEditor editor) {
super(realParent);
Composite parent = getMain();
this.doc = doc;
setupForm(parent, title);
myEditor = editor;
......
......@@ -89,7 +89,8 @@ import de.tum.in.www2.cupplugin.editors.Jumper;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupReduceGraphView implements ICupParserLaLrChangeObserver,
public class CupReduceGraphView extends FailableView
implements ICupParserLaLrChangeObserver,
IZoomableWorkbenchPart, ICupEditorPageVisibility,
IRegisterForControllerChanges {
......@@ -118,7 +119,9 @@ public class CupReduceGraphView implements ICupParserLaLrChangeObserver,
private final LayoutAlgorithm layout_big;
public CupReduceGraphView(Composite parent, Jumper jumper, CupTextEditor editor) {
public CupReduceGraphView(Composite realParent, Jumper jumper, CupTextEditor editor) {
super(realParent);
Composite parent = getMain();
this.editor = editor;
Controller.getInstance(editor).registerObserver(this);
IDocument doc = editor.getDocumentProvider().getDocument(
......
......@@ -5,10 +5,11 @@ import org.eclipse.swt.widgets.Composite;
import de.tum.in.www2.cupplugin.editors.Jumper;
public class CupReduceTableView {
public CupReduceTableView(Composite parent, Jumper jumper, IDocument doc) {
public class CupReduceTableView extends FailableView {
public CupReduceTableView(Composite realParent, Jumper jumper, IDocument doc) {
super(realParent);
Composite parent = getMain();
}
public void dispose() {
......
package de.tum.in.www2.cupplugin.views;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
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.Display;
import org.eclipse.swt.widgets.Label;
import de.tum.in.www2.cupplugin.Colors;
public abstract class FailableView {
private static final int VIEW_MAIN = 0;
private static final int VIEW_ERROR = 1;
private static final int ERROR_MARGIN = 10;
private static final int ERROR_FONTSIZE = 20;
private Composite parent;
private StackLayout layout;
private Composite main;
private Composite error;
private Label message;
private String prevError;
private int currentView = -1;
protected Composite getMain() {
return main;
}
protected void showError(String msg) {
System.err.println("show error called!");
if (currentView == VIEW_ERROR && prevError != null && prevError.equals(msg))
return;
this.message.setText(msg);
layout.topControl = error;
currentView = VIEW_ERROR;
parent.layout ();
}
protected void showMain() {
System.err.println("show main called!");
layout.topControl = main;
if (currentView != VIEW_MAIN) {
currentView = VIEW_MAIN;
parent.layout ();
}
}
public FailableView(Composite parent) {
this.parent = parent;
// TODO: testing
parent.setBackground(new Color(parent.getDisplay(), Colors.green));
layout = new StackLayout ();
parent.setLayout (layout);
main = new Composite (parent, SWT.NONE);
error = new Composite (parent, SWT.NONE);
error.setBackground(new Color(parent.getDisplay(), Colors.white));
Display display = Display.getCurrent();
ClassLoader cl = this.getClass().getClassLoader();
error.setBackgroundImage(new Image(display, cl.getResourceAsStream("/icons/cup_blurred_light2.jpg")));
GridLayout fillLayout = new GridLayout();
fillLayout.numColumns = 1;
fillLayout.marginWidth = ERROR_MARGIN;
fillLayout.marginHeight = ERROR_MARGIN;
error.setLayout(fillLayout);
message = new Label (error, SWT.CENTER);
FontData[] fD = message.getFont().getFontData();
fD[0].setHeight(ERROR_FONTSIZE);
message.setFont(new Font(Display.getCurrent(),fD[0]));
message.setText("ERROR");
message.setForeground(new Color(parent.getDisplay(), Colors.purple));
GridData gd = new GridData();
gd.widthHint = 100;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.horizontalAlignment = GridData.FILL;
gd.verticalAlignment = SWT.CENTER;
message.setLayoutData(gd);
showMain();
}
}
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