Skip to content

Commit

Permalink
extract DMR utils
Browse files Browse the repository at this point in the history
  • Loading branch information
heiko-braun committed Aug 7, 2012
1 parent f8da5c7 commit 0c91b11
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
40 changes: 40 additions & 0 deletions gui/src/main/java/org/jboss/as/console/client/tools/DMR.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.jboss.as.console.client.tools;

import org.jboss.dmr.client.ModelNode;

import java.util.Map;
import java.util.Set;

/**
* @author Heiko Braun
* @date 7/24/12
*/
public class DMR {

public static void mergeChanges(ModelNode target, Map<String,Object> changeset)
{
final Set<String> changesetKeys = changeset.keySet();
final Set<String> attributeNames = target.keys();

for(String key : changesetKeys)
{
boolean matched = false;
for(String attribute : attributeNames)
{
if(key.equals(attribute))
{
final Object o = changeset.get(key);
final ModelNode node = Types.toDMR(o);
target.get(attribute).set(node);
matched = true;
break;
}
}

if(!matched)
throw new RuntimeException("Unmatched attribute name in changeset: "+key);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,7 @@ public void onSave(Map<String, Object> changeset) {

final FXModel modelStep = selectionModel.getSelectedObject();
final ModelNode modelNode = modelStep.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;
}
}
}
DMR.mergeChanges(modelNode, changeset);

getCurrentTemplate().removeModel(modelStep.getId());
getCurrentTemplate().getModels().add(FXModel.fromModelNode(modelNode));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,7 @@ public void onSave(Map<String, Object> 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;
}
}
}
DMR.mergeChanges(modelNode, changeset);

presenter.onUpdateTemplate(FXTemplate.fromModelNode(modelNode));
}
Expand Down

0 comments on commit 0c91b11

Please sign in to comment.