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

added table observer for relations

parent 6a4749ba
No related branches found
No related tags found
No related merge requests found
...@@ -291,9 +291,13 @@ ...@@ -291,9 +291,13 @@
name="External Observer Script"> name="External Observer Script">
</observer> </observer>
<observer <observer
class="de.bmotionstudio.gef.editor.observer.ColumnObserver" class="de.bmotionstudio.gef.editor.observer.TableObserver"
name="Table Observer"> name="Table Observer">
</observer> </observer>
<observer
class="de.bmotionstudio.gef.editor.observer.ColumnObserver"
name="Column Observer">
</observer>
</extension> </extension>
<extension <extension
point="de.bmotionstudio.gef.editor.schedulerEvent"> point="de.bmotionstudio.gef.editor.schedulerEvent">
...@@ -537,7 +541,13 @@ ...@@ -537,7 +541,13 @@
<observer <observer
id="de.bmotionstudio.gef.editor.observer.ColumnObserver"> id="de.bmotionstudio.gef.editor.observer.ColumnObserver">
<control <control
id="de.bmotionstudio.gef.editor.tablecell"> id="de.bmotionstudio.gef.editor.tablecolumn">
</control>
</observer>
<observer
id="de.bmotionstudio.gef.editor.observer.TableObserver">
<control
id="de.bmotionstudio.gef.editor.table">
</control> </control>
</observer> </observer>
</include> </include>
......
...@@ -2,10 +2,10 @@ package de.bmotionstudio.gef.editor.observer; ...@@ -2,10 +2,10 @@ package de.bmotionstudio.gef.editor.observer;
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.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 {
...@@ -25,53 +25,24 @@ public class ColumnObserver extends Observer { ...@@ -25,53 +25,24 @@ public class ColumnObserver extends Observer {
String fEval = BMSUtil.parseExpression(expression, control, String fEval = BMSUtil.parseExpression(expression, control,
animation); animation);
fEval = fEval.replace("}", "").replace("{", "");
fEval = fEval.replace("}", "").replace("{", "").replace(")", "")
.replace("(", "");
String[] splitArray = fEval.split(","); String[] splitArray = fEval.split(",");
// --------------------------------------------------------------- AbstractAttribute attributeRows = control.getParent().getAttribute(
AttributeConstants.ATTRIBUTE_ROWS);
int numberOfRows = splitArray.length;
BControl tableControl = control.getParent().getParent();
// Set the correct number of rows
tableControl
.setAttributeValue(AttributeConstants.ATTRIBUTE_ROWS,
numberOfRows, true, false);
System.out.println("number of rows: " + numberOfRows);
boolean setColumns = false;
// Set content and the correct number of columns Integer defaultRows = Integer.valueOf(attributeRows.getInitValue()
for (int i = 0; i < numberOfRows; i++) { .toString());
String content = UnicodeTranslator.toAscii(splitArray[i]) control.getParent().setAttributeValue(
.replace("|->", ","); AttributeConstants.ATTRIBUTE_ROWS,
defaultRows + splitArray.length, true, false);
String[] vals = content.split(",");
int numberOfColumns = vals.length;
// Set only one time the number of columns!
if (!setColumns) {
tableControl
.setAttributeValue(
AttributeConstants.ATTRIBUTE_COLUMNS,
numberOfColumns, true, false);
setColumns = true;
System.out.println("number of columns: " + numberOfColumns);
}
for (int z = 0; z < numberOfColumns; z++) {
String val = vals[z];
BControl column = tableControl.getChildrenArray().get(z);
BControl cell = column.getChildrenArray().get(i);
cell.setAttributeValue(AttributeConstants.ATTRIBUTE_TEXT,
val);
}
for (int i = defaultRows; i < splitArray.length + defaultRows; i++) {
control.getChildrenArray()
.get(i)
.setAttributeValue(AttributeConstants.ATTRIBUTE_TEXT,
splitArray[i - defaultRows]);
} }
} }
......
package de.bmotionstudio.gef.editor.observer;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardTableObserver;
import de.bmotionstudio.gef.editor.util.BMSUtil;
import de.prob.unicode.UnicodeTranslator;
public class TableObserver extends Observer {
private String expression;
private String predicate;
@Override
public void check(Animation animation, BControl control) {
// First evaluate predicate (predicate field)
String bolValue = "true";
if (predicate != null && predicate.length() > 0) {
bolValue = BMSUtil.parsePredicate(predicate, control, animation);
}
if (Boolean.valueOf(bolValue)) {
String fEval = BMSUtil.parseExpression(expression, control,
animation);
fEval = fEval.replace("}", "").replace("{", "").replace(")", "")
.replace("(", "");
String[] splitArray = fEval.split(",");
// ---------------------------------------------------------------
Integer numberOfOldRows = Integer.valueOf(control
.getAttributeValue(AttributeConstants.ATTRIBUTE_ROWS)
.toString());
Integer numberOfOldColumns = Integer.valueOf(control
.getAttributeValue(AttributeConstants.ATTRIBUTE_COLUMNS)
.toString());
int numberOfNewRows = splitArray.length;
// Set the correct number of rows
control.setAttributeValue(AttributeConstants.ATTRIBUTE_ROWS,
numberOfNewRows + numberOfOldRows, true, false);
boolean setColumns = false;
// 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[] vals = content.split(",");
int numberOfNewColumns = vals.length;
// Set only one time the number of columns!
if (!setColumns) {
int ncolumns = numberOfNewColumns;
if (numberOfOldColumns > numberOfNewColumns)
ncolumns = numberOfOldColumns;
control.setAttributeValue(
AttributeConstants.ATTRIBUTE_COLUMNS, ncolumns,
true, false);
setColumns = true;
}
for (int z = 0; z < numberOfNewColumns; z++) {
String val = vals[z];
BControl column = control.getChildrenArray().get(z);
BControl cell = column.getChildrenArray().get(i);
cell.setAttributeValue(AttributeConstants.ATTRIBUTE_TEXT,
val);
}
}
}
}
public void setExpression(String expression) {
this.expression = expression;
}
public String getExpression() {
return expression;
}
public String getPredicate() {
return predicate;
}
public void setPredicate(String predicate) {
this.predicate = predicate;
}
@Override
public ObserverWizard getWizard(BControl control) {
return new WizardTableObserver(control, this);
}
}
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.bmotionstudio.gef.editor.observer.wizard;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
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;
public class WizardTableObserver extends ObserverWizard {
private class TableObserverPage extends WizardPage {
private Text txtExpression;
private Text txtPredicate;
public Text getTxtExpression() {
return txtExpression;
}
protected TableObserverPage(final String pageName) {
super(pageName);
}
public void createControl(final Composite parent) {
final DataBindingContext dbc = new DataBindingContext();
Composite container = new Composite(parent, SWT.NONE);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
container.setLayout(new GridLayout(2, false));
Label lb = new Label(container, SWT.NONE);
lb.setText("Predicate:");
txtPredicate = new Text(container, SWT.BORDER);
txtPredicate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
txtPredicate.setFont(new Font(Display.getDefault(), new FontData(
"Arial", 10, SWT.NONE)));
lb = new Label(container, SWT.NONE);
lb.setText("Expression:");
lb.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
txtExpression = new Text(container, SWT.BORDER | SWT.MULTI
| SWT.WRAP);
txtExpression.setLayoutData(new GridData(GridData.FILL_BOTH));
initBindings(dbc);
setControl(container);
}
private void initBindings(DataBindingContext dbc) {
dbc.bindValue(SWTObservables.observeText(txtPredicate, SWT.Modify),
BeansObservables.observeValue(
(TableObserver) getObserver(), "predicate"));
dbc.bindValue(
SWTObservables.observeText(txtExpression, SWT.Modify),
BeansObservables.observeValue(
(TableObserver) getObserver(), "expression"));
}
}
public WizardTableObserver(BControl bcontrol,
Observer bobserver) {
super(bcontrol, bobserver);
addPage(new TableObserverPage("TableObserverPage"));
}
@Override
protected Boolean prepareToFinish() {
TableObserverPage page = (TableObserverPage) getPage("TableObserverPage");
String errorStr = "";
if (page.getTxtExpression().getText().length() == 0)
errorStr += "Please enter an expression.\n";
if (page.getErrorMessage() != null)
errorStr += "Please check the syntax/parser error.\n";
if (errorStr.length() > 0) {
MessageDialog.openError(Display.getDefault().getActiveShell(),
"An Error occured", errorStr);
return false;
}
return true;
}
@Override
public Point getSize() {
return new Point(600, 500);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment