diff --git a/gui/src/main/java/org/jboss/as/console/client/tools/FXModel.java b/gui/src/main/java/org/jboss/as/console/client/tools/FXModel.java index 28f40c4cdd..863d7de391 100644 --- a/gui/src/main/java/org/jboss/as/console/client/tools/FXModel.java +++ b/gui/src/main/java/org/jboss/as/console/client/tools/FXModel.java @@ -73,6 +73,7 @@ public String toBase64() { public ModelNode asModelNode() { ModelNode modelNode = new ModelNode(); + modelNode.get("id").set(id); modelNode.get("execType").set(type.name()); modelNode.get("address").set(address); modelNode.get("description").set(description); @@ -85,6 +86,7 @@ public ModelNode asModelNode() { public static FXModel fromModelNode(ModelNode modelNode) { + final String id = modelNode.get("id").asString(); final String type = modelNode.get("execType").asString(); final ModelNode address = modelNode.get("address").asObject(); String description = modelNode.get("description").asString(); @@ -97,7 +99,12 @@ public static FXModel fromModelNode(ModelNode modelNode) { final FXModel fxModel = new FXModel(ExecutionType.valueOf(type), address); fxModel.getFieldNames().addAll(values); fxModel.setDescription(description); + fxModel.setId(id); return fxModel; } + private void setId(String id) { + this.id = id; + } + } diff --git a/gui/src/main/java/org/jboss/as/console/client/tools/FXModelsView.java b/gui/src/main/java/org/jboss/as/console/client/tools/FXModelsView.java index c89c405557..e5439ade0c 100644 --- a/gui/src/main/java/org/jboss/as/console/client/tools/FXModelsView.java +++ b/gui/src/main/java/org/jboss/as/console/client/tools/FXModelsView.java @@ -20,9 +20,7 @@ import org.jboss.ballroom.client.widgets.tools.ToolButton; import org.jboss.ballroom.client.widgets.tools.ToolStrip; import org.jboss.dmr.client.ModelNode; -import org.jboss.dmr.client.ModelType; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -60,14 +58,14 @@ public Object getKey(FXModel FXModel) { final SingleSelectionModel selectionModel = new SingleSelectionModel(); table.setSelectionModel(selectionModel); - TextColumn idCol = new TextColumn() { + + TextColumn descCol = new TextColumn() { @Override public String getValue(FXModel FXModel) { - return FXModel.getId(); + return FXModel.getDescription(); } }; - TextColumn typeCol = new TextColumn() { @Override public String getValue(FXModel FXModel) { @@ -75,8 +73,8 @@ public String getValue(FXModel FXModel) { } }; - table.addColumn(idCol, "ID"); table.addColumn(typeCol, "Execution Type"); + table.addColumn(descCol, "Description"); ToolStrip toolstrip = new ToolStrip(); ToolButton addBtn = new ToolButton("Add", new ClickHandler() { @@ -136,20 +134,13 @@ public void onSelectionChange(SelectionChangeEvent selectionChangeEvent) { if(modelStep!=null) { - Map payload = new HashMap(); - payload.put("id", modelStep.getId()); - payload.put("description", modelStep.getDescription()); - payload.put("address", modelStep.getAddress().asString()); - payload.put("execType", modelStep.getType().name()); - payload.put("fieldNames", modelStep.getFieldNames()); - - form.edit(payload); + form.edit(modelStep.asModelNode()); } } }); - FXFormToolStrip formTools = new FXFormToolStrip(form, new FXFormToolStrip.FormCallback() { + SimpleFormToolStrip formTools = new SimpleFormToolStrip(form, new SimpleFormToolStrip.FormCallback() { @Override public void onSave(Map changeset) { @@ -162,8 +153,8 @@ public void onSave(Map changeset) { if(key.equals(attribute)) { final Object o = changeset.get(key); - final ModelType dmrType = Types.toDMR(o); - modelNode.get(attribute).set(dmrType, o); + final ModelNode node = Types.toDMR(o); + modelNode.get(attribute).set(node); break; } } @@ -200,12 +191,12 @@ private FXTemplate getCurrentTemplate() return this.currentTemplate; } - public void setModelSteps(FXTemplate template, List models) { + public void setTemplate(FXTemplate template) { this.currentTemplate = template; this.headline.setText("Models: Template '"+template.getName()+"'"); dataProvider.getList().clear(); - dataProvider.getList().addAll(models); + dataProvider.getList().addAll(template.getModels()); dataProvider.flush(); table.selectDefaultEntity(); } diff --git a/gui/src/main/java/org/jboss/as/console/client/tools/FXTemplate.java b/gui/src/main/java/org/jboss/as/console/client/tools/FXTemplate.java index 6fb77a97be..26c6d27578 100644 --- a/gui/src/main/java/org/jboss/as/console/client/tools/FXTemplate.java +++ b/gui/src/main/java/org/jboss/as/console/client/tools/FXTemplate.java @@ -37,6 +37,11 @@ public List getModels() { public static FXTemplate fromBase64(String encoded) { ModelNode modelNode = ModelNode.fromBase64(encoded); + return fromModelNode(modelNode); + } + + public static FXTemplate fromModelNode(ModelNode modelNode) + { final String name = modelNode.get("name").asString(); final String id = modelNode.get("id").asString(); diff --git a/gui/src/main/java/org/jboss/as/console/client/tools/FXTemplatesView.java b/gui/src/main/java/org/jboss/as/console/client/tools/FXTemplatesView.java index e8c79f8860..afb3b5acfe 100644 --- a/gui/src/main/java/org/jboss/as/console/client/tools/FXTemplatesView.java +++ b/gui/src/main/java/org/jboss/as/console/client/tools/FXTemplatesView.java @@ -15,13 +15,14 @@ import org.jboss.as.console.client.shared.viewframework.builder.MultipleToOneLayout; import org.jboss.as.console.client.widgets.pages.PagedView; import org.jboss.as.console.client.widgets.tables.TextLinkCell; -import org.jboss.ballroom.client.widgets.forms.Form; -import org.jboss.ballroom.client.widgets.forms.TextBoxItem; +import org.jboss.ballroom.client.widgets.forms.TextAreaItem; import org.jboss.ballroom.client.widgets.forms.TextItem; import org.jboss.ballroom.client.widgets.tables.DefaultCellTable; import org.jboss.ballroom.client.widgets.tools.ToolButton; import org.jboss.ballroom.client.widgets.tools.ToolStrip; +import org.jboss.dmr.client.ModelNode; +import java.util.Map; import java.util.Set; /** @@ -63,13 +64,6 @@ public Object getKey(FXTemplate fxTemplate) { final SingleSelectionModel selectionModel = new SingleSelectionModel(); table.setSelectionModel(selectionModel); - TextColumn idCol = new TextColumn() { - @Override - public String getValue(FXTemplate fxTemplate) { - return fxTemplate.getId(); - } - - }; TextColumn nameCol = new TextColumn() { @Override @@ -78,17 +72,16 @@ public String getValue(FXTemplate fxTemplate) { } }; - table.addColumn(idCol, "ID"); table.addColumn(nameCol, "Name"); Column option = new Column( new TextLinkCell(Console.CONSTANTS.common_label_view(), new ActionCell.Delegate() { - @Override - public void execute(FXTemplate selection) { - pages.showPage(1); - } - }) + @Override + public void execute(FXTemplate selection) { + pages.showPage(1); + } + }) ) { @Override @@ -120,9 +113,9 @@ public void onClick(ClickEvent clickEvent) { toolstrip.addToolButtonRight(removeBtn); - final Form form = new Form(Object.class); + final SimpleForm form = new SimpleForm(); final TextItem id = new TextItem("id", "ID"); - final TextBoxItem name = new TextBoxItem("name", "Name", true); + final TextAreaItem name = new TextAreaItem("name", "Name", true); form.setFields(id, name); modelStepView = new FXModelsView(); @@ -135,16 +128,46 @@ public void onSelectionChange(SelectionChangeEvent selectionChangeEvent) { if(template!=null) { - id.setValue(template.getId()); - name.setValue(template.getName()); + form.edit(template.asModelNode()); // update the model step views - modelStepView.setModelSteps(template, template.getModels()); + modelStepView.setTemplate(template); } } }); + SimpleFormToolStrip formTools = new SimpleFormToolStrip(form, new SimpleFormToolStrip.FormCallback() { + @Override + public void onSave(Map changeset) { + + final FXTemplate template = selectionModel.getSelectedObject(); + final ModelNode modelNode = template.asModelNode(); + for(String key : changeset.keySet()) + { + for(String attribute : modelNode.keys()) + { + if(key.equals(attribute)) + { + final Object o = changeset.get(key); + final ModelNode node = Types.toDMR(o); + modelNode.get(attribute).set(node); + break; + } + } + } + + presenter.onUpdateTemplate(FXTemplate.fromModelNode(modelNode)); + } + + @Override + public void onDelete(Object entity) { + + } + }) ; + VerticalPanel formLayout = new VerticalPanel(); + formLayout.setStyleName("fill-layout-width"); + formLayout.add(formTools.asWidget()); formLayout.add(form.asWidget()); MultipleToOneLayout layout = new MultipleToOneLayout() diff --git a/gui/src/main/java/org/jboss/as/console/client/tools/NewFXTemplateWizard.java b/gui/src/main/java/org/jboss/as/console/client/tools/NewFXTemplateWizard.java index 6c8d5749d1..75c6057ca1 100644 --- a/gui/src/main/java/org/jboss/as/console/client/tools/NewFXTemplateWizard.java +++ b/gui/src/main/java/org/jboss/as/console/client/tools/NewFXTemplateWizard.java @@ -33,9 +33,10 @@ Widget asWidget() { VerticalPanel layout = new VerticalPanel(); layout.addStyleName("window-content"); - final Form form = new Form(Object.class); + final SimpleForm form = new SimpleForm(); + form.setEnabled(true); - final TextBoxItem name = new TextBoxItem("name", "Name", true); + final TextAreaItem name = new TextAreaItem("name", "Name", true); final TextAreaItem address = new TextAreaItem("address", "Address", true); final ComboBoxItem type = new ComboBoxItem("execType", "ExecType") { @@ -45,7 +46,6 @@ public boolean isRequired() { } }; - type.setValueMap(new String[] { FXModel.ExecutionType.CREATE.name(), FXModel.ExecutionType.UPDATE.name(), diff --git a/gui/src/main/java/org/jboss/as/console/client/tools/SimpleForm.java b/gui/src/main/java/org/jboss/as/console/client/tools/SimpleForm.java index aa310f6f70..af93a3dc02 100644 --- a/gui/src/main/java/org/jboss/as/console/client/tools/SimpleForm.java +++ b/gui/src/main/java/org/jboss/as/console/client/tools/SimpleForm.java @@ -9,6 +9,7 @@ import org.jboss.ballroom.client.widgets.forms.GroupRenderer; import org.jboss.ballroom.client.widgets.forms.PlainFormView; import org.jboss.ballroom.client.widgets.forms.RenderMetaData; +import org.jboss.dmr.client.ModelNode; import java.util.ArrayList; import java.util.HashMap; @@ -26,7 +27,7 @@ public class SimpleForm { private int numColumns = 1; private List plainViews = new ArrayList(); private boolean enabled; - private Map snapshot; + private ModelNode snapshot; public void setFields(FormItem... fields) { @@ -34,18 +35,20 @@ public void setFields(FormItem... fields) items.add(item); } - public void edit(Map values) + public void edit(ModelNode values) { + System.out.println("Edit "+values); + this.snapshot = values; - for(String key : values.keySet()) + for(String key : values.keys()) { for(FormItem item : items) { if(item.getName().equals(key)) { item.resetMetaData(); - final Object value = values.get(key); + final Object value = Types.fromDmr(values.get(key)); if(value!=null) { diff --git a/gui/src/main/java/org/jboss/as/console/client/tools/FXFormToolStrip.java b/gui/src/main/java/org/jboss/as/console/client/tools/SimpleFormToolStrip.java similarity index 96% rename from gui/src/main/java/org/jboss/as/console/client/tools/FXFormToolStrip.java rename to gui/src/main/java/org/jboss/as/console/client/tools/SimpleFormToolStrip.java index 813dd21d84..500842e9fd 100644 --- a/gui/src/main/java/org/jboss/as/console/client/tools/FXFormToolStrip.java +++ b/gui/src/main/java/org/jboss/as/console/client/tools/SimpleFormToolStrip.java @@ -19,7 +19,7 @@ * @author Heiko Braun * @date 9/19/11 */ -public class FXFormToolStrip { +public class SimpleFormToolStrip { private SimpleForm form = null; private FormCallback callback; @@ -38,12 +38,12 @@ public interface PreValidation { } - public FXFormToolStrip(SimpleForm form, FormCallback callback) { + public SimpleFormToolStrip(SimpleForm form, FormCallback callback) { this.form = form; this.callback = callback; } - public FXFormToolStrip(SimpleForm form, FormCallback callback, String deleteOpName) { + public SimpleFormToolStrip(SimpleForm form, FormCallback callback, String deleteOpName) { this.form = form; this.callback = callback; this.deleteOpName = deleteOpName; diff --git a/gui/src/main/java/org/jboss/as/console/client/tools/Types.java b/gui/src/main/java/org/jboss/as/console/client/tools/Types.java index 3a0c7fd2be..fafeabeb11 100644 --- a/gui/src/main/java/org/jboss/as/console/client/tools/Types.java +++ b/gui/src/main/java/org/jboss/as/console/client/tools/Types.java @@ -1,15 +1,58 @@ package org.jboss.as.console.client.tools; +import org.jboss.dmr.client.ModelNode; import org.jboss.dmr.client.ModelType; +import java.util.ArrayList; +import java.util.List; + /** * @author Heiko Braun * @date 7/23/12 */ public class Types { - public static ModelType toDMR(Object o) { - return resolveModelType(o.getClass().getName()); + public static ModelNode toDMR(Object o) { + ModelNode node = new ModelNode(); + final ModelType attributeType = resolveModelType(o.getClass().getName()); + + if(ModelType.STRING == attributeType) + { + node.set((String)o); + } + else if(ModelType.INT == attributeType) + { + node.set((Integer)o); + } + else if(ModelType.LONG == attributeType) + { + node.set((Long)o); + } + else if(ModelType.BOOLEAN == attributeType) + { + node.set((Boolean)o); + } + else if(ModelType.DOUBLE == attributeType) + { + node.set((Double)o); + } + else if(ModelType.LIST == attributeType) + { + final List nodeList = node.asList(); + node.setEmptyList(); + for(ModelNode item : nodeList) + node.add(item.toString()); + + } + else if (ModelType.OBJECT == attributeType) + { + node.set(o.toString()); + } + else { + throw new RuntimeException("Unsupported type "+attributeType); + } + + return node; } private static ModelType resolveModelType(String javaTypeName) { @@ -39,4 +82,49 @@ else if("java.util.ArrayList".equals(javaTypeName)) { return type; } + public static Object fromDmr(ModelNode attributeNode) { + + Object result = null; + final ModelType attributeType = attributeNode.getType(); + + if(ModelType.STRING == attributeType) + { + result = attributeNode.asString(); + } + else if(ModelType.INT == attributeType) + { + result = attributeNode.asInt(); + } + else if(ModelType.LONG == attributeType) + { + result = attributeNode.asLong(); + } + else if(ModelType.BOOLEAN == attributeType) + { + result = attributeNode.asBoolean(); + } + else if(ModelType.DOUBLE == attributeType) + { + result = attributeNode.asDouble(); + } + else if(ModelType.LIST == attributeType) + { + final List nodeList = attributeNode.asList(); + List list = new ArrayList(nodeList.size()); + for(ModelNode item : nodeList) + list.add(item.toString()); + + result = list; + } + else if(ModelType.OBJECT == attributeType) + { + result = attributeNode.asString(); + } + else { + throw new RuntimeException("Unsupported type "+attributeType); + } + + return result; + } + }