Updated Mapping
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-codelistmapping-import-widget@98236 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c934924fde
commit
9ab262c4c3
|
@ -0,0 +1,156 @@
|
|||
package org.gcube.portlets.user.td.codelistmappingimportwidget.client.grid;
|
||||
|
||||
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.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.event.logical.shared.HasSelectionHandlers;
|
||||
import com.google.gwt.event.logical.shared.SelectionHandler;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.sencha.gxt.core.client.IdentityValueProvider;
|
||||
import com.sencha.gxt.core.client.Style.SelectionMode;
|
||||
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
|
||||
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.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.ContentPanel;
|
||||
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.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;
|
||||
|
||||
public class ColumnDataGridPanel extends ContentPanel implements
|
||||
HasSelectionHandlers<ColumnData> {
|
||||
protected static final int GRIDHEIGHT = 360;
|
||||
|
||||
protected static final ColumnDataProperties props = GWT
|
||||
.create(ColumnDataProperties.class);
|
||||
|
||||
protected final CheckBoxSelectionModel<ColumnData> sm;
|
||||
|
||||
protected final Grid<ColumnData> grid;
|
||||
protected TRId trId;
|
||||
|
||||
public ColumnDataGridPanel(TRId trId) {
|
||||
Log.debug("ColumnDataGridPanel");
|
||||
if(trId==null){
|
||||
Log.error("ColumnDataGridPanel: TRId is null");
|
||||
}
|
||||
Log.debug("ColumnDataGridPanel: "+trId.toString());
|
||||
this.trId=trId;
|
||||
setHeaderVisible(false);
|
||||
//setHeadingText("Columns");
|
||||
|
||||
ColumnConfig<ColumnData, String> labelCol = new ColumnConfig<ColumnData, String>(
|
||||
props.label(), 120,"Column");
|
||||
|
||||
IdentityValueProvider<ColumnData> identity = new IdentityValueProvider<ColumnData>();
|
||||
|
||||
sm = new CheckBoxSelectionModel<ColumnData>(identity);
|
||||
|
||||
List<ColumnConfig<ColumnData, ?>> l = new ArrayList<ColumnConfig<ColumnData, ?>>();
|
||||
|
||||
l.add(labelCol);
|
||||
ColumnModel<ColumnData> cm = new ColumnModel<ColumnData>(l);
|
||||
|
||||
ListStore<ColumnData> store = new ListStore<ColumnData>(props.id());
|
||||
|
||||
RpcProxy<ListLoadConfig, ListLoadResult<ColumnData>> proxy = new RpcProxy<ListLoadConfig, ListLoadResult<ColumnData>>() {
|
||||
|
||||
public void load(ListLoadConfig loadConfig,
|
||||
final AsyncCallback<ListLoadResult<ColumnData>> callback) {
|
||||
loadData(loadConfig, callback);
|
||||
}
|
||||
};
|
||||
final ListLoader<ListLoadConfig, ListLoadResult<ColumnData>> loader = new ListLoader<ListLoadConfig, ListLoadResult<ColumnData>>(
|
||||
proxy);
|
||||
|
||||
loader.setRemoteSort(false);
|
||||
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, ColumnData, ListLoadResult<ColumnData>>(
|
||||
store) {
|
||||
});
|
||||
|
||||
grid = new Grid<ColumnData>(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(GRIDHEIGHT);
|
||||
grid.getView().setStripeRows(true);
|
||||
grid.getView().setColumnLines(true);
|
||||
grid.getView().setAutoFill(true);
|
||||
grid.setBorders(false);
|
||||
grid.setLoadMask(true);
|
||||
grid.setColumnReordering(true);
|
||||
|
||||
VerticalLayoutContainer con = new VerticalLayoutContainer();
|
||||
con.setScrollMode(ScrollMode.AUTO);
|
||||
con.add(grid, new VerticalLayoutData(-1, -1, new Margins(0)));
|
||||
setWidget(con);
|
||||
|
||||
}
|
||||
|
||||
public Grid<ColumnData> getGrid() {
|
||||
return grid;
|
||||
}
|
||||
|
||||
protected void loadData(ListLoadConfig loadConfig,
|
||||
final AsyncCallback<ListLoadResult<ColumnData>> callback) {
|
||||
TDGWTServiceAsync.INSTANCE
|
||||
.getColumns(trId, new AsyncCallback<ArrayList<ColumnData>>() {
|
||||
|
||||
public void onFailure(Throwable caught) {
|
||||
Log.error("No load columns: "
|
||||
+ caught.getLocalizedMessage());
|
||||
callback.onFailure(caught);
|
||||
}
|
||||
|
||||
public void onSuccess(ArrayList<ColumnData> result) {
|
||||
Log.trace("loaded " + result.size() + " columns");
|
||||
callback.onSuccess(new ListLoadResultBean<ColumnData>(
|
||||
result));
|
||||
sm.selectAll();
|
||||
forceLayout();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ColumnData getSelectedItem() {
|
||||
return grid.getSelectionModel().getSelectedItem();
|
||||
|
||||
}
|
||||
|
||||
public HandlerRegistration addSelectionHandler(
|
||||
SelectionHandler<ColumnData> handler) {
|
||||
return grid.getSelectionModel().addSelectionHandler(handler);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package org.gcube.portlets.user.td.codelistmappingimportwidget.client.grid;
|
||||
|
||||
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;
|
||||
|
||||
public interface ColumnDataProperties extends PropertyAccess<ColumnData> {
|
||||
|
||||
@Path("id")
|
||||
ModelKeyProvider<ColumnData> id();
|
||||
|
||||
ValueProvider<ColumnData, String> label();
|
||||
|
||||
// ValueProvider<ColumnData, String> typeName();
|
||||
|
||||
// ValueProvider<ColumnData, String> typeCode();
|
||||
|
||||
}
|
Loading…
Reference in New Issue