You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(7) |
Aug
|
Sep
(46) |
Oct
(102) |
Nov
(10) |
Dec
(21) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(1) |
Feb
(3) |
Mar
(14) |
Apr
(9) |
May
(12) |
Jun
(4) |
Jul
(40) |
Aug
(60) |
Sep
(38) |
Oct
(2) |
Nov
(1) |
Dec
(42) |
2008 |
Jan
(23) |
Feb
(29) |
Mar
(107) |
Apr
(27) |
May
(3) |
Jun
(1) |
Jul
(15) |
Aug
(7) |
Sep
(19) |
Oct
|
Nov
(2) |
Dec
|
2009 |
Jan
(36) |
Feb
(4) |
Mar
(2) |
Apr
(1) |
May
(1) |
Jun
(15) |
Jul
(30) |
Aug
(32) |
Sep
(11) |
Oct
(21) |
Nov
(12) |
Dec
(15) |
2010 |
Jan
(29) |
Feb
(9) |
Mar
(25) |
Apr
|
May
(7) |
Jun
(5) |
Jul
(21) |
Aug
(32) |
Sep
(10) |
Oct
(8) |
Nov
(29) |
Dec
(8) |
2011 |
Jan
(9) |
Feb
(35) |
Mar
(11) |
Apr
(4) |
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(30) |
2012 |
Jan
(5) |
Feb
(7) |
Mar
(10) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <pat...@us...> - 2010-11-12 16:51:06
|
Revision: 1152 http://cishell.svn.sourceforge.net/cishell/?rev=1152&view=rev Author: pataphil Date: 2010-11-12 16:50:55 +0000 (Fri, 12 Nov 2010) Log Message: ----------- * Made more Java 1.5 and cleaned up a bit. * Fixed bug in validation relating to multiple fields validating depending on each other. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/BooleanComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/LabelingComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/MultiValuedComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java 2010-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -37,10 +37,6 @@ import org.osgi.service.metatype.MetaTypeProvider; import org.osgi.service.metatype.ObjectClassDefinition; -/** - * - * @author Bruce Herr (bh...@bh...) - */ public class SWTGui implements GUI, UpdateListener { private static final int MAXIMUM_INITIAL_DIALOGUE_HEIGHT = 500; @@ -53,8 +49,7 @@ private Button okButton; - public SWTGui(final Shell shell, int style, - String id, MetaTypeProvider provider) { + public SWTGui(final Shell shell, int style, String id, MetaTypeProvider provider) { this.shell = shell; if (provider == null) { @@ -62,20 +57,18 @@ } ObjectClassDefinition ocd = provider.getObjectClassDefinition(id, null); - shell.setText(ocd.getName()); - - - + this.shell.setText(ocd.getName()); + GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 1; - shell.setLayout(gridLayout); + this.shell.setLayout(gridLayout); - Font defaultFont = new Font(shell.getDisplay(), "SanSerif", 8, SWT.NONE); + Font defaultFont = new Font(this.shell.getDisplay(), "SanSerif", 8, SWT.NONE); //stuff to display a message String message = ocd.getDescription(); if(message != null && !message.equals("")){ - Label msg = new Label(shell, SWT.WRAP); + Label msg = new Label(this.shell, SWT.WRAP); msg.setText(message); msg.pack(true); GridData labelData = new GridData(); @@ -88,11 +81,11 @@ } //set up the user area where the main GUI will be set up using Parameters - composite = new SWTGuiComposite(shell, style, id, provider); + composite = new SWTGuiComposite(this.shell, style, id, provider); composite.addUpdateListener(this); //the group w/ ok and cancel - Composite buttonsGroup = new Composite(shell, SWT.NONE); + Composite buttonsGroup = new Composite(this.shell, SWT.NONE); FillLayout rowLayout = new FillLayout(); rowLayout.spacing = 5; buttonsGroup.setLayout(rowLayout); @@ -103,11 +96,11 @@ gridData.grabExcessHorizontalSpace = false; buttonsGroup.setLayoutData(gridData); - okButton = new Button(buttonsGroup, SWT.PUSH); - okButton.setText("OK"); - okButton.setSize(40, 20); - okButton.setFont(defaultFont); - okButton.addSelectionListener(new SelectionAdapter() { + this.okButton = new Button(buttonsGroup, SWT.PUSH); + this.okButton.setText("OK"); + this.okButton.setSize(40, 20); + this.okButton.setFont(defaultFont); + this.okButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { hitOk = true; close(); @@ -129,14 +122,14 @@ }); - shell.addDisposeListener(new DisposeListener() { + this.shell.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { if (!hitOk && listener != null) { listener.cancelled(); } }}); - shell.setDefaultButton(okButton); + this.shell.setDefaultButton(this.okButton); validate(); } @@ -145,10 +138,10 @@ * @see org.cishell.service.guibuilder.GUI#close() */ public void close() { - shell.getDisplay().syncExec(new Runnable() { + this.shell.getDisplay().syncExec(new Runnable() { public void run() { - shell.close(); - shell.dispose(); + SWTGui.this.shell.close(); + SWTGui.this.shell.dispose(); }}); } @@ -156,18 +149,18 @@ * @see org.cishell.service.guibuilder.GUI#isClosed() */ public boolean isClosed() { - return shell.isDisposed(); + return this.shell.isDisposed(); } /** * @see org.cishell.service.guibuilder.GUI#open() */ public void open() { - shell.getDisplay().syncExec(new Runnable() { + this.shell.getDisplay().syncExec(new Runnable() { public void run() { - shell.pack(); - resizeShell(shell); - shell.open(); + SWTGui.this.shell.pack(); + resizeShell(SWTGui.this.shell); + SWTGui.this.shell.open(); } private void resizeShell(Shell shell) { @@ -183,7 +176,7 @@ /** * @see org.cishell.service.guibuilder.GUI#openAndWait() */ - public Dictionary openAndWait() { + public Dictionary<String, Object> openAndWait() { open(); final Display display = shell.getDisplay(); @@ -201,11 +194,11 @@ } private static class OpenAndWaitListener implements SelectionListener { - Dictionary valuesEntered = null; + Dictionary<String, Object> valuesEntered = null; public void cancelled() {} - public void hitOk(Dictionary valuesEntered) { + public void hitOk(Dictionary<String, Object> valuesEntered) { this.valuesEntered = valuesEntered; } } @@ -220,11 +213,11 @@ public String validate() { String valid = composite.validate(); - //if valid is a string then the string is the error message - if (valid != null && valid.length() > 0) { - okButton.setEnabled(false); + // If valid is a string then the string is the error message. + if ((valid != null) && (valid.length() > 0)) { + this.okButton.setEnabled(false); } else { - okButton.setEnabled(true); + this.okButton.setEnabled(true); } return valid; Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java 2010-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -16,7 +16,6 @@ import java.util.Dictionary; import java.util.HashSet; import java.util.Hashtable; -import java.util.Iterator; import java.util.Set; import org.cishell.reference.gui.guibuilder.swt.builder.ComponentProvider; @@ -40,53 +39,50 @@ * @author Bruce Herr (bh...@bh...) */ public class SWTGuiComposite implements UpdateListener { - private ObjectClassDefinition ocd; - private Dictionary idToComponentMap; - private Dictionary enteredResponses; - protected Set listeners; + private ObjectClassDefinition objectClassDefinition; + private Dictionary<String, GUIComponent> idToComponentMap; + private Dictionary<String, Object> enteredResponses; + protected Set<UpdateListener> updateListeners; private Composite parent; private Composite parameterArea; - private ScrolledComposite scroll; - private int style; + private ScrolledComposite scrollingArea; - public SWTGuiComposite(Composite parent, int style, - String id, MetaTypeProvider provider) { + public SWTGuiComposite(Composite parent, int style, String id, MetaTypeProvider provider) { if (provider == null) { throw new IllegalArgumentException("Null MetaTypeProvider given"); } - this.idToComponentMap = new Hashtable(); - this.ocd = provider.getObjectClassDefinition(id, null); + this.idToComponentMap = new Hashtable<String, GUIComponent>(); + this.objectClassDefinition = provider.getObjectClassDefinition(id, null); this.parent = parent; - this.style = style; - this.listeners = new HashSet(); - this.enteredResponses = new Hashtable(); + this.updateListeners = new HashSet<UpdateListener>(); + this.enteredResponses = new Hashtable<String, Object>(); setupGUI(); - - AttributeDefinition[] attrs = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); - for (int i=0; i < attrs.length; i++) { - GUIComponent component = ComponentProvider.getInstance().createComponent(attrs[i]); - - component.setAttributeDefinition(attrs[i]); - component.createGUI(parameterArea, style); - idToComponentMap.put(attrs[i].getID(), component); + + for (AttributeDefinition attribute : + this.objectClassDefinition.getAttributeDefinitions(ObjectClassDefinition.ALL)) { + GUIComponent component = ComponentProvider.getInstance().createComponent(attribute); + + component.setAttributeDefinition(attribute); + component.createGUI(this.parameterArea, style); + this.idToComponentMap.put(attribute.getID(), component); component.addUpdateListener(this); Object value = component.getValue(); String valid = component.validate(); - if (value != null && (valid == null || valid.length() == 0)) { - enteredResponses.put(component.getAttributeDefinition().getID(), value); + if ((value != null) && ((valid == null) || (valid.length() == 0))) { + this.enteredResponses.put(component.getAttributeDefinition().getID(), value); } } - setScrollDimensions(scroll, parameterArea); + setScrollDimensions(this.scrollingArea, this.parameterArea); - parameterArea.addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - enteredResponses = getEnteredResponses(); + this.parameterArea.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent event) { + SWTGuiComposite.this.enteredResponses = getEnteredResponses(); }}); } @@ -97,17 +93,17 @@ } private void setupGUI() { - scroll = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); - scroll.setLayout(new GridLayout(1, true)); - scroll.setExpandHorizontal(true); - scroll.setExpandVertical(true); - scroll.setAlwaysShowScrollBars(false); + this.scrollingArea = new ScrolledComposite(this.parent, SWT.H_SCROLL | SWT.V_SCROLL); + this.scrollingArea.setLayout(new GridLayout(1, true)); + this.scrollingArea.setExpandHorizontal(true); + this.scrollingArea.setExpandVertical(true); + this.scrollingArea.setAlwaysShowScrollBars(false); - parameterArea = new Composite(scroll, SWT.NONE); - parameterArea.setLayout(new GridLayout(GUIComponent.MAX_SPAN+1,false)); + this.parameterArea = new Composite(scrollingArea, SWT.NONE); + this.parameterArea.setLayout(new GridLayout(GUIComponent.MAX_SPAN + 1, false)); - GridData gd = new GridData(SWT.FILL,SWT.FILL,true,true); - parameterArea.setLayoutData(gd); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + this.parameterArea.setLayoutData(gridData); GridData userData = new GridData(); userData.grabExcessVerticalSpace = true; @@ -115,23 +111,28 @@ userData.verticalAlignment = SWT.FILL; userData.horizontalAlignment = SWT.FILL; - scroll.setLayoutData(userData); - scroll.setContent(parameterArea); + this.scrollingArea.setLayoutData(userData); + this.scrollingArea.setContent(this.parameterArea); } public ObjectClassDefinition getObjectClassDefinition() { - return ocd; + return this.objectClassDefinition; } public Object getResponse(String id) { - GUIComponent component = (GUIComponent) idToComponentMap.get(id); - - return component == null ? null : component.getValue(); + GUIComponent component = this.idToComponentMap.get(id); + + if (component != null) { + return component.getValue(); + } else { + return null; + } +// return component == null ? null : component.getValue(); } - public Dictionary getEnteredResponses() { - return enteredResponses; + public Dictionary<String, Object> getEnteredResponses() { + return this.enteredResponses; } /** @@ -139,7 +140,7 @@ * @return the shell */ public Shell getShell() { - return parent.getShell(); + return this.parent.getShell(); } /** @@ -147,22 +148,22 @@ * @return the composite */ public Composite getUserArea() { - return parameterArea; + return this.parameterArea; } public Composite getComposite() { - return scroll; + return this.scrollingArea; } public String validate() { String totalValid = ""; - - AttributeDefinition[] attrs = ocd.getAttributeDefinitions(ObjectClassDefinition.REQUIRED); - - for (int i=0; i < attrs.length; i++) { - GUIComponent component = (GUIComponent) idToComponentMap.get(attrs[i].getID()); + + for (AttributeDefinition attribute : this.objectClassDefinition.getAttributeDefinitions( + ObjectClassDefinition.REQUIRED)) { + GUIComponent component = this.idToComponentMap.get(attribute.getID()); String valid = component.validate(); - if (valid != null && valid.length() > 0) { + + if ((valid != null) && (valid.length() > 0)) { totalValid += "\"" + valid + "\"; "; } } @@ -174,22 +175,22 @@ Object value = component.getValue(); String valid = component.validate(); - if (value != null && (valid == null || valid.length() == 0)) { - enteredResponses.put(component.getAttributeDefinition().getID(), value); + if ((value != null) && ((valid == null) || (valid.length() == 0))) { + this.enteredResponses.put(component.getAttributeDefinition().getID(), value); } else { - enteredResponses.remove(component.getAttributeDefinition().getID()); + this.enteredResponses.remove(component.getAttributeDefinition().getID()); } - - for (Iterator i=listeners.iterator(); i.hasNext(); ) { - ((UpdateListener) i.next()).componentUpdated(component); + + for (UpdateListener listener : this.updateListeners) { + listener.componentUpdated(component); } } public void addUpdateListener(UpdateListener listener) { - listeners.add(listener); + this.updateListeners.add(listener); } public void removeUpdateListener(UpdateListener listener) { - listeners.remove(listener); + this.updateListeners.remove(listener); } } Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractComponent.java 2010-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractComponent.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -14,7 +14,6 @@ package org.cishell.reference.gui.guibuilder.swt.builder; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import org.eclipse.swt.widgets.Composite; @@ -26,51 +25,53 @@ * @author Bruce Herr (bh...@bh...) */ public abstract class AbstractComponent implements GUIComponent { - protected AttributeDefinition attr; + protected AttributeDefinition attribute; protected boolean drawsLabel; - protected int numColumns; - protected Set listeners; + protected int columnCount; + protected Set<UpdateListener> listeners; public abstract void setValue(Object value); public abstract Object getValue(); public abstract String validate(); public abstract Control createGUI(Composite parent, int style); - public AbstractComponent(boolean drawsLabel, int numColumns) { + public AbstractComponent(boolean drawsLabel, int columnCount) { this.drawsLabel = drawsLabel; - this.numColumns = numColumns; - this.listeners = new HashSet(); + this.columnCount = columnCount; + this.listeners = new HashSet<UpdateListener>(); } public AttributeDefinition getAttributeDefinition() { - if (attr == null) { + if (this.attribute == null) { throw new IllegalStateException("AttributeDefinition has not been set"); } - return attr; + return this.attribute; } - public void setAttributeDefinition(AttributeDefinition attr) { - this.attr = attr; + public void setAttributeDefinition(AttributeDefinition attribute) { + this.attribute = attribute; } + public boolean drawsLabel() { - return drawsLabel; + return this.drawsLabel; } + public int getColumns() { - return numColumns; + return this.columnCount; } protected void update() { - for (Iterator i=listeners.iterator(); i.hasNext(); ) { - ((UpdateListener) i.next()).componentUpdated(this); + for (UpdateListener listener : this.listeners) { + listener.componentUpdated(this); } } public void addUpdateListener(UpdateListener listener) { - listeners.add(listener); + this.listeners.add(listener); } public void removeUpdateListener(UpdateListener listener) { - listeners.remove(listener); + this.listeners.remove(listener); } } Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/BooleanComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/BooleanComponent.java 2010-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/BooleanComponent.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -32,18 +32,18 @@ public Control createGUI(Composite parent, int style) { checkbox = new Button(parent, SWT.CHECK); - GridData gridData = new GridData(SWT.LEFT,SWT.CENTER,false,false); + GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false); gridData.horizontalSpan = MAX_SPAN; checkbox.setLayoutData(gridData); - String label = attr.getName(); + String label = attribute.getName(); if(label != null) checkbox.setText(label); else checkbox.setText(""); checkbox.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent event) { update(); }}); @@ -51,11 +51,11 @@ } public Object getValue() { - return checkbox.getSelection() ? Boolean.TRUE : Boolean.FALSE; + return Boolean.valueOf(this.checkbox.getSelection()); } public void setValue(Object value) { - if (value instanceof Boolean && value != null) { + if ((value instanceof Boolean) && (value != null)) { checkbox.setSelection(((Boolean) value).booleanValue()); } else { checkbox.setSelection(false); @@ -63,6 +63,6 @@ } public String validate() { - return attr.validate(""+checkbox.getSelection()); + return attribute.validate("" + checkbox.getSelection()); } } Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/LabelingComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/LabelingComponent.java 2010-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/LabelingComponent.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -50,20 +50,22 @@ setAttributeDefinition(childComponent.getAttributeDefinition()); if (!childComponent.drawsLabel()) { - numColumns++; + columnCount++; } - String description = attr.getDescription(); - if (description != null && description.length() > 0) { - numColumns++; + String description = attribute.getDescription(); + + if ((description != null) && (description.length() > 0)) { + columnCount++; } + childComponent.addUpdateListener(this); } public Control createGUI(Composite parent, int style) { if (drawsLabel && !childComponent.drawsLabel()) { - String labelText = attr.getName(); + String labelText = attribute.getName(); if (labelText == null) { labelText = ""; } @@ -81,7 +83,6 @@ } private void createAndAddDescriptionButton(Control control, Composite parent) { - /* * Create the description button, and add it to the parent. * */ @@ -116,13 +117,80 @@ descriptionButton.addSelectionListener(listener); } + + /** + * Sets the location for a hovering shell. + * + * @param descriptionShell + * the object that is to hover + * @param position + * the position of a widget to hover over + */ + private void setHoverLocation(Shell descriptionShell, Point position) { + Rectangle displayBounds = descriptionShell.getDisplay().getBounds(); + Rectangle shellBounds = descriptionShell.getBounds(); + shellBounds.x = Math.max(Math.min(position.x + + DESCRIPTION_SHELL_LEFT_MARGIN, displayBounds.width + - shellBounds.width), 0); + + shellBounds.y = Math.max(Math.min(position.y, displayBounds.height + - shellBounds.height), 0); + descriptionShell.setBounds(shellBounds); + } + + protected void setDefaultValue() { + String[] defaults = attribute.getDefaultValue(); + + if ((defaults != null) && (defaults.length > 0)) { + Object value = StringConverter.getInstance().stringToObject(attribute, defaults[0]); + setValue(value); + } + } + + public Object getValue() { + return childComponent.getValue(); + } + + public void setValue(Object value) { + childComponent.setValue(value); + } + + public String validate() { + String valid = childComponent.validate(); + + // If valid is a string then the string is the error message. + if ((valid != null) && (valid.length() > 0)) { + label.setForeground(ERROR_COLOR); + } else { + label.setForeground(null); + } + + return valid; + } + + public void componentUpdated(GUIComponent component) { + if (!childComponent.drawsLabel()) { + validate(); + } + + update(); + } + + private String getDescriptionText() { + String descriptionText = attribute.getDescription(); + if (descriptionText == null || descriptionText.length() == 0) { + descriptionText = DEFAULT_DESCRIPTION_TEXT; + } + + return descriptionText; + } + /* * Adds selection listener to the button. Whenever a button is pressed it triggers * the button selected event, which causes the creation of a new Description hover. * Once a button is unselected it deletes the Description hover. * */ class DescriptionButtonListener implements SelectionListener { - private Shell descriptionShell = null; private String descText; @@ -180,7 +248,6 @@ } } - private Shell createDescriptionShell(final String descText, Button descriptionButton) { Shell descriptionShell = new Shell(descriptionButton.getShell(), SWT.NONE); @@ -232,71 +299,4 @@ } } } - - /** - * Sets the location for a hovering shell. - * - * @param descriptionShell - * the object that is to hover - * @param position - * the position of a widget to hover over - */ - private void setHoverLocation(Shell descriptionShell, Point position) { - Rectangle displayBounds = descriptionShell.getDisplay().getBounds(); - Rectangle shellBounds = descriptionShell.getBounds(); - shellBounds.x = Math.max(Math.min(position.x - + DESCRIPTION_SHELL_LEFT_MARGIN, displayBounds.width - - shellBounds.width), 0); - - shellBounds.y = Math.max(Math.min(position.y, displayBounds.height - - shellBounds.height), 0); - descriptionShell.setBounds(shellBounds); - } - - protected void setDefaultValue() { - String[] defaults = attr.getDefaultValue(); - - if (defaults != null && defaults.length > 0) { - - Object value = StringConverter.getInstance().stringToObject(attr, - defaults[0]); - setValue(value); - } - } - - public Object getValue() { - return childComponent.getValue(); - } - - public void setValue(Object value) { - childComponent.setValue(value); - } - - public String validate() { - return childComponent.validate(); - } - - public void componentUpdated(GUIComponent component) { - if (!childComponent.drawsLabel()) { - String valid = validate(); - - // if valid is a string then the string is the error message - if (valid != null && valid.length() > 0) { - label.setForeground(ERROR_COLOR); - } else { - label.setForeground(null); - } - } - update(); - } - - private String getDescriptionText() { - String descriptionText = attr.getDescription(); - if (descriptionText == null || descriptionText.length() == 0) { - descriptionText = DEFAULT_DESCRIPTION_TEXT; - } - - return descriptionText; - } - } Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/MultiValuedComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/MultiValuedComponent.java 2010-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/MultiValuedComponent.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -54,7 +54,7 @@ } protected synchronized void addComponent(int position) { - GUIComponent component = ComponentProvider.getInstance().createBasicComponent(attr); + GUIComponent component = ComponentProvider.getInstance().createBasicComponent(attribute); Control control = component.createGUI(panel, style); Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java 2010-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -50,15 +50,14 @@ } public Control createGUI(Composite parent, int style) { - GridData gd = new GridData(SWT.FILL,SWT.CENTER,true,true); gd.horizontalSpan = MAX_SPAN-1; gd.minimumWidth = 100; - optionValues = attr.getOptionValues(); + optionValues = attribute.getOptionValues(); if(optionValues != null) { combo = new Combo(parent, style | SWT.DROP_DOWN | SWT.READ_ONLY); - String[] optionLabels = attr.getOptionLabels(); + String[] optionLabels = attribute.getOptionLabels(); if(optionLabels == null) { combo.setItems(optionValues); } else { @@ -78,18 +77,20 @@ return combo; } else { int flags; - if(multiline) { + + if (multiline) { flags = style | SWT.BORDER | SWT.MULTI | SWT.V_SCROLL; gd.minimumHeight = 100; gd.minimumWidth = 250; } else { flags = style | SWT.BORDER; } + textField = new Text(parent, flags); textField.setLayoutData(gd); textField.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { + public void modifyText(ModifyEvent event) { update(); } }); @@ -101,9 +102,9 @@ public Object getValue() { Object value; if(combo == null) { - value = StringConverter.getInstance().stringToObject(attr, textField.getText()); + value = StringConverter.getInstance().stringToObject(attribute, textField.getText()); } else { - value = StringConverter.getInstance().stringToObject(attr, getListValue()); + value = StringConverter.getInstance().stringToObject(attribute, getListValue()); } return value; @@ -122,9 +123,9 @@ return "Invalid basic value"; } if(combo == null) { - return attr.validate(textField.getText()); + return attribute.validate(textField.getText()); } else { - return attr.validate(getListValue()); + return attribute.validate(getListValue()); } } @@ -151,10 +152,10 @@ /* TODO: Log this (or do something with it besides printint it to a place most * users won't see it)? */ - String warningMessage = + /*String warningMessage = "Attempted to set combo box to a value that didn't exist inside the " + "combo box."; - System.err.println(warningMessage); + System.err.println(warningMessage);*/ } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-11-12 16:47:20
|
Revision: 1151 http://cishell.svn.sourceforge.net/cishell/?rev=1151&view=rev Author: pataphil Date: 2010-11-12 16:47:14 +0000 (Fri, 12 Nov 2010) Log Message: ----------- * Made SelectionListener Java 1.5. Modified Paths: -------------- trunk/core/org.cishell.framework/src/org/cishell/service/guibuilder/SelectionListener.java Modified: trunk/core/org.cishell.framework/src/org/cishell/service/guibuilder/SelectionListener.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/service/guibuilder/SelectionListener.java 2010-11-04 21:34:56 UTC (rev 1150) +++ trunk/core/org.cishell.framework/src/org/cishell/service/guibuilder/SelectionListener.java 2010-11-12 16:47:14 UTC (rev 1151) @@ -28,7 +28,7 @@ * * @param valuesEntered The data the user entered */ - public void hitOk(Dictionary valuesEntered); + public void hitOk(Dictionary<String, Object> valuesEntered); /** * Notification that the user cancelled the operation This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-11-04 21:35:02
|
Revision: 1150 http://cishell.svn.sourceforge.net/cishell/?rev=1150&view=rev Author: pataphil Date: 2010-11-04 21:34:56 +0000 (Thu, 04 Nov 2010) Log Message: ----------- * Added R icon for use in the Data Manager. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java trunk/core/org.cishell.framework/src/org/cishell/framework/data/DataProperty.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/r.png Added: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/r.png =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/r.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java 2010-11-02 17:48:25 UTC (rev 1149) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java 2010-11-04 21:34:56 UTC (rev 1150) @@ -44,6 +44,7 @@ private Image rasterImageIcon; private Image vectorImageIcon; private Image modelIcon; + private Image rIcon; private Map typeToImageMapping; @@ -75,6 +76,7 @@ rasterImageIcon = getImage("raster_image.jpg", this.brandPluginID); vectorImageIcon = getImage("vector_image.jpg", this.brandPluginID); modelIcon = getImage("model.jpg", this.brandPluginID); + rIcon = getImage("r.png", this.brandPluginID); typeToImageMapping = new HashMap(); registerImage(DataProperty.OTHER_TYPE, unknownIcon); @@ -96,6 +98,7 @@ registerImage(DataProperty.RASTER_IMAGE_TYPE, rasterImageIcon); registerImage(DataProperty.VECTOR_IMAGE_TYPE, vectorImageIcon); registerImage(DataProperty.MODEL_TYPE, modelIcon); + registerImage(DataProperty.R_INSTANCE_TYPE, rIcon); } /** Modified: trunk/core/org.cishell.framework/src/org/cishell/framework/data/DataProperty.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/data/DataProperty.java 2010-11-02 17:48:25 UTC (rev 1149) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/data/DataProperty.java 2010-11-04 21:34:56 UTC (rev 1150) @@ -93,4 +93,7 @@ /** Says this data model is a 'model' object */ public static String MODEL_TYPE = "Model"; + + /** Says this data model is an 'R instance' object */ + public static String R_INSTANCE_TYPE = "R Instance"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-11-02 17:48:31
|
Revision: 1149 http://cishell.svn.sourceforge.net/cishell/?rev=1149&view=rev Author: pataphil Date: 2010-11-02 17:48:25 +0000 (Tue, 02 Nov 2010) Log Message: ----------- * Fixed default File/Directory GUI widget prefixes. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/FileComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/FileComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/FileComponent.java 2010-10-29 02:47:34 UTC (rev 1148) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/FileComponent.java 2010-11-02 17:48:25 UTC (rev 1149) @@ -16,8 +16,6 @@ import java.io.File; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java 2010-10-29 02:47:34 UTC (rev 1148) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java 2010-11-02 17:48:25 UTC (rev 1149) @@ -129,16 +129,18 @@ } public void setValue(Object value) { - if(value.toString().startsWith("textarea:")) { - value = value.toString().substring("textarea:".length()); - } + String valueString = emptyStringIfNull(value); + valueString = fixTextFieldPrefix("textarea:", valueString); + valueString = fixTextFieldPrefix("file:", valueString); + valueString = fixTextFieldPrefix("directory:", valueString); + if (textField != null) { - textField.setText(value == null ? "" : value.toString()); + textField.setText(valueString); } else if (combo != null) { + int setComboToIndex = -1; - int setComboToIndex = -1; for (int i = 0; i < optionValues.length; i++) { - if (value.equals(optionValues[i])) { + if (valueString.equals(optionValues[i])) { setComboToIndex = i; } } @@ -146,9 +148,31 @@ if (setComboToIndex != -1) { combo.select(setComboToIndex); } else { - System.err.println("Attempted to set combo box to a value " + - "that didn't exist inside the combo box."); + /* TODO: Log this (or do something with it besides printint it to a place most + * users won't see it)? + */ + String warningMessage = + "Attempted to set combo box to a value that didn't exist inside the " + + "combo box."; + System.err.println(warningMessage); } } } + + // TODO: Use the CIShell Utilities version, but only when that's been all refactor and stuff. + private String emptyStringIfNull(Object value) { + if (value == null) { + return ""; + } else { + return value.toString(); + } + } + + private String fixTextFieldPrefix(String prefix, String value) { + if (value.startsWith(prefix)) { + return value.substring(prefix.length()); + } else { + return value; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kon...@us...> - 2010-10-29 02:47:40
|
Revision: 1148 http://cishell.svn.sourceforge.net/cishell/?rev=1148&view=rev Author: kongchinhua Date: 2010-10-29 02:47:34 +0000 (Fri, 29 Oct 2010) Log Message: ----------- - Reuse color if all color been used Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorRegistry.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorRegistry.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorRegistry.java 2010-10-29 02:38:19 UTC (rev 1147) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorRegistry.java 2010-10-29 02:47:34 UTC (rev 1148) @@ -70,13 +70,15 @@ } /* - * Return next color index + * Return next color index. This will reuse the color if it out of color */ private int getNextIndex() { int index = currentIndex; - if (currentIndex < colorSchema.size()) { + if (currentIndex < colorSchema.size() - 1) { currentIndex++; + } else { + currentIndex = 0; } return index; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kon...@us...> - 2010-10-29 02:38:25
|
Revision: 1147 http://cishell.svn.sourceforge.net/cishell/?rev=1147&view=rev Author: kongchinhua Date: 2010-10-29 02:38:19 +0000 (Fri, 29 Oct 2010) Log Message: ----------- Fixed index overflow issue Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorSchema.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorSchema.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorSchema.java 2010-10-28 22:16:06 UTC (rev 1146) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorSchema.java 2010-10-29 02:38:19 UTC (rev 1147) @@ -40,7 +40,7 @@ * index */ public Color get(int index) { - if (index > this.totalColors) { + if (index >= this.totalColors) { return getDefaultColor(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-10-28 22:16:14
|
Revision: 1146 http://cishell.svn.sourceforge.net/cishell/?rev=1146&view=rev Author: pataphil Date: 2010-10-28 22:16:06 +0000 (Thu, 28 Oct 2010) Log Message: ----------- * Implemented ToCaseFunction. * Reviewed by Joseph. Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ToCaseFunction.java Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ToCaseFunction.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ToCaseFunction.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ToCaseFunction.java 2010-10-28 22:16:06 UTC (rev 1146) @@ -0,0 +1,16 @@ +package org.cishell.utilities; + +import com.google.common.base.Function; + +public enum ToCaseFunction implements Function<String, String> { + LOWER { + public String apply(String from) { + return from.toLowerCase(); + } + }, + UPPER { + public String apply(String from) { + return from.toUpperCase(); + } + }; +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-10-28 22:15:17
|
Revision: 1145 http://cishell.svn.sourceforge.net/cishell/?rev=1145&view=rev Author: pataphil Date: 2010-10-28 22:15:11 +0000 (Thu, 28 Oct 2010) Log Message: ----------- * Implemented FileUtilities.writeEntireStreamToTemporaryFileInDirectory * Fixed a small bug in ensureDirectoryExists * Reviewed by Joseph. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2010-10-22 18:08:52 UTC (rev 1144) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2010-10-28 22:15:11 UTC (rev 1145) @@ -33,12 +33,13 @@ * temporaryDirectoryPath, creating the directory if it doesn't * already exist. */ - private static File createTemporaryDirectory( - String temporaryDirectoryPath) { - return ensureDirectoryExists( - temporaryDirectoryPath + File.separator + "temp"); + public static File createTemporaryDirectory(String temporaryDirectoryPath) { + String fullDirectoryPath = + String.format("%s%stemp", temporaryDirectoryPath, File.separator); + + return ensureDirectoryExists(fullDirectoryPath); } - + // Attempt to create a temporary file on disk whose name is passed in. public static File createTemporaryFile(File temporaryDirectory, String temporaryDirectoryPath, @@ -282,6 +283,27 @@ return temporaryFile; } + + public static File writeEntireStreamToTemporaryFileInDirectory( + InputStream input, File directory, String fileName, String fileExtension) + throws IOException { + File temporaryFile = + createTemporaryFile(directory, directory.getAbsolutePath(), fileName, fileExtension); + OutputStream output = new FileOutputStream(temporaryFile); + // TODO: Use READ_TEXT_FILE_BUFFER_SIZE. + byte[] readCharacters = new byte[1]; + int readCharacterCount = input.read(readCharacters); + + while (readCharacterCount > 0) { + output.write(readCharacters, 0, readCharacterCount); + readCharacterCount = input.read(readCharacters); + } + + output.close(); + input.close(); + + return temporaryFile; + } public static String getFileExtension(File file) { return getFileExtension(file.getAbsolutePath()); @@ -301,14 +323,14 @@ File directory = new File(directoryPath); if (!directory.exists()) { - directory.mkdir(); + directory.mkdirs(); directory.deleteOnExit(); } return directory; } -public static final char FILENAME_CHARACTER_REPLACEMENT = '#'; + public static final char FILENAME_CHARACTER_REPLACEMENT = '#'; /* Attempt to enumerate characters which cannot be used to name a file. * For our purposes, this should be as aggressive as sensible. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2010-10-22 18:09:01
|
Revision: 1144 http://cishell.svn.sourceforge.net/cishell/?rev=1144&view=rev Author: jrbibers Date: 2010-10-22 18:08:52 +0000 (Fri, 22 Oct 2010) Log Message: ----------- Adding utilities for the Google Guava extension of Comparator, Ordering. We add decorators for Ordering.explicit() to handle ordering of unspecified values. Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/OrderingUtilities.java Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/OrderingUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/OrderingUtilities.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/OrderingUtilities.java 2010-10-22 18:08:52 UTC (rev 1144) @@ -0,0 +1,73 @@ +package org.cishell.utilities; + +import java.util.Collection; +import java.util.List; + +import com.google.common.base.Function; +import com.google.common.collect.Lists; +import com.google.common.collect.Ordering; + +public class OrderingUtilities { + /** + * Normally Ordering.explicit() gives an Ordering that throws a ClassCastException for + * unspecified values. This method gives an explicit ordering that puts unspecified values + * before all others. + * <br/><br/> + * Until {@link http://code.google.com/p/guava-libraries/issues/detail?id=332} is addressed. + */ + public static <T> Ordering<T> explicitWithUnknownsFirst(List<T> valuesInOrder) { + Function<T, T> unknownToNullFunction = new IdentityIndicatorFunction<T>(valuesInOrder); + + return Ordering.explicit(valuesInOrder).nullsFirst().onResultOf(unknownToNullFunction); + } + + /** + * {@link org.cishell.utilities.OrderingUtilities.explicitWithUnknownsFirst(List<T>)} + */ + public static <T> Ordering<T> explicitWithUnknownsFirst( + T leastValue, T... remainingValuesInOrder) { + return explicitWithUnknownsFirst(Lists.asList(leastValue, remainingValuesInOrder)); + } + + + /** + * Normally Ordering.explicit() gives an Ordering that throws a ClassCastException for + * unspecified values. This method gives an explicit ordering that puts unspecified values + * after all others. + * <br/><br/> + * Until {@link http://code.google.com/p/guava-libraries/issues/detail?id=332} is addressed. + */ + public static <T> Ordering<T> explicitWithUnknownsLast(List<T> valuesInOrder) { + Function<T, T> unknownToNullFunction = new IdentityIndicatorFunction<T>(valuesInOrder); + + return Ordering.explicit(valuesInOrder).nullsLast().onResultOf(unknownToNullFunction); + } + + /** + * {@link org.cishell.utilities.OrderingUtilities.explicitWithUnknownsLast(List<T>)} + */ + public static <T> Ordering<T> explicitWithUnknownsLast( + T leastValue, T... remainingValuesInOrder) { + return explicitWithUnknownsLast(Lists.asList(leastValue, remainingValuesInOrder)); + } + + /** + * For values in the given collection, this is the identity function. + * For other values we return null. + */ + public static class IdentityIndicatorFunction<T> implements Function<T, T> { + private Collection<? extends T> values; + + public IdentityIndicatorFunction(Collection<? extends T> values) { + this.values = values; + } + + public T apply(T candidateValue) { + if (values.contains(candidateValue)) { + return candidateValue; + } else { + return null; + } + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-10-19 22:08:31
|
Revision: 1143 http://cishell.svn.sourceforge.net/cishell/?rev=1143&view=rev Author: pataphil Date: 2010-10-19 22:08:25 +0000 (Tue, 19 Oct 2010) Log Message: ----------- * mutateParameters can now throw AllParametersMutatedOutException if the AlgorithmFactory wishes to not present the user with any input options. * Reviewed by Micah. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java Added Paths: ----------- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AllParametersMutatedOutException.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2010-10-04 21:57:32 UTC (rev 1142) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2010-10-19 22:08:25 UTC (rev 1143) @@ -31,6 +31,7 @@ import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; +import org.cishell.framework.algorithm.AllParametersMutatedOutException; import org.cishell.framework.algorithm.DataValidator; import org.cishell.framework.algorithm.ParameterMutator; import org.cishell.framework.algorithm.ProgressMonitor; @@ -373,16 +374,22 @@ if ((factory instanceof ParameterMutator) && (provider != null)) { try { - ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatypePID, null); + ObjectClassDefinition objectClassDefinition = + provider.getObjectClassDefinition(metatypePID, null); - if (ocd == null) { + if (objectClassDefinition == null) { logNullOCDWarning(pid, metatypePID); } - ocd = ((ParameterMutator) factory).mutateParameters(data, ocd); + try { + objectClassDefinition = + ((ParameterMutator) factory).mutateParameters(data, objectClassDefinition); - if (ocd != null) { - provider = new BasicMetaTypeProvider(ocd); + if (objectClassDefinition != null) { + provider = new BasicMetaTypeProvider(objectClassDefinition); + } + } catch (AllParametersMutatedOutException e) { + provider = null; } } catch (IllegalArgumentException e) { log(LogService.LOG_DEBUG, pid + " has an invalid metatype id: " + metatypePID, e); Added: trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AllParametersMutatedOutException.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AllParametersMutatedOutException.java (rev 0) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AllParametersMutatedOutException.java 2010-10-19 22:08:25 UTC (rev 1143) @@ -0,0 +1,21 @@ +package org.cishell.framework.algorithm; + +public class AllParametersMutatedOutException extends RuntimeException { + private static final long serialVersionUID = 9017277008277139930L; + + public AllParametersMutatedOutException(String message, Throwable exception) { + super(message, exception); + } + + public AllParametersMutatedOutException(Throwable exception) { + super(exception); + } + + public AllParametersMutatedOutException(String message) { + super(message); + } + + public AllParametersMutatedOutException() { + this("Algorithm canceled by user."); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-10-04 21:57:39
|
Revision: 1142 http://cishell.svn.sourceforge.net/cishell/?rev=1142&view=rev Author: pataphil Date: 2010-10-04 21:57:32 +0000 (Mon, 04 Oct 2010) Log Message: ----------- * Fixed NullPointerException bug. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2010-10-01 17:30:59 UTC (rev 1141) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2010-10-04 21:57:32 UTC (rev 1142) @@ -126,7 +126,7 @@ this.logger.log(LogService.LOG_ERROR, logMessage); } - return null; + return new Data[0]; } private Data[] labelFileData(File file, Data[] validatedFileData) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-10-01 17:31:06
|
Revision: 1141 http://cishell.svn.sourceforge.net/cishell/?rev=1141&view=rev Author: pataphil Date: 2010-10-01 17:30:59 +0000 (Fri, 01 Oct 2010) Log Message: ----------- * Enhanced ProgressMonitor to accept doubles. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerTableItem.java trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerView.java trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/ProgressMonitor.java Modified: trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerTableItem.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerTableItem.java 2010-09-30 14:55:41 UTC (rev 1140) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerTableItem.java 2010-10-01 17:30:59 UTC (rev 1141) @@ -18,22 +18,22 @@ * if it is monitorable. */ public class SchedulerTableItem { - private Algorithm algorithm; - private Calendar cal; - private String algorithmLabel; + public static final Image CHECKED_IMAGE = Activator.createImage("check.gif"); + public static final Image UNCHECKED_IMAGE = Activator.createImage("uncheck.gif"); + public static final Image ERROR_IMAGE = Activator.createImage("error.gif"); + + private String algorithmLabel; + private Calendar calendar; - private TableItem tableItem; + private TableItem tableItem; private TableEditor tableEditor; - private int progressSelection; + private int progressSelection; private ProgressBar progressBar; - - private static Image checkedImage = Activator.createImage("check.gif"); - private static Image uncheckedImage = Activator.createImage("uncheck.gif"); - private static Image errorImage = Activator.createImage("error.gif"); private boolean encounteredError; - private String workBeingDone; + @SuppressWarnings("unused") + private String workBeingDone; private boolean cancelRequested; private boolean pauseRequested; private boolean started; @@ -49,29 +49,24 @@ * Initializes flags and records the current algorithm to monitor * * @param algorithmLabel + * @param calendar * @param algorithm - * @param cal */ - public SchedulerTableItem(String algorithmLabel, Algorithm algorithm, Calendar cal) { - this.algorithm = algorithm; - this.cal = cal; - + public SchedulerTableItem(String algorithmLabel, Calendar calendar, Algorithm algorithm) { + this.algorithmLabel = algorithmLabel; + this.calendar = calendar; + this.encounteredError = false; - this.cancelRequested = false; - this.started = false; - this.done = false; - - this.isCancellable = false; - this.isPauseable = false; + this.started = false; + this.done = false; + this.isCancellable = false; + this.isPauseable = false; this.isWorkTrackable = false; - - this.algorithmLabel = algorithmLabel; - if (algorithm instanceof ProgressTrackable) { - algorithmProgressMonitor = new AlgorithmProgressMonitor(); - ((ProgressTrackable)algorithm).setProgressMonitor(algorithmProgressMonitor); + this.algorithmProgressMonitor = new AlgorithmProgressMonitor(); + ((ProgressTrackable)algorithm).setProgressMonitor(this.algorithmProgressMonitor); } } @@ -80,7 +75,7 @@ * @param request Cancel request */ public void requestCancel(boolean request) { - cancelRequested = request; + this.cancelRequested = request; } /** @@ -88,7 +83,7 @@ * @param request Pause request */ public void requestPause(boolean request) { - pauseRequested = request; + this.pauseRequested = request; } /** @@ -110,16 +105,17 @@ * @param table The parent table */ public void finishTableEntry(final Table table) { - done = true; + this.done = true; - if (!tableItem.isDisposed()) { + if (!this.tableItem.isDisposed()) { guiRun(new Runnable() { public void run() { - progressBar.dispose(); - progressBar = new ProgressBar(table, SWT.NONE); + SchedulerTableItem.this.progressBar.dispose(); + SchedulerTableItem.this.progressBar = new ProgressBar(table, SWT.NONE); - progressSelection = progressBar.getMaximum(); - drawTableEntry(table, table.indexOf(tableItem)); + SchedulerTableItem.this.progressSelection = + SchedulerTableItem.this.progressBar.getMaximum(); + drawTableEntry(table, table.indexOf(SchedulerTableItem.this.tableItem)); } }); } @@ -133,56 +129,65 @@ public void moveTableEntry(final Table table, final int tblNdx) { guiRun(new Runnable() { public void run() { - progressSelection = progressBar.getSelection(); + SchedulerTableItem.this.progressSelection = + SchedulerTableItem.this.progressBar.getSelection(); drawTableEntry(table, tblNdx); } }); } /** - * Draws a table entry with the current state provided - * the parent table and index of the new entry - * - * @param table Parent table - * @param tblNdx Index into the table + * Draws a table entry with the current state provided the parent table and index of the + * new entry. */ - private void drawTableEntry(final Table table, final int tblNdx) { + private void drawTableEntry(final Table table, final int tableIndex) { guiRun(new Runnable() { public void run() { - if (tableItem != null) { - tableItem.dispose(); + if (SchedulerTableItem.this.tableItem != null) { + SchedulerTableItem.this.tableItem.dispose(); } - tableItem = new TableItem(table, SWT.NONE, tblNdx); + + SchedulerTableItem.this.tableItem = new TableItem(table, SWT.NONE, tableIndex); - if (done) { - tableItem.setImage(SchedulerView.COMPLETED_COLUMN, checkedImage); + if (SchedulerTableItem.this.done) { + SchedulerTableItem.this.tableItem.setImage( + SchedulerView.COMPLETED_COLUMN, CHECKED_IMAGE); } - else if (encounteredError) { - tableItem.setImage(SchedulerView.COMPLETED_COLUMN, errorImage); + else if (SchedulerTableItem.this.encounteredError) { + SchedulerTableItem.this.tableItem.setImage( + SchedulerView.COMPLETED_COLUMN, ERROR_IMAGE); } else { - tableItem.setImage(SchedulerView.COMPLETED_COLUMN, uncheckedImage); + SchedulerTableItem.this.tableItem.setImage( + SchedulerView.COMPLETED_COLUMN, UNCHECKED_IMAGE); } - tableItem.setText(SchedulerView.ALGORITHM_COLUMN, algorithmLabel); + SchedulerTableItem.this.tableItem.setText( + SchedulerView.ALGORITHM_COLUMN, SchedulerTableItem.this.algorithmLabel); setCalendar(); - if (started) { - if (progressBar != null) - progressBar.dispose(); - if (isWorkTrackable || done) { - progressBar = new ProgressBar(table, SWT.NONE); - progressBar.setSelection(progressSelection); + if (SchedulerTableItem.this.started) { + if (SchedulerTableItem.this.progressBar != null) + SchedulerTableItem.this.progressBar.dispose(); + if (SchedulerTableItem.this.isWorkTrackable || SchedulerTableItem.this.done) { + SchedulerTableItem.this.progressBar = new ProgressBar(table, SWT.NONE); + SchedulerTableItem.this.progressBar.setSelection( + SchedulerTableItem.this.progressSelection); } else { - progressBar = new ProgressBar(table, SWT.INDETERMINATE); + SchedulerTableItem.this.progressBar = + new ProgressBar(table, SWT.INDETERMINATE); } } else { - progressBar = new ProgressBar(table, SWT.NONE); + SchedulerTableItem.this.progressBar = new ProgressBar(table, SWT.NONE); } - tableEditor = new TableEditor(table); - tableEditor.grabHorizontal = tableEditor.grabVertical = true; - tableEditor.setEditor(progressBar, tableItem, - SchedulerView.PERCENT_COLUMN); + + SchedulerTableItem.this.tableEditor = new TableEditor(table); + SchedulerTableItem.this.tableEditor.grabHorizontal = true; + SchedulerTableItem.this.tableEditor.grabVertical = true; + SchedulerTableItem.this.tableEditor.setEditor( + SchedulerTableItem.this.progressBar, + SchedulerTableItem.this.tableItem, + SchedulerView.PERCENT_COLUMN); } }); } @@ -193,10 +198,10 @@ private void setCalendar() { guiRun(new Runnable() { public void run() { - final String date = getDateString(cal); - final String time = getTimeString(cal); - tableItem.setText(SchedulerView.DATE_COLUMN, date); - tableItem.setText(SchedulerView.TIME_COLUMN, time); + String date = getDateString(SchedulerTableItem.this.calendar); + String time = getTimeString(SchedulerTableItem.this.calendar); + SchedulerTableItem.this.tableItem.setText(SchedulerView.DATE_COLUMN, date); + SchedulerTableItem.this.tableItem.setText(SchedulerView.TIME_COLUMN, time); } }); } @@ -207,17 +212,17 @@ * @param table The parent table */ public void algorithmStarted(Table table) { - done = false; - started = true; - drawTableEntry(table, table.indexOf(tableItem)); + this.done = false; + this.started = true; + drawTableEntry(table, table.indexOf(this.tableItem)); } /** * Notification of rescheduling of the algorithm - * @param cal The rescheduled time + * @param calendar The rescheduled time */ - public void reschedule(Calendar cal) { - this.cal = cal; + public void reschedule(Calendar calendar) { + this.calendar = calendar; setCalendar(); } @@ -226,8 +231,8 @@ * @param table Parent table */ public void errorTableEntry(Table table) { - encounteredError = true; - drawTableEntry(table, table.indexOf(tableItem)); + this.encounteredError = true; + drawTableEntry(table, table.indexOf(this.tableItem)); } /** @@ -237,11 +242,14 @@ public void refresh() { guiRun(new Runnable() { public void run() { - if (!progressBar.isDisposed()) { - progressBar.setSelection(progressSelection); - tableEditor.grabHorizontal = tableEditor.grabVertical = true; - tableEditor.setEditor(progressBar, tableItem, - SchedulerView.PERCENT_COLUMN); + if (!SchedulerTableItem.this.progressBar.isDisposed()) { + SchedulerTableItem.this.progressBar.setSelection(SchedulerTableItem.this.progressSelection); + SchedulerTableItem.this.tableEditor.grabHorizontal = true; + SchedulerTableItem.this.tableEditor.grabVertical = true; + SchedulerTableItem.this.tableEditor.setEditor( + SchedulerTableItem.this.progressBar, + SchedulerTableItem.this.tableItem, + SchedulerView.PERCENT_COLUMN); } } }); @@ -254,8 +262,8 @@ public void remove() { guiRun(new Runnable() { public void run() { - progressBar.dispose(); - tableItem.dispose(); + SchedulerTableItem.this.progressBar.dispose(); + SchedulerTableItem.this.tableItem.dispose(); } }); } @@ -336,8 +344,11 @@ * @return cancellable state */ public boolean isCancellable() { - if (done) return false; - return isCancellable; + if (this.done) { + return false; + } + + return this.isCancellable; } /** @@ -346,8 +357,11 @@ * @return Pausable state */ public boolean isPausable() { - if (done) return false; - return isPauseable; + if (this.done) { + return false; + } + + return this.isPauseable; } /** @@ -363,7 +377,7 @@ * @return Paused state */ public boolean isPaused() { - if (algorithmProgressMonitor.isPaused() && !done) { + if (this.algorithmProgressMonitor.isPaused() && !this.done) { return true; } else { @@ -377,7 +391,7 @@ * @return Running state */ public boolean isRunning() { - if (cancelRequested) { + if (this.cancelRequested) { return false; } return true; @@ -388,77 +402,90 @@ * @return Done state */ public boolean isDone() { - return done; + return this.done; } - /** * Monitors an algorithm - * */ private class AlgorithmProgressMonitor implements ProgressMonitor { - private int totalWorkUnits; + private double totalWorkUnits; public void describeWork(String currentWork) { - workBeingDone = currentWork; + SchedulerTableItem.this.workBeingDone = currentWork; } public void done() { - done = true; + SchedulerTableItem.this.done = true; } public boolean isCanceled() { - return cancelRequested; + return SchedulerTableItem.this.cancelRequested; } public boolean isPaused() { - return pauseRequested; + return SchedulerTableItem.this.pauseRequested; } public void setCanceled(boolean value) { - cancelRequested = value; + SchedulerTableItem.this.cancelRequested = value; } public void setPaused(boolean value) { - pauseRequested = value; + SchedulerTableItem.this.pauseRequested = value; } public void start(int capabilities, int totalWorkUnits) { - + start(capabilities, (double) this.totalWorkUnits); + } + + public void start(int capabilities, double totalWorkUnits) { if ((capabilities & ProgressMonitor.CANCELLABLE) > 0){ - isCancellable = true; + SchedulerTableItem.this.isCancellable = true; } - if ((capabilities & ProgressMonitor.PAUSEABLE) > 0){ - isPauseable = true; + + if ((capabilities & ProgressMonitor.PAUSEABLE) > 0) { + SchedulerTableItem.this.isPauseable = true; } - if ((capabilities & ProgressMonitor.WORK_TRACKABLE) > 0){ + + if ((capabilities & ProgressMonitor.WORK_TRACKABLE) > 0) { refresh(); - isWorkTrackable = true; + SchedulerTableItem.this.isWorkTrackable = true; guiRun(new Runnable() { public void run() { - Table table = (Table)progressBar.getParent(); - progressBar.dispose(); - progressBar = new ProgressBar(table, SWT.NONE); - progressBar.setSelection(progressBar.getMinimum()); - tableEditor = new TableEditor(table); - tableEditor.grabHorizontal = tableEditor.grabVertical = true; - tableEditor.setEditor(progressBar, tableItem, SchedulerView.PERCENT_COLUMN); + Table table = (Table) progressBar.getParent(); + SchedulerTableItem.this.progressBar.dispose(); + SchedulerTableItem.this.progressBar = new ProgressBar(table, SWT.NONE); + SchedulerTableItem.this.progressBar.setSelection(progressBar.getMinimum()); + SchedulerTableItem.this.tableEditor = new TableEditor(table); + SchedulerTableItem.this.tableEditor.grabHorizontal = true; + SchedulerTableItem.this.tableEditor.grabVertical = true; + SchedulerTableItem.this.tableEditor.setEditor( + SchedulerTableItem.this.progressBar, + SchedulerTableItem.this.tableItem, + SchedulerView.PERCENT_COLUMN); } }); } + this.totalWorkUnits = totalWorkUnits; } public void worked(final int work) { - // final int totalWorkUnits = this.totalWorkUnits; + worked((double) work); + } + + public void worked(final double work) { guiRun(new Runnable() { public void run() { - if (!progressBar.isDisposed()) { - progressSelection = (int) (progressBar.getMaximum() * ((double) work / (double) totalWorkUnits)); - // progressBar.setSelection(progress); + if (!SchedulerTableItem.this.progressBar.isDisposed()) { + SchedulerTableItem.this.progressSelection = (int) ( + SchedulerTableItem.this.progressBar.getMaximum() * + (work / AlgorithmProgressMonitor.this.totalWorkUnits)); } } }); + refresh(); } } Modified: trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerView.java 2010-09-30 14:55:41 UTC (rev 1140) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerView.java 2010-10-01 17:30:59 UTC (rev 1141) @@ -338,8 +338,8 @@ .getProperty(AlgorithmProperty.LABEL); } - SchedulerTableItem schedulerTableItem = new SchedulerTableItem( - algorithmLabel, algorithm, cal); + SchedulerTableItem schedulerTableItem = + new SchedulerTableItem(algorithmLabel, cal, algorithm); schedulerTableItem.initTableEntry(table, 0); algorithmToGuiItemMap.put(algorithm, schedulerTableItem); Modified: trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/ProgressMonitor.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/ProgressMonitor.java 2010-09-30 14:55:41 UTC (rev 1140) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/ProgressMonitor.java 2010-10-01 17:30:59 UTC (rev 1141) @@ -19,8 +19,6 @@ * description of current work during execution. Except for the setter methods, * the methods are generally only called by the algorithm with the CIShell * application providing the progress monitor implementation. - * - * @author Bruce Herr (bh...@bh...) */ public interface ProgressMonitor { /** @@ -37,7 +35,10 @@ public void setCanceled(boolean value) {} public void setPaused(boolean value) {} public void start(int capabilities, int totalWorkUnits) {} - public void worked(int work) {}}; + public void start(int capabilities, double totalWorkUnits) {} + public void worked(int work) {} + public void worked(double work) {} + }; /** * Capability constant specifying that this algorithm can @@ -69,6 +70,7 @@ * algorithm does not provide progress information */ public void start(int capabilities, int totalWorkUnits); + public void start(int capabilities, double totalWorkUnits); /** * Notifies that a certain number of units of work has been completed @@ -77,6 +79,7 @@ * */ public void worked(int work); + public void worked(double work); /** * The algorithm is finished executing This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-09-30 14:55:50
|
Revision: 1140 http://cishell.svn.sourceforge.net/cishell/?rev=1140&view=rev Author: pataphil Date: 2010-09-30 14:55:41 +0000 (Thu, 30 Sep 2010) Log Message: ----------- * Reimplemented labeling file data items with prettier labels upon loading files. * Reviewed by Joseph. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/PrettyLabeler.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2010-09-30 14:54:33 UTC (rev 1139) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2010-09-30 14:55:41 UTC (rev 1140) @@ -15,6 +15,7 @@ org.cishell.service.database, org.cishell.service.guibuilder;version="1.0.0", org.cishell.utilities, + org.cishell.utilities.dictionary, org.osgi.framework;version="1.3.0", org.osgi.service.cm;version="1.2.0", org.osgi.service.component;version="1.0.0", Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2010-09-30 14:54:33 UTC (rev 1139) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2010-09-30 14:55:41 UTC (rev 1140) @@ -48,7 +48,10 @@ File file = getFileToLoadFromUser(window, display); if (file != null) { - return validateFile(window, display, file); + Data[] validatedFileData = validateFile(window, display, file); + Data[] labeledFileData = labelFileData(file, validatedFileData); + + return labeledFileData; } else { return null; } @@ -101,13 +104,14 @@ } else { try { return FileValidator.validateFile( - file, validator, this.progressMonitor, this.ciShellContext, this.logger); + file, validator, this.progressMonitor, this.ciShellContext, this.logger); } catch (AlgorithmExecutionException e) { - if (e.getCause() != null - && e.getCause() instanceof UnsupportedEncodingException) { - String logMessage = - "This file cannot be loaded; it uses the unsupported character encoding " - + e.getCause().getMessage() + "."; + if ((e.getCause() != null) + && (e.getCause() instanceof UnsupportedEncodingException)) { + String format = + "This file cannot be loaded; it uses the unsupported character " + + "encoding %s."; + String logMessage = String.format(format, e.getCause().getMessage()); this.logger.log(LogService.LOG_ERROR, logMessage); } else { throw e; @@ -119,13 +123,18 @@ "The chosen file is not compatible with this format. " + "Check that your file is correctly formatted or try another validator. " + "The reason is: " + e.getMessage(); - e.printStackTrace(); // TODO remove this.logger.log(LogService.LOG_ERROR, logMessage); } return null; } + private Data[] labelFileData(File file, Data[] validatedFileData) { + Data[] labeledFileData = PrettyLabeler.relabelWithFileName(validatedFileData, file); + + return labeledFileData; + } + private AlgorithmFactory getValidatorFromUser( IWorkbenchWindow window, Display display, File file) { ValidatorSelectorRunnable validatorSelector = Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/PrettyLabeler.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/PrettyLabeler.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/PrettyLabeler.java 2010-09-30 14:55:41 UTC (rev 1140) @@ -0,0 +1,44 @@ +package org.cishell.reference.gui.persistence.load; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Dictionary; + +import org.cishell.framework.data.BasicData; +import org.cishell.framework.data.Data; +import org.cishell.framework.data.DataProperty; +import org.cishell.utilities.dictionary.DictionaryUtilities; + +public class PrettyLabeler { + public static Data[] relabelWithFileName(Data[] data, File file) { + File absoluteFile = file.getAbsoluteFile(); + File parent = absoluteFile.getParentFile(); + + // TODO parent == null + + String prefix; + String parentName = parent.getName(); + if (parentName.trim().length() == 0) { + prefix = File.separator; + } else { + prefix = "..." + File.separator + parentName + File.separator; + } + + Collection<Data> newData = new ArrayList<Data>(data.length); + + /* TODO: This isn't actually correct. + * It will assign the same label to all of the data items if we ever do this. + */ + for (Data datum : data) { + Dictionary<String, Object> labeledDatumMetadata = + DictionaryUtilities.copy(datum.getMetadata()); + Data labeledDatum = + new BasicData(labeledDatumMetadata, datum.getData(), datum.getFormat()); + labeledDatumMetadata.put(DataProperty.LABEL, prefix + absoluteFile.getName()); + newData.add(labeledDatum); + } + + return newData.toArray(new Data[0]); + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-09-30 14:54:43
|
Revision: 1139 http://cishell.svn.sourceforge.net/cishell/?rev=1139&view=rev Author: pataphil Date: 2010-09-30 14:54:33 +0000 (Thu, 30 Sep 2010) Log Message: ----------- * Added DictionaryUtilities.putAll(), and refactored copy() to use it. * Reviewed by Joseph. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryUtilities.java 2010-09-28 22:21:12 UTC (rev 1138) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryUtilities.java 2010-09-30 14:54:33 UTC (rev 1139) @@ -1,6 +1,7 @@ package org.cishell.utilities.dictionary; import java.util.Dictionary; +import java.util.Enumeration; import java.util.Hashtable; public class DictionaryUtilities { @@ -28,14 +29,20 @@ return newDictionary; } - public static <K, V> Dictionary<K, V> copy(Dictionary<K, V> originalDictionary) { - Dictionary<K, V> newDictionary = new Hashtable<K, V>(); + /** + * Uses Hashtable for the copy. + */ + public static<K, V> Dictionary<K, V> copy(Dictionary<K, V> originalDictionary) { + Hashtable<K, V> newDictionary = new Hashtable<K, V>(); + putAll(newDictionary, originalDictionary); - for (DictionaryEntry<K, V> originalEntry : - new DictionaryIterator<K, V>(originalDictionary)) { - newDictionary.put(originalEntry.getKey(), originalEntry.getValue()); - } - return newDictionary; } + + public static<K, V> void putAll(Dictionary<K, V> target, Dictionary<K, V> source) { + for (Enumeration<K> keys = source.keys(); keys.hasMoreElements(); ) { + K key = keys.nextElement(); + target.put(key, source.get(key)); + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-09-28 22:21:18
|
Revision: 1138 http://cishell.svn.sourceforge.net/cishell/?rev=1138&view=rev Author: pataphil Date: 2010-09-28 22:21:12 +0000 (Tue, 28 Sep 2010) Log Message: ----------- * The warning message displayed to users when a bundle on the menu isn't found now prints the actual tool's (i.e. Sci2, EpiC, Network Workbench) name instead of Network Workbench for all tools. * The above warning message also displays the appropriate bug tracker URL. * Reviewed by Micah. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2010-09-28 22:19:35 UTC (rev 1137) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2010-09-28 22:21:12 UTC (rev 1138) @@ -17,6 +17,7 @@ org.cishell.reference.service.metatype, org.cishell.service.conversion;version="1.0.0", org.cishell.service.guibuilder;version="1.0.0", + org.cishell.utilities, org.osgi.service.cm;version="1.2.0", org.osgi.service.log;version="1.3.0", org.osgi.service.metatype;version="1.1.0" Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java 2010-09-28 22:19:35 UTC (rev 1137) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java 2010-09-28 22:21:12 UTC (rev 1138) @@ -1,9 +1,14 @@ package org.cishell.reference.gui.menumanager; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + import org.cishell.framework.CIShellContext; import org.cishell.framework.LocalCIShellContext; import org.cishell.reference.gui.menumanager.menu.MenuAdapter; import org.cishell.reference.gui.workspace.CIShellApplication; +import org.cishell.utilities.StringUtilities; import org.eclipse.jface.action.IMenuManager; import org.eclipse.swt.SWT; import org.eclipse.swt.awt.SWT_AWT; @@ -14,35 +19,33 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; -/** - * The activator class controls the plug-in life cycle - */ public class Activator extends AbstractUIPlugin implements IStartup { - - // The plug-in ID public static final String PLUGIN_ID = "org.cishell.reference.gui.menumanager"; - // The shared instance + public static final String CONFIGURATION_DIRECTORY = "configuration"; + public static final String WELCOME_TEXT_FILE_NAME = "Welcome.properties"; + + public static final String DEFAULT_TOOL_NAME = "CIShell"; + public static final String TOOL_NAME_PROPERTY = "toolName"; + public static final String DEFAULT_TOOL_TICKET_URL = + "http://cns-jira.slis.indiana.edu/secure/CreateIssue.jspa?issuetype=1"; + public static final String TOOL_TICKET_URL_PROPERTY = "toolTicketURL"; + + // The shared instance. private static Activator plugin; - - private static BundleContext context; - - MenuAdapter menuAdapter; - - /** - * The constructor - */ + private static BundleContext bundleContext; + + @SuppressWarnings("unused") + private MenuAdapter menuAdapter; + public Activator() { - plugin = this; + Activator.plugin = this; } - /** - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext context) throws Exception { - super.start(context); + public void start(BundleContext bundleContext) throws Exception { + super.start(bundleContext); - Activator.context = context; + Activator.bundleContext = bundleContext; while (getWorkbench() == null) { Thread.sleep(500); @@ -57,15 +60,25 @@ final Shell shell = windows[0].getShell(); IMenuManager menuManager = CIShellApplication.getMenuManager(); - CIShellContext ciContext = new LocalCIShellContext(context); + CIShellContext ciShellContext = new LocalCIShellContext(bundleContext); + Properties properties = getProperties(); + String toolName = getToolName(properties); + String toolTicketURL = getToolTicketURL(properties); - menuAdapter = new MenuAdapter(menuManager,shell,context,ciContext, windows[0]); + this.menuAdapter = new MenuAdapter( + toolName, + toolTicketURL, + menuManager, + shell, + bundleContext, + ciShellContext, + windows[0]); try { - //Fix to make swing based algorithms work on Macs + // Fix to make swing based algorithms work on Macs. shell.getDisplay().syncExec(new Runnable(){ public void run() { - //This will simply initialize the SWT_AWT compatibility mode + // This will simply initialize the SWT_AWT compatibility mode. SWT_AWT.new_Frame(new Shell(SWT.EMBEDDED)); }}); } catch (Exception e) { @@ -73,36 +86,62 @@ } } - /** - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) - */ public void stop(BundleContext context) throws Exception { - plugin = null; - menuAdapter = null; + Activator.plugin = null; + this.menuAdapter = null; super.stop(context); } - public static Object getService(String service_pid) { - ServiceReference ref = context.getServiceReference(service_pid); - - if (ref != null) { - return context.getService(ref); + public static Object getService(String servicePID) { + ServiceReference serviceReference = + Activator.bundleContext.getServiceReference(servicePID); + + if (serviceReference != null) { + return Activator.bundleContext.getService(serviceReference); } else { return null; } } - /** - * Returns the shared instance - * - * @return the shared instance - */ public static Activator getDefault() { - return plugin; + return Activator.plugin; } public void earlyStartup() { - } + + private static Properties getProperties() { + Properties brandBundleProperties = new Properties(); + + try { + URL welcomeTextFileURL = new URL(new URL( + System.getProperty("osgi.configuration.area")), WELCOME_TEXT_FILE_NAME); + brandBundleProperties.load(welcomeTextFileURL.openStream()); + } catch (IOException e) { + throw new RuntimeException(e.getMessage(), e); + } + + return brandBundleProperties; + } + + private static String getToolName(Properties properties) { + String toolName = properties.getProperty(TOOL_NAME_PROPERTY); + + if (!StringUtilities.isNull_Empty_OrWhitespace(toolName)) { + return toolName; + } else { + return DEFAULT_TOOL_NAME; + } + } + + private static String getToolTicketURL(Properties properties) { + String toolTicketURL = properties.getProperty(TOOL_TICKET_URL_PROPERTY); + + if (!StringUtilities.isNull_Empty_OrWhitespace(toolTicketURL)) { + return toolTicketURL; + } else { + return DEFAULT_TOOL_TICKET_URL; + } + } } Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2010-09-28 22:19:35 UTC (rev 1137) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2010-09-28 22:21:12 UTC (rev 1138) @@ -67,12 +67,16 @@ public static final String PRESERVED_SERVICE_PID = "service.pid"; public static final String PRESERVED = "preserved"; + public static final String HELP_DESK_EMAIL_ADDRESS = "nwb...@go..."; + + private String toolName; + private String toolTicketURL; private IMenuManager menuManager; private Shell shell; private BundleContext bundleContext; private CIShellContext ciShellContext; - private Map algorithmsToItems; - private Map itemsToParents; + private Map<String, Action> algorithmsToActions; + private Map<Action, IMenuManager> actionsToMenuManagers; private ContextListener contextListener; private IWorkbenchWindow workbenchWindow; private LogService logger; @@ -85,13 +89,13 @@ * the menu_path and label but are not listed in DEFAULT_MENU_FILE_NAME will be added on to * the menu. */ - private Map pidsToServiceReferences; + private Map<String, ServiceReference> pidsToServiceReferences; /* * This is the exactly same copy of pidsToServiceReferences. * Since some plug-ins could display on menu more than once, it provides a map between a pid * and a serviceReference while in pidsToServiceReferences that pid has been removed. */ - private Map pidsToServiceReferencesCopy; + private Map<String, ServiceReference> pidsToServiceReferencesCopy; private Document documentObjectModel; private Runnable updateAction = new Runnable() { @@ -103,34 +107,38 @@ private Runnable stopAction = new Runnable() { public void run() { String[] algorithmKeys = - (String[])MenuAdapter.this.algorithmsToItems.keySet().toArray(new String[]{}); + MenuAdapter.this.algorithmsToActions.keySet().toArray(new String[]{}); for (int ii = 0; ii < algorithmKeys.length; ii++) { - Action item = (Action)algorithmsToItems.get(algorithmKeys[ii]); - IMenuManager targetMenu = (IMenuManager)MenuAdapter.this.itemsToParents.get(item); + Action item = MenuAdapter.this.algorithmsToActions.get(algorithmKeys[ii]); + IMenuManager targetMenu = MenuAdapter.this.actionsToMenuManagers.get(item); targetMenu.remove(item.getId()); - MenuAdapter.this.algorithmsToItems.remove(algorithmKeys[ii]); - MenuAdapter.this.itemsToParents.remove(item); + MenuAdapter.this.algorithmsToActions.remove(algorithmKeys[ii]); + MenuAdapter.this.actionsToMenuManagers.remove(item); } } }; public MenuAdapter( + String toolName, + String toolTicketURL, IMenuManager menuManager, Shell shell, BundleContext bundleContext, CIShellContext ciShellContext, IWorkbenchWindow workbenchWindow) { + this.toolName = toolName; + this.toolTicketURL = toolTicketURL; this.menuManager = menuManager; this.shell = shell; this.bundleContext = bundleContext; this.ciShellContext = ciShellContext; this.workbenchWindow = workbenchWindow; - this.algorithmsToItems = new HashMap(); - this.itemsToParents = new HashMap(); - this.pidsToServiceReferences = new HashMap(); - this.pidsToServiceReferencesCopy = new HashMap(); + this.algorithmsToActions = new HashMap<String, Action>(); + this.actionsToMenuManagers = new HashMap<Action, IMenuManager>(); + this.pidsToServiceReferences = new HashMap<String, ServiceReference>(); + this.pidsToServiceReferencesCopy = new HashMap<String, ServiceReference>(); this.logger = (LogService)this.ciShellContext.getService(LogService.class.getName()); /* @@ -244,8 +252,8 @@ continue; } else { String pid = (String)serviceReferences[ii].getProperty(PRESERVED_SERVICE_PID); - pidsToServiceReferences.put(pid.toLowerCase().trim(), serviceReferences[ii]); - pidsToServiceReferencesCopy.put( + this.pidsToServiceReferences.put(pid.toLowerCase().trim(), serviceReferences[ii]); + this.pidsToServiceReferencesCopy.put( pid.toLowerCase().trim(), serviceReferences[ii]); } } @@ -386,8 +394,7 @@ // Check if the PID has registered in pidsToServiceReferences. if (this.pidsToServiceReferencesCopy.containsKey(pid.toLowerCase().trim())){ ServiceReference serviceReference = - (ServiceReference)this.pidsToServiceReferencesCopy.get( - pid.toLowerCase().trim()); + this.pidsToServiceReferencesCopy.get(pid.toLowerCase().trim()); this.pidsToServiceReferences.remove(pid.toLowerCase().trim()); AlgorithmAction action = new AlgorithmAction(serviceReference, this.bundleContext, this.ciShellContext); @@ -414,14 +421,24 @@ } } else { + String algorithmNotFoundFormat = + "Oops! %s tried to place an algorithm with the id '%s' " + + "on the menu, but the algorithm could not be found."; String algorithmNotFoundMessage = - "Oops! Network Workbench tried to place an algorithm with the id '" + - pid + - "' on the menu, but the algorithm could not be found."; - String contactInformationMessage = - "If you see this error, please contact nwb...@go..., or " + - "post a ticket on our bug tracker at: " + - "http://cns-trac.slis.indiana.edu/trac/nwb ."; + String.format(algorithmNotFoundFormat, this.toolName, pid); +// String algorithmNotFoundMessage = +// "Oops! Network Workbench tried to place an algorithm with the id '" + +// pid + +// "' on the menu, but the algorithm could not be found."; + String contactInformationFormat = + "If you see this error, please contact %s, " + + "or post a ticket on our bug tracker at: %s ."; + String contactInformationMessage = String.format( + contactInformationFormat, HELP_DESK_EMAIL_ADDRESS, this.toolTicketURL); +// String contactInformationMessage = +// "If you see this error, please contact nwb...@go..., or " + +// "post a ticket on our bug tracker at: " + +// "http://cns-trac.slis.indiana.edu/trac/nwb ."; this.logger.log(LogService.LOG_DEBUG, algorithmNotFoundMessage); this.logger.log(LogService.LOG_DEBUG, contactInformationMessage); } @@ -452,13 +469,17 @@ */ private void processLeftServiceBundles() { if (!this.pidsToServiceReferences.isEmpty()){ - Object[] keys = this.pidsToServiceReferences.keySet().toArray(); - - for (int ii = 0; ii < keys.length; ii++) { - ServiceReference serviceReference = - (ServiceReference)this.pidsToServiceReferences.get((String)keys[ii]); + for (String key : this.pidsToServiceReferences.keySet()) { + ServiceReference serviceReference = this.pidsToServiceReferences.get(key); makeMenuItem(serviceReference); - } + } +// Object[] keys = this.pidsToServiceReferences.keySet().toArray(); +// +// for (int ii = 0; ii < keys.length; ii++) { +// ServiceReference serviceReference = +// (ServiceReference)this.pidsToServiceReferences.get((String)keys[ii]); +// makeMenuItem(serviceReference); +// } } } @@ -536,8 +557,8 @@ targetMenu.appendToGroup(group, action); handleActionAccelerator(action, targetMenu, serviceReference); targetMenu.appendToGroup(group, new Separator()); - algorithmsToItems.put(getItemID(serviceReference), action); - itemsToParents.put(action, targetMenu); + algorithmsToActions.put(getItemID(serviceReference), action); + actionsToMenuManagers.put(action, targetMenu); Display.getDefault().asyncExec(this.updateAction); } else { @@ -564,7 +585,7 @@ } private void updateMenuItem(ServiceReference serviceReference) { - Action item = (Action)this.algorithmsToItems.get(getItemID(serviceReference)); + Action item = (Action)this.algorithmsToActions.get(getItemID(serviceReference)); if (item != null) { this.logger.log( @@ -575,7 +596,7 @@ private void removeMenuItem(ServiceReference serviceReference) { String path = (String)serviceReference.getProperty(MENU_PATH); - final Action item = (Action)this.algorithmsToItems.get(getItemID(serviceReference)); + final Action item = this.algorithmsToActions.get(getItemID(serviceReference)); if ((path != null) && (item != null)) { int index = path.lastIndexOf('/'); @@ -593,8 +614,8 @@ }); } - this.algorithmsToItems.remove(getItemID(serviceReference)); - this.itemsToParents.remove(item); + this.algorithmsToActions.remove(getItemID(serviceReference)); + this.actionsToMenuManagers.remove(item); } } } @@ -646,7 +667,7 @@ String shortcutString = (String)serviceReference.getProperty(SHORTCUT); if (shortcutString != null) { - return action.convertAccelerator(shortcutString); + return Action.convertAccelerator(shortcutString); } else { return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-09-28 22:19:41
|
Revision: 1137 http://cishell.svn.sourceforge.net/cishell/?rev=1137&view=rev Author: pataphil Date: 2010-09-28 22:19:35 +0000 (Tue, 28 Sep 2010) Log Message: ----------- * Added StringUtilities.getStackTraceAsString(). * Reviewed by Micah. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-09-27 18:02:57 UTC (rev 1136) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-09-28 22:19:35 UTC (rev 1137) @@ -1,5 +1,8 @@ package org.cishell.utilities; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.io.Writer; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -380,4 +383,12 @@ // public static String escape(String unescaped) { // return unescaped.replaceAll("\"", "\\\"" // } + + public static String getStackTraceAsString(Throwable e) { + Writer writer = new StringWriter(); + PrintWriter printWriter = new PrintWriter(writer); + e.printStackTrace(printWriter); + + return writer.toString(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kon...@us...> - 2010-09-27 18:03:04
|
Revision: 1136 http://cishell.svn.sourceforge.net/cishell/?rev=1136&view=rev Author: kongchinhua Date: 2010-09-27 18:02:57 +0000 (Mon, 27 Sep 2010) Log Message: ----------- Add ColorRegistry and ColorSchema for color management support - ColorSchema: Defined the scope of available colors of an application - ColorRegistry: assign color based on the given ColorSchema Reviewed by Patrick Modified Paths: -------------- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorRegistry.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorSchema.java Modified: trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-09-20 16:50:16 UTC (rev 1135) +++ trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-09-27 18:02:57 UTC (rev 1136) @@ -30,6 +30,7 @@ prefuse.util, prefuse.util.collections Export-Package: org.cishell.utilities, + org.cishell.utilities.color, org.cishell.utilities.database, org.cishell.utilities.dictionary, org.cishell.utilities.mutateParameter, Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorRegistry.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorRegistry.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorRegistry.java 2010-09-27 18:02:57 UTC (rev 1136) @@ -0,0 +1,83 @@ +package org.cishell.utilities.color; + +import java.awt.Color; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * ColorRegistry provide algorithm to assign color to + * specific item that defined in <E>. It use generic + * so that the implementation can be use for any type + * of item. + * + * To use ColorRegistry, create your own ColorSchema + * that hold the set of available colors and also + * a default color if the color is out + * @author kongch + * + */ +public class ColorRegistry<K> { + private int currentIndex; + private ColorSchema colorSchema; + private Map<K, Color> registedColors; + + public ColorRegistry(ColorSchema colorSchema) { + this.currentIndex = 0; + this.colorSchema = colorSchema; + this.registedColors = new HashMap<K, Color>(); + } + + /** + * Get all the keys that hold the specified color. + * @return Return the registered keys + */ + public Set<K> getKeySet() { + return registedColors.keySet(); + } + + /** + * Request a color for the specific key. + * @param key - key must be type of <E> + * @return Return color that assigned to the specific + * key. If all the colors are fully used, the default + * color denied by the ColorSchema will be returned + */ + public Color getColorOf(K key) { + if (registedColors.containsKey(key)) { + return registedColors.get(key); + } else { + return reserveColorFor(key); + } + } + + /** + * Clear all entry and reset to initial state. + */ + public void clear() { + registedColors.clear(); + } + + /* + * Request a color from the color schema + */ + private Color reserveColorFor(K key) { + + Color color = colorSchema.get(getNextIndex()); + registedColors.put(key, color); + + return color; + } + + /* + * Return next color index + */ + private int getNextIndex() { + int index = currentIndex; + + if (currentIndex < colorSchema.size()) { + currentIndex++; + } + return index; + } +} Property changes on: trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorRegistry.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorSchema.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorSchema.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorSchema.java 2010-09-27 18:02:57 UTC (rev 1136) @@ -0,0 +1,83 @@ +package org.cishell.utilities.color; + +import java.awt.Color; + +/** + * ColorSchema defined a set of colors to be used for + * an application. This allows the interchange of color + * schema set if needed. + * + * Schema contains a set of available color and a + * default color value. The defaultColor will be + * set to BLACK if it is not given + * @author kongch + * + */ +public class ColorSchema { + private int totalColors; + private Color[] colors; + private Color defaultColor; + + public ColorSchema(Color[] colors, Color defaultColor) { + setColors(colors); + setDefaultColor(defaultColor); + } + + /** + * The size of the color in schema which is not including + * defaultColor. + * @return Return the size of the color array + */ + public int size() { + return this.totalColors; + } + + /** + * Get color by index. + * @param index - index of the color in the schema + * @return Return a defaultColor if the given index is + * out of bound. Else return the color of the given + * index + */ + public Color get(int index) { + if (index > this.totalColors) { + return getDefaultColor(); + } + + return this.colors[index]; + } + + /** + * Get the set of available color. + * @return Always return the set of color under schema + */ + public Color[] getColors() { + return this.colors; + } + + /** + * Get the default color. + * @return Always return the default color + */ + public Color getDefaultColor() { + return this.defaultColor; + } + + private void setColors(Color[] colors) { + if (colors == null) { + this.colors = new Color[]{}; + } else { + this.colors = colors; + } + this.totalColors = this.colors.length; + } + + private void setDefaultColor(Color defaultColor) { + /* Assigned to BLACK if it is not given */ + if (defaultColor == null) { + this.defaultColor = Color.BLACK; + } else { + this.defaultColor = defaultColor; + } + } +} Property changes on: trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorSchema.java ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-09-20 16:50:28
|
Revision: 1135 http://cishell.svn.sourceforge.net/cishell/?rev=1135&view=rev Author: pataphil Date: 2010-09-20 16:50:16 +0000 (Mon, 20 Sep 2010) Log Message: ----------- * Fixed validation so it actually works properly. * Now makes more use of Google Collections. (The manifest reflects this in its imports.) * Added Utilities class. * Not reviewed. Modified Paths: -------------- trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModelField.java Added Paths: ----------- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/field/validation/Utilities.java Modified: trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF 2010-09-20 16:48:46 UTC (rev 1134) +++ trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF 2010-09-20 16:50:16 UTC (rev 1135) @@ -6,7 +6,8 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5 Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime -Import-Package: com.google.common.collect, +Import-Package: com.google.common.base, + com.google.common.collect, org.cishell.utilities, org.cishell.utility.datastructure, org.cishell.utility.datastructure.datamodel, Modified: trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModelField.java =================================================================== --- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModelField.java 2010-09-20 16:48:46 UTC (rev 1134) +++ trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModelField.java 2010-09-20 16:50:16 UTC (rev 1135) @@ -11,6 +11,7 @@ import org.cishell.utility.datastructure.datamodel.field.DataModelFieldContainer; import org.cishell.utility.datastructure.datamodel.field.validation.FieldValidationAction; import org.cishell.utility.datastructure.datamodel.field.validation.FieldValidator; +import org.cishell.utility.swt.model.field.validation.Utilities; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; @@ -118,10 +119,19 @@ public void addValidator(FieldValidator<ValueType> validator) { validator.addFieldToValidate(this); this.validators.add(validator); + // Just in case validator was added after other validators were added. + this.otherValidators.remove(validator); } + public void addValidators(Collection<FieldValidator<ValueType>> validators) { + for (FieldValidator<ValueType> validator : validators) { + addValidator(validator); + } + } + public void addOtherValidators(Collection<FieldValidator<ValueType>> validators) { - this.otherValidators.addAll(validators); + this.otherValidators.addAll( + Utilities.allFieldValidatorsExcept(validators, this.validators)); } public void addValidationAction(FieldValidationAction action) { Added: trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/field/validation/Utilities.java =================================================================== --- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/field/validation/Utilities.java (rev 0) +++ trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/field/validation/Utilities.java 2010-09-20 16:50:16 UTC (rev 1135) @@ -0,0 +1,21 @@ +package org.cishell.utility.swt.model.field.validation; + +import java.util.Collection; + +import org.cishell.utility.datastructure.datamodel.field.validation.FieldValidator; + +import com.google.common.base.Predicate; +import com.google.common.collect.Collections2; + +public class Utilities { + public static<T> Collection<FieldValidator<T>> allFieldValidatorsExcept( + Collection<FieldValidator<T>> allValidators, + final Collection<FieldValidator<T>> except) { + return Collections2.filter( + allValidators, new Predicate<FieldValidator<T>>() { + public boolean apply(FieldValidator<T> input) { + return !except.contains(input); + } + }); + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-09-20 16:48:53
|
Revision: 1134 http://cishell.svn.sourceforge.net/cishell/?rev=1134&view=rev Author: pataphil Date: 2010-09-20 16:48:46 +0000 (Mon, 20 Sep 2010) Log Message: ----------- * Fixed up Javadocs/comments for DataModel and DataModelField. * Added OneOccurrenceOfValueValidationRule (for allowing only one COUNT DISTINCT). * Minor cleanup in UniqueValueValidationRule. * Not reviewed. Modified Paths: -------------- 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/field/DataModelField.java trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/UniqueValueValidationRule.java Added Paths: ----------- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/OneOccurrenceOfValueValidationRule.java Modified: 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 2010-09-07 19:26:49 UTC (rev 1133) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/DataModel.java 2010-09-20 16:48:46 UTC (rev 1134) @@ -57,30 +57,30 @@ // DataModelAreaContainer methods - /// {@inheritDoc} + /** {@inheritDoc} */ public Collection<String> getAreaNames(); - /// {@inheritDoc} + /** {@inheritDoc} */ public Collection<DataModelArea> getAreas(); - /// {@inheritDoc} + /** {@inheritDoc} */ public DataModelArea getArea(String name); - /// {@inheritDoc} + /** {@inheritDoc} */ public DataModelArea createArea(String name) throws UniqueNameException; - /// {@inheritDoc} + /** {@inheritDoc} */ public DataModelArea createArea(String name, Object componentForArea) throws ClassCastException, ModelStructureException, UniqueNameException; - /// {@inheritDoc} + /** {@inheritDoc} */ public void addArea(DataModelArea area) throws ClassCastException, ModelStructureException, UniqueNameException; - /// {@inheritDoc} + /** {@inheritDoc} */ public boolean areaDisposed(String name); - /// {@inheritDoc} + /** {@inheritDoc} */ public boolean areaDisposed(DataModelArea area); // Group methods - /// @return all of the group names in this DataModel. + /** @return all of the group names in this DataModel. */ public Collection<String> getGroupNames(); - /// @return all of the groups in this DataModel. + /** @return all of the groups in this DataModel. */ public Collection<DataModelGroup> getGroups(); /** * Get a group by specific name. Modified: 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 2010-09-07 19:26:49 UTC (rev 1133) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelField.java 2010-09-20 16:48:46 UTC (rev 1134) @@ -21,15 +21,17 @@ public ValueType setValue(ValueType value); public ValueType reset(); - /// Add a validator to that should validate this field. + /** Add a validator that should validate this field. */ public void addValidator(FieldValidator<ValueType> validator); - /// Add validators that should be considered when performing validation actions. + /** Add all of the specified validators as validators that validate this field. */ + public void addValidators(Collection<FieldValidator<ValueType>> validators); + /** Add validators that should be considered when performing validation actions. */ public void addOtherValidators(Collection<FieldValidator<ValueType>> otherValidators); - /// Add an action to perform, given if everything validated or not. + /** Add an action to perform, given if everything validated or not. */ public void addValidationAction(FieldValidationAction action); - /// Notify everything that has added this field that this field has been disposed. + /** Notify everything that has added this field that this field has been disposed. */ public void dispose(); - /// Has this field been disposed? + /** Has this field been disposed? */ public boolean isDisposed(); } \ No newline at end of file Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/OneOccurrenceOfValueValidationRule.java =================================================================== --- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/OneOccurrenceOfValueValidationRule.java (rev 0) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/OneOccurrenceOfValueValidationRule.java 2010-09-20 16:48:46 UTC (rev 1134) @@ -0,0 +1,56 @@ +package org.cishell.utility.datastructure.datamodel.field.validation; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.cishell.utilities.MapUtilities; +import org.cishell.utilities.StringUtilities; +import org.cishell.utility.datastructure.datamodel.DataModel; +import org.cishell.utility.datastructure.datamodel.exception.ModelValidationException; +import org.cishell.utility.datastructure.datamodel.field.DataModelField; + +public class OneOccurrenceOfValueValidationRule<ValueType> + implements FieldValidationRule<ValueType> { + private String baseFieldName; + private Collection<ValueType> targetValue = new ArrayList<ValueType>(1); + private Map<String, ValueType> fieldValuesByNames = new HashMap<String, ValueType>(); + + public OneOccurrenceOfValueValidationRule(String baseFieldName, ValueType targetValue) { + this.baseFieldName = baseFieldName; + this.targetValue.add(targetValue); + } + + public void validateField(DataModelField<ValueType> field, DataModel model) + throws ModelValidationException { + String fieldName = field.getName(); + ValueType fieldValue = field.getValue(); + + this.fieldValuesByNames.put(fieldName, fieldValue); + Collection<String> namesOfFieldsWithValue = MapUtilities.getValidKeysOfTypesInMap( + this.fieldValuesByNames, this.targetValue, new ArrayList<String>()); + + if (namesOfFieldsWithValue.size() > 1) { + String exceptionMessage = String.format( + "Field's value must be not identical. Matches %sfields: [%s]", + this.baseFieldName, + StringUtilities.implodeItems(namesOfFieldsWithValue, ", ")); + throw new ModelValidationException(exceptionMessage); + } + } + + public void fieldUpdated(DataModelField<ValueType> field) { + this.fieldValuesByNames.put(field.getName(), field.getValue()); + } + + public void fieldsUpdated(Collection<DataModelField<ValueType>> fields) { + for (DataModelField<ValueType> field : fields) { + fieldUpdated(field); + } + } + + public void fieldDisposed(DataModelField<ValueType> field) { + this.fieldValuesByNames.remove(field.getName()); + } +} \ No newline at end of file Modified: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/UniqueValueValidationRule.java =================================================================== --- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/UniqueValueValidationRule.java 2010-09-07 19:26:49 UTC (rev 1133) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/UniqueValueValidationRule.java 2010-09-20 16:48:46 UTC (rev 1134) @@ -14,7 +14,6 @@ public class UniqueValueValidationRule<ValueType> implements FieldValidationRule<ValueType> { private String baseFieldName; private Map<String, ValueType> fieldValuesByNames = new HashMap<String, ValueType>(); -// private Multimap<ValueType, String> fieldNamesByValues = HashMultimap.create(); public UniqueValueValidationRule(String baseFieldName) { this.baseFieldName = baseFieldName; @@ -34,7 +33,7 @@ if (namesOfFieldsWithValue.size() > 0) { String exceptionMessage = String.format( - "Field's value must be identical. Matches %sfields: [%s]", + "Field's value must be not identical. Matches %sfields: [%s]", this.baseFieldName, StringUtilities.implodeItems(namesOfFieldsWithValue, ", ")); throw new ModelValidationException(exceptionMessage); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kon...@us...> - 2010-09-07 19:26:55
|
Revision: 1133 http://cishell.svn.sourceforge.net/cishell/?rev=1133&view=rev Author: kongchinhua Date: 2010-09-07 19:26:49 +0000 (Tue, 07 Sep 2010) Log Message: ----------- Customized exception handling for Null value support. Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/NullValueSupportException.java Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/NullValueSupportException.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/NullValueSupportException.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/NullValueSupportException.java 2010-09-07 19:26:49 UTC (rev 1133) @@ -0,0 +1,14 @@ +package org.cishell.utilities; + +/** + * Customized exception handling for Null value support. + * @author kongch + * + */ +public class NullValueSupportException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public NullValueSupportException(String message, Exception e) { + super(message, e); + } +} Property changes on: trunk/core/org.cishell.utilities/src/org/cishell/utilities/NullValueSupportException.java ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kon...@us...> - 2010-09-07 19:24:16
|
Revision: 1132 http://cishell.svn.sourceforge.net/cishell/?rev=1132&view=rev Author: kongchinhua Date: 2010-09-07 19:24:10 +0000 (Tue, 07 Sep 2010) Log Message: ----------- Fixed style guide warning Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FrequencyMap.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FrequencyMap.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FrequencyMap.java 2010-09-07 19:15:01 UTC (rev 1131) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FrequencyMap.java 2010-09-07 19:24:10 UTC (rev 1132) @@ -31,7 +31,7 @@ } /** - * Add the given key to the map and increase the frequency by 1 + * Add the given key to the map and increase the frequency by 1. * @param key - key to be added */ public void add(E key) { @@ -62,14 +62,14 @@ } /** - * Retrieve a set of keys stored in this map + * Retrieve a set of keys stored in this map. */ public Set<E> keySet() { return itemToFrequencyMap.keySet(); } /** - * Get the emergence frequency for the given key + * Get the emergence frequency for the given key. * @param key - item to be lookup * @return Return number of times the key exists * if lookup success. Return zero if key not exist This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kon...@us...> - 2010-09-07 19:15:07
|
Revision: 1131 http://cishell.svn.sourceforge.net/cishell/?rev=1131&view=rev Author: kongchinhua Date: 2010-09-07 19:15:01 +0000 (Tue, 07 Sep 2010) Log Message: ----------- Support Frequency counting - It is important to use key with unmodified value with deep comp[are of equal function - Safe to use with generic objects: String, Integer, etc - Non-generic class need customized equal and hashcode method Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FrequencyMap.java Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FrequencyMap.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FrequencyMap.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FrequencyMap.java 2010-09-07 19:15:01 UTC (rev 1131) @@ -0,0 +1,107 @@ +package org.cishell.utilities; + +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; + +/** + * FrequencyMap is a map of key with its emergence frequency. + * It supports two type of mapping structures: null key and + * non-null key; by providing boolean value to enable + * allowNullValue through constructor call. Add() method will + * add a new key if the key is not exist. Else it will increase + * the frequency by 1. sum() will return the count that + * represents sum of all the frequency values in the map + * @author kongch + * + * @param <E> + */ +public class FrequencyMap <E> { + private Map<E, Frequency> itemToFrequencyMap; + private int count; + + public FrequencyMap(boolean allowNullValue) { + count = 0; + if (allowNullValue) { + itemToFrequencyMap = new HashMap<E, Frequency>(); + } else { + itemToFrequencyMap = new Hashtable<E, Frequency>(); + } + } + + /** + * Add the given key to the map and increase the frequency by 1 + * @param key - key to be added + */ + public void add(E key) { + Frequency frequency; + + /* + * Get the Frequency object for the given key if key already exist. + * Else create a new Frequency object and add it to the map + */ + if (itemToFrequencyMap.containsKey(key)) { + frequency = itemToFrequencyMap.get(key); + } else { + frequency = new Frequency(); + try { + itemToFrequencyMap.put(key, frequency); + } catch (NullPointerException e) { + /* It is a non-null map. Throw a runtime exception */ + String message = "FrequencyMap.add(E key) was called with a null key." + + " If null support is desired, " + + " construct FrequencyMap with allowNullValue = true"; + throw new NullValueSupportException(message, e); + } + } + + /* increase frequency by 1 and also sum of all frequencies by 1 */ + count++; + frequency.increase(); + } + + /** + * Retrieve a set of keys stored in this map + */ + public Set<E> keySet() { + return itemToFrequencyMap.keySet(); + } + + /** + * Get the emergence frequency for the given key + * @param key - item to be lookup + * @return Return number of times the key exists + * if lookup success. Return zero if key not exist + */ + public int getFrequency(E key) { + if (itemToFrequencyMap.containsKey(key)) { + return itemToFrequencyMap.get(key).getValue(); + } else { + return 0; + } + } + + public int sum() { + return count; + } + + public boolean isEmpty() { + return itemToFrequencyMap.isEmpty(); + } + + private class Frequency { + private int value; + public Frequency() { + value = 0; + } + + public void increase() { + value++; + } + + public int getValue() { + return value; + } + } +} Property changes on: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FrequencyMap.java ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-27 15:23:33
|
Revision: 1130 http://cishell.svn.sourceforge.net/cishell/?rev=1130&view=rev Author: pataphil Date: 2010-08-27 15:23:24 +0000 (Fri, 27 Aug 2010) Log Message: ----------- * Escaping the separator string in StringUtilities.getAllTokens is now optional. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-08-26 17:58:18 UTC (rev 1129) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-08-27 15:23:24 UTC (rev 1130) @@ -1,7 +1,6 @@ package org.cishell.utilities; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -316,15 +315,25 @@ } public static String getNthToken( - String originalString, String separator, int index, boolean trim) { - return getAllTokens(originalString, separator, trim)[index]; + String originalString, + String separator, + int index, + boolean trim, + boolean escapeForRegularExpression) { + return getAllTokens(originalString, separator, trim, escapeForRegularExpression)[index]; } public static String[] getAllTokens( - String originalString, String separator, boolean trim) { - String escapedSeparator = escapeForRegularExpression(separator); - String[] tokens = originalString.split(escapedSeparator); + String originalString, + String separator, + boolean trim, + boolean escapeForRegularExpression) { + if (escapeForRegularExpression) { + separator = escapeForRegularExpression(separator); + } + String[] tokens = originalString.split(separator); + if (trim) { String[] trimmedTokens = new String[tokens.length]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-26 17:58:25
|
Revision: 1129 http://cishell.svn.sourceforge.net/cishell/?rev=1129&view=rev Author: pataphil Date: 2010-08-26 17:58:18 +0000 (Thu, 26 Aug 2010) Log Message: ----------- * Restructured how validation works. * Not reviewed. Modified Paths: -------------- trunk/core/org.cishell.utility.datastructure/META-INF/MANIFEST.MF trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelField.java trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModelField.java Added Paths: ----------- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/BasicFieldValidator.java trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/EmptyTextFieldValidationRule.java trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/FieldValidationAction.java trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/FieldValidationRule.java trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/FieldValidator.java trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/UniqueValueValidationRule.java trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/field/ trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/field/validation/ Removed Paths: ------------- 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.swt/src/org/cishell/utilities/swt/ 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:07:46 UTC (rev 1128) +++ trunk/core/org.cishell.utility.datastructure/META-INF/MANIFEST.MF 2010-08-26 17:58:18 UTC (rev 1129) @@ -9,5 +9,8 @@ org.cishell.utility.datastructure.datamodel.area, org.cishell.utility.datastructure.datamodel.exception, org.cishell.utility.datastructure.datamodel.field, + org.cishell.utility.datastructure.datamodel.field.validation, org.cishell.utility.datastructure.datamodel.group, org.cishell.utility.datastructure.datamodel.gui +Import-Package: com.google.common.collect, + org.cishell.utilities Modified: 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 2010-08-23 18:07:46 UTC (rev 1128) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/DataModelField.java 2010-08-26 17:58:18 UTC (rev 1129) @@ -2,7 +2,8 @@ import java.util.Collection; -import org.cishell.utility.datastructure.datamodel.DataModel; +import org.cishell.utility.datastructure.datamodel.field.validation.FieldValidationAction; +import org.cishell.utility.datastructure.datamodel.field.validation.FieldValidator; /** * DataModelFields are the meat of DataModels. @@ -20,10 +21,15 @@ 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); + /// Add a validator to that should validate this field. + public void addValidator(FieldValidator<ValueType> validator); + /// Add validators that should be considered when performing validation actions. + public void addOtherValidators(Collection<FieldValidator<ValueType>> otherValidators); + /// Add an action to perform, given if everything validated or not. + public void addValidationAction(FieldValidationAction action); + /// Notify everything that has added this field that this field has been disposed. public void dispose(); + /// Has this field been disposed? + public boolean isDisposed(); } \ No newline at end of file Deleted: 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 2010-08-23 18:07:46 UTC (rev 1128) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/FieldValidationAction.java 2010-08-26 17:58:18 UTC (rev 1129) @@ -1,12 +0,0 @@ -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 Deleted: 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 2010-08-23 18:07:46 UTC (rev 1128) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/FieldValidationRule.java 2010-08-26 17:58:18 UTC (rev 1129) @@ -1,10 +0,0 @@ -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/field/validation/BasicFieldValidator.java =================================================================== --- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/BasicFieldValidator.java (rev 0) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/BasicFieldValidator.java 2010-08-26 17:58:18 UTC (rev 1129) @@ -0,0 +1,69 @@ +package org.cishell.utility.datastructure.datamodel.field.validation; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; + +import org.cishell.utility.datastructure.datamodel.DataModel; +import org.cishell.utility.datastructure.datamodel.exception.ModelValidationException; +import org.cishell.utility.datastructure.datamodel.field.DataModelField; + +public class BasicFieldValidator<ValueType> implements FieldValidator<ValueType> { + private String baseFieldName; + private Collection<DataModelField<ValueType>> fieldsToValidate = + new HashSet<DataModelField<ValueType>>(); + private Collection<FieldValidationRule<ValueType>> rules = + new HashSet<FieldValidationRule<ValueType>>(); + + public BasicFieldValidator(String baseFieldName) { + this.baseFieldName = baseFieldName; + } + + public void addFieldToValidate(DataModelField<ValueType> field) { + this.fieldsToValidate.add(field); + } + + public void addValidationRule(FieldValidationRule<ValueType> rule) { + this.rules.add(rule); + } + + public Collection<String> runValidation(DataModel model) { + Collection<String> errorMessages = new ArrayList<String>(); + + for (DataModelField<ValueType> field : this.fieldsToValidate) { + String errorHeader = String.format( + "(%s%s, %s): ", this.baseFieldName, field.getName(), field.getValue().toString()); + + for (FieldValidationRule<ValueType> rule : this.rules) { + try { + rule.validateField(field, model); + } catch (ModelValidationException e) { + String errorMessage = errorHeader + e.getMessage(); + errorMessages.add(errorMessage); + } + } + } + + return errorMessages; + } + + public void fieldUpdated(DataModelField<ValueType> field) { + for (FieldValidationRule<ValueType> rule : this.rules) { + rule.fieldUpdated(field); + } + } + + public void fieldsUpdated(Collection<DataModelField<ValueType>> fields) { + for (FieldValidationRule<ValueType> rule : this.rules) { + rule.fieldsUpdated(fields); + } + } + + public void fieldDisposed(DataModelField<ValueType> field) { + for (FieldValidationRule<ValueType> rule : this.rules) { + rule.fieldDisposed(field); + } + + this.fieldsToValidate.remove(field); + } +} \ No newline at end of file Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/EmptyTextFieldValidationRule.java =================================================================== --- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/EmptyTextFieldValidationRule.java (rev 0) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/EmptyTextFieldValidationRule.java 2010-08-26 17:58:18 UTC (rev 1129) @@ -0,0 +1,27 @@ +package org.cishell.utility.datastructure.datamodel.field.validation; + +import java.util.Collection; + +import org.cishell.utilities.StringUtilities; +import org.cishell.utility.datastructure.datamodel.DataModel; +import org.cishell.utility.datastructure.datamodel.exception.ModelValidationException; +import org.cishell.utility.datastructure.datamodel.field.DataModelField; + +public class EmptyTextFieldValidationRule implements FieldValidationRule<String> { + public void validateField(DataModelField<String> field, DataModel model) + throws ModelValidationException { + if (StringUtilities.isNull_Empty_OrWhitespace(field.getValue())) { + String exceptionMessage = "Field may not be empty."; + throw new ModelValidationException(exceptionMessage); + } + } + + public void fieldUpdated(DataModelField<String> field) { + } + + public void fieldsUpdated(Collection<DataModelField<String>> fields) { + } + + public void fieldDisposed(DataModelField<String> field) { + } +} \ No newline at end of file Copied: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/FieldValidationAction.java (from rev 1128, 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/validation/FieldValidationAction.java (rev 0) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/FieldValidationAction.java 2010-08-26 17:58:18 UTC (rev 1129) @@ -0,0 +1,8 @@ +package org.cishell.utility.datastructure.datamodel.field.validation; + +import java.util.Collection; + +public interface FieldValidationAction { + public void doesValidate(); + public void doesNotValidate(Collection<String> errorMessages); +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/FieldValidationAction.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/FieldValidationRule.java (from rev 1128, 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/validation/FieldValidationRule.java (rev 0) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/FieldValidationRule.java 2010-08-26 17:58:18 UTC (rev 1129) @@ -0,0 +1,16 @@ +package org.cishell.utility.datastructure.datamodel.field.validation; + +import java.util.Collection; + +import org.cishell.utility.datastructure.datamodel.DataModel; +import org.cishell.utility.datastructure.datamodel.exception.ModelValidationException; +import org.cishell.utility.datastructure.datamodel.field.DataModelField; + +public interface FieldValidationRule<ValueType> { + public void validateField(DataModelField<ValueType> field, DataModel model) + throws ModelValidationException; + /// Update any internal states as necessary. + public void fieldUpdated(DataModelField<ValueType> field); + public void fieldsUpdated(Collection<DataModelField<ValueType>> fields); + public void fieldDisposed(DataModelField<ValueType> field); +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/FieldValidationRule.java ___________________________________________________________________ Added: svn:mergeinfo + Added: trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/FieldValidator.java =================================================================== --- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/FieldValidator.java (rev 0) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/FieldValidator.java 2010-08-26 17:58:18 UTC (rev 1129) @@ -0,0 +1,26 @@ +package org.cishell.utility.datastructure.datamodel.field.validation; + +import java.util.Collection; + +import org.cishell.utility.datastructure.datamodel.DataModel; +import org.cishell.utility.datastructure.datamodel.field.DataModelField; + +/** + * FieldValidators potentially validate multiple fields all in one batch. + * Fields may need multiple FieldValidators if they belong to multiple groupings of + * validation rules ({@link FieldValidationRule}). + */ +public interface FieldValidator<ValueType> { + /// Add a field to perform validation on. + public void addFieldToValidate(DataModelField<ValueType> field); + /// Add a validation rule that this validator should use for validation. + public void addValidationRule(FieldValidationRule<ValueType> rule); + /// Update any internal states as necessary. + public void fieldUpdated(DataModelField<ValueType> field); + /// Update any internal states as necessary. + public void fieldsUpdated(Collection<DataModelField<ValueType>> fields); + /// Perform validation on all fields added for validation. + public Collection<String> runValidation(DataModel model); + /// Called by the field when the field has been disposed. + 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/validation/UniqueValueValidationRule.java =================================================================== --- trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/UniqueValueValidationRule.java (rev 0) +++ trunk/core/org.cishell.utility.datastructure/src/org/cishell/utility/datastructure/datamodel/field/validation/UniqueValueValidationRule.java 2010-08-26 17:58:18 UTC (rev 1129) @@ -0,0 +1,57 @@ +package org.cishell.utility.datastructure.datamodel.field.validation; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.cishell.utilities.MapUtilities; +import org.cishell.utilities.StringUtilities; +import org.cishell.utility.datastructure.datamodel.DataModel; +import org.cishell.utility.datastructure.datamodel.exception.ModelValidationException; +import org.cishell.utility.datastructure.datamodel.field.DataModelField; + +public class UniqueValueValidationRule<ValueType> implements FieldValidationRule<ValueType> { + private String baseFieldName; + private Map<String, ValueType> fieldValuesByNames = new HashMap<String, ValueType>(); +// private Multimap<ValueType, String> fieldNamesByValues = HashMultimap.create(); + + public UniqueValueValidationRule(String baseFieldName) { + this.baseFieldName = baseFieldName; + } + + public void validateField(DataModelField<ValueType> field, DataModel model) + throws ModelValidationException { + String fieldName = field.getName(); + ValueType fieldValue = field.getValue(); + Collection<String> fieldNameForFiltering = Arrays.asList(fieldName); + @SuppressWarnings("unchecked") + Collection<ValueType> fieldValueForFiltering = Arrays.asList(fieldValue); + + this.fieldValuesByNames.put(fieldName, fieldValue); + Collection<String> namesOfFieldsWithValue = MapUtilities.getValidKeysOfTypesInMap( + this.fieldValuesByNames, fieldValueForFiltering, fieldNameForFiltering); + + if (namesOfFieldsWithValue.size() > 0) { + String exceptionMessage = String.format( + "Field's value must be identical. Matches %sfields: [%s]", + this.baseFieldName, + StringUtilities.implodeItems(namesOfFieldsWithValue, ", ")); + throw new ModelValidationException(exceptionMessage); + } + } + + public void fieldUpdated(DataModelField<ValueType> field) { + this.fieldValuesByNames.put(field.getName(), field.getValue()); + } + + public void fieldsUpdated(Collection<DataModelField<ValueType>> fields) { + for (DataModelField<ValueType> field : fields) { + fieldUpdated(field); + } + } + + public void fieldDisposed(DataModelField<ValueType> field) { + this.fieldValuesByNames.remove(field.getName()); + } +} \ 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:07:46 UTC (rev 1128) +++ trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF 2010-08-26 17:58:18 UTC (rev 1129) @@ -13,6 +13,7 @@ org.cishell.utility.datastructure.datamodel.area, org.cishell.utility.datastructure.datamodel.exception, org.cishell.utility.datastructure.datamodel.field, + org.cishell.utility.datastructure.datamodel.field.validation, org.cishell.utility.datastructure.datamodel.group, org.cishell.utility.datastructure.datamodel.gui Export-Package: org.cishell.utility.swt, Modified: trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModelField.java =================================================================== --- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModelField.java 2010-08-23 18:07:46 UTC (rev 1128) +++ trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/model/SWTModelField.java 2010-08-26 17:58:18 UTC (rev 1129) @@ -7,11 +7,10 @@ import org.cishell.utility.datastructure.datamodel.DataModel; import org.cishell.utility.datastructure.datamodel.ModelDataSynchronizer; -import org.cishell.utility.datastructure.datamodel.exception.ModelValidationException; import org.cishell.utility.datastructure.datamodel.field.DataModelField; import org.cishell.utility.datastructure.datamodel.field.DataModelFieldContainer; -import org.cishell.utility.datastructure.datamodel.field.FieldValidationAction; -import org.cishell.utility.datastructure.datamodel.field.FieldValidationRule; +import org.cishell.utility.datastructure.datamodel.field.validation.FieldValidationAction; +import org.cishell.utility.datastructure.datamodel.field.validation.FieldValidator; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; @@ -23,6 +22,7 @@ DataSynchronizerType extends ModelDataSynchronizer<ValueType>> implements DataModelField<ValueType> { private Set<DataModelFieldContainer> containers = new HashSet<DataModelFieldContainer>(); + private DataModel model; private String name; private Composite parentComponent; private ValueType defaultValue; @@ -30,18 +30,22 @@ private ValueType value; private BaseGUIComponentType widget; private DataSynchronizerType dataSynchronizer; - private Collection<FieldValidationRule<ValueType>> validators = - new ArrayList<FieldValidationRule<ValueType>>(); - private Collection<FieldValidationAction<ValueType>> validationActions = - new ArrayList<FieldValidationAction<ValueType>>(); + private Collection<FieldValidator<ValueType>> validators = + new ArrayList<FieldValidator<ValueType>>(); + private Collection<FieldValidator<ValueType>> otherValidators = + new ArrayList<FieldValidator<ValueType>>(); + private Collection<FieldValidationAction> validationActions = + new HashSet<FieldValidationAction>(); + private boolean isDisposed = false; public SWTModelField( - final DataModel model, + DataModel model, String name, Composite parentComponent, ValueType defaultValue, BaseGUIComponentType widget, DataSynchronizerType dataSynchronizer) { + this.model = model; this.name = name; this.parentComponent = parentComponent; this.defaultValue = defaultValue; @@ -55,7 +59,7 @@ SWTModelField.this.previousValue = SWTModelField.this.value; SWTModelField.this.value = SWTModelField.this.dataSynchronizer.synchronizeFromGUI(); - validate(model); + validate(); } } }); @@ -111,63 +115,74 @@ return this.value; } - public void addValidationRule( - FieldValidationRule<ValueType> validator, boolean validateNow, DataModel model) { + public void addValidator(FieldValidator<ValueType> validator) { + validator.addFieldToValidate(this); this.validators.add(validator); - - if (validateNow) { - validate(model); - } } - public void addValidationAction(FieldValidationAction<ValueType> validationAction) { - this.validationActions.add(validationAction); + public void addOtherValidators(Collection<FieldValidator<ValueType>> validators) { + this.otherValidators.addAll(validators); } - public void validate(DataModel model) { - Collection<ModelValidationException> reasonsInvalid = attemptValidation(model); - performValidationActions(model, reasonsInvalid); + public void addValidationAction(FieldValidationAction action) { + this.validationActions.add(action); } public void dispose() { + this.isDisposed = true; + for (DataModelFieldContainer container : this.containers) { container.fieldDisposed(this); } - for (FieldValidationRule<ValueType> validator : this.validators) { + for (FieldValidator<ValueType> validator : this.validators) { validator.fieldDisposed(this); } - for (FieldValidationAction<ValueType> validationAction : this.validationActions) { - validationAction.fieldDisposed(this); - } + validate(); } - private Collection<ModelValidationException> attemptValidation(DataModel model) { - Collection<ModelValidationException> reasonsInvalid = - new ArrayList<ModelValidationException>(); + public boolean isDisposed() { + return this.isDisposed; + } - for (FieldValidationRule<ValueType> validator : this.validators) { - try { - validator.validateField(this, model); - } catch (ModelValidationException e) { - reasonsInvalid.add(e); - } - } + public void validate() { + Collection<String> errorMessages = attemptValidation(model); + performValidationActions(this.model, errorMessages); + } - return reasonsInvalid; + private Collection<String> attemptValidation(DataModel model) { + Collection<String> errorMessages = attemptValidationOnValidators(this.validators, true); + errorMessages.addAll(attemptValidationOnValidators(this.otherValidators, false)); + + return errorMessages; } - private void performValidationActions( - DataModel model, Collection<ModelValidationException> reasonsInvalid) { - if (reasonsInvalid.size() == 0) { - for (FieldValidationAction<ValueType> validationAction : this.validationActions) { - validationAction.fieldDoesValidate(this); + private void performValidationActions(DataModel model, Collection<String> errorMessages) { + if (errorMessages.size() == 0) { + for (FieldValidationAction validationAction : this.validationActions) { + validationAction.doesValidate(); } } else { - for (FieldValidationAction<ValueType> validationAction : this.validationActions) { - validationAction.fieldDoesNotValidate(this, reasonsInvalid); + for (FieldValidationAction validationAction : this.validationActions) { + validationAction.doesNotValidate(errorMessages); } } } + + private Collection<String> attemptValidationOnValidators( + Collection<FieldValidator<ValueType>> validators, boolean update) { + Collection<String> errorMessages = new ArrayList<String>(); + + for (FieldValidator<ValueType> validator : validators) { + if (update && !this.isDisposed) { + validator.fieldUpdated(this); + } + + Collection<String> temporaryErrorMessage = validator.runValidation(model); + errorMessages.addAll(temporaryErrorMessage); + } + + return errorMessages; + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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] |