2013-02-06 23:25:43 +01:00
|
|
|
package org.gcube.portlets.user.reportgenerator.client.dialog;
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.portlets.d4sreporting.common.client.CommonConstants;
|
2013-03-01 19:42:50 +01:00
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.TimeSeriesFilter;
|
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.TimeSeriesinfo;
|
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.RepTimeSeries;
|
2013-02-06 23:25:43 +01:00
|
|
|
import org.gcube.portlets.user.reportgenerator.client.targets.TSArea;
|
|
|
|
|
2013-03-01 19:42:50 +01:00
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
2013-02-06 23:25:43 +01:00
|
|
|
import com.google.gwt.user.client.Window;
|
|
|
|
import com.google.gwt.user.client.ui.Button;
|
|
|
|
import com.google.gwt.user.client.ui.ChangeListener;
|
|
|
|
import com.google.gwt.user.client.ui.CheckBox;
|
|
|
|
import com.google.gwt.user.client.ui.ClickListener;
|
|
|
|
import com.google.gwt.user.client.ui.DialogBox;
|
|
|
|
import com.google.gwt.user.client.ui.FlexTable;
|
|
|
|
import com.google.gwt.user.client.ui.Grid;
|
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
|
|
import com.google.gwt.user.client.ui.ScrollPanel;
|
|
|
|
import com.google.gwt.user.client.ui.TextBox;
|
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author massi
|
|
|
|
*
|
|
|
|
*/
|
2013-03-01 19:42:50 +01:00
|
|
|
public class TimeSeriesFilterDialog extends DialogBox {
|
2013-02-06 23:25:43 +01:00
|
|
|
ScrollPanel scroller = new ScrollPanel();
|
|
|
|
TextBox from = new TextBox();
|
|
|
|
TextBox to = new TextBox();
|
|
|
|
FlexTable flexTable = new FlexTable();
|
|
|
|
|
|
|
|
List<TSHeader> compoundHeaders = new LinkedList<TSHeader>();
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param sts a ts
|
|
|
|
* @param caller .
|
|
|
|
*/
|
2013-03-01 19:42:50 +01:00
|
|
|
public TimeSeriesFilterDialog(final TSArea caller, final RepTimeSeries sts) {
|
|
|
|
|
|
|
|
final TimeSeriesinfo droppedTS = sts.getTsMetadata();
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
setText(droppedTS.getTitle() + " Filter");
|
|
|
|
String name = droppedTS.getTitle();
|
|
|
|
long rowsNo = droppedTS.getDimension();
|
|
|
|
|
|
|
|
|
|
|
|
Grid metadata = new Grid(2, 2);
|
|
|
|
metadata.setWidget(0, 0, new HTML("Name:", true));
|
|
|
|
metadata.setWidget(0, 1, new HTML(name));
|
|
|
|
metadata.setWidget(1, 0, new HTML("Total rows : ", true));
|
|
|
|
metadata.setWidget(1, 1, new HTML(""+rowsNo));
|
|
|
|
|
|
|
|
|
|
|
|
final VerticalPanel main_panel = new VerticalPanel();
|
|
|
|
main_panel.addStyleName("bgBlank p8 font_family font_12");
|
|
|
|
|
|
|
|
main_panel.add(metadata);
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
List<String> headersString = droppedTS.getHeaderLabels();
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
for (int i = 0; i < headersString.size(); i++) {
|
|
|
|
CheckBox toAdd = new CheckBox();
|
|
|
|
toAdd.setChecked(true);
|
|
|
|
compoundHeaders.add(new TSHeader(this, flexTable, toAdd, i, new HTML(headersString.get(i) )));
|
|
|
|
}
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
main_panel.add(new HTML("Selected fields: (click to remove)"));
|
|
|
|
|
|
|
|
flexTable = getTableHeader(compoundHeaders);
|
|
|
|
main_panel.add(flexTable);
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
main_panel.add(new HTML("Select rows interval:"));
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
from.setText("1");
|
|
|
|
to.setText("10");
|
|
|
|
to.setMaxLength(6);
|
|
|
|
from.setMaxLength(6);
|
|
|
|
from.addChangeListener(textBoxListener);
|
|
|
|
to.addChangeListener(textBoxListener);
|
2013-03-01 19:42:50 +01:00
|
|
|
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
Grid rowsInterval = new Grid(1, 4);
|
|
|
|
rowsInterval.setWidget(0, 0, new HTML("From row:"));
|
|
|
|
rowsInterval.setWidget(0, 1, from);
|
|
|
|
rowsInterval.setWidget(0, 2, new HTML(" To row:"));
|
|
|
|
rowsInterval.setWidget(0, 3, to);
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
main_panel.add(rowsInterval);
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
main_panel.add(new HTML("<hr align=\"left\" size=\"1\" width=\"100%\" color=\"gray\" noshade>"));
|
|
|
|
HorizontalPanel buttonspanel = new HorizontalPanel();
|
|
|
|
buttonspanel.setHeight("50");
|
|
|
|
buttonspanel.setSpacing(3);
|
2013-03-01 19:42:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
// PopupPanel is a SimplePanel, so you have to set it's widget property to
|
|
|
|
// whatever you want its contents to be.
|
|
|
|
Button close = new Button("Close");
|
2013-03-01 19:42:50 +01:00
|
|
|
close.addClickHandler(new ClickHandler() {
|
|
|
|
public void onClick(ClickEvent event) {
|
2013-02-06 23:25:43 +01:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
});
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
Button apply = new Button("Apply");
|
2013-03-01 19:42:50 +01:00
|
|
|
apply.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
2013-02-06 23:25:43 +01:00
|
|
|
List<TSHeader> selectedCols = compoundHeaders;
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
List<Integer> colsToShow = new LinkedList<Integer>();
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
for (TSHeader head : selectedCols) {
|
|
|
|
colsToShow.add(new Integer(head.getMyColNo()));
|
|
|
|
}
|
|
|
|
int fromInt = Integer.parseInt(from.getText());
|
|
|
|
int toInt = Integer.parseInt(to.getText());
|
2013-03-01 19:42:50 +01:00
|
|
|
|
|
|
|
TimeSeriesFilter toSet = new TimeSeriesFilter(colsToShow, null, null, fromInt, toInt);
|
2013-02-06 23:25:43 +01:00
|
|
|
caller.setNewFilter(toSet);
|
|
|
|
caller.refreshHeaders();
|
|
|
|
hide();
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
});
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
buttonspanel.add(close);
|
|
|
|
buttonspanel.add(apply);
|
|
|
|
main_panel.add(buttonspanel);
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
scroller.setPixelSize(550, 280);
|
|
|
|
main_panel.setPixelSize(550, 260);
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
scroller.add(main_panel);
|
|
|
|
setWidget(scroller);
|
|
|
|
}
|
2013-03-01 19:42:50 +01:00
|
|
|
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param toRemove .
|
|
|
|
* @return .
|
|
|
|
*/
|
|
|
|
public boolean removeHeader(TSHeader toRemove) {
|
|
|
|
return compoundHeaders.remove(toRemove);
|
|
|
|
}
|
2013-03-01 19:42:50 +01:00
|
|
|
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
/**
|
|
|
|
* display the header of the ts
|
|
|
|
* @param droppedTS
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private FlexTable getTableHeader(List<TSHeader> headers) {
|
|
|
|
flexTable.clear();
|
|
|
|
int n = headers.size();
|
|
|
|
|
|
|
|
for (int i = 0; i < n ; i++) {
|
|
|
|
flexTable.getCellFormatter().setStyleName(0, i, "timeSeries_header");
|
|
|
|
flexTable.setWidget(0, i, headers.get(i));
|
|
|
|
flexTable.getCellFormatter().setStyleName(1, i, "timeSeries_td");
|
|
|
|
flexTable.setWidget(1, i, new HTML("..."));
|
|
|
|
}
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
return flexTable;
|
|
|
|
}
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
ChangeListener textBoxListener = new ChangeListener() {
|
|
|
|
|
|
|
|
public void onChange(Widget sender) {
|
|
|
|
TextBox tb = (TextBox) sender;
|
|
|
|
String text = tb.getText();
|
|
|
|
String checkedText = text;
|
|
|
|
text = text.replaceAll(CommonConstants.ACCEPTED_CHARS_JUST_NUM, "");
|
|
|
|
if (! text.equals(checkedText) ) {
|
|
|
|
Window.alert("Only numbers are accepted");
|
|
|
|
tb.setText(text);
|
|
|
|
}
|
|
|
|
int start = Integer.parseInt(from.getText());
|
|
|
|
int end = Integer.parseInt(to.getText());
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
if (start >= end) {
|
|
|
|
Window.alert("From must be greater than to");
|
|
|
|
to.setText(""+(start+10));
|
|
|
|
}
|
2013-03-01 19:42:50 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
2013-03-01 19:42:50 +01:00
|
|
|
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
};
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public void show() {
|
2013-03-01 19:42:50 +01:00
|
|
|
super.show();
|
|
|
|
center();
|
|
|
|
}
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|