[jboss-svn-commits] JBL Code SVN: r25095 - labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Feb 4 04:30:29 EST 2009
Author: Rikkola
Date: 2009-02-04 04:30:29 -0500 (Wed, 04 Feb 2009)
New Revision: 25095
Modified:
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/DSLSentenceWidget.java
Log:
GUVNOR-114: Enumeration widget for DSL dissappears after adding another fact type, or non DSL RHS using business guided editor
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/DSLSentenceWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/DSLSentenceWidget.java 2009-02-04 09:04:08 UTC (rev 25094)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/DSLSentenceWidget.java 2009-02-04 09:30:29 UTC (rev 25095)
@@ -1,4 +1,5 @@
package org.drools.guvnor.client.modeldriven.ui;
+
/*
* Copyright 2005 JBoss Inc
*
@@ -15,8 +16,6 @@
* limitations under the License.
*/
-
-
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
@@ -27,11 +26,9 @@
import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
import org.drools.guvnor.client.modeldriven.brl.DSLSentence;
-import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.ChangeListener;
-import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
@@ -41,14 +38,13 @@
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
-import com.gwtext.client.widgets.Component;
import com.gwtext.client.widgets.DatePicker;
-import com.gwtext.client.widgets.event.DatePickerListener;
import com.gwtext.client.widgets.event.DatePickerListenerAdapter;
import com.gwtext.client.widgets.form.DateField;
/**
* This displays a widget to edit a DSL sentence.
+ *
* @author Michael Neale
*/
public class DSLSentenceWidget extends Composite {
@@ -56,478 +52,516 @@
private static final String ENUM_TAG = "ENUM";
private static final String DATE_TAG = "DATE";
private static final String BOOLEAN_TAG = "BOOLEAN";
- private final List widgets;
- private final DSLSentence sentence;
- private SuggestionCompletionEngine completions;
+ private final List widgets;
+ private final DSLSentence sentence;
+ private SuggestionCompletionEngine completions;
private final VerticalPanel layout;
private HorizontalPanel currentRow;
- public DSLSentenceWidget(DSLSentence sentence, SuggestionCompletionEngine completions) {
- widgets = new ArrayList();
- this.sentence = sentence;
- this.completions = completions;
- this.layout = new VerticalPanel();
- this.currentRow = new HorizontalPanel();
- this.layout.add(currentRow);
- this.layout.setCellWidth(currentRow, "100%");
- this.layout.setWidth("100%");
- init( );
- }
- private void init( ) {
- makeWidgets(this.sentence.sentence);
- initWidget( this.layout );
- }
+ public DSLSentenceWidget(DSLSentence sentence,
+ SuggestionCompletionEngine completions) {
+ widgets = new ArrayList();
+ this.sentence = sentence;
+ this.completions = completions;
+ this.layout = new VerticalPanel();
+ this.currentRow = new HorizontalPanel();
+ this.layout.add(currentRow);
+ this.layout.setCellWidth(currentRow, "100%");
+ this.layout.setWidth("100%");
+ init();
+ }
+ private void init() {
+ makeWidgets(this.sentence.sentence);
+ initWidget(this.layout);
+ }
- /**
- * This will take a DSL line item, and split it into widget thingamies for displaying.
- * One day, if this is too complex, this will have to be done on the server side.
- */
- public void makeWidgets(String dslLine) {
+ /**
+ * This will take a DSL line item, and split it into widget thingamies for
+ * displaying. One day, if this is too complex, this will have to be done on
+ * the server side.
+ */
+ public void makeWidgets(String dslLine) {
- int startVariable = dslLine.indexOf("{");
- List<Widget> lineWidgets = new ArrayList<Widget>();
+ int startVariable = dslLine.indexOf("{");
+ List<Widget> lineWidgets = new ArrayList<Widget>();
- String startLabel = "";
- if(startVariable>0){
- startLabel = dslLine.substring(0,startVariable);
+ boolean firstOneIsBracket = (dslLine.indexOf("{") == 0);
- }else{
- startLabel = dslLine;
- }
+ String startLabel = "";
+ if (startVariable > 0) {
+ startLabel = dslLine.substring(0, startVariable);
+ } else if (!firstOneIsBracket) {
+ // There are no curly brackets in the text.
+ // Just print it
+ startLabel = dslLine;
+ }
- Widget label = getLabel(startLabel);
- lineWidgets.add(label);
+ Widget label = getLabel(startLabel);
+ lineWidgets.add(label);
- while(startVariable>0){
- int endVariable = dslLine.indexOf("}",startVariable);
- String currVariable = dslLine.substring(startVariable+1, endVariable);
+ while (startVariable > 0 || firstOneIsBracket) {
+ firstOneIsBracket = false;
- Widget varWidget = processVariable(currVariable);
- lineWidgets.add(varWidget);
+ int endVariable = dslLine.indexOf("}", startVariable);
+ String currVariable = dslLine.substring(startVariable + 1,
+ endVariable);
- //Parse out the next label between variables
- startVariable = dslLine.indexOf("{",endVariable);
- String lbl;
- if(startVariable>0){
- lbl = dslLine.substring(endVariable+1,startVariable);
- }else{
- lbl = dslLine.substring(endVariable+1, dslLine.length());
- }
+ Widget varWidget = processVariable(currVariable);
+ lineWidgets.add(varWidget);
- if (lbl.indexOf("\\n") > -1) {
- String[] lines = lbl.split("\\\\n");
- for (int i = 0; i < lines.length; i++) {
- lineWidgets.add(new NewLine());
+ // Parse out the next label between variables
+ startVariable = dslLine.indexOf("{", endVariable);
+ String lbl;
+ if (startVariable > 0) {
+ lbl = dslLine.substring(endVariable + 1, startVariable);
+ } else {
+ lbl = dslLine.substring(endVariable + 1, dslLine.length());
+ }
+
+ if (lbl.indexOf("\\n") > -1) {
+ String[] lines = lbl.split("\\\\n");
+ for (int i = 0; i < lines.length; i++) {
+ lineWidgets.add(new NewLine());
lineWidgets.add(getLabel(lines[i]));
}
- } else {
- Widget currLabel = getLabel(lbl);
- lineWidgets.add(currLabel);
- }
+ } else {
+ Widget currLabel = getLabel(lbl);
+ lineWidgets.add(currLabel);
+ }
- }
+ }
- for(Widget widg : lineWidgets){
- addWidget(widg);
- }
- updateSentence();
- }
+ for (Widget widg : lineWidgets) {
+ addWidget(widg);
+ }
+ updateSentence();
+ }
- class NewLine extends Widget {}
+ class NewLine extends Widget {
+ }
- public Widget processVariable(String currVariable){
+ public Widget processVariable(String currVariable) {
- Widget result = null;
- //Formats are: <varName>:ENUM:<Field.type>
- // <varName>:DATE:<dateFormat>
- // <varName>:BOOLEAN:[checked | unchecked] <-initial value
+ Widget result = null;
+ // Formats are: <varName>:ENUM:<Field.type>
+ // <varName>:DATE:<dateFormat>
+ // <varName>:BOOLEAN:[checked | unchecked] <-initial value
- int colonIndex = currVariable.indexOf(":");
- if(colonIndex>0){
+ int colonIndex = currVariable.indexOf(":");
+ if (colonIndex > 0) {
- String definition = currVariable.substring(colonIndex+1,currVariable.length());
+ String definition = currVariable.substring(colonIndex + 1,
+ currVariable.length());
- int secondColonIndex = definition.indexOf(":");
- if(secondColonIndex>0){
+ int secondColonIndex = definition.indexOf(":");
+ if (secondColonIndex > 0) {
- String type = currVariable.substring(colonIndex+1,colonIndex+secondColonIndex+1);
- if(type.equalsIgnoreCase(ENUM_TAG)){
- result = getEnumDropdown(currVariable);
- }else if(type.equalsIgnoreCase(DATE_TAG)){
- result = getDateSelector(currVariable);
- }else if(type.equalsIgnoreCase(BOOLEAN_TAG)){
- result = getCheckbox(currVariable);
- }
- }else{
- String regex = currVariable.substring(colonIndex+1,currVariable.length());
- result = getBox(currVariable,regex);
- }
- }
- else{
- result = getBox(currVariable,"");
- }
+ String type = currVariable.substring(colonIndex + 1, colonIndex
+ + secondColonIndex + 1);
+ if (type.equalsIgnoreCase(ENUM_TAG)) {
+ result = getEnumDropdown(currVariable);
+ } else if (type.equalsIgnoreCase(DATE_TAG)) {
+ result = getDateSelector(currVariable);
+ } else if (type.equalsIgnoreCase(BOOLEAN_TAG)) {
+ result = getCheckbox(currVariable);
+ }
+ } else {
+ String regex = currVariable.substring(colonIndex + 1,
+ currVariable.length());
+ result = getBox(currVariable, regex);
+ }
+ } else {
+ result = getBox(currVariable, "");
+ }
- return result;
- }
+ return result;
+ }
- public Widget getEnumDropdown(String variableDef){
+ public Widget getEnumDropdown(String variableDef) {
- Widget resultWidget = new DSLDropDown(variableDef);
- return resultWidget;
- }
+ Widget resultWidget = new DSLDropDown(variableDef);
+ return resultWidget;
+ }
- public Widget getBox(String variableDef, String regex){
+ public Widget getBox(String variableDef, String regex) {
- int colonIndex = variableDef.indexOf(":");
- if(colonIndex>0){
- variableDef = variableDef.substring(0,colonIndex);
- }
- FieldEditor currentBox = new FieldEditor();
- currentBox.setVisibleLength(variableDef.length()+1);
- currentBox.setText(variableDef);
- currentBox.setRestriction(regex);
+ int colonIndex = variableDef.indexOf(":");
+ if (colonIndex > 0) {
+ variableDef = variableDef.substring(0, colonIndex);
+ }
+ FieldEditor currentBox = new FieldEditor();
+ currentBox.setVisibleLength(variableDef.length() + 1);
+ currentBox.setText(variableDef);
+ currentBox.setRestriction(regex);
- return currentBox;
- }
+ return currentBox;
+ }
- public Widget getCheckbox(String variableDef){
- return new DSLCheckBox(variableDef);
- }
+ public Widget getCheckbox(String variableDef) {
+ return new DSLCheckBox(variableDef);
+ }
- public Widget getDateSelector(String variableDef){
- return new DSLDateSelector(variableDef);
- }
+ public Widget getDateSelector(String variableDef) {
+ return new DSLDateSelector(variableDef);
+ }
- public Widget getLabel(String labelDef){
- Label label = new SmallLabel();
- label.setText(labelDef+" ");
+ public Widget getLabel(String labelDef) {
+ Label label = new SmallLabel();
+ label.setText(labelDef + " ");
- return label;
- }
+ return label;
+ }
- private void addWidget(Widget currentBox) {
- if (currentBox instanceof NewLine) {
- currentRow = new HorizontalPanel();
- layout.add(currentRow);
- layout.setCellWidth(currentRow, "100%");
- } else {
- currentRow.add(currentBox);
- }
- widgets.add( currentBox );
- }
+ private void addWidget(Widget currentBox) {
+ if (currentBox instanceof NewLine) {
+ currentRow = new HorizontalPanel();
+ layout.add(currentRow);
+ layout.setCellWidth(currentRow, "100%");
+ } else {
+ currentRow.add(currentBox);
+ }
+ widgets.add(currentBox);
+ }
- /**
- * This will go through the widgets and build up a sentence.
- */
- protected void updateSentence() {
- String newSentence = "";
- for ( Iterator iter = widgets.iterator(); iter.hasNext(); ) {
- Widget wid = (Widget) iter.next();
- if (wid instanceof Label) {
- newSentence = newSentence + ((Label) wid).getText();
- } else if (wid instanceof FieldEditor) {
- FieldEditor editor = (FieldEditor) wid;
+ /**
+ * This will go through the widgets and build up a sentence.
+ */
+ protected void updateSentence() {
+ String newSentence = "";
+ for (Iterator iter = widgets.iterator(); iter.hasNext();) {
+ Widget wid = (Widget) iter.next();
+ if (wid instanceof Label) {
+ newSentence = newSentence + ((Label) wid).getText();
+ } else if (wid instanceof FieldEditor) {
+ FieldEditor editor = (FieldEditor) wid;
- String varString = editor.getText();
- String restriction =editor.getRestriction();
- if(!restriction.equals("")){
- varString = varString+":"+restriction;
- }
+ String varString = editor.getText();
+ String restriction = editor.getRestriction();
+ if (!restriction.equals("")) {
+ varString = varString + ":" + restriction;
+ }
- newSentence = newSentence + " {" + varString + "} ";
- }else if (wid instanceof DSLDropDown){
+ newSentence = newSentence + " {" + varString + "} ";
+ } else if (wid instanceof DSLDropDown) {
- //Add the meta-data back to the field so that is shows up as a dropdown when refreshed from repo
- DSLDropDown drop = (DSLDropDown)wid;
- ListBox box = drop.getListBox();
- String type = drop.getType();
- String factAndField = drop.getFactAndField();
+ // Add the meta-data back to the field so that is shows up as a
+ // dropdown when refreshed from repo
+ DSLDropDown drop = (DSLDropDown) wid;
+ ListBox box = drop.getListBox();
+ String type = drop.getType();
+ String factAndField = drop.getFactAndField();
- newSentence = newSentence + "{"+box.getValue(box.getSelectedIndex())+":"+type+":"+factAndField+ "} ";
- }else if(wid instanceof DSLCheckBox){
+ newSentence = newSentence + "{"
+ + box.getValue(box.getSelectedIndex()) + ":" + type
+ + ":" + factAndField + "} ";
+ } else if (wid instanceof DSLCheckBox) {
- DSLCheckBox check = (DSLCheckBox)wid;
- boolean checkValue = check.getCheckedValue();
- newSentence = newSentence + "{"+checkValue+":"+check.getType()+":"+checkValue+ "} ";
- }else if(wid instanceof DSLDateSelector){
- DSLDateSelector dateSel = (DSLDateSelector)wid;
- String dateString = dateSel.getDateString();
- String format = dateSel.getFormat();
- newSentence = newSentence + "{"+dateString+":"+dateSel.getType()+":"+format+ "} ";
- } else if (wid instanceof NewLine) {
- newSentence = newSentence + "\\n";
- }
- }
- this.sentence.sentence = newSentence.trim();
- }
+ DSLCheckBox check = (DSLCheckBox) wid;
+ boolean checkValue = check.getCheckedValue();
+ newSentence = newSentence + "{" + checkValue + ":"
+ + check.getType() + ":" + checkValue + "} ";
+ } else if (wid instanceof DSLDateSelector) {
+ DSLDateSelector dateSel = (DSLDateSelector) wid;
+ String dateString = dateSel.getDateString();
+ String format = dateSel.getFormat();
+ newSentence = newSentence + "{" + dateString + ":"
+ + dateSel.getType() + ":" + format + "} ";
+ } else if (wid instanceof NewLine) {
+ newSentence = newSentence + "\\n";
+ }
+ }
+ this.sentence.sentence = newSentence.trim();
+ }
- class FieldEditor extends DirtyableComposite {
+ class FieldEditor extends DirtyableComposite {
- private TextBox box;
- private HorizontalPanel panel = new HorizontalPanel();
- private String oldValue = "";
- private String regex = "";
- public FieldEditor() {
- box = new TextBox();
- //box.setStyleName( "dsl-field-TextBox" );
+ private TextBox box;
+ private HorizontalPanel panel = new HorizontalPanel();
+ private String oldValue = "";
+ private String regex = "";
- panel.add( new HTML(" ") );
- panel.add( box );
- panel.add( new HTML(" ") );
+ public FieldEditor() {
+ box = new TextBox();
+ // box.setStyleName( "dsl-field-TextBox" );
- box.addChangeListener( new ChangeListener() {
- public void onChange(Widget w) {
- TextBox otherBox = (TextBox)w;
+ panel.add(new HTML(" "));
+ panel.add(box);
+ panel.add(new HTML(" "));
- if(!regex.equals("") && !otherBox.getText().matches(regex)){
- Window.alert("The value "+otherBox.getText()+" is not valid for this field");
- box.setText(oldValue);
- }else{
- oldValue = otherBox.getText();
- updateSentence();
- makeDirty();
- }
- }
- });
+ box.addChangeListener(new ChangeListener() {
+ public void onChange(Widget w) {
+ TextBox otherBox = (TextBox) w;
- initWidget( panel );
- }
+ if (!regex.equals("") && !otherBox.getText().matches(regex)) {
+ Window.alert("The value " + otherBox.getText()
+ + " is not valid for this field");
+ box.setText(oldValue);
+ } else {
+ oldValue = otherBox.getText();
+ updateSentence();
+ makeDirty();
+ }
+ }
+ });
- public void setText(String t) {
- box.setText( t );
- }
+ initWidget(panel);
+ }
- public void setVisibleLength(int l) {
- box.setVisibleLength( l );
- }
+ public void setText(String t) {
+ box.setText(t);
+ }
- public String getText() {
- return box.getText();
- }
+ public void setVisibleLength(int l) {
+ box.setVisibleLength(l);
+ }
- public void setRestriction(String regex){
- this.regex = regex;
- }
+ public String getText() {
+ return box.getText();
+ }
- public String getRestriction(){
- return this.regex;
- }
+ public void setRestriction(String regex) {
+ this.regex = regex;
+ }
- public boolean isValid(){
- boolean result = true;
- if(!regex.equals(""))
- result = this.box.getText().matches(this.regex);
+ public String getRestriction() {
+ return this.regex;
+ }
- return result;
- }
- }
+ public boolean isValid() {
+ boolean result = true;
+ if (!regex.equals(""))
+ result = this.box.getText().matches(this.regex);
+ return result;
+ }
+ }
- class DSLDropDown extends DirtyableComposite{
+ class DSLDropDown extends DirtyableComposite {
- ListBox resultWidget = null;
- //Format for the dropdown def is <varName>:<type>:<Fact.field>
- private String varName ="";
- private String type ="";
- private String factAndField = "";
+ ListBox resultWidget = null;
+ // Format for the dropdown def is <varName>:<type>:<Fact.field>
+ private String varName = "";
+ private String type = "";
+ private String factAndField = "";
- public DSLDropDown(String variableDef){
- int firstIndex = variableDef.indexOf(":");
- int lastIndex = variableDef.lastIndexOf(":");
- varName = variableDef.substring(0,firstIndex);
- type = variableDef.substring(firstIndex+1,lastIndex);
- factAndField = variableDef.substring(lastIndex+1, variableDef.length());
+ public DSLDropDown(String variableDef) {
+ int firstIndex = variableDef.indexOf(":");
+ int lastIndex = variableDef.lastIndexOf(":");
+ varName = variableDef.substring(0, firstIndex);
+ type = variableDef.substring(firstIndex + 1, lastIndex);
+ factAndField = variableDef.substring(lastIndex + 1, variableDef
+ .length());
- int dotIndex = factAndField.indexOf(".");
- String type = factAndField.substring(0,dotIndex);
- String field= factAndField.substring(dotIndex+1,factAndField.length());
+ int dotIndex = factAndField.indexOf(".");
+ String type = factAndField.substring(0, dotIndex);
+ String field = factAndField.substring(dotIndex + 1, factAndField
+ .length());
String[] data = completions.getEnumValues(type, field);
- ListBox list = new ListBox();
+ ListBox list = new ListBox();
- if(data!=null){
- int selected = -1;
- for(int i=0;i<data.length;i++){
- String realValue = data[i];
- String display = data[i];
- if (data[i].indexOf('=') > -1) {
- String[] vs = ConstraintValueEditorHelper.splitValue(data[i]);
- realValue = vs[0];
- display = vs[1];
- }
- if(varName.equals(realValue)){
- selected=i;
- }
- list.addItem(display, realValue);
- }
- if(selected>=0) list.setSelectedIndex(selected);
- }
- list.addChangeListener( new ChangeListener() {
- public void onChange(Widget w) {
- updateSentence();
- makeDirty();
- }
- });
+ if (data != null) {
+ int selected = -1;
+ for (int i = 0; i < data.length; i++) {
+ String realValue = data[i];
+ String display = data[i];
+ if (data[i].indexOf('=') > -1) {
+ String[] vs = ConstraintValueEditorHelper
+ .splitValue(data[i]);
+ realValue = vs[0];
+ display = vs[1];
+ }
+ if (varName.equals(realValue)) {
+ selected = i;
+ }
+ list.addItem(display, realValue);
+ }
+ if (selected >= 0)
+ list.setSelectedIndex(selected);
+ }
+ list.addChangeListener(new ChangeListener() {
+ public void onChange(Widget w) {
+ updateSentence();
+ makeDirty();
+ }
+ });
- initWidget(list);
- resultWidget = list;
- }
+ initWidget(list);
+ resultWidget = list;
+ }
+
public ListBox getListBox() {
return resultWidget;
}
+
public void setListBox(ListBox resultWidget) {
this.resultWidget = resultWidget;
}
+
public String getType() {
return type;
}
+
public void setType(String type) {
this.type = type;
}
+
public String getFactAndField() {
return factAndField;
}
+
public void setFactAndField(String factAndField) {
this.factAndField = factAndField;
}
- }
+ }
- class DSLCheckBox extends Composite {
- ListBox resultWidget = null;
- //Format for the dropdown def is <varName>:<type>:<Fact.field>
- private String varName ="";
+ class DSLCheckBox extends Composite {
+ ListBox resultWidget = null;
+ // Format for the dropdown def is <varName>:<type>:<Fact.field>
+ private String varName = "";
- public DSLCheckBox(String variableDef){
+ public DSLCheckBox(String variableDef) {
- int firstIndex = variableDef.indexOf(":");
- int lastIndex = variableDef.lastIndexOf(":");
- varName = variableDef.substring(0,firstIndex);
- String checkedUnchecked = variableDef.substring(lastIndex+1, variableDef.length());
+ int firstIndex = variableDef.indexOf(":");
+ int lastIndex = variableDef.lastIndexOf(":");
+ varName = variableDef.substring(0, firstIndex);
+ String checkedUnchecked = variableDef.substring(lastIndex + 1,
+ variableDef.length());
- resultWidget = new ListBox();
- resultWidget.addItem("true");
- resultWidget.addItem("false");
+ resultWidget = new ListBox();
+ resultWidget.addItem("true");
+ resultWidget.addItem("false");
- if(checkedUnchecked.equalsIgnoreCase("checked")){
- resultWidget.setSelectedIndex(0);
- }else{
- resultWidget.setSelectedIndex(1);
- }
+ if (checkedUnchecked.equalsIgnoreCase("checked")) {
+ resultWidget.setSelectedIndex(0);
+ } else {
+ resultWidget.setSelectedIndex(1);
+ }
- resultWidget.addClickListener( new ClickListener() {
- public void onClick(Widget w) {
- updateSentence();
- }
- });
+ resultWidget.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ updateSentence();
+ }
+ });
- resultWidget.setVisible(true);
- initWidget(resultWidget);
- }
+ resultWidget.setVisible(true);
+ initWidget(resultWidget);
+ }
+
public ListBox getListBox() {
return resultWidget;
}
+
public void setListBox(ListBox resultWidget) {
this.resultWidget = resultWidget;
}
+
public String getType() {
return BOOLEAN_TAG;
}
-
public String getVarName() {
return varName;
}
+
public void setVarName(String varName) {
this.varName = varName;
}
- public boolean getCheckedValue() {
- return this.resultWidget.getSelectedIndex() == 0;
+ public boolean getCheckedValue() {
+ return this.resultWidget.getSelectedIndex() == 0;
- }
- }
+ }
+ }
- class DSLDateSelector extends DirtyableComposite{
- DateField resultWidget = null;
- //Format for the dropdown def is <varName>:<type>:<Fact.field>
- private String varName ="";
- private String format ="";
- private String defaultFormat = "dd-MMM-yyyy";
- private DateTimeFormat formatter = null;
- public DSLDateSelector(String variableDef){
+ class DSLDateSelector extends DirtyableComposite {
+ DateField resultWidget = null;
+ // Format for the dropdown def is <varName>:<type>:<Fact.field>
+ private String varName = "";
+ private String format = "";
+ private String defaultFormat = "dd-MMM-yyyy";
+ private DateTimeFormat formatter = null;
- int firstIndex = variableDef.indexOf(":");
- int lastIndex = variableDef.lastIndexOf(":");
- varName = variableDef.substring(0,firstIndex);
- format = variableDef.substring(lastIndex+1, variableDef.length());
+ public DSLDateSelector(String variableDef) {
- //Ugly ugly way to get a date format
- if(format.equals("") || format.equals("default")){
- formatter = DateTimeFormat.getFormat(defaultFormat);
- }else{
- try{
- formatter = DateTimeFormat.getFormat(format);
- }catch(Exception e){
- formatter = DateTimeFormat.getFormat(defaultFormat);
- }
- }
+ int firstIndex = variableDef.indexOf(":");
+ int lastIndex = variableDef.lastIndexOf(":");
+ varName = variableDef.substring(0, firstIndex);
+ format = variableDef.substring(lastIndex + 1, variableDef.length());
- Date origDate = null;
- if(!varName.equals("")){
- try{
- origDate = formatter.parse(varName);
- }catch(Exception e){
+ // Ugly ugly way to get a date format
+ if (format.equals("") || format.equals("default")) {
+ formatter = DateTimeFormat.getFormat(defaultFormat);
+ } else {
+ try {
+ formatter = DateTimeFormat.getFormat(format);
+ } catch (Exception e) {
+ formatter = DateTimeFormat.getFormat(defaultFormat);
+ }
+ }
- }
- }
+ Date origDate = null;
+ if (!varName.equals("")) {
+ try {
+ origDate = formatter.parse(varName);
+ } catch (Exception e) {
- resultWidget = new DateField();
- if(origDate!=null)
- resultWidget.setValue(origDate);
+ }
+ }
- resultWidget.addListener( new DatePickerListenerAdapter() {
+ resultWidget = new DateField();
+ if (origDate != null)
+ resultWidget.setValue(origDate);
+ resultWidget.addListener(new DatePickerListenerAdapter() {
+
public void onSelect(DatePicker dataPicker, Date date) {
resultWidget.setValue(date);
updateSentence();
- makeDirty();
+ makeDirty();
}
- });
+ });
- resultWidget.setVisible(true);
- initWidget(resultWidget);
- }
+ resultWidget.setVisible(true);
+ initWidget(resultWidget);
+ }
+
public DateField getListBox() {
return resultWidget;
}
+
public void setListBox(DateField resultWidget) {
this.resultWidget = resultWidget;
}
+
public String getType() {
return DATE_TAG;
}
- public String getFormat(){
+ public String getFormat() {
return this.format;
}
+
public String getDateString() {
- Date value = resultWidget.getValue();
- String result ="";
- if(value!=null)
- result =formatter.format(value);
+ Date value = resultWidget.getValue();
+ String result = "";
+ if (value != null)
+ result = formatter.format(value);
else
result = varName;
-
- return result;
+
+ return result;
}
+
public String getVarName() {
return varName;
}
+
public void setVarName(String varName) {
this.varName = varName;
}
- }
+ }
}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list