389 lines
14 KiB
Java
389 lines
14 KiB
Java
package org.gcube.portlets.user.td.client.rule;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.gcube.portlets.user.td.client.resource.TabularDataResources;
|
|
import org.gcube.portlets.user.td.columnwidget.client.properties.ColumnDataPropertiesCombo;
|
|
import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionServiceAsync;
|
|
import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleDescriptionDataPropertiesCombo;
|
|
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFinalException;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.rule.RulesOnColumnApplySession;
|
|
import org.gcube.portlets.user.td.tablewidget.client.util.UtilsGXT3;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnData;
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
import com.google.gwt.cell.client.TextCell;
|
|
import com.google.gwt.core.client.GWT;
|
|
import com.google.gwt.event.logical.shared.SelectionEvent;
|
|
import com.google.gwt.event.logical.shared.SelectionHandler;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.web.bindery.event.shared.EventBus;
|
|
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
|
|
import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction;
|
|
import com.sencha.gxt.core.client.util.Margins;
|
|
import com.sencha.gxt.data.client.loader.RpcProxy;
|
|
import com.sencha.gxt.data.shared.LabelProvider;
|
|
import com.sencha.gxt.data.shared.ListStore;
|
|
import com.sencha.gxt.data.shared.loader.ListLoadConfig;
|
|
import com.sencha.gxt.data.shared.loader.ListLoadResult;
|
|
import com.sencha.gxt.data.shared.loader.ListLoadResultBean;
|
|
import com.sencha.gxt.data.shared.loader.ListLoader;
|
|
import com.sencha.gxt.data.shared.loader.LoadResultListStoreBinding;
|
|
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.ComboBox;
|
|
import com.sencha.gxt.widget.core.client.form.DualListField;
|
|
import com.sencha.gxt.widget.core.client.form.FieldSet;
|
|
import com.sencha.gxt.widget.core.client.form.DualListField.Mode;
|
|
import com.sencha.gxt.widget.core.client.form.FieldLabel;
|
|
import com.sencha.gxt.widget.core.client.form.validator.EmptyValidator;
|
|
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 RuleApplyPanel extends FramedPanel {
|
|
private static final String WIDTH = "630px";
|
|
private static final String HEIGHT = "520px";
|
|
private EventBus eventBus;
|
|
private RuleApplyDialog parent;
|
|
private TRId trId;
|
|
private ArrayList<ColumnData> columns;
|
|
private ColumnData column;
|
|
|
|
private TextButton btnApply;
|
|
private TextButton btnClose;
|
|
|
|
|
|
private ComboBox<ColumnData> comboColumns;
|
|
private ListLoader<ListLoadConfig, ListLoadResult<RuleDescriptionData>> availableRulesLoader;
|
|
private ListLoader<ListLoadConfig, ListLoadResult<RuleDescriptionData>> appliesRulesLoader;
|
|
private DualListField<RuleDescriptionData, String> rulesDualList;
|
|
|
|
public RuleApplyPanel(RuleApplyDialog parent, TRId trId, EventBus eventBus) {
|
|
this.parent = parent;
|
|
this.trId = trId;
|
|
Log.debug("TemplateApplyPanel");
|
|
setWidth(WIDTH);
|
|
setHeight(HEIGHT);
|
|
setHeaderVisible(false);
|
|
setBodyBorder(false);
|
|
this.eventBus = eventBus;
|
|
retrieveColumns();
|
|
|
|
}
|
|
|
|
protected void retrieveColumns() {
|
|
TDGWTServiceAsync.INSTANCE.getColumns(trId,
|
|
new AsyncCallback<ArrayList<ColumnData>>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
} else {
|
|
if (caught instanceof TDGWTIsLockedException) {
|
|
Log.error(caught.getLocalizedMessage());
|
|
UtilsGXT3.alert("Error Locked",
|
|
caught.getLocalizedMessage());
|
|
} else {
|
|
if (caught instanceof TDGWTIsFinalException) {
|
|
Log.error(caught.getLocalizedMessage());
|
|
UtilsGXT3.alert("Error Final",
|
|
caught.getLocalizedMessage());
|
|
} else {
|
|
Log.debug("Error retrieving columns: "
|
|
+ caught.getLocalizedMessage());
|
|
UtilsGXT3
|
|
.alert("Error retrieving columns",
|
|
"Error retrieving column on server!");
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(ArrayList<ColumnData> result) {
|
|
Log.debug("Retrieved Columns");
|
|
if (result == null) {
|
|
UtilsGXT3.alert("Error",
|
|
"The requested columns is null");
|
|
}
|
|
columns = result;
|
|
create();
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
protected void create() {
|
|
|
|
Log.debug("Create RuleApplyPanel(): " + trId);
|
|
|
|
FieldSet configurationFieldSet = new FieldSet();
|
|
configurationFieldSet.setHeadingText("Configuration");
|
|
configurationFieldSet.setCollapsible(false);
|
|
|
|
|
|
VerticalLayoutContainer configurationFieldSetLayout=new VerticalLayoutContainer();
|
|
configurationFieldSet.add(configurationFieldSetLayout);
|
|
|
|
// Column Data
|
|
ColumnDataPropertiesCombo propsColumnData = GWT
|
|
.create(ColumnDataPropertiesCombo.class);
|
|
ListStore<ColumnData> storeCombo = new ListStore<ColumnData>(
|
|
propsColumnData.id());
|
|
storeCombo.addAll(columns);
|
|
|
|
Log.trace("StoreCombo created");
|
|
comboColumns = new ComboBox<ColumnData>(storeCombo,
|
|
propsColumnData.label());
|
|
|
|
Log.trace("Combo ColumnData created");
|
|
|
|
addHandlersForComboColumn(propsColumnData.label());
|
|
comboColumns.setEmptyText("Select a column...");
|
|
comboColumns.setWidth(191);
|
|
comboColumns.setTypeAhead(false);
|
|
comboColumns.setEditable(false);
|
|
comboColumns.setTriggerAction(TriggerAction.ALL);
|
|
|
|
FieldLabel comboColumnsLabel = new FieldLabel(comboColumns, "Column");
|
|
configurationFieldSetLayout.add(comboColumnsLabel, new VerticalLayoutData(1, -1,
|
|
new Margins(0)));
|
|
|
|
// Rules
|
|
RuleDescriptionDataPropertiesCombo propsRules = GWT
|
|
.create(RuleDescriptionDataPropertiesCombo.class);
|
|
|
|
ListStore<RuleDescriptionData> availableRulesStore = new ListStore<RuleDescriptionData>(
|
|
propsRules.id());
|
|
|
|
RpcProxy<ListLoadConfig, ListLoadResult<RuleDescriptionData>> availableRulesProxy = new RpcProxy<ListLoadConfig, ListLoadResult<RuleDescriptionData>>() {
|
|
|
|
public void load(
|
|
ListLoadConfig loadConfig,
|
|
final AsyncCallback<ListLoadResult<RuleDescriptionData>> callback) {
|
|
loadAvaibleRules(loadConfig, callback);
|
|
}
|
|
};
|
|
availableRulesLoader = new ListLoader<ListLoadConfig, ListLoadResult<RuleDescriptionData>>(
|
|
availableRulesProxy);
|
|
|
|
availableRulesLoader.setRemoteSort(false);
|
|
availableRulesLoader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, RuleDescriptionData, ListLoadResult<RuleDescriptionData>>(
|
|
availableRulesStore) {
|
|
});
|
|
|
|
|
|
ListStore<RuleDescriptionData> appliesRulesStore = new ListStore<RuleDescriptionData>(
|
|
propsRules.id());
|
|
|
|
RpcProxy<ListLoadConfig, ListLoadResult<RuleDescriptionData>> appliesRulesProxy = new RpcProxy<ListLoadConfig, ListLoadResult<RuleDescriptionData>>() {
|
|
|
|
public void load(
|
|
ListLoadConfig loadConfig,
|
|
final AsyncCallback<ListLoadResult<RuleDescriptionData>> callback) {
|
|
loadAppliesRules(loadConfig, callback);
|
|
}
|
|
};
|
|
appliesRulesLoader = new ListLoader<ListLoadConfig, ListLoadResult<RuleDescriptionData>>(
|
|
appliesRulesProxy);
|
|
|
|
appliesRulesLoader.setRemoteSort(false);
|
|
appliesRulesLoader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, RuleDescriptionData, ListLoadResult<RuleDescriptionData>>(
|
|
appliesRulesStore) {
|
|
});
|
|
|
|
|
|
|
|
rulesDualList = new DualListField<RuleDescriptionData, String>(
|
|
availableRulesStore, appliesRulesStore, propsRules.nameProv(), new TextCell());
|
|
rulesDualList.addValidator(new EmptyValidator<List<RuleDescriptionData>>());
|
|
rulesDualList.setEnableDnd(true);
|
|
rulesDualList.setMode(Mode.INSERT);
|
|
|
|
FieldLabel ruleDualListLabel = new FieldLabel(rulesDualList, "Rules");
|
|
|
|
configurationFieldSetLayout.add(ruleDualListLabel, new VerticalLayoutData(1, -1,
|
|
new Margins(0)));
|
|
|
|
// Button
|
|
btnApply = new TextButton("Apply");
|
|
btnApply.setIcon(TabularDataResources.INSTANCE.ruleApply());
|
|
btnApply.setIconAlign(IconAlign.RIGHT);
|
|
btnApply.setToolTip("Apply Template");
|
|
btnApply.addSelectHandler(new SelectHandler() {
|
|
|
|
public void onSelect(SelectEvent event) {
|
|
Log.debug("Pressed Apply");
|
|
apply();
|
|
|
|
}
|
|
});
|
|
|
|
btnClose = new TextButton("Close");
|
|
btnClose.setIcon(TabularDataResources.INSTANCE.close());
|
|
btnClose.setIconAlign(IconAlign.RIGHT);
|
|
btnClose.setToolTip("Close");
|
|
btnClose.addSelectHandler(new SelectHandler() {
|
|
|
|
public void onSelect(SelectEvent event) {
|
|
Log.debug("Pressed Close");
|
|
close();
|
|
}
|
|
});
|
|
|
|
HBoxLayoutContainer flowButton = new HBoxLayoutContainer();
|
|
flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE);
|
|
flowButton.setPack(BoxLayoutPack.CENTER);
|
|
|
|
flowButton.add(btnApply, new BoxLayoutData(new Margins(2, 4, 2, 4)));
|
|
flowButton.add(btnClose, new BoxLayoutData(new Margins(2, 4, 2, 4)));
|
|
|
|
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
|
v.add(configurationFieldSet, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
v.add(flowButton,
|
|
new VerticalLayoutData(1, 36, new Margins(5, 2, 5, 2)));
|
|
add(v);
|
|
|
|
}
|
|
|
|
private void addHandlersForComboColumn(final LabelProvider<ColumnData> labelProvider) {
|
|
comboColumns.addSelectionHandler(new SelectionHandler<ColumnData>() {
|
|
public void onSelection(SelectionEvent<ColumnData> event) {
|
|
Info.display(
|
|
"Column Selected",
|
|
"You selected "
|
|
+ (event.getSelectedItem() == null ? "nothing"
|
|
: labelProvider.getLabel(event
|
|
.getSelectedItem()) + "!"));
|
|
Log.debug("ComboColumn selected: " + event.getSelectedItem());
|
|
ColumnData columnData = event.getSelectedItem();
|
|
updateRulesInDualList(columnData);
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
protected void updateRulesInDualList(ColumnData columnData) {
|
|
column=columnData;
|
|
availableRulesLoader.load();
|
|
|
|
}
|
|
|
|
protected void loadAvaibleRules(ListLoadConfig loadConfig,
|
|
final AsyncCallback<ListLoadResult<RuleDescriptionData>> callback) {
|
|
|
|
ExpressionServiceAsync.INSTANCE.getApplicableBaseColumnRules(column,
|
|
new AsyncCallback<ArrayList<RuleDescriptionData>>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
} else {
|
|
Log.error("Error retrieving applicable rules:"
|
|
+ caught.getLocalizedMessage());
|
|
UtilsGXT3.alert("Error retrieving rules",
|
|
"Error retrieving applicable rules");
|
|
}
|
|
callback.onFailure(caught);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(ArrayList<RuleDescriptionData> result) {
|
|
Log.trace("loaded " + result.size() + " Rules");
|
|
callback.onSuccess(new ListLoadResultBean<RuleDescriptionData>(
|
|
result));
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
protected void loadAppliesRules(ListLoadConfig loadConfig,
|
|
final AsyncCallback<ListLoadResult<RuleDescriptionData>> callback) {
|
|
|
|
ExpressionServiceAsync.INSTANCE.getApplicableBaseColumnRules(column,
|
|
new AsyncCallback<ArrayList<RuleDescriptionData>>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
} else {
|
|
Log.error("Error retrieving applicable rules:"
|
|
+ caught.getLocalizedMessage());
|
|
UtilsGXT3.alert("Error retrieving rules",
|
|
"Error retrieving applicable rules");
|
|
}
|
|
callback.onFailure(caught);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(ArrayList<RuleDescriptionData> result) {
|
|
Log.trace("loaded " + result.size() + " Rules");
|
|
callback.onSuccess(new ListLoadResultBean<RuleDescriptionData>(
|
|
result));
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
protected ArrayList<RuleDescriptionData> getSelectedItems() {
|
|
List<RuleDescriptionData> selectedItems=rulesDualList.getValue();
|
|
ArrayList<RuleDescriptionData> rulesSelected=new ArrayList<RuleDescriptionData>(selectedItems);
|
|
return rulesSelected;
|
|
}
|
|
|
|
protected void apply() {
|
|
ArrayList<RuleDescriptionData> selectedRules = getSelectedItems();
|
|
ColumnData column=comboColumns.getCurrentValue();
|
|
if(column!=null){
|
|
RulesOnColumnApplySession rulesOnColumnApplySession=new RulesOnColumnApplySession(trId, column, selectedRules);
|
|
parent.applyRules(rulesOnColumnApplySession);
|
|
} else {
|
|
Log.error("No column selected");
|
|
UtilsGXT3.alert("Attention",
|
|
"Select a column");
|
|
}
|
|
}
|
|
|
|
protected void close() {
|
|
parent.close();
|
|
}
|
|
|
|
|
|
|
|
}
|