2015-05-18 17:10:35 +02:00
|
|
|
package org.gcube.portlets.user.td.rulewidget.client;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionServiceAsync;
|
|
|
|
import org.gcube.portlets.user.td.expressionwidget.shared.rule.RuleDescriptionDataProperties;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleScopeType;
|
2015-05-19 18:54:51 +02:00
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData;
|
2015-05-18 17:10:35 +02:00
|
|
|
import org.gcube.portlets.user.td.rulewidget.client.resources.ResourceBundle;
|
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
|
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
|
|
|
|
import org.gcube.portlets.user.td.wizardwidget.client.util.UtilsGXT3;
|
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
import com.google.gwt.cell.client.AbstractCell;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
import com.google.gwt.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(ResourceBundle.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(ResourceBundle.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(ResourceBundle.INSTANCE.close());
|
|
|
|
btnClose.setIconAlign(IconAlign.RIGHT);
|
|
|
|
btnClose.setToolTip("Close");
|
|
|
|
btnClose.addSelectHandler(new SelectHandler() {
|
|
|
|
|
|
|
|
public void onSelect(SelectEvent event) {
|
|
|
|
Log.debug("Pressed Close");
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
HBoxLayoutContainer flowButton = new HBoxLayoutContainer();
|
|
|
|
flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE);
|
|
|
|
flowButton.setPack(BoxLayoutPack.CENTER);
|
|
|
|
|
|
|
|
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(ResourceBundle.INSTANCE.information());
|
|
|
|
infoItem.addSelectionHandler(new SelectionHandler<Item>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSelection(SelectionEvent<Item> event) {
|
|
|
|
RuleDescriptionData selected = grid.getSelectionModel()
|
|
|
|
.getSelectedItem();
|
|
|
|
Log.debug(selected.toString());
|
|
|
|
requestInfo(selected);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
contextMenu.add(infoItem);
|
|
|
|
|
|
|
|
grid.setContextMenu(contextMenu);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|