modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractNotificationSenderForm.java | 10 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceOperationNotificationSenderForm.java | 154 +++++++--- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java | 12 3 files changed, 142 insertions(+), 34 deletions(-)
New commits: commit 1f713565d0b0e03aa9347138bab1ec08fb8602a6 Author: John Mazzitelli mazz@redhat.com Date: Mon Oct 11 13:46:14 2010 -0400
properly validate the specific resource picker form item
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceOperationNotificationSenderForm.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceOperationNotificationSenderForm.java index 3fda778..f60cd9e 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceOperationNotificationSenderForm.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceOperationNotificationSenderForm.java @@ -317,6 +317,7 @@ public class ResourceOperationNotificationSenderForm extends AbstractNotificatio hideOperationArguments(); selectOperation(Integer.valueOf(operationSelectItem.getValue().toString())); } + singleResourceTextItem.validate(); // makes sure a resource with ops is selected otherwise a validation error shows operationSelectItem.show(); markForRedraw(); } else { @@ -373,6 +374,8 @@ public class ResourceOperationNotificationSenderForm extends AbstractNotificatio operationSelectItem.setValueMap(valueMap); operationSelectItem.hide(); hideOperationArguments(); + + singleResourceTextItem.validate(); // makes sure a resource with ops is selected otherwise a validation error shows }
private void hideOperationArguments() { @@ -485,18 +488,26 @@ public class ResourceOperationNotificationSenderForm extends AbstractNotificatio }
private class ResourceIdValidator extends CustomValidator { - private final StaticTextItem idTextItem; + private final FormItem idItem;
- public ResourceIdValidator(StaticTextItem idTextItem) { - this.idTextItem = idTextItem; + public ResourceIdValidator(FormItem idItem) { + this.idItem = idItem; }
+ @SuppressWarnings("unchecked") @Override protected boolean condition(Object value) { - Integer id = Integer.valueOf(idTextItem.getAttributeAsInt(RESOURCE_ID_ATTRIBUTE)); + Integer id = Integer.valueOf(idItem.getAttributeAsInt(RESOURCE_ID_ATTRIBUTE)); boolean valid = (id != null && id.intValue() != 0); if (!valid) { setErrorMessage("Please pick a resource"); + } else { + LinkedHashMap<Integer, OperationDefinition> ops = (LinkedHashMap<Integer, OperationDefinition>) operationSelectItem + .getAttributeAsObject(OPERATION_DEFS_ATTRIBUTE); + if (ops == null || ops.isEmpty()) { + valid = false; + setErrorMessage("Please pick a resource that has one or more operations"); + } } return valid; }
commit 9fbab172a12b874d13ba56d21c1dcf8d4fff834c Author: John Mazzitelli mazz@redhat.com Date: Mon Oct 11 13:45:47 2010 -0400
disable row selections if the disable override is set
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java index c573007..fe69ec7 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java @@ -195,7 +195,7 @@ public class Table extends LocatableHLayout implements RefreshableView { listGrid.setHeight100(); listGrid.setAlternateRecordStyles(true); listGrid.setResizeFieldsInRealTime(false); - listGrid.setSelectionType(SelectionStyle.SIMPLE); + listGrid.setSelectionType(getDefaultSelectionStyle());
if (flexRowDisplay) { listGrid.setAutoFitData(Autofit.HORIZONTAL); @@ -224,6 +224,10 @@ public class Table extends LocatableHLayout implements RefreshableView { contents.addMember(listGrid); }
+ protected SelectionStyle getDefaultSelectionStyle() { + return SelectionStyle.SIMPLE; + } + @Override protected void onDraw() { try { @@ -539,6 +543,12 @@ public class Table extends LocatableHLayout implements RefreshableView {
protected void refreshTableInfo() { if (showFooter) { + if (this.tableActionDisableOverride) { + this.listGrid.setSelectionType(SelectionStyle.NONE); + } else { + this.listGrid.setSelectionType(getDefaultSelectionStyle()); + } + int count = this.listGrid.getSelection().length; for (TableActionInfo tableAction : tableActions) { if (tableAction.actionButton != null) { // if null, we haven't initialized our buttons yet, so skip this
commit b2952714eca5432433a41ef8b934a5663008fbf8 Author: John Mazzitelli mazz@redhat.com Date: Mon Oct 11 12:54:07 2010 -0400
saves resource operation notif defs for SELF and SPECIFIC.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractNotificationSenderForm.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractNotificationSenderForm.java index 0dabe26..5b68ee4 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractNotificationSenderForm.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractNotificationSenderForm.java @@ -87,6 +87,10 @@ public abstract class AbstractNotificationSenderForm extends LocatableVLayout { this.configuration = configuration; }
+ public void cleanConfiguration() { + this.configuration.getMap().clear(); + } + /** * The {@link AlertNotification#getExtraConfiguration()} for the new alert definition notification. * @@ -100,5 +104,11 @@ public abstract class AbstractNotificationSenderForm extends LocatableVLayout { this.extraConfiguration = extraConfiguration; }
+ public void cleanExtraConfiguration() { + if (this.extraConfiguration != null) { + this.extraConfiguration.getMap().clear(); + } + } + public abstract boolean validate(); } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceOperationNotificationSenderForm.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceOperationNotificationSenderForm.java index cd50d2c..3fda778 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceOperationNotificationSenderForm.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceOperationNotificationSenderForm.java @@ -28,12 +28,12 @@ import java.util.LinkedHashMap; import java.util.Set;
import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.types.Overflow; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.FormItemIfFunction; import com.smartgwt.client.widgets.form.fields.ButtonItem; -import com.smartgwt.client.widgets.form.fields.CanvasItem; import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.form.fields.StaticTextItem; @@ -41,9 +41,12 @@ import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; import com.smartgwt.client.widgets.form.fields.events.ClickEvent; import com.smartgwt.client.widgets.form.fields.events.ClickHandler; +import com.smartgwt.client.widgets.form.validator.CustomValidator; +import com.smartgwt.client.widgets.layout.HLayout;
import org.rhq.core.domain.alert.notification.AlertNotification; import org.rhq.core.domain.configuration.Configuration; +import org.rhq.core.domain.configuration.PropertySimple; import org.rhq.core.domain.configuration.definition.ConfigurationDefinition; import org.rhq.core.domain.criteria.ResourceCriteria; import org.rhq.core.domain.criteria.ResourceTypeCriteria; @@ -58,6 +61,7 @@ import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; import org.rhq.enterprise.gui.coregui.client.inventory.resource.selection.SingleResourcePicker; import org.rhq.enterprise.gui.coregui.client.inventory.resource.selection.ResourcePicker.OkHandler; import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout;
/** * This notification form will be used for the Resource Operation sender. This form lets @@ -73,9 +77,10 @@ public class ResourceOperationNotificationSenderForm extends AbstractNotificatio private final ResourceType resourceType; // the type representing the current resource or the current type being edited
private LocatableDynamicForm dynamicForm; + private SelectItem modeSelectItem; private StaticTextItem singleResourceTextItem; private SelectItem ancestorTypeSelectItem; - private CanvasItem operationArgumentsCanvasItem; + private HLayout operationArgumentsCanvasItem; private SelectItem operationSelectItem;
public ResourceOperationNotificationSenderForm(String locatorId, AlertNotification notif, String sender, @@ -92,14 +97,10 @@ public class ResourceOperationNotificationSenderForm extends AbstractNotificatio dynamicForm = new LocatableDynamicForm(extendLocatorId("resOpForm")); dynamicForm.setNumCols(3);
- operationArgumentsCanvasItem = new CanvasItem(); - operationArgumentsCanvasItem.setStartRow(true); - operationArgumentsCanvasItem.setEndRow(true); - operationArgumentsCanvasItem.setShowTitle(false); - operationArgumentsCanvasItem.setColSpan(3); - operationArgumentsCanvasItem.setCanvas(new Label()); - operationArgumentsCanvasItem.setWidth("*"); - operationArgumentsCanvasItem.setVisible(false); + operationArgumentsCanvasItem = new LocatableHLayout(extendLocatorId("opArgLayout")); + operationArgumentsCanvasItem.setOverflow(Overflow.VISIBLE); + operationArgumentsCanvasItem.setHeight(400); + operationArgumentsCanvasItem.setWidth(500);
operationSelectItem = new SelectItem("operationSelectItem", "Operation"); operationSelectItem.setStartRow(true); @@ -124,6 +125,7 @@ public class ResourceOperationNotificationSenderForm extends AbstractNotificatio singleResourceTextItem.setValue("Pick a resource..."); singleResourceTextItem.setShowIfCondition(new ShowIfModeFunction(ResourceSelectionMode.SPECIFIC)); singleResourceTextItem.setAttribute(RESOURCE_ID_ATTRIBUTE, 0); // we hide the resource ID in this attribute + singleResourceTextItem.setValidators(new ResourceIdValidator(singleResourceTextItem));
ButtonItem singleResourceButtonItem = new ButtonItem("singleResourceButtonItem", "Pick"); singleResourceButtonItem.setStartRow(false); @@ -159,7 +161,7 @@ public class ResourceOperationNotificationSenderForm extends AbstractNotificatio
// the mode selector menu
- SelectItem modeSelectItem = new SelectItem("modeSelectItem", "Resource Selection Mode"); + modeSelectItem = new SelectItem("modeSelectItem", "Resource Selection Mode"); modeSelectItem.setStartRow(true); modeSelectItem.setEndRow(true); modeSelectItem.setWrapTitle(false); @@ -194,9 +196,10 @@ public class ResourceOperationNotificationSenderForm extends AbstractNotificatio });
dynamicForm.setFields(modeSelectItem, singleResourceTextItem, singleResourceButtonItem, ancestorTypeSelectItem, - operationSelectItem, operationArgumentsCanvasItem); + operationSelectItem);
addMember(dynamicForm); + addMember(operationArgumentsCanvasItem);
// prepopulate the form ResourceOperationNotificationInfo notifInfo; @@ -222,7 +225,7 @@ public class ResourceOperationNotificationSenderForm extends AbstractNotificatio } } else { modeSelectItem.setValue(ResourceSelectionMode.SELF.name()); - setOperationDropDownMenuValues(resourceType.getId(), null, getExtraConfiguration()); + setOperationDropDownMenuValues(resourceType.getId(), null, null); } }
@@ -255,16 +258,16 @@ public class ResourceOperationNotificationSenderForm extends AbstractNotificatio ConfigurationDefinition paramDef = def.getParametersConfigurationDefinition(); if (paramDef != null) { Configuration extraConfig = getExtraConfiguration(); - if (extraConfig != null) { - extraConfig.getMap().clear(); // changing the op, the old props are no longer valid - } else { + if (extraConfig == null) { extraConfig = new Configuration(); setExtraConfiguration(extraConfig); + } else { + cleanExtraConfiguration(); } showOperationArguments(paramDef, extraConfig); } else { - setExtraConfiguration(null); - hideOperationArguments(); + cleanExtraConfiguration(); + showOperationArguments(null, null); } } else { hideOperationDropDownMenu(); @@ -306,7 +309,7 @@ public class ResourceOperationNotificationSenderForm extends AbstractNotificatio } operationSelectItem.setAttribute(OPERATION_DEFS_ATTRIBUTE, (Object) opDefs); operationSelectItem.setValueMap(valueMap); - if (opId != null && opId > 0 && valueMap.containsKey(opId)) { + if (opId != null && opId > 0 && opDefs.containsKey(opId)) { operationSelectItem.setValue(String.valueOf(opId)); showOperationArguments(opDefs.get(opId).getParametersConfigurationDefinition(), args); } else { @@ -373,39 +376,95 @@ public class ResourceOperationNotificationSenderForm extends AbstractNotificatio }
private void hideOperationArguments() { - Canvas canvas = operationArgumentsCanvasItem.getCanvas(); - if (canvas != null) { - canvas.destroy(); + Canvas[] canvii = operationArgumentsCanvasItem.getMembers(); + if (canvii != null) { + for (Canvas canvas : canvii) { + canvas.destroy(); + } } - - operationArgumentsCanvasItem.setCanvas(new Label("")); - operationArgumentsCanvasItem.hide(); markForRedraw(); }
private void showOperationArguments(ConfigurationDefinition def, Configuration config) { - Canvas canvas = operationArgumentsCanvasItem.getCanvas(); - if (canvas != null) { - canvas.destroy(); + Canvas[] canvii = operationArgumentsCanvasItem.getMembers(); + if (canvii != null) { + for (Canvas canvas : canvii) { + canvas.destroy(); + } }
if (def != null) { - canvas = new ConfigurationEditor(extendLocatorId("opArgs"), def, config); + ConfigurationEditor configEditor = new ConfigurationEditor(extendLocatorId("opArgs"), def, config); + operationArgumentsCanvasItem.addMember(configEditor); } else { Label l = new Label("This operation does not take any parameters"); l.setWrap(false); - canvas = l; + operationArgumentsCanvasItem.addMember(l); }
- operationArgumentsCanvasItem.setCanvas(canvas); - operationArgumentsCanvasItem.show(); markForRedraw(); }
+ private ConfigurationEditor getConfigurationEditor() { + Canvas[] canvii = operationArgumentsCanvasItem.getMembers(); + if (canvii != null) { + for (Canvas canvas : canvii) { + if (canvas instanceof ConfigurationEditor) { + return (ConfigurationEditor) canvas; + } + } + } + return null; + } + @Override public boolean validate() { try { - return true; + if (dynamicForm.validate(false)) { + // let's make sure the args can be validated successfully. + // If there is no config editor, there are no parameters for this operation + ConfigurationEditor configEditor = getConfigurationEditor(); + if (configEditor != null) { + if (!configEditor.validate()) { + return false; + } + // nothing else to store - our config editor directly edited our extraConfig already + } else { + setExtraConfiguration(null); + } + + // now fill in the configuration object with the information based on what was selected + String selectedModeString = modeSelectItem.getValue().toString(); + ResourceSelectionMode selectedMode = ResourceSelectionMode.valueOf(selectedModeString); + Configuration config = getConfiguration(); + config.put(new PropertySimple(ResourceOperationNotificationInfo.Constants.SELECTION_MODE + .getPropertyName(), selectedMode)); + switch (selectedMode) { + case SELF: { + // nothing extra needs to be done + break; + } + case SPECIFIC: { + int resourceId = singleResourceTextItem.getAttributeAsInt(RESOURCE_ID_ATTRIBUTE); + config.put(new PropertySimple(ResourceOperationNotificationInfo.Constants.SPECIFIC_RESOURCE_ID + .getPropertyName(), resourceId)); + break; + } + case RELATIVE: { + // TODO + break; + } + } + + // indicate which operation is to be invoked by storing the op ID in the config + String operationId = operationSelectItem.getValue().toString(); + config.put(new PropertySimple(ResourceOperationNotificationInfo.Constants.OPERATION_ID + .getPropertyName(), operationId)); + + return true; + } else { + return false; + } } catch (Exception e) { CoreGUI.getErrorHandler().handleError("Cannot save the notification configuration", e); return false; @@ -424,4 +483,22 @@ public class ResourceOperationNotificationSenderForm extends AbstractNotificatio return mode.name().equals(modeTypeString); } } + + private class ResourceIdValidator extends CustomValidator { + private final StaticTextItem idTextItem; + + public ResourceIdValidator(StaticTextItem idTextItem) { + this.idTextItem = idTextItem; + } + + @Override + protected boolean condition(Object value) { + Integer id = Integer.valueOf(idTextItem.getAttributeAsInt(RESOURCE_ID_ATTRIBUTE)); + boolean valid = (id != null && id.intValue() != 0); + if (!valid) { + setErrorMessage("Please pick a resource"); + } + return valid; + } + } }
rhq-commits@lists.fedorahosted.org