[rhq] modules/enterprise

Jiri Kremser jkremser at fedoraproject.org
Wed Aug 29 12:16:14 UTC 2012


 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java                         |   45 +++
 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceCompositeSearchView.java |  116 ++++++----
 2 files changed, 116 insertions(+), 45 deletions(-)

New commits:
commit 74704eda37bce26278fa089437d98bcd590b4317
Author: Jirka Kremser <jkremser at redhat.com>
Date:   Wed Aug 29 14:15:26 2012 +0200

    [BZ 814305 - Dealing with singletons in inventory] Refresh button now takes into consideration the already created singletons and they are not populated in the create/import child combobox

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 2eea340..d539136 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
@@ -597,7 +597,7 @@ public class Table<DS extends RPCDataSource> extends LocatableHLayout implements
             } else {
                 // menu action
                 LocatableMenu menu = new LocatableMenu(tableAction.getLocatorId() + "Menu");
-                final Map<String, ? extends Object> menuEntries = tableAction.getValueMap();
+                final Map<String, Object> menuEntries = tableAction.getValueMap();
                 for (final String key : menuEntries.keySet()) {
                     MenuItem item = new MenuItem(key);
                     item.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
@@ -980,7 +980,7 @@ public class Table<DS extends RPCDataSource> extends LocatableHLayout implements
      * completion. Failure to do so may leave the widgets disabled.
      */
     public void addTableAction(String locatorId, String title, String confirmation,
-        LinkedHashMap<String, ? extends Object> valueMap, TableAction tableAction) {
+        Map<String, Object> valueMap, TableAction tableAction) {
         // If the specified locator ID is qualified, strip off the ancestry prefix, so we can make sure its locator ID
         // extends the footer's locator ID as it should.
         int underscoreIndex = locatorId.lastIndexOf('_');
@@ -995,6 +995,37 @@ public class Table<DS extends RPCDataSource> extends LocatableHLayout implements
         tableActions.add(info);
     }
 
+    /**
+     * Updates the list of table's associated actions <code>tableActions</code>.
+     * It automatically updates the gui by calling <code>drawFooter()</code> provided the table has been initialized.
+     * 
+     * Note: To prevent user action while a current action completes, all widgets on the footer are disabled
+     * when footer actions take place, typically a button click. It is up to the action to ensure the page
+     * (via refresh() or CoreGUI.refresh()) or footer (via refreshTableActions) are refreshed as needed at action
+     * completion. Failure to do so may leave the widgets disabled.
+     * 
+     * @param title the title of a modified action
+     * @param valueMap the map containing the tuples with name of a select item and <code>actionValue</code> which is 
+     * then passed to <code>tableAction.executeAction()</code>; use the <code>LinkedHashMap</code> if you want to 
+     * preserve the order of map items
+     * @param tableAction the tableAction object (on this object the <code>executeAction()</code> is actually invoked)
+     */
+    public void updateTableAction(String title, Map<String, Object> valueMap,
+        TableAction tableAction) {
+        if (title == null) {
+            return;
+        }
+        for (TableActionInfo info : tableActions) {
+            if (title.equals(info.getTitle())) {
+                if (valueMap != null) info.setValueMap(valueMap);
+                if (tableAction != null) info.setAction(tableAction);
+                // the action listeners have to be re-added
+                if (isInitialized()) drawFooter();
+                break;
+            }
+        }
+    }
+
     public void setListGridDoubleClickHandler(DoubleClickHandler handler) {
         doubleClickHandler = handler;
     }
@@ -1247,12 +1278,12 @@ public class Table<DS extends RPCDataSource> extends LocatableHLayout implements
         private String locatorId;
         private String title;
         private String confirmMessage;
-        private LinkedHashMap<String, ? extends Object> valueMap;
+        private Map<String, Object> valueMap;
         private TableAction action;
         private Canvas actionCanvas;
 
         protected TableActionInfo(String locatorId, String title, String confirmMessage,
-            LinkedHashMap<String, ? extends Object> valueMap, TableAction action) {
+            Map<String, Object> valueMap, TableAction action) {
             this.locatorId = locatorId;
             this.title = title;
             this.confirmMessage = confirmMessage;
@@ -1272,9 +1303,13 @@ public class Table<DS extends RPCDataSource> extends LocatableHLayout implements
             return confirmMessage;
         }
 
-        public LinkedHashMap<String, ? extends Object> getValueMap() {
+        public Map<String, Object> getValueMap() {
             return valueMap;
         }
+        
+        public void setValueMap(Map<String, Object> valueMap) {
+            this.valueMap = valueMap;
+        }
 
         public Canvas getActionCanvas() {
             return actionCanvas;
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceCompositeSearchView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceCompositeSearchView.java
index bb43f26..265778b 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceCompositeSearchView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceCompositeSearchView.java
@@ -89,41 +89,49 @@ public class ResourceCompositeSearchView extends ResourceSearchView {
         super.onInit();
 
         // To properly filter Create Child and Import menus we need existing singleton child resources. If the
-        // user has creat permission and the parent type has singleton child types and creatable or importable child
+        // user has create permission and the parent type has singleton child types and creatable or importable child
         // types, perform an async call to fetch the singleton children. If we make the async call don't declare this
-        // instance initialized until after it completesas we must  have the children before the menu buttons can be drawn.
+        // instance initialized until after it completes as we must have the children before the menu buttons can be drawn.
 
         final Resource parentResource = parentResourceComposite.getResource();
         ResourceType parentType = parentResource.getResourceType();
-
         creatableChildTypes = getCreatableChildTypes(parentType);
         importableChildTypes = getImportableChildTypes(parentType);
         hasCreatableTypes = !creatableChildTypes.isEmpty();
         hasImportableTypes = !importableChildTypes.isEmpty();
-        singletonChildren = new ArrayList(); // initialize to non-null
+        refreshSingletons(parentResource, null);
+        
+    }
+    
+    private void refreshSingletons(final Resource parentResource, final AsyncCallback<PageList<Resource>> callback) {
+        singletonChildren = new ArrayList<Resource>(); // initialize to non-null
 
-        Integer[] singletonChildTypes = getSingletonChildTypes(parentType);
+        Integer[] singletonChildTypes = getSingletonChildTypes(parentResource.getResourceType());
 
         if (canCreate && singletonChildTypes.length > 0 && (hasCreatableTypes || hasImportableTypes)) {
             ResourceCriteria criteria = new ResourceCriteria();
             criteria.addFilterParentResourceId(parentResource.getId());
             criteria.addFilterResourceTypeIds(singletonChildTypes);
-            GWTServiceLookup.getResourceService().findResourcesByCriteria(criteria,
-                new AsyncCallback<PageList<Resource>>() {
-
-                    @Override
-                    public void onSuccess(PageList<Resource> result) {
-                        singletonChildren = result;
-                        initialized = true;
+            GWTServiceLookup.getResourceService().findResourcesByCriteria(criteria, new AsyncCallback<PageList<Resource>>() {
+
+                @Override
+                public void onSuccess(PageList<Resource> result) {
+                    singletonChildren = result;
+                    initialized = true;
+                    if (callback != null) {
+                        callback.onSuccess(result);
                     }
+                }
 
-                    @Override
-                    public void onFailure(Throwable caught) {
-                        Log.error("Failed to load child resources for [" + parentResource + "]", caught);
-                        initialized = true;
+                @Override
+                public void onFailure(Throwable caught) {
+                    Log.error("Failed to load child resources for [" + parentResource + "]", caught);
+                    initialized = true;
+                    if (callback != null) {
+                        callback.onFailure(caught);
                     }
-                });
-
+                }
+            });
         } else {
             initialized = true;
         }
@@ -196,34 +204,38 @@ public class ResourceCompositeSearchView extends ResourceSearchView {
                 }
             });
 
-        addImportAndCreateButtons();
+        addImportAndCreateButtons(false);
 
         super.configureTable();
     }
 
     @SuppressWarnings("unchecked")
-    private void addImportAndCreateButtons() {
+    private void addImportAndCreateButtons(boolean override) {
 
         final Resource parentResource = parentResourceComposite.getResource();
         ResourceType parentType = parentResource.getResourceType();
 
         // Create Child Menu and Manual Import Menu
         if (canCreate && (hasCreatableTypes || hasImportableTypes)) {
-
             if (hasCreatableTypes) {
                 Map<String, ResourceType> displayNameMap = getDisplayNames(creatableChildTypes);
                 LinkedHashMap<String, ResourceType> createTypeValueMap = new LinkedHashMap<String, ResourceType>(
                     displayNameMap);
                 removeExistingSingletons(singletonChildren, createTypeValueMap);
-                addTableAction(extendLocatorId("CreateChild"), MSG.common_button_create_child(), null,
-                    createTypeValueMap, new AbstractTableAction(TableActionEnablement.ALWAYS) {
-                        public void executeAction(ListGridRecord[] selection, Object actionValue) {
-                            ResourceFactoryCreateWizard.showCreateWizard(parentResource, (ResourceType) actionValue);
-                            // we can refresh the table buttons immediately since the wizard is a dialog, the
-                            // user can't access enabled buttons anyway.
-                            ResourceCompositeSearchView.this.refreshTableInfo();
-                        }
-                    });
+                AbstractTableAction createAction = new AbstractTableAction(TableActionEnablement.ALWAYS) {
+                    public void executeAction(ListGridRecord[] selection, Object actionValue) {
+                        ResourceFactoryCreateWizard.showCreateWizard(parentResource, (ResourceType) actionValue);
+                        // we can refresh the table buttons immediately since the wizard is a dialog, the
+                        // user can't access enabled buttons anyway.
+                        ResourceCompositeSearchView.this.refreshTableInfo();
+                    }
+                };
+                if (override) {
+                    updateTableAction(MSG.common_button_create_child(), createTypeValueMap, createAction);
+                } else {
+                    addTableAction(extendLocatorId("CreateChild"), MSG.common_button_create_child(), null,
+                        createTypeValueMap, createAction);
+                }
             }
 
             if (hasImportableTypes) {
@@ -231,18 +243,23 @@ public class ResourceCompositeSearchView extends ResourceSearchView {
                 LinkedHashMap<String, ResourceType> importTypeValueMap = new LinkedHashMap<String, ResourceType>(
                     displayNameMap);
                 removeExistingSingletons(singletonChildren, importTypeValueMap);
-                addTableAction(extendLocatorId("Import"), MSG.common_button_import(), null, importTypeValueMap,
-                    new AbstractTableAction(TableActionEnablement.ALWAYS) {
-                        public void executeAction(ListGridRecord[] selection, Object actionValue) {
-                            ResourceFactoryImportWizard.showImportWizard(parentResource, (ResourceType) actionValue);
-                            // we can refresh the table buttons immediately since the wizard is a dialog, the
-                            // user can't access enabled buttons anyway.
-                            ResourceCompositeSearchView.this.refreshTableInfo();
-                        }
-                    });
+                AbstractTableAction importAction = new AbstractTableAction(TableActionEnablement.ALWAYS) {
+                    public void executeAction(ListGridRecord[] selection, Object actionValue) {
+                        ResourceFactoryImportWizard.showImportWizard(parentResource, (ResourceType) actionValue);
+                        // we can refresh the table buttons immediately since the wizard is a dialog, the
+                        // user can't access enabled buttons anyway.
+                        ResourceCompositeSearchView.this.refreshTableInfo();
+                    }
+                };
+                if (override) {
+                    updateTableAction(MSG.common_button_import(), importTypeValueMap, importAction);
+                } else {
+                    addTableAction(extendLocatorId("Import"), MSG.common_button_import(), null, importTypeValueMap,
+                        importAction);
+                }
             }
 
-        } else {
+        } else if (!override) {
             if (!canCreate && hasCreatableTypes) {
                 addTableAction(extendLocatorId("CreateChild"), MSG.common_button_create_child(),
                     new AbstractTableAction(TableActionEnablement.NEVER) {
@@ -261,6 +278,7 @@ public class ResourceCompositeSearchView extends ResourceSearchView {
             }
         }
     }
+   
 
     private void removeExistingSingletons(List<Resource> singletonChildren, Map<String, ResourceType> displayNameMap) {
 
@@ -359,5 +377,23 @@ public class ResourceCompositeSearchView extends ResourceSearchView {
         return new ResourceCompositeSearchView(locatorId, parentResourceComposite, new Criteria("parentId",
             String.valueOf(parentResourceComposite.getResource().getId())), MSG.view_tabs_common_child_resources());
     }
+    
+    @Override
+    public void refresh() {
+        refreshSingletons(parentResourceComposite.getResource(), new AsyncCallback<PageList<Resource>>() {
+
+            @Override
+            public void onSuccess(PageList<Resource> result) {
+                addImportAndCreateButtons(true);
+                ResourceCompositeSearchView.super.refresh();
+            }
+
+            @Override
+            public void onFailure(Throwable caught) {
+                ResourceCompositeSearchView.super.refresh();
+            }
+        });
+
+    }
 
 }




More information about the rhq-commits mailing list