429 lines
13 KiB
Java
429 lines
13 KiB
Java
package org.gcube.portlets.user.geoportaldataviewer.client.ui;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
|
|
import org.gcube.application.geoportalcommon.shared.ItemField;
|
|
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
|
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
|
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER;
|
|
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerServiceAsync;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowPopupOnCentroiEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.util.StringUtil;
|
|
|
|
import com.github.gwtbootstrap.client.ui.Alert;
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
|
import com.github.gwtbootstrap.client.ui.ListBox;
|
|
import com.github.gwtbootstrap.client.ui.NavLink;
|
|
import com.github.gwtbootstrap.client.ui.TextBox;
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
|
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
|
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
|
import com.google.gwt.core.client.GWT;
|
|
import com.google.gwt.event.dom.client.ChangeEvent;
|
|
import com.google.gwt.event.dom.client.ChangeHandler;
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
import com.google.gwt.event.dom.client.KeyPressEvent;
|
|
import com.google.gwt.event.dom.client.KeyPressHandler;
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
import com.google.gwt.user.client.Window;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
import com.google.gwt.user.client.ui.FlexTable;
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
public class SearchFacilityUI extends Composite {
|
|
|
|
private static SearchFacilityPanelUiBinder uiBinder = GWT.create(SearchFacilityPanelUiBinder.class);
|
|
|
|
protected static final int MIN_LENGHT_SERCHING_STRING = 3;
|
|
|
|
@UiField
|
|
ListBox listBoxSortBy;
|
|
|
|
@UiField
|
|
ListBox listBoxSearchFor;
|
|
|
|
@UiField
|
|
TextBox searchField;
|
|
|
|
@UiField
|
|
NavLink sortByToogle;
|
|
|
|
@UiField
|
|
Button resetSearch;
|
|
|
|
@UiField
|
|
HTMLPanel panelResults;
|
|
|
|
@UiField
|
|
HorizontalPanel toogleSortBy;
|
|
|
|
private List<ItemField> searchForFields;
|
|
|
|
private List<ItemField> sortByFields;
|
|
|
|
private SearchingFilter currentSortFilter;
|
|
|
|
private HandlerManager appManagerBus;
|
|
|
|
private static final String LABEL_FILTER_SEPARATOR = " - ";
|
|
|
|
private ResultSetPaginatedData latestResult;
|
|
|
|
interface SearchFacilityPanelUiBinder extends UiBinder<Widget, SearchFacilityUI> {
|
|
}
|
|
|
|
public SearchFacilityUI(HandlerManager appManagerBus, List<ItemField> sortByFields, List<ItemField> searchForFields,
|
|
SearchingFilter initialSortFilter) {
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
this.searchForFields = searchForFields;
|
|
this.currentSortFilter = initialSortFilter;
|
|
this.sortByFields = sortByFields;
|
|
this.appManagerBus = appManagerBus;
|
|
|
|
resetSearch.setType(ButtonType.LINK);
|
|
|
|
listBoxSortBy.setWidth("130px");
|
|
listBoxSearchFor.setWidth("130px");
|
|
|
|
bindEvents();
|
|
}
|
|
|
|
private String toLabelFilter(ItemField itemField, ORDER direction) {
|
|
String labelFilter = itemField.getDisplayName() + LABEL_FILTER_SEPARATOR + direction.name();
|
|
return labelFilter;
|
|
}
|
|
|
|
/**
|
|
* Bind events.
|
|
*/
|
|
private void bindEvents() {
|
|
|
|
for (ItemField record_FIELD : sortByFields) {
|
|
if(record_FIELD.isSortable()) {
|
|
String labelASC = toLabelFilter(record_FIELD, ORDER.ASC);
|
|
String labelDESC = toLabelFilter(record_FIELD, ORDER.DESC);
|
|
listBoxSortBy.addItem(labelASC);
|
|
listBoxSortBy.addItem(labelDESC);
|
|
}
|
|
}
|
|
|
|
listBoxSortBy.addChangeHandler(new ChangeHandler() {
|
|
|
|
@Override
|
|
public void onChange(ChangeEvent event) {
|
|
if(latestResult!=null && latestResult.getData().size()>0) {
|
|
doSearchEvent();
|
|
}
|
|
}
|
|
});
|
|
|
|
for (ItemField record_FIELD : searchForFields) {
|
|
GWT.log("search for: "+record_FIELD);
|
|
if(record_FIELD.isSearchable()) {
|
|
listBoxSearchFor.addItem(record_FIELD.getDisplayName());
|
|
}
|
|
}
|
|
|
|
listBoxSearchFor.addChangeHandler(new ChangeHandler() {
|
|
|
|
@Override
|
|
public void onChange(ChangeEvent event) {
|
|
if (searchField.getText().length() >= MIN_LENGHT_SERCHING_STRING) {
|
|
doSearchEvent();
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
sortByToogle.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
if (toogleSortBy.isVisible())
|
|
toogleSortBy.setVisible(false);
|
|
else
|
|
toogleSortBy.setVisible(true);
|
|
|
|
}
|
|
});
|
|
|
|
// navShowOnMap.addClickHandler(new ClickHandler() {
|
|
//
|
|
// @Override
|
|
// public void onClick(ClickEvent event) {
|
|
// List<ConcessioneDV> listConcessioni = null;
|
|
// if (grpw != null && grpw.getSelectItems() != null) {
|
|
// listConcessioni = grpw.getSelectItems();
|
|
// }
|
|
// appManagerBus
|
|
// .fireEvent(new ActionOnItemEvent<ConcessioneDV>(listConcessioni, ACTION_ON_ITEM.VIEW_ON_MAP));
|
|
//
|
|
// }
|
|
// });
|
|
|
|
searchField.addKeyPressHandler(new KeyPressHandler() {
|
|
|
|
@Override
|
|
public void onKeyPress(KeyPressEvent event) {
|
|
if (com.google.gwt.event.dom.client.KeyCodes.KEY_ENTER == event.getCharCode()) {
|
|
GWT.log(searchField.getText());
|
|
doSearchEvent();
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
resetSearch.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
searchField.setText("");
|
|
//appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
|
|
resetSearch.setVisible(false);
|
|
panelResults.clear();
|
|
latestResult = null;
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
private void searchConcessioni() {
|
|
|
|
SearchingFilter filter = getCurrentSortFilter();
|
|
panelResults.clear();
|
|
panelResults.add(new HTML("<hr>"));
|
|
panelResults.add(new LoaderIcon("Searching..."));
|
|
GeoportalDataViewerServiceAsync.Util.getInstance().getListConcessioni(0, 30, filter, false,
|
|
new AsyncCallback<ResultSetPaginatedData>() {
|
|
|
|
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
// showLoading(false);
|
|
// Window.alert(caught.getMessage());
|
|
panelResults.clear();
|
|
panelResults.add(new HTML("<hr>"));
|
|
Alert alert = new Alert("Error on searching. Please, refresh or change it");
|
|
alert.setType(AlertType.ERROR);
|
|
alert.setClose(false);
|
|
panelResults.add(alert);
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(ResultSetPaginatedData result) {
|
|
|
|
latestResult = result;
|
|
|
|
panelResults.clear();
|
|
panelResults.add(new HTML("<hr>"));
|
|
|
|
if (result.getData().size() == 0) {
|
|
panelResults.add(new HTML("No result found"));
|
|
return;
|
|
}
|
|
|
|
FlexTable ft = new FlexTable();
|
|
ft.getElement().setClassName("table-results");
|
|
int i = 1;
|
|
ft.setWidget(0, i, new HTML("Name"));
|
|
|
|
String selValue = listBoxSearchFor.getSelectedValue().toLowerCase();
|
|
|
|
boolean addIntroduction = false;
|
|
if(selValue.startsWith("name") || selValue.startsWith("any")) {
|
|
ft.setWidget(0, ++i, new HTML("Introduction"));
|
|
addIntroduction = true;
|
|
}
|
|
|
|
boolean addStaff = false;
|
|
if(selValue.startsWith("direttore")) {
|
|
ft.setWidget(0, ++i, new HTML("Authors"));
|
|
ft.setWidget(0, ++i, new HTML("Responsabile"));
|
|
ft.setWidget(0, ++i, new HTML("Editore"));
|
|
ft.setWidget(0, ++i, new HTML("Titolari"));
|
|
ft.setWidget(0, ++i, new HTML("Contributore"));
|
|
addStaff = true;
|
|
}
|
|
boolean addParole = false;
|
|
if(selValue.startsWith("parola")) {
|
|
ft.setWidget(0, ++i, new HTML("Parole Libere"));
|
|
ft.setWidget(0, ++i, new HTML("Parole Cronologia"));
|
|
addParole = true;
|
|
}
|
|
|
|
i = 1;
|
|
for (ConcessioneDV concessione : result.getData()) {
|
|
int j = -1;
|
|
|
|
NavLink locateOnMap = new NavLink("Show");
|
|
locateOnMap.setTitle("Locate on the Map and show details");
|
|
locateOnMap.setIcon(IconType.MAP_MARKER);
|
|
|
|
locateOnMap.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
GeoNaItemRef gir = new GeoNaItemRef(concessione.getItemId(), GeoportalDataViewerConstants.RECORD_TYPE.CONCESSIONE.toString());
|
|
appManagerBus.fireEvent(new ShowDetailsEvent(gir, null, null));
|
|
appManagerBus.fireEvent(new ShowPopupOnCentroiEvent(concessione));
|
|
|
|
}
|
|
});
|
|
|
|
ft.setWidget(i, ++j, locateOnMap);
|
|
|
|
|
|
ft.setWidget(i, ++j, new HTML(concessione.getNome()));
|
|
if(addIntroduction)
|
|
ft.setWidget(i, ++j, new HTML(StringUtil.ellipsize(concessione.getIntroduzione(), 100)));
|
|
|
|
if(addStaff) {
|
|
ft.setWidget(i, ++j, new HTML(toDisplayList(concessione.getAuthors())));
|
|
ft.setWidget(i, ++j, new HTML(toDisplayList(Arrays.asList(concessione.getResponsabile()))));
|
|
ft.setWidget(i, ++j, new HTML(toDisplayList(Arrays.asList(concessione.getEditore()))));
|
|
ft.setWidget(i, ++j, new HTML(toDisplayList(concessione.getTitolari())));
|
|
ft.setWidget(i, ++j, new HTML(toDisplayList(Arrays.asList(concessione.getContributore()))));
|
|
}
|
|
|
|
if(addParole) {
|
|
ft.setWidget(i, ++j, new HTML(toDisplayList(concessione.getParoleChiaveLibere())));
|
|
ft.setWidget(i, ++j, new HTML(toDisplayList(concessione.getParoleChiaveICCD())));
|
|
}
|
|
|
|
|
|
// List<UploadedImageDV> listImg = concessione.getImmaginiRappresentative();
|
|
// GWT.log(listImg.toString());
|
|
// boolean imagePreviewFound = false;
|
|
// if (listImg != null && listImg.size() > 0) {
|
|
//
|
|
// UploadedImageDV uImg = listImg.get(0);
|
|
//
|
|
// if (uImg != null && uImg.getListWsContent() != null
|
|
// && uImg.getListWsContent().size() > 0) {
|
|
// WorkspaceContentDV wsc = uImg.getListWsContent().get(0);
|
|
// String image = "<img style=\"width:50px;height:50px;\" src='" + wsc.getLink()
|
|
// + "' alt='" + wsc.getName() + "'>";
|
|
// ft.setWidget(i, 2, new HTML(image));
|
|
// imagePreviewFound = true;
|
|
// }
|
|
// }
|
|
//
|
|
// if (!imagePreviewFound) {
|
|
// ft.setWidget(i, 2, new Image(GNAImages.ICONS.italyIcon()));
|
|
// }
|
|
|
|
i++;
|
|
}
|
|
|
|
panelResults.add(ft);
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* To display authors.
|
|
*
|
|
* @param authors the authors
|
|
* @return the string
|
|
*/
|
|
private String toDisplayList(List<String> listValues) {
|
|
String toDisplay = "";
|
|
if (listValues == null)
|
|
return toDisplay;
|
|
|
|
for (String author : listValues) {
|
|
toDisplay += author + "; ";
|
|
}
|
|
return toDisplay;
|
|
}
|
|
|
|
private void doSearchEvent() {
|
|
String searchText = searchField.getText();
|
|
if (searchText.length() < MIN_LENGHT_SERCHING_STRING) {
|
|
Window.alert("Please enter at least " + MIN_LENGHT_SERCHING_STRING + " characters");
|
|
return;
|
|
}
|
|
|
|
resetSearch.setVisible(true);
|
|
// appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE,
|
|
// getCurrentSortFilter()));
|
|
|
|
searchConcessioni();
|
|
}
|
|
|
|
public SearchingFilter toSortFilter(String labelFilter) {
|
|
GWT.log("toSortFilter for label " + labelFilter);
|
|
String[] array = labelFilter.split(LABEL_FILTER_SEPARATOR);
|
|
|
|
SearchingFilter sortFilter = null;
|
|
try {
|
|
ItemField recordField = null;
|
|
for (ItemField value : sortByFields) {
|
|
if (array[0].equalsIgnoreCase(value.getDisplayName())) {
|
|
recordField = value;
|
|
break;
|
|
}
|
|
}
|
|
ORDER orderField = ORDER.valueOf(array[1]);
|
|
sortFilter = new SearchingFilter(Arrays.asList(recordField), orderField);
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
GWT.log("toSortFilter Got " + sortFilter);
|
|
return sortFilter;
|
|
|
|
}
|
|
|
|
private SearchingFilter builtSearchingFilter() {
|
|
SearchingFilter searchingFilter = toSortFilter(listBoxSortBy.getSelectedValue());
|
|
String searchText = searchField.getText();
|
|
if (searchText != null && !searchText.isEmpty()) {
|
|
Map<String, Object> searchInto = new HashMap<String, Object>();
|
|
|
|
List<String> listOfSeachingFields = new ArrayList<String>();
|
|
|
|
for (ItemField recordField : searchForFields) {
|
|
if (recordField.getDisplayName().equals(listBoxSearchFor.getSelectedValue())) {
|
|
listOfSeachingFields = recordField.getJsonFields();
|
|
continue;
|
|
}
|
|
}
|
|
|
|
if(listOfSeachingFields.size()==0) {
|
|
listOfSeachingFields.add("nome");
|
|
}
|
|
for (String fieldname : listOfSeachingFields) {
|
|
searchInto.put(fieldname, searchText);
|
|
}
|
|
|
|
searchingFilter.setSearchInto(searchInto);
|
|
}
|
|
return searchingFilter;
|
|
}
|
|
|
|
public SearchingFilter getCurrentSortFilter() {
|
|
currentSortFilter = builtSearchingFilter();
|
|
GWT.log("currentSortFilter: " + currentSortFilter);
|
|
return currentSortFilter;
|
|
}
|
|
|
|
}
|