2013-02-08 10:56:27 +01:00
|
|
|
package org.gcube.portlets.user.workspace.client.view.panels;
|
|
|
|
|
2013-09-12 12:07:23 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2013-02-08 10:56:27 +01:00
|
|
|
import org.gcube.portlets.user.workspace.client.AppController;
|
|
|
|
import org.gcube.portlets.user.workspace.client.ConstantsPortlet;
|
|
|
|
import org.gcube.portlets.user.workspace.client.event.SaveSmartFolderEvent;
|
2013-09-12 12:07:23 +02:00
|
|
|
import org.gcube.portlets.user.workspace.client.event.ScopeChangeEvent;
|
2013-02-08 10:56:27 +01:00
|
|
|
import org.gcube.portlets.user.workspace.client.event.SearchTextEvent;
|
2013-09-12 12:07:23 +02:00
|
|
|
import org.gcube.portlets.user.workspace.client.model.ScopeModel;
|
|
|
|
import org.gcube.portlets.user.workspace.client.view.GxtComboBox;
|
2014-05-16 17:44:31 +02:00
|
|
|
import org.gcube.portlets.user.workspace.client.view.toolbars.GxtBreadcrumbPathPanel;
|
2013-02-08 10:56:27 +01:00
|
|
|
|
|
|
|
import com.extjs.gxt.ui.client.event.ComponentEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.KeyListener;
|
2013-09-12 12:07:23 +02:00
|
|
|
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
2013-02-08 10:56:27 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
|
|
|
|
import com.extjs.gxt.ui.client.widget.LayoutContainer;
|
|
|
|
import com.extjs.gxt.ui.client.widget.VerticalPanel;
|
2013-09-12 12:07:23 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.form.ComboBox;
|
2013-02-08 10:56:27 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.form.DateField;
|
2013-09-12 12:07:23 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
|
2013-02-08 10:56:27 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.form.TextField;
|
|
|
|
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
|
|
|
import com.google.gwt.dom.client.Style.Unit;
|
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
|
import com.google.gwt.event.logical.shared.ResizeEvent;
|
|
|
|
import com.google.gwt.event.logical.shared.ResizeHandler;
|
|
|
|
import com.google.gwt.user.client.Window;
|
|
|
|
import com.google.gwt.user.client.ui.Button;
|
|
|
|
import com.google.gwt.user.client.ui.RootPanel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* @author Massimiliano Assante ISTI-CNR
|
|
|
|
*
|
|
|
|
* @version 1.0 May 14th 2012
|
|
|
|
*/
|
|
|
|
public class GxtSeachAndFilterPanel extends LayoutContainer {
|
|
|
|
|
2013-09-12 12:07:23 +02:00
|
|
|
private GxtComboBox comboBoxGxt = null;
|
|
|
|
private ComboBox<ScopeModel> cbViewScope = null;
|
2013-02-08 10:56:27 +01:00
|
|
|
private final TextField<String> textSearch = new TextField<String>();
|
|
|
|
private Button bSearch = new Button(ConstantsPortlet.SEARCH);
|
|
|
|
private Button bCancel = new Button(ConstantsPortlet.CANCEL);
|
|
|
|
private Button bSave = new Button(ConstantsPortlet.SAVE);
|
|
|
|
private TextField<String> textFull = new TextField<String>();
|
|
|
|
private DateField fromDate = new DateField();
|
|
|
|
private DateField toDate = new DateField();
|
2013-09-12 12:07:23 +02:00
|
|
|
private SimpleComboBox<String> cbNameFilter = null;
|
2014-05-16 17:44:31 +02:00
|
|
|
// private HorizontalPanel hpToolbarPathPanel = null;
|
2013-02-08 10:56:27 +01:00
|
|
|
private boolean isSearchActive = false;
|
2014-05-28 18:39:09 +02:00
|
|
|
private VerticalPanel verticalPanel = new VerticalPanel();
|
2013-02-08 10:56:27 +01:00
|
|
|
|
2014-05-16 17:44:31 +02:00
|
|
|
private HorizontalPanel hp = new HorizontalPanel();
|
2014-07-29 12:14:13 +02:00
|
|
|
// private HorizontalPanel hp2 = new HorizontalPanel();
|
2013-02-08 10:56:27 +01:00
|
|
|
|
2014-05-16 17:44:31 +02:00
|
|
|
private HorizontalPanel hpMain = new HorizontalPanel();
|
|
|
|
private GxtBreadcrumbPathPanel toolbarPahtPanel;
|
2013-02-08 10:56:27 +01:00
|
|
|
|
2014-05-16 17:44:31 +02:00
|
|
|
public GxtSeachAndFilterPanel(GxtBreadcrumbPathPanel toolBarPathPanel) {
|
2013-02-08 10:56:27 +01:00
|
|
|
|
|
|
|
setLayout(new FitLayout());
|
|
|
|
setBorders(true);
|
2014-07-28 16:21:45 +02:00
|
|
|
this.setId("SearchAndFilter");
|
|
|
|
this.setBorders(false);
|
|
|
|
// this.setStyleAttribute("background-color", "#d0def0");
|
2013-09-12 12:07:23 +02:00
|
|
|
this.comboBoxGxt = new GxtComboBox();
|
|
|
|
this.cbViewScope = this.comboBoxGxt.getComboViewScope();
|
|
|
|
this.cbNameFilter = this.comboBoxGxt.getComboStringFilter();
|
2014-07-28 16:21:45 +02:00
|
|
|
this.textSearch.setId("TextSearch");
|
|
|
|
// this.textSearch.setStyleAttribute("margin-bottom", "0px");
|
2013-09-12 12:07:23 +02:00
|
|
|
this.cbViewScope.setWidth(360);
|
2013-02-25 19:03:42 +01:00
|
|
|
// this.cbViewScope.setAutoWidth(true);
|
2014-05-16 17:44:31 +02:00
|
|
|
|
|
|
|
this.toolbarPahtPanel = toolBarPathPanel;
|
2014-07-29 12:14:13 +02:00
|
|
|
|
2014-07-28 16:21:45 +02:00
|
|
|
hp.setStyleAttribute("margin-left", "2px");
|
2013-02-08 10:56:27 +01:00
|
|
|
|
|
|
|
seVisibleButtonsCancelSave(false);
|
|
|
|
|
|
|
|
textSearch.setAllowBlank(true);
|
2014-05-12 11:58:39 +02:00
|
|
|
textSearch.setEmptyText(ConstantsPortlet.SEARCHBYNAME);
|
2013-02-08 10:56:27 +01:00
|
|
|
textSearch.setWidth(325);
|
|
|
|
|
2014-05-12 11:58:39 +02:00
|
|
|
/* COMMENTED TO FIX https://support.social.isti.cnr.it/ticket/87
|
2013-02-08 10:56:27 +01:00
|
|
|
textSearch.setRegex("^[a-zA-Z0-9]+[ a-zA-Z0-9_().-]*"); //alphanumeric
|
|
|
|
textSearch.getMessages().setRegexText(ConstantsExplorer.MESSAGE_SEARCH_FORCE_APHANUMERIC);
|
|
|
|
textSearch.setAutoValidate(true);
|
2014-05-12 11:58:39 +02:00
|
|
|
*/
|
2013-02-08 10:56:27 +01:00
|
|
|
hp.add(textSearch);
|
|
|
|
|
|
|
|
bSearch.setStyleName("wizardButton");
|
|
|
|
bSearch.getElement().getStyle().setMarginLeft(3, Unit.PX);
|
|
|
|
bCancel.setStyleName("wizardButton");
|
|
|
|
bCancel.getElement().getStyle().setMarginLeft(3, Unit.PX);
|
|
|
|
bSave.setStyleName("wizardButton");
|
|
|
|
bSave.getElement().getStyle().setMarginLeft(3, Unit.PX);
|
|
|
|
|
|
|
|
hp.add(bSearch);
|
|
|
|
// hp.add(bCancel);
|
|
|
|
hp.add(bSave);
|
|
|
|
|
2014-07-28 16:21:45 +02:00
|
|
|
hp.setHeight(20);
|
|
|
|
hpMain.setHeight(20);
|
2013-02-08 10:56:27 +01:00
|
|
|
bSearch.setWidth("70px");
|
|
|
|
bSave.setWidth("70px");
|
2013-09-12 12:07:23 +02:00
|
|
|
|
|
|
|
cbViewScope.setStyleAttribute("margin-left", "132px");
|
|
|
|
cbViewScope.setStyleAttribute("margin-top", "2px");
|
2013-06-06 18:03:35 +02:00
|
|
|
|
2014-07-29 12:14:13 +02:00
|
|
|
hpMain.setId("hpMain");
|
|
|
|
hpMain.setStyleAttribute("background", "#D0DEF0");
|
|
|
|
verticalPanel.setId("VerticalPanelSearchAndFilter");
|
|
|
|
verticalPanel.setStyleAttribute("background", "#D0DEF0");
|
2013-02-08 10:56:27 +01:00
|
|
|
hpMain.add(hp);
|
2013-09-12 12:07:23 +02:00
|
|
|
|
|
|
|
//SOLUTION FOR SCOPE INVISIBLE
|
|
|
|
cbViewScope.setVisible(false);
|
|
|
|
|
2014-07-28 16:21:45 +02:00
|
|
|
// hpMain.add(hp2);
|
2013-09-12 12:07:23 +02:00
|
|
|
|
2014-07-28 16:21:45 +02:00
|
|
|
// verticalPanel.setLayout(new FitLayout());
|
2014-07-29 12:14:13 +02:00
|
|
|
|
|
|
|
// hpMain.setStyleAttribute("margin", "2px; 8px;");
|
|
|
|
verticalPanel.add(this.toolbarPahtPanel.getToolBarPathPanel());
|
2014-05-28 18:39:09 +02:00
|
|
|
verticalPanel.add(hpMain);
|
2014-07-28 16:21:45 +02:00
|
|
|
// verticalPanel.setStyleAttribute("background-color", "#d0def0");
|
2013-02-08 10:56:27 +01:00
|
|
|
|
|
|
|
this.addListeners();
|
|
|
|
|
2014-05-28 18:39:09 +02:00
|
|
|
add(verticalPanel);
|
2013-02-08 10:56:27 +01:00
|
|
|
|
|
|
|
updateSize();
|
|
|
|
Window.addResizeHandler(new ResizeHandler() {
|
|
|
|
@Override
|
|
|
|
public void onResize(ResizeEvent event) {
|
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update window size
|
|
|
|
*/
|
|
|
|
public void updateSize() {
|
|
|
|
RootPanel workspace = RootPanel.get(ConstantsPortlet.WORKSPACEDIV);
|
|
|
|
int leftBorder = workspace.getAbsoluteLeft();
|
|
|
|
int rootWidth = Window.getClientWidth() - 2* leftBorder; //- rightScrollBar;
|
2013-06-06 18:03:35 +02:00
|
|
|
|
|
|
|
//SOLUTION FOR SCOPE INVISIBLE
|
2013-09-12 12:07:23 +02:00
|
|
|
hp.setWidth(rootWidth);
|
2013-06-06 18:03:35 +02:00
|
|
|
|
|
|
|
// ORIGINAL CODE
|
|
|
|
// hp.setWidth(rootWidth - 500);
|
2013-02-08 10:56:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void searchText(String value){
|
|
|
|
textSearch.setValue(value);
|
|
|
|
seVisibleButtonsCancelSave(true);
|
|
|
|
AppController.getEventBus().fireEvent(new SearchTextEvent(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addListeners(){
|
|
|
|
|
|
|
|
bSearch.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
if(textSearch.getValue()!=null && !textSearch.getValue().isEmpty() && textSearch.isValid()){
|
|
|
|
// seVisibleButtonsCancelSave(true);
|
|
|
|
// AppController.getEventBus().fireEvent(new SearchTextEvent(textSearch.getValue()));
|
|
|
|
searchText(textSearch.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KeyListener keyListener = new KeyListener() {
|
|
|
|
public void componentKeyUp(ComponentEvent event) {
|
|
|
|
if (event.getKeyCode() == 13) { // KEY_ENTER
|
|
|
|
// seVisibleButtonsCancelSave(true);
|
|
|
|
// AppController.getEventBus().fireEvent(new SearchTextEvent(textSearch.getValue()));
|
|
|
|
searchText(textSearch.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
textSearch.addKeyListener(keyListener);
|
2013-09-12 12:07:23 +02:00
|
|
|
//
|
|
|
|
// bCancel.addClickHandler(new ClickHandler() {
|
|
|
|
// @Override
|
|
|
|
// public void onClick(ClickEvent event) {
|
|
|
|
// if(textSearch.getValue()!=null && !textSearch.getValue().isEmpty() && textSearch.isValid()){
|
|
|
|
// searchCancel();
|
|
|
|
// AppController.getEventBus().fireEvent(new SearchTextEvent(null));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
2013-02-08 10:56:27 +01:00
|
|
|
|
|
|
|
bSave.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
if(textSearch.getValue()!=null && !textSearch.getValue().isEmpty() && textSearch.isValid()){
|
|
|
|
if (textSearch.getValue() != null && textSearch.getValue().length()>0) {
|
|
|
|
AppController.getEventBus().fireEvent(new SaveSmartFolderEvent(null, textSearch.getValue(), null));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-12 12:07:23 +02:00
|
|
|
this.cbViewScope.addSelectionChangedListener(new SelectionChangedListener<ScopeModel>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void selectionChanged(SelectionChangedEvent<ScopeModel> se) {
|
|
|
|
|
|
|
|
ScopeModel scope = se.getSelectedItem();
|
|
|
|
|
|
|
|
AppController.getEventBus().fireEvent(new ScopeChangeEvent(scope.getId()));
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-02-08 10:56:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void resetFields(){
|
|
|
|
this.textSearch.reset();
|
|
|
|
this.textFull.reset();
|
|
|
|
this.fromDate.reset();
|
|
|
|
this.toDate.reset();
|
2013-09-12 12:07:23 +02:00
|
|
|
this.cbNameFilter.reset();
|
|
|
|
|
2013-02-08 10:56:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void seVisibleButtonsCancelSave(boolean flag){
|
|
|
|
|
|
|
|
this.bCancel.setVisible(flag);
|
|
|
|
this.bSave.setVisible(flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void searchCancel(){
|
|
|
|
resetFields();
|
|
|
|
seVisibleButtonsCancelSave(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSearchActive(){
|
|
|
|
return this.isSearchActive;
|
|
|
|
}
|
|
|
|
|
2013-09-12 12:07:23 +02:00
|
|
|
public void setListScope(List<ScopeModel> listScope){
|
|
|
|
|
|
|
|
this.comboBoxGxt.setListScope(listScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void selectScopeByIndex(int index){
|
|
|
|
|
|
|
|
this.cbViewScope.setValue(cbViewScope.getStore().getAt(index));
|
|
|
|
}
|
|
|
|
|
2013-02-08 10:56:27 +01:00
|
|
|
public void setSearchActive(boolean isSearchActive) {
|
|
|
|
this.isSearchActive = isSearchActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setVisibleButtonSave(boolean bool){
|
|
|
|
this.bSave.setVisible(bool);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setEmptyText(String emptyText){
|
|
|
|
textSearch.setEmptyText(emptyText);
|
|
|
|
}
|
|
|
|
|
2014-05-16 17:44:31 +02:00
|
|
|
public GxtBreadcrumbPathPanel getToolbarPathPanel() {
|
|
|
|
return toolbarPahtPanel;
|
|
|
|
}
|
|
|
|
|
2013-02-08 10:56:27 +01:00
|
|
|
}
|