|
From: <pat...@us...> - 2010-08-23 18:07:54
|
Revision: 1128
http://cishell.svn.sourceforge.net/cishell/?rev=1128&view=rev
Author: pataphil
Date: 2010-08-23 18:07:46 +0000 (Mon, 23 Aug 2010)
Log Message:
-----------
* Revamped DataModel framework.
* Reviewed by Chintan.
Modified Paths:
--------------
trunk/core/org.cishell.utility.datastructure/META-INF/MANIFEST.MF
trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/ExpandableComponentWidget.java
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/ScrolledComponentFactory.java
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/datasynchronizer/CheckBoxDataSynchronizer.java
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/datasynchronizer/DropDownDataSynchronizer.java
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/datasynchronizer/SingleListSelectionDataSynchronizer.java
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/datasynchronizer/TextDataSynchronizer.java
Added Paths:
-----------
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/DataModel.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/ModelDataSynchronizer.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/area/
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/area/AbstractDataModelArea.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/area/DataModelArea.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/area/DataModelAreaContainer.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/exception/
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/exception/ModelStructureException.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/exception/ModelValidationException.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/exception/UniqueNameException.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelField.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelFieldContainer.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/FieldValidationAction.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/FieldValidationRule.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/group/
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/group/BasicModelGroup.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/group/DataModelGroup.java
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/gui/
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/gui/AbstractGUIDataModel.java
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/WidgetConstructionException.java
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModel.java
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModelArea.java
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModelField.java
Removed Paths:
-------------
trunk/core/org.cishell.utility.datastructure/src/org/cishell/utilities/
trunk/core/org.cishell.utility.swt/src/org/cishell/utilities/swt/model/
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/GUIModel.java
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/GUIModelField.java
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/GUIModelGroup.java
trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/datasynchronizer/ModelDataSynchronizer.java
Modified: trunk/core/org.cishell.utility.datastructure/META-INF/MANIFEST.MF
===================================================================
--- trunk/core/org.cishell.utility.datastructure/META-INF/MANIFEST.MF 2010-08-23 18:06:40 UTC (rev 1127)
+++ trunk/core/org.cishell.utility.datastructure/META-INF/MANIFEST.MF 2010-08-23 18:07:46 UTC (rev 1128)
@@ -4,4 +4,10 @@
Bundle-SymbolicName: org.cishell.utility.datastructure
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Export-Package: org.cishell.utility.datastructure
+Export-Package: org.cishell.utility.datastructure,
+ org.cishell.utility.datastructure.datamodel,
+ org.cishell.utility.datastructure.datamodel.area,
+ org.cishell.utility.datastructure.datamodel.exception,
+ org.cishell.utility.datastructure.datamodel.field,
+ org.cishell.utility.datastructure.datamodel.group,
+ org.cishell.utility.datastructure.datamodel.gui
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/DataModel.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/DataModel.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/DataModel.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,201 @@
+package org.cishell.utility.datastructure.datamodel;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.cishell.utility.datastructure.datamodel.area.DataModelArea;
+import org.cishell.utility.datastructure.datamodel.area.DataModelAreaContainer;
+import org.cishell.utility.datastructure.datamodel.exception.ModelStructureException;
+import org.cishell.utility.datastructure.datamodel.exception.UniqueNameException;
+import org.cishell.utility.datastructure.datamodel.field.DataModelField;
+import org.cishell.utility.datastructure.datamodel.group.DataModelGroup;
+
+/**
+ * DataModel is intended to organize and structure the manipulation of data elements
+ * (@link DataModelField) in a generic fashion.
+ * DataModel is inspired by GUIs--a GUI requiring user input (through various input fields) could
+ * be tied to a DataModel, which automatically contains values from the GUI. When the GUI is done
+ * (as in, the user finished), the DataModel could then be used for data retrieval in a
+ * GUI-agnostic fashion.
+ * Though of course implementation-specific, DataModel is designed to allow the
+ * addition/modification/deletion of user input fields without any knowledge of the particular
+ * (type of) GUI the DataModel is tied to. In other words, a DataModel could be purely data,
+ * AWT-/Swing-, or SWT-based, and input fields could still be interacted with on an
+ * abstract level.
+ * DataModels consist of areas {@link DataModelArea} and groups (@link DataModelGroup).
+ * Areas and groups both contain fields (@link DataModelField).
+ * Where as groups are purely organization structures (so one could get all fields within a group,
+ * say), areas are also tied to physical composite GUI structures so GUI-agnostic code can add
+ * fields to a given specific area.
+ * When adding fields, an area is not required. This implies that areas are not required for a
+ * valid model, and thus the ability to extend areas with sub-areas and/or fields is up to the
+ * GUI designer.
+ * A group is required when adding fields. DataModel itself actually provides no mechanism for
+ * retrieving fields directly. Rather, the recommended/somewhat-enforced method for field
+ * retrieval is via groups.
+ * Currently, there is no mechanism for abstractly expressing field component styles.
+ * DataModel is not thread-synchronized.
+ * Further usage details are described on a per-method basis.
+ */
+public interface DataModel extends DataModelAreaContainer {
+ public static final String DEFAULT_GROUP_NAME = "defaultGroup";
+
+ // Miscellaneous methods
+
+ /**
+ * Set the parent GUI component.
+ * GUI-agnostic on the interface level.
+ * The GUI-specific implementations of this interface must type check parent for validity.
+ * This has to exist so fields can be added to GUIs without knowing about the GUI or how the
+ * GUI works.
+ * Parent components can be retrieved from specific fields or specific areas.
+ *
+ * @param currentParentComponent the current parent/containing GUI component to which this
+ * model should add subsequent fields to.
+ */
+ public void setCurrentParentComponent(Object currentParentComponent) throws ClassCastException;
+
+ // DataModelAreaContainer methods
+
+ /// {@inheritDoc}
+ public Collection<String> getAreaNames();
+ /// {@inheritDoc}
+ public Collection<DataModelArea> getAreas();
+ /// {@inheritDoc}
+ public DataModelArea getArea(String name);
+ /// {@inheritDoc}
+ public DataModelArea createArea(String name) throws UniqueNameException;
+ /// {@inheritDoc}
+ public DataModelArea createArea(String name, Object componentForArea)
+ throws ClassCastException, ModelStructureException, UniqueNameException;
+ /// {@inheritDoc}
+ public void addArea(DataModelArea area)
+ throws ClassCastException, ModelStructureException, UniqueNameException;
+ /// {@inheritDoc}
+ public boolean areaDisposed(String name);
+ /// {@inheritDoc}
+ public boolean areaDisposed(DataModelArea area);
+
+ // Group methods
+
+ /// @return all of the group names in this DataModel.
+ public Collection<String> getGroupNames();
+ /// @return all of the groups in this DataModel.
+ public Collection<DataModelGroup> getGroups();
+ /**
+ * Get a group by specific name.
+ *
+ * @return the DataModelGroup with name if found. Otherwise, null.
+ */
+ public DataModelGroup getGroup(String name);
+ /**
+ * Explicitly create a group with name.
+ *
+ * @param name the name of the new group.
+ * @return the created group.
+ * @throws UniqueNameException if a group with name has already been created.
+ */
+ public DataModelGroup createGroup(String name) throws UniqueNameException;
+
+ // Add Field methods
+
+ /**
+ * Adds a checkbox field to the parent/containing GUI component of the specified area or the
+ * current parent/containing GUI component if no area is specified.
+ * Also creates the GUI-specific component.
+ *
+ * @see addField
+ * @param name the name of the new field.
+ * @param areaName the name of the area to add this field to. Not required.
+ * @param groupName the name of the group to add this field to. Not required, though a default
+ * will be used if not provided.
+ * @param defaultOn if true, the default value of this check box will be checked.
+ * @throws UniqueNameException if a field with name has already been added.
+ */
+ public DataModelField<Boolean> addCheckBox(
+ String name, String areaName, String groupName, boolean defaultOn)
+ throws UniqueNameException;
+ /**
+ * Adds a single-selection drop down field to the parent/containing GUI component of the
+ * specified area or the current parent/containing GUI component if no area is specified.
+ * Also creates the GUI-specific component.
+ *
+ * @see addField
+ * @param name the name of the new field.
+ * @param areaName the name of the area to add this field to. Not required.
+ * @param groupName the name of the group to add this field to. Not required, though a default
+ * will be used if not provided.
+ * @param selectedIndex the element of unorderedOptionLabels to have selected by default.
+ * @param unorderedOptionLabels the literal items that get displayed as user-selectable
+ * options. Note: selectedIndex should fall within these bounds, and these should be exactly
+ * the keys into optionValuesByLabels.
+ * @param optionValuesByLabels the option label-to-value mapping used to tie user-selected
+ * options to actual values used by code later on.
+ * @throws UniqueNameException if a field with name has already been added.
+ */
+ public<T> DataModelField<T> addDropDown(
+ String name,
+ String areaName,
+ String groupName,
+ int selectedIndex,
+ Collection<String> unorderedOptionLabels,
+ Map<String, T> optionValuesByLabels) throws UniqueNameException;
+ /**
+ * Adds a single-selection list field to the parent/containing GUI component of the specified
+ * area or the current parent/containing GUI component if no area is specified.
+ * Also creates the GUI-specific component.
+ *
+ * @see addField
+ * @param name the name of the new field.
+ * @param areaName the name of the area to add this field to. Not required.
+ * @param groupName the name of the group to add this field to. Not required, though a default
+ * will be used if not provided.
+ * @param selectedIndex the element of unorderedOptionLabels to have selected by default.
+ * @param unorderedOptionLabels the literal items that get displayed as user-selectable
+ * options. Note: selectedIndex should fall within these bounds, and these should be exactly
+ * the keys into optionValuesByLabels.
+ * @param optionValuesByLabels the option label-to-value mapping used to tie user-selected
+ * options to actual values used by code later on.
+ * @throws UniqueNameException if a field with name has already been added.
+ */
+ public<T> DataModelField<T> addList(
+ String name,
+ String areaName,
+ String groupName,
+ int selectedIndex,
+ Collection<String> unorderedOptionLabels,
+ Map<String, T> optionValuesByLabels) throws UniqueNameException;
+ /**
+ * Adds a text field to the parent/containing GUI component of the specified area or the
+ * current parent/containing GUI component if no area is specified.
+ *
+ * @see addField
+ * @param name the name of the new field.
+ * @param areaName the name of the area to add this field to. Not required.
+ * @param groupName the name of the group to add this field to. Not required, though a default
+ * will be used if not provided.
+ * @param defaultValue the default value of this text field.
+ * @param isMultiLined if true, this text field will be multi-lined. Otherwise, it will be
+ * single-lined.
+ * @throws UniqueNameException if a field with name has already been added.
+ */
+ public DataModelField<String> addText(
+ String name,
+ String areaName,
+ String groupName,
+ String defaultValue,
+ boolean isMultiLined) throws UniqueNameException;
+ /**
+ * Adds an already-created field to the area named areaName and group named groupName, both
+ * if specified.
+ * Note: It is up to the caller to have added field to the specified area's parent/containing
+ * GUI component, and the implementing class should verify this.
+ *
+ * @param areaName the name of the area to add this field to. Not required.
+ * @param groupName the name of the group to add this field to. Not required, though a default
+ * will be used if not provided.
+ * @throws UniqueNameException if a field with name has already been added.
+ */
+ public<T> void addField(String areaName, String groupName, DataModelField<T> field)
+ throws UniqueNameException;
+}
\ No newline at end of file
Copied: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/ModelDataSynchronizer.java (from rev 1118, trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/datasynchronizer/ModelDataSynchronizer.java)
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/ModelDataSynchronizer.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/ModelDataSynchronizer.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,12 @@
+package org.cishell.utility.datastructure.datamodel;
+
+/**
+ *
+ */
+public interface ModelDataSynchronizer<T> {
+ public int updateListenerCode();
+ public T value();
+ public T synchronizeFromGUI();
+ public T synchronizeToGUI(T value);
+ public T reset(T defaultValue);
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/area/AbstractDataModelArea.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/area/AbstractDataModelArea.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/area/AbstractDataModelArea.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,154 @@
+package org.cishell.utility.datastructure.datamodel.area;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.cishell.utility.datastructure.datamodel.exception.ModelStructureException;
+import org.cishell.utility.datastructure.datamodel.exception.UniqueNameException;
+import org.cishell.utility.datastructure.datamodel.field.DataModelField;
+
+public abstract class AbstractDataModelArea<
+ BaseGUIComponentType, GUIContainerComponentType extends BaseGUIComponentType>
+ implements DataModelArea {
+ private DataModelArea parentArea;
+ private GUIContainerComponentType parentComponent;
+ private String name;
+
+ private Map<String, DataModelArea> areas = new HashMap<String, DataModelArea>();
+ private Map<String, DataModelField<?>> fields = new HashMap<String, DataModelField<?>>();
+
+ public AbstractDataModelArea(
+ DataModelArea parentArea, GUIContainerComponentType parentComponent, String name) {
+ this.parentArea = parentArea;
+ this.parentComponent = parentComponent;
+ this.name = name;
+ }
+
+ // Misceallaneous methods
+
+ public DataModelArea getParentArea() {
+ return this.parentArea;
+ }
+
+ public Object getParentComponent() {
+ return this.parentComponent;
+ }
+
+ public GUIContainerComponentType getParentComponentWithType() {
+ return this.parentComponent;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ // DataModelAreaContainer methods
+
+ public Collection<String> getAreaNames() {
+ return this.areas.keySet();
+ }
+
+ public Collection<DataModelArea> getAreas() {
+ return this.areas.values();
+ }
+
+ public DataModelArea getArea(String name) {
+ return this.areas.get(name);
+ }
+
+ public DataModelArea createArea(String name) throws UniqueNameException {
+ if (getArea(name) != null) {
+ String exceptionMessage = String.format(
+ "The area '%s' already exists. All areas must have unique names.", name);
+ throw new UniqueNameException(exceptionMessage);
+ } else {
+ DataModelArea area = internalCreateArea(name);
+ this.areas.put(name, area);
+
+ return area;
+ }
+ }
+
+ public abstract DataModelArea createArea(String name, Object componentForArea)
+ throws ClassCastException, ModelStructureException, UniqueNameException;
+
+ protected abstract DataModelArea internalCreateArea(String name);
+
+ public void addArea(DataModelArea area)
+ throws ClassCastException, ModelStructureException, UniqueNameException {
+ String name = area.getName();
+
+ if (getArea(name) != null) {
+ String exceptionMessage = String.format(
+ "The area '%s' already exists. All areas must have unique names.", name);
+ throw new UniqueNameException(exceptionMessage);
+ } else if (area.getParentComponent() != getParentComponent()) {
+ String exceptionMessage = String.format(
+ "Tried to manually add area %s to area %s, but parent components do not match.",
+ name,
+ getName());
+ throw new ModelStructureException(exceptionMessage);
+ } else {
+ this.areas.put(name, area);
+ }
+ }
+
+ public boolean areaDisposed(String name) {
+ if (this.areas.containsKey(name)) {
+ this.areas.remove(name);
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public boolean areaDisposed(DataModelArea area) {
+ return areaDisposed(area.getName());
+ }
+
+ // DataModelFieldContainer methods
+
+ public Collection<String> getFieldNames() {
+ return this.fields.keySet();
+ }
+
+ public Collection<DataModelField<?>> getFields() {
+ return this.fields.values();
+ }
+
+ public DataModelField<?> getField(String fieldName) {
+ return this.fields.get(fieldName);
+ }
+
+ public<T> void addField(DataModelField<T> field) throws UniqueNameException {
+ String fieldName = field.getName();
+
+ if (getField(fieldName) != null) {
+ String format =
+ "The field '%s' already exists in this area (%s). " +
+ "All fields must have unique names.";
+ String exceptionMessage = String.format(
+ format, fieldName, this.name);
+ throw new UniqueNameException(exceptionMessage);
+ } else {
+ this.fields.put(fieldName, field);
+ field.addToContainer(this);
+ }
+ }
+
+ public boolean fieldDisposed(String fieldName) {
+ if (this.fields.containsKey(fieldName)) {
+ this.fields.remove(fieldName);
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public<T> boolean fieldDisposed(DataModelField<T> field) {
+ return fieldDisposed(field.getName());
+ }
+}
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/area/DataModelArea.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/area/DataModelArea.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/area/DataModelArea.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,40 @@
+package org.cishell.utility.datastructure.datamodel.area;
+
+import java.util.Collection;
+
+import org.cishell.utility.datastructure.datamodel.exception.ModelStructureException;
+import org.cishell.utility.datastructure.datamodel.exception.UniqueNameException;
+import org.cishell.utility.datastructure.datamodel.field.DataModelField;
+import org.cishell.utility.datastructure.datamodel.field.DataModelFieldContainer;
+
+/**
+ * DataModelArea corresponds to a physical area tied to a DataModel GUI.
+ * DataModelAreas can contain other DataModelAreas, as well as DataModelFields.
+ */
+public interface DataModelArea extends DataModelAreaContainer, DataModelFieldContainer {
+ // Miscellaneous methods
+
+ public DataModelArea getParentArea();
+ public Object getParentComponent();
+ public String getName();
+
+ // DataModelAreaContainer methods
+
+ public Collection<String> getAreaNames();
+ public Collection<DataModelArea> getAreas();
+ public DataModelArea getArea(String name);
+ public DataModelArea createArea(String name) throws UniqueNameException;
+ public DataModelArea createArea(String name, Object componentForArea)
+ throws ClassCastException, ModelStructureException, UniqueNameException;
+ public boolean areaDisposed(String name);
+ public boolean areaDisposed(DataModelArea area);
+
+ // DataModelFieldContainer methods
+
+ public Collection<String> getFieldNames();
+ public Collection<DataModelField<?>> getFields();
+ public DataModelField<?> getField(String fieldName);
+ public<T> void addField(DataModelField<T> field) throws UniqueNameException;
+ public boolean fieldDisposed(String fieldName);
+ public<T> boolean fieldDisposed(DataModelField<T> field);
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/area/DataModelAreaContainer.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/area/DataModelAreaContainer.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/area/DataModelAreaContainer.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,28 @@
+package org.cishell.utility.datastructure.datamodel.area;
+
+import java.util.Collection;
+
+import org.cishell.utility.datastructure.datamodel.exception.ModelStructureException;
+import org.cishell.utility.datastructure.datamodel.exception.UniqueNameException;
+
+// TODO: addToContainer type stuff
+public interface DataModelAreaContainer {
+ public Collection<String> getAreaNames();
+ public Collection<DataModelArea> getAreas();
+ public DataModelArea getArea(String name);
+ public DataModelArea createArea(String name) throws UniqueNameException;
+ /**
+ * @throws ClassCastException if componentForArea is not of the proper GUI container type.
+ * @throws ModelStructureException if componentForArea's parent is not this area's internal
+ * GUI container.
+ * @throws UniqueNameException if an area with name already exists.
+ */
+ public DataModelArea createArea(String name, Object componentForArea)
+ throws ClassCastException, ModelStructureException, UniqueNameException;
+ public void addArea(DataModelArea area)
+ throws ClassCastException, ModelStructureException, UniqueNameException;
+
+ //TODO: why is this returning boolean?
+ public boolean areaDisposed(String name);
+ public boolean areaDisposed(DataModelArea area);
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/exception/ModelStructureException.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/exception/ModelStructureException.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/exception/ModelStructureException.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,21 @@
+package org.cishell.utility.datastructure.datamodel.exception;
+
+public class ModelStructureException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public ModelStructureException() {
+ super();
+ }
+
+ public ModelStructureException(String arg0) {
+ super(arg0);
+ }
+
+ public ModelStructureException(Throwable arg0) {
+ super(arg0);
+ }
+
+ public ModelStructureException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/exception/ModelValidationException.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/exception/ModelValidationException.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/exception/ModelValidationException.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,21 @@
+package org.cishell.utility.datastructure.datamodel.exception;
+
+public class ModelValidationException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public ModelValidationException() {
+ super();
+ }
+
+ public ModelValidationException(String arg0) {
+ super(arg0);
+ }
+
+ public ModelValidationException(Throwable arg0) {
+ super(arg0);
+ }
+
+ public ModelValidationException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/exception/UniqueNameException.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/exception/UniqueNameException.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/exception/UniqueNameException.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,21 @@
+package org.cishell.utility.datastructure.datamodel.exception;
+
+public class UniqueNameException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public UniqueNameException() {
+ super();
+ }
+
+ public UniqueNameException(String arg0) {
+ super(arg0);
+ }
+
+ public UniqueNameException(Throwable arg0) {
+ super(arg0);
+ }
+
+ public UniqueNameException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelField.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelField.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelField.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,29 @@
+package org.cishell.utility.datastructure.datamodel.field;
+
+import java.util.Collection;
+
+import org.cishell.utility.datastructure.datamodel.DataModel;
+
+/**
+ * DataModelFields are the meat of DataModels.
+ * They contain the actual data and internal behavior/user-interaction logic.
+ */
+public interface DataModelField<ValueType> {
+ public Collection<DataModelFieldContainer> getContainers();
+ public boolean addToContainer(DataModelFieldContainer container);
+
+ public String getName();
+ public Object getParentComponent();
+ public ValueType getDefaultValue();
+ public ValueType getPreviousValue();
+ public ValueType getValue();
+ public ValueType setValue(ValueType value);
+ public ValueType reset();
+
+ public void addValidationRule(
+ FieldValidationRule<ValueType> validator, boolean validateNow, DataModel model);
+ public void addValidationAction(FieldValidationAction<ValueType> validationAction);
+ public void validate(DataModel model);
+
+ public void dispose();
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelFieldContainer.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelFieldContainer.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelFieldContainer.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,14 @@
+package org.cishell.utility.datastructure.datamodel.field;
+
+import java.util.Collection;
+
+import org.cishell.utility.datastructure.datamodel.exception.UniqueNameException;
+
+public interface DataModelFieldContainer {
+ public Collection<String> getFieldNames();
+ public Collection<DataModelField<?>> getFields();
+ public DataModelField<?> getField(String fieldName);
+ public<T> void addField(DataModelField<T> field) throws UniqueNameException;
+ public boolean fieldDisposed(String fieldName);
+ public<T> boolean fieldDisposed(DataModelField<T> field);
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/FieldValidationAction.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/FieldValidationAction.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/FieldValidationAction.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,12 @@
+package org.cishell.utility.datastructure.datamodel.field;
+
+import java.util.Collection;
+
+import org.cishell.utility.datastructure.datamodel.exception.ModelValidationException;
+
+public interface FieldValidationAction<ValueType> {
+ public void fieldDoesValidate(DataModelField<ValueType> field);
+ public void fieldDoesNotValidate(
+ DataModelField<ValueType> field, Collection<ModelValidationException> reasons);
+ public void fieldDisposed(DataModelField<ValueType> field);
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/FieldValidationRule.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/FieldValidationRule.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/FieldValidationRule.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,10 @@
+package org.cishell.utility.datastructure.datamodel.field;
+
+import org.cishell.utility.datastructure.datamodel.DataModel;
+import org.cishell.utility.datastructure.datamodel.exception.ModelValidationException;
+
+public interface FieldValidationRule<ValueType> {
+ public void validateField(DataModelField<ValueType> field, DataModel model)
+ throws ModelValidationException;
+ public void fieldDisposed(DataModelField<ValueType> field);
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/group/BasicModelGroup.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/group/BasicModelGroup.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/group/BasicModelGroup.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,68 @@
+package org.cishell.utility.datastructure.datamodel.group;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.cishell.utility.datastructure.datamodel.exception.UniqueNameException;
+import org.cishell.utility.datastructure.datamodel.field.DataModelField;
+
+public class BasicModelGroup implements DataModelGroup {
+ private String name;
+ private Map<String, DataModelField<?>> fields = new HashMap<String, DataModelField<?>>();
+
+ public BasicModelGroup(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public Collection<String> getFieldNames() {
+ return this.fields.keySet();
+ }
+
+ public Collection<DataModelField<?>> getFields() {
+ Collection<DataModelField<?>> fields = new ArrayList<DataModelField<?>>();
+ fields.addAll(this.fields.values());
+
+ return fields;
+ }
+
+ public DataModelField<?> getField(String name) {
+ return this.fields.get(name);
+ }
+
+ public<T> void addField(DataModelField<T> field)
+ throws ClassCastException, UniqueNameException {
+ String fieldName = field.getName();
+
+ if (this.fields.containsKey(fieldName)) {
+ String format =
+ "The field '%s' already exists in this group (%s). " +
+ "All fields must have unique names.";
+ String exceptionMessage = String.format(
+ format, fieldName, this.name);
+ throw new UniqueNameException(exceptionMessage);
+ }
+
+ this.fields.put(fieldName, field);
+ field.addToContainer(this);
+ }
+
+ public boolean fieldDisposed(String fieldName) {
+ if (this.fields.containsKey(fieldName)) {
+ this.fields.remove(fieldName);
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public<T> boolean fieldDisposed(DataModelField<T> field) {
+ return fieldDisposed(field.getName());
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/group/DataModelGroup.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/group/DataModelGroup.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/group/DataModelGroup.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,24 @@
+package org.cishell.utility.datastructure.datamodel.group;
+
+import java.util.Collection;
+
+import org.cishell.utility.datastructure.datamodel.exception.UniqueNameException;
+import org.cishell.utility.datastructure.datamodel.field.DataModelField;
+import org.cishell.utility.datastructure.datamodel.field.DataModelFieldContainer;
+
+/**
+ * Model groups are organizational structures for related DataModelFields.
+ * They are not tied to the physical structure of a GUI.
+ * Anything that wishes to retrieve data from a DataModel can ask for ModelGroups.
+ */
+public interface DataModelGroup extends DataModelFieldContainer {
+ public String getName();
+
+ public Collection<String> getFieldNames();
+ public Collection<DataModelField<?>> getFields();
+ public DataModelField<?> getField(String fieldName);
+ public<T> void addField(DataModelField<T> field)
+ throws ClassCastException, UniqueNameException;
+ public boolean fieldDisposed(String fieldName);
+ public<T> boolean fieldDisposed(DataModelField<T> field);
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/gui/AbstractGUIDataModel.java
===================================================================
--- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/gui/AbstractGUIDataModel.java (rev 0)
+++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/gui/AbstractGUIDataModel.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,158 @@
+package org.cishell.utility.datastructure.datamodel.gui;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.cishell.utility.datastructure.datamodel.DataModel;
+import org.cishell.utility.datastructure.datamodel.area.DataModelArea;
+import org.cishell.utility.datastructure.datamodel.exception.ModelStructureException;
+import org.cishell.utility.datastructure.datamodel.exception.UniqueNameException;
+import org.cishell.utility.datastructure.datamodel.field.DataModelField;
+import org.cishell.utility.datastructure.datamodel.group.BasicModelGroup;
+import org.cishell.utility.datastructure.datamodel.group.DataModelGroup;
+
+/// TODO: Document this.
+/// TODO: Figure out a way to generically express styles for both widgets and areas.
+public abstract class AbstractGUIDataModel<
+ BaseGUIComponentType, GUIContainerComponentType extends BaseGUIComponentType>
+ implements DataModel {
+ private Map<String, DataModelArea> areas = new HashMap<String, DataModelArea>();
+ private Map<String, DataModelGroup> groups = new HashMap<String, DataModelGroup>();
+ private GUIContainerComponentType currentParentComponent;
+
+ public AbstractGUIDataModel() {
+ }
+
+ // Miscellaneous methods
+
+ @SuppressWarnings("unchecked")
+ public void setCurrentParentComponent(Object currentParentComponent)
+ throws ClassCastException {
+ this.currentParentComponent = (GUIContainerComponentType) currentParentComponent;
+ }
+
+ public GUIContainerComponentType getCurrentParentComponent() {
+ return this.currentParentComponent;
+ }
+
+ // DataModelAreaContainer methods (via DataModel)
+
+ public Collection<String> getAreaNames() {
+ return this.areas.keySet();
+ }
+
+ public Collection<DataModelArea> getAreas() {
+ return this.areas.values();
+ }
+
+ public DataModelArea getArea(String name) {
+ return this.areas.get(name);
+ }
+
+ public DataModelArea createArea(String name) throws UniqueNameException {
+ if (getArea(name) != null) {
+ String exceptionMessage = String.format(
+ "The area '%s' already exists. All areas must have unique names.", name);
+ throw new UniqueNameException(exceptionMessage);
+ } else {
+ DataModelArea area = createGUISpecificArea(name);
+ this.areas.put(name, area);
+
+ return area;
+ }
+ }
+
+ public abstract DataModelArea createArea(String name, Object componentForArea)
+ throws ClassCastException, ModelStructureException, UniqueNameException;
+
+ protected abstract DataModelArea createGUISpecificArea(String name);
+
+ public void addArea(DataModelArea area)
+ throws ClassCastException, ModelStructureException, UniqueNameException {
+ String name = area.getName();
+
+ if (getArea(name) != null) {
+ String exceptionMessage = String.format(
+ "The area '%s' already exists. All areas must have unique names.", name);
+ throw new UniqueNameException(exceptionMessage);
+ } else {
+ this.areas.put(name, area);
+ }
+ }
+
+ public boolean areaDisposed(String name) {
+ if (this.areas.containsKey(name)) {
+ this.areas.remove(name);
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public boolean areaDisposed(DataModelArea area) {
+ return areaDisposed(area.getName());
+ }
+
+ // Group methods
+
+ public Collection<String> getGroupNames() {
+ return this.groups.keySet();
+ }
+
+ public Collection<DataModelGroup> getGroups() {
+ return this.groups.values();
+ }
+
+ public DataModelGroup getGroup(String name) {
+ return this.groups.get(name);
+ }
+
+ public DataModelGroup createGroup(String name) throws UniqueNameException {
+ if (getGroup(name) != null) {
+ String exceptionMessage = String.format(
+ "The group '%s' already exists. All groups must have unique names.", name);
+ throw new UniqueNameException(exceptionMessage);
+ } else {
+ DataModelGroup group = new BasicModelGroup(name);
+ this.groups.put(name, group);
+
+ return group;
+ }
+ }
+
+ // Add Field methods
+
+ public abstract DataModelField<Boolean> addCheckBox(
+ String name,
+ String areaName,
+ String groupName,
+ boolean defaultOn) throws UniqueNameException;
+
+ public abstract<T> DataModelField<T> addDropDown(
+ String name,
+ String areaName,
+ String groupName,
+ int selectedIndex,
+ Collection<String> unorderedOptionLabels,
+ Map<String, T> optionValuesByLabels) throws UniqueNameException;
+
+ public abstract<T> DataModelField<T> addList(
+ String name,
+ String areaName,
+ String groupName,
+ int selectedIndex,
+ Collection<String> unorderedOptionLabels,
+ Map<String, T> optionValuesByLabels) throws UniqueNameException;
+
+ public abstract DataModelField<String> addText(
+ String name,
+ String areaName,
+ String groupName,
+ String defaultValue,
+ boolean isMultiLined) throws UniqueNameException;
+
+ public abstract<T> void addField(String areaName, String groupName, DataModelField<T> field)
+ throws UniqueNameException;
+}
\ No newline at end of file
Modified: trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF
===================================================================
--- trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF 2010-08-23 18:06:40 UTC (rev 1127)
+++ trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF 2010-08-23 18:07:46 UTC (rev 1128)
@@ -8,7 +8,13 @@
org.eclipse.core.runtime
Import-Package: com.google.common.collect,
org.cishell.utilities,
- org.cishell.utility.datastructure
+ org.cishell.utility.datastructure,
+ org.cishell.utility.datastructure.datamodel,
+ org.cishell.utility.datastructure.datamodel.area,
+ org.cishell.utility.datastructure.datamodel.exception,
+ org.cishell.utility.datastructure.datamodel.field,
+ org.cishell.utility.datastructure.datamodel.group,
+ org.cishell.utility.datastructure.datamodel.gui
Export-Package: org.cishell.utility.swt,
org.cishell.utility.swt.model,
org.cishell.utility.swt.model.datasynchronizer
Modified: trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/ExpandableComponentWidget.java
===================================================================
--- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/ExpandableComponentWidget.java 2010-08-23 18:06:40 UTC (rev 1127)
+++ trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/ExpandableComponentWidget.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -65,7 +65,8 @@
return 1;
}
- public T addComponent(int style, Map<String, Object> arguments) {
+ public T addComponent(int style, Map<String, Object> arguments)
+ throws WidgetConstructionException {
// TODO: Fix this terrible hack?
if (this.components.size() == 0) {
for (Label columnLabel : this.columnLabels) {
@@ -75,7 +76,12 @@
final int componentCount = this.components.size();
T component = this.componentFactory.constructWidget(
- this, this.scrolledAreaGrid, style, arguments, componentCount, this.uniqueComponentCount);
+ this,
+ this.scrolledAreaGrid,
+ style,
+ arguments,
+ componentCount,
+ this.uniqueComponentCount);
this.uniqueComponentCount++;
fixSize();
Modified: trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/ScrolledComponentFactory.java
===================================================================
--- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/ScrolledComponentFactory.java 2010-08-23 18:06:40 UTC (rev 1127)
+++ trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/ScrolledComponentFactory.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -9,7 +9,7 @@
int style,
Map<String, Object> arguments,
int index,
- int uniqueIndex);
+ int uniqueIndex) throws WidgetConstructionException;
public void reindexComponent(T component, int newIndex);
}
\ No newline at end of file
Added: trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/WidgetConstructionException.java
===================================================================
--- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/WidgetConstructionException.java (rev 0)
+++ trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/WidgetConstructionException.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,21 @@
+package org.cishell.utility.swt;
+
+public class WidgetConstructionException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public WidgetConstructionException() {
+ super();
+ }
+
+ public WidgetConstructionException(String arg0) {
+ super(arg0);
+ }
+
+ public WidgetConstructionException(Throwable arg0) {
+ super(arg0);
+ }
+
+ public WidgetConstructionException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+}
\ No newline at end of file
Deleted: trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/GUIModel.java
===================================================================
--- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/GUIModel.java 2010-08-23 18:06:40 UTC (rev 1127)
+++ trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/GUIModel.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -1,190 +0,0 @@
-package org.cishell.utility.swt.model;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.cishell.utility.swt.model.datasynchronizer.CheckBoxDataSynchronizer;
-import org.cishell.utility.swt.model.datasynchronizer.DropDownDataSynchronizer;
-import org.cishell.utility.swt.model.datasynchronizer.ModelDataSynchronizer;
-import org.cishell.utility.swt.model.datasynchronizer.SingleListSelectionDataSynchronizer;
-import org.cishell.utility.swt.model.datasynchronizer.TextDataSynchronizer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.List;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.Widget;
-
-public class GUIModel {
- private Map<String, GUIModelGroup> groups = new HashMap<String, GUIModelGroup>();
-
- public GUIModel() {
- }
-
- public Collection<String> getGroupNames() {
- return this.groups.keySet();
- }
-
- public Collection<GUIModelGroup> getGroups() {
- return this.groups.values();
- }
-
- public GUIModelGroup getGroup(String name) {
- if (!this.groups.containsKey(name)) {
- GUIModelGroup newGroup = new GUIModelGroup(name);
- this.groups.put(name, newGroup);
-
- return newGroup;
- } else {
- return this.groups.get(name);
- }
- }
-
- public GUIModelField<Boolean, Button, CheckBoxDataSynchronizer> addCheckBox(
- String groupName, String name, boolean on, Composite parent, int style) {
- Button checkBox = new Button(parent, style | SWT.CHECK);
- CheckBoxDataSynchronizer dataSynchronizer = new CheckBoxDataSynchronizer(checkBox, on);
- GUIModelField<Boolean, Button, CheckBoxDataSynchronizer> field =
- new GUIModelField<Boolean, Button, CheckBoxDataSynchronizer>(
- name, on, checkBox, dataSynchronizer);
- addField(groupName, field);
-
- return field;
- }
-
- public GUIModelField<String, Combo, DropDownDataSynchronizer> addDropDown(
- String groupName,
- String name,
- int selectedIndex,
- Collection<String> unorderedOptionLabels,
- Map<String, String> optionValuesByLabels,
- Composite parent,
- int style) {
- java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels);
- Combo dropDown = new Combo(parent, style | SWT.DROP_DOWN);
- DropDownDataSynchronizer dataSynchronizer = new DropDownDataSynchronizer(
- dropDown, selectedIndex, orderedOptionLabels, optionValuesByLabels);
- GUIModelField<String, Combo, DropDownDataSynchronizer> field =
- new GUIModelField<String, Combo, DropDownDataSynchronizer>(
- name,
- optionValuesByLabels.get(orderedOptionLabels.get(selectedIndex)),
- dropDown,
- dataSynchronizer);
- addField(groupName, field);
-
- return field;
- }
-
- // TODO: addMultiSelectionDropDown
-
- // TODO: Test this out.
- // TODO: Make it so the build works with this stuff.
-// public GUIModelField<
-// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer>
-// addDate(String name, org.joda.time.DateTime date, Composite parent, int style) {
-// org.eclipse.swt.widgets.DateTime dateSelector =
-// new org.eclipse.swt.widgets.DateTime(parent, style | SWT.DATE);
-// DateDataSynchronizer dataSynchronizer = new DateDataSynchronizer(dateSelector, date);
-// GUIModelField<
-// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer> field =
-// new GUIModelField<
-// org.joda.time.DateTime,
-// org.eclipse.swt.widgets.DateTime,
-// DateDataSynchronizer>(
-// name, date, dateSelector, dataSynchronizer);
-// addField(field);
-//
-// return field;
-// }
-
- // TODO: Test this out.
-// public GUIModelField<
-// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer>
-// addTime(String name, org.joda.time.DateTime time, Composite parent, int style) {
-// org.eclipse.swt.widgets.DateTime timeSelector =
-// new org.eclipse.swt.widgets.DateTime(parent, style | SWT.TIME);
-// TimeDataSynchronizer dataSynchronizer = new TimeDataSynchronizer(timeSelector, time);
-// GUIModelField<
-// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer> field =
-// new GUIModelField<
-// org.joda.time.DateTime,
-// org.eclipse.swt.widgets.DateTime,
-// TimeDataSynchronizer>(
-// name, time, timeSelector, dataSynchronizer);
-// addField(field);
-//
-// return field;
-// }
-
- // TODO: addCalendar
-
- // TODO: Test this out.
- public GUIModelField<String, List, SingleListSelectionDataSynchronizer> addList(
- String groupName,
- String name,
- int selectedIndex,
- Collection<String> unorderedOptionLabels,
- Map<String, String> optionValuesByLabels,
- Composite parent,
- int style) {
- java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels);
- List list = new List(parent, style | SWT.SINGLE);
- SingleListSelectionDataSynchronizer dataSynchronizer =
- new SingleListSelectionDataSynchronizer(
- list, selectedIndex, orderedOptionLabels, optionValuesByLabels);
- GUIModelField<String, List, SingleListSelectionDataSynchronizer> field =
- new GUIModelField<String, List, SingleListSelectionDataSynchronizer>(
- name, list.getItem(selectedIndex), list, dataSynchronizer);
- addField(groupName, field);
-
- return field;
- }
-
- // TODO: addMultiSelectionList
- // TODO: addProgressBar
- // TODO: addSash?
- // TODO: addSlider
- // TODO: addScale
- // TODO: addSpinner
- // TODO: addStyledText
-
- public GUIModelField<String, Text, TextDataSynchronizer> addText(
- String groupName,
- String name,
- String value,
- boolean isMultiLined,
- Composite parent,
- int style) {
- if (isMultiLined) {
- style = style | SWT.MULTI;
- } else {
- style = style | SWT.SINGLE;
- }
-
- Text text = new Text(parent, style);
- TextDataSynchronizer dataSynchronizer = new TextDataSynchronizer(text, value);
- GUIModelField<String, Text, TextDataSynchronizer> field =
- new GUIModelField<String, Text, TextDataSynchronizer>(
- name, value, text, dataSynchronizer);
- addField(groupName, field);
-
- return field;
- }
-
- public<T> void addField(
- String groupName,
- GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) {
- GUIModelGroup group = getGroup(groupName);
- group.addField(field);
- }
-
- public<T> void removeField(
- GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) {
- for (GUIModelGroup group : this.groups.values()) {
- group.removeField(field);
- }
- }
-}
\ No newline at end of file
Deleted: trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/GUIModelField.java
===================================================================
--- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/GUIModelField.java 2010-08-23 18:06:40 UTC (rev 1127)
+++ trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/GUIModelField.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -1,65 +0,0 @@
-package org.cishell.utility.swt.model;
-
-import org.cishell.utility.swt.model.datasynchronizer.ModelDataSynchronizer;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Widget;
-
-public class GUIModelField<T, U extends Widget, V extends ModelDataSynchronizer<T>> {
- private String name;
- private T defaultValue;
- private T previousValue;
- private T value;
- private U widget;
- private V dataSynchronizer;
-
- public GUIModelField(
- String name,
- T defaultValue,
- U widget,
- V dataSynchronizer) {
- this.name = name;
- this.defaultValue = defaultValue;
- this.value = this.defaultValue;
- this.widget = widget;
- this.dataSynchronizer = dataSynchronizer;
-
- this.widget.addListener(this.dataSynchronizer.swtUpdateListenerCode(), new Listener() {
- public void handleEvent(Event event) {
- if (event.type == GUIModelField.this.dataSynchronizer.swtUpdateListenerCode()) {
- GUIModelField.this.previousValue = GUIModelField.this.value;
- GUIModelField.this.value =
- GUIModelField.this.dataSynchronizer.synchronizeFromGUI();
- }
- }
- });
- }
-
- public String getName() {
- return this.name;
- }
-
- public T getPreviousValue() {
- return this.previousValue;
- }
-
- public T getValue() {
- return this.value;
- }
-
- public U getWidget() {
- return this.widget;
- }
-
- public V getDataSynchronizer() {
- return this.dataSynchronizer;
- }
-
- public void setValue(T value) {
- this.value = this.dataSynchronizer.synchronizeToGUI(value);
- }
-
- public void reset() {
- this.value = this.dataSynchronizer.reset(this.defaultValue);
- }
-}
\ No newline at end of file
Deleted: trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/GUIModelGroup.java
===================================================================
--- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/GUIModelGroup.java 2010-08-23 18:06:40 UTC (rev 1127)
+++ trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/GUIModelGroup.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -1,57 +0,0 @@
-package org.cishell.utility.swt.model;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.cishell.utility.swt.model.datasynchronizer.ModelDataSynchronizer;
-import org.eclipse.swt.widgets.Widget;
-
-public class GUIModelGroup {
- private String name;
- private Map<String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>>
- inputFieldsByName = new HashMap<
- String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>>();
-
- public GUIModelGroup(String name) {
- this.name = name;
- }
-
- public String getName() {
- return this.name;
- }
-
- public Collection<String> getFieldNames() {
- return this.inputFieldsByName.keySet();
- }
-
- public Collection<
- GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>> getFields() {
- return this.inputFieldsByName.values();
- }
-
- public GUIModelField<
- ?, ? extends Widget, ? extends ModelDataSynchronizer<?>> getField(String name) {
- return this.inputFieldsByName.get(name);
- }
-
- public<T> void addField(
- GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) {
- String fieldName = field.getName();
-
- if (this.inputFieldsByName.containsKey(fieldName)) {
- String exceptionMessage =
- "A field with the name \"" + fieldName + "\" already exists. Unable to continue.";
- throw new ModelFieldException(exceptionMessage);
- }
-
- this.inputFieldsByName.put(fieldName, field);
- }
-
- public<T> void removeField(
- GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) {
- if (this.inputFieldsByName.containsValue(field)) {
- this.inputFieldsByName.remove(field.getName());
- }
- }
-}
\ No newline at end of file
Copied: trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModel.java (from rev 1118, trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/GUIModel.java)
===================================================================
--- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModel.java (rev 0)
+++ trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModel.java 2010-08-23 18:07:46 UTC (rev 1128)
@@ -0,0 +1,237 @@
+package org.cishell.utility.swt.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+
+import org.cishell.utilities.StringUtilities;
+import org.cishell.utility.datastructure.datamodel.area.DataModelArea;
+import org.cishell.utility.datastructure.datamodel.exception.ModelStructureException;
+import org.cishell.utility.datastructure.datamodel.exception.UniqueNameException;
+import org.cishell.utility.datastructure.datamodel.field.DataModelField;
+import org.cishell.utility.datastructure.datamodel.group.DataModelGroup;
+import org.cishell.utility.datastructure.datamodel.gui.AbstractGUIDataModel;
+import org.cishell.utility.swt.model.datasynchronizer.CheckBoxDataSynchronizer;
+import org.cishell.utility.swt.model.datasynchronizer.DropDownDataSynchronizer;
+import org.cishell.utility.swt.model.datasynchronizer.SingleListSelectionDataSynchronizer;
+import org.cishell.utility.swt.model.datasynchronizer.TextDataSynchronizer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Widget;
+
+public class SWTModel extends AbstractGUIDataModel<Widget, Composite> {
+ private int newAreaStyle;
+
+ public SWTModel(int newAreaStyle) {
+ this.newAreaStyle = newAreaStyle;
+ }
+
+ @Override
+ public DataModelArea createArea(String name, Object componentForArea)
+ throws ClassCastException, ModelStructureException, UniqueNameException {
+ if (getArea(name) != null) {
+ String exceptionMessage = String.format(
+ "The area '%s' already exists. All areas must have unique names.", name);
+ throw new UniqueNameException(exceptionMessage);
+ } else {
+ DataModelArea area = new SWTModelArea(
+ null,
+ null,
+ name,
+ (Composite) com...
[truncated message content] |