Skip to content
Snippets Groups Projects
Commit 3f1a353d authored by cramakri's avatar cramakri
Browse files

LMS-1415 Support for specifying arbitrary attributes and properties in the sample search url.

SVN: 15007
parent 1b7ea36a
No related branches found
No related tags found
No related merge requests found
Showing
with 319 additions and 190 deletions
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.client.web.client.application.locator;
import java.util.ArrayList;
import java.util.Map;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.user.client.rpc.AsyncCallback;
import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.DefaultTabItem;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.DispatcherHelper;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.ITabItem;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.ITabItemFactory;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.help.HelpPageIdentifier;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.help.HelpPageIdentifier.HelpPageAction;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.help.HelpPageIdentifier.HelpPageDomain;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IDisposableComponent;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.listener.OpenEntityDetailsTabAction;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.sample.SampleSearchHitGrid;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListSampleDisplayCriteria;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSetWithEntityTypes;
import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriterion;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchField;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleAttributeSearchFieldKind;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SearchCriteriaConnection;
class SampleSearchLocatorResolver
{
private final IViewContext<ICommonClientServiceAsync> viewContext;
private final ViewLocator locator;
SampleSearchLocatorResolver(IViewContext<ICommonClientServiceAsync> viewContext,
ViewLocator locator)
{
this.viewContext = viewContext;
this.locator = locator;
}
void openInitialEntitySearch() throws UserFailureException
{
openEntitySearch();
}
private void openEntitySearch()
{
ListSampleDisplayCriteria displayCriteria = getListSampleDisplayCriteria();
viewContext.getCommonService().listSamples(displayCriteria,
new OpenEntitySearchTabCallback(displayCriteria));
}
/**
* Convert the locator parameters into a ListSampleDisplayCriteria -- a LSDC is used to pass the
* search parameters to the server.
*/
private ListSampleDisplayCriteria getListSampleDisplayCriteria()
{
// Loop over the parameters and create a detailed search criteria for each parameter
// -- a parameter key could refer to an attribute (valid options known at compile time)
// -- or a property (valid options must be retrieved from server)
Map<String, String> parameters = locator.getParameters();
ArrayList<DetailedSearchCriterion> criterionList = new ArrayList<DetailedSearchCriterion>();
DetailedSearchCriteria searchCriteria = new DetailedSearchCriteria();
// Default to match all
searchCriteria.setConnection(SearchLocatorResolver.DEFAULT_MATCH_CONNECTION);
for (String key : parameters.keySet())
{
String value = parameters.get(key);
// The match key is handled separately
if (key.equals(SearchLocatorResolver.MATCH_KEY))
{
if (value.equalsIgnoreCase(SearchLocatorResolver.MATCH_ANY_VALUE))
{
searchCriteria.setConnection(SearchCriteriaConnection.MATCH_ANY);
}
} else if (key.equals("gwt.codesvr"))
{
// ignore this gwt keyword
} else
{
DetailedSearchCriterion searchCriterion = getSearchCriterionForKeyValue(key, value);
criterionList.add(searchCriterion);
}
}
// Default the search criteria if none is provided
if (criterionList.isEmpty())
{
DetailedSearchCriterion searchCriterion =
new DetailedSearchCriterion(DetailedSearchField
.createAttributeField(SampleAttributeSearchFieldKind.CODE),
SearchLocatorResolver.DEFAULT_SEARCH_STRING);
criterionList.add(searchCriterion);
}
searchCriteria.setCriteria(criterionList);
// Create a display criteria object for the search string
ListSampleDisplayCriteria displayCriteria = ListSampleDisplayCriteria.createForSearch();
displayCriteria.updateSearchCriteria(searchCriteria);
return displayCriteria;
}
/**
* Convert the key/value to a search criterion. The kind of field depends on whether the key
* refers to an attribute or property.
*/
private DetailedSearchCriterion getSearchCriterionForKeyValue(String key, String value)
{
DetailedSearchField field;
try
{
SampleAttributeSearchFieldKind attributeKind =
SampleAttributeSearchFieldKind.valueOf(key.toUpperCase());
field = DetailedSearchField.createAttributeField(attributeKind);
} catch (IllegalArgumentException ex)
{
// this is not an attribute
field = DetailedSearchField.createPropertyField(key.toUpperCase());
}
return new DetailedSearchCriterion(field, value);
}
private class OpenEntitySearchTabCallback implements
AsyncCallback<ResultSetWithEntityTypes<Sample>>
{
private final ListSampleDisplayCriteria displayCriteria;
private OpenEntitySearchTabCallback(ListSampleDisplayCriteria displayCriteria)
{
this.displayCriteria = displayCriteria;
}
public final void onFailure(Throwable caught)
{
// Error in the search -- notify the user
MessageBox.alert("Error", caught.getMessage(), null);
}
public final void onSuccess(ResultSetWithEntityTypes<Sample> result)
{
switch (result.getResultSet().getTotalLength())
{
// Nothing found -- notify the user
case 0:
MessageBox.alert("Error", "No samples matching criteria ["
+ displayCriteria.getSearchCriteria().toString() + "] were found.",
null);
break;
// One result found -- show it in the details view
case 1:
Sample sample = result.getResultSet().getList().get(0).getOriginalObject();
OpenEntityDetailsTabAction detailsAction =
new OpenEntityDetailsTabAction(sample, viewContext);
detailsAction.execute();
break;
// Multiple results found -- show them in a grid
default:
OpenEntitySearchGridTabAction searchAction =
new OpenEntitySearchGridTabAction(displayCriteria, viewContext);
DispatcherHelper.dispatchNaviEvent(searchAction);
break;
}
}
}
private static class OpenEntitySearchGridTabAction implements ITabItemFactory
{
private final ListSampleDisplayCriteria displayCriteria;
private final IViewContext<ICommonClientServiceAsync> viewContext;
private OpenEntitySearchGridTabAction(ListSampleDisplayCriteria displayCriteria,
IViewContext<ICommonClientServiceAsync> viewContext)
{
this.displayCriteria = displayCriteria;
this.viewContext = viewContext;
}
private String getMessage(String key)
{
return viewContext.getMessage(key);
}
private ITabItem createTab(String dictionaryMsgKey, IDisposableComponent component)
{
String title = getMessage(dictionaryMsgKey);
return DefaultTabItem.create(title, component, viewContext);
}
public ITabItem create()
{
// CRDEBUG
System.err.println(displayCriteria.getSearchCriteria().toString());
IDisposableComponent browser =
SampleSearchHitGrid.createWithInitialDisplayCriteria(viewContext,
displayCriteria);
return createTab(Dict.SAMPLE_SEARCH, browser);
}
public String getId()
{
return SampleSearchHitGrid.SEARCH_BROWSER_ID;
}
public HelpPageIdentifier getHelpPageIdentifier()
{
return new HelpPageIdentifier(HelpPageDomain.SAMPLE, HelpPageAction.SEARCH);
}
}
}
\ No newline at end of file
package ch.systemsx.cisd.openbis.generic.client.web.client.application.locator; package ch.systemsx.cisd.openbis.generic.client.web.client.application.locator;
import java.util.ArrayList;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.user.client.rpc.AsyncCallback;
import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.DefaultTabItem;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.DispatcherHelper;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.ITabItem;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.ITabItemFactory;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.help.HelpPageIdentifier;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.help.HelpPageIdentifier.HelpPageAction;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.help.HelpPageIdentifier.HelpPageDomain;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IDisposableComponent;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.listener.OpenEntityDetailsTabAction;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.sample.SampleSearchHitGrid;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListSampleDisplayCriteria;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSetWithEntityTypes;
import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException; import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException;
import ch.systemsx.cisd.openbis.generic.shared.basic.PermlinkUtilities; import ch.systemsx.cisd.openbis.generic.shared.basic.PermlinkUtilities;
import ch.systemsx.cisd.openbis.generic.shared.basic.SearchlinkUtilities;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriterion;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchField;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleAttributeSearchFieldKind;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SearchCriteriaConnection; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SearchCriteriaConnection;
/** /**
* ViewLocatorHandler for Permlink locators. * ViewLocatorHandler for Search locators.
* *
* @author Chandrasekhar Ramakrishnan * @author Chandrasekhar Ramakrishnan
*/ */
...@@ -42,7 +18,16 @@ public class SearchLocatorResolver extends AbstractViewLocatorResolver ...@@ -42,7 +18,16 @@ public class SearchLocatorResolver extends AbstractViewLocatorResolver
private final static String SEARCH_ACTION = ViewLocator.SEARCH_ACTION; private final static String SEARCH_ACTION = ViewLocator.SEARCH_ACTION;
private static final String DEFAULT_SEARCH_STRING = "*"; protected static final String DEFAULT_SEARCH_STRING = "*";
protected static final String MATCH_KEY = "searchmatch";
protected static final String MATCH_ANY_VALUE = "any";
protected static final String MATCH_ALL_VALUE = "all";
protected static final SearchCriteriaConnection DEFAULT_MATCH_CONNECTION =
SearchCriteriaConnection.MATCH_ALL;
public SearchLocatorResolver(IViewContext<ICommonClientServiceAsync> viewContext) public SearchLocatorResolver(IViewContext<ICommonClientServiceAsync> viewContext)
{ {
...@@ -52,154 +37,24 @@ public class SearchLocatorResolver extends AbstractViewLocatorResolver ...@@ -52,154 +37,24 @@ public class SearchLocatorResolver extends AbstractViewLocatorResolver
public void resolve(ViewLocator locator) throws UserFailureException public void resolve(ViewLocator locator) throws UserFailureException
{ {
// If a searchlink has been specified, open a search on the specified object
String searchEntityKindValueOrNull = locator.tryGetEntity(); String searchEntityKindValueOrNull = locator.tryGetEntity();
String codeStringOrNull = if (null == searchEntityKindValueOrNull)
locator.getParameters().get(SearchlinkUtilities.CODE_PARAMETER_KEY); return;
if (null != searchEntityKindValueOrNull)
{
openInitialEntitySearch(searchEntityKindValueOrNull, codeStringOrNull);
}
}
private void openInitialEntitySearch(String entityKindValue, String codeStringOrNull) // Find the specific resolver based on entity type
throws UserFailureException EntityKind entityKind = getEntityKind(searchEntityKindValueOrNull);
{ if (EntityKind.SAMPLE == entityKind)
EntityKind entityKind = getEntityKind(entityKindValue); {
if (EntityKind.SAMPLE != entityKind) SampleSearchLocatorResolver resolver =
new SampleSearchLocatorResolver(viewContext, locator);
resolver.openInitialEntitySearch();
} else
{ {
throw new UserFailureException( throw new UserFailureException(
"URLs for searching openBIS only support SAMPLE searches. Entity " + entityKind "URLs for searching openBIS only support SAMPLE searches. Entity " + entityKind
+ " is not supported."); + " is not supported.");
} }
if (codeStringOrNull != null)
{
openEntitySearch(entityKind, codeStringOrNull);
} else
{
// default the search string
openEntitySearch(entityKind, DEFAULT_SEARCH_STRING);
}
}
private void openEntitySearch(EntityKind entityKind, String codeString)
{
ListSampleDisplayCriteria displayCriteria =
getListSampleDisplayCriteriaForCodeString(codeString);
viewContext.getCommonService().listSamples(displayCriteria,
new OpenEntitySearchTabCallback(codeString, displayCriteria));
}
/**
* Convert the code into a ListSampleDisplayCriteria -- a LSDC is used to pass the search
* parameters to the server.
*/
private ListSampleDisplayCriteria getListSampleDisplayCriteriaForCodeString(String codeString)
{
// Create a display criteria object for the search string
ListSampleDisplayCriteria displayCriteria = ListSampleDisplayCriteria.createForSearch();
DetailedSearchCriterion searchCriterion =
new DetailedSearchCriterion(DetailedSearchField
.createAttributeField(SampleAttributeSearchFieldKind.CODE), codeString);
DetailedSearchCriteria searchCriteria = new DetailedSearchCriteria();
searchCriteria.setConnection(SearchCriteriaConnection.MATCH_ALL);
ArrayList<DetailedSearchCriterion> criterionList = new ArrayList<DetailedSearchCriterion>();
criterionList.add(searchCriterion);
searchCriteria.setCriteria(criterionList);
displayCriteria.updateSearchCriteria(searchCriteria);
return displayCriteria;
}
private class OpenEntitySearchTabCallback implements
AsyncCallback<ResultSetWithEntityTypes<Sample>>
{
private final String codeString;
private final ListSampleDisplayCriteria displayCriteria;
private OpenEntitySearchTabCallback(String codeString,
ListSampleDisplayCriteria displayCriteria)
{
this.codeString = codeString;
this.displayCriteria = displayCriteria;
}
public final void onFailure(Throwable caught)
{
// Error in the search -- notify the user
MessageBox.alert("Error", caught.getMessage(), null);
}
public final void onSuccess(ResultSetWithEntityTypes<Sample> result)
{
switch (result.getResultSet().getTotalLength())
{
// Nothing found -- notify the user
case 0:
MessageBox.alert("Error",
"No samples with code " + codeString + " were found.", null);
break;
// One result found -- show it in the details view
case 1:
Sample sample = result.getResultSet().getList().get(0).getOriginalObject();
OpenEntityDetailsTabAction detailsAction =
new OpenEntityDetailsTabAction(sample, viewContext);
detailsAction.execute();
break;
// Multiple results found -- show them in a grid
default:
OpenEntitySearchGridTabAction searchAction =
new OpenEntitySearchGridTabAction(codeString, displayCriteria);
DispatcherHelper.dispatchNaviEvent(searchAction);
break;
}
}
}
private class OpenEntitySearchGridTabAction implements ITabItemFactory
{
private final ListSampleDisplayCriteria displayCriteria;
private OpenEntitySearchGridTabAction(String codeString,
ListSampleDisplayCriteria displayCriteria)
{
this.displayCriteria = displayCriteria;
}
private String getMessage(String key)
{
return viewContext.getMessage(key);
}
private ITabItem createTab(String dictionaryMsgKey, IDisposableComponent component)
{
String title = getMessage(dictionaryMsgKey);
return DefaultTabItem.create(title, component, viewContext);
}
public ITabItem create()
{
IDisposableComponent browser =
SampleSearchHitGrid.createWithInitialDisplayCriteria(viewContext,
displayCriteria);
return createTab(Dict.SAMPLE_SEARCH, browser);
}
public String getId()
{
return SampleSearchHitGrid.SEARCH_BROWSER_ID;
}
public HelpPageIdentifier getHelpPageIdentifier()
{
return new HelpPageIdentifier(HelpPageDomain.SAMPLE, HelpPageAction.SEARCH);
}
} }
private EntityKind getEntityKind(String entityKindValueOrNull) private EntityKind getEntityKind(String entityKindValueOrNull)
......
...@@ -34,7 +34,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.search. ...@@ -34,7 +34,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.search.
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.search.IDetailedSearchHitGrid; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.search.IDetailedSearchHitGrid;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListSampleDisplayCriteria; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListSampleDisplayCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriterion;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
...@@ -71,9 +70,7 @@ public class SampleSearchHitGrid extends SampleBrowserGrid implements IDetailedS ...@@ -71,9 +70,7 @@ public class SampleSearchHitGrid extends SampleBrowserGrid implements IDetailedS
} }
/** /**
* Create a search hit grid and initialize the search with the display criteria. N.b. The * Create a search hit grid and initialize the search with the display criteria.
* implementation of this method assumes that the display criteria has one and only one
* criterion.
*/ */
public static IDisposableComponent createWithInitialDisplayCriteria( public static IDisposableComponent createWithInitialDisplayCriteria(
final IViewContext<ICommonClientServiceAsync> viewContext, final IViewContext<ICommonClientServiceAsync> viewContext,
...@@ -81,21 +78,16 @@ public class SampleSearchHitGrid extends SampleBrowserGrid implements IDetailedS ...@@ -81,21 +78,16 @@ public class SampleSearchHitGrid extends SampleBrowserGrid implements IDetailedS
{ {
assert displayCriteria.getSearchCriteria().getCriteria().size() == 1; assert displayCriteria.getSearchCriteria().getCriteria().size() == 1;
// User the caller-provided display criteria // Use the caller-provided display criteria
ISampleCriteriaProvider criteriaProvider = ISampleCriteriaProvider criteriaProvider =
new SampleCriteriaProvider(viewContext, displayCriteria); new SampleCriteriaProvider(viewContext, displayCriteria);
SampleSearchHitGrid grid = new SampleSearchHitGrid(viewContext, criteriaProvider); SampleSearchHitGrid grid = new SampleSearchHitGrid(viewContext, criteriaProvider);
final DetailedSearchWindow searchWindow = final DetailedSearchWindow searchWindow =
new DetailedSearchWindow(viewContext, EntityKind.SAMPLE); new DetailedSearchWindow(viewContext, EntityKind.SAMPLE);
// Extract the search criterion (it is assumed that there is only one -- see method comment)
DetailedSearchCriterion searchCriterion =
displayCriteria.getSearchCriteria().getCriteria().get(0);
// Set the initial search string before creating the toolbar because the toolbar will use // Set the initial search string before creating the toolbar because the toolbar will use
// the initial search string in its own initialization. // the initial search string in its own initialization.
searchWindow.setInitialSearchCriterion(searchCriterion.getField(), searchCriterion searchWindow.setInitialSearchCriteria(displayCriteria.getSearchCriteria());
.getValue());
final DetailedSearchToolbar toolbar = final DetailedSearchToolbar toolbar =
new DetailedSearchToolbar(grid, viewContext.getMessage(Dict.BUTTON_CHANGE_QUERY), new DetailedSearchToolbar(grid, viewContext.getMessage(Dict.BUTTON_CHANGE_QUERY),
......
...@@ -27,7 +27,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; ...@@ -27,7 +27,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriterion; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriterion;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchField;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
...@@ -47,17 +46,20 @@ public class DetailedSearchCriteriaWidget extends VerticalPanel ...@@ -47,17 +46,20 @@ public class DetailedSearchCriteriaWidget extends VerticalPanel
private final IViewContext<ICommonClientServiceAsync> viewContext; private final IViewContext<ICommonClientServiceAsync> viewContext;
private final EntityKind entityKind;
public DetailedSearchCriteriaWidget(IViewContext<ICommonClientServiceAsync> viewContext, public DetailedSearchCriteriaWidget(IViewContext<ICommonClientServiceAsync> viewContext,
EntityKind entityKind) EntityKind entityKind)
{ {
this.viewContext = viewContext; this.viewContext = viewContext;
this.entityKind = entityKind;
setLayoutOnChange(true); setLayoutOnChange(true);
criteriaWidgets = new ArrayList<DetailedSearchCriterionWidget>(); criteriaWidgets = new ArrayList<DetailedSearchCriterionWidget>();
add(matchRadios = add(matchRadios =
new MatchCriteriaRadio(viewContext.getMessage(Dict.MATCH_ALL), viewContext new MatchCriteriaRadio(viewContext.getMessage(Dict.MATCH_ALL), viewContext
.getMessage(Dict.MATCH_ANY))); .getMessage(Dict.MATCH_ANY)));
addCriterion(new DetailedSearchCriterionWidget(viewContext, this, FIRST_ID_SUFFIX, addCriterion(new DetailedSearchCriterionWidget(viewContext, this, FIRST_ID_SUFFIX,
entityKind)); this.entityKind));
} }
private void enableRemovalIfOneExists(final boolean enable) private void enableRemovalIfOneExists(final boolean enable)
...@@ -193,14 +195,30 @@ public class DetailedSearchCriteriaWidget extends VerticalPanel ...@@ -193,14 +195,30 @@ public class DetailedSearchCriteriaWidget extends VerticalPanel
} }
/** /**
* Set the initial search string to the argument. This should be called after creation but * Set the initial search criteria to the argument. This should be called after creation but
* before the user has had a chance to use the window, otherwise user input may be overwritten. * before the user has had a chance to use the window, otherwise user input may be overwritten.
*/ */
public void setInitialSearchCriterion(DetailedSearchField initialField, public void setInitialSearchCritera(DetailedSearchCriteria searchCriteria)
String initialSearchString)
{ {
DetailedSearchCriterionWidget widget = criteriaWidgets.get(0); List<DetailedSearchCriterion> criterionList = searchCriteria.getCriteria();
widget.setSearchCriterion(initialField, initialSearchString); int index = 0, size = criterionList.size();
// Populate the existing search criterion widgets
for (DetailedSearchCriterionWidget widget : criteriaWidgets)
{
DetailedSearchCriterion criterion = criterionList.get(index++);
widget.setSearchCriterion(criterion);
}
// Create any additional widgets required
for (; index < size; ++index)
{
DetailedSearchCriterion criterion = criterionList.get(index);
DetailedSearchCriterionWidget widget =
new DetailedSearchCriterionWidget(viewContext, this, FIRST_ID_SUFFIX,
entityKind);
widget.setSearchCriterion(criterion);
addCriterion(widget);
}
} }
void onEnterKey() void onEnterKey()
......
...@@ -35,6 +35,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.GenericCon ...@@ -35,6 +35,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.GenericCon
import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.DetailedSearchFieldComboModel; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.DetailedSearchFieldComboModel;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.StringUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.StringUtils;
import ch.systemsx.cisd.openbis.generic.shared.basic.AttributeSearchFieldKindProvider;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriterion; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriterion;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchField; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchField;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
...@@ -229,15 +230,20 @@ public class DetailedSearchCriterionWidget extends HorizontalPanel ...@@ -229,15 +230,20 @@ public class DetailedSearchCriterionWidget extends HorizontalPanel
} }
/** /**
* Set the search string to the argument. * Set the parameters to be those specified in the searchCriterion
*/ */
public void setSearchCriterion(DetailedSearchField field, String searchString) public void setSearchCriterion(DetailedSearchCriterion criterion)
{ {
DetailedSearchField field = criterion.getField();
String searchString = criterion.getValue();
String description = ""; String description = "";
switch (field.getKind()) switch (field.getKind())
{ {
case ATTRIBUTE: case ATTRIBUTE:
description = field.getAttributeCode(); description =
AttributeSearchFieldKindProvider.getAttributeFieldKind(
nameField.getEntityKind(), field.getAttributeCode())
.getDescription();
break; break;
case PROPERTY: case PROPERTY:
description = field.getPropertyCode(); description = field.getPropertyCode();
...@@ -249,6 +255,7 @@ public class DetailedSearchCriterionWidget extends HorizontalPanel ...@@ -249,6 +255,7 @@ public class DetailedSearchCriterionWidget extends HorizontalPanel
description = "Any Property"; description = "Any Property";
break; break;
} }
DetailedSearchFieldComboModel model = new DetailedSearchFieldComboModel(description, field); DetailedSearchFieldComboModel model = new DetailedSearchFieldComboModel(description, field);
nameField.setValue(model); nameField.setValue(model);
valueField.setValue(searchString); valueField.setValue(searchString);
......
...@@ -23,7 +23,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.help.HelpP ...@@ -23,7 +23,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.help.HelpP
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.data.DataSetSearchHitGrid; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.data.DataSetSearchHitGrid;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.DialogWithOnlineHelpUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.DialogWithOnlineHelpUtils;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchField;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
...@@ -160,10 +159,10 @@ public class DetailedSearchWindow extends Dialog ...@@ -160,10 +159,10 @@ public class DetailedSearchWindow extends Dialog
* does not notify the listener of any changes -- the caller must keep the window and toolbar in * does not notify the listener of any changes -- the caller must keep the window and toolbar in
* sync. * sync.
*/ */
public void setInitialSearchCriterion(DetailedSearchField initialField, String searchString) public void setInitialSearchCriteria(DetailedSearchCriteria searchCriteria)
{ {
// Set the widget // Set the widget
criteriaWidget.setInitialSearchCriterion(initialField, searchString); criteriaWidget.setInitialSearchCritera(searchCriteria);
} }
private void onSearch() private void onSearch()
......
...@@ -46,4 +46,23 @@ public class AttributeSearchFieldKindProvider ...@@ -46,4 +46,23 @@ public class AttributeSearchFieldKindProvider
} }
return null; // cannot happen return null; // cannot happen
} }
/**
* Return the attribute search field kind that matches the given entityKind / code combintation
*/
public static IAttributeSearchFieldKind getAttributeFieldKind(EntityKind entityKind, String code)
{
switch (entityKind)
{
case DATA_SET:
return DataSetAttributeSearchFieldKind.valueOf(code);
case EXPERIMENT:
return ExperimentAttributeSearchFieldKind.valueOf(code);
case MATERIAL:
return MaterialAttributeSearchFieldKind.valueOf(code);
case SAMPLE:
return SampleAttributeSearchFieldKind.valueOf(code);
}
return null; // cannot happen
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment