diff --git a/gui/src/main/java/org/jboss/as/console/client/shared/help/HelpSystem.java b/gui/src/main/java/org/jboss/as/console/client/shared/help/HelpSystem.java index 65fc7c6c3..35da88eae 100644 --- a/gui/src/main/java/org/jboss/as/console/client/shared/help/HelpSystem.java +++ b/gui/src/main/java/org/jboss/as/console/client/shared/help/HelpSystem.java @@ -111,37 +111,7 @@ public void getAttributeDescriptions( } } - dispatcher.execute(new DMRAction(operation), new AsyncCallback() { - @Override - public void onSuccess(DMRResponse result) { - ModelNode response = result.get(); - - if(response.isFailure()) - { - Log.debug(response.toString()); - onFailure(new Exception(response.getFailureDescription())); - } - else - { - LinkedList fields = new LinkedList(); - ModelNode payload = response.get(RESULT); - - ModelNode descriptionModel = null; - if(ModelType.LIST.equals(payload.getType())) - descriptionModel = payload.asList().get(0); - else - descriptionModel = payload; - - matchSubElements(descriptionModel, fieldNames, fields); - callback.onSuccess(fields); - } - } - - @Override - public void onFailure(Throwable caught) { - callback.onFailure(caught); - } - }); + dispatcher.execute(new DMRAction(operation), new DescriptionsCallback(fieldNames, callback)); } public interface AddressCallback @@ -169,45 +139,54 @@ public void getMetricDescriptions( operation.get(OP).set(READ_RESOURCE_DESCRIPTION_OPERATION); operation.get(LOCALE).set(getLocale()); - dispatcher.execute(new DMRAction(operation), new AsyncCallback() { - @Override - public void onSuccess(DMRResponse result) { - ModelNode response = result.get(); + dispatcher.execute(new DMRAction(operation), new DescriptionsCallback(attributeNames, callback)); + } + private class DescriptionsCallback implements AsyncCallback { + private List fieldNames; + private AsyncCallback> callback; - if(response.isFailure()) - { - Log.debug(response.toString()); - onFailure(new Exception(response.getFailureDescription())); - } - else - { - LinkedList fields = new LinkedList(); + public DescriptionsCallback(List fieldNames, AsyncCallback> callback) { + this.fieldNames = fieldNames; + this.callback = callback; + } + + @Override + public void onSuccess(DMRResponse result) { + ModelNode response = result.get(); - ModelNode payload = response.get(RESULT); - ModelNode descriptionModel = null; - if(ModelType.LIST.equals(payload.getType())) - descriptionModel = payload.asList().get(0); - else - descriptionModel = payload; + if(response.isFailure()) + { + Log.debug(response.toString()); + onFailure(new Exception(response.getFailureDescription())); + } + else + { + LinkedList fields = new LinkedList(); + ModelNode payload = response.get(RESULT); - matchSubElements(descriptionModel, attributeNames, fields); + ModelNode descriptionModel = null; + if(ModelType.LIST.equals(payload.getType())) + descriptionModel = payload.asList().get(0); + else + descriptionModel = payload; - callback.onSuccess(fields); - } - } + matchSubElements(descriptionModel, fieldNames, fields); - @Override - public void onFailure(Throwable caught) { - callback.onFailure(caught); + callback.onSuccess(getOrderedFields(fieldNames, fields)); } - }); - } + } + + @Override + public void onFailure(Throwable caught) { + callback.onFailure(caught); + } + } private static void matchSubElements(ModelNode descriptionModel, List fieldNames, LinkedList fields) { @@ -279,4 +258,19 @@ private static void matchSubElements(ModelNode descriptionModel, List fi Log.error("Failed to read help descriptionModel", e); } } + + /** + * returns the fields in the requested order + */ + private List getOrderedFields(List fieldNames, List fields) { + List orderedFields = new LinkedList<>(); + for (Lookup fieldName : fieldNames) { + for (FieldDesc field : fields) { + if (fieldName.getJavaName().equals(field.getRef())) + orderedFields.add(field); + } + } + + return orderedFields; + } }