diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/properties/ColumnDataProperties.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/properties/ColumnDataProperties.java new file mode 100644 index 0000000..1bda48a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/properties/ColumnDataProperties.java @@ -0,0 +1,25 @@ +package org.gcube.portlets.user.td.tablewidget.client.properties; + +import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; + +import com.google.gwt.editor.client.Editor.Path; +import com.sencha.gxt.core.client.ValueProvider; +import com.sencha.gxt.data.shared.ModelKeyProvider; +import com.sencha.gxt.data.shared.PropertyAccess; + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public interface ColumnDataProperties extends + PropertyAccess { + + @Path("id") + ModelKeyProvider id(); + + ValueProvider label(); + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/rows/DeleteDuplicateRowsPanel.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/rows/DeleteDuplicateRowsPanel.java new file mode 100644 index 0000000..921e703 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/rows/DeleteDuplicateRowsPanel.java @@ -0,0 +1,177 @@ +package org.gcube.portlets.user.td.tablewidget.client.rows; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; +import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsSession; +import org.gcube.portlets.user.td.tablewidget.client.progress.DeleteRowsProgressDialog; +import org.gcube.portlets.user.td.tablewidget.client.properties.ColumnDataProperties; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.cell.client.TextCell; +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.web.bindery.event.shared.EventBus; +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.loader.ListLoadConfig; +import com.sencha.gxt.data.shared.loader.ListLoadConfigBean; +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.box.AlertMessageBox; +import com.sencha.gxt.widget.core.client.button.TextButton; +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.HideEvent; +import com.sencha.gxt.widget.core.client.event.SelectEvent; +import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler; +import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; +import com.sencha.gxt.widget.core.client.form.DualListField; +import com.sencha.gxt.widget.core.client.form.DualListField.Mode; +import com.sencha.gxt.widget.core.client.form.FieldLabel; +import com.sencha.gxt.widget.core.client.form.validator.EmptyValidator; + +public class DeleteDuplicateRowsPanel extends FramedPanel { + protected String WIDTH = "640px"; + protected String HEIGHT = "520px"; + + protected TRId trId; + protected EventBus eventBus; + protected ArrayList rows; + protected DeleteRowsSession deleteRowsSession; + protected DeleteRowsProgressDialog deleteRowsProgressDialog; + + protected ListLoader> loader; + protected FieldLabel columnsSelectLabel; + protected TextButton deleteButton; + + public DeleteDuplicateRowsPanel(TRId trId, EventBus eventBus) { + setWidth(WIDTH); + setHeight(HEIGHT); + setHeaderVisible(false); + setBodyBorder(false); + this.trId = trId; + this.eventBus = eventBus; + Log.debug("Create DeleteDuplicatePanel(): [" + trId.toString() + "]"); + + ColumnDataProperties props = GWT.create(ColumnDataProperties.class); + ListStore store = new ListStore(props.id()); + + RpcProxy> proxy = new RpcProxy>() { + + public void load(ListLoadConfig loadConfig, + final AsyncCallback> callback) { + loadData(loadConfig, callback); + } + }; + + loader = new ListLoader>( + proxy) { + @Override + protected ListLoadConfig newLoadConfig() { + return (ListLoadConfig) new ListLoadConfigBean(); + } + + }; + + loader.addLoadHandler(new LoadResultListStoreBinding>( + store)); + + ListStore toStore = new ListStore(props.id()); + + final DualListField columnsField = new DualListField( + store, toStore, props.label(), new TextCell()); + columnsField.addValidator(new EmptyValidator>()); + columnsField.setEnableDnd(true); + columnsField.setMode(Mode.INSERT); + + // Delete Button + deleteButton = new TextButton("Delete"); + SelectHandler changeHandler = new SelectHandler() { + + public void onSelect(SelectEvent event) { + onDeleteDuplicate(); + + } + }; + deleteButton.addSelectHandler(changeHandler); + FieldLabel columnsLabel = new FieldLabel(null,"Columns"); + columnsSelectLabel = new FieldLabel(columnsField); + + VerticalLayoutContainer v = new VerticalLayoutContainer(); + v.add(columnsLabel, new VerticalLayoutData(1, -1, new Margins(1))); + v.add(columnsSelectLabel, new VerticalLayoutData(1, -1, new Margins(1))); + v.add(deleteButton, new VerticalLayoutData(-1, -1, new Margins(10, 0, + 10, 0))); + + add(v, new VerticalLayoutData(-1, -1, new Margins(0))); + + } + + protected void loadData(ListLoadConfig loadConfig, + final AsyncCallback> callback) { + TDGWTServiceAsync.INSTANCE.getColumns(trId, + new AsyncCallback>() { + + public void onFailure(Throwable caught) { + Log.error("load columns failure:" + + caught.getLocalizedMessage()); + alert("Error retrieving columns", + "Error retrieving columns"); + callback.onFailure(caught); + } + + public void onSuccess(ArrayList result) { + Log.trace("loaded " + result.size() + " ColumnData"); + callback.onSuccess(new ListLoadResultBean( + result)); + + } + + }); + + } + + + + protected void onDeleteDuplicate() { + /*TDGWTServiceAsync.INSTANCE.startDeleteRows(deleteRowsSession, + new AsyncCallback() { + + public void onFailure(Throwable caught) { + Log.debug("Delete Rows Error: " + + caught.getLocalizedMessage()); + alert("Error Deleting Rows", + "Error in invocation Delete Rows operation!"); + + } + + public void onSuccess(Void result) { + deleteRowsProgressDialog = new DeleteRowsProgressDialog( + deleteRowsSession, eventBus); + } + + }); + */ + } + + private void alert(String title, String message) { + final AlertMessageBox d = new AlertMessageBox(title, message); + d.addHideHandler(new HideHandler() { + + public void onHide(HideEvent event) { + + } + }); + d.show(); + + } + +}