2014-03-17 18:59:08 +01:00
|
|
|
package org.gcube.portlets.user.td.columnwidget.client.batch;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.td.columnwidget.client.ChangeColumnTypeDialog;
|
|
|
|
import org.gcube.portlets.user.td.columnwidget.client.dimension.CodelistSelectionListener;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.Occurences;
|
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
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.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.web.bindery.event.shared.EventBus;
|
|
|
|
import com.sencha.gxt.core.client.IdentityValueProvider;
|
|
|
|
import com.sencha.gxt.core.client.Style.SelectionMode;
|
|
|
|
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.ListLoadResult;
|
|
|
|
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.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.grid.RowNumberer;
|
|
|
|
|
2014-03-17 19:03:29 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author "Giancarlo Panichi"
|
|
|
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
|
|
*
|
|
|
|
*/
|
2014-03-17 18:59:08 +01:00
|
|
|
public class BatchReplacePanel extends FramedPanel implements
|
|
|
|
CodelistSelectionListener {
|
|
|
|
protected String WIDTH = "640px";
|
|
|
|
protected String HEIGHT = "520px";
|
|
|
|
protected EventBus eventBus;
|
|
|
|
protected ChangeColumnTypeDialog parent;
|
|
|
|
protected TextField label = null;
|
|
|
|
protected TRId trId;
|
|
|
|
protected String columnName;
|
|
|
|
|
|
|
|
protected ListLoader<ListLoadConfig, ListLoadResult<Occurences>> loader;
|
|
|
|
protected Grid<Occurences> grid;
|
|
|
|
|
|
|
|
public BatchReplacePanel(TRId trId, String columnName, EventBus eventBus) {
|
|
|
|
setWidth(WIDTH);
|
|
|
|
setHeight(HEIGHT);
|
|
|
|
setHeaderVisible(false);
|
|
|
|
setBodyBorder(false);
|
|
|
|
this.trId = trId;
|
|
|
|
this.columnName = columnName;
|
|
|
|
this.eventBus = eventBus;
|
|
|
|
Log.debug("Create BatchReplacePanel(): [" + trId.toString()+" , columnName:"+columnName + "]");
|
|
|
|
create();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void create(){
|
|
|
|
|
|
|
|
IdentityValueProvider<Occurences> identity=new IdentityValueProvider<Occurences>();
|
|
|
|
CheckBoxSelectionModel<Occurences> sm = new CheckBoxSelectionModel<Occurences>(
|
|
|
|
identity);
|
|
|
|
|
|
|
|
RowNumberer<Occurences> number = new RowNumberer<Occurences>(identity);
|
|
|
|
|
|
|
|
OccurencesProperties props = GWT.create(OccurencesProperties.class);
|
|
|
|
|
|
|
|
|
|
|
|
ColumnConfig<Occurences, String> valueCol = new ColumnConfig<Occurences, String>(
|
|
|
|
props.value());
|
|
|
|
ColumnConfig<Occurences, Integer> numberCol = new ColumnConfig<Occurences, Integer>(
|
|
|
|
props.number());
|
|
|
|
|
|
|
|
|
|
|
|
List<ColumnConfig<Occurences, ?>> l = new ArrayList<ColumnConfig<Occurences, ?>>();
|
|
|
|
l.add(number);
|
|
|
|
l.add(valueCol);
|
|
|
|
l.add(numberCol);
|
|
|
|
ColumnModel<Occurences> cm = new ColumnModel<Occurences>(l);
|
|
|
|
|
|
|
|
ListStore<Occurences> store = new ListStore<Occurences>(props.id());
|
|
|
|
|
|
|
|
RpcProxy<ListLoadConfig, ListLoadResult<Occurences>> proxy = new RpcProxy<ListLoadConfig, ListLoadResult<Occurences>>() {
|
|
|
|
|
|
|
|
public void load(ListLoadConfig loadConfig,
|
|
|
|
final AsyncCallback<ListLoadResult<Occurences>> callback) {
|
|
|
|
loadData(loadConfig, callback);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
loader = new ListLoader<ListLoadConfig, ListLoadResult<Occurences>>(
|
|
|
|
proxy);
|
|
|
|
|
|
|
|
loader.setRemoteSort(false);
|
|
|
|
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, Occurences, ListLoadResult<Occurences>>(
|
|
|
|
store) {
|
|
|
|
});
|
|
|
|
|
|
|
|
grid = new Grid<Occurences>(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.getView().setAutoExpandColumn(labelCol);
|
|
|
|
//grid.setHeight(360);
|
|
|
|
grid.getView().setStripeRows(true);
|
|
|
|
grid.getView().setColumnLines(true);
|
|
|
|
grid.getView().setAutoFill(true);
|
|
|
|
grid.setBorders(false);
|
|
|
|
grid.setLoadMask(true);
|
|
|
|
grid.setColumnReordering(true);
|
|
|
|
grid.setColumnResize(false);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void loadData(ListLoadConfig loadConfig,
|
|
|
|
final AsyncCallback<ListLoadResult<Occurences>> callback) {
|
|
|
|
/*TDGWTServiceAsync.INSTANCE.getColumns(trId,
|
|
|
|
new AsyncCallback<ArrayList<Occurences>>() {
|
|
|
|
|
|
|
|
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<ColumnData> result) {
|
|
|
|
Log.trace("loaded " + result.size() + " ColumnData");
|
|
|
|
callback.onSuccess(new ListLoadResultBean<ColumnData>(
|
|
|
|
result));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void selected(TabResource tabResource) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void aborted() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void failed(String reason, String detail) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|