Updated Normalize

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-table-widget@114685 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-05-06 11:29:24 +00:00 committed by Giancarlo Panichi
parent 01051f62ca
commit 7c6392a0a8
2 changed files with 82 additions and 38 deletions

View File

@ -54,6 +54,12 @@ import com.sencha.gxt.widget.core.client.form.ComboBox;
import com.sencha.gxt.widget.core.client.form.FieldLabel;
import com.sencha.gxt.widget.core.client.info.Info;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class DenormalizePanel extends FramedPanel implements
MonitorDialogListener {
protected String WIDTH = "640px";

View File

@ -21,6 +21,7 @@ import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredTy
import org.gcube.portlets.user.td.widgetcommonevent.shared.OperationResult;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnData;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
@ -55,6 +56,12 @@ import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
import com.sencha.gxt.widget.core.client.grid.Grid;
/**
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class NormalizePanel extends FramedPanel implements
MonitorDialogListener {
protected String WIDTH = "640px";
@ -90,13 +97,46 @@ public class NormalizePanel extends FramedPanel implements
}
protected void create() {
Log.debug("Create NormalizationPanel(): [" + trId.toString() + "]");
setWidth(WIDTH);
setHeight(HEIGHT);
setHeaderVisible(false);
setBodyBorder(false);
Log.debug("Create NormalizationPanel(): [" + trId.toString() + "]");
// Normalize Button
normalizeButton = new TextButton("Normalize");
normalizeButton.setIcon(ResourceBundle.INSTANCE.tableNormalize());
normalizeButton.setIconAlign(IconAlign.RIGHT);
normalizeButton.setTitle("Normalize");
SelectHandler normalizeHandler = new SelectHandler() {
public void onSelect(SelectEvent event) {
onNormalize();
}
};
normalizeButton.addSelectHandler(normalizeHandler);
normalizedColumnName = new TextField();
FieldLabel normalizedColumnNameLabel = new FieldLabel(
normalizedColumnName, "Normalized column");
normalizedColumnNameLabel.setLabelWidth(110);
valueColumnName = new TextField();
FieldLabel valueColumnNameLabel = new FieldLabel(valueColumnName,
"Value column");
valueColumnNameLabel.setLabelWidth(110);
FieldLabel columnsLabel = new FieldLabel(null, "Columns to Normalize");
columnsLabel.setLabelWidth(150);
columnsLabel.getElement().applyStyles("font-weight:bold");
HBoxLayoutContainer hBox = new HBoxLayoutContainer();
hBox.add(normalizeButton, new BoxLayoutData(new Margins(2, 5, 2, 5)));
// Grid ColumnData
ColumnDataProperties props = GWT.create(ColumnDataProperties.class);
ColumnConfig<ColumnData, String> labelCol = new ColumnConfig<ColumnData, String>(
@ -153,38 +193,6 @@ public class NormalizePanel extends FramedPanel implements
grid.setColumnReordering(true);
grid.setColumnResize(false);
// Normalize Button
normalizeButton = new TextButton("Normalize");
normalizeButton.setIcon(ResourceBundle.INSTANCE.tableNormalize());
normalizeButton.setIconAlign(IconAlign.RIGHT);
normalizeButton.setTitle("Normalize");
SelectHandler deleteHandler = new SelectHandler() {
public void onSelect(SelectEvent event) {
onNormalize();
}
};
normalizeButton.addSelectHandler(deleteHandler);
normalizedColumnName = new TextField();
FieldLabel normalizedColumnNameLabel = new FieldLabel(
normalizedColumnName, "Normalized column");
normalizedColumnNameLabel.setLabelWidth(110);
valueColumnName = new TextField();
FieldLabel valueColumnNameLabel = new FieldLabel(valueColumnName,
"Value column");
valueColumnNameLabel.setLabelWidth(110);
FieldLabel columnsLabel = new FieldLabel(null, "Columns to Normalize");
columnsLabel.setLabelWidth(150);
columnsLabel.getElement().applyStyles("font-weight:bold");
HBoxLayoutContainer hBox = new HBoxLayoutContainer();
hBox.add(normalizeButton, new BoxLayoutData(new Margins(2, 5, 2, 5)));
VerticalLayoutContainer v = new VerticalLayoutContainer();
v.setScrollMode(ScrollMode.AUTOY);
v.setAdjustForScroll(true);
@ -230,13 +238,27 @@ public class NormalizePanel extends FramedPanel implements
"Error retrieving columns");
}
}
normalizeButton.disable();
callback.onFailure(caught);
}
public void onSuccess(ArrayList<ColumnData> result) {
Log.trace("loaded " + result.size() + " ColumnData");
callback.onSuccess(new ListLoadResultBean<ColumnData>(
result));
sanitizesColumns(result);
if (result.size() > 0) {
callback.onSuccess(new ListLoadResultBean<ColumnData>(
result));
} else {
normalizeButton.disable();
Log.error("This tabular resource has not Integer or Numeric columns, normalize is not applicable!");
UtilsGXT3
.alert("Attention",
"This tabular resource has not Integer or Numeric columns, normalize is not applicable!");
callback.onFailure(new Throwable(
"This tabular resource has not Integer or Numeric columns, normalize is not applicable!"));
}
}
@ -244,6 +266,19 @@ public class NormalizePanel extends FramedPanel implements
}
protected void sanitizesColumns(ArrayList<ColumnData> columns) {
ArrayList<ColumnData> removableColumn = new ArrayList<ColumnData>();
for (ColumnData c : columns) {
if (!(c.getDataTypeName().compareTo(
ColumnDataType.Integer.toString()) == 0 || c
.getDataTypeName().compareTo(
ColumnDataType.Numeric.toString()) == 0)) {
removableColumn.add(c);
}
}
columns.removeAll(removableColumn);
}
protected void onNormalize() {
ArrayList<ColumnData> col = getSelectedItems();
if (col == null || col.size() < 1) {
@ -308,7 +343,8 @@ public class NormalizePanel extends FramedPanel implements
public void operationComplete(OperationResult operationResult) {
ChangeTableWhy why = ChangeTableWhy.TABLEUPDATED;
ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent(
ChangeTableRequestType.NORMALIZE, operationResult.getTrId(), why);
ChangeTableRequestType.NORMALIZE, operationResult.getTrId(),
why);
eventBus.fireEvent(changeTableRequestEvent);
close();
}
@ -321,10 +357,12 @@ public class NormalizePanel extends FramedPanel implements
}
@Override
public void operationStopped(OperationResult operationResult, String reason, String details) {
public void operationStopped(OperationResult operationResult,
String reason, String details) {
ChangeTableWhy why = ChangeTableWhy.TABLECURATION;
ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent(
ChangeTableRequestType.NORMALIZE, operationResult.getTrId(), why);
ChangeTableRequestType.NORMALIZE, operationResult.getTrId(),
why);
eventBus.fireEvent(changeTableRequestEvent);
close();