this.width = width;
this.height = height;
flexTable = createInfoTable(dsConfig.getPublisherID(), dsConfig.getDsName(), dsConfig.getDsTimeoutInterval());
}
private Widget createChart(final DataSourceConfiguration dsConfig, final int width, final int height) {
final ContentPanel panel = new FramedPanel();
dashboardService.getDataUpdate(dsConfig.getDsID(), "1", dsConfig.getSeriesCount(), 50, new AsyncCallback<ArrayList<DataVO>>() {
public void onFailure(Throwable caught) {
dbg.debug("Failed in getDataUpdate " + caught);
}
public void onSuccess(ArrayList<DataVO> result) {
// the panel that will hold the chart
//panel.setCollapsible(true);
dbg.debug("seriesSetCount=" + result.size());
new Draggable(panel, panel.getHeader()).setUseProxy(false);
final Resizable resize = new Resizable(panel, Dir.E, Dir.SE, Dir.S);
resize.setMinHeight(400);
resize.setMinWidth(400);
panel.setLayoutData(HasHorizontalAlignment.ALIGN_LEFT);
panel.getElement().getStyle().setMargin(2, Unit.PX);
// set a header of the panel
panel.setHeadingText(dsConfig.getDsName());
panel.setPixelSize(width, height);
panel.setBodyBorder(true);
panel.setBodyStyleName("white-bg");
try {
chart = ChartFactory.getChart(dsConfig,result,ChartType.VERTICAL_BAR);
final ToggleButton toggleLive = new ToggleButton("Live");
toggleLive.setValue(true,false);
// toggleLive.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
//
// public void onValueChange(ValueChangeEvent<Boolean> event) {
// if (event.getValue()) {
// enableLive();
// } else {
// disableLive();
// }
//
// }
// });
toggleLive.addSelectHandler(new SelectHandler() {
public void onSelect(SelectEvent event) {
if (pushListener == null){
enableLive();
toggleLive.setValue(true, false, true);
} else {
disableLive();
toggleLive.setValue(false, false, true);
}
}
});
// final ComboBox<LineSeries<TimeSeriesDataVO>> box = new ComboBox<LineSeries<TimeSeriesDataVO>>(fieldStore,
// new LabelProvider<LineSeries<TimeSeriesDataVO>>() {
// public String getLabel(LineSeries<TimeSeriesDataVO> item) {
// return item.getYField().getPath();
// }
// });
final TextField fieldInput = new TextField();
fieldInput.setValue("first");
fieldInput.setAllowBlank(false);
fieldInput.addValidator(new MaxLengthValidator(20));
final RegExp regex = RegExp.compile("\\s");
fieldInput.addValidator(new Validator<String>() {
public List<EditorError> validate(Editor<String> editor, String value) {
if (regex.test(value)) {
List<EditorError> errors = new ArrayList<EditorError>();
errors.add(new DefaultEditorError(editor, "Field name cannot contain spaces.", ""));
return errors;
}
return null;
}
});
TextButton add = new TextButton("Add");
add.addSelectHandler(new SelectHandler() {
public void onSelect(SelectEvent event) {
// String field = fieldInput.getValue();
// if (fieldInput.isCurrentValid() && field.length() > 0 && fieldStore.findModelWithKey(field) == null && fieldStore.size() < 10) {
// for (int i = 0; i < store.size(); i++) {
// TimeSeriesDataVO item = store.get(i);
// item.put(field, Math.random() * 100);
// }
// LineSeries<TimeSeriesDataVO> series = createLine(field);
// fieldStore.add(series);
// axis.addField(series.getYField());
// chart.addSeries(series);
// chart.redrawChart();
// }
}
});
TextButton remove = new TextButton("Remove");
remove.addSelectHandler(new SelectHandler() {
public void onSelect(SelectEvent event) {
// String field = box.getText();
// LineSeries<TimeSeriesDataVO> series = fieldStore.findModelWithKey(field);
// if (field.length() > 0 && series != null && fieldStore.size() > 0) {
// for (int i = 0; i < store.size(); i++) {
// TimeSeriesDataVO item = store.get(i);
// item.remove(field);
// }
// fieldStore.remove(series);
// axis.removeField(series.getYField());
// chart.removeSeries(series);
// chart.redrawChart();
// }
// box.clear();
}
});
ToolBar toolBar = new ToolBar();
toolBar.add(toggleLive);
toolBar.add(new SeparatorToolItem());
toolBar.add(add);
toolBar.add(fieldInput);
toolBar.add(new SeparatorToolItem());
toolBar.add(remove);
// toolBar.add(box);
VerticalLayoutContainer layout2 = new VerticalLayoutContainer();
toolBar.setLayoutData(new VerticalLayoutData(1, -1));
layout2.add(toolBar);
// chart.setLayoutData(new VerticalLayoutData(1, 1));
layout2.add(chart.asWidget());
final VerticalLayoutContainer layout = new VerticalLayoutContainer();
layout.setBorders(true);
// table that provide the data source information
layout.add(flexTable, new VerticalLayoutData(1, height / 10));
errorLabel.setHeight("20px");
errorLabel.setText("");
layout.add(layout2,new VerticalLayoutData(1, 1));
layout.add(errorLabel);
enableLive();
panel.add(layout);
} catch (ChartSettingsNotValidException e) {
errorLabel.setText(e.getMessage());
dbg.debug("Failed in createChart " + e);