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
No related branches found
No related tags found
No related merge requests found
...@@ -384,6 +384,9 @@ ...@@ -384,6 +384,9 @@
<control <control
id="de.bmotionstudio.gef.editor.table"> id="de.bmotionstudio.gef.editor.table">
</control> </control>
<control
id="de.bmotionstudio.gef.editor.tablecolumn">
</control>
</observer> </observer>
<observer <observer
id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates">
...@@ -474,6 +477,9 @@ ...@@ -474,6 +477,9 @@
<control <control
id="de.bmotionstudio.gef.editor.table"> id="de.bmotionstudio.gef.editor.table">
</control> </control>
<control
id="de.bmotionstudio.gef.editor.tablecolumn">
</control>
</observer> </observer>
<observer <observer
id="de.bmotionstudio.gef.editor.observer.SwitchChildCoordinates"> id="de.bmotionstudio.gef.editor.observer.SwitchChildCoordinates">
...@@ -522,6 +528,9 @@ ...@@ -522,6 +528,9 @@
<control <control
id="de.bmotionstudio.gef.editor.table"> id="de.bmotionstudio.gef.editor.table">
</control> </control>
<control
id="de.bmotionstudio.gef.editor.tablecolumn">
</control>
</observer> </observer>
<observer <observer
id="de.bmotionstudio.gef.editor.observer.SwitchImage"> id="de.bmotionstudio.gef.editor.observer.SwitchImage">
......
package de.bmotionstudio.gef.editor.observer; 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.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; import de.bmotionstudio.gef.editor.attribute.AbstractAttribute;
import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardColumnObserver; import de.bmotionstudio.gef.editor.observer.wizard.WizardColumnObserver;
import de.bmotionstudio.gef.editor.util.BMSUtil; import de.bmotionstudio.gef.editor.util.BMSUtil;
import de.prob.unicode.UnicodeTranslator;
public class ColumnObserver extends Observer { public class ColumnObserver extends Observer {
private String expression; private String expression;
private String predicate; 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 @Override
public void check(Animation animation, BControl control) { public void check(Animation animation, BControl control) {
...@@ -25,8 +46,10 @@ public class ColumnObserver extends Observer { ...@@ -25,8 +46,10 @@ public class ColumnObserver extends Observer {
String fEval = BMSUtil.parseExpression(expression, control, String fEval = BMSUtil.parseExpression(expression, control,
animation); animation);
fEval = fEval.replace("}", "").replace("{", ""); fEval = UnicodeTranslator.toAscii(fEval);
String[] splitArray = fEval.split(","); fEval = fEval.replaceAll("^\\{", "");
fEval = fEval.replaceAll("\\}$", "");
List<String> output = split(fEval, '#');
AbstractAttribute attributeRows = control.getParent().getAttribute( AbstractAttribute attributeRows = control.getParent().getAttribute(
AttributeConstants.ATTRIBUTE_ROWS); AttributeConstants.ATTRIBUTE_ROWS);
...@@ -36,13 +59,16 @@ public class ColumnObserver extends Observer { ...@@ -36,13 +59,16 @@ public class ColumnObserver extends Observer {
control.getParent().setAttributeValue( control.getParent().setAttributeValue(
AttributeConstants.ATTRIBUTE_ROWS, 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() control.getChildrenArray()
.get(i) .get(i)
.setAttributeValue(AttributeConstants.ATTRIBUTE_TEXT, .setAttributeValue(AttributeConstants.ATTRIBUTE_TEXT,
splitArray[i - defaultRows]); val);
} }
} }
......
package de.bmotionstudio.gef.editor.observer; 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.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; import de.bmotionstudio.gef.editor.attribute.AbstractAttribute;
...@@ -13,6 +20,41 @@ public class TableObserver extends Observer { ...@@ -13,6 +20,41 @@ public class TableObserver extends Observer {
private String expression; private String expression;
private String predicate; 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 @Override
public void check(Animation animation, BControl control) { public void check(Animation animation, BControl control) {
...@@ -26,12 +68,15 @@ public class TableObserver extends Observer { ...@@ -26,12 +68,15 @@ public class TableObserver extends Observer {
String fEval = BMSUtil.parseExpression(expression, control, String fEval = BMSUtil.parseExpression(expression, control,
animation); animation);
fEval = UnicodeTranslator.toAscii(fEval);
fEval = fEval.replaceAll("^\\{", "");
fEval = fEval.replaceAll("\\}$", "");
fEval = fEval.replace("}", "").replace("{", "").replace(")", "") // System.out.println(fEval);
.replace("(", "");
String[] splitArray = fEval.split(",");
// --------------------------------------------------------------- // String input = "aa, a, aa, {bb, 1, 2}, {cc}, {dd,5}";
String input = fEval;
List<String> rows = split(input, '#');
AbstractAttribute attributeRows = control AbstractAttribute attributeRows = control
.getAttribute(AttributeConstants.ATTRIBUTE_ROWS); .getAttribute(AttributeConstants.ATTRIBUTE_ROWS);
...@@ -43,7 +88,7 @@ public class TableObserver extends Observer { ...@@ -43,7 +88,7 @@ public class TableObserver extends Observer {
Integer numberOfOldColumns = Integer.valueOf(attributeColumns Integer numberOfOldColumns = Integer.valueOf(attributeColumns
.getInitValue().toString()); .getInitValue().toString());
int numberOfNewRows = splitArray.length; int numberOfNewRows = rows.size();
// Set the correct number of rows // Set the correct number of rows
control.setAttributeValue(AttributeConstants.ATTRIBUTE_ROWS, control.setAttributeValue(AttributeConstants.ATTRIBUTE_ROWS,
...@@ -54,11 +99,14 @@ public class TableObserver extends Observer { ...@@ -54,11 +99,14 @@ public class TableObserver extends Observer {
// Set content and the correct number of columns // Set content and the correct number of columns
for (int i = numberOfOldRows; i < numberOfNewRows + numberOfOldRows; i++) { for (int i = numberOfOldRows; i < numberOfNewRows + numberOfOldRows; i++) {
String content = UnicodeTranslator.toAscii( String content = UnicodeTranslator.toAscii(rows.get(i
splitArray[i - numberOfOldRows]).replace("|->", ","); - numberOfOldRows));
String[] vals = content.split(","); content = content.replaceAll("^\\(", "");
int numberOfNewColumns = vals.length; content = content.replaceAll("\\)$", "");
List<String> columns = split2(content, '#');
int numberOfNewColumns = columns.size();
// Set only one time the number of columns! // Set only one time the number of columns!
if (!setColumns) { if (!setColumns) {
...@@ -72,9 +120,11 @@ public class TableObserver extends Observer { ...@@ -72,9 +120,11 @@ public class TableObserver extends Observer {
} }
for (int z = 0; z < numberOfNewColumns; z++) { for (int z = 0; z < numberOfNewColumns; z++) {
String val = vals[z]; String val = columns.get(z);
BControl column = control.getChildrenArray().get(z); BControl column = control.getChildrenArray().get(z);
BControl cell = column.getChildrenArray().get(i); BControl cell = column.getChildrenArray().get(i);
if (val != null && val.length() > 0)
val = UnicodeTranslator.toUnicode(val);
cell.setAttributeValue(AttributeConstants.ATTRIBUTE_TEXT, cell.setAttributeValue(AttributeConstants.ATTRIBUTE_TEXT,
val); val);
} }
...@@ -85,6 +135,13 @@ public class TableObserver extends Observer { ...@@ -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) { public void setExpression(String expression) {
this.expression = expression; this.expression = expression;
} }
......
...@@ -26,6 +26,8 @@ import org.eclipse.swt.widgets.Display; ...@@ -26,6 +26,8 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text; 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 org.eventb.core.ast.PowerSetType;
import de.bmotionstudio.gef.editor.eventb.EventBHelper; import de.bmotionstudio.gef.editor.eventb.EventBHelper;
...@@ -34,6 +36,7 @@ import de.bmotionstudio.gef.editor.model.BControl; ...@@ -34,6 +36,7 @@ import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.Observer; import de.bmotionstudio.gef.editor.observer.Observer;
import de.bmotionstudio.gef.editor.observer.ObserverWizard; import de.bmotionstudio.gef.editor.observer.ObserverWizard;
import de.bmotionstudio.gef.editor.observer.TableObserver; import de.bmotionstudio.gef.editor.observer.TableObserver;
import de.prob.unicode.UnicodeTranslator;
public class WizardTableObserver extends ObserverWizard { public class WizardTableObserver extends ObserverWizard {
...@@ -90,16 +93,26 @@ public class WizardTableObserver extends ObserverWizard { ...@@ -90,16 +93,26 @@ public class WizardTableObserver extends ObserverWizard {
java.util.List<MachineContentObject> constants = EventBHelper java.util.List<MachineContentObject> constants = EventBHelper
.getConstants(getBControl().getVisualization()); .getConstants(getBControl().getVisualization());
for (MachineContentObject mobj : constants) { 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()); relationList.add(mobj.getLabel());
} }
}
java.util.List<MachineContentObject> variables = EventBHelper java.util.List<MachineContentObject> variables = EventBHelper
.getVariables(getBControl().getVisualization()); .getVariables(getBControl().getVisualization());
for (MachineContentObject mobj : variables) { 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()); relationList.add(mobj.getLabel());
} }
}
final List list = new List(conRight, SWT.SINGLE | SWT.BORDER); final List list = new List(conRight, SWT.SINGLE | SWT.BORDER);
list.setLayoutData(new GridData(GridData.FILL_BOTH)); 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