Permalink
Browse files

Added the 'filter by name' text box so that users can now search for

artifacts by name (with * as the wildcard char).
  • Loading branch information...
EricWittmann committed Nov 12, 2012
1 parent 37e3ebc commit 7dfede496cdeb602b9a7f60e87b5d9a817964041
@@ -27,7 +27,7 @@
import org.overlord.sramp.ui.shared.beans.ArtifactSummary;
import org.overlord.sramp.ui.shared.beans.PageInfo;
import org.overlord.sramp.ui.shared.rsvcs.RemoteServiceException;
-import org.overlord.sramp.ui.shared.types.ArtifactFilter;
+import org.overlord.sramp.ui.shared.types.ArtifactTypeFilter;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
@@ -38,14 +38,14 @@
* @author eric.wittmann@redhat.com
*/
public class BrowseActivity extends AbstractActivity<BrowsePlace, IBrowseView> implements IBrowseActivity {
-
+
/**
* Constructor.
*/
public BrowseActivity(BrowsePlace place, IClientFactory clientFactory) {
super(place, clientFactory);
}
-
+
/**
* @see org.overlord.sramp.ui.client.activities.AbstractActivity#createView(com.google.gwt.event.shared.EventBus)
*/
@@ -55,26 +55,26 @@ protected IBrowseView createView(EventBus eventBus) {
view.setActivity(this);
return view;
}
-
+
/**
* @see org.overlord.sramp.ui.client.activities.AbstractActivity#doStart(com.google.gwt.user.client.ui.AcceptsOneWidget, com.google.gwt.event.shared.EventBus)
*/
@Override
protected void doStart(AcceptsOneWidget panel, EventBus eventBus) {
getView().onQueryStarting(getPlace());
-
+
final PageInfo page = new PageInfo();
page.setPage(getPlace().getPage(0));
page.setPageSize(getPlace().getPageSize(getView().getDefaultPageSize()));
page.setOrderBy(getPlace().getOrderBy(getView().getDefaultOrderBy()));
page.setAscending(getPlace().isAscending(Boolean.TRUE));
- ArtifactFilter filter = null;
+ ArtifactTypeFilter filter = null;
if (getPlace().getTypeFilter() == null)
- filter = ArtifactFilter.all;
+ filter = ArtifactTypeFilter.all;
else
- filter = ArtifactFilter.valueOf(getPlace().getTypeFilter());
-
- getService(IQueryService.class).findArtifactsAsync(page, filter, new RemoteServiceAsyncCallback<List<ArtifactSummary>>() {
+ filter = ArtifactTypeFilter.valueOf(getPlace().getTypeFilter());
+
+ getService(IQueryService.class).findArtifactsAsync(page, filter, getPlace().getNameFilter(), new RemoteServiceAsyncCallback<List<ArtifactSummary>>() {
@Override
public void onSuccess(List<ArtifactSummary> result) {
getView().onQueryComplete(result, result.size() == page.getPageSize());
@@ -85,7 +85,7 @@ protected void onRemoteServiceFailure(RemoteServiceException caught) {
}
});
}
-
+
/**
* @see org.overlord.sramp.ui.client.activities.AbstractActivity#updateBreadcrumb(org.overlord.sramp.ui.client.widgets.BreadcrumbPanel)
*/
@@ -21,33 +21,50 @@
/**
* Place: /dashboard/browse
- *
+ *
* @author eric.wittmann@redhat.com
*/
public class BrowsePlace extends AbstractPagedPlace implements Cloneable {
-
+
+ private String nameFilter;
private String typeFilter;
/**
* Constructor.
*/
public BrowsePlace() {
- this(null, null, null, null, null);
+ this(null, null, null, null, null, null);
}
-
+
/**
* Constructor.
+ * @param nameFilter
* @param page
* @param pageSize
* @param orderBy
* @param ascending
* @param typeFilter
*/
- public BrowsePlace(Integer page, Integer pageSize, String orderBy, Boolean ascending, String typeFilter) {
+ public BrowsePlace(String nameFilter, Integer page, Integer pageSize, String orderBy, Boolean ascending, String typeFilter) {
super(page, pageSize, orderBy, ascending);
+ setNameFilter(nameFilter);
setTypeFilter(typeFilter);
}
+ /**
+ * @return the nameFilter
+ */
+ public String getNameFilter() {
+ return nameFilter;
+ }
+
+ /**
+ * @param nameFilter the nameFilter to set
+ */
+ public void setNameFilter(String nameFilter) {
+ this.nameFilter = nameFilter;
+ }
+
/**
* @return the typeFilter
*/
@@ -61,13 +78,14 @@ public String getTypeFilter() {
public void setTypeFilter(String typeFilter) {
this.typeFilter = typeFilter;
}
-
+
/**
* Creates a new copy of this place.
* @see java.lang.Object#clone()
*/
public BrowsePlace clone() {
BrowsePlace copy = new BrowsePlace();
+ copy.setNameFilter(getNameFilter());
copy.setAscending(isAscending());
copy.setOrderBy(getOrderBy());
copy.setPage(getPage());
@@ -86,6 +104,11 @@ public boolean equals(Object obj) {
if (!super.equals(obj))
return false;
BrowsePlace other = (BrowsePlace) obj;
+ if (nameFilter == null) {
+ if (other.nameFilter != null)
+ return false;
+ } else if (!nameFilter.equals(other.nameFilter))
+ return false;
if (typeFilter == null) {
if (other.typeFilter != null)
return false;
@@ -103,7 +126,7 @@ public boolean equals(Object obj) {
*/
@Override
public String getToken(BrowsePlace place) {
- return PlaceUtils.createPlaceToken(place, "tf", place.getTypeFilter());
+ return PlaceUtils.createPlaceToken(place, "nf", place.getNameFilter(), "tf", place.getTypeFilter());
}
/**
@@ -112,8 +135,10 @@ public String getToken(BrowsePlace place) {
@Override
public BrowsePlace getPlace(String token) {
Map<String, String> params = PlaceUtils.parsePlaceToken(token);
+ String nameFilter = params.get("nf");
String typeFilter = params.get("tf");
BrowsePlace place = new BrowsePlace();
+ place.setNameFilter(nameFilter);
place.setTypeFilter(typeFilter);
PlaceUtils.fillPagedPlace(place, params);
return place;
@@ -20,7 +20,7 @@
import org.overlord.sramp.ui.client.services.IService;
import org.overlord.sramp.ui.shared.beans.ArtifactSummary;
import org.overlord.sramp.ui.shared.beans.PageInfo;
-import org.overlord.sramp.ui.shared.types.ArtifactFilter;
+import org.overlord.sramp.ui.shared.types.ArtifactTypeFilter;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -34,9 +34,10 @@
/**
* Finds artifacts using the remote query service.
* @param page
- * @param filter
+ * @param typeFilter
+ * @param nameFilter
* @param callback
*/
- public void findArtifactsAsync(PageInfo page, ArtifactFilter filter, AsyncCallback<List<ArtifactSummary>> callback);
-
+ public void findArtifactsAsync(PageInfo page, ArtifactTypeFilter typeFilter, String nameFilter, AsyncCallback<List<ArtifactSummary>> callback);
+
}
@@ -22,7 +22,7 @@
import org.overlord.sramp.ui.shared.beans.PageInfo;
import org.overlord.sramp.ui.shared.rsvcs.IQueryRemoteService;
import org.overlord.sramp.ui.shared.rsvcs.IQueryRemoteServiceAsync;
-import org.overlord.sramp.ui.shared.types.ArtifactFilter;
+import org.overlord.sramp.ui.shared.types.ArtifactTypeFilter;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -33,7 +33,7 @@
* @author eric.wittmann@redhat.com
*/
public class QueryService extends AbstractService implements IQueryService {
-
+
private final IQueryRemoteServiceAsync queryRemoteService = GWT.create(IQueryRemoteService.class);
/**
@@ -43,12 +43,12 @@ public QueryService() {
}
/**
- * @see org.overlord.sramp.ui.client.services.query.IQueryService#findArtifactsAsync(org.overlord.sramp.ui.shared.beans.PageInfo, org.overlord.sramp.ui.shared.types.ArtifactFilter, com.google.gwt.user.client.rpc.AsyncCallback)
+ * @see org.overlord.sramp.ui.client.services.query.IQueryService#findArtifactsAsync(org.overlord.sramp.ui.shared.beans.PageInfo, org.overlord.sramp.ui.shared.types.ArtifactTypeFilter, java.lang.String, com.google.gwt.user.client.rpc.AsyncCallback)
*/
@Override
- public void findArtifactsAsync(PageInfo page, ArtifactFilter filter,
+ public void findArtifactsAsync(PageInfo page, ArtifactTypeFilter typeFilter, String nameFilter,
AsyncCallback<List<ArtifactSummary>> callback) {
- queryRemoteService.findArtifacts(page, filter, callback);
+ queryRemoteService.findArtifacts(page, typeFilter, nameFilter, callback);
}
-
+
}
@@ -20,16 +20,26 @@
import org.overlord.sramp.ui.client.activities.IBrowseActivity;
import org.overlord.sramp.ui.client.places.AbstractPagedPlace;
import org.overlord.sramp.ui.client.places.BrowsePlace;
+import org.overlord.sramp.ui.client.services.Services;
+import org.overlord.sramp.ui.client.services.place.IPlaceService;
import org.overlord.sramp.ui.client.widgets.ArtifactSummaryPanel;
import org.overlord.sramp.ui.client.widgets.DataTable;
import org.overlord.sramp.ui.client.widgets.DataTableWithPager;
import org.overlord.sramp.ui.client.widgets.PlaceFilterPanel;
import org.overlord.sramp.ui.shared.beans.ArtifactSummary;
import org.overlord.sramp.ui.shared.rsvcs.RemoteServiceException;
-import org.overlord.sramp.ui.shared.types.ArtifactFilter;
+import org.overlord.sramp.ui.shared.types.ArtifactTypeFilter;
+import com.google.gwt.event.dom.client.ChangeEvent;
+import com.google.gwt.event.dom.client.ChangeHandler;
+import com.google.gwt.place.shared.Place;
import com.google.gwt.user.cellview.client.TextColumn;
+import com.google.gwt.user.client.History;
+import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.InlineLabel;
+import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
import com.google.gwt.view.client.SingleSelectionModel;
@@ -45,15 +55,16 @@
private static final String DEFAULT_ORDER_BY = "name";
private ArtifactDataTable artifacts;
- private PlaceFilterPanel<BrowsePlace> filterPanel;
+ private PlaceFilterPanel<BrowsePlace> typeFilterPanel;
+ private TextBox nameFilterBox;
private ArtifactSummaryPanel summaryPanel;
private BrowsePlace currentPlace;
/**
* Constructor.
*/
public BrowseView() {
- filterPanel = new PlaceFilterPanel<BrowsePlace>(i18n().translate("views.browse.filter-panel.label")) {
+ typeFilterPanel = new PlaceFilterPanel<BrowsePlace>(i18n().translate("views.browse.filter-panel.label")) {
@Override
protected boolean matches(BrowsePlace currentPlace, BrowsePlace targetPlace) {
String currentTypeFilter = currentPlace.getTypeFilter();
@@ -66,33 +77,65 @@ else if (currentTypeFilter != null && currentTypeFilter.equals(targetTypeFilter)
}
};
artifacts = createArtifactTable();
+ nameFilterBox = new TextBox();
+ nameFilterBox.addChangeHandler(new ChangeHandler() {
+ @Override
+ public void onChange(ChangeEvent event) {
+ BrowsePlace newPlace = currentPlace.clone();
+ newPlace.setNameFilter(nameFilterBox.getValue());
+ History.newItem(toHistoryToken(newPlace));
+ }
+ });
summaryPanel = new ArtifactSummaryPanel();
+ FlowPanel nameFilterPanel = new FlowPanel();
+ nameFilterPanel.setStyleName("filterPanel");
+ InlineLabel label = new InlineLabel("Filter by name:");
+ label.setStyleName("label");
+ nameFilterPanel.add(label);
+ nameFilterPanel.add(nameFilterBox);
+
+ VerticalPanel vpanel = new VerticalPanel();
+ vpanel.add(typeFilterPanel);
+ vpanel.add(nameFilterPanel);
+
HorizontalPanel hpanel = new HorizontalPanel();
hpanel.setWidth("100%");
- hpanel.add(filterPanel);
+ hpanel.add(vpanel);
hpanel.add(artifacts);
hpanel.add(summaryPanel);
- hpanel.setCellWidth(filterPanel, "175px");
+ hpanel.setCellWidth(vpanel, "175px");
hpanel.setCellWidth(summaryPanel, "300px");
this.initWidget(hpanel);
}
+ /**
+ * Creates a history token for the given {@link Place}.
+ * @param place the {@link Place} to tokenize
+ * @return the place token
+ */
+ private static String toHistoryToken(Place place) {
+ if (place == null)
+ return "";
+ IPlaceService placeService = Services.getServices().getService(IPlaceService.class);
+ return placeService.generatePlaceToken(place);
+ }
+
/**
* Called to configure the filters.
* @param currentPlace
*/
private void configureFilters(BrowsePlace currentPlace) {
- for (ArtifactFilter filter : ArtifactFilter.values()) {
+ for (ArtifactTypeFilter filter : ArtifactTypeFilter.values()) {
BrowsePlace p = currentPlace.clone();
p.setPage(null);
p.setTypeFilter(filter.getCode());
- this.filterPanel.addFilterOption(i18n().translate(filter.getI18nKey()), p);
+ this.typeFilterPanel.addFilterOption(i18n().translate(filter.getI18nKey()), p);
}
- this.filterPanel.setCurrentPlace(currentPlace);
+ this.typeFilterPanel.setCurrentPlace(currentPlace);
}
/**
@@ -142,6 +185,7 @@ public void onQueryStarting(BrowsePlace currentPlace) {
configureFilters(currentPlace);
this.currentPlace = currentPlace;
this.artifacts.reset();
+ this.nameFilterBox.setValue(currentPlace.getNameFilter());
}
/**
@@ -26,7 +26,7 @@
import org.overlord.sramp.ui.shared.beans.PageInfo;
import org.overlord.sramp.ui.shared.rsvcs.IQueryRemoteService;
import org.overlord.sramp.ui.shared.rsvcs.RemoteServiceException;
-import org.overlord.sramp.ui.shared.types.ArtifactFilter;
+import org.overlord.sramp.ui.shared.types.ArtifactTypeFilter;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
@@ -46,13 +46,19 @@ public QueryRemoteService() {
}
/**
- * @see org.overlord.sramp.ui.shared.rsvcs.IQueryRemoteService#findArtifacts(PageInfo, ArtifactFilter)
+ * @see org.overlord.sramp.ui.shared.rsvcs.IQueryRemoteService#findArtifacts(org.overlord.sramp.ui.shared.beans.PageInfo, org.overlord.sramp.ui.shared.types.ArtifactTypeFilter, java.lang.String)
*/
@Override
- public List<ArtifactSummary> findArtifacts(final PageInfo page, ArtifactFilter filter) throws RemoteServiceException {
+ public List<ArtifactSummary> findArtifacts(PageInfo page, ArtifactTypeFilter filter, String nameFilter)
+ throws RemoteServiceException {
try {
int startIndex = page.getPage() * page.getPageSize();
- QueryResultSet rset = SrampAtomApiClient.getInstance().query(filter.getQueryBase(), startIndex,
+ String query = filter.getQueryBase();
+ if (nameFilter != null) {
+ String criteria = nameFilter.replace("*", ".*").replace("'", "''");
+ query = query + "[fn:matches(@name, '" + criteria + "')]";
+ }
+ QueryResultSet rset = SrampAtomApiClient.getInstance().query(query, startIndex,
page.getPageSize(), page.getOrderBy(), page.isAscending());
List<ArtifactSummary> rval = new ArrayList<ArtifactSummary>();
for (org.overlord.sramp.client.query.ArtifactSummary entry : rset) {
Oops, something went wrong.

0 comments on commit 7dfede4

Please sign in to comment.