From: <pat...@us...> - 2009-08-18 22:26:33
|
Revision: 929 http://cishell.svn.sourceforge.net/cishell/?rev=929&view=rev Author: pataphil Date: 2009-08-18 22:26:25 +0000 (Tue, 18 Aug 2009) Log Message: ----------- * Finished enhancing GUI parameter builder page (for both the Java and Static Executable Algorithm Wizards). * Reviewed by Chintan. Modified Paths: -------------- trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/guibuilder/AttributeDefinitionEditor.java trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/guibuilder/EditableAttributeDefinition.java trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/guibuilder/ParameterBuilderDelegate.java trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/pages/ParameterListBuilderPage.java trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/StaticExecutableInputDataDelegate.java trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/StaticExecutableOutputDataDelegate.java Added Paths: ----------- trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/utilities/ParameterUtilities.java Modified: trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/guibuilder/AttributeDefinitionEditor.java =================================================================== --- trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/guibuilder/AttributeDefinitionEditor.java 2009-08-18 21:53:40 UTC (rev 928) +++ trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/guibuilder/AttributeDefinitionEditor.java 2009-08-18 22:26:25 UTC (rev 929) @@ -1,5 +1,6 @@ package org.cishell.templates.guibuilder; +import org.cishell.templates.wizards.utilities.ParameterUtilities; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; @@ -12,90 +13,165 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import org.osgi.service.metatype.AttributeDefinition; public class AttributeDefinitionEditor extends Dialog { - public static final String[] TYPE_LABELS = new String[]{ - "String","Integer","Long","Short","Double","Float","Boolean", "Char", - "Byte", "File", "Directory" - }; - public static final int[] TYPE_VALUES = new int[] { - 1,3,2,4,7,8,11,5,6,1,1 - }; + private EditableAttributeDefinition attributeDefinition; + private Text idText; + private Text nameText; + private Text descriptionText; + private Text defaultValueText; + private Text minimumValueText; + private Text maximumValueText; + private Combo selectedTypeCombo; - private EditableAttributeDefinition attribute; - private Text id; - private Text name; - private Text description; - private Text defaultValue; - private Combo type; - - public AttributeDefinitionEditor(Composite parent, EditableAttributeDefinition attr) { - this(parent.getShell(), attr); + public AttributeDefinitionEditor( + Composite parent, + EditableAttributeDefinition attributeDefinition) { + this(parent.getShell(), attributeDefinition); } - private AttributeDefinitionEditor(Shell parentShell, EditableAttributeDefinition attr) { + private AttributeDefinitionEditor( + Shell parentShell, + EditableAttributeDefinition attributeDefinition) { super(parentShell); - this.attribute = attr; + this.attributeDefinition = attributeDefinition; } protected Control createDialogArea(Composite parent) { - Composite composite = (Composite) super.createDialogArea(parent); + Composite composite = (Composite)super.createDialogArea(parent); Composite panel = new Composite(composite, SWT.NONE); GridLayout gridLayout = new GridLayout(2, false); panel.setLayout(gridLayout); - id = newTextInput(panel, "Unique ID"); - id.setText(attribute.getID()); + this.idText = createNewTextInput(panel, ParameterUtilities.ID_LABEL); + this.idText.setText(attributeDefinition.getID()); - name = newTextInput(panel, "Name"); - name.setText(attribute.getName()); + this.nameText = createNewTextInput(panel, ParameterUtilities.NAME_LABEL); + this.nameText.setText(attributeDefinition.getName()); - description = newTextInput(panel, "Description"); - description.setText(attribute.getDescription()); + this.selectedTypeCombo = + newListInput(panel, ParameterUtilities.INPUT_TYPE_LABEL); + this.selectedTypeCombo.setItems(ParameterUtilities.TYPE_LABELS); - defaultValue = newTextInput(panel, "Default Value"); - defaultValue.setText(attribute.getDefaultValue()[0]); + this.descriptionText = + createNewTextInput(panel, ParameterUtilities.DESCRIPTION_LABEL); + this.descriptionText.setText(attributeDefinition.getDescription()); - type = newListInput(panel, "Input Type"); - type.setItems(TYPE_LABELS); + this.defaultValueText = + createNewTextInput(panel, ParameterUtilities.DEFAULT_VALUE_LABEL); + this.defaultValueText.setText( + attributeDefinition.getActualDefaultValue()); - type.addSelectionListener(new SelectionListener(){ - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); + this.minimumValueText = + createNewTextInput(panel, ParameterUtilities.MINIMUM_VALUE_LABEL); + this.minimumValueText.setText(attributeDefinition.getMinValue()); + + this.maximumValueText = + createNewTextInput(panel, ParameterUtilities.MAXIMUM_VALUE_LABEL); + this.maximumValueText.setText(attributeDefinition.getMaxValue()); + + this.selectedTypeCombo.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent selectionEvent) { + widgetSelected(selectionEvent); } - public void widgetSelected(SelectionEvent e) { - int i = type.getSelectionIndex(); - if (i == 9) { //file - defaultValue.setText("file:"); + public void widgetSelected(SelectionEvent selectionEvent) { + int selectionIndex = selectedTypeCombo.getSelectionIndex(); + + boolean hadFileOrDirectoryType = + ParameterUtilities.attributeHasFileOrDirectoryType( + AttributeDefinitionEditor.this.attributeDefinition); + + if (selectionIndex == + ParameterUtilities.TYPE_VALUE_INDEX_FILE) { + AttributeDefinitionEditor.this.defaultValueText.setText( + ParameterUtilities.DEFAULT_FILE_VALUE); + } else if (selectionIndex == + ParameterUtilities.TYPE_VALUE_INDEX_DIRECTORY) { + AttributeDefinitionEditor.this.defaultValueText.setText( + ParameterUtilities.DEFAULT_DIRECTORY_VALUE); + } else if (hadFileOrDirectoryType) { + AttributeDefinitionEditor.this.defaultValueText.setText( + ""); } - if (i == 10) { //directory - defaultValue.setText("directory:"); - } - defaultValue.setEnabled(i != 9 && i != 10); - }}); + + /* + * Enable the default value if the selectedTypeCombo of value + * is not file or directory. + */ + boolean defaultValueTextEnabledStatus = + shouldEnableDefaultValueTextBasedOnSelectionIndex( + selectionIndex); + AttributeDefinitionEditor.this.defaultValueText.setEnabled( + defaultValueTextEnabledStatus); + + /* + * Enable the minimum and maximum values if the + * selectedTypeCombo of value is numeric. + */ + boolean minAndMaxTextsEnabledStatus = + shouldEnableMinAndMaxTextsBasedOnSelectionIndex( + selectionIndex); + AttributeDefinitionEditor.this.minimumValueText.setEnabled( + minAndMaxTextsEnabledStatus); + AttributeDefinitionEditor.this.maximumValueText.setEnabled( + minAndMaxTextsEnabledStatus); + } + }); - for (int i=0; i < TYPE_VALUES.length; i++) { - if (TYPE_VALUES[i] == attribute.getType()) { - type.select(i); - break; - } + if (ParameterUtilities.attributeHasFileType( + this.attributeDefinition)) { + this.selectedTypeCombo.select( + ParameterUtilities.TYPE_VALUE_INDEX_FILE); + } else if (ParameterUtilities.attributeHasDirectoryType( + this.attributeDefinition)) { + this.selectedTypeCombo.select( + ParameterUtilities.TYPE_VALUE_INDEX_DIRECTORY); + } else { + for (int ii = 0; + ii < ParameterUtilities.TYPE_VALUES.length; + ii++) { + if (ParameterUtilities.TYPE_VALUES[ii] == + this.attributeDefinition.getType()) { + this.selectedTypeCombo.select(ii); + + break; + } + } } + /* + * This is necessary because the + * this.selectedTypeCombo.select(ii); + * line above doesn't actually fire the selected event. + */ + boolean defaultValueTextEnabledStatus = + shouldEnableDefaultValueTextBasedOnAttribute( + this.attributeDefinition); + this.defaultValueText.setEnabled(defaultValueTextEnabledStatus); + boolean minAndMaxTextsEnabledStatus = + shouldEnableMinAndMaxTextsBasedOnAttribute( + this.attributeDefinition); + AttributeDefinitionEditor.this.minimumValueText.setEnabled( + minAndMaxTextsEnabledStatus); + AttributeDefinitionEditor.this.maximumValueText.setEnabled( + minAndMaxTextsEnabledStatus); + composite.getShell().setText("Parameter Editor"); return composite; } - private Text newTextInput(Composite panel, String text) { + private Text createNewTextInput(Composite panel, String text) { Label label = new Label(panel, SWT.NONE); label.setText(text); GridData data = new GridData(SWT.LEFT, SWT.BEGINNING, false, false); label.setLayoutData(data); - Text input = new Text(panel, SWT.NONE); + Text input = new Text(panel, SWT.BORDER); data = new GridData(SWT.FILL, SWT.BEGINNING, true, false); input.setLayoutData(data); @@ -113,24 +189,88 @@ return list; } + /* + * TODO: Validate the default, min, and max fields depending on the type. + * This may require setting up a non-editable string field for errors and + * throwing an exception back to here from the validation methods, + * or something. + */ protected void okPressed() { - attribute.setID(cleanText(id.getText())); - attribute.setName(cleanText(name.getText())); - String desc = cleanText(description.getText()); - if (desc.length() == 0) { - desc = " "; - } - attribute.setDescription(desc); - attribute.setDefaultValue(new String[]{cleanText(defaultValue.getText())}); - attribute.setType(TYPE_VALUES[type.getSelectionIndex()]); + this.attributeDefinition.setID(cleanText(this.idText.getText())); + this.attributeDefinition.setName(cleanText(this.nameText.getText())); + this.attributeDefinition.setType( + ParameterUtilities.TYPE_VALUES[ + this.selectedTypeCombo.getSelectionIndex()]); + this.attributeDefinition.setDescription( + cleanText(this.descriptionText.getText(), false)); + // TODO: cleanDefaultValue + this.attributeDefinition.setDefaultValue( + cleanText(this.defaultValueText.getText())); + // TODO: cleanNumberValue + this.attributeDefinition.setMinValue( + cleanText(this.minimumValueText.getText())); + this.attributeDefinition.setMaxValue( + cleanText(this.maximumValueText.getText())); super.okPressed(); } private String cleanText(String text) { - text = text.replaceAll("<", "<"); - text = text.replaceAll(">", ">"); - - return text; + return cleanText(text, true); } + + private String cleanText(String text, boolean canHaveZeroLength) { + String cleanedText = + text.replaceAll("<", "<").replaceAll(">", ">"); + + if (!canHaveZeroLength && cleanedText.length() == 0) { + return " "; + } else { + return cleanedText; + } + } + + private static boolean shouldEnableDefaultValueTextBasedOnSelectionIndex( + int selectionIndex) { + switch (selectionIndex) { + default: + return true; + case ParameterUtilities.TYPE_VALUE_INDEX_FILE: + case ParameterUtilities.TYPE_VALUE_INDEX_DIRECTORY: + return false; + } + } + + private static boolean shouldEnableDefaultValueTextBasedOnAttribute( + EditableAttributeDefinition attribute) { + return !ParameterUtilities.attributeHasFileOrDirectoryType(attribute); + } + + private static boolean shouldEnableMinAndMaxTextsBasedOnSelectionIndex( + int selectionIndex) { + switch (selectionIndex) { + default: + return true; + case ParameterUtilities.TYPE_VALUE_INDEX_STRING: + case ParameterUtilities.TYPE_VALUE_INDEX_BOOLEAN: + case ParameterUtilities.TYPE_VALUE_INDEX_CHARACTER: + case ParameterUtilities.TYPE_VALUE_INDEX_BYTE: + case ParameterUtilities.TYPE_VALUE_INDEX_FILE: + case ParameterUtilities.TYPE_VALUE_INDEX_DIRECTORY: + return false; + } + } + + private static boolean shouldEnableMinAndMaxTextsBasedOnAttribute( + EditableAttributeDefinition attribute) { + switch (attribute.getType()) { + default: + return true; + case AttributeDefinition.STRING: + case AttributeDefinition.BOOLEAN: + case AttributeDefinition.CHARACTER: + case AttributeDefinition.BYTE: + return false; + } + } } Modified: trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/guibuilder/EditableAttributeDefinition.java =================================================================== --- trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/guibuilder/EditableAttributeDefinition.java 2009-08-18 21:53:40 UTC (rev 928) +++ trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/guibuilder/EditableAttributeDefinition.java 2009-08-18 22:26:25 UTC (rev 929) @@ -19,15 +19,18 @@ String id; String name; String description; - String[] defaultValue; + String defaultValue; int type; String minValue; String maxValue; public EditableAttributeDefinition() {} - public EditableAttributeDefinition(String id, String name, String description, - String[] defaultValue, int type) { + public EditableAttributeDefinition(String id, + String name, + String description, + String defaultValue, + int type) { this.id = id; this.name = name; this.description = description; @@ -52,8 +55,12 @@ } public String[] getDefaultValue() { - return defaultValue; + return new String[] { defaultValue }; } + + public String getActualDefaultValue() { + return defaultValue; + } public String getDescription() { return description; @@ -72,8 +79,12 @@ } public void setDefaultValue(String[] defaultValue) { - this.defaultValue = defaultValue; + this.defaultValue = defaultValue[0]; } + + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } public void setDescription(String description) { this.description = description; Modified: trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/guibuilder/ParameterBuilderDelegate.java =================================================================== --- trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/guibuilder/ParameterBuilderDelegate.java 2009-08-18 21:53:40 UTC (rev 928) +++ trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/guibuilder/ParameterBuilderDelegate.java 2009-08-18 22:26:25 UTC (rev 929) @@ -3,6 +3,7 @@ import java.util.HashMap; import java.util.Map; +import org.cishell.templates.wizards.utilities.ParameterUtilities; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.TableItem; @@ -10,37 +11,68 @@ public class ParameterBuilderDelegate implements BuilderDelegate { public static final String[] COLUMN_LABELS = new String[] { - "id", "Type", "Label" + "ID", + "Label", + "Type", + "Description", + "Default", + "Minimum Value (Number Types Only)", + "Maximum Value (Number Types Only)" }; + public static final String DEFAULT_ATTRIBUTE_DEFINITION_NAME = + "Parameter Label"; + public static final String DEFAULT_ATTRIBUTE_DEFINITION_DESCRIPTION = + "Parameter Description"; + public static final String DEFAULT_ATTRIBUTE_DEFINITION_VALUE = + "Default Value"; + public static final int DEFAULT_ATTRIBUTE_DEFINITION_TYPE = + AttributeDefinition.STRING; + public static final String DEFAULT_ATTRIBUTE_DEFINITION_MINIMUM_VALUE = ""; + public static final String DEFAULT_ATTRIBUTE_DEFINITION_MAXIMUM_VALUE = ""; + private Map idToAttributeMap; private int lastID; private Composite parent; public ParameterBuilderDelegate(Composite parent) { this.parent = parent; - idToAttributeMap = new HashMap(); - lastID = 0; + this.idToAttributeMap = new HashMap(); + this.lastID = 0; } public String[] createItem() { - EditableAttributeDefinition attribute = new EditableAttributeDefinition(); - lastID++; - attribute.setID("" + lastID); - attribute.setName("Parameter Label"); - attribute.setDescription("Parameter Description"); - attribute.setDefaultValue(new String[] { "Default value" }); - attribute.setType(AttributeDefinition.STRING); + EditableAttributeDefinition attributeDefinition = + new EditableAttributeDefinition(); + this.lastID++; - boolean success = edit(attribute); + attributeDefinition.setID(Integer.toString(lastID)); + attributeDefinition.setName(DEFAULT_ATTRIBUTE_DEFINITION_NAME); + attributeDefinition.setType(DEFAULT_ATTRIBUTE_DEFINITION_TYPE); + attributeDefinition.setDescription( + DEFAULT_ATTRIBUTE_DEFINITION_DESCRIPTION); + attributeDefinition.setDefaultValue( + DEFAULT_ATTRIBUTE_DEFINITION_VALUE); + attributeDefinition.setMinValue( + DEFAULT_ATTRIBUTE_DEFINITION_MINIMUM_VALUE); + attributeDefinition.setMaxValue( + DEFAULT_ATTRIBUTE_DEFINITION_MAXIMUM_VALUE); - if (success) { - idToAttributeMap.put(attribute.getID(), attribute); + boolean newItemWasCreated = + editAttributeDefinition(attributeDefinition); + + if (newItemWasCreated) { + idToAttributeMap.put(attributeDefinition.getID(), + attributeDefinition); String[] item = new String[]{ - attribute.getID(), - getTypeString(attribute.getType()), - attribute.getName() + attributeDefinition.getID(), + attributeDefinition.getName(), + getTypeString(attributeDefinition), + attributeDefinition.getDescription(), + attributeDefinition.getActualDefaultValue(), + attributeDefinition.getMinValue(), + attributeDefinition.getMaxValue() }; return item; @@ -55,14 +87,19 @@ EditableAttributeDefinition attribute = (EditableAttributeDefinition)idToAttributeMap.get(itemID); - edit(attribute); - - item.setText(0, attribute.getID()); - item.setText(1, getTypeString(attribute.getType())); - item.setText(2, attribute.getName()); + if (editAttributeDefinition(attribute)) { + item.setText(0, attribute.getID()); + item.setText(1, attribute.getName()); + item.setText(2, getTypeString(attribute)); + item.setText(3, attribute.getDescription()); + item.setText(4, attribute.getActualDefaultValue()); + item.setText(5, attribute.getMinValue()); + item.setText(6, attribute.getMaxValue()); + } } - protected boolean edit(EditableAttributeDefinition attribute) { + protected boolean editAttributeDefinition( + EditableAttributeDefinition attribute) { AttributeDefinitionEditor attributeDefinitionEditor = new AttributeDefinitionEditor(parent, attribute); int returnCode = attributeDefinitionEditor.open(); @@ -74,19 +111,23 @@ return returnCode == Dialog.OK; } - protected String getTypeString(int type) { - String typeString = "Unknown"; + protected String getTypeString(EditableAttributeDefinition attribute) { + if (ParameterUtilities.attributeHasFileType(attribute)) { + return "File"; + } else if (ParameterUtilities.attributeHasDirectoryType( + attribute)) { + return "Directory"; + } else { + int type = attribute.getType(); + + for (int ii = 0; ii < ParameterUtilities.TYPE_VALUES.length; ii++) { + if (ParameterUtilities.TYPE_VALUES[ii] == type) { + return ParameterUtilities.TYPE_LABELS[ii]; + } + } + } - for (int ii = 0; - ii < AttributeDefinitionEditor.TYPE_VALUES.length; - ii++) { - if (AttributeDefinitionEditor.TYPE_VALUES[ii] == type) { - typeString = AttributeDefinitionEditor.TYPE_LABELS[ii]; - break; - } - } - - return typeString; + return "Unknown Type"; } public EditableAttributeDefinition getAttributeDefinition(String id) { Modified: trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/pages/ParameterListBuilderPage.java =================================================================== --- trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/pages/ParameterListBuilderPage.java 2009-08-18 21:53:40 UTC (rev 928) +++ trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/pages/ParameterListBuilderPage.java 2009-08-18 22:26:25 UTC (rev 929) @@ -13,10 +13,10 @@ * ***************************************************************************/ package org.cishell.templates.wizards.pages; -import org.cishell.templates.guibuilder.AttributeDefinitionEditor; import org.cishell.templates.guibuilder.EditableAttributeDefinition; import org.cishell.templates.guibuilder.ParameterListBuilder; import org.cishell.templates.staticexecutable.providers.InputParameterProvider; +import org.cishell.templates.wizards.utilities.ParameterUtilities; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; @@ -58,13 +58,34 @@ EditableAttributeDefinition[] attributes = getAttributeDefinitions(); String output = ""; - for (int ii =0; ii < attributes.length; ii++) { + for (int ii = 0; ii < attributes.length; ii++) { output += "\t\t<AD name=\"" + attributes[ii].getName()+"\" " + "id=\"" + attributes[ii].getID() + "\" " + "type=\"" + getTypeString(attributes[ii]) + "\" " + "description=\"" + attributes[ii].getDescription() + "\" " + - "default=\"" + attributes[ii].getDefaultValue()[0] + "\"/>\n"; + "default=\"" + attributes[ii].getActualDefaultValue() + "\""; + + switch (attributes[ii].getType()) { + /*TODO: make explicit comment + * There are more number types than non-number types, so make + * switching on number types the default. + */ + case AttributeDefinition.BOOLEAN: + case AttributeDefinition.CHARACTER: + case AttributeDefinition.STRING: + break; + default: + if (!attributes[ii].getMinValue().equals("")) { + output += " min=\"" + attributes[ii].getMinValue() + "\""; + } + + if (!attributes[ii].getMaxValue().equals("")) { + output += " max=\"" + attributes[ii].getMaxValue() + "\""; + } + } + + output += "/>\n"; } return output; @@ -74,11 +95,9 @@ String typeString = "Unknown"; int type = attribute.getType(); - for (int ii = 0; - ii < AttributeDefinitionEditor.TYPE_VALUES.length; - ii++) { - if (AttributeDefinitionEditor.TYPE_VALUES[ii] == type) { - typeString = AttributeDefinitionEditor.TYPE_LABELS[ii]; + for (int ii = 0; ii < ParameterUtilities.TYPE_VALUES.length; ii++) { + if (ParameterUtilities.TYPE_VALUES[ii] == type) { + typeString = ParameterUtilities.TYPE_LABELS[ii]; break; } Modified: trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/StaticExecutableInputDataDelegate.java =================================================================== --- trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/StaticExecutableInputDataDelegate.java 2009-08-18 21:53:40 UTC (rev 928) +++ trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/StaticExecutableInputDataDelegate.java 2009-08-18 22:26:25 UTC (rev 929) @@ -3,8 +3,8 @@ import java.util.HashMap; import java.util.Map; -import org.cishell.templates.guibuilder.AttributeDefinitionEditor; import org.cishell.templates.guibuilder.BuilderDelegate; +import org.cishell.templates.wizards.utilities.ParameterUtilities; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.TableItem; @@ -87,11 +87,9 @@ protected String getTypeString(int type) { String typeString = "Unknown"; - for (int ii = 0; - ii < AttributeDefinitionEditor.TYPE_VALUES.length; - ii++) { - if (AttributeDefinitionEditor.TYPE_VALUES[ii] == type) { - typeString = AttributeDefinitionEditor.TYPE_LABELS[ii]; + for (int ii = 0; ii < ParameterUtilities.TYPE_VALUES.length; ii++) { + if (ParameterUtilities.TYPE_VALUES[ii] == type) { + typeString = ParameterUtilities.TYPE_LABELS[ii]; break; } } Modified: trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/StaticExecutableOutputDataDelegate.java =================================================================== --- trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/StaticExecutableOutputDataDelegate.java 2009-08-18 21:53:40 UTC (rev 928) +++ trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/StaticExecutableOutputDataDelegate.java 2009-08-18 22:26:25 UTC (rev 929) @@ -3,8 +3,8 @@ import java.util.HashMap; import java.util.Map; -import org.cishell.templates.guibuilder.AttributeDefinitionEditor; import org.cishell.templates.guibuilder.BuilderDelegate; +import org.cishell.templates.wizards.utilities.ParameterUtilities; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.TableItem; @@ -103,11 +103,9 @@ protected String getTypeString(int type) { String typeString = "Unknown"; - for (int ii = 0; - ii < AttributeDefinitionEditor.TYPE_VALUES.length; - ii++) { - if (AttributeDefinitionEditor.TYPE_VALUES[ii] == type) { - typeString = AttributeDefinitionEditor.TYPE_LABELS[ii]; + for (int ii = 0; ii < ParameterUtilities.TYPE_VALUES.length; ii++) { + if (ParameterUtilities.TYPE_VALUES[ii] == type) { + typeString = ParameterUtilities.TYPE_LABELS[ii]; break; } } Added: trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/utilities/ParameterUtilities.java =================================================================== --- trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/utilities/ParameterUtilities.java (rev 0) +++ trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/utilities/ParameterUtilities.java 2009-08-18 22:26:25 UTC (rev 929) @@ -0,0 +1,87 @@ +package org.cishell.templates.wizards.utilities; + +import org.cishell.templates.guibuilder.EditableAttributeDefinition; +import org.osgi.service.metatype.AttributeDefinition; + +public class ParameterUtilities { + public static final String ID_LABEL = "Unique ID"; + public static final String NAME_LABEL = "Name"; + public static final String INPUT_TYPE_LABEL = "Input Type"; + public static final String DESCRIPTION_LABEL = "Description"; + public static final String DEFAULT_VALUE_LABEL = "Default Value"; + public static final String MINIMUM_VALUE_LABEL = "Minimum Value"; + public static final String MAXIMUM_VALUE_LABEL = "Maximum Value"; + + public static final String DEFAULT_FILE_VALUE = "file:"; + public static final String DEFAULT_DIRECTORY_VALUE = "directory:"; + + public static final String[] TYPE_LABELS = new String[] { + "String", + "Integer", + "Long", + "Short", + "Double", + "Float", + "Boolean", + "Char", + "Byte", + "File", + "Directory" + }; + + public static final int[] TYPE_VALUES = new int[] { + AttributeDefinition.STRING, + AttributeDefinition.INTEGER, + AttributeDefinition.LONG, + AttributeDefinition.SHORT, + AttributeDefinition.DOUBLE, + AttributeDefinition.FLOAT, + AttributeDefinition.BOOLEAN, + AttributeDefinition.CHARACTER, + AttributeDefinition.BYTE, + AttributeDefinition.STRING, + AttributeDefinition.STRING + }; + + public static final int TYPE_VALUE_INDEX_STRING = 0; + public static final int TYPE_VALUE_INDEX_INTEGER = 1; + public static final int TYPE_VALUE_INDEX_LONG = 2; + public static final int TYPE_VALUE_INDEX_SHORT = 3; + public static final int TYPE_VALUE_INDEX_DOUBLE = 4; + public static final int TYPE_VALUE_INDEX_FLOAT = 5; + public static final int TYPE_VALUE_INDEX_BOOLEAN = 6; + public static final int TYPE_VALUE_INDEX_CHARACTER = 7; + public static final int TYPE_VALUE_INDEX_BYTE = 8; + public static final int TYPE_VALUE_INDEX_FILE = 9; + public static final int TYPE_VALUE_INDEX_DIRECTORY = 10; + + public static boolean attributeHasFileOrDirectoryType( + EditableAttributeDefinition attribute) { + return attributeHasFileType(attribute) || + attributeHasDirectoryType(attribute); + } + + public static boolean attributeHasFileType( + EditableAttributeDefinition attribute) { + String defaultValue = attribute.getActualDefaultValue(); + + if ((attribute.getType() == AttributeDefinition.STRING) && + defaultValue.equals(DEFAULT_FILE_VALUE)) { + return true; + } else { + return false; + } + } + + public static boolean attributeHasDirectoryType( + EditableAttributeDefinition attribute) { + String defaultValue = attribute.getActualDefaultValue(); + + if ((attribute.getType() == AttributeDefinition.STRING) && + defaultValue.equals(DEFAULT_DIRECTORY_VALUE)) { + return true; + } else { + return false; + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |