tabular-data-expression-widget/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionPa...

175 lines
5.8 KiB
Java

package org.gcube.portlets.user.td.expressionwidget.client;
import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources;
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
import com.allen_sauer.gwt.log.client.Log;
import com.google.web.bindery.event.shared.EventBus;
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.widget.core.client.FramedPanel;
import com.sencha.gxt.widget.core.client.button.TextButton;
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData;
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutPack;
import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer;
import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer.HBoxLayoutAlign;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
import com.sencha.gxt.widget.core.client.form.FieldLabel;
import com.sencha.gxt.widget.core.client.form.FieldSet;
import com.sencha.gxt.widget.core.client.form.TextField;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ReplaceColumnByExpressionPanel extends FramedPanel {
protected static final String WIDTH = "648px";
protected static final String HEIGHT = "364px";
protected static final String CONDITIONWIDTH = "612px";
protected static final String CONDITIONHEIGHT = "150px";
protected EventBus eventBus;
protected ReplaceColumnByExpressionDialog parent;
protected ColumnData column;
private TextButton btnApply;
private TextButton btnClose;
private FieldSet conditionsFieldSet;
private ConditionWidget conditionWidget;
private TextField replaceValue;
public ReplaceColumnByExpressionPanel(
ReplaceColumnByExpressionDialog parent, ColumnData column,
EventBus eventBus) {
super();
this.parent = parent;
this.column = column;
this.eventBus = eventBus;
Log.debug(column.toString());
init();
create();
}
protected void init() {
setWidth(WIDTH);
setHeight(HEIGHT);
setBodyBorder(false);
setHeaderVisible(false);
// Important: fixed rendering of widgets
forceLayoutOnResize = true;
}
protected void create() {
VerticalLayoutContainer basicLayout = new VerticalLayoutContainer();
basicLayout.setAdjustForScroll(true);
basicLayout.setScrollMode(ScrollMode.AUTO);
HBoxLayoutContainer flowButton = new HBoxLayoutContainer();
flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE);
flowButton.setPack(BoxLayoutPack.CENTER);
// Properties
FieldSet properties = new FieldSet();
properties.setHeadingText("Properties");
properties.setCollapsible(false);
VerticalLayoutContainer propertiesLayout = new VerticalLayoutContainer();
properties.add(propertiesLayout);
TextField columnName = new TextField();
columnName.setToolTip("Column");
columnName.setReadOnly(true);
columnName.setValue(column.getLabel());
propertiesLayout.add(new FieldLabel(columnName, "Column"),
new VerticalLayoutData(1, -1));
// Conditions
conditionsFieldSet = new FieldSet();
conditionsFieldSet.setHeadingText("Conditions");
conditionsFieldSet.setCollapsible(false);
conditionWidget = new ConditionWidget(column,CONDITIONWIDTH, CONDITIONHEIGHT);
Log.debug("ConditionWidget" + conditionWidget);
conditionsFieldSet.add(conditionWidget);
// Value
FieldSet replaceValueFieldSet = new FieldSet();
replaceValueFieldSet.setHeadingText("Replace Value");
replaceValueFieldSet.setCollapsible(false);
VerticalLayoutContainer replaceValueFieldSetLayout = new VerticalLayoutContainer();
replaceValueFieldSet.add(replaceValueFieldSetLayout);
replaceValue = new TextField();
replaceValue.setToolTip("Replace Value");
replaceValue.setValue("");
replaceValueFieldSetLayout.add(new FieldLabel(replaceValue,
"Replace Value"), new VerticalLayoutData(1, -1));
//
btnApply = new TextButton("Apply");
btnApply.setIcon(ExpressionResources.INSTANCE.columnReplaceByExpression());
btnApply.setIconAlign(IconAlign.RIGHT);
btnApply.setTitle("Apply replace by expression");
btnApply.addSelectHandler(new SelectHandler() {
public void onSelect(SelectEvent event) {
Log.debug("Pressed Apply");
applyReplaceColumnByExpression();
}
});
btnClose = new TextButton("Close");
btnClose.setIcon(ExpressionResources.INSTANCE.close());
btnClose.setIconAlign(IconAlign.RIGHT);
btnClose.setTitle("Close");
btnClose.addSelectHandler(new SelectHandler() {
public void onSelect(SelectEvent event) {
Log.debug("Pressed Close");
close();
}
});
flowButton.add(btnApply, new BoxLayoutData(new Margins(2, 4, 2, 4)));
flowButton.add(btnClose, new BoxLayoutData(new Margins(2, 4, 2, 4)));
//Add to basic layout
basicLayout.add(properties, new VerticalLayoutData(-1, -1, new Margins(
1)));
basicLayout.add(conditionsFieldSet, new VerticalLayoutData(-1, -1,
new Margins(1)));
basicLayout.add(replaceValueFieldSet, new VerticalLayoutData(-1, -1, new Margins(
1)));
basicLayout.add(flowButton, new VerticalLayoutData(-1, 36, new Margins(
5, 2, 5, 2)));
add(basicLayout);
}
protected void applyReplaceColumnByExpression() {
C_Expression exp = conditionWidget.getExpression();
String value = replaceValue.getCurrentValue();
parent.applyReplaceColumnByExpression(exp,value);
}
protected void close() {
parent.close();
}
}