modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java | 131 ++++++++-- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/PropertyGrid.java | 11 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java | 10 3 files changed, 129 insertions(+), 23 deletions(-)
New commits: commit 9325dbcc42782c4a89be13acb7243dc08b618ec2 Author: Ian Springer ian.springer@redhat.com Date: Fri Oct 1 21:15:08 2010 -0400
work on completing impl of map-of-simples in ConfigurationEditor
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java index 343a709..fdc2d9c 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java @@ -39,6 +39,7 @@ import com.smartgwt.client.types.TreeModelType; import com.smartgwt.client.types.VisibilityMode; import com.smartgwt.client.util.BooleanCallback; import com.smartgwt.client.util.SC; +import com.smartgwt.client.util.ValueCallback; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.Label; @@ -73,6 +74,8 @@ import com.smartgwt.client.widgets.form.validator.Validator; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.events.CellSavedEvent; +import com.smartgwt.client.widgets.grid.events.CellSavedHandler; import com.smartgwt.client.widgets.grid.events.RecordClickEvent; import com.smartgwt.client.widgets.grid.events.RecordClickHandler; import com.smartgwt.client.widgets.grid.events.SelectionChangedHandler; @@ -115,11 +118,13 @@ import org.rhq.core.domain.configuration.definition.constraint.FloatRangeConstra import org.rhq.core.domain.configuration.definition.constraint.IntegerRangeConstraint; import org.rhq.core.domain.configuration.definition.constraint.RegexConstraint; import org.rhq.core.domain.resource.ResourceType; +import org.rhq.enterprise.gui.coregui.client.CoreGUI; import org.rhq.enterprise.gui.coregui.client.components.table.PropertyGrid; import org.rhq.enterprise.gui.coregui.client.gwt.ConfigurationGWTServiceAsync; import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeRepository; import org.rhq.enterprise.gui.coregui.client.util.CanvasUtility; +import org.rhq.enterprise.gui.coregui.client.util.message.Message; import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm; import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout; import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIButton; @@ -561,12 +566,12 @@ public class ConfigurationEditor extends LocatableVLayout { }
private void buildMapsField(ArrayList<FormItem> fields, PropertyDefinitionMap propertyDefinitionMap, - PropertyMap propertyMap) { + final PropertyMap propertyMap) { // create the property grid - PropertyGrid propertyGrid = new PropertyGrid(); + final PropertyGrid propertyGrid = new PropertyGrid(); propertyGrid.getNameField().setName("Name"); propertyGrid.getValuesField().setName("Value"); - + // create the editors Map<String, FormItem> editorsMap = new HashMap<String, FormItem>(); TextItem textEditor = new TextItem(); @@ -575,29 +580,123 @@ public class ConfigurationEditor extends LocatableVLayout { // set the editors and attribute name where to find the record type propertyGrid.setEditorsMap("fieldType", editorsMap);
- if (propertyMap != null) { - ListGridRecord[] records = new ListGridRecord[propertyMap.getMap().size()]; + if (propertyDefinitionMap != null) { + ListGridRecord[] records = new ListGridRecord[propertyDefinitionMap.getPropertyDefinitions().size()]; int i = 0; - for (Property property : propertyMap.getMap().values()) { + // TODO (ips): For open maps, create the records based on props, not propDefs. + // TODO (ips): Render unset checkboxes amd descriptions for member props, just as we would for top-level simples. + for (PropertyDefinition propDef : propertyDefinitionMap.getPropertyDefinitions().values()) { ListGridRecord record = new ListGridRecord(); - record.setAttribute("Name", property.getName()); - record.setAttribute("Value", ((PropertySimple) property).getStringValue()); + String propertyName = propDef.getName(); + record.setAttribute("Name", propertyName); + PropertySimple prop = propertyMap.getSimple(propertyName); + String value = (prop != null) ? prop.getStringValue() : null; + record.setAttribute("Value", value); record.setAttribute("fieldType", "simpleText"); + record.setAttribute("readOnly", propDef.isReadOnly()); records[i++] = record; } propertyGrid.setData(records); }
- propertyGrid.draw(); + VLayout canvas = new VLayout(); + + canvas.addMember(propertyGrid); + + // Footer + ToolStrip footer = new ToolStrip(); + footer.setPadding(5); + footer.setWidth100(); + footer.setMembersMargin(15); + canvas.addMember(footer); + + // Properties can only be added to or deleted from non-read-only "open" maps. + if (propertyDefinitionMap.getPropertyDefinitions().isEmpty() && !propertyDefinitionMap.isReadOnly()) { + final IButton deleteButton = new LocatableIButton(extendLocatorId(propertyMap.getName()), "Delete"); + deleteButton.setDisabled(true); + deleteButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { + public void onClick(ClickEvent clickEvent) { + final ListGridRecord[] selectedRecords = propertyGrid.getSelection(); + String noun = (selectedRecords.length == 1) ? "property" : "properties"; + String message = "Are you sure you want to delete the selected" + noun + "?"; + SC.ask(message, new BooleanCallback() { + public void execute(Boolean confirmed) { + if (confirmed) { + for (ListGridRecord selectedRecord : selectedRecords) { + propertyGrid.removeData(selectedRecord); + String propertyName = selectedRecord.getAttribute("Name"); + propertyMap.getMap().remove(propertyName); + } + } + } + }); + } + }); + footer.addMember(deleteButton);
- CanvasItem item = new CanvasItem(); - item.setCanvas(propertyGrid); - // item.setHeight(500); - item.setColSpan(3); - item.setEndRow(true); - item.setShowTitle(false); - fields.add(item); + propertyGrid.addSelectionChangedHandler(new SelectionChangedHandler() { + public void onSelectionChanged(SelectionEvent selectionEvent) { + int count = propertyGrid.getSelection().length; + deleteButton.setDisabled(count < 1); + } + }); + + final IButton newButton = new LocatableIButton(extendLocatorId(propertyMap.getName()), "New"); + newButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { + public void onClick(ClickEvent clickEvent) { + SC.askforValue("Enter the name of the property to be added.", new ValueCallback() { + @Override + public void execute(String propertyName) { + if (propertyMap.get(propertyName) != null) { + CoreGUI.getMessageCenter().notify( + new Message("Cannot add property named '" + propertyName + + "', because the set already contains a property with that name.", + Message.Severity.Error, EnumSet.of(Message.Option.Transient))); + } else { + propertyMap.put(new PropertySimple(propertyName, null)); + + ListGridRecord record = new ListGridRecord(); + record.setAttribute("Name", propertyName); + record.setAttribute("Value", ""); + record.setAttribute("fieldType", "simpleText"); + + propertyGrid.addData(record); + propertyGrid.focus(); + propertyGrid.enableSpecificEditor(record); + + CoreGUI.getMessageCenter().notify(new Message("Added property to the set.", EnumSet.of( + Message.Option.Transient))); + } + } + }); + } + }); + footer.addMember(newButton); + }
+ propertyGrid.addCellSavedHandler(new CellSavedHandler() { + @Override + public void onCellSaved(CellSavedEvent cellSavedEvent) { + Record record = cellSavedEvent.getRecord(); + String propertyName = record.getAttribute("Name"); + PropertySimple prop = propertyMap.getSimple(propertyName); + if (prop == null) { + prop = new PropertySimple(propertyName, null); + } + String value = record.getAttribute("Value"); + prop.setStringValue(value); + } + }); + + propertyGrid.draw(); + + CanvasItem canvasItem = new CanvasItem(); + canvasItem.setCanvas(canvas); + // item.setHeight(500); + canvasItem.setColSpan(3); + canvasItem.setEndRow(true); + canvasItem.setShowTitle(false); + fields.add(canvasItem); }
private void buildListOfMapsField(final String locatorId, ArrayList<FormItem> fields, diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/PropertyGrid.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/PropertyGrid.java index ee6b7d7..73340fa 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/PropertyGrid.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/PropertyGrid.java @@ -38,7 +38,6 @@ import com.smartgwt.client.widgets.grid.events.RecordClickHandler; * @author Dan Mihai Ile */ public class PropertyGrid extends ListGrid { - /** * Map to hold the editors */ @@ -56,7 +55,7 @@ public class PropertyGrid extends ListGrid { */ public PropertyGrid() {
- // create the 2 fields, one for names, other for values + // Create the 2 fields - one for names, other for values. ListGridField nameField = new ListGridField(); nameField.setCanEdit(false); ListGridField valueField = new ListGridField(); @@ -100,7 +99,7 @@ public class PropertyGrid extends ListGrid {
/** * Set the name of the attribute from where the row will get the editor name - * to be used on the {@link Map} from where the rows will get it's editors + * to be used on the {@link Map} from where the rows will get its editors * <p/> * When an edit starts the {@link PropertyGrid} will retrieve the key of the * editor form the row's attributes and use that key on the map to get the @@ -120,8 +119,9 @@ public class PropertyGrid extends ListGrid { * * @param record the record */ - private void enableSpecificEditor(Record record) { - if (editorsMap != null) { + public void enableSpecificEditor(Record record) { + boolean readOnly = record.getAttributeAsBoolean("readOnly"); + if (editorsMap != null && !readOnly) { String attribute = record.getAttribute(valueFieldAttribute); if (editorsMap.containsKey(attribute)) { FormItem formItem = editorsMap.get(attribute); @@ -129,5 +129,4 @@ public class PropertyGrid extends ListGrid { } } } - } \ No newline at end of file diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java index 429ef36..3a0b464 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java @@ -39,6 +39,10 @@ public class Message { public enum Severity { Info, Warning, Error, Fatal }; public enum Option { Transient, Sticky, BackgroundJobResult };
+ public Message(String conciseMessage) { + this(conciseMessage, (Severity)null); + } + public Message(String conciseMessage, Severity severity) { this(conciseMessage, null, severity); } @@ -46,7 +50,11 @@ public class Message { public Message(String conciseMessage, String detailedMessage) { this(conciseMessage, detailedMessage, null); } - + + public Message(String conciseMessage, EnumSet<Option> options) { + this(conciseMessage, null, options); + } + public Message(String conciseMessage, String detailedMessage, Severity severity) { this(conciseMessage, detailedMessage, severity, null); }
rhq-commits@lists.fedorahosted.org