modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/DurationItem.java
| 286 +++++-----
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java
| 6
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/UnitType.java
| 9
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDataSource.java
| 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java
| 44 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleListView.java
| 1
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/schedule/GroupOperationScheduleDetailsView.java
| 5
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/operation/schedule/ResourceOperationScheduleDetailsView.java
| 11
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/TypeConversionUtility.java
| 26
9 files changed, 232 insertions(+), 158 deletions(-)
New commits:
commit aa921e544cbff948cb15809e8f4d9afd2fe91d26
Author: Ian Springer <ian.springer(a)redhat.com>
Date: Fri Feb 4 17:23:35 2011 -0500
finish DurationItem widget
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/DurationItem.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/DurationItem.java
index 5a06a57..e882254 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/DurationItem.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/DurationItem.java
@@ -25,20 +25,24 @@ package org.rhq.enterprise.gui.coregui.client.components.form;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.CanvasItem;
import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
+import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.IntegerItem;
+import com.smartgwt.client.widgets.form.fields.StaticTextItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.form.validator.IntegerRangeValidator;
import org.rhq.enterprise.gui.coregui.client.util.FormUtility;
+import org.rhq.enterprise.gui.coregui.client.util.TypeConversionUtility;
import org.rhq.enterprise.gui.coregui.client.util.selenium.Locatable;
+import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.Set;
import java.util.TreeSet;
/**
- * A form item for entering a time duration - consists of an IntegerItem for entering the
amount of time and a
- * ComboBoxItem for entering the time units.
+ * A form item for entering a duration - consists of an IntegerItem for entering the
amount of time and a
+ * ComboBoxItem for entering the duration units.
*
* @author Ian Springer
*/
@@ -48,116 +52,143 @@ public class DurationItem extends CanvasItem {
private static final String FIELD_UNITS = "units";
private final DynamicForm form;
- private TimeUnit defaultUnit;
- private String contextualHelp;
- private boolean supportsIterations;
+ private TimeUnit defaultTimeUnit;
+ private Set<UnitType> supportedUnitTypes;
private TimeUnit valueUnit;
private boolean isReadOnly;
+ private UnitType unitType;
- public DurationItem(String name, String title, Set<TimeUnit> supportedUnits,
boolean supportsIterations,
+ public DurationItem(String name, String title, TreeSet<TimeUnit>
supportedUnits, boolean supportsIterations,
boolean isReadOnly, Locatable parentWidget) {
super(name, title);
- this.supportsIterations = supportsIterations;
+ this.supportedUnitTypes = EnumSet.noneOf(UnitType.class);
+ if (supportedUnits != null && !supportedUnits.isEmpty()) {
+ this.supportedUnitTypes.add(UnitType.TIME);
+ this.valueUnit = supportedUnits.iterator().next();
+ }
+ if (supportsIterations) {
+ this.supportedUnitTypes.add(UnitType.ITERATIONS);
+ }
+
this.isReadOnly = isReadOnly;
this.form = new EnhancedDynamicForm(parentWidget.extendLocatorId(name), false,
false);
- this.form.setNumCols(4);
- this.form.setColWidths("140", "90", "105",
"*");
-
- final IntegerItem valueItem = new IntegerItem(FIELD_VALUE, title);
- valueItem.setShowTitle(getShowTitle());
- valueItem.setValue(getValue());
- IntegerRangeValidator integerRangeValidator = new IntegerRangeValidator();
- integerRangeValidator.setMin(1);
- valueItem.setValidators(integerRangeValidator);
- valueItem.setValidateOnChange(getValidateOnChange());
- valueItem.setValidateOnExit(getValidateOnExit());
-
- valueItem.addChangedHandler(new ChangedHandler() {
- public void onChanged(ChangedEvent event) {
- updateValue();
- }
- });
- ComboBoxItem unitsItem = new ComboBoxItem(FIELD_UNITS);
- unitsItem.setShowTitle(false);
+ if (this.isReadOnly) {
+ this.form.setNumCols(2);
+ this.form.setColWidths("140", "160");
- // TODO: i18n valueMap values
- LinkedHashMap<String, String> valueMap = new LinkedHashMap<String,
String>();
- if (supportsIterations) {
- valueMap.put("times", "times");
- }
- if (supportedUnits != null && !supportedUnits.isEmpty()) {
- TreeSet<TimeUnit> sortedSupportedUnits = new
TreeSet<TimeUnit>(supportedUnits);
- for (TimeUnit unit : sortedSupportedUnits) {
- valueMap.put(unit.name().toLowerCase(), unit.name().toLowerCase());
- }
- this.valueUnit = sortedSupportedUnits.iterator().next();
- unitsItem.setValueMap(valueMap);
- }
+ StaticTextItem staticTextItem = new StaticTextItem(FIELD_VALUE, title);
+ staticTextItem.setShowTitle(getShowTitle());
- if (this.defaultUnit != null) {
- unitsItem.setDefaultValue(this.defaultUnit.name().toLowerCase());
+ this.form.setFields(staticTextItem);
} else {
- unitsItem.setDefaultToFirstOption(true);
- }
+ this.form.setNumCols(4);
+ this.form.setColWidths("140", "90", "105",
"*");
+
+ final IntegerItem valueItem = new IntegerItem(FIELD_VALUE, title);
+ valueItem.setShowTitle(getShowTitle());
+ valueItem.setValue(getValue());
+ IntegerRangeValidator integerRangeValidator = new IntegerRangeValidator();
+ integerRangeValidator.setMin(1);
+ valueItem.setValidators(integerRangeValidator);
+ valueItem.setValidateOnChange(getValidateOnChange());
+ valueItem.setValidateOnExit(getValidateOnExit());
+
+ valueItem.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ updateValue();
+ }
+ });
- if (this.contextualHelp != null) {
- FormUtility.addContextualHelp(unitsItem, this.contextualHelp);
- }
+ ComboBoxItem unitsItem = new ComboBoxItem(FIELD_UNITS);
+ unitsItem.setShowTitle(false);
+
+ // TODO: i18n valueMap values
+ LinkedHashMap<String, String> valueMap = new LinkedHashMap<String,
String>();
+ if (this.supportedUnitTypes.contains(UnitType.ITERATIONS)) {
+ valueMap.put("times", "times");
+ }
+ if (this.supportedUnitTypes.contains(UnitType.TIME)) {
+ for (TimeUnit unit : supportedUnits) {
+ valueMap.put(unit.name().toLowerCase(), unit.name().toLowerCase());
+ }
+ }
+ unitsItem.setValueMap(valueMap);
- unitsItem.addChangedHandler(new ChangedHandler() {
- public void onChanged(ChangedEvent event) {
- updateValue();
+ if (this.defaultTimeUnit != null) {
+ unitsItem.setDefaultValue(this.defaultTimeUnit.name().toLowerCase());
+ } else {
+ unitsItem.setDefaultToFirstOption(true);
}
- });
- this.form.setFields(valueItem, unitsItem);
- valueItem.setWidth(90);
- unitsItem.setWidth(105);
+ unitsItem.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ updateValue();
+ }
+ });
+
+ this.form.setFields(valueItem, unitsItem);
+ valueItem.setWidth(90);
+ unitsItem.setWidth(105);
+ }
setCanvas(this.form);
}
- public void setValue(Object value) {
- Integer intValue;
- if (value instanceof String) {
- intValue = Integer.valueOf((String)value);
- } else if (value instanceof Integer) {
- intValue = (Integer) value;
- } else {
- intValue = null;
+ public void setValue(Integer value, UnitType unitType) {
+ if (!this.supportedUnitTypes.contains(unitType)) {
+ throw new IllegalArgumentException("Unit type [" + unitType +
"] is not supported by this DurationItem.");
+ }
+ this.unitType = unitType;
+
+ String unitString = null;
+ switch (unitType) {
+ case TIME:
+ unitString = this.valueUnit.name().toLowerCase();
+ break;
+ case ITERATIONS:
+ unitString = "times";
}
- if (intValue != null) {
- this.form.setValue(FIELD_VALUE, intValue);
+ if (this.isReadOnly) {
+ String stringValue;
+ if (value == null) {
+ stringValue = "";
+ } else {
+ stringValue = value + " " + unitString;
+ }
+ this.form.setValue(FIELD_VALUE, stringValue);
} else {
- this.form.setValue(FIELD_VALUE, (String)null);
+ if (value != null) {
+ this.form.setValue(FIELD_VALUE, value);
+ } else {
+ this.form.setValue(FIELD_VALUE, (String)null);
+ }
+ this.form.setValue(FIELD_UNITS, unitString);
}
- super.setValue(value);
+ setValue(value);
}
private void updateValue() {
- Integer convertedValue = null;
+ Integer value = calculateValue();
+ setValue(value);
+ }
+ private Integer calculateValue() {
IntegerItem valueItem = (IntegerItem) this.form.getItem(FIELD_VALUE);
Object value = valueItem.getValue();
- Integer intValue;
- if (value instanceof String) {
- intValue = Integer.valueOf((String)value);
- } else if (value instanceof Integer) {
- intValue = (Integer) value;
- } else {
- intValue = null;
- }
-
- if (intValue != null) {
+ Integer integerValue = TypeConversionUtility.toInteger(value);
+ Integer convertedValue = null;
+ if (integerValue != null) {
TimeUnit unit = getInputTimeUnit();
if (unit == null) {
- convertedValue = intValue;
+ this.unitType = UnitType.ITERATIONS;
+ convertedValue = integerValue;
} else {
+ this.unitType = UnitType.TIME;
if (unit.compareTo(this.valueUnit) < 0) {
throw new IllegalStateException("Input unit is less than target
unit.");
}
@@ -165,148 +196,147 @@ public class DurationItem extends CanvasItem {
case MILLISECONDS:
switch (this.valueUnit) {
case MILLISECONDS:
- convertedValue = intValue;
+ convertedValue = integerValue;
break;
}
break;
case SECONDS:
switch (this.valueUnit) {
case SECONDS:
- convertedValue = intValue;
+ convertedValue = integerValue;
break;
case MILLISECONDS:
- convertedValue = intValue * 1000;
+ convertedValue = integerValue * 1000;
break;
}
break;
case MINUTES:
switch (this.valueUnit) {
case MINUTES:
- convertedValue = intValue;
+ convertedValue = integerValue;
break;
case SECONDS:
- convertedValue = intValue * 60;
+ convertedValue = integerValue * 60;
break;
case MILLISECONDS:
- convertedValue = intValue * 60 * 1000;
+ convertedValue = integerValue * 60 * 1000;
break;
}
break;
case HOURS:
switch (this.valueUnit) {
case HOURS:
- convertedValue = intValue;
+ convertedValue = integerValue;
break;
case MINUTES:
- convertedValue = intValue * 60;
+ convertedValue = integerValue * 60;
break;
case SECONDS:
- convertedValue = intValue * 60 * 60;
+ convertedValue = integerValue * 60 * 60;
break;
case MILLISECONDS:
- convertedValue = intValue * 60 * 60 * 1000;
+ convertedValue = integerValue * 60 * 60 * 1000;
break;
}
break;
case DAYS:
switch (this.valueUnit) {
case DAYS:
- convertedValue = intValue;
+ convertedValue = integerValue;
break;
case HOURS:
- convertedValue = intValue * 24;
+ convertedValue = integerValue * 24;
break;
case MINUTES:
- convertedValue = intValue * 24 * 60;
+ convertedValue = integerValue * 24 * 60;
break;
case SECONDS:
- convertedValue = intValue * 24 * 60 * 60;
+ convertedValue = integerValue * 24 * 60 * 60;
break;
case MILLISECONDS:
- convertedValue = intValue * 24 * 60 * 60 * 1000;
+ convertedValue = integerValue * 24 * 60 * 60 * 1000;
break;
}
break;
case WEEKS:
switch (this.valueUnit) {
case WEEKS:
- convertedValue = intValue;
+ convertedValue = integerValue;
break;
case DAYS:
- convertedValue = intValue * 7;
+ convertedValue = integerValue * 7;
break;
case HOURS:
- convertedValue = intValue * 7 * 24;
+ convertedValue = integerValue * 7 * 24;
break;
case MINUTES:
- convertedValue = intValue * 7 * 24 * 60;
+ convertedValue = integerValue * 7 * 24 * 60;
break;
case SECONDS:
- convertedValue = intValue * 7 * 24 * 60 * 60;
+ convertedValue = integerValue * 7 * 24 * 60 * 60;
break;
case MILLISECONDS:
- convertedValue = intValue * 7 * 24 * 60 * 60 * 1000;
+ convertedValue = integerValue * 7 * 24 * 60 * 60 * 1000;
break;
}
break;
case MONTHS:
switch (this.valueUnit) {
case MONTHS:
- convertedValue = intValue;
+ convertedValue = integerValue;
break;
case WEEKS:
- convertedValue = intValue * 4;
+ convertedValue = integerValue * 4;
break;
case DAYS:
- convertedValue = intValue * 30;
+ convertedValue = integerValue * 30;
break;
case HOURS:
- convertedValue = intValue * 30 * 24;
+ convertedValue = integerValue * 30 * 24;
break;
case MINUTES:
- convertedValue = intValue * 30 * 24 * 60;
+ convertedValue = integerValue * 30 * 24 * 60;
break;
case SECONDS:
- convertedValue = intValue * 30 * 24 * 60 * 60;
+ convertedValue = integerValue * 30 * 24 * 60 * 60;
break;
case MILLISECONDS:
- convertedValue = intValue * 30 * 24 * 60 * 60 * 1000;
+ convertedValue = integerValue * 30 * 24 * 60 * 60 *
1000;
break;
}
break;
case YEARS:
switch (this.valueUnit) {
case YEARS:
- convertedValue = intValue;
+ convertedValue = integerValue;
break;
case MONTHS:
- convertedValue = intValue * 12;
+ convertedValue = integerValue * 12;
break;
case WEEKS:
- convertedValue = intValue * 52;
+ convertedValue = integerValue * 52;
break;
case DAYS:
- convertedValue = intValue * 365;
+ convertedValue = integerValue * 365;
break;
case HOURS:
- convertedValue = intValue * 365 * 24;
+ convertedValue = integerValue * 365 * 24;
break;
case MINUTES:
- convertedValue = intValue * 365 * 24 * 60;
+ convertedValue = integerValue * 365 * 24 * 60;
break;
case SECONDS:
- convertedValue = intValue * 365 * 24 * 60 * 60;
+ convertedValue = integerValue * 365 * 24 * 60 * 60;
break;
case MILLISECONDS:
- convertedValue = intValue * 365 * 24 * 60 * 60 * 1000;
+ convertedValue = integerValue * 365 * 24 * 60 * 60 *
1000;
break;
}
break;
}
}
}
-
- super.setValue(convertedValue);
+ return convertedValue;
}
private TimeUnit getInputTimeUnit() {
@@ -322,6 +352,10 @@ public class DurationItem extends CanvasItem {
return unit;
}
+ public UnitType getUnitType() {
+ return unitType;
+ }
+
public Integer getValueAsInteger() {
return (Integer) getValue();
}
@@ -331,20 +365,28 @@ public class DurationItem extends CanvasItem {
return this.form.validate();
}
- public void setDefaultUnit(TimeUnit defaultUnit) {
- this.defaultUnit = defaultUnit;
+ public void setDefaultTimeUnit(TimeUnit defaultTimeUnit) {
+ this.defaultTimeUnit = defaultTimeUnit;
}
public void setContextualHelp(String contextualHelp) {
- this.contextualHelp = contextualHelp;
+ if (contextualHelp != null) {
+ FormItem item;
+ if (this.isReadOnly) {
+ item = this.form.getItem(FIELD_VALUE);
+ } else {
+ item = this.form.getItem(FIELD_UNITS);
+ }
+ FormUtility.addContextualHelp(item, contextualHelp);
+ }
}
/**
- * Returns the time unit of this item's {@link #getValue() value} - if null, the
item's value represents an iteration
- * count, not a time duration.
+ * If this item's {@link #getValue() value} represents a time duration, returns
the value's time unit; otherwise
+ * returns null.
*
- * @return the time unit of this item's {@link #getValue() value} - if null, the
item's value represents an iteration
- * count, not a time duration
+ * @return if this item's {@link #getValue() value} represents a time duration,
returns the value's time unit; otherwise
+ * returns null
*/
public TimeUnit getValueUnit() {
return this.valueUnit;
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java
index 27df563..7f01d38 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java
@@ -101,7 +101,7 @@ public class EnhancedDynamicForm extends LocatableDynamicForm {
hasIdField = true;
}
if (this.isReadOnly) {
- if ((item instanceof StaticTextItem) || (item instanceof CanvasItem
&& !(item instanceof DurationItem))) {
+ if ((item instanceof StaticTextItem) || (item instanceof CanvasItem)) {
// note: EditableFormItem is a subclass of CanvasItem
if (item instanceof EditableFormItem) {
((EditableFormItem) item).setReadOnly(true);
@@ -110,8 +110,7 @@ public class EnhancedDynamicForm extends LocatableDynamicForm {
} else {
StaticTextItem staticItem = new StaticTextItem(item.getName(),
item.getTitle());
staticItem.setTooltip(item.getTooltip());
- Object value = (item instanceof DurationItem) ? item.toString() :
item.getValue();
- staticItem.setValue(value);
+ staticItem.setValue(item.getValue());
staticItem.setColSpan(item.getAttribute("colSpan"));
// TODO: Any other fields we should copy? icons?
@@ -153,4 +152,5 @@ public class EnhancedDynamicForm extends LocatableDynamicForm {
public boolean isReadOnly() {
return isReadOnly;
}
+
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/UnitType.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/UnitType.java
new file mode 100644
index 0000000..2731c52
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/UnitType.java
@@ -0,0 +1,9 @@
+package org.rhq.enterprise.gui.coregui.client.components.form;
+
+/**
+ * @author Ian Springer
+ */
+public enum UnitType {
+ TIME,
+ ITERATIONS
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDataSource.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDataSource.java
index f927030..07d90e3 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDataSource.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDataSource.java
@@ -90,7 +90,7 @@ public abstract class AbstractOperationScheduleDataSource<T extends
OperationSch
idField.setCanEdit(false);
fields.add(idField);
- DataSourceTextField operationNameField = createTextField(Field.OPERATION_NAME,
"Operation Name", null, 100,
+ DataSourceTextField operationNameField = createTextField(Field.OPERATION_NAME,
"Operation", null, 100,
true);
fields.add(operationNameField);
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java
index 6f0162e..2801c7a 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java
@@ -22,10 +22,10 @@ package
org.rhq.enterprise.gui.coregui.client.inventory.common.detail.operation.
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeSet;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.Record;
@@ -52,9 +52,11 @@ import
org.rhq.enterprise.gui.coregui.client.components.form.AbstractRecordEdito
import org.rhq.enterprise.gui.coregui.client.components.form.DurationItem;
import org.rhq.enterprise.gui.coregui.client.components.form.EnhancedDynamicForm;
import org.rhq.enterprise.gui.coregui.client.components.form.TimeUnit;
+import org.rhq.enterprise.gui.coregui.client.components.form.UnitType;
import org.rhq.enterprise.gui.coregui.client.components.trigger.JobTriggerEditor;
import
org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.operation.schedule.ResourceOperationScheduleDataSource;
import org.rhq.enterprise.gui.coregui.client.util.FormUtility;
+import org.rhq.enterprise.gui.coregui.client.util.TypeConversionUtility;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
@@ -88,12 +90,14 @@ public abstract class AbstractOperationScheduleDetailsView extends
AbstractRecor
}
}
+ protected abstract boolean hasControlPermission();
+
@Override
public void renderView(ViewPath viewPath) {
super.renderView(viewPath);
// Existing schedules are not editable. This may change in the future.
- boolean isReadOnly = (getRecordId() != 0);
+ boolean isReadOnly = (!hasControlPermission() || (getRecordId() != 0));
init(isReadOnly);
}
@@ -112,11 +116,11 @@ public abstract class AbstractOperationScheduleDetailsView extends
AbstractRecor
List<FormItem> items = new ArrayList<FormItem>();
if (!isNewRecord()) {
- StaticTextItem idItem = new
StaticTextItem(ResourceOperationScheduleDataSource.Field.ID);
+ StaticTextItem idItem = new
StaticTextItem(AbstractOperationScheduleDataSource.Field.ID);
items.add(idItem);
}
- SelectItem operationNameItem = new
SelectItem(ResourceOperationScheduleDataSource.Field.OPERATION_NAME, "Name");
+ SelectItem operationNameItem = new
SelectItem(AbstractOperationScheduleDataSource.Field.OPERATION_NAME);
items.add(operationNameItem);
operationNameItem.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
@@ -154,41 +158,19 @@ public abstract class AbstractOperationScheduleDetailsView extends
AbstractRecor
contentPane.addMember(hr);
}
- /*this.timeoutForm = new
EnhancedDynamicForm(extendLocatorId("TimeoutForm"), isReadOnly(),
isNewRecord());
- this.timeoutForm.setNumCols(4);
- this.timeoutForm.setColWidths("140", "90", "105",
"*");
-
- IntegerItem timeoutItem = new IntegerItem("timeoutValue",
"Timeout");
- IntegerRangeValidator integerRangeValidator = new IntegerRangeValidator();
- integerRangeValidator.setMin(1);
- timeoutItem.setValidators(integerRangeValidator);
- ComboBoxItem timeoutUnitsItem = new ComboBoxItem("timeoutUnits");
- timeoutUnitsItem.setShowTitle(false);
- LinkedHashMap<String, String> valueMap = new LinkedHashMap<String,
String>(3);
- valueMap.put("seconds", "seconds");
- valueMap.put("minutes", "minutes");
- valueMap.put("hours", "hours");
- timeoutUnitsItem.setValueMap(valueMap);
- timeoutUnitsItem.setDefaultValue("minutes");
- FormUtility.addContextualHelp(timeoutUnitsItem, "a time duration - if
specified, if the duration elapses before a scheduled operation execution has completed,
the RHQ Server will timeout the operation and consider it to have failed; note, it is
usually not possible to abort the underlying managed resource operation if it was
initiated");
- this.timeoutForm.setFields(timeoutItem, timeoutUnitsItem);
- timeoutItem.setWidth(90);
- timeoutUnitsItem.setWidth(105);
- contentPane.addMember(this.timeoutForm);
- */
-
this.notesForm = new EnhancedDynamicForm(extendLocatorId("NotesForm"),
isReadOnly(),
isNewRecord());
this.notesForm.setColWidths("140", "50%", "140",
"50%");
List<FormItem> notesFields = new ArrayList<FormItem>();
- Set<TimeUnit> supportedUnits = new HashSet<TimeUnit>(3);
+ TreeSet<TimeUnit> supportedUnits = new TreeSet<TimeUnit>();
supportedUnits.add(TimeUnit.SECONDS);
supportedUnits.add(TimeUnit.MINUTES);
supportedUnits.add(TimeUnit.HOURS);
DurationItem timeoutItem = new
DurationItem(AbstractOperationScheduleDataSource.Field.TIMEOUT, "Timeout",
supportedUnits, false, isReadOnly(), this.notesForm);
+ timeoutItem.setContextualHelp("a time duration - if specified, if the
duration elapses before a scheduled operation execution has completed, the RHQ Server will
timeout the operation and consider it to have failed; note, it is usually not possible to
abort the underlying managed resource operation if it was already initiated");
notesFields.add(timeoutItem);
if (!isNewRecord()) {
@@ -245,8 +227,10 @@ public abstract class AbstractOperationScheduleDetailsView extends
AbstractRecor
FormItem nextFireTimeItem =
this.notesForm.getField(ResourceOperationScheduleDataSource.Field.NEXT_FIRE_TIME);
nextFireTimeItem.setValue(getForm().getValue(ResourceOperationScheduleDataSource.Field.NEXT_FIRE_TIME));
- FormItem timeoutItem =
this.notesForm.getField(AbstractOperationScheduleDataSource.Field.TIMEOUT);
-
timeoutItem.setValue(getForm().getValue(AbstractOperationScheduleDataSource.Field.TIMEOUT));
+ DurationItem timeoutItem = (DurationItem)
this.notesForm.getField(AbstractOperationScheduleDataSource.Field.TIMEOUT);
+ Object value =
getForm().getValue(AbstractOperationScheduleDataSource.Field.TIMEOUT);
+ Integer integerValue = TypeConversionUtility.toInteger(value);
+ timeoutItem.setValue(integerValue, UnitType.TIME);
FormItem notesItem =
this.notesForm.getField(ResourceOperationScheduleDataSource.Field.DESCRIPTION);
notesItem.setValue(getForm().getValue(ResourceOperationScheduleDataSource.Field.DESCRIPTION));
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleListView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleListView.java
index 59f58e6..152260f 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleListView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleListView.java
@@ -39,7 +39,6 @@ public abstract class AbstractOperationScheduleListView extends
TableSection<Abs
protected abstract boolean hasControlPermission();
-
@Override
protected void configureTable() {
super.configureTable();
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/schedule/GroupOperationScheduleDetailsView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/schedule/GroupOperationScheduleDetailsView.java
index a397553..23db066 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/schedule/GroupOperationScheduleDetailsView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/schedule/GroupOperationScheduleDetailsView.java
@@ -40,6 +40,11 @@ public class GroupOperationScheduleDetailsView extends
AbstractOperationSchedule
}
@Override
+ protected boolean hasControlPermission() {
+ return this.groupComposite.getResourcePermission().isControl();
+ }
+
+ @Override
protected void init(final boolean isReadOnly) {
if (isNewRecord()) {
ResourceDatasource resourceDatasource = new ResourceDatasource();
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/operation/schedule/ResourceOperationScheduleDetailsView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/operation/schedule/ResourceOperationScheduleDetailsView.java
index 483f97d..22d89dd 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/operation/schedule/ResourceOperationScheduleDetailsView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/operation/schedule/ResourceOperationScheduleDetailsView.java
@@ -4,13 +4,22 @@ import org.rhq.core.domain.resource.composite.ResourceComposite;
import
org.rhq.enterprise.gui.coregui.client.inventory.common.detail.operation.schedule.AbstractOperationScheduleDetailsView;
/**
- *
+ * @author Ian Springer
*/
public class ResourceOperationScheduleDetailsView extends
AbstractOperationScheduleDetailsView {
+ private ResourceComposite resourceComposite;
+
public ResourceOperationScheduleDetailsView(String locatorId, ResourceComposite
resourceComposite, int scheduleId) {
super(locatorId, new ResourceOperationScheduleDataSource(resourceComposite),
resourceComposite.getResource().getResourceType(), scheduleId);
+
+ this.resourceComposite = resourceComposite;
+ }
+
+ @Override
+ protected boolean hasControlPermission() {
+ return this.resourceComposite.getResourcePermission().isControl();
}
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/TypeConversionUtility.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/TypeConversionUtility.java
new file mode 100644
index 0000000..ac6d6ae
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/TypeConversionUtility.java
@@ -0,0 +1,26 @@
+package org.rhq.enterprise.gui.coregui.client.util;
+
+/**
+ * @author Ian Springer
+ */
+public class TypeConversionUtility {
+
+ private TypeConversionUtility() {
+ }
+
+ public static Integer toInteger(Object object) {
+ Integer integer;
+ if (object instanceof String) {
+ integer = Integer.valueOf((String)object);
+ } else if (object instanceof Number) {
+ integer = ((Number) object).intValue();
+ } else if (object == null) {
+ integer = null;
+ } else {
+ throw new IllegalArgumentException("Failed to convert " +
object.getClass().getName() + " [" + object
+ + "] to an Integer.");
+ }
+ return integer;
+ }
+
+}