81: Allow the creation and use of expressions on multi column in TDM portlet
Task-Url: https://support.d4science.org/issues/81 Added rule on table to active rules git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-rule-widget@115127 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
5958104137
commit
0ba2ebc2b7
|
@ -3,8 +3,12 @@ package org.gcube.portlets.user.td.rulewidget.client;
|
||||||
import org.gcube.portlets.user.td.rulewidget.client.resources.ResourceBundle;
|
import org.gcube.portlets.user.td.rulewidget.client.resources.ResourceBundle;
|
||||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||||
|
|
||||||
|
import com.allen_sauer.gwt.log.client.Log;
|
||||||
import com.google.web.bindery.event.shared.EventBus;
|
import com.google.web.bindery.event.shared.EventBus;
|
||||||
|
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
|
||||||
import com.sencha.gxt.widget.core.client.Window;
|
import com.sencha.gxt.widget.core.client.Window;
|
||||||
|
import com.sencha.gxt.widget.core.client.button.TextButton;
|
||||||
|
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutPack;
|
||||||
import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
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.event.SelectEvent.SelectHandler;
|
||||||
|
|
||||||
|
@ -17,12 +21,11 @@ import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
||||||
public class RuleActiveDialog extends Window {
|
public class RuleActiveDialog extends Window {
|
||||||
private static final String WIDTH = "770px";
|
private static final String WIDTH = "770px";
|
||||||
private static final String HEIGHT = "428px";
|
private static final String HEIGHT = "428px";
|
||||||
|
private TextButton btnClose;
|
||||||
public RuleActiveDialog(TRId trId, EventBus eventBus) {
|
public RuleActiveDialog(TRId trId, EventBus eventBus) {
|
||||||
initWindow();
|
initWindow();
|
||||||
|
RuleActiveTabPanel ruleActiveTabPanel=new RuleActiveTabPanel(trId, eventBus);
|
||||||
RuleActivePanel ruleActivePanel = new RuleActivePanel(this,
|
add(ruleActiveTabPanel);
|
||||||
trId, eventBus);
|
|
||||||
add(ruleActivePanel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initWindow() {
|
protected void initWindow() {
|
||||||
|
@ -35,7 +38,23 @@ public class RuleActiveDialog extends Window {
|
||||||
setModal(true);
|
setModal(true);
|
||||||
forceLayoutOnResize = true;
|
forceLayoutOnResize = true;
|
||||||
getHeader().setIcon(ResourceBundle.INSTANCE.ruleTabularResource());
|
getHeader().setIcon(ResourceBundle.INSTANCE.ruleTabularResource());
|
||||||
|
|
||||||
|
|
||||||
|
btnClose = new TextButton("Close");
|
||||||
|
btnClose.setIcon(ResourceBundle.INSTANCE.close());
|
||||||
|
btnClose.setIconAlign(IconAlign.RIGHT);
|
||||||
|
btnClose.setToolTip("Close");
|
||||||
|
btnClose.addSelectHandler(new SelectHandler() {
|
||||||
|
|
||||||
|
public void onSelect(SelectEvent event) {
|
||||||
|
Log.debug("Pressed Close");
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addButton(btnClose);
|
||||||
|
setButtonAlign(BoxLayoutPack.CENTER);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,23 +29,14 @@ import com.google.gwt.safehtml.shared.SafeHtml;
|
||||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
import com.google.web.bindery.event.shared.EventBus;
|
import com.google.web.bindery.event.shared.EventBus;
|
||||||
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
|
|
||||||
import com.sencha.gxt.core.client.XTemplates;
|
import com.sencha.gxt.core.client.XTemplates;
|
||||||
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
|
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
|
||||||
import com.sencha.gxt.core.client.util.Margins;
|
import com.sencha.gxt.core.client.util.Margins;
|
||||||
import com.sencha.gxt.data.shared.ListStore;
|
import com.sencha.gxt.data.shared.ListStore;
|
||||||
import com.sencha.gxt.widget.core.client.FramedPanel;
|
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;
|
||||||
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
|
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.FieldLabel;
|
||||||
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.ColumnConfig;
|
||||||
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
|
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.Grid;
|
||||||
|
@ -61,34 +52,28 @@ import com.sencha.gxt.widget.core.client.menu.MenuItem;
|
||||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RuleActivePanel extends FramedPanel {
|
public class RuleActiveOnColumnPanel extends FramedPanel {
|
||||||
private static final String WIDTH = "760px";
|
private static final String WIDTH = "760px";
|
||||||
private static final String HEIGHT = "418px";
|
private static final String HEIGHT = "418px";
|
||||||
private static final int RULE_ON_COLUMN_FIELDSET_HEIGHT = 348;
|
|
||||||
private static final String RULES_GRID_HEIGHT = "102px";
|
private static final String RULES_GRID_HEIGHT = "102px";
|
||||||
|
|
||||||
|
|
||||||
interface RuleActiveTemplates extends XTemplates {
|
interface RuleActiveTemplates extends XTemplates {
|
||||||
@XTemplate("<span title=\"{value}\">{value}</span>")
|
@XTemplate("<span title=\"{value}\">{value}</span>")
|
||||||
SafeHtml format(String value);
|
SafeHtml format(String value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
private RuleActiveDialog parent;
|
|
||||||
private TRId trId;
|
private TRId trId;
|
||||||
private ArrayList<ColumnData> columns;
|
private ArrayList<ColumnData> columns;
|
||||||
|
|
||||||
private AppliedRulesResponseData appliedRuleResponseData;
|
private AppliedRulesResponseData appliedRuleResponseData;
|
||||||
|
|
||||||
private TextButton btnClose;
|
|
||||||
private VerticalLayoutContainer mainLayoutContainer;
|
private VerticalLayoutContainer mainLayoutContainer;
|
||||||
|
|
||||||
public RuleActivePanel(RuleActiveDialog parent, TRId trId,
|
public RuleActiveOnColumnPanel(TRId trId, EventBus eventBus) {
|
||||||
EventBus eventBus) {
|
super();
|
||||||
this.parent = parent;
|
|
||||||
this.trId = trId;
|
this.trId = trId;
|
||||||
|
Log.debug("RuleActiveOnColumnPanel");
|
||||||
Log.debug("RuleActivePanel");
|
|
||||||
setWidth(WIDTH);
|
setWidth(WIDTH);
|
||||||
setHeight(HEIGHT);
|
setHeight(HEIGHT);
|
||||||
setHeaderVisible(false);
|
setHeaderVisible(false);
|
||||||
|
@ -145,19 +130,13 @@ public class RuleActivePanel extends FramedPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void create() {
|
protected void create() {
|
||||||
|
Log.debug("Create RuleActiveOnColumnPanel(): " + trId);
|
||||||
Log.debug("Create RuleActivePanel(): " + trId);
|
|
||||||
|
|
||||||
// SimpleContainer rulesOnColumnContainer=new SimpleContainer();
|
|
||||||
FieldSet columnRulesFieldSet = new FieldSet();
|
|
||||||
columnRulesFieldSet.setHeadingText("Rules On Column");
|
|
||||||
columnRulesFieldSet.setCollapsible(false);
|
|
||||||
|
|
||||||
VerticalLayoutContainer columnRulesFieldSetLayout = new VerticalLayoutContainer();
|
VerticalLayoutContainer columnRulesFieldSetLayout = new VerticalLayoutContainer();
|
||||||
columnRulesFieldSetLayout.setScrollMode(ScrollMode.AUTO);
|
columnRulesFieldSetLayout.setScrollMode(ScrollMode.AUTO);
|
||||||
columnRulesFieldSetLayout.setAdjustForScroll(true);
|
columnRulesFieldSetLayout.setAdjustForScroll(true);
|
||||||
|
|
||||||
columnRulesFieldSet.add(columnRulesFieldSetLayout);
|
add(columnRulesFieldSetLayout);
|
||||||
|
|
||||||
HashMap<String, ArrayList<RuleDescriptionData>> columnRuleMapping = appliedRuleResponseData
|
HashMap<String, ArrayList<RuleDescriptionData>> columnRuleMapping = appliedRuleResponseData
|
||||||
.getColumnRuleMapping();
|
.getColumnRuleMapping();
|
||||||
|
@ -174,36 +153,15 @@ public class RuleActivePanel extends FramedPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FieldLabel noRulesLabel = new FieldLabel(null, "No rules applied!");
|
FieldLabel noRulesLabel = new FieldLabel(null, "No rules on column applied!");
|
||||||
noRulesLabel.setLabelSeparator("");
|
noRulesLabel.setLabelSeparator("");
|
||||||
|
noRulesLabel.setLabelWidth(200);
|
||||||
columnRulesFieldSetLayout.add(noRulesLabel, new VerticalLayoutData(
|
columnRulesFieldSetLayout.add(noRulesLabel, new VerticalLayoutData(
|
||||||
1, -1, new Margins(0)));
|
1, -1, new Margins(0)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
btnClose = new TextButton("Close");
|
|
||||||
btnClose.setIcon(ResourceBundle.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(btnClose, new BoxLayoutData(new Margins(2, 4, 2, 4)));
|
|
||||||
|
|
||||||
mainLayoutContainer = new VerticalLayoutContainer();
|
|
||||||
mainLayoutContainer.add(columnRulesFieldSet, new VerticalLayoutData(-1,
|
|
||||||
RULE_ON_COLUMN_FIELDSET_HEIGHT, new Margins(0)));
|
|
||||||
mainLayoutContainer.add(flowButton,
|
|
||||||
new VerticalLayoutData(1, 36, new Margins(5, 2, 5, 2)));
|
|
||||||
add(mainLayoutContainer);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,19 +216,18 @@ public class RuleActivePanel extends FramedPanel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||||
RuleActiveTemplates ruleActiveTemplates = GWT
|
RuleActiveTemplates ruleActiveTemplates = GWT
|
||||||
.create(RuleActiveTemplates .class);
|
.create(RuleActiveTemplates.class);
|
||||||
sb.append(ruleActiveTemplates.format(value));
|
sb.append(ruleActiveTemplates.format(value));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
List<ColumnConfig<RuleDescriptionData, ?>> l = new ArrayList<ColumnConfig<RuleDescriptionData, ?>>();
|
List<ColumnConfig<RuleDescriptionData, ?>> l = new ArrayList<ColumnConfig<RuleDescriptionData, ?>>();
|
||||||
l.add(nameCol);
|
l.add(nameCol);
|
||||||
l.add(descriptionCol);
|
l.add(descriptionCol);
|
||||||
l.add(ownerCol);
|
l.add(ownerCol);
|
||||||
l.add(creationDateCol);
|
l.add(creationDateCol);
|
||||||
|
|
||||||
ColumnModel<RuleDescriptionData> cm = new ColumnModel<RuleDescriptionData>(
|
ColumnModel<RuleDescriptionData> cm = new ColumnModel<RuleDescriptionData>(
|
||||||
l);
|
l);
|
||||||
|
|
||||||
|
@ -316,8 +273,8 @@ public class RuleActivePanel extends FramedPanel {
|
||||||
|
|
||||||
protected void getActiveRulesOnColumn() {
|
protected void getActiveRulesOnColumn() {
|
||||||
|
|
||||||
ExpressionServiceAsync.INSTANCE.getActiveRulesByTabularResourceId(
|
ExpressionServiceAsync.INSTANCE.getActiveRulesByTabularResourceId(trId,
|
||||||
trId, new AsyncCallback<AppliedRulesResponseData>() {
|
new AsyncCallback<AppliedRulesResponseData>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
|
@ -341,12 +298,11 @@ public class RuleActivePanel extends FramedPanel {
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void updateActiveRulesOnColumn() {
|
protected void updateActiveRulesOnColumn() {
|
||||||
|
|
||||||
ExpressionServiceAsync.INSTANCE.getActiveRulesByTabularResourceId(
|
ExpressionServiceAsync.INSTANCE.getActiveRulesByTabularResourceId(trId,
|
||||||
trId, new AsyncCallback<AppliedRulesResponseData>() {
|
new AsyncCallback<AppliedRulesResponseData>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
|
@ -370,20 +326,11 @@ public class RuleActivePanel extends FramedPanel {
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void close() {
|
|
||||||
parent.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected void requestInfo(RuleDescriptionData rule) {
|
protected void requestInfo(RuleDescriptionData rule) {
|
||||||
final RuleInfoDialog infoRuleDialog = new RuleInfoDialog(rule);
|
final RuleInfoDialog infoRuleDialog = new RuleInfoDialog(rule);
|
||||||
infoRuleDialog.show();
|
infoRuleDialog.show();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createContextMenu(final Grid<RuleDescriptionData> grid) {
|
protected void createContextMenu(final Grid<RuleDescriptionData> grid) {
|
||||||
|
@ -403,7 +350,7 @@ public class RuleActivePanel extends FramedPanel {
|
||||||
requestInfo(selected);
|
requestInfo(selected);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
MenuItem detachItem = new MenuItem();
|
MenuItem detachItem = new MenuItem();
|
||||||
detachItem.setText("Detach");
|
detachItem.setText("Detach");
|
||||||
detachItem.setToolTip("Detach rule");
|
detachItem.setToolTip("Detach rule");
|
||||||
|
@ -418,9 +365,7 @@ public class RuleActivePanel extends FramedPanel {
|
||||||
requestDetach(selected, grid);
|
requestDetach(selected, grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
contextMenu.add(infoItem);
|
contextMenu.add(infoItem);
|
||||||
contextMenu.add(detachItem);
|
contextMenu.add(detachItem);
|
||||||
|
@ -431,17 +376,18 @@ public class RuleActivePanel extends FramedPanel {
|
||||||
|
|
||||||
protected void requestDetach(RuleDescriptionData selected,
|
protected void requestDetach(RuleDescriptionData selected,
|
||||||
final Grid<RuleDescriptionData> grid) {
|
final Grid<RuleDescriptionData> grid) {
|
||||||
|
|
||||||
String columnLocalId=grid.getItemId();
|
String columnLocalId = grid.getItemId();
|
||||||
ColumnData columnData=new ColumnData();
|
ColumnData columnData = new ColumnData();
|
||||||
columnData.setColumnId(columnLocalId);
|
columnData.setColumnId(columnLocalId);
|
||||||
ArrayList<RuleDescriptionData> detachRules=new ArrayList<RuleDescriptionData>();
|
ArrayList<RuleDescriptionData> detachRules = new ArrayList<RuleDescriptionData>();
|
||||||
detachRules.add(selected);
|
detachRules.add(selected);
|
||||||
|
|
||||||
DetachColumnRulesSession detachColumnRulesSession=new DetachColumnRulesSession(trId, columnData, detachRules);
|
DetachColumnRulesSession detachColumnRulesSession = new DetachColumnRulesSession(
|
||||||
|
trId, columnData, detachRules);
|
||||||
ExpressionServiceAsync.INSTANCE.setDetachColumnRules(detachColumnRulesSession,
|
|
||||||
new AsyncCallback<Void>() {
|
ExpressionServiceAsync.INSTANCE.setDetachColumnRules(
|
||||||
|
detachColumnRulesSession, new AsyncCallback<Void>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
|
@ -460,22 +406,18 @@ public class RuleActivePanel extends FramedPanel {
|
||||||
public void onSuccess(Void result) {
|
public void onSuccess(Void result) {
|
||||||
updateActiveRulesOnColumn();
|
updateActiveRulesOnColumn();
|
||||||
Log.debug("The rule is detached!");
|
Log.debug("The rule is detached!");
|
||||||
UtilsGXT3.info("Detach Rule",
|
UtilsGXT3.info("Detach Rule", "The rule is detached!");
|
||||||
"The rule is detached!");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void recreate() {
|
||||||
protected void recreate(){
|
|
||||||
remove(mainLayoutContainer);
|
remove(mainLayoutContainer);
|
||||||
create();
|
create();
|
||||||
forceLayout();
|
forceLayout();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,347 @@
|
||||||
|
package org.gcube.portlets.user.td.rulewidget.client;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionServiceAsync;
|
||||||
|
import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleDescriptionDataProperties;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.rule.AppliedRulesResponseData;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.rule.DetachTableRulesSession;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
|
||||||
|
import org.gcube.portlets.user.td.rulewidget.client.resources.ResourceBundle;
|
||||||
|
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.wizardwidget.client.util.UtilsGXT3;
|
||||||
|
|
||||||
|
import com.allen_sauer.gwt.log.client.Log;
|
||||||
|
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.core.client.XTemplates;
|
||||||
|
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
|
||||||
|
import com.sencha.gxt.core.client.util.Margins;
|
||||||
|
import com.sencha.gxt.data.shared.ListStore;
|
||||||
|
import com.sencha.gxt.widget.core.client.FramedPanel;
|
||||||
|
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.form.FieldLabel;
|
||||||
|
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.menu.Item;
|
||||||
|
import com.sencha.gxt.widget.core.client.menu.Menu;
|
||||||
|
import com.sencha.gxt.widget.core.client.menu.MenuItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author giancarlo email: <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RuleActiveOnTablePanel extends FramedPanel {
|
||||||
|
private static final String WIDTH = "760px";
|
||||||
|
private static final String HEIGHT = "418px";
|
||||||
|
|
||||||
|
interface RuleActiveTemplates extends XTemplates {
|
||||||
|
@XTemplate("<span title=\"{value}\">{value}</span>")
|
||||||
|
SafeHtml format(String value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private EventBus eventBus;
|
||||||
|
private TRId trId;
|
||||||
|
|
||||||
|
private AppliedRulesResponseData appliedRuleResponseData;
|
||||||
|
private VerticalLayoutContainer mainLayoutContainer;
|
||||||
|
|
||||||
|
public RuleActiveOnTablePanel(TRId trId, EventBus eventBus) {
|
||||||
|
super();
|
||||||
|
this.trId = trId;
|
||||||
|
this.eventBus = eventBus;
|
||||||
|
Log.debug("RuleActiveOnTablePanel");
|
||||||
|
setWidth(WIDTH);
|
||||||
|
setHeight(HEIGHT);
|
||||||
|
setHeaderVisible(false);
|
||||||
|
setBodyBorder(false);
|
||||||
|
getActiveRules();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void create() {
|
||||||
|
Log.debug("Create RuleActiveOnTablePanel(): " + trId);
|
||||||
|
|
||||||
|
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
||||||
|
v.setScrollMode(ScrollMode.AUTO);
|
||||||
|
v.setAdjustForScroll(true);
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList<RuleDescriptionData> appliedTableRules=appliedRuleResponseData.getTableRules();
|
||||||
|
if (appliedTableRules == null || appliedTableRules.size() <=0) {
|
||||||
|
FieldLabel noRulesLabel = new FieldLabel(null, "No rules on table applied!");
|
||||||
|
noRulesLabel.setLabelSeparator("");
|
||||||
|
noRulesLabel.setLabelWidth(200);
|
||||||
|
v.add(noRulesLabel, new VerticalLayoutData(
|
||||||
|
1, -1, new Margins(0)));
|
||||||
|
add(v);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Grid
|
||||||
|
|
||||||
|
RuleDescriptionDataProperties propsRules = GWT
|
||||||
|
.create(RuleDescriptionDataProperties.class);
|
||||||
|
|
||||||
|
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) {
|
||||||
|
RuleActiveTemplates ruleActiveTemplates = GWT
|
||||||
|
.create(RuleActiveTemplates.class);
|
||||||
|
sb.append(ruleActiveTemplates.format(value));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ColumnConfig<RuleDescriptionData, String> descriptionCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||||
|
propsRules.description(), 120, "Description");
|
||||||
|
descriptionCol.setCell(new AbstractCell<String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||||
|
RuleActiveTemplates ruleActiveTemplates = GWT
|
||||||
|
.create(RuleActiveTemplates.class);
|
||||||
|
sb.append(ruleActiveTemplates.format(value));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ColumnConfig<RuleDescriptionData, String> ownerCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||||
|
propsRules.ownerLogin(), 70, "Owner");
|
||||||
|
ownerCol.setCell(new AbstractCell<String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||||
|
RuleActiveTemplates ruleActiveTemplates = GWT
|
||||||
|
.create(RuleActiveTemplates.class);
|
||||||
|
sb.append(ruleActiveTemplates.format(value));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ColumnConfig<RuleDescriptionData, String> creationDateCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||||
|
propsRules.creationDate(), 50, "Creation Date");
|
||||||
|
|
||||||
|
creationDateCol.setCell(new AbstractCell<String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||||
|
RuleActiveTemplates ruleActiveTemplates = GWT
|
||||||
|
.create(RuleActiveTemplates.class);
|
||||||
|
sb.append(ruleActiveTemplates.format(value));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
List<ColumnConfig<RuleDescriptionData, ?>> l = new ArrayList<ColumnConfig<RuleDescriptionData, ?>>();
|
||||||
|
l.add(nameCol);
|
||||||
|
l.add(descriptionCol);
|
||||||
|
l.add(ownerCol);
|
||||||
|
l.add(creationDateCol);
|
||||||
|
|
||||||
|
ColumnModel<RuleDescriptionData> cm = new ColumnModel<RuleDescriptionData>(
|
||||||
|
l);
|
||||||
|
|
||||||
|
StringFilter<RuleDescriptionData> nameFilter = new StringFilter<RuleDescriptionData>(
|
||||||
|
propsRules.name());
|
||||||
|
StringFilter<RuleDescriptionData> descriptionFilter = new StringFilter<RuleDescriptionData>(
|
||||||
|
propsRules.description());
|
||||||
|
|
||||||
|
// Applies Rules
|
||||||
|
ListStore<RuleDescriptionData> appliedRulesStore = new ListStore<RuleDescriptionData>(
|
||||||
|
propsRules.id());
|
||||||
|
|
||||||
|
|
||||||
|
appliedRulesStore.addAll(appliedTableRules);
|
||||||
|
|
||||||
|
|
||||||
|
final Grid<RuleDescriptionData> gridAppliedRules = new Grid<RuleDescriptionData>(
|
||||||
|
appliedRulesStore, cm);
|
||||||
|
//gridAppliedRules.setHeight(RULES_GRID_HEIGHT);
|
||||||
|
gridAppliedRules.getView().setStripeRows(true);
|
||||||
|
gridAppliedRules.getView().setColumnLines(true);
|
||||||
|
gridAppliedRules.getView().setAutoFill(true);
|
||||||
|
gridAppliedRules.setBorders(false);
|
||||||
|
gridAppliedRules.setLoadMask(true);
|
||||||
|
gridAppliedRules.setColumnReordering(true);
|
||||||
|
gridAppliedRules.setColumnResize(true);
|
||||||
|
gridAppliedRules.getView().setAutoExpandColumn(descriptionCol);
|
||||||
|
|
||||||
|
GridFilters<RuleDescriptionData> filtersAppliesRules = new GridFilters<RuleDescriptionData>();
|
||||||
|
filtersAppliesRules.initPlugin(gridAppliedRules);
|
||||||
|
filtersAppliesRules.setLocal(true);
|
||||||
|
filtersAppliesRules.addFilter(nameFilter);
|
||||||
|
filtersAppliesRules.addFilter(descriptionFilter);
|
||||||
|
|
||||||
|
createContextMenu(gridAppliedRules);
|
||||||
|
|
||||||
|
v.add(gridAppliedRules, new VerticalLayoutData(
|
||||||
|
1, 1, new Margins(0)));
|
||||||
|
add(v);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void getActiveRules() {
|
||||||
|
|
||||||
|
ExpressionServiceAsync.INSTANCE.getActiveRulesByTabularResourceId(trId,
|
||||||
|
new AsyncCallback<AppliedRulesResponseData>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable caught) {
|
||||||
|
if (caught instanceof TDGWTSessionExpiredException) {
|
||||||
|
eventBus.fireEvent(new SessionExpiredEvent(
|
||||||
|
SessionExpiredType.EXPIREDONSERVER));
|
||||||
|
} else {
|
||||||
|
Log.error(caught.getLocalizedMessage());
|
||||||
|
UtilsGXT3.alert("Error retrieving active rules",
|
||||||
|
caught.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(AppliedRulesResponseData result) {
|
||||||
|
Log.trace("AppliedRuleResponseData: " + result);
|
||||||
|
appliedRuleResponseData = result;
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateActiveRulesOnColumn() {
|
||||||
|
|
||||||
|
ExpressionServiceAsync.INSTANCE.getActiveRulesByTabularResourceId(trId,
|
||||||
|
new AsyncCallback<AppliedRulesResponseData>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable caught) {
|
||||||
|
if (caught instanceof TDGWTSessionExpiredException) {
|
||||||
|
eventBus.fireEvent(new SessionExpiredEvent(
|
||||||
|
SessionExpiredType.EXPIREDONSERVER));
|
||||||
|
} else {
|
||||||
|
Log.error(caught.getLocalizedMessage());
|
||||||
|
UtilsGXT3.alert("Error retrieving applied rules",
|
||||||
|
caught.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(AppliedRulesResponseData result) {
|
||||||
|
Log.trace("AppliedRuleResponseData: " + result);
|
||||||
|
appliedRuleResponseData = result;
|
||||||
|
recreate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void requestInfo(RuleDescriptionData rule) {
|
||||||
|
final RuleInfoDialog infoRuleDialog = new RuleInfoDialog(rule);
|
||||||
|
infoRuleDialog.show();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createContextMenu(final Grid<RuleDescriptionData> grid) {
|
||||||
|
Menu contextMenu = new Menu();
|
||||||
|
|
||||||
|
MenuItem infoItem = new MenuItem();
|
||||||
|
infoItem.setText("Info");
|
||||||
|
infoItem.setToolTip("Info");
|
||||||
|
infoItem.setIcon(ResourceBundle.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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
MenuItem detachItem = new MenuItem();
|
||||||
|
detachItem.setText("Detach");
|
||||||
|
detachItem.setToolTip("Detach rule");
|
||||||
|
detachItem.setIcon(ResourceBundle.INSTANCE.ruleColumnDetach());
|
||||||
|
detachItem.addSelectionHandler(new SelectionHandler<Item>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSelection(SelectionEvent<Item> event) {
|
||||||
|
RuleDescriptionData selected = grid.getSelectionModel()
|
||||||
|
.getSelectedItem();
|
||||||
|
Log.debug(selected.toString());
|
||||||
|
requestDetach(selected, grid);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
contextMenu.add(infoItem);
|
||||||
|
contextMenu.add(detachItem);
|
||||||
|
|
||||||
|
grid.setContextMenu(contextMenu);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void requestDetach(RuleDescriptionData selected,
|
||||||
|
final Grid<RuleDescriptionData> grid) {
|
||||||
|
|
||||||
|
ArrayList<RuleDescriptionData> detachRules = new ArrayList<RuleDescriptionData>();
|
||||||
|
detachRules.add(selected);
|
||||||
|
|
||||||
|
DetachTableRulesSession detachTableRulesSession = new DetachTableRulesSession(
|
||||||
|
trId, detachRules);
|
||||||
|
|
||||||
|
ExpressionServiceAsync.INSTANCE.setDetachTableRules(
|
||||||
|
detachTableRulesSession, new AsyncCallback<Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable caught) {
|
||||||
|
if (caught instanceof TDGWTSessionExpiredException) {
|
||||||
|
eventBus.fireEvent(new SessionExpiredEvent(
|
||||||
|
SessionExpiredType.EXPIREDONSERVER));
|
||||||
|
} else {
|
||||||
|
Log.error(caught.getLocalizedMessage());
|
||||||
|
UtilsGXT3.alert("Error in detach rules",
|
||||||
|
caught.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Void result) {
|
||||||
|
updateActiveRulesOnColumn();
|
||||||
|
Log.debug("The rule is detached!");
|
||||||
|
UtilsGXT3.info("Detach Rule", "The rule is detached!");
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void recreate() {
|
||||||
|
remove(mainLayoutContainer);
|
||||||
|
create();
|
||||||
|
forceLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package org.gcube.portlets.user.td.rulewidget.client;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||||
|
|
||||||
|
import com.allen_sauer.gwt.log.client.Log;
|
||||||
|
import com.google.web.bindery.event.shared.EventBus;
|
||||||
|
import com.sencha.gxt.widget.core.client.TabItemConfig;
|
||||||
|
import com.sencha.gxt.widget.core.client.TabPanel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author giancarlo
|
||||||
|
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RuleActiveTabPanel extends TabPanel {
|
||||||
|
private EventBus eventBus;
|
||||||
|
private RuleActiveOnColumnPanel ruleActiveOnColumnPanel;
|
||||||
|
private TRId trId;
|
||||||
|
private RuleActiveOnTablePanel ruleActiveOnTablePanel;
|
||||||
|
|
||||||
|
public RuleActiveTabPanel(TRId trId, EventBus eventBus) {
|
||||||
|
super();
|
||||||
|
Log.debug("Create RuleActiveTabPanel");
|
||||||
|
this.trId=trId;
|
||||||
|
this.eventBus = eventBus;
|
||||||
|
setBodyBorder(false);
|
||||||
|
setBorders(false);
|
||||||
|
setAnimScroll(true);
|
||||||
|
setTabScroll(true);
|
||||||
|
setCloseContextMenu(false);
|
||||||
|
addTabs();
|
||||||
|
startTabs();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startTabs() {
|
||||||
|
Log.debug("Start RuleActiveTabPanel Tabs");
|
||||||
|
setActiveWidget(getWidget(0));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addTabs(){
|
||||||
|
TabItemConfig ruleOnColumnItemConf = new TabItemConfig(
|
||||||
|
"Rule On Column", false);
|
||||||
|
|
||||||
|
ruleActiveOnColumnPanel = new RuleActiveOnColumnPanel(trId,eventBus);
|
||||||
|
add(ruleActiveOnColumnPanel, ruleOnColumnItemConf);
|
||||||
|
|
||||||
|
TabItemConfig ruleOnTableItemConf = new TabItemConfig(
|
||||||
|
"Rule On Table", false);
|
||||||
|
|
||||||
|
ruleActiveOnTablePanel = new RuleActiveOnTablePanel(trId,eventBus);
|
||||||
|
add(ruleActiveOnTablePanel, ruleOnTableItemConf);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue