modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java
| 49 ++++++++--
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/resource/FavoriteResourcesPortlet.java
| 14 +-
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java
| 2
3 files changed, 50 insertions(+), 15 deletions(-)
New commits:
commit 1840dab79a64b517546aeb89ca2492bfb807d458
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 9 13:22:14 2011 -0500
fix table refresh so it maintains the initial criteria even when entering additional
search criteria from the search bar
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 7b5d087..ce0754e 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
@@ -458,7 +458,7 @@ public class Table<DS extends RPCDataSource> extends
LocatableHLayout implements
IButton refreshButton = new
LocatableIButton(extendLocatorId("Refresh"), MSG.common_button_refresh());
refreshButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
- listGrid.invalidateCache();
+ refresh();
}
});
footer.addMember(refreshButton);
@@ -545,22 +545,54 @@ public class Table<DS extends RPCDataSource> extends
LocatableHLayout implements
private ArrayList<Integer> fieldSizes = new ArrayList<Integer>();
- public void refresh(Criteria criteria) {
+ /**
+ * Refreshes the list grid with the explicit criteria.
+ * Usually you do not want to call this - to maintain proper filtering
+ * and usage of the initial criteria, call {@link #refresh()} instead.
+ *
+ * @param criteria the criteria to use to refresh the table with
+ */
+ protected void refresh(Criteria criteria) {
if (null != this.listGrid) {
- this.listGrid.invalidateCache();
this.listGrid.setCriteria(criteria);
+ this.listGrid.invalidateCache();
this.listGrid.markForRedraw();
}
}
+ /**
+ * Refreshes the list grid so it reloads. This attempts to maintain
+ * the original criteria along with any current filter settings.
+ */
public void refresh() {
- // if this table has a filter form (table filters OR search bar)
- // we need to refresh it as per the filtering. If there are no filters,
- // just do a allow for a default refresh by simply invalidating the cache
if (null != this.listGrid) {
+ // if this table has a filter form (table filters OR search bar)
+ // we need to refresh it as per the filtering.
if (this.filterForm != null && this.filterForm.hasContent()) {
- refresh(this.filterForm.getValuesAsCriteria());
+ Criteria filterFormCriteria = this.filterForm.getValuesAsCriteria();
+ if (this.criteria == null) {
+ // there was no initial criteria, filter based on the filter form
data only
+ refresh(filterFormCriteria);
+ } else {
+ // there is both initial criteria and filters. We need criteria that
combines both.
+ Criteria fullCriteria = new Criteria();
+ String[] criteriaAttribs = this.criteria.getAttributes(); // the
initial criteria attributes
+ for (String attribName : criteriaAttribs) {
+ Object attribValue =
this.criteria.getAttributeAsObject(attribName);
+ fullCriteria.setAttribute(attribName, attribValue);
+ }
+ if (filterFormCriteria != null) {
+ criteriaAttribs = filterFormCriteria.getAttributes(); // the
filter form criteria attributes (like the search bar)
+ for (String attribName : criteriaAttribs) {
+ Object attribValue =
filterFormCriteria.getAttributeAsObject(attribName);
+ fullCriteria.setAttribute(attribName, attribValue);
+ }
+ }
+ refresh(fullCriteria);
+ }
} else {
+ // If there are no filters, just do a default refresh by simply
invalidating the cache.
+ // This should reuse the original initial criteria.
this.listGrid.invalidateCache();
this.listGrid.markForRedraw();
}
@@ -862,6 +894,7 @@ public class Table<DS extends RPCDataSource> extends
LocatableHLayout implements
String name = searchBarItem.getName();
searchBarItem.setName(name + "_hidden");
hiddenItem = new HiddenItem(name);
+ hiddenItem.setValue(searchBarItem.getSearchBar().getValue());
}
}
@@ -876,7 +909,7 @@ public class Table<DS extends RPCDataSource> extends
LocatableHLayout implements
}
private void fetchFilteredTableData() {
- table.refresh(getValuesAsCriteria());
+ table.refresh();
}
public void onKeyPress(KeyPressEvent event) {
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/resource/FavoriteResourcesPortlet.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/resource/FavoriteResourcesPortlet.java
index d861fad..f14d791 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/resource/FavoriteResourcesPortlet.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/inventory/resource/FavoriteResourcesPortlet.java
@@ -61,17 +61,14 @@ public class FavoriteResourcesPortlet extends ResourceSearchView
implements Auto
private Timer refreshTimer;
public FavoriteResourcesPortlet(String locatorId) {
- super(locatorId);
+ super(locatorId, createInitialCriteria());
setOverflow(Overflow.VISIBLE);
setShowHeader(false);
setShowFooter(false);
}
- @Override
- protected void configureTable() {
- super.configureTable();
-
+ private static Criteria createInitialCriteria() {
Set<Integer> favoriteIds =
UserSessionManager.getUserPreferences().getFavoriteResources();
Integer[] favArray = favoriteIds.toArray(new Integer[favoriteIds.size()]);
@@ -83,7 +80,12 @@ public class FavoriteResourcesPortlet extends ResourceSearchView
implements Auto
criteria.addCriteria("resourceIds", favArray);
}
- refresh(criteria);
+ return criteria;
+ }
+
+ @Override
+ protected void configureTable() {
+ super.configureTable();
getListGrid().addFieldStateChangedHandler(new FieldStateChangedHandler() {
public void onFieldStateChanged(FieldStateChangedEvent
fieldStateChangedEvent) {
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java
index 2517d3e..465b37c 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java
@@ -138,7 +138,7 @@ public class TaggedView extends LocatableVLayout implements
BookmarkableView {
}
for (Table t : viewsWithTags) {
- t.refresh(criteria);
+ t.refresh();
}
}
Show replies by date