Commit fc0f1ec1 authored by Johannes Roith's avatar Johannes Roith

- Links work now.

- Some cosmetic fixes.
parent 9d288869
......@@ -10,6 +10,8 @@ import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
......@@ -23,11 +25,13 @@ import org.eclipse.ui.forms.widgets.TableWrapLayout;
import de.in.tum.www2.cup.Conflict;
import de.in.tum.www2.cup.ConflictManager;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.Range;
import de.in.tum.www2.cup.ReduceReduceConflict;
import de.in.tum.www2.cup.ShiftReduceConflict;
import de.in.tum.www2.cup.ast.ParserResult;
import de.in.tum.www2.cup.ast.ProductionRight;
import de.in.tum.www2.cup.internal.internal_error;
import de.in.tum.www2.cup.internal.lalr_item;
import de.tum.in.www2.cupplugin.Colors;
import de.tum.in.www2.cupplugin.PluginUtility;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
......@@ -40,7 +44,7 @@ import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupConflictsView implements ICupEditorPageVisibility,
ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
private static final int OUTER_MARGIN = 10; // TODO: share between panels.
private Jumper jumper;
......@@ -54,96 +58,129 @@ ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
private Label conflictTypeLabel;
private Label stateLabel;
private Link detailText;
private List<Range> links = new ArrayList<Range>();
public ConflictPanel(Composite parent, int style) {
super(parent, style);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
data.grabExcessHorizontalSpace = true;
data.widthHint = 100; // Do not remove. This is a bugfix. :-)
data.heightHint = 80;
setLayoutData(data);
setLayoutData(data);
setBackground(new Color(Display.getCurrent(), Colors.lightGray));
TableWrapLayout layout = new TableWrapLayout();
layout.numColumns = 2;
layout.verticalSpacing = 3;
setLayout(layout);
this.conflictTypeLabel = new Label(this, SWT.NONE);
FontData[] fD = conflictTypeLabel.getFont().getFontData();
fD[0].setHeight(14);
conflictTypeLabel.setFont( new Font(Display.getCurrent(),fD[0]));
this.stateLabel = new Label(this, SWT.NONE);
this.detailText = new Link(this, SWT.WRAP);
this.detailText.setBackground(new Color(Display.getCurrent(), Colors.lightGray));
this.detailText.setBackground(new Color(Display.getCurrent(),
Colors.lightGray));
TableWrapData td = new TableWrapData();
td.colspan = 1;
detailText.setLayoutData(td);
TableWrapData td = new TableWrapData();
td.colspan = 1;
detailText.setLayoutData(td);
detailText.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
jumper.jumpToEditorSelection(links.get(Integer
.parseInt(e.text)));
System.out.println(e.text);
}
});
}
public void update(Conflict conflict) {
stateLabel.setText("State: " + conflict.getState().index());
if (conflict instanceof ReduceReduceConflict) {
conflictTypeLabel.setText("Reduce-Reduce conflict");
detailText.setText("");
// TODO!
} else if (conflict instanceof ShiftReduceConflict) {
ShiftReduceConflict src = (ShiftReduceConflict) conflict;
conflictTypeLabel.setText("Shift-Reduce conflict");
ProductionRight conflict1Ast = src.getConflictItem1().the_production().getAstNode();
ProductionRight conflict1Ast = src.getConflictItem1()
.the_production().getAstNode();
links.clear();
int linkCounter = 0;
StringBuilder builder = new StringBuilder();
builder.append("Conflict between ");
builder.append("<a href=\"conflict1Production\">");
if (conflict1Ast != null) {
builder.append("<a href=\"" + linkCounter++ + "\">");
links.add(conflict1Ast.getRange());
}
try {
builder.append(src.getConflictItem1().to_simple_string());
} catch (internal_error e1) {
e1.printStackTrace();
}
builder.append("</a>");
builder.append(" and other <a href=\"test2\">items</a>.");
if (conflict1Ast != null)
builder.append("</a>");
builder.append(" and ");
int size = src.getConflictItems2().size();
for (int i = 0; i < size; i++) {
lalr_item item = src.getConflictItems2().get(i);
ProductionRight conflict2ItemAst = item.the_production()
.getAstNode();
if (conflict2ItemAst != null) {
builder.append("<a href=\"" + linkCounter++ + "\">");
links.add(conflict1Ast.getRange());
}
try {
builder.append(item.to_simple_string());
} catch (internal_error e1) {
e1.printStackTrace();
}
if (conflict2ItemAst != null)
builder.append("</a>");
if (i != size - 1)
builder.append(", ");
}
detailText.setText(builder.toString());
detailText.setBackground(new Color(Display.getCurrent(), Colors.lightGray));
// TODO: this MUST not be set here, because the link item is reused!
detailText.addSelectionListener(new SelectionAdapter(){
@Override
public void widgetSelected(SelectionEvent e) {
if (e.text.equals("conflict1Production")) {
if (conflict1Ast != null)
jumper.jumpToEditorSelection(conflict1Ast.getRange());
else
PluginUtility.showMessage("This item does not have a matching AST node.");
}
System.out.println(e.text);
}
});
detailText.setBackground(new Color(Display.getCurrent(),
Colors.lightGray));
} else {
throw new RuntimeException("unexpected conflict type.");
}
stateLabel.setText("State: " + conflict.getState().index());
}
}
public CupConflictsView(Composite parent, Jumper jumper, CupTextEditor editor) {
public CupConflictsView(Composite parent, Jumper jumper,
CupTextEditor editor) {
this.editor = editor;
this.jumper = jumper;
this.conflictPanels = new ArrayList<ConflictPanel> ();
this.conflictPanels = new ArrayList<ConflictPanel>();
Controller.getInstance(editor).registerObserver(this);
Model.getInstanceForDocument(editor.getDocument()).registerModelObserver(this);
Model.getInstanceForDocument(editor.getDocument())
.registerModelObserver(this);
parent.setBackground(new Color(parent.getDisplay(), Colors.white));
FillLayout fillLayout = new FillLayout();
fillLayout.marginWidth = OUTER_MARGIN;
fillLayout.marginHeight = OUTER_MARGIN;
fillLayout.marginWidth = OUTER_MARGIN;
fillLayout.marginHeight = OUTER_MARGIN;
parent.setLayout(fillLayout);
this.scrolled = new ScrolledComposite(parent, SWT.V_SCROLL);
this.scrolled.setExpandHorizontal(true);
this.scrolled.setExpandVertical(true);
......@@ -156,39 +193,40 @@ ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
gl.numColumns = 1;
gl.makeColumnsEqualWidth = true;
list.setLayout(gl);
refreshScrolledLayout ();
refreshScrolledLayout();
}
private void updateConflicts(List<Conflict> conflicts) {
int size = conflicts.size();
matchPanelNumber(size);
for (int i=0; i < size; i++) {
for (int i = 0; i < size; i++) {
Conflict conflict = conflicts.get(i);
ConflictPanel panel = conflictPanels.get(i);
panel.update(conflict);
}
refreshScrolledLayout ();
refreshScrolledLayout();
}
private void matchPanelNumber(int number) {
int excessPanels = this.conflictPanels.size() - number;
if (excessPanels > 0) {
for (int i=0; i < excessPanels; i++)
for (int i = 0; i < excessPanels; i++)
this.conflictPanels.remove(0);
} else {
while (this.conflictPanels.size() < number) {
conflictPanels.add (new ConflictPanel(list, SWT.NONE));
conflictPanels.add(new ConflictPanel(list, SWT.NONE));
}
}
System.out.println("conflictPanels size: " + this.conflictPanels.size());
System.out
.println("conflictPanels size: " + this.conflictPanels.size());
}
private void refreshScrolledLayout() {
scrolled.layout(true, true);
scrolled.setMinSize(list.computeSize(SWT.DEFAULT, SWT.DEFAULT));
scrolled.setMinSize(list.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
public void dispose() {
......@@ -208,7 +246,7 @@ ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
}
}
}
@Override
public void becameHidden() {
this.isVisible = false;
......@@ -230,7 +268,7 @@ ICupParserLaLrChangeObserver, IRegisterForControllerChanges {
updateConflicts(cm.getConflicts());
} else {
matchPanelNumber(0);
}
}
}
}
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