Updated Rules

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-portlet@114265 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-04-20 16:02:29 +00:00
parent 55e17e0181
commit 0e993650c0
5 changed files with 452 additions and 151 deletions

View File

@ -6,7 +6,7 @@ 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.expressionwidget.shared.rule.RuleDescriptionDataProperties;
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;
@ -20,23 +20,22 @@ 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.cell.client.AbstractCell;
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.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
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.XTemplates;
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.dnd.core.client.GridDragSource;
import com.sencha.gxt.dnd.core.client.GridDropTarget;
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;
@ -48,11 +47,13 @@ import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.Verti
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.form.FieldSet;
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;
import com.sencha.gxt.widget.core.client.grid.filters.GridFilters;
import com.sencha.gxt.widget.core.client.grid.filters.StringFilter;
import com.sencha.gxt.widget.core.client.info.Info;
/**
@ -62,26 +63,43 @@ import com.sencha.gxt.widget.core.client.info.Info;
*
*/
public class RuleApplyPanel extends FramedPanel {
private static final String RULES_GRID_HEIGHT = "184px";
private static final String SET_RULES = "SetRules";
interface RuleApplyTemplates extends XTemplates {
@XTemplate("<span title=\"{value}\">{value}</span>")
SafeHtml format(String value);
}
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 ArrayList<RuleDescriptionData> applicableRules;
private ArrayList<RuleDescriptionData> appliesRules;
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;
private ListStore<RuleDescriptionData> applicableRulesStore;
private Grid<RuleDescriptionData> gridApplicableRules;
private ListStore<RuleDescriptionData> appliesRulesStore;
private Grid<RuleDescriptionData> gridAppliesRules;
public RuleApplyPanel(RuleApplyDialog parent, TRId trId, EventBus eventBus) {
public RuleApplyPanel(RuleApplyDialog parent, TRId trId, EventBus eventBus) {
this.parent = parent;
this.trId = trId;
applicableRules=new ArrayList<RuleDescriptionData>();
appliesRules=new ArrayList<RuleDescriptionData>();
Log.debug("TemplateApplyPanel");
setWidth(WIDTH);
setHeight(HEIGHT);
@ -140,15 +158,14 @@ public class RuleApplyPanel extends FramedPanel {
protected void create() {
Log.debug("Create RuleApplyPanel(): " + trId);
FieldSet configurationFieldSet = new FieldSet();
configurationFieldSet.setHeadingText("Configuration");
configurationFieldSet.setCollapsible(false);
VerticalLayoutContainer configurationFieldSetLayout=new VerticalLayoutContainer();
VerticalLayoutContainer configurationFieldSetLayout = new VerticalLayoutContainer();
configurationFieldSet.add(configurationFieldSetLayout);
// Column Data
ColumnDataPropertiesCombo propsColumnData = GWT
.create(ColumnDataPropertiesCombo.class);
@ -170,64 +187,152 @@ public class RuleApplyPanel extends FramedPanel {
comboColumns.setTriggerAction(TriggerAction.ALL);
FieldLabel comboColumnsLabel = new FieldLabel(comboColumns, "Column");
configurationFieldSetLayout.add(comboColumnsLabel, new VerticalLayoutData(1, -1,
new Margins(0)));
configurationFieldSetLayout.add(comboColumnsLabel,
new VerticalLayoutData(1, -1, new Margins(0)));
// Rules
RuleDescriptionDataPropertiesCombo propsRules = GWT
.create(RuleDescriptionDataPropertiesCombo.class);
// IdentityValueProvider<RuleDescriptionData> identity = new
// IdentityValueProvider<RuleDescriptionData>();
// CheckBoxSelectionModel<RuleDescriptionData> sm = new
// CheckBoxSelectionModel<RuleDescriptionData>(
// identity);
ListStore<RuleDescriptionData> availableRulesStore = new ListStore<RuleDescriptionData>(
propsRules.id());
RpcProxy<ListLoadConfig, ListLoadResult<RuleDescriptionData>> availableRulesProxy = new RpcProxy<ListLoadConfig, ListLoadResult<RuleDescriptionData>>() {
RuleDescriptionDataProperties propsRules = GWT
.create(RuleDescriptionDataProperties.class);
public void load(
ListLoadConfig loadConfig,
final AsyncCallback<ListLoadResult<RuleDescriptionData>> callback) {
loadAvaibleRules(loadConfig, callback);
ColumnConfig<RuleDescriptionData, String> nameCol = new ColumnConfig<RuleDescriptionData, String>(
propsRules.name(), 120, "Name");
nameCol.setCell(new AbstractCell<String>() {
@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
RuleApplyTemplates ruleApplyTemplates = GWT
.create(RuleApplyTemplates.class);
sb.append(ruleApplyTemplates.format(value));
}
};
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>>() {
ColumnConfig<RuleDescriptionData, String> descriptionCol = new ColumnConfig<RuleDescriptionData, String>(
propsRules.description(), 120, "Description");
descriptionCol.setCell(new AbstractCell<String>() {
public void load(
ListLoadConfig loadConfig,
final AsyncCallback<ListLoadResult<RuleDescriptionData>> callback) {
loadAppliesRules(loadConfig, callback);
@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
RuleApplyTemplates ruleApplyTemplates = GWT
.create(RuleApplyTemplates.class);
sb.append(ruleApplyTemplates.format(value));
}
};
appliesRulesLoader = new ListLoader<ListLoadConfig, ListLoadResult<RuleDescriptionData>>(
appliesRulesProxy);
appliesRulesLoader.setRemoteSort(false);
appliesRulesLoader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, RuleDescriptionData, ListLoadResult<RuleDescriptionData>>(
appliesRulesStore) {
});
ColumnConfig<RuleDescriptionData, String> ownerCol = new ColumnConfig<RuleDescriptionData, String>(
propsRules.owner(), 70, "Owner");
ownerCol.setCell(new AbstractCell<String>() {
@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
RuleApplyTemplates ruleApplyTemplates = GWT
.create(RuleApplyTemplates.class);
sb.append(ruleApplyTemplates.format(value));
}
});
ColumnConfig<RuleDescriptionData, String> readableExpressionCol = new ColumnConfig<RuleDescriptionData, String>(
propsRules.readableExpression(), 160, "Expression");
readableExpressionCol.setCell(new AbstractCell<String>() {
@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
RuleApplyTemplates ruleApplyTemplates = GWT
.create(RuleApplyTemplates.class);
sb.append(ruleApplyTemplates.format(value));
}
});
List<ColumnConfig<RuleDescriptionData, ?>> l = new ArrayList<ColumnConfig<RuleDescriptionData, ?>>();
l.add(nameCol);
l.add(descriptionCol);
l.add(ownerCol);
l.add(readableExpressionCol);
ColumnModel<RuleDescriptionData> cm = new ColumnModel<RuleDescriptionData>(
l);
StringFilter<RuleDescriptionData> nameFilter = new StringFilter<RuleDescriptionData>(propsRules.name());
StringFilter<RuleDescriptionData> descriptionFilter = new StringFilter<RuleDescriptionData>(propsRules.description());
rulesDualList = new DualListField<RuleDescriptionData, String>(
availableRulesStore, appliesRulesStore, propsRules.nameProv(), new TextCell());
rulesDualList.addValidator(new EmptyValidator<List<RuleDescriptionData>>());
rulesDualList.setEnableDnd(true);
rulesDualList.setMode(Mode.INSERT);
// Applicable Rules
applicableRulesStore = new ListStore<RuleDescriptionData>(
propsRules.id());
gridApplicableRules = new Grid<RuleDescriptionData>(
applicableRulesStore, cm);
gridApplicableRules.setHeight(RULES_GRID_HEIGHT);
gridApplicableRules.getView().setStripeRows(true);
gridApplicableRules.getView().setColumnLines(true);
gridApplicableRules.getView().setAutoFill(true);
gridApplicableRules.setBorders(false);
gridApplicableRules.setLoadMask(true);
gridApplicableRules.setColumnReordering(true);
gridApplicableRules.setColumnResize(true);
gridApplicableRules.getView().setAutoExpandColumn(descriptionCol);
FieldLabel ruleDualListLabel = new FieldLabel(rulesDualList, "Rules");
configurationFieldSetLayout.add(ruleDualListLabel, new VerticalLayoutData(1, -1,
new Margins(0)));
GridFilters<RuleDescriptionData> filtersApplicableRules = new GridFilters<RuleDescriptionData>();
filtersApplicableRules.initPlugin(gridApplicableRules);
filtersApplicableRules.setLocal(true);
filtersApplicableRules.addFilter(nameFilter);
filtersApplicableRules.addFilter(descriptionFilter);
// Applies Rules
appliesRulesStore = new ListStore<RuleDescriptionData>(
propsRules.id());
gridAppliesRules = new Grid<RuleDescriptionData>(
appliesRulesStore, cm);
gridAppliesRules.setHeight(RULES_GRID_HEIGHT);
gridAppliesRules.getView().setStripeRows(true);
gridAppliesRules.getView().setColumnLines(true);
gridAppliesRules.getView().setAutoFill(true);
gridAppliesRules.setBorders(false);
gridAppliesRules.setLoadMask(true);
gridAppliesRules.setColumnReordering(true);
gridAppliesRules.setColumnResize(true);
gridAppliesRules.getView().setAutoExpandColumn(descriptionCol);
GridFilters<RuleDescriptionData> filtersAppliesRules = new GridFilters<RuleDescriptionData>();
filtersAppliesRules.initPlugin(gridAppliesRules);
filtersAppliesRules.setLocal(true);
filtersAppliesRules.addFilter(nameFilter);
filtersAppliesRules.addFilter(descriptionFilter);
//
new GridDragSource<RuleDescriptionData>(gridApplicableRules).setGroup(SET_RULES);
new GridDragSource<RuleDescriptionData>(gridAppliesRules).setGroup(SET_RULES);
new GridDropTarget<RuleDescriptionData>(gridApplicableRules).setGroup(SET_RULES);
new GridDropTarget<RuleDescriptionData>(gridAppliesRules).setGroup(SET_RULES);
//
FieldLabel rulesApplicableLabel = new FieldLabel(gridApplicableRules, "Applicable Rules");
configurationFieldSetLayout.add(rulesApplicableLabel,
new VerticalLayoutData(1, -1, new Margins(0)));
FieldLabel rulesAppliesLabel = new FieldLabel(gridAppliesRules, "Applies Rules");
configurationFieldSetLayout.add(rulesAppliesLabel,
new VerticalLayoutData(1, -1, new Margins(0)));
// Button
btnApply = new TextButton("Apply");
@ -263,14 +368,16 @@ public class RuleApplyPanel extends FramedPanel {
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(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) {
private void addHandlersForComboColumn(
final LabelProvider<ColumnData> labelProvider) {
comboColumns.addSelectionHandler(new SelectionHandler<ColumnData>() {
public void onSelection(SelectionEvent<ColumnData> event) {
Info.display(
@ -281,21 +388,50 @@ public class RuleApplyPanel extends FramedPanel {
.getSelectedItem()) + "!"));
Log.debug("ComboColumn selected: " + event.getSelectedItem());
ColumnData columnData = event.getSelectedItem();
updateRulesInDualList(columnData);
updateRulesInGrids(columnData);
}
});
}
protected void updateRulesInDualList(ColumnData columnData) {
column=columnData;
availableRulesLoader.load();
protected void updateRulesInGrids(ColumnData columnData) {
column = columnData;
getApplicableBaseColumnRules();
}
protected void loadAvaibleRules(ListLoadConfig loadConfig,
final AsyncCallback<ListLoadResult<RuleDescriptionData>> callback) {
protected void getApplicableBaseColumnRules(){
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");
}
}
@Override
public void onSuccess(ArrayList<RuleDescriptionData> result) {
Log.trace("loaded " + result.size() + " Rules");
applicableRules=result;
getAppliesBaseColumnRules();
}
});
}
protected void getAppliesBaseColumnRules(){
ExpressionServiceAsync.INSTANCE.getApplicableBaseColumnRules(column,
new AsyncCallback<ArrayList<RuleDescriptionData>>() {
@ -311,71 +447,42 @@ public class RuleApplyPanel extends FramedPanel {
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));
appliesRules=result;
applicableRulesStore.clear();
applicableRulesStore.addAll(applicableRules);
appliesRulesStore.clear();
appliesRulesStore.addAll(appliesRules);
forceLayout();
}
});
}
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);
List<RuleDescriptionData> selectedItems = appliesRulesStore.getAll();
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);
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");
UtilsGXT3.alert("Attention", "Select a column");
}
}
@ -383,6 +490,4 @@ public class RuleApplyPanel extends FramedPanel {
parent.close();
}
}

View File

@ -20,6 +20,8 @@ import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -40,21 +42,30 @@ 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.Dialog;
import com.sencha.gxt.widget.core.client.FramedPanel;
import com.sencha.gxt.widget.core.client.Dialog.PredefinedButton;
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.MarginData;
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.TextArea;
import com.sencha.gxt.widget.core.client.form.TextField;
import com.sencha.gxt.widget.core.client.grid.CheckBoxSelectionModel;
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;
import com.sencha.gxt.widget.core.client.menu.Item;
import com.sencha.gxt.widget.core.client.menu.Menu;
import com.sencha.gxt.widget.core.client.menu.MenuItem;
import com.sencha.gxt.widget.core.client.toolbar.LabelToolItem;
import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
@ -242,7 +253,9 @@ public class RuleDeletePanel extends FramedPanel {
grid.setColumnReordering(true);
grid.setColumnResize(true);
grid.getView().setAutoExpandColumn(descriptionCol);
createContextMenu();
ToolBar toolBar = new ToolBar();
toolBar.add(grid);
toolBar.addStyleName(ThemeStyles.get().style().borderTop());
@ -322,23 +335,6 @@ public class RuleDeletePanel extends FramedPanel {
});
}
/*
* protected void setMenu() { Menu contextMenu = new Menu();
*
* MenuItem deleteTemplateItem = new MenuItem("Delete");
* deleteTemplateItem.setId("DeleteTemplate");
* deleteTemplateItem.setIcon(ResourceBundle.INSTANCE.removeTemplate());
* deleteTemplateItem.addSelectionHandler(new SelectionHandler<Item>() {
*
* @Override public void onSelection(SelectionEvent<Item> event) {
* Log.debug("Delete Template"); RuleDescriptionData templateDesc =
* getSelectedItem();
*
* } });
*
* grid.setContextMenu(contextMenu); }
*/
protected ArrayList<RuleDescriptionData> getSelectedItem() {
ArrayList<RuleDescriptionData> rules = new ArrayList<RuleDescriptionData>();
for (RuleDescriptionData rule : grid.getSelectionModel()
@ -392,4 +388,84 @@ public class RuleDeletePanel extends FramedPanel {
return false;
}
protected void requestInfo(RuleDescriptionData rule) {
final Dialog infoRuleDialog = new Dialog();
infoRuleDialog.setHeadingText("Info Rule");
infoRuleDialog.getHeader().setIcon(TabularDataResources.INSTANCE.information());
infoRuleDialog.setPredefinedButtons(PredefinedButton.OK);
FieldSet configurationFieldSet = new FieldSet();
configurationFieldSet.setHeadingText("Configuration");
configurationFieldSet.setCollapsible(false);
configurationFieldSet.setBorders(true);
VerticalLayoutContainer configurationFieldSetLayout = new VerticalLayoutContainer();
configurationFieldSet.add(configurationFieldSetLayout, new MarginData(0));
TextField ruleName = new TextField();
ruleName.setToolTip("Rule Name");
ruleName.setValue(rule.getName());
ruleName.setReadOnly(true);
FieldLabel ruleNameLabel = new FieldLabel(ruleName, "Name");
configurationFieldSetLayout.add(ruleNameLabel,new VerticalLayoutData(1, -1, new Margins(0)));
TextArea ruleDescription = new TextArea();
ruleDescription.setToolTip("Rule Description");
ruleDescription.setValue(rule.getDescription());
ruleDescription.setReadOnly(true);
FieldLabel ruleDescriptionLabel = new FieldLabel(ruleDescription, "Description");
configurationFieldSetLayout.add(ruleDescriptionLabel,new VerticalLayoutData(1, -1, new Margins(0)));
TextField ruleOwner = new TextField();
ruleOwner.setToolTip("Rule Owner");
ruleOwner.setValue(rule.getOwner());
ruleOwner.setReadOnly(true);
FieldLabel ruleOwnerLabel = new FieldLabel(ruleOwner, "Owner");
configurationFieldSetLayout.add(ruleOwnerLabel,new VerticalLayoutData(1, -1, new Margins(0)));
TextArea ruleExpression = new TextArea();
ruleExpression.setToolTip("Rule Expression");
ruleExpression.setValue(rule.getReadableExpression());
ruleExpression.setReadOnly(true);
ruleExpression.setHeight("82px");
FieldLabel ruleExpressionLabel = new FieldLabel(ruleExpression, "Expression");
configurationFieldSetLayout.add(ruleExpressionLabel,new VerticalLayoutData(1, -1, new Margins(0)));
infoRuleDialog.add(configurationFieldSet, new MarginData(0));
infoRuleDialog.setHideOnButtonClick(true);
infoRuleDialog.setButtonAlign(BoxLayoutPack.CENTER);
infoRuleDialog.setWidth(500);
infoRuleDialog.show();
}
protected void createContextMenu() {
Menu contextMenu = new Menu();
MenuItem infoItem = new MenuItem();
infoItem.setText("Info");
infoItem.setIcon(TabularDataResources.INSTANCE.information());
infoItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
RuleDescriptionData selected = grid.getSelectionModel().getSelectedItem();
Log.debug(selected.toString());
requestInfo(selected);
}
});
contextMenu.add(infoItem);
grid.setContextMenu(contextMenu);
}
}

View File

@ -2,6 +2,8 @@ package org.gcube.portlets.user.td.client.rule;
import org.gcube.portlets.user.td.client.resource.TabularDataResources;
import org.gcube.portlets.user.td.expressionwidget.client.RuleDialog;
import org.gcube.portlets.user.td.expressionwidget.client.notification.RuleDialogNotification;
import org.gcube.portlets.user.td.expressionwidget.client.notification.RuleDialogNotification.RuleDialogNotificationListener;
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
import com.allen_sauer.gwt.log.client.Log;
@ -16,17 +18,18 @@ import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class RuleOpenDialog extends Window {
public class RuleOpenDialog extends Window implements RuleDialogNotificationListener {
private static final String WIDTH = "720px";
private static final String HEIGHT = "530px";
private EventBus eventBus;
private RuleOpenPanel rulesOpenPanel;
public RuleOpenDialog(EventBus eventBus) {
initWindow();
this.eventBus=eventBus;
RuleOpenPanel templateOpenPanel = new RuleOpenPanel(this,
rulesOpenPanel= new RuleOpenPanel(this,
eventBus);
add(templateOpenPanel);
add(rulesOpenPanel);
}
protected void initWindow() {
@ -67,12 +70,33 @@ public class RuleOpenDialog extends Window {
}
private void openRuleDialog(RuleDescriptionData ruleDescriptionData) {
protected void openRuleDialog(RuleDescriptionData ruleDescriptionData) {
Log.debug("Request Open New Rule Dialog");
RuleDialog cfDialog = new RuleDialog(ruleDescriptionData,eventBus);
cfDialog.addRuleDialogNotificationListener(this);
cfDialog.show();
}
@Override
public void onNotification(RuleDialogNotification ruleDialogNotification) {
rulesOpenPanel.gridReload();
}
@Override
public void aborted() {
}
@Override
public void failed(Throwable throwable) {
Log.debug("Error in edit rule: "+throwable.getLocalizedMessage());
}
}

View File

@ -20,6 +20,8 @@ import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -40,21 +42,31 @@ 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.ContentPanel;
import com.sencha.gxt.widget.core.client.Dialog;
import com.sencha.gxt.widget.core.client.Dialog.PredefinedButton;
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.MarginData;
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.TextArea;
import com.sencha.gxt.widget.core.client.form.TextField;
import com.sencha.gxt.widget.core.client.grid.CheckBoxSelectionModel;
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;
import com.sencha.gxt.widget.core.client.menu.Item;
import com.sencha.gxt.widget.core.client.menu.Menu;
import com.sencha.gxt.widget.core.client.menu.MenuItem;
import com.sencha.gxt.widget.core.client.toolbar.LabelToolItem;
import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
@ -139,7 +151,7 @@ public class RuleOpenPanel extends FramedPanel {
sb.append(ruleOpenTemplates.format(value));
}
});
ColumnConfig<RuleDescriptionData, String> ownerCol = new ColumnConfig<RuleDescriptionData, String>(
props.owner(), 70, "Owner");
ownerCol.setCell(new AbstractCell<String>() {
@ -151,7 +163,6 @@ public class RuleOpenPanel extends FramedPanel {
sb.append(ruleOpenTemplates.format(value));
}
});
ColumnConfig<RuleDescriptionData, String> readableExpressionCol = new ColumnConfig<RuleDescriptionData, String>(
props.readableExpression(), 160, "Expression");
@ -249,6 +260,8 @@ public class RuleOpenPanel extends FramedPanel {
grid.setColumnResize(true);
grid.getView().setAutoExpandColumn(descriptionCol);
createContextMenu();
ToolBar toolBar = new ToolBar();
toolBar.add(grid);
toolBar.addStyleName(ThemeStyles.get().style().borderTop());
@ -320,7 +333,11 @@ public class RuleOpenPanel extends FramedPanel {
@Override
public void onSuccess(ArrayList<RuleDescriptionData> result) {
Log.trace("loaded " + result.size() + " Rules");
if (result != null) {
Log.trace("loaded " + result.size() + " Rules");
} else {
Log.trace("get Rules return: null");
}
callback.onSuccess(new ListLoadResultBean<RuleDescriptionData>(
result));
@ -330,14 +347,15 @@ public class RuleOpenPanel extends FramedPanel {
}
protected RuleDescriptionData getSelectedItem() {
RuleDescriptionData template = grid.getSelectionModel().getSelectedItem();
RuleDescriptionData template = grid.getSelectionModel()
.getSelectedItem();
return template;
}
protected void edit() {
RuleDescriptionData rule = getSelectedItem();
if (rule == null ) {
if (rule == null) {
UtilsGXT3.info("Attention", "Select the rule");
} else {
parent.ruleEdit(rule);
@ -378,4 +396,82 @@ public class RuleOpenPanel extends FramedPanel {
return false;
}
protected void requestInfo(RuleDescriptionData rule) {
final Dialog infoRuleDialog = new Dialog();
infoRuleDialog.setHeadingText("Info Rule");
infoRuleDialog.getHeader().setIcon(TabularDataResources.INSTANCE.information());
infoRuleDialog.setPredefinedButtons(PredefinedButton.OK);
FieldSet configurationFieldSet = new FieldSet();
configurationFieldSet.setHeadingText("Configuration");
configurationFieldSet.setCollapsible(false);
configurationFieldSet.setBorders(true);
VerticalLayoutContainer configurationFieldSetLayout = new VerticalLayoutContainer();
configurationFieldSet.add(configurationFieldSetLayout, new MarginData(0));
TextField ruleName = new TextField();
ruleName.setToolTip("Rule Name");
ruleName.setValue(rule.getName());
ruleName.setReadOnly(true);
FieldLabel ruleNameLabel = new FieldLabel(ruleName, "Name");
configurationFieldSetLayout.add(ruleNameLabel,new VerticalLayoutData(1, -1, new Margins(0)));
TextArea ruleDescription = new TextArea();
ruleDescription.setToolTip("Rule Description");
ruleDescription.setValue(rule.getDescription());
ruleDescription.setReadOnly(true);
FieldLabel ruleDescriptionLabel = new FieldLabel(ruleDescription, "Description");
configurationFieldSetLayout.add(ruleDescriptionLabel,new VerticalLayoutData(1, -1, new Margins(0)));
TextField ruleOwner = new TextField();
ruleOwner.setToolTip("Rule Owner");
ruleOwner.setValue(rule.getOwner());
ruleOwner.setReadOnly(true);
FieldLabel ruleOwnerLabel = new FieldLabel(ruleOwner, "Owner");
configurationFieldSetLayout.add(ruleOwnerLabel,new VerticalLayoutData(1, -1, new Margins(0)));
TextArea ruleExpression = new TextArea();
ruleExpression.setToolTip("Rule Expression");
ruleExpression.setValue(rule.getReadableExpression());
ruleExpression.setReadOnly(true);
ruleExpression.setHeight("82px");
FieldLabel ruleExpressionLabel = new FieldLabel(ruleExpression, "Expression");
configurationFieldSetLayout.add(ruleExpressionLabel,new VerticalLayoutData(1, -1, new Margins(0)));
infoRuleDialog.add(configurationFieldSet, new MarginData(0));
infoRuleDialog.setHideOnButtonClick(true);
infoRuleDialog.setButtonAlign(BoxLayoutPack.CENTER);
infoRuleDialog.setWidth(500);
infoRuleDialog.show();
}
protected void createContextMenu() {
Menu contextMenu = new Menu();
MenuItem infoItem = new MenuItem();
infoItem.setText("Info");
infoItem.setIcon(TabularDataResources.INSTANCE.information());
infoItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
RuleDescriptionData selected = grid.getSelectionModel().getSelectedItem();
Log.debug(selected.toString());
requestInfo(selected);
}
});
contextMenu.add(infoItem);
grid.setContextMenu(contextMenu);
}
}

View File

@ -99,18 +99,18 @@
<set-property-fallback name="locale" value="en" />
-->
<!--
<set-property name="log_ConsoleLogger" value="ENABLED" />
<set-property name="log_DivLogger" value="ENABLED" />
<set-property name="log_GWTLogger" value="ENABLED" />
<set-property name="log_SystemLogger" value="ENABLED" /> -->
<set-property name="log_SystemLogger" value="ENABLED" />
<!-- Not in GWT 2.6 <set-property name="log_FirebugLogger" value="ENABLED" /> -->
<!--
<set-property name="log_ConsoleLogger" value="DISABLED" />
<set-property name="log_DivLogger" value="DISABLED" />
<set-property name="log_GWTLogger" value="DISABLED" />
<set-property name="log_SystemLogger" value="DISABLED" />
<set-property name="log_SystemLogger" value="DISABLED" /> -->
<!-- Not in GWT 2.6 <set-property name="log_FirebugLogger" value="DISABLED" /> -->
<!-- Specify the paths for translatable code -->