modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java | 39 +- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewNotificationEditor.java | 161 ++++++++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NotificationsAlertDefinitionForm.java | 133 ++++---- 3 files changed, 269 insertions(+), 64 deletions(-)
New commits: commit cf57ff1d2706723c74d1a66c914a69e4d68f0b91 Author: John Mazzitelli mazz@redhat.com Date: Thu Sep 30 14:48:49 2010 -0400
introduce the start of the new notification editor.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewNotificationEditor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewNotificationEditor.java new file mode 100644 index 0000000..1711bd5 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewNotificationEditor.java @@ -0,0 +1,161 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2010 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation, and/or the GNU Lesser + * General Public License, version 2.1, also as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.rhq.enterprise.gui.coregui.client.alert.definitions; + +import java.util.ArrayList; +import java.util.LinkedHashMap; + +import com.smartgwt.client.types.Alignment; +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.FormItem; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.SpacerItem; +import com.smartgwt.client.widgets.form.fields.events.ClickEvent; +import com.smartgwt.client.widgets.form.fields.events.ClickHandler; + +import org.rhq.core.domain.alert.AlertDefinition; +import org.rhq.core.domain.alert.notification.AlertNotification; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm; + +/** + * @author John Mazzitelli + */ +public class NewNotificationEditor extends LocatableDynamicForm { + + private final AlertDefinition alertDefinition; // the definition we are adding the notification to + private final ArrayList<AlertNotification> notifications; // if we are creating a new notification, it gets added to this list + private final AlertNotification notificationToEdit; // the notification that this editor is editing (may be null) + private final Runnable closeFunction; // this is called after a button is pressed and the editor should close + + private SelectItem notificationSenderSelectItem; + + public NewNotificationEditor(String locatorId, AlertDefinition alertDefinition, + ArrayList<AlertNotification> notifs, AlertNotification notifToEdit, Runnable closeFunc) { + + super(locatorId); + this.alertDefinition = alertDefinition; + this.notifications = notifs; + this.notificationToEdit = notifToEdit; + this.closeFunction = closeFunc; + } + + @Override + protected void onInit() { + super.onInit(); + + setMargin(20); + + notificationSenderSelectItem = new SelectItem("notificationSender", "Notification Sender"); + + LinkedHashMap<String, String> senders = new LinkedHashMap<String, String>(); + if (notificationToEdit != null) { + // we were given a notification to edit, you can't change the sender type, its the only option + senders.put(notificationToEdit.getSenderName(), notificationToEdit.getSenderName()); + notificationSenderSelectItem.setDisabled(true); + } else { + // we are creating a new notification, need to provide all senders as options + senders.put("System Users", "System Users"); + senders.put("dummySender", "Dummy Sender"); + } + + notificationSenderSelectItem.setValueMap(senders); + notificationSenderSelectItem.setDefaultToFirstOption(true); + notificationSenderSelectItem.setWrapTitle(false); + notificationSenderSelectItem.setRedrawOnChange(true); + notificationSenderSelectItem.setWidth("*"); + + SpacerItem spacer1 = new SpacerItem(); + spacer1.setColSpan(2); + spacer1.setHeight(5); + + SpacerItem spacer2 = new SpacerItem(); + spacer2.setColSpan(2); + spacer2.setHeight(5); + + ButtonItem ok = new ButtonItem("okButtonItem", "OK"); + ok.setEndRow(false); + ok.setAlign(Alignment.RIGHT); + ok.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + if (validate(false)) { + saveNewNotification(); + closeFunction.run(); + } + } + }); + + ButtonItem cancel = new ButtonItem("cancelButtonItem", "Cancel"); + cancel.setStartRow(false); + cancel.setAlign(Alignment.LEFT); + cancel.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + closeFunction.run(); + } + }); + + ArrayList<FormItem> formItems = new ArrayList<FormItem>(); + formItems.add(notificationSenderSelectItem); + formItems.add(spacer1); + // TODO put config editor here + formItems.add(spacer2); + formItems.add(ok); + formItems.add(cancel); + + setFields(formItems.toArray(new FormItem[formItems.size()])); + }; + + private void saveNewNotification() { + AlertNotification notif; + + if (notificationToEdit == null) { + // we are adding a new notification - we just add it to the end of the list + String selectedSender = notificationSenderSelectItem.getValue().toString(); + notif = new AlertNotification(selectedSender); + notif.setAlertDefinition(alertDefinition); + notifications.add(notif); + } else { + notif = notificationToEdit; + } + + // notif.setConfiguration(configuration); + // notif.setExtraConfiguration(extraConfiguration); + } + + private class ShowIfSenderFunction implements FormItemIfFunction { + private final String senderName; + + public ShowIfSenderFunction(String senderName) { + this.senderName = senderName; + } + + public boolean execute(FormItem item, Object value, DynamicForm form) { + String selectedSenderString = form.getValue("notificationSender").toString(); + return senderName.equals(selectedSenderString); + } + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NotificationsAlertDefinitionForm.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NotificationsAlertDefinitionForm.java index b8e4644..bc585ac 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NotificationsAlertDefinitionForm.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NotificationsAlertDefinitionForm.java @@ -123,6 +123,11 @@ public class NotificationsAlertDefinitionForm extends LocatableVLayout implement
@Override public void saveAlertDefinition() { + if (notifications != null && notifications.size() > 0) { + for (AlertNotification notif : notifications) { + notif.setAlertDefinition(alertDefinition); + } + } alertDefinition.setAlertNotifications(notifications);
// make our own new internal copy since we gave ours to the definition object @@ -184,7 +189,6 @@ public class NotificationsAlertDefinitionForm extends LocatableVLayout implement record.setAttribute(FIELD_SENDER, from.getSenderName()); // our executeFetch will fill in the real value for FIELD_CONFIGURATION record.setAttribute(FIELD_CONFIGURATION, "(unknown)"); - // TODO what's the extraConfiguration the notification? return record; }
@@ -290,15 +294,15 @@ public class NotificationsAlertDefinitionForm extends LocatableVLayout implement } });
- // NewNotificationEditor newEditor = new NewNotificationEditor( - // extendLocatorId("newNotificationEditor"), notifications, new Runnable() { - // @Override - // public void run() { - // winModal.markForDestroy(); - // table.refresh(); - // } - // }); - /// winModal.addItem(newEditor); + NewNotificationEditor newEditor = new NewNotificationEditor(extendLocatorId("newNotificationEditor"), + alertDefinition, notifications, notifToEdit, new Runnable() { + @Override + public void run() { + winModal.markForDestroy(); + table.refresh(); + } + }); + winModal.addItem(newEditor); winModal.show(); } }
commit 0b06e79336f625dcd36e15004d746ee2228e13aa Author: John Mazzitelli mazz@redhat.com Date: Thu Sep 30 14:48:26 2010 -0400
add cancel button
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java index 3fcc64e..361ad78 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java @@ -96,14 +96,15 @@ public class NewConditionEditor extends LocatableDynamicForm { private boolean supportsOperations = false; private boolean supportsEvents = false; private boolean supportsResourceConfig = false; - private Runnable okFunction; // this is called after the OK button is pressed and a new condition is saved + private Runnable closeFunction; // this is called after a button is pressed and the editor should close private ResourceType resourceType;
- public NewConditionEditor(String locatorId, HashSet<AlertCondition> conditions, ResourceType rtype, Runnable okFunc) { + public NewConditionEditor(String locatorId, HashSet<AlertCondition> conditions, ResourceType rtype, + Runnable closeFunc) {
super(locatorId); this.conditions = conditions; - this.okFunction = okFunc; + this.closeFunction = closeFunc; this.resourceType = rtype;
this.supportsEvents = (rtype.getEventDefinitions() != null && rtype.getEventDefinitions().size() > 0); @@ -174,26 +175,40 @@ public class NewConditionEditor extends LocatableDynamicForm { conditionTypeSelectItem.setRedrawOnChange(true); conditionTypeSelectItem.setWidth("*");
- SpacerItem spacer = new SpacerItem(); - spacer.setColSpan(2); - spacer.setHeight(5); + SpacerItem spacer1 = new SpacerItem(); + spacer1.setColSpan(2); + spacer1.setHeight(5);
- ButtonItem ok = new ButtonItem("buttonItem", "OK"); - ok.setColSpan(2); - ok.setAlign(Alignment.CENTER); + SpacerItem spacer2 = new SpacerItem(); + spacer2.setColSpan(2); + spacer2.setHeight(5); + + ButtonItem ok = new ButtonItem("okButtonItem", "OK"); + ok.setEndRow(false); + ok.setAlign(Alignment.RIGHT); ok.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (validate(false)) { saveNewCondition(); - okFunction.run(); + closeFunction.run(); } } });
+ ButtonItem cancel = new ButtonItem("cancelButtonItem", "Cancel"); + cancel.setStartRow(false); + cancel.setAlign(Alignment.LEFT); + cancel.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + closeFunction.run(); + } + }); + ArrayList<FormItem> formItems = new ArrayList<FormItem>(); formItems.add(conditionTypeSelectItem); - formItems.add(spacer); + formItems.add(spacer1); formItems.addAll(buildAvailabilityChangeFormItems()); if (supportsMetrics) { formItems.addAll(buildMetricThresholdFormItems()); @@ -216,7 +231,9 @@ public class NewConditionEditor extends LocatableDynamicForm { if (supportsResourceConfig) { formItems.addAll(buildResourceConfigChangeFormItems()); } + formItems.add(spacer2); formItems.add(ok); + formItems.add(cancel);
setFields(formItems.toArray(new FormItem[formItems.size()])); };
commit 5135c435804aef06ae9f37b1cebe72f2d79f580e Author: John Mazzitelli mazz@redhat.com Date: Thu Sep 30 12:19:04 2010 -0400
get notification tab ready to support editing an existing notif as well as adding new ones. this adds double click handler
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NotificationsAlertDefinitionForm.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NotificationsAlertDefinitionForm.java index cffdd78..b8e4644 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NotificationsAlertDefinitionForm.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NotificationsAlertDefinitionForm.java @@ -34,6 +34,9 @@ import com.smartgwt.client.types.Overflow; import com.smartgwt.client.widgets.Window; import com.smartgwt.client.widgets.events.CloseClickHandler; import com.smartgwt.client.widgets.events.CloseClientEvent; +import com.smartgwt.client.widgets.events.DoubleClickEvent; +import com.smartgwt.client.widgets.events.DoubleClickHandler; +import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord;
@@ -42,7 +45,6 @@ import org.rhq.core.domain.alert.notification.AlertNotification; import org.rhq.enterprise.gui.coregui.client.CoreGUI; import org.rhq.enterprise.gui.coregui.client.components.table.Table; import org.rhq.enterprise.gui.coregui.client.components.table.TableAction; -import org.rhq.enterprise.gui.coregui.client.components.table.Table.SelectionEnablement; import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource; import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout; @@ -140,57 +142,6 @@ public class NotificationsAlertDefinitionForm extends LocatableVLayout implement if (!formBuilt) {
table = new NotificationTable(extendLocatorId("notificationsTable")); - table.setShowHeader(false); - - final NotificationDataSource dataSource = new NotificationDataSource(); - table.setDataSource(dataSource); - - table.addTableAction(this.extendLocatorId("add"), "Add", SelectionEnablement.ALWAYS, null, - new TableAction() { - @Override - public void executeAction(ListGridRecord[] selection) { - final Window winModal = new LocatableWindow(NotificationsAlertDefinitionForm.this - .extendLocatorId("newNotificationEditorWindow")); - winModal.setTitle("Add Notification"); - winModal.setOverflow(Overflow.VISIBLE); - winModal.setShowMinimizeButton(false); - winModal.setIsModal(true); - winModal.setShowModalMask(true); - winModal.setAutoSize(true); - winModal.setAutoCenter(true); - //winModal.setShowResizer(true); - //winModal.setCanDragResize(true); - winModal.centerInPage(); - winModal.addCloseClickHandler(new CloseClickHandler() { - @Override - public void onCloseClick(CloseClientEvent event) { - winModal.markForDestroy(); - } - }); - - // NewNotificationEditor newEditor = new NewNotificationEditor( - // extendLocatorId("newNotificationEditor"), notifications, new Runnable() { - // @Override - // public void run() { - // winModal.markForDestroy(); - // table.refresh(); - // } - // }); - /// winModal.addItem(newEditor); - winModal.show(); - } - }); - table.addTableAction(this.extendLocatorId("delete"), "Delete", SelectionEnablement.ANY, "Are you sure?", - new TableAction() { - @Override - public void executeAction(ListGridRecord[] selection) { - for (ListGridRecord record : selection) { - AlertNotification notif = dataSource.copyValues(record); - notifications.remove(notif); - } - table.refresh(); - } - });
addMember(table);
@@ -268,6 +219,10 @@ public class NotificationsAlertDefinitionForm extends LocatableVLayout implement private class NotificationTable extends Table { public NotificationTable(String locatorId) { super(locatorId); + setShowHeader(false); + + final NotificationDataSource dataSource = new NotificationDataSource(); + setDataSource(dataSource); }
@Override @@ -277,6 +232,74 @@ public class NotificationsAlertDefinitionForm extends LocatableVLayout implement ListGridField configField = new ListGridField(FIELD_CONFIGURATION, "Configuration"); configField.setWidth("75%"); getListGrid().setFields(senderField, configField); + + getListGrid().addDoubleClickHandler(new DoubleClickHandler() { + @Override + public void onDoubleClick(DoubleClickEvent event) { + ListGrid listGrid = (ListGrid) event.getSource(); + ListGridRecord[] selectedRows = listGrid.getSelection(); + if (selectedRows != null && selectedRows.length == 1) { + AlertNotification notif = ((NotificationDataSource) getDataSource()) + .copyValues(selectedRows[0]); + popupNotificationEditor(notif); + } + } + }); + + addTableAction(this.extendLocatorId("add"), "Add", SelectionEnablement.ALWAYS, null, new TableAction() { + @Override + public void executeAction(ListGridRecord[] selection) { + popupNotificationEditor(null); + } + }); + + addTableAction(this.extendLocatorId("delete"), "Delete", SelectionEnablement.ANY, "Are you sure?", + new TableAction() { + @Override + public void executeAction(ListGridRecord[] selection) { + for (ListGridRecord record : selection) { + AlertNotification notif = ((NotificationDataSource) getDataSource()).copyValues(record); + notifications.remove(notif); + } + table.refresh(); + } + }); + } + + private void popupNotificationEditor(AlertNotification notifToEdit) { + final Window winModal = new LocatableWindow(NotificationsAlertDefinitionForm.this + .extendLocatorId("notificationEditorWindow")); + if (notifToEdit == null) { + winModal.setTitle("Add Notification"); + } else { + winModal.setTitle("Edit Notification"); + } + winModal.setOverflow(Overflow.VISIBLE); + winModal.setShowMinimizeButton(false); + winModal.setIsModal(true); + winModal.setShowModalMask(true); + winModal.setAutoSize(true); + winModal.setAutoCenter(true); + //winModal.setShowResizer(true); + //winModal.setCanDragResize(true); + winModal.centerInPage(); + winModal.addCloseClickHandler(new CloseClickHandler() { + @Override + public void onCloseClick(CloseClientEvent event) { + winModal.markForDestroy(); + } + }); + + // NewNotificationEditor newEditor = new NewNotificationEditor( + // extendLocatorId("newNotificationEditor"), notifications, new Runnable() { + // @Override + // public void run() { + // winModal.markForDestroy(); + // table.refresh(); + // } + // }); + /// winModal.addItem(newEditor); + winModal.show(); } } }