81: Allow the creation and use of expressions on multi column in TDM portlet
Task-Url: https://support.d4science.org/issues/81 Updated Rule on Table creation git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-portlet@114810 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b5efb227e0
commit
f24177423e
7
pom.xml
7
pom.xml
|
@ -297,6 +297,13 @@
|
|||
<artifactId>tabular-data-share-widget</artifactId>
|
||||
<version>[0.0.1-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<!-- tabular-data-rule-widget -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>tabular-data-rule-widget</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<!-- tabular-data-csv-import-widget -->
|
||||
<dependency>
|
||||
|
|
|
@ -8,11 +8,6 @@ import java.util.HashMap;
|
|||
import org.gcube.portlets.user.td.chartswidget.client.ChartsWidgetTD;
|
||||
import org.gcube.portlets.user.td.client.logs.TDMLogs;
|
||||
import org.gcube.portlets.user.td.client.rstudio.RStudio;
|
||||
import org.gcube.portlets.user.td.client.rule.RuleActiveDialog;
|
||||
import org.gcube.portlets.user.td.client.rule.RuleApplyDialog;
|
||||
import org.gcube.portlets.user.td.client.rule.RuleDeleteDialog;
|
||||
import org.gcube.portlets.user.td.client.rule.RuleOpenDialog;
|
||||
import org.gcube.portlets.user.td.client.rule.RuleShareDialog;
|
||||
import org.gcube.portlets.user.td.client.template.TemplateApplyDialog;
|
||||
import org.gcube.portlets.user.td.client.template.TemplateDeleteDialog;
|
||||
import org.gcube.portlets.user.td.client.template.TemplateOpenDialog;
|
||||
|
@ -25,7 +20,7 @@ import org.gcube.portlets.user.td.csvimportwidget.client.CSVImportWizardTD;
|
|||
import org.gcube.portlets.user.td.expressionwidget.client.MultiColumnFilterDialog;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.ReplaceColumnByMultiColumnExpressionDialog;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.RowsDeleteByMultiColumnExpressionDialog;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.RuleDialog;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.RuleOnColumnCreateDialog;
|
||||
import org.gcube.portlets.user.td.extractcodelistwidget.client.ExtractCodelistWizardTD;
|
||||
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
|
||||
|
@ -37,6 +32,11 @@ import org.gcube.portlets.user.td.mainboxwidget.client.MainBoxPanel;
|
|||
import org.gcube.portlets.user.td.mapwidget.client.MapWidgetTD;
|
||||
import org.gcube.portlets.user.td.openwidget.client.TDOpen;
|
||||
import org.gcube.portlets.user.td.replacebyexternalwidget.client.ReplaceByExternalTD;
|
||||
import org.gcube.portlets.user.td.rulewidget.client.RuleActiveDialog;
|
||||
import org.gcube.portlets.user.td.rulewidget.client.RuleApplyDialog;
|
||||
import org.gcube.portlets.user.td.rulewidget.client.RuleDeleteDialog;
|
||||
import org.gcube.portlets.user.td.rulewidget.client.RuleOpenDialog;
|
||||
import org.gcube.portlets.user.td.rulewidget.client.RuleShareDialog;
|
||||
import org.gcube.portlets.user.td.sdmxexportwidget.client.SDMXExportWizardTD;
|
||||
import org.gcube.portlets.user.td.sdmximportwidget.client.SDMXImportWizardTD;
|
||||
import org.gcube.portlets.user.td.sharewidget.client.TRShare;
|
||||
|
@ -1714,7 +1714,7 @@ public class TabularDataController {
|
|||
|
||||
private void openNewRule() {
|
||||
Log.debug("Request Open New Rule Dialog");
|
||||
RuleDialog cfDialog = new RuleDialog(eventBus);
|
||||
RuleOnColumnCreateDialog cfDialog = new RuleOnColumnCreateDialog(eventBus);
|
||||
cfDialog.show();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
package org.gcube.portlets.user.td.client.rule;
|
||||
|
||||
import org.gcube.portlets.user.td.client.resource.TabularDataResources;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.sencha.gxt.widget.core.client.Window;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class RuleActiveDialog extends Window {
|
||||
private static final String WIDTH = "720px";
|
||||
private static final String HEIGHT = "428px";
|
||||
public RuleActiveDialog(TRId trId, EventBus eventBus) {
|
||||
initWindow();
|
||||
|
||||
RuleActivePanel ruleActivePanel = new RuleActivePanel(this,
|
||||
trId, eventBus);
|
||||
add(ruleActivePanel);
|
||||
}
|
||||
|
||||
protected void initWindow() {
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
setBodyBorder(false);
|
||||
setResizable(false);
|
||||
setHeadingText("Active Rules On TabularResource");
|
||||
setClosable(true);
|
||||
setModal(true);
|
||||
forceLayoutOnResize = true;
|
||||
getHeader().setIcon(TabularDataResources.INSTANCE.ruleTabularResource());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void initTools() {
|
||||
super.initTools();
|
||||
|
||||
closeBtn.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,481 +0,0 @@
|
|||
package org.gcube.portlets.user.td.client.rule;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.user.td.client.resource.TabularDataResources;
|
||||
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.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.AppliedRulesResponseData;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.rule.DetachColumnRulesSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
|
||||
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.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.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.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.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 RuleActivePanel extends FramedPanel {
|
||||
private static final int RULE_ON_COLUMN_FIELDSET_HEIGHT = 348;
|
||||
private static final String RULES_GRID_HEIGHT = "102px";
|
||||
private static final String WIDTH = "630px";
|
||||
private static final String HEIGHT = "418px";
|
||||
|
||||
interface RuleApplyTemplates extends XTemplates {
|
||||
@XTemplate("<span title=\"{value}\">{value}</span>")
|
||||
SafeHtml format(String value);
|
||||
}
|
||||
|
||||
private EventBus eventBus;
|
||||
private RuleActiveDialog parent;
|
||||
private TRId trId;
|
||||
private ArrayList<ColumnData> columns;
|
||||
|
||||
private AppliedRulesResponseData appliedRuleResponseData;
|
||||
|
||||
private TextButton btnClose;
|
||||
private VerticalLayoutContainer mainLayoutContainer;
|
||||
|
||||
public RuleActivePanel(RuleActiveDialog parent, TRId trId,
|
||||
EventBus eventBus) {
|
||||
this.parent = parent;
|
||||
this.trId = trId;
|
||||
|
||||
Log.debug("RuleActivePanel");
|
||||
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;
|
||||
|
||||
getActiveRulesOnColumn();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void create() {
|
||||
|
||||
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();
|
||||
columnRulesFieldSetLayout.setScrollMode(ScrollMode.AUTO);
|
||||
columnRulesFieldSetLayout.setAdjustForScroll(true);
|
||||
|
||||
columnRulesFieldSet.add(columnRulesFieldSetLayout);
|
||||
|
||||
HashMap<String, ArrayList<RuleDescriptionData>> columnRuleMapping = appliedRuleResponseData
|
||||
.getColumnRuleMapping();
|
||||
if (columnRuleMapping != null && columnRuleMapping.size() > 0) {
|
||||
|
||||
for (ColumnData column : columns) {
|
||||
ArrayList<RuleDescriptionData> columnAppliedRules = columnRuleMapping
|
||||
.get(column.getColumnId());
|
||||
if (columnAppliedRules != null && columnAppliedRules.size() > 0) {
|
||||
FieldLabel columnLabel = createColumnRules(column,
|
||||
columnAppliedRules);
|
||||
columnRulesFieldSetLayout.add(columnLabel,
|
||||
new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
FieldLabel noRulesLabel = new FieldLabel(null, "No rules applied!");
|
||||
noRulesLabel.setLabelSeparator("");
|
||||
columnRulesFieldSetLayout.add(noRulesLabel, new VerticalLayoutData(
|
||||
1, -1, new Margins(0)));
|
||||
|
||||
}
|
||||
|
||||
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(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);
|
||||
|
||||
}
|
||||
|
||||
private FieldLabel createColumnRules(ColumnData column,
|
||||
ArrayList<RuleDescriptionData> columnAppliedRules) {
|
||||
// Rules
|
||||
|
||||
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) {
|
||||
RuleApplyTemplates ruleApplyTemplates = GWT
|
||||
.create(RuleApplyTemplates.class);
|
||||
sb.append(ruleApplyTemplates.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) {
|
||||
RuleApplyTemplates ruleApplyTemplates = GWT
|
||||
.create(RuleApplyTemplates.class);
|
||||
sb.append(ruleApplyTemplates.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) {
|
||||
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());
|
||||
|
||||
// Applies Rules
|
||||
ListStore<RuleDescriptionData> appliedRulesStore = new ListStore<RuleDescriptionData>(
|
||||
propsRules.id());
|
||||
|
||||
if (columnAppliedRules != null && columnAppliedRules.size() > 0) {
|
||||
appliedRulesStore.addAll(columnAppliedRules);
|
||||
}
|
||||
|
||||
final Grid<RuleDescriptionData> gridAppliedRules = new Grid<RuleDescriptionData>(
|
||||
appliedRulesStore, cm);
|
||||
gridAppliedRules.setItemId(column.getColumnId());
|
||||
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);
|
||||
|
||||
FieldLabel rulesAppliedLabel = new FieldLabel(gridAppliedRules,
|
||||
column.getLabel());
|
||||
|
||||
return rulesAppliedLabel;
|
||||
}
|
||||
|
||||
protected void getActiveRulesOnColumn() {
|
||||
|
||||
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 close() {
|
||||
parent.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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(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);
|
||||
}
|
||||
});
|
||||
|
||||
MenuItem detachItem = new MenuItem();
|
||||
detachItem.setText("Detach");
|
||||
detachItem.setToolTip("Detach rule");
|
||||
detachItem.setIcon(TabularDataResources.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) {
|
||||
|
||||
String columnLocalId=grid.getItemId();
|
||||
ColumnData columnData=new ColumnData();
|
||||
columnData.setColumnId(columnLocalId);
|
||||
ArrayList<RuleDescriptionData> detachRules=new ArrayList<RuleDescriptionData>();
|
||||
detachRules.add(selected);
|
||||
|
||||
DetachColumnRulesSession detachColumnRulesSession=new DetachColumnRulesSession(trId, columnData, detachRules);
|
||||
|
||||
ExpressionServiceAsync.INSTANCE.setDetachColumnRules(detachColumnRulesSession,
|
||||
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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,171 +0,0 @@
|
|||
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.rpc.ExpressionServiceAsync;
|
||||
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.ApplyAndDetachColumnRulesSession;
|
||||
import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialog;
|
||||
import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialogListener;
|
||||
import org.gcube.portlets.user.td.tablewidget.client.util.UtilsGXT3;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.client.event.ChangeTableRequestEvent;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableRequestType;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableWhy;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.OperationResult;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.sencha.gxt.widget.core.client.Window;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class RuleApplyDialog extends Window implements
|
||||
MonitorDialogListener {
|
||||
private static final String WIDTH = "720px";
|
||||
private static final String HEIGHT = "530px";
|
||||
private EventBus eventBus;
|
||||
|
||||
public RuleApplyDialog(TRId trId, EventBus eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
initWindow();
|
||||
|
||||
RuleApplyPanel ruleApplyPanel = new RuleApplyPanel(this,
|
||||
trId, eventBus);
|
||||
add(ruleApplyPanel);
|
||||
}
|
||||
|
||||
protected void initWindow() {
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
setBodyBorder(false);
|
||||
setResizable(false);
|
||||
setHeadingText("Apply Rules On Column");
|
||||
setClosable(true);
|
||||
setModal(true);
|
||||
forceLayoutOnResize = true;
|
||||
getHeader().setIcon(TabularDataResources.INSTANCE.ruleColumnApply());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void initTools() {
|
||||
super.initTools();
|
||||
|
||||
closeBtn.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
hide();
|
||||
}
|
||||
|
||||
protected void applyRules(ApplyAndDetachColumnRulesSession applyColumnRulesSession) {
|
||||
ExpressionServiceAsync.INSTANCE.startApplyAndDetachColumnRules(applyColumnRulesSession, new AsyncCallback<String>() {
|
||||
|
||||
@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 Is Final",
|
||||
caught.getLocalizedMessage());
|
||||
} else {
|
||||
Log.debug("Apply Rules On Column Error: "
|
||||
+ caught.getLocalizedMessage());
|
||||
UtilsGXT3
|
||||
.alert("Apply Rules On Column",
|
||||
caught.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String taskId) {
|
||||
if(taskId!=null){
|
||||
openMonitorDialog(taskId);
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void openMonitorDialog(String taskId) {
|
||||
MonitorDialog monitorDialog = new MonitorDialog(taskId, eventBus);
|
||||
monitorDialog.addProgressDialogListener(this);
|
||||
monitorDialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationComplete(OperationResult operationResult) {
|
||||
ChangeTableWhy why = ChangeTableWhy.TABLEUPDATED;
|
||||
ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent(
|
||||
ChangeTableRequestType.RULESONCOLUMNAPPLY, operationResult.getTrId(), why);
|
||||
eventBus.fireEvent(changeTableRequestEvent);
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationFailed(Throwable caught, String reason, String details) {
|
||||
UtilsGXT3.alert(reason, details);
|
||||
close();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationStopped(OperationResult operationResult, String reason, String details) {
|
||||
ChangeTableWhy why = ChangeTableWhy.TABLECURATION;
|
||||
ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent(
|
||||
ChangeTableRequestType.RULESONCOLUMNAPPLY, operationResult.getTrId(), why);
|
||||
eventBus.fireEvent(changeTableRequestEvent);
|
||||
close();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationAborted() {
|
||||
close();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationPutInBackground() {
|
||||
close();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,602 +0,0 @@
|
|||
package org.gcube.portlets.user.td.client.rule;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
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.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;
|
||||
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.ApplyAndDetachColumnRulesSession;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
|
||||
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.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.gwt.user.client.ui.HTML;
|
||||
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.shared.LabelProvider;
|
||||
import com.sencha.gxt.data.shared.ListStore;
|
||||
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;
|
||||
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.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.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;
|
||||
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 RuleApplyPanel extends FramedPanel {
|
||||
private static final String RULE_TIP = "<p>Tip.: Use drag and drop in order to change selected rules.</p>";
|
||||
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 AppliedRulesResponseData appliedRuleResponseData;
|
||||
private ArrayList<RuleDescriptionData> applicableRules;
|
||||
private ArrayList<RuleDescriptionData> appliedRules;
|
||||
|
||||
private TextButton btnApply;
|
||||
private TextButton btnClose;
|
||||
|
||||
private ComboBox<ColumnData> comboColumns;
|
||||
private ListStore<RuleDescriptionData> applicableRulesStore;
|
||||
private Grid<RuleDescriptionData> gridApplicableRules;
|
||||
private ListStore<RuleDescriptionData> selectedRulesStore;
|
||||
private Grid<RuleDescriptionData> gridSelectedRules;
|
||||
|
||||
public RuleApplyPanel(RuleApplyDialog parent, TRId trId, EventBus eventBus) {
|
||||
this.parent = parent;
|
||||
this.trId = trId;
|
||||
applicableRules = new ArrayList<RuleDescriptionData>();
|
||||
|
||||
Log.debug("RuleApplyPanel");
|
||||
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;
|
||||
|
||||
getAppliedBaseColumnRules();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
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) {
|
||||
RuleApplyTemplates ruleApplyTemplates = GWT
|
||||
.create(RuleApplyTemplates.class);
|
||||
sb.append(ruleApplyTemplates.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) {
|
||||
RuleApplyTemplates ruleApplyTemplates = GWT
|
||||
.create(RuleApplyTemplates.class);
|
||||
sb.append(ruleApplyTemplates.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) {
|
||||
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());
|
||||
|
||||
// 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);
|
||||
|
||||
GridFilters<RuleDescriptionData> filtersApplicableRules = new GridFilters<RuleDescriptionData>();
|
||||
filtersApplicableRules.initPlugin(gridApplicableRules);
|
||||
filtersApplicableRules.setLocal(true);
|
||||
filtersApplicableRules.addFilter(nameFilter);
|
||||
filtersApplicableRules.addFilter(descriptionFilter);
|
||||
|
||||
createContextMenu(gridApplicableRules);
|
||||
|
||||
// Selected Rules
|
||||
selectedRulesStore = new ListStore<RuleDescriptionData>(propsRules.id());
|
||||
|
||||
gridSelectedRules = new Grid<RuleDescriptionData>(selectedRulesStore,
|
||||
cm);
|
||||
gridSelectedRules.setHeight(RULES_GRID_HEIGHT);
|
||||
gridSelectedRules.getView().setStripeRows(true);
|
||||
gridSelectedRules.getView().setColumnLines(true);
|
||||
gridSelectedRules.getView().setAutoFill(true);
|
||||
gridSelectedRules.setBorders(false);
|
||||
gridSelectedRules.setLoadMask(true);
|
||||
gridSelectedRules.setColumnReordering(true);
|
||||
gridSelectedRules.setColumnResize(true);
|
||||
gridSelectedRules.getView().setAutoExpandColumn(descriptionCol);
|
||||
|
||||
GridFilters<RuleDescriptionData> filtersSelectedRules = new GridFilters<RuleDescriptionData>();
|
||||
filtersSelectedRules.initPlugin(gridSelectedRules);
|
||||
filtersSelectedRules.setLocal(true);
|
||||
filtersSelectedRules.addFilter(nameFilter);
|
||||
filtersSelectedRules.addFilter(descriptionFilter);
|
||||
|
||||
createContextMenu(gridSelectedRules);
|
||||
|
||||
//
|
||||
|
||||
new GridDragSource<RuleDescriptionData>(gridApplicableRules)
|
||||
.setGroup(SET_RULES);
|
||||
new GridDragSource<RuleDescriptionData>(gridSelectedRules)
|
||||
.setGroup(SET_RULES);
|
||||
|
||||
new GridDropTarget<RuleDescriptionData>(gridApplicableRules)
|
||||
.setGroup(SET_RULES);
|
||||
new GridDropTarget<RuleDescriptionData>(gridSelectedRules)
|
||||
.setGroup(SET_RULES);
|
||||
|
||||
//
|
||||
FieldLabel rulesApplicableLabel = new FieldLabel(gridApplicableRules,
|
||||
"Applicable Rules");
|
||||
|
||||
configurationFieldSetLayout.add(rulesApplicableLabel,
|
||||
new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
|
||||
FieldLabel rulesSelectedLabel = new FieldLabel(gridSelectedRules,
|
||||
"Selected Rules");
|
||||
|
||||
configurationFieldSetLayout.add(rulesSelectedLabel,
|
||||
new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
|
||||
//
|
||||
HTML rulesNote = new HTML(RULE_TIP);
|
||||
configurationFieldSetLayout.add(rulesNote,
|
||||
new VerticalLayoutData(-1, -1, new Margins(0)));
|
||||
// Button
|
||||
btnApply = new TextButton("Apply");
|
||||
btnApply.setIcon(TabularDataResources.INSTANCE.ruleColumnApply());
|
||||
btnApply.setIconAlign(IconAlign.RIGHT);
|
||||
btnApply.setToolTip("Apply Rule");
|
||||
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();
|
||||
updateRulesInGrids(columnData);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void updateRulesInGrids(ColumnData columnData) {
|
||||
column = columnData;
|
||||
applicableRulesStore.clear();
|
||||
selectedRulesStore.clear();
|
||||
HashMap<String, ArrayList<RuleDescriptionData>> columnRuleMapping = appliedRuleResponseData
|
||||
.getColumnRuleMapping();
|
||||
|
||||
if (columnRuleMapping != null) {
|
||||
ArrayList<RuleDescriptionData> applied = columnRuleMapping
|
||||
.get(columnData.getColumnId());
|
||||
|
||||
if (applied != null) {
|
||||
appliedRules = applied;
|
||||
selectedRulesStore.addAll(new ArrayList<RuleDescriptionData>(
|
||||
applied));
|
||||
|
||||
}
|
||||
}
|
||||
getApplicableBaseColumnRules();
|
||||
|
||||
}
|
||||
|
||||
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(caught.getLocalizedMessage());
|
||||
UtilsGXT3.alert(
|
||||
"Error retrieving applicable rules",
|
||||
caught.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(ArrayList<RuleDescriptionData> result) {
|
||||
Log.trace("loaded " + result.size() + " Rules");
|
||||
if (appliedRules != null && appliedRules.size() > 0) {
|
||||
ArrayList<RuleDescriptionData> removableRules = new ArrayList<RuleDescriptionData>();
|
||||
for (RuleDescriptionData ruleApplied : appliedRules) {
|
||||
for (RuleDescriptionData ruleApplicable : result) {
|
||||
if (ruleApplicable.equals(ruleApplied)) {
|
||||
removableRules.add(ruleApplicable);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
result.removeAll(removableRules);
|
||||
|
||||
}
|
||||
applicableRules = result;
|
||||
applicableRulesStore
|
||||
.addAll(new ArrayList<RuleDescriptionData>(
|
||||
applicableRules));
|
||||
|
||||
forceLayout();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void getAppliedBaseColumnRules() {
|
||||
|
||||
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 selected rules",
|
||||
caught.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(AppliedRulesResponseData result) {
|
||||
Log.trace("AppliedRuleResponseData: " + result);
|
||||
appliedRuleResponseData = result;
|
||||
create();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected ArrayList<RuleDescriptionData> getSelectedItems() {
|
||||
List<RuleDescriptionData> selectedItems = selectedRulesStore.getAll();
|
||||
ArrayList<RuleDescriptionData> rulesSelected = new ArrayList<RuleDescriptionData>(
|
||||
selectedItems);
|
||||
return rulesSelected;
|
||||
}
|
||||
|
||||
protected void apply() {
|
||||
ColumnData column = comboColumns.getCurrentValue();
|
||||
if (column != null) {
|
||||
ArrayList<RuleDescriptionData> selectedRules = getSelectedItems();
|
||||
if(selectedRules==null){
|
||||
selectedRules=new ArrayList<RuleDescriptionData>();
|
||||
}
|
||||
ArrayList<RuleDescriptionData> rulesThatWillBeDetach = new ArrayList<RuleDescriptionData>();
|
||||
ArrayList<RuleDescriptionData> rulesThatWillBeApplied = new ArrayList<RuleDescriptionData>();
|
||||
HashMap<String, ArrayList<RuleDescriptionData>> columnRuleMapping = appliedRuleResponseData
|
||||
.getColumnRuleMapping();
|
||||
if (columnRuleMapping != null) {
|
||||
ArrayList<RuleDescriptionData> rulesApplied = columnRuleMapping
|
||||
.get(column.getColumnId());
|
||||
if (rulesApplied != null && rulesApplied.size() > 0) {
|
||||
for (RuleDescriptionData ruleApplied : rulesApplied) {
|
||||
boolean ruleStillApplied = false;
|
||||
for (RuleDescriptionData ruleSelected : selectedRules) {
|
||||
if (ruleSelected.getId() == ruleApplied.getId()) {
|
||||
ruleStillApplied = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ruleStillApplied) {
|
||||
rulesThatWillBeDetach.add(ruleApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (RuleDescriptionData ruleSelected : selectedRules) {
|
||||
boolean ruleApplied = false;
|
||||
|
||||
if (columnRuleMapping != null) {
|
||||
ArrayList<RuleDescriptionData> rulesApplied = columnRuleMapping
|
||||
.get(column.getColumnId());
|
||||
if (rulesApplied != null) {
|
||||
for (RuleDescriptionData ruleAlreadyApplied : rulesApplied) {
|
||||
if (ruleSelected.getId() == ruleAlreadyApplied
|
||||
.getId()) {
|
||||
ruleApplied = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
if (ruleApplied == false) {
|
||||
rulesThatWillBeApplied.add(ruleSelected);
|
||||
}
|
||||
}
|
||||
|
||||
if(rulesThatWillBeApplied.size()<=0&&rulesThatWillBeDetach.size()<=0){
|
||||
Log.error("Select a rule!");
|
||||
UtilsGXT3.alert("Attention", "Select a rule!");
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyAndDetachColumnRulesSession applyColumnRulesSession = new ApplyAndDetachColumnRulesSession(
|
||||
trId, column, rulesThatWillBeApplied, rulesThatWillBeDetach);
|
||||
parent.applyRules(applyColumnRulesSession);
|
||||
|
||||
} else {
|
||||
Log.error("No column selected");
|
||||
UtilsGXT3.alert("Attention", "Select a column");
|
||||
}
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
parent.close();
|
||||
}
|
||||
|
||||
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.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);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
package org.gcube.portlets.user.td.client.rule;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.gcube.portlets.user.td.client.resource.TabularDataResources;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionServiceAsync;
|
||||
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.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 com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.sencha.gxt.widget.core.client.Window;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class RuleDeleteDialog extends Window {
|
||||
private static final String WIDTH = "720px";
|
||||
private static final String HEIGHT = "530px";
|
||||
private EventBus eventBus;
|
||||
private RuleDeletePanel ruleDeletePanel;
|
||||
|
||||
public RuleDeleteDialog(EventBus eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
initWindow();
|
||||
|
||||
ruleDeletePanel = new RuleDeletePanel(this,
|
||||
eventBus);
|
||||
add(ruleDeletePanel);
|
||||
}
|
||||
|
||||
protected void initWindow() {
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
setBodyBorder(false);
|
||||
setResizable(false);
|
||||
setHeadingText("Delete Rule");
|
||||
setClosable(true);
|
||||
setModal(true);
|
||||
forceLayoutOnResize = true;
|
||||
getHeader().setIcon(TabularDataResources.INSTANCE.ruleDelete());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void initTools() {
|
||||
super.initTools();
|
||||
|
||||
closeBtn.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
hide();
|
||||
}
|
||||
|
||||
protected void removeRule(
|
||||
ArrayList<RuleDescriptionData> rules) {
|
||||
|
||||
ExpressionServiceAsync.INSTANCE.removeRulesById(rules,
|
||||
new AsyncCallback<Void>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(Void v) {
|
||||
Log.debug("Rule is deleted!");
|
||||
UtilsGXT3.info("Delete Rule", "The rule is deleted!");
|
||||
ruleDeletePanel.gridReload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
if (caught instanceof TDGWTSessionExpiredException) {
|
||||
eventBus.fireEvent(new SessionExpiredEvent(
|
||||
SessionExpiredType.EXPIREDONSERVER));
|
||||
} else {
|
||||
Log.error("Error deleting column rule: "
|
||||
+ caught.getLocalizedMessage());
|
||||
caught.printStackTrace();
|
||||
UtilsGXT3.alert("Error deleting column rule",
|
||||
caught.getLocalizedMessage());
|
||||
}
|
||||
ruleDeletePanel.gridReload();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -1,430 +0,0 @@
|
|||
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.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.RuleDescriptionData;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType;
|
||||
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 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.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;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
|
||||
import com.sencha.gxt.core.client.IdentityValueProvider;
|
||||
import com.sencha.gxt.core.client.Style.SelectionMode;
|
||||
import com.sencha.gxt.core.client.XTemplates;
|
||||
import com.sencha.gxt.core.client.resources.ThemeStyles;
|
||||
import com.sencha.gxt.core.client.util.Margins;
|
||||
import com.sencha.gxt.data.client.loader.RpcProxy;
|
||||
import com.sencha.gxt.data.shared.ListStore;
|
||||
import com.sencha.gxt.data.shared.ModelKeyProvider;
|
||||
import com.sencha.gxt.data.shared.Store;
|
||||
import com.sencha.gxt.data.shared.Store.StoreFilter;
|
||||
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.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;
|
||||
|
||||
public class RuleDeletePanel extends FramedPanel {
|
||||
private static final String WIDTH = "630px";
|
||||
private static final String HEIGHT = "520px";
|
||||
|
||||
interface RuleDeleteTemplates extends XTemplates {
|
||||
@XTemplate("<span title=\"{value}\">{value}</span>")
|
||||
SafeHtml format(String value);
|
||||
}
|
||||
|
||||
private EventBus eventBus;
|
||||
private RuleDeleteDialog parent;
|
||||
|
||||
private TextButton btnDelete;
|
||||
private TextButton btnClose;
|
||||
|
||||
private ListLoader<ListLoadConfig, ListLoadResult<RuleDescriptionData>> loader;
|
||||
private Grid<RuleDescriptionData> grid;
|
||||
private ExtendedListStore<RuleDescriptionData> store;
|
||||
|
||||
public RuleDeletePanel(RuleDeleteDialog parent, EventBus eventBus) {
|
||||
this.parent = parent;
|
||||
Log.debug("RuleDeletePanel");
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
setHeaderVisible(false);
|
||||
setBodyBorder(false);
|
||||
this.eventBus = eventBus;
|
||||
|
||||
create();
|
||||
|
||||
}
|
||||
|
||||
protected void create() {
|
||||
ToolBar toolBarHead = new ToolBar();
|
||||
toolBarHead.add(new LabelToolItem("Search: "));
|
||||
final TextField searchField = new TextField();
|
||||
toolBarHead.add(searchField);
|
||||
|
||||
TextButton btnReload = new TextButton();
|
||||
// btnReload.setText("Reload");
|
||||
btnReload.setIcon(TabularDataResources.INSTANCE.refresh());
|
||||
btnReload.setToolTip("Reload");
|
||||
toolBarHead.add(btnReload);
|
||||
|
||||
IdentityValueProvider<RuleDescriptionData> identity = new IdentityValueProvider<RuleDescriptionData>();
|
||||
CheckBoxSelectionModel<RuleDescriptionData> sm = new CheckBoxSelectionModel<RuleDescriptionData>(
|
||||
identity);
|
||||
|
||||
RuleDescriptionDataProperties props = GWT
|
||||
.create(RuleDescriptionDataProperties.class);
|
||||
|
||||
ColumnConfig<RuleDescriptionData, String> nameCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.name(), 120, "Name");
|
||||
|
||||
nameCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleDeleteTemplates ruleDeleteTemplates = GWT
|
||||
.create(RuleDeleteTemplates.class);
|
||||
sb.append(ruleDeleteTemplates.format(value));
|
||||
}
|
||||
});
|
||||
|
||||
ColumnConfig<RuleDescriptionData, String> scopeCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.scopeLabel(), 40, "Scope");
|
||||
|
||||
nameCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleDeleteTemplates ruleDeleteTemplates = GWT
|
||||
.create(RuleDeleteTemplates.class);
|
||||
sb.append(ruleDeleteTemplates.format(value));
|
||||
}
|
||||
});
|
||||
|
||||
ColumnConfig<RuleDescriptionData, String> descriptionCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.description(), 120, "Description");
|
||||
descriptionCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleDeleteTemplates ruleDeleteTemplates = GWT
|
||||
.create(RuleDeleteTemplates.class);
|
||||
sb.append(ruleDeleteTemplates.format(value));
|
||||
}
|
||||
});
|
||||
|
||||
ColumnConfig<RuleDescriptionData, String> ownerCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.ownerLogin(), 70, "Owner");
|
||||
ownerCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleDeleteTemplates ruleDeleteTemplates = GWT
|
||||
.create(RuleDeleteTemplates.class);
|
||||
sb.append(ruleDeleteTemplates.format(value));
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
ColumnConfig<RuleDescriptionData, String> readableExpressionCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.readableExpression(), 160, "Expression");
|
||||
|
||||
readableExpressionCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleDeleteTemplates ruleDeleteTemplates = GWT
|
||||
.create(RuleDeleteTemplates.class);
|
||||
sb.append(ruleDeleteTemplates.format(value));
|
||||
}
|
||||
});*/
|
||||
|
||||
List<ColumnConfig<RuleDescriptionData, ?>> l = new ArrayList<ColumnConfig<RuleDescriptionData, ?>>();
|
||||
l.add(nameCol);
|
||||
l.add(scopeCol);
|
||||
l.add(descriptionCol);
|
||||
l.add(ownerCol);
|
||||
//l.add(readableExpressionCol);
|
||||
|
||||
ColumnModel<RuleDescriptionData> cm = new ColumnModel<RuleDescriptionData>(
|
||||
l);
|
||||
|
||||
store = new ExtendedListStore<RuleDescriptionData>(props.id());
|
||||
|
||||
searchField.addKeyUpHandler(new KeyUpHandler() {
|
||||
|
||||
public void onKeyUp(KeyUpEvent event) {
|
||||
Log.trace("searchTerm: " + searchField.getCurrentValue());
|
||||
store.applyFilters();
|
||||
}
|
||||
});
|
||||
|
||||
store.addFilter(new StoreFilter<RuleDescriptionData>() {
|
||||
|
||||
@Override
|
||||
public boolean select(Store<RuleDescriptionData> store,
|
||||
RuleDescriptionData parent, RuleDescriptionData item) {
|
||||
String searchTerm = searchField.getCurrentValue();
|
||||
if (searchTerm == null)
|
||||
return true;
|
||||
return RuleDeletePanel.this.select(item, searchTerm);
|
||||
}
|
||||
});
|
||||
|
||||
store.setEnableFilters(true);
|
||||
|
||||
RpcProxy<ListLoadConfig, ListLoadResult<RuleDescriptionData>> proxy = new RpcProxy<ListLoadConfig, ListLoadResult<RuleDescriptionData>>() {
|
||||
|
||||
public void load(
|
||||
ListLoadConfig loadConfig,
|
||||
final AsyncCallback<ListLoadResult<RuleDescriptionData>> callback) {
|
||||
loadData(loadConfig, callback);
|
||||
}
|
||||
};
|
||||
loader = new ListLoader<ListLoadConfig, ListLoadResult<RuleDescriptionData>>(
|
||||
proxy);
|
||||
|
||||
loader.setRemoteSort(false);
|
||||
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, RuleDescriptionData, ListLoadResult<RuleDescriptionData>>(
|
||||
store) {
|
||||
});
|
||||
|
||||
SelectHandler sh = new SelectHandler() {
|
||||
public void onSelect(SelectEvent event) {
|
||||
loader.load();
|
||||
}
|
||||
};
|
||||
|
||||
btnReload.addSelectHandler(sh);
|
||||
|
||||
grid = new Grid<RuleDescriptionData>(store, cm) {
|
||||
@Override
|
||||
protected void onAfterFirstAttach() {
|
||||
super.onAfterFirstAttach();
|
||||
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
||||
|
||||
public void execute() {
|
||||
loader.load();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
sm.setSelectionMode(SelectionMode.MULTI);
|
||||
grid.setLoader(loader);
|
||||
grid.setSelectionModel(sm);
|
||||
grid.setHeight("384px");
|
||||
grid.getView().setStripeRows(true);
|
||||
grid.getView().setColumnLines(true);
|
||||
grid.getView().setAutoFill(true);
|
||||
grid.setBorders(false);
|
||||
grid.setLoadMask(true);
|
||||
grid.setColumnReordering(true);
|
||||
grid.setColumnResize(true);
|
||||
grid.getView().setAutoExpandColumn(descriptionCol);
|
||||
|
||||
createContextMenu();
|
||||
|
||||
ToolBar toolBar = new ToolBar();
|
||||
toolBar.add(grid);
|
||||
toolBar.addStyleName(ThemeStyles.get().style().borderTop());
|
||||
toolBar.getElement().getStyle().setProperty("borderBottom", "none");
|
||||
|
||||
btnDelete = new TextButton("Delete");
|
||||
btnDelete.setIcon(TabularDataResources.INSTANCE.ruleDelete());
|
||||
btnDelete.setIconAlign(IconAlign.RIGHT);
|
||||
btnDelete.setToolTip("Delete");
|
||||
btnDelete.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
Log.debug("Pressed Delete");
|
||||
delete();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
BoxLayoutData boxLayoutData = new BoxLayoutData(new Margins(2, 4, 2, 4));
|
||||
flowButton.add(btnDelete, boxLayoutData);
|
||||
flowButton.add(btnClose, boxLayoutData);
|
||||
|
||||
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
||||
v.add(toolBarHead, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
v.add(grid, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
v.add(toolBar, new VerticalLayoutData(1, 25, new Margins(0)));
|
||||
v.add(flowButton,
|
||||
new VerticalLayoutData(1, 36, new Margins(5, 2, 5, 2)));
|
||||
add(v);
|
||||
|
||||
}
|
||||
|
||||
protected void loadData(ListLoadConfig loadConfig,
|
||||
final AsyncCallback<ListLoadResult<RuleDescriptionData>> callback) {
|
||||
|
||||
ExpressionServiceAsync.INSTANCE.getRules(RuleScopeType.COLUMN,
|
||||
new AsyncCallback<ArrayList<RuleDescriptionData>>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
if (caught instanceof TDGWTSessionExpiredException) {
|
||||
eventBus.fireEvent(new SessionExpiredEvent(
|
||||
SessionExpiredType.EXPIREDONSERVER));
|
||||
} else {
|
||||
Log.error("Load rules failure:"
|
||||
+ caught.getLocalizedMessage());
|
||||
UtilsGXT3.alert("Error retrieving rules",
|
||||
"Error retrieving 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> getSelectedItem() {
|
||||
ArrayList<RuleDescriptionData> rules = new ArrayList<RuleDescriptionData>();
|
||||
for (RuleDescriptionData rule : grid.getSelectionModel()
|
||||
.getSelectedItems()) {
|
||||
rules.add(rule);
|
||||
}
|
||||
return rules;
|
||||
}
|
||||
|
||||
protected void delete() {
|
||||
ArrayList<RuleDescriptionData> rules = getSelectedItem();
|
||||
if (rules == null || rules.size() == 0) {
|
||||
UtilsGXT3.info("Attention", "Select the rule to be deleted");
|
||||
} else {
|
||||
Log.debug("Rules Delete: " + rules);
|
||||
parent.removeRule(rules);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
parent.close();
|
||||
}
|
||||
|
||||
protected class ExtendedListStore<M> extends ListStore<M> {
|
||||
|
||||
public ExtendedListStore(ModelKeyProvider<? super M> keyProvider) {
|
||||
super(keyProvider);
|
||||
}
|
||||
|
||||
public void applyFilters() {
|
||||
super.applyFilters();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void gridReload() {
|
||||
grid.getLoader().load();
|
||||
}
|
||||
|
||||
protected boolean select(RuleDescriptionData item, String searchTerm) {
|
||||
if (item.getName() != null
|
||||
&& item.getName().toLowerCase()
|
||||
.contains(searchTerm.toLowerCase()))
|
||||
return true;
|
||||
if (item.getDescription() != null
|
||||
&& item.getDescription().toLowerCase()
|
||||
.contains(searchTerm.toLowerCase()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void requestInfo(RuleDescriptionData rule) {
|
||||
|
||||
final RuleInfoDialog infoRuleDialog = new RuleInfoDialog(rule);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
package org.gcube.portlets.user.td.client.rule;
|
||||
|
||||
import org.gcube.portlets.user.td.client.resource.TabularDataResources;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
|
||||
|
||||
import com.sencha.gxt.core.client.util.Margins;
|
||||
import com.sencha.gxt.widget.core.client.Dialog;
|
||||
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutPack;
|
||||
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.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;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo
|
||||
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class RuleInfoDialog extends Dialog {
|
||||
RuleDescriptionData ruleDescriptionData;
|
||||
|
||||
public RuleInfoDialog(RuleDescriptionData ruleDescriptionData){
|
||||
this.ruleDescriptionData=ruleDescriptionData;
|
||||
initWindow();
|
||||
create();
|
||||
}
|
||||
|
||||
protected void initWindow(){
|
||||
setModal(true);
|
||||
setHeadingText("Info Rule");
|
||||
getHeader().setIcon(
|
||||
TabularDataResources.INSTANCE.information());
|
||||
setPredefinedButtons(PredefinedButton.OK);
|
||||
setHideOnButtonClick(true);
|
||||
setButtonAlign(BoxLayoutPack.CENTER);
|
||||
setWidth(500);
|
||||
|
||||
}
|
||||
|
||||
protected void create(){
|
||||
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.setValue(ruleDescriptionData.getName());
|
||||
ruleName.setReadOnly(true);
|
||||
FieldLabel ruleNameLabel = new FieldLabel(ruleName, "Name");
|
||||
configurationFieldSetLayout.add(ruleNameLabel, new VerticalLayoutData(
|
||||
1, -1, new Margins(0)));
|
||||
|
||||
TextField ruleScope = new TextField();
|
||||
ruleScope.setValue(ruleDescriptionData.getScopeLabel());
|
||||
ruleScope.setReadOnly(true);
|
||||
FieldLabel ruleScopeLabel = new FieldLabel(ruleScope, "Scope");
|
||||
configurationFieldSetLayout.add(ruleScopeLabel, new VerticalLayoutData(
|
||||
1, -1, new Margins(0)));
|
||||
|
||||
TextArea ruleDescription = new TextArea();
|
||||
ruleDescription.setValue(ruleDescriptionData.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.setValue(ruleDescriptionData.getOwnerLogin());
|
||||
ruleOwner.setReadOnly(true);
|
||||
FieldLabel ruleOwnerLabel = new FieldLabel(ruleOwner, "Owner");
|
||||
configurationFieldSetLayout.add(ruleOwnerLabel, new VerticalLayoutData(
|
||||
1, -1, new Margins(0)));
|
||||
|
||||
TextArea ruleExpression = new TextArea();
|
||||
ruleExpression.setValue(ruleDescriptionData.getReadableExpression());
|
||||
ruleExpression.setReadOnly(true);
|
||||
ruleExpression.setHeight("82px");
|
||||
FieldLabel ruleExpressionLabel = new FieldLabel(ruleExpression,
|
||||
"Expression");
|
||||
configurationFieldSetLayout.add(ruleExpressionLabel,
|
||||
new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
|
||||
add(configurationFieldSet, new MarginData(0));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
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.RuleEditDialog;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.notification.RuleEditDialogNotification;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.notification.RuleEditDialogNotification.RuleEditDialogNotificationListener;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.sencha.gxt.widget.core.client.Window;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class RuleOpenDialog extends Window implements RuleEditDialogNotificationListener {
|
||||
private static final String WIDTH = "720px";
|
||||
private static final String HEIGHT = "530px";
|
||||
private RuleOpenPanel rulesOpenPanel;
|
||||
private EventBus eventBus;
|
||||
|
||||
public RuleOpenDialog(EventBus eventBus) {
|
||||
this.eventBus=eventBus;
|
||||
initWindow();
|
||||
rulesOpenPanel= new RuleOpenPanel(this,
|
||||
eventBus);
|
||||
add(rulesOpenPanel);
|
||||
}
|
||||
|
||||
protected void initWindow() {
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
setBodyBorder(false);
|
||||
setResizable(false);
|
||||
setHeadingText("Open Rule");
|
||||
setClosable(true);
|
||||
setModal(true);
|
||||
forceLayoutOnResize = true;
|
||||
getHeader().setIcon(TabularDataResources.INSTANCE.ruleOpen());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void initTools() {
|
||||
super.initTools();
|
||||
|
||||
closeBtn.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
hide();
|
||||
}
|
||||
|
||||
public void ruleEdit(RuleDescriptionData ruleDescriptionData) {
|
||||
openRuleDialog(ruleDescriptionData);
|
||||
|
||||
}
|
||||
|
||||
protected void openRuleDialog(RuleDescriptionData ruleDescriptionData) {
|
||||
Log.debug("Request Open New Rule Dialog");
|
||||
RuleEditDialog reDialog = new RuleEditDialog(ruleDescriptionData,eventBus);
|
||||
reDialog.addRuleEditDialogNotificationListener(this);
|
||||
reDialog.show();
|
||||
|
||||
|
||||
/*RuleDialog cfDialog = new RuleDialog(ruleDescriptionData,eventBus);
|
||||
cfDialog.addRuleDialogNotificationListener(this);
|
||||
cfDialog.show();*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotification(RuleEditDialogNotification ruleEditDialogNotification) {
|
||||
rulesOpenPanel.gridReload();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void aborted() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable throwable) {
|
||||
Log.debug("Error in edit rule: "+throwable.getLocalizedMessage());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,436 +0,0 @@
|
|||
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.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.RuleDescriptionData;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType;
|
||||
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 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.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;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
|
||||
import com.sencha.gxt.core.client.IdentityValueProvider;
|
||||
import com.sencha.gxt.core.client.Style.SelectionMode;
|
||||
import com.sencha.gxt.core.client.XTemplates;
|
||||
import com.sencha.gxt.core.client.resources.ThemeStyles;
|
||||
import com.sencha.gxt.core.client.util.Margins;
|
||||
import com.sencha.gxt.data.client.loader.RpcProxy;
|
||||
import com.sencha.gxt.data.shared.ListStore;
|
||||
import com.sencha.gxt.data.shared.ModelKeyProvider;
|
||||
import com.sencha.gxt.data.shared.Store;
|
||||
import com.sencha.gxt.data.shared.Store.StoreFilter;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class RuleOpenPanel extends FramedPanel {
|
||||
private static final String WIDTH = "630px";
|
||||
private static final String HEIGHT = "520px";
|
||||
|
||||
interface RuleOpenTemplates extends XTemplates {
|
||||
@XTemplate("<span title=\"{value}\">{value}</span>")
|
||||
SafeHtml format(String value);
|
||||
}
|
||||
|
||||
private EventBus eventBus;
|
||||
private RuleOpenDialog parent;
|
||||
|
||||
private TextButton btnOpen;
|
||||
private TextButton btnClose;
|
||||
|
||||
private ListLoader<ListLoadConfig, ListLoadResult<RuleDescriptionData>> loader;
|
||||
private Grid<RuleDescriptionData> grid;
|
||||
private ExtendedListStore<RuleDescriptionData> store;
|
||||
|
||||
public RuleOpenPanel(RuleOpenDialog parent, EventBus eventBus) {
|
||||
this.parent = parent;
|
||||
Log.debug("RuleOpenPanel");
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
setHeaderVisible(false);
|
||||
setBodyBorder(false);
|
||||
this.eventBus = eventBus;
|
||||
|
||||
create();
|
||||
|
||||
}
|
||||
|
||||
protected void create() {
|
||||
ToolBar toolBarHead = new ToolBar();
|
||||
toolBarHead.add(new LabelToolItem("Search: "));
|
||||
final TextField searchField = new TextField();
|
||||
toolBarHead.add(searchField);
|
||||
|
||||
TextButton btnReload = new TextButton();
|
||||
// btnReload.setText("Reload");
|
||||
btnReload.setIcon(TabularDataResources.INSTANCE.refresh());
|
||||
btnReload.setToolTip("Reload");
|
||||
toolBarHead.add(btnReload);
|
||||
|
||||
IdentityValueProvider<RuleDescriptionData> identity = new IdentityValueProvider<RuleDescriptionData>();
|
||||
CheckBoxSelectionModel<RuleDescriptionData> sm = new CheckBoxSelectionModel<RuleDescriptionData>(
|
||||
identity);
|
||||
|
||||
RuleDescriptionDataProperties props = GWT
|
||||
.create(RuleDescriptionDataProperties.class);
|
||||
|
||||
ColumnConfig<RuleDescriptionData, String> nameCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.name(), 120, "Name");
|
||||
|
||||
nameCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleOpenTemplates ruleOpenTemplates = GWT
|
||||
.create(RuleOpenTemplates.class);
|
||||
sb.append(ruleOpenTemplates.format(value));
|
||||
}
|
||||
});
|
||||
|
||||
ColumnConfig<RuleDescriptionData, String> scopeCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.scopeLabel(), 40, "Scope");
|
||||
|
||||
nameCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleOpenTemplates ruleOpenTemplates = GWT
|
||||
.create(RuleOpenTemplates.class);
|
||||
sb.append(ruleOpenTemplates.format(value));
|
||||
}
|
||||
});
|
||||
|
||||
ColumnConfig<RuleDescriptionData, String> descriptionCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.description(), 120, "Description");
|
||||
descriptionCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleOpenTemplates ruleOpenTemplates = GWT
|
||||
.create(RuleOpenTemplates.class);
|
||||
sb.append(ruleOpenTemplates.format(value));
|
||||
}
|
||||
});
|
||||
|
||||
ColumnConfig<RuleDescriptionData, String> ownerCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.ownerLogin(), 70, "Owner");
|
||||
ownerCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleOpenTemplates ruleOpenTemplates = GWT
|
||||
.create(RuleOpenTemplates.class);
|
||||
sb.append(ruleOpenTemplates.format(value));
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
ColumnConfig<RuleDescriptionData, String> readableExpressionCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.readableExpression(), 160, "Expression");
|
||||
|
||||
readableExpressionCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleOpenTemplates ruleOpenTemplates = GWT
|
||||
.create(RuleOpenTemplates.class);
|
||||
sb.append(ruleOpenTemplates.format(value));
|
||||
}
|
||||
});*/
|
||||
|
||||
List<ColumnConfig<RuleDescriptionData, ?>> l = new ArrayList<ColumnConfig<RuleDescriptionData, ?>>();
|
||||
l.add(nameCol);
|
||||
l.add(scopeCol);
|
||||
l.add(descriptionCol);
|
||||
l.add(ownerCol);
|
||||
//l.add(readableExpressionCol);
|
||||
|
||||
ColumnModel<RuleDescriptionData> cm = new ColumnModel<RuleDescriptionData>(
|
||||
l);
|
||||
|
||||
store = new ExtendedListStore<RuleDescriptionData>(props.id());
|
||||
|
||||
searchField.addKeyUpHandler(new KeyUpHandler() {
|
||||
|
||||
public void onKeyUp(KeyUpEvent event) {
|
||||
Log.trace("searchTerm: " + searchField.getCurrentValue());
|
||||
store.applyFilters();
|
||||
}
|
||||
});
|
||||
|
||||
store.addFilter(new StoreFilter<RuleDescriptionData>() {
|
||||
|
||||
@Override
|
||||
public boolean select(Store<RuleDescriptionData> store,
|
||||
RuleDescriptionData parent, RuleDescriptionData item) {
|
||||
String searchTerm = searchField.getCurrentValue();
|
||||
if (searchTerm == null)
|
||||
return true;
|
||||
return RuleOpenPanel.this.select(item, searchTerm);
|
||||
}
|
||||
});
|
||||
|
||||
store.setEnableFilters(true);
|
||||
|
||||
RpcProxy<ListLoadConfig, ListLoadResult<RuleDescriptionData>> proxy = new RpcProxy<ListLoadConfig, ListLoadResult<RuleDescriptionData>>() {
|
||||
|
||||
public void load(
|
||||
ListLoadConfig loadConfig,
|
||||
final AsyncCallback<ListLoadResult<RuleDescriptionData>> callback) {
|
||||
loadData(loadConfig, callback);
|
||||
}
|
||||
};
|
||||
loader = new ListLoader<ListLoadConfig, ListLoadResult<RuleDescriptionData>>(
|
||||
proxy);
|
||||
|
||||
loader.setRemoteSort(false);
|
||||
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, RuleDescriptionData, ListLoadResult<RuleDescriptionData>>(
|
||||
store) {
|
||||
});
|
||||
|
||||
SelectHandler sh = new SelectHandler() {
|
||||
public void onSelect(SelectEvent event) {
|
||||
loader.load();
|
||||
}
|
||||
};
|
||||
|
||||
btnReload.addSelectHandler(sh);
|
||||
|
||||
grid = new Grid<RuleDescriptionData>(store, cm) {
|
||||
@Override
|
||||
protected void onAfterFirstAttach() {
|
||||
super.onAfterFirstAttach();
|
||||
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
||||
|
||||
public void execute() {
|
||||
loader.load();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
sm.setSelectionMode(SelectionMode.SINGLE);
|
||||
grid.setLoader(loader);
|
||||
grid.setSelectionModel(sm);
|
||||
grid.setHeight("384px");
|
||||
grid.getView().setStripeRows(true);
|
||||
grid.getView().setColumnLines(true);
|
||||
grid.getView().setAutoFill(true);
|
||||
grid.setBorders(false);
|
||||
grid.setLoadMask(true);
|
||||
grid.setColumnReordering(true);
|
||||
grid.setColumnResize(true);
|
||||
grid.getView().setAutoExpandColumn(descriptionCol);
|
||||
|
||||
createContextMenu();
|
||||
|
||||
ToolBar toolBar = new ToolBar();
|
||||
toolBar.add(grid);
|
||||
toolBar.addStyleName(ThemeStyles.get().style().borderTop());
|
||||
toolBar.getElement().getStyle().setProperty("borderBottom", "none");
|
||||
|
||||
btnOpen = new TextButton("Edit");
|
||||
btnOpen.setIcon(TabularDataResources.INSTANCE.ruleEdit());
|
||||
btnOpen.setIconAlign(IconAlign.RIGHT);
|
||||
btnOpen.setToolTip("Edit Rule");
|
||||
btnOpen.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
Log.debug("Pressed Open");
|
||||
edit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
BoxLayoutData boxLayoutData = new BoxLayoutData(new Margins(2, 4, 2, 4));
|
||||
flowButton.add(btnOpen, boxLayoutData);
|
||||
flowButton.add(btnClose, boxLayoutData);
|
||||
|
||||
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
||||
v.add(toolBarHead, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
v.add(grid, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
v.add(toolBar, new VerticalLayoutData(1, 25, new Margins(0)));
|
||||
v.add(flowButton,
|
||||
new VerticalLayoutData(1, 36, new Margins(5, 2, 5, 2)));
|
||||
add(v);
|
||||
|
||||
}
|
||||
|
||||
protected void loadData(ListLoadConfig loadConfig,
|
||||
final AsyncCallback<ListLoadResult<RuleDescriptionData>> callback) {
|
||||
|
||||
ExpressionServiceAsync.INSTANCE.getRules(RuleScopeType.COLUMN,
|
||||
new AsyncCallback<ArrayList<RuleDescriptionData>>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
if (caught instanceof TDGWTSessionExpiredException) {
|
||||
eventBus.fireEvent(new SessionExpiredEvent(
|
||||
SessionExpiredType.EXPIREDONSERVER));
|
||||
} else {
|
||||
Log.error("Load rules failure:"
|
||||
+ caught.getLocalizedMessage());
|
||||
UtilsGXT3.alert("Error retrieving rules",
|
||||
"Error retrieving rules");
|
||||
}
|
||||
callback.onFailure(caught);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(ArrayList<RuleDescriptionData> result) {
|
||||
if (result != null) {
|
||||
Log.trace("loaded " + result.size() + " Rules");
|
||||
} else {
|
||||
Log.trace("get Rules return: null");
|
||||
}
|
||||
callback.onSuccess(new ListLoadResultBean<RuleDescriptionData>(
|
||||
result));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected RuleDescriptionData getSelectedItem() {
|
||||
RuleDescriptionData template = grid.getSelectionModel()
|
||||
.getSelectedItem();
|
||||
return template;
|
||||
}
|
||||
|
||||
protected void edit() {
|
||||
|
||||
RuleDescriptionData rule = getSelectedItem();
|
||||
if (rule == null) {
|
||||
UtilsGXT3.info("Attention", "Select the rule");
|
||||
} else {
|
||||
parent.ruleEdit(rule);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
parent.close();
|
||||
}
|
||||
|
||||
protected class ExtendedListStore<M> extends ListStore<M> {
|
||||
|
||||
public ExtendedListStore(ModelKeyProvider<? super M> keyProvider) {
|
||||
super(keyProvider);
|
||||
}
|
||||
|
||||
public void applyFilters() {
|
||||
super.applyFilters();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void gridReload() {
|
||||
grid.getLoader().load();
|
||||
}
|
||||
|
||||
protected boolean select(RuleDescriptionData item, String searchTerm) {
|
||||
if (item.getName() != null
|
||||
&& item.getName().toLowerCase()
|
||||
.contains(searchTerm.toLowerCase()))
|
||||
return true;
|
||||
if (item.getDescription() != null
|
||||
&& item.getDescription().toLowerCase()
|
||||
.contains(searchTerm.toLowerCase()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void requestInfo(RuleDescriptionData rule) {
|
||||
final RuleInfoDialog infoRuleDialog = new RuleInfoDialog(rule);
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package org.gcube.portlets.user.td.client.rule;
|
||||
|
||||
import org.gcube.portlets.user.td.client.resource.TabularDataResources;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData;
|
||||
import org.gcube.portlets.user.td.sharewidget.client.RuleShare;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.sencha.gxt.widget.core.client.Window;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class RuleShareDialog extends Window {
|
||||
private static final String WIDTH = "720px";
|
||||
private static final String HEIGHT = "530px";
|
||||
|
||||
private EventBus eventBus;
|
||||
|
||||
public RuleShareDialog(EventBus eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
initWindow();
|
||||
|
||||
RuleSharePanel templateDeletePanel = new RuleSharePanel(this,
|
||||
eventBus);
|
||||
add(templateDeletePanel);
|
||||
}
|
||||
|
||||
protected void initWindow() {
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
setBodyBorder(false);
|
||||
setResizable(false);
|
||||
setHeadingText("Share Rule");
|
||||
setClosable(true);
|
||||
setModal(true);
|
||||
forceLayoutOnResize = true;
|
||||
getHeader().setIcon(TabularDataResources.INSTANCE.ruleShare());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void initTools() {
|
||||
super.initTools();
|
||||
|
||||
closeBtn.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
public void ruleShare(RuleDescriptionData ruleDescriptionData) {
|
||||
Log.debug("Share Window");
|
||||
@SuppressWarnings("unused")
|
||||
RuleShare ruleShare = new RuleShare(ruleDescriptionData, eventBus);
|
||||
close();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,422 +0,0 @@
|
|||
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.client.rule.RuleDeletePanel.RuleDeleteTemplates;
|
||||
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.RuleDescriptionData;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType;
|
||||
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 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.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.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.core.client.IdentityValueProvider;
|
||||
import com.sencha.gxt.core.client.Style.SelectionMode;
|
||||
import com.sencha.gxt.core.client.resources.ThemeStyles;
|
||||
import com.sencha.gxt.core.client.util.Margins;
|
||||
import com.sencha.gxt.data.client.loader.RpcProxy;
|
||||
import com.sencha.gxt.data.shared.ListStore;
|
||||
import com.sencha.gxt.data.shared.ModelKeyProvider;
|
||||
import com.sencha.gxt.data.shared.Store;
|
||||
import com.sencha.gxt.data.shared.Store.StoreFilter;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class RuleSharePanel extends FramedPanel {
|
||||
private static final String WIDTH = "630px";
|
||||
private static final String HEIGHT = "520px";
|
||||
private EventBus eventBus;
|
||||
private RuleShareDialog parent;
|
||||
|
||||
private TextButton btnClose;
|
||||
private TextButton btnShare;
|
||||
|
||||
private ListLoader<ListLoadConfig, ListLoadResult<RuleDescriptionData>> loader;
|
||||
private Grid<RuleDescriptionData> grid;
|
||||
private ExtendedListStore<RuleDescriptionData> store;
|
||||
|
||||
public RuleSharePanel(RuleShareDialog parent, EventBus eventBus) {
|
||||
this.parent = parent;
|
||||
Log.debug("RuleSharePanel");
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
setHeaderVisible(false);
|
||||
setBodyBorder(false);
|
||||
this.eventBus = eventBus;
|
||||
|
||||
create();
|
||||
|
||||
}
|
||||
|
||||
protected void create() {
|
||||
ToolBar toolBarHead = new ToolBar();
|
||||
toolBarHead.add(new LabelToolItem("Search: "));
|
||||
final TextField searchField = new TextField();
|
||||
toolBarHead.add(searchField);
|
||||
|
||||
TextButton btnReload = new TextButton();
|
||||
// btnReload.setText("Reload");
|
||||
btnReload.setIcon(TabularDataResources.INSTANCE.refresh());
|
||||
btnReload.setToolTip("Reload");
|
||||
toolBarHead.add(btnReload);
|
||||
|
||||
IdentityValueProvider<RuleDescriptionData> identity = new IdentityValueProvider<RuleDescriptionData>();
|
||||
CheckBoxSelectionModel<RuleDescriptionData> sm = new CheckBoxSelectionModel<RuleDescriptionData>(
|
||||
identity);
|
||||
|
||||
RuleDescriptionDataProperties props = GWT
|
||||
.create(RuleDescriptionDataProperties.class);
|
||||
|
||||
ColumnConfig<RuleDescriptionData, String> nameCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.name(), 120, "Name");
|
||||
|
||||
nameCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleDeleteTemplates ruleDeleteTemplates = GWT
|
||||
.create(RuleDeleteTemplates.class);
|
||||
sb.append(ruleDeleteTemplates.format(value));
|
||||
}
|
||||
});
|
||||
|
||||
ColumnConfig<RuleDescriptionData, String> scopeCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.scopeLabel(), 40, "Scope");
|
||||
|
||||
nameCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleDeleteTemplates ruleDeleteTemplates = GWT
|
||||
.create(RuleDeleteTemplates.class);
|
||||
sb.append(ruleDeleteTemplates.format(value));
|
||||
}
|
||||
});
|
||||
|
||||
ColumnConfig<RuleDescriptionData, String> descriptionCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.description(), 120, "Description");
|
||||
descriptionCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleDeleteTemplates ruleDeleteTemplates = GWT
|
||||
.create(RuleDeleteTemplates.class);
|
||||
sb.append(ruleDeleteTemplates.format(value));
|
||||
}
|
||||
});
|
||||
|
||||
ColumnConfig<RuleDescriptionData, String> ownerCol = new ColumnConfig<RuleDescriptionData, String>(
|
||||
props.ownerLogin(), 70, "Owner");
|
||||
ownerCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@Override
|
||||
public void render(Context context, String value, SafeHtmlBuilder sb) {
|
||||
RuleDeleteTemplates ruleDeleteTemplates = GWT
|
||||
.create(RuleDeleteTemplates.class);
|
||||
sb.append(ruleDeleteTemplates.format(value));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
List<ColumnConfig<RuleDescriptionData, ?>> l = new ArrayList<ColumnConfig<RuleDescriptionData, ?>>();
|
||||
l.add(nameCol);
|
||||
l.add(scopeCol);
|
||||
l.add(descriptionCol);
|
||||
l.add(ownerCol);
|
||||
|
||||
|
||||
ColumnModel<RuleDescriptionData> cm = new ColumnModel<RuleDescriptionData>(l);
|
||||
|
||||
store = new ExtendedListStore<RuleDescriptionData>(props.id());
|
||||
|
||||
searchField.addKeyUpHandler(new KeyUpHandler() {
|
||||
|
||||
public void onKeyUp(KeyUpEvent event) {
|
||||
Log.trace("searchTerm: " + searchField.getCurrentValue());
|
||||
store.applyFilters();
|
||||
}
|
||||
});
|
||||
|
||||
store.addFilter(new StoreFilter<RuleDescriptionData>() {
|
||||
|
||||
@Override
|
||||
public boolean select(Store<RuleDescriptionData> store,
|
||||
RuleDescriptionData parent, RuleDescriptionData item) {
|
||||
String searchTerm = searchField.getCurrentValue();
|
||||
if (searchTerm == null)
|
||||
return true;
|
||||
return RuleSharePanel.this.select(item, searchTerm);
|
||||
}
|
||||
});
|
||||
|
||||
store.setEnableFilters(true);
|
||||
|
||||
RpcProxy<ListLoadConfig, ListLoadResult<RuleDescriptionData>> proxy = new RpcProxy<ListLoadConfig, ListLoadResult<RuleDescriptionData>>() {
|
||||
|
||||
public void load(ListLoadConfig loadConfig,
|
||||
final AsyncCallback<ListLoadResult<RuleDescriptionData>> callback) {
|
||||
loadData(loadConfig, callback);
|
||||
}
|
||||
};
|
||||
loader = new ListLoader<ListLoadConfig, ListLoadResult<RuleDescriptionData>>(
|
||||
proxy);
|
||||
|
||||
loader.setRemoteSort(false);
|
||||
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, RuleDescriptionData, ListLoadResult<RuleDescriptionData>>(
|
||||
store) {
|
||||
});
|
||||
|
||||
SelectHandler sh = new SelectHandler() {
|
||||
public void onSelect(SelectEvent event) {
|
||||
loader.load();
|
||||
}
|
||||
};
|
||||
|
||||
btnReload.addSelectHandler(sh);
|
||||
|
||||
grid = new Grid<RuleDescriptionData>(store, cm) {
|
||||
@Override
|
||||
protected void onAfterFirstAttach() {
|
||||
super.onAfterFirstAttach();
|
||||
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
||||
|
||||
public void execute() {
|
||||
loader.load();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
sm.setSelectionMode(SelectionMode.SINGLE);
|
||||
grid.setLoader(loader);
|
||||
grid.setSelectionModel(sm);
|
||||
grid.setHeight("384px");
|
||||
grid.getView().setStripeRows(true);
|
||||
grid.getView().setColumnLines(true);
|
||||
grid.getView().setAutoFill(true);
|
||||
grid.setBorders(false);
|
||||
grid.setLoadMask(true);
|
||||
grid.setColumnReordering(true);
|
||||
grid.setColumnResize(true);
|
||||
grid.getView().setAutoExpandColumn(descriptionCol);
|
||||
|
||||
createContextMenu();
|
||||
|
||||
|
||||
ToolBar toolBar = new ToolBar();
|
||||
toolBar.add(grid);
|
||||
toolBar.addStyleName(ThemeStyles.get().style().borderTop());
|
||||
toolBar.getElement().getStyle().setProperty("borderBottom", "none");
|
||||
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
btnShare = new TextButton("Share");
|
||||
btnShare.setIcon(TabularDataResources.INSTANCE.ruleShare());
|
||||
btnShare.setIconAlign(IconAlign.RIGHT);
|
||||
btnShare.setToolTip("Share");
|
||||
btnShare.addSelectHandler(new SelectHandler() {
|
||||
|
||||
public void onSelect(SelectEvent event) {
|
||||
Log.debug("Pressed Share");
|
||||
share();
|
||||
}
|
||||
});
|
||||
|
||||
HBoxLayoutContainer flowButton = new HBoxLayoutContainer();
|
||||
flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE);
|
||||
flowButton.setPack(BoxLayoutPack.CENTER);
|
||||
|
||||
BoxLayoutData boxLayoutData = new BoxLayoutData(new Margins(2, 4, 2, 4));
|
||||
flowButton.add(btnShare, boxLayoutData);
|
||||
flowButton.add(btnClose, boxLayoutData);
|
||||
|
||||
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
||||
v.add(toolBarHead, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
v.add(grid, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
v.add(toolBar, new VerticalLayoutData(1, 25, new Margins(0)));
|
||||
v.add(flowButton,
|
||||
new VerticalLayoutData(1, 36, new Margins(5, 2, 5, 2)));
|
||||
add(v);
|
||||
|
||||
}
|
||||
|
||||
protected void loadData(ListLoadConfig loadConfig,
|
||||
final AsyncCallback<ListLoadResult<RuleDescriptionData>> callback) {
|
||||
|
||||
ExpressionServiceAsync.INSTANCE.getRules(RuleScopeType.COLUMN,
|
||||
new AsyncCallback<ArrayList<RuleDescriptionData>>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
if (caught instanceof TDGWTSessionExpiredException) {
|
||||
eventBus.fireEvent(new SessionExpiredEvent(
|
||||
SessionExpiredType.EXPIREDONSERVER));
|
||||
} else {
|
||||
Log.error("Load rules failure:"
|
||||
+ caught.getLocalizedMessage());
|
||||
UtilsGXT3.alert("Error retrieving rules",
|
||||
"Error retrieving 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> getSelectedItem() {
|
||||
ArrayList<RuleDescriptionData> rules = new ArrayList<RuleDescriptionData>();
|
||||
for (RuleDescriptionData rule : grid.getSelectionModel()
|
||||
.getSelectedItems()) {
|
||||
rules.add(rule);
|
||||
}
|
||||
return rules;
|
||||
}
|
||||
|
||||
|
||||
protected void share() {
|
||||
|
||||
ArrayList<RuleDescriptionData> rules = getSelectedItem();
|
||||
if (rules == null || rules.size() == 0) {
|
||||
UtilsGXT3.info("Attention", "Select the rule");
|
||||
} else {
|
||||
RuleDescriptionData rule = rules.get(0);
|
||||
Log.debug("templateShare: " + rule);
|
||||
parent.ruleShare(rule);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
parent.close();
|
||||
}
|
||||
|
||||
protected class ExtendedListStore<M> extends ListStore<M> {
|
||||
|
||||
public ExtendedListStore(ModelKeyProvider<? super M> keyProvider) {
|
||||
super(keyProvider);
|
||||
}
|
||||
|
||||
public void applyFilters() {
|
||||
super.applyFilters();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void gridReload() {
|
||||
grid.getLoader().load();
|
||||
}
|
||||
|
||||
protected boolean select(RuleDescriptionData item, String searchTerm) {
|
||||
if (item.getName() != null
|
||||
&& item.getName().toLowerCase()
|
||||
.contains(searchTerm.toLowerCase()))
|
||||
return true;
|
||||
if (item.getDescription() != null
|
||||
&& item.getDescription().toLowerCase()
|
||||
.contains(searchTerm.toLowerCase()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void requestInfo(RuleDescriptionData rule) {
|
||||
final RuleInfoDialog infoRuleDialog = new RuleInfoDialog(rule);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -33,6 +33,7 @@
|
|||
<inherits name='org.gcube.portlets.user.td.informationwidget.Information' />
|
||||
<inherits name='org.gcube.portlets.user.td.columnwidget.ColumnWidget' />
|
||||
<inherits name='org.gcube.portlets.user.td.resourceswidget.ResourcesWidget' />
|
||||
<inherits name='org.gcube.portlets.user.td.rulewidget.RuleWidget' />
|
||||
|
||||
<inherits name='org.gcube.portlets.user.td.toolboxwidget.ToolBox' />
|
||||
<inherits name='org.gcube.portlets.user.td.openwidget.TDOpen' />
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module rename-to='tabulardataportlet'>
|
||||
|
||||
<inherits name='com.google.gwt.user.User' />
|
||||
<inherits name="com.google.gwt.http.HTTP" />
|
||||
<!-- <inherits name="com.google.gwt.i18n.I18N" /> -->
|
||||
|
@ -38,7 +37,8 @@
|
|||
<inherits name='org.gcube.portlets.user.td.informationwidget.Information' />
|
||||
<inherits name='org.gcube.portlets.user.td.columnwidget.ColumnWidget' />
|
||||
<inherits name='org.gcube.portlets.user.td.resourceswidget.ResourcesWidget' />
|
||||
|
||||
<inherits name='org.gcube.portlets.user.td.rulewidget.RuleWidget' />
|
||||
|
||||
<inherits name='org.gcube.portlets.user.td.toolboxwidget.ToolBox' />
|
||||
<inherits name='org.gcube.portlets.user.td.openwidget.TDOpen' />
|
||||
<inherits
|
||||
|
@ -95,11 +95,11 @@
|
|||
name="locale" values="es" /> <set-property name="locale" value="en, it, es"
|
||||
/> <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"
|
||||
/> -->
|
||||
|
||||
|
|
Loading…
Reference in New Issue