modules/enterprise/gui/coregui/src/main/java/org/rhq/core/domain/measurement/MeasurementConverterClient.java | 103 ++++----- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsAlertDefinitionForm.java | 10 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsEditor.java | 109 ++++++++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsDataSource.java | 2 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java | 60 +++-- 5 files changed, 213 insertions(+), 71 deletions(-)
New commits: commit e292517b3189ed60c6b38cdab023d6fec7dd9098 Author: John Mazzitelli mazz@redhat.com Date: Wed Sep 8 17:01:50 2010 -0400
initial start of the conditions tab for alert def
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsAlertDefinitionForm.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsAlertDefinitionForm.java index 201360b..f19d967 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsAlertDefinitionForm.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsAlertDefinitionForm.java @@ -25,6 +25,7 @@ package org.rhq.enterprise.gui.coregui.client.alert.definitions;
import java.util.LinkedHashMap;
+import com.smartgwt.client.widgets.form.fields.CanvasItem; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.form.fields.StaticTextItem;
@@ -128,7 +129,14 @@ public class ConditionsAlertDefinitionForm extends LocatableDynamicForm implemen conditionExpression.setDefaultValue(BooleanExpression.ALL.name()); conditionExpressionStatic = new StaticTextItem("conditionExpressionStatic", "Fire alert when");
- setFields(conditionExpression, conditionExpressionStatic); + ConditionsEditor conditionsEditor = new ConditionsEditor(this.extendLocatorId("conditionsEditor"), this); + + CanvasItem canvasItem = new CanvasItem("conditionsEditorCanvasItem"); + canvasItem.setCanvas(conditionsEditor); + canvasItem.setShowTitle(false); + canvasItem.setColSpan(2); + + setFields(conditionExpression, conditionExpressionStatic, canvasItem);
formBuilt = true; } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsEditor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsEditor.java new file mode 100644 index 0000000..ddc3545 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsEditor.java @@ -0,0 +1,109 @@ +/* + * 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 com.smartgwt.client.data.DSRequest; +import com.smartgwt.client.data.DSResponse; +import com.smartgwt.client.data.fields.DataSourceTextField; +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import org.rhq.core.domain.alert.AlertCondition; +import org.rhq.enterprise.gui.coregui.client.alert.AlertFormatUtility; +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.util.RPCDataSource; +import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout; + +/** + * @author John Mazzitelli + */ +public class ConditionsEditor extends LocatableVLayout { + + private final ConditionsAlertDefinitionForm form; + private Table table; + + public ConditionsEditor(String locatorId, ConditionsAlertDefinitionForm form) { + super(locatorId); + this.form = form; + } + + @Override + protected void onInit() { + super.onInit(); + + table = new Table("conditionsTable"); + table.setShowHeader(false); + table.setDataSource(new ConditionDataSource()); + + table.addTableAction(this.extendLocatorId("add"), "Add", SelectionEnablement.ALWAYS, null, new TableAction() { + @Override + public void executeAction(ListGridRecord[] selection) { + // TODO Auto-generated method stub + } + }); + table.addTableAction(this.extendLocatorId("delete"), "Delete", SelectionEnablement.ANY, "Are you sure?", + new TableAction() { + @Override + public void executeAction(ListGridRecord[] selection) { + // TODO Auto-generated method stub + } + }); + + addMember(table); + } + + public void setEditable(boolean editable) { + table.setTableActionDisableOverride(!editable); + } + + private class ConditionDataSource extends RPCDataSource<AlertCondition> { + private static final String FIELD_OBJECT = "obj"; + private static final String FIELD_CONDITION = "condition"; + + public ConditionDataSource() { + DataSourceTextField conditionField = new DataSourceTextField(FIELD_CONDITION, "Condition"); + addField(conditionField); + } + + @Override + public AlertCondition copyValues(ListGridRecord from) { + return (AlertCondition) from.getAttributeAsObject(FIELD_OBJECT); + } + + @Override + public ListGridRecord copyValues(AlertCondition from) { + ListGridRecord record = new ListGridRecord(); + record.setAttribute(FIELD_CONDITION, AlertFormatUtility.formatAlertConditionForDisplay(from)); + record.setAttribute(FIELD_OBJECT, from); + return record; + } + + @Override + protected void executeFetch(DSRequest request, DSResponse response) { + response.setData(buildRecords(ConditionsEditor.this.form.getAlertDefinition().getConditions())); + processResponse(request.getRequestId(), response); + } + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsDataSource.java index ac7b789..dc04a1e 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsDataSource.java @@ -97,6 +97,8 @@ public class ResourceAlertDefinitionsDataSource extends AbstractAlertDefinitions AlertDefinitionCriteria criteria = new AlertDefinitionCriteria();
criteria.fetchGroupAlertDefinition(true); + criteria.fetchConditions(true); + criteria.fetchAlertNotifications(true);
Criteria requestCriteria = request.getCriteria(); if (requestCriteria != null) { 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 90b448f..d12a864 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 @@ -120,6 +120,7 @@ public class Table extends LocatableHLayout { ;
private List<TableActionInfo> tableActions = new ArrayList<TableActionInfo>(); + private boolean tableActionDisableOverride = false; private List<Canvas> extraWidgets = new ArrayList<Canvas>();
public Table(String locatorId) { @@ -476,29 +477,54 @@ public class Table extends LocatableHLayout { this.headerIcons.add(headerIcon); }
+ /** + * By default, all table actions have buttons that are enabled or + * disabled based on if and how many rows are selected. There are + * times when you don't want the user to be able to press table action + * buttons regardless of which rows are selected. This method let's + * you set this override-disable flag. + * + * @param disabled if true, all table action buttons will be disabled + * if false, table action buttons will be enabled based on their predefined + * selection enablement rule. + */ + public void setTableActionDisableOverride(boolean disabled) { + this.tableActionDisableOverride = disabled; + refreshTableInfo(); + } + + public boolean getTableActionDisableOverride() { + return this.tableActionDisableOverride; + } + protected void refreshTableInfo() { if (showFooter) { int count = this.listGrid.getSelection().length; for (TableActionInfo tableAction : tableActions) { boolean enabled; - switch (tableAction.enablement) { - case ALWAYS: - enabled = true; - break; - case NEVER: + if (!this.tableActionDisableOverride) { + switch (tableAction.enablement) { + case ALWAYS: + enabled = true; + break; + case NEVER: + enabled = false; + break; + case ANY: + enabled = (count >= 1); + break; + case SINGLE: + enabled = (count == 1); + break; + case MULTIPLE: + enabled = (count > 1); + break; + default: + throw new IllegalStateException("Unhandled SelectionEnablement: " + + tableAction.enablement.name()); + } + } else { enabled = false; - break; - case ANY: - enabled = (count >= 1); - break; - case SINGLE: - enabled = (count == 1); - break; - case MULTIPLE: - enabled = (count > 1); - break; - default: - throw new IllegalStateException("Unhandled SelectionEnablement: " + tableAction.enablement.name()); } tableAction.actionButton.setDisabled(!enabled); }
commit 116b730cb2cd65086374eccb0d74904abef053cb Author: John Mazzitelli mazz@redhat.com Date: Wed Sep 8 16:59:25 2010 -0400
fix NPE - make sure targetUnits is not null before checking to see if its family is RELATIVE
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/core/domain/measurement/MeasurementConverterClient.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/core/domain/measurement/MeasurementConverterClient.java index f78b62c..f084ec0 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/core/domain/measurement/MeasurementConverterClient.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/core/domain/measurement/MeasurementConverterClient.java @@ -1,47 +1,46 @@ - /* - * RHQ Management Platform - * Copyright (C) 2005-2008 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.core.domain.measurement; - - import org.rhq.core.domain.measurement.composite.MeasurementNumericValueAndUnits; - import org.rhq.core.domain.measurement.util.MeasurementConversionException; - - import com.google.gwt.i18n.client.NumberFormat; - - import java.util.HashSet; - import java.util.Set; - - public class MeasurementConverterClient { +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 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.core.domain.measurement; + +import java.util.HashSet; +import java.util.Set; + +import com.google.gwt.i18n.client.NumberFormat; + +import org.rhq.core.domain.measurement.composite.MeasurementNumericValueAndUnits; +import org.rhq.core.domain.measurement.util.MeasurementConversionException; + +public class MeasurementConverterClient { private static final int MAX_PRECISION_DIGITS = 4; private static final String NULL_OR_NAN_FORMATTED_VALUE = "--no data available--";
- private static NumberFormat getDefaultNumberFormat() { NumberFormat nf = NumberFormat.getFormat("0.0");
return nf; }
- public static Double scale(MeasurementNumericValueAndUnits origin, MeasurementUnits targetUnits) + public static Double scale(MeasurementNumericValueAndUnits origin, MeasurementUnits targetUnits) throws MeasurementConversionException { MeasurementUnits originUnits = origin.getUnits(); Double originValue = origin.getValue(); @@ -201,7 +200,7 @@ }
public static String format(Double value, MeasurementUnits targetUnits, boolean bestFit, - Integer minimumFractionDigits, Integer maximumFractionDigits) { + Integer minimumFractionDigits, Integer maximumFractionDigits) { if (value == null || Double.isNaN(value)) { return NULL_OR_NAN_FORMATTED_VALUE; } @@ -213,15 +212,13 @@ }
// apply relative scale at presentation time - if (MeasurementUnits.Family.RELATIVE == targetUnits.getFamily()) { + if (targetUnits != null && MeasurementUnits.Family.RELATIVE == targetUnits.getFamily()) { value = MeasurementUnits.scaleUp(value, targetUnits); }
- NumberFormat numberFormat = - NumberFormat.getFormat( - getFormat( - minimumFractionDigits != null ? minimumFractionDigits : 1, - maximumFractionDigits != null ? maximumFractionDigits : 1)); + NumberFormat numberFormat = NumberFormat.getFormat(getFormat( + minimumFractionDigits != null ? minimumFractionDigits : 1, + maximumFractionDigits != null ? maximumFractionDigits : 1));
String formatted = numberFormat.format(value);
@@ -273,7 +270,7 @@ if (MeasurementUnits.Family.RELATIVE == units.getFamily()) { return new MeasurementNumericValueAndUnits(origin, units); } - + if (MeasurementUnits.Family.TEMPERATURE == units.getFamily()) { return new MeasurementNumericValueAndUnits(origin, units); } @@ -347,14 +344,14 @@ return currentValueAndUnits; }
- public static String getFormat(int minDigits, int maxDigits) { - StringBuilder buf = new StringBuilder("0."); - for (int i = 0; i < minDigits;i++) { - buf.append("0"); - } - for (int i = 0; i < (maxDigits-minDigits);i++) { - buf.append("#"); - } - return buf.toString(); - } + public static String getFormat(int minDigits, int maxDigits) { + StringBuilder buf = new StringBuilder("0."); + for (int i = 0; i < minDigits; i++) { + buf.append("0"); + } + for (int i = 0; i < (maxDigits - minDigits); i++) { + buf.append("#"); + } + return buf.toString(); + } }
rhq-commits@lists.fedorahosted.org