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

LMS-1415 Added data set search.

SVN: 15040
parent a5574de5
No related branches found
No related tags found
No related merge requests found
/*
* 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 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.data.DataSetSearchHitGrid;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IDisposableComponent;
import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriteria;
/**
* A resolver that takes search critera, executes a dataset search, and displays the results.
*
* @author Chandrasekhar Ramakrishnan
*/
public class DataSetSearchLocatorResolver
{
private final IViewContext<ICommonClientServiceAsync> viewContext;
public DataSetSearchLocatorResolver(IViewContext<ICommonClientServiceAsync> viewContext)
{
this.viewContext = viewContext;
}
public void openEntitySearch(DetailedSearchCriteria searchCriteria) throws UserFailureException
{
// Open the search view using the provided criteria
OpenEntitySearchGridTabAction searchAction =
new OpenEntitySearchGridTabAction(searchCriteria, viewContext);
DispatcherHelper.dispatchNaviEvent(searchAction);
}
private static class OpenEntitySearchGridTabAction implements ITabItemFactory
{
private final DetailedSearchCriteria searchCriteria;
private final IViewContext<ICommonClientServiceAsync> viewContext;
private OpenEntitySearchGridTabAction(DetailedSearchCriteria searchCriteria,
IViewContext<ICommonClientServiceAsync> viewContext)
{
this.searchCriteria = searchCriteria;
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()
{
IDisposableComponent browser =
DataSetSearchHitGrid.createWithInitialSearchCriteria(viewContext,
searchCriteria);
return createTab(Dict.DATA_SET_SEARCH, browser);
}
public String getId()
{
return DataSetSearchHitGrid.BROWSER_ID;
}
public HelpPageIdentifier getHelpPageIdentifier()
{
return new HelpPageIdentifier(HelpPageDomain.DATA_SET, HelpPageAction.SEARCH);
}
}
}
\ No newline at end of file
...@@ -58,6 +58,8 @@ public class SampleSearchLocatorResolver ...@@ -58,6 +58,8 @@ public class SampleSearchLocatorResolver
ListSampleDisplayCriteria displayCriteria = ListSampleDisplayCriteria.createForSearch(); ListSampleDisplayCriteria displayCriteria = ListSampleDisplayCriteria.createForSearch();
displayCriteria.updateSearchCriteria(searchCriteria); displayCriteria.updateSearchCriteria(searchCriteria);
// Do a search first and based on the results of the search, open either the details view or
// the search view
viewContext.getCommonService().listSamples(displayCriteria, viewContext.getCommonService().listSamples(displayCriteria,
new OpenEntitySearchTabCallback(displayCriteria)); new OpenEntitySearchTabCallback(displayCriteria));
} }
...@@ -80,6 +82,8 @@ public class SampleSearchLocatorResolver ...@@ -80,6 +82,8 @@ public class SampleSearchLocatorResolver
public final void onSuccess(ResultSetWithEntityTypes<Sample> result) public final void onSuccess(ResultSetWithEntityTypes<Sample> result)
{ {
// If the search found just one sample, show it in the details view. If many samples
// were found, open the search view.
switch (result.getResultSet().getTotalLength()) switch (result.getResultSet().getTotalLength())
{ {
// Nothing found -- notify the user // Nothing found -- notify the user
......
...@@ -63,6 +63,10 @@ public class SearchLocatorResolver extends AbstractViewLocatorResolver ...@@ -63,6 +63,10 @@ public class SearchLocatorResolver extends AbstractViewLocatorResolver
{ {
SampleSearchLocatorResolver resolver = new SampleSearchLocatorResolver(viewContext); SampleSearchLocatorResolver resolver = new SampleSearchLocatorResolver(viewContext);
resolver.openEntitySearch(searchCriteria); resolver.openEntitySearch(searchCriteria);
} else if (EntityKind.DATA_SET == entityKind)
{
DataSetSearchLocatorResolver resolver = new DataSetSearchLocatorResolver(viewContext);
resolver.openEntitySearch(searchCriteria);
} else } else
{ {
throw new UserFailureException( throw new UserFailureException(
......
...@@ -65,6 +65,28 @@ public class DataSetSearchHitGrid extends AbstractExternalDataGrid implements ...@@ -65,6 +65,28 @@ public class DataSetSearchHitGrid extends AbstractExternalDataGrid implements
return grid.asDisposableWithToolbar(toolbar); return grid.asDisposableWithToolbar(toolbar);
} }
public static IDisposableComponent createWithInitialSearchCriteria(
final IViewContext<ICommonClientServiceAsync> viewContext,
DetailedSearchCriteria searchCriteria)
{
DataSetSearchHitGrid grid = new DataSetSearchHitGrid(viewContext);
grid.chosenSearchCriteria = searchCriteria;
final DetailedSearchWindow searchWindow =
new DetailedSearchWindow(viewContext, EntityKind.DATA_SET);
// Set the initial search string before creating the toolbar because the toolbar will use
// the initial search string in its own initialization.
searchWindow.setInitialSearchCriteria(searchCriteria);
final DetailedSearchToolbar toolbar =
new DetailedSearchToolbar(grid, viewContext.getMessage(Dict.BUTTON_CHANGE_QUERY),
searchWindow, true);
searchWindow.setUpdateListener(toolbar);
return grid.asDisposableWithToolbar(toolbar);
}
private DetailedSearchCriteria chosenSearchCriteria; private DetailedSearchCriteria chosenSearchCriteria;
private DataSetSearchHitGrid(final IViewContext<ICommonClientServiceAsync> viewContext) private DataSetSearchHitGrid(final IViewContext<ICommonClientServiceAsync> viewContext)
......
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