Skip to content
Snippets Groups Projects
Commit 8e72a001 authored by Lukas Ladenberger's avatar Lukas Ladenberger
Browse files

working on table + corresponding observer

parent 0624da31
Branches
Tags
No related merge requests found
......@@ -384,6 +384,9 @@
<control
id="de.bmotionstudio.gef.editor.table">
</control>
<control
id="de.bmotionstudio.gef.editor.tablecolumn">
</control>
</observer>
<observer
id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates">
......@@ -474,6 +477,9 @@
<control
id="de.bmotionstudio.gef.editor.table">
</control>
<control
id="de.bmotionstudio.gef.editor.tablecolumn">
</control>
</observer>
<observer
id="de.bmotionstudio.gef.editor.observer.SwitchChildCoordinates">
......@@ -522,6 +528,9 @@
<control
id="de.bmotionstudio.gef.editor.table">
</control>
<control
id="de.bmotionstudio.gef.editor.tablecolumn">
</control>
</observer>
<observer
id="de.bmotionstudio.gef.editor.observer.SwitchImage">
......
package de.bmotionstudio.gef.editor.observer;
import java.util.LinkedList;
import java.util.List;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.attribute.AbstractAttribute;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardColumnObserver;
import de.bmotionstudio.gef.editor.util.BMSUtil;
import de.prob.unicode.UnicodeTranslator;
public class ColumnObserver extends Observer {
private String expression;
private String predicate;
public static List<String> split(String input, char tempReplacement) {
while (input.matches(".*\"[^\\{\\}]+,[^\\{\\}]+.*")) {
input = input.replaceAll("(\"[^\\{\\}]+),([^\\{\\}]+)", "$1"
+ tempReplacement + "$2");
}
while (input.matches(".*\\{[^\\}]+,[^\\}]+\\}.*")) {
input = input.replaceAll("(\\{[^\\}]+),([^\\}]+\\})", "$1"
+ tempReplacement + "$2");
}
String[] split = input.split(",");
List<String> output = new LinkedList<String>();
for (String s : split) {
output.add(s.replaceAll(tempReplacement + "", ",").trim());
}
return output;
}
@Override
public void check(Animation animation, BControl control) {
......@@ -25,8 +46,10 @@ public class ColumnObserver extends Observer {
String fEval = BMSUtil.parseExpression(expression, control,
animation);
fEval = fEval.replace("}", "").replace("{", "");
String[] splitArray = fEval.split(",");
fEval = UnicodeTranslator.toAscii(fEval);
fEval = fEval.replaceAll("^\\{", "");
fEval = fEval.replaceAll("\\}$", "");
List<String> output = split(fEval, '#');
AbstractAttribute attributeRows = control.getParent().getAttribute(
AttributeConstants.ATTRIBUTE_ROWS);
......@@ -36,13 +59,16 @@ public class ColumnObserver extends Observer {
control.getParent().setAttributeValue(
AttributeConstants.ATTRIBUTE_ROWS,
defaultRows + splitArray.length, true, false);
defaultRows + output.size(), true, false);
for (int i = defaultRows; i < splitArray.length + defaultRows; i++) {
for (int i = defaultRows; i < output.size() + defaultRows; i++) {
String val = output.get(i - defaultRows);
if (val != null && val.length() > 0)
val = UnicodeTranslator.toUnicode(val);
control.getChildrenArray()
.get(i)
.setAttributeValue(AttributeConstants.ATTRIBUTE_TEXT,
splitArray[i - defaultRows]);
val);
}
}
......
package de.bmotionstudio.gef.editor.observer;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.attribute.AbstractAttribute;
......@@ -13,6 +20,41 @@ public class TableObserver extends Observer {
private String expression;
private String predicate;
public static List<String> split(String input, char tempReplacement) {
while (input.matches(".*\"[^\\{\\}]+,[^\\{\\}]+.*")) {
input = input.replaceAll("([^\\{\\}]+),([^\\{\\}]+)", "$1"
+ tempReplacement + "$2");
}
while (input.matches(".*\\{[^\\}]+,[^\\}]+\\}.*")) {
input = input.replaceAll("(\\{[^\\}]+),([^\\}]+\\})", "$1"
+ tempReplacement + "$2");
}
String[] split = input.split(",");
List<String> output = new LinkedList<String>();
for (String s : split) {
output.add(s.replaceAll(tempReplacement + "", ",").trim());
}
return output;
}
public static List<String> split2(String input, char tempReplacement) {
while (input.matches(".*\"[^\\(\\)]+\\|->[^\\(\\)]+.*")) {
input = input.replaceAll("(\"[^\\(\\)]+)\\|->([^\\(\\)]+)", "$1"
+ tempReplacement + "$2");
}
while (input.matches(".*\\([^\\)]+\\|->[^\\)]+\\).*")) {
input = input.replaceAll("(\\([^\\)]+)\\|->([^\\)]+\\))", "$1"
+ tempReplacement + "$2");
}
String[] split = input.split("\\|->");
List<String> output = new LinkedList<String>();
for (String s : split) {
output.add(s.replaceAll(tempReplacement + "", "\\|->").trim());
}
return output;
}
@Override
public void check(Animation animation, BControl control) {
......@@ -26,12 +68,15 @@ public class TableObserver extends Observer {
String fEval = BMSUtil.parseExpression(expression, control,
animation);
fEval = UnicodeTranslator.toAscii(fEval);
fEval = fEval.replaceAll("^\\{", "");
fEval = fEval.replaceAll("\\}$", "");
fEval = fEval.replace("}", "").replace("{", "").replace(")", "")
.replace("(", "");
String[] splitArray = fEval.split(",");
// System.out.println(fEval);
// ---------------------------------------------------------------
// String input = "aa, a, aa, {bb, 1, 2}, {cc}, {dd,5}";
String input = fEval;
List<String> rows = split(input, '#');
AbstractAttribute attributeRows = control
.getAttribute(AttributeConstants.ATTRIBUTE_ROWS);
......@@ -43,7 +88,7 @@ public class TableObserver extends Observer {
Integer numberOfOldColumns = Integer.valueOf(attributeColumns
.getInitValue().toString());
int numberOfNewRows = splitArray.length;
int numberOfNewRows = rows.size();
// Set the correct number of rows
control.setAttributeValue(AttributeConstants.ATTRIBUTE_ROWS,
......@@ -54,11 +99,14 @@ public class TableObserver extends Observer {
// Set content and the correct number of columns
for (int i = numberOfOldRows; i < numberOfNewRows + numberOfOldRows; i++) {
String content = UnicodeTranslator.toAscii(
splitArray[i - numberOfOldRows]).replace("|->", ",");
String content = UnicodeTranslator.toAscii(rows.get(i
- numberOfOldRows));
String[] vals = content.split(",");
int numberOfNewColumns = vals.length;
content = content.replaceAll("^\\(", "");
content = content.replaceAll("\\)$", "");
List<String> columns = split2(content, '#');
int numberOfNewColumns = columns.size();
// Set only one time the number of columns!
if (!setColumns) {
......@@ -72,9 +120,11 @@ public class TableObserver extends Observer {
}
for (int z = 0; z < numberOfNewColumns; z++) {
String val = vals[z];
String val = columns.get(z);
BControl column = control.getChildrenArray().get(z);
BControl cell = column.getChildrenArray().get(i);
if (val != null && val.length() > 0)
val = UnicodeTranslator.toUnicode(val);
cell.setAttributeValue(AttributeConstants.ATTRIBUTE_TEXT,
val);
}
......@@ -85,6 +135,13 @@ public class TableObserver extends Observer {
}
private Iterable<MatchResult> findMatches(String pattern, CharSequence s) {
List<MatchResult> results = new ArrayList<MatchResult>();
for (Matcher m = Pattern.compile(pattern).matcher(s); m.find();)
results.add(m.toMatchResult());
return results;
}
public void setExpression(String expression) {
this.expression = expression;
}
......
......@@ -26,6 +26,8 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
import org.eventb.core.ast.Expression;
import org.eventb.core.ast.FormulaFactory;
import org.eventb.core.ast.PowerSetType;
import de.bmotionstudio.gef.editor.eventb.EventBHelper;
......@@ -34,6 +36,7 @@ import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.Observer;
import de.bmotionstudio.gef.editor.observer.ObserverWizard;
import de.bmotionstudio.gef.editor.observer.TableObserver;
import de.prob.unicode.UnicodeTranslator;
public class WizardTableObserver extends ObserverWizard {
......@@ -90,16 +93,26 @@ public class WizardTableObserver extends ObserverWizard {
java.util.List<MachineContentObject> constants = EventBHelper
.getConstants(getBControl().getVisualization());
for (MachineContentObject mobj : constants) {
if (mobj.getType() instanceof PowerSetType)
if (mobj.getType() instanceof PowerSetType) {
Expression expression = ((PowerSetType) mobj.getType())
.toExpression(FormulaFactory.getDefault());
System.out.println(UnicodeTranslator.toAscii(expression
.toString()));
relationList.add(mobj.getLabel());
}
}
java.util.List<MachineContentObject> variables = EventBHelper
.getVariables(getBControl().getVisualization());
for (MachineContentObject mobj : variables) {
if (mobj.getType() instanceof PowerSetType)
if (mobj.getType() instanceof PowerSetType) {
Expression expression = ((PowerSetType) mobj.getType())
.toExpression(FormulaFactory.getDefault());
System.out.println(UnicodeTranslator.toAscii(expression
.toString()));
relationList.add(mobj.getLabel());
}
}
final List list = new List(conRight, SWT.SINGLE | SWT.BORDER);
list.setLayoutData(new GridData(GridData.FILL_BOTH));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment