Added Position Column
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-column-widget@112335 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
25e2ceab1b
commit
a78e6d2754
|
@ -0,0 +1,60 @@
|
||||||
|
package org.gcube.portlets.user.td.columnwidget.client;
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PositionColumnDialog extends Window {
|
||||||
|
private static final int WIDTH=400;
|
||||||
|
private static final int HEIGHT=120;
|
||||||
|
|
||||||
|
public PositionColumnDialog(TRId trId, EventBus eventBus) {
|
||||||
|
initWindow();
|
||||||
|
|
||||||
|
PositionColumnPanel changeColumnsPositionPanel= new PositionColumnPanel(trId, eventBus);
|
||||||
|
add(changeColumnsPositionPanel);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void initWindow() {
|
||||||
|
setWidth(WIDTH);
|
||||||
|
setHeight(HEIGHT);
|
||||||
|
setBodyBorder(false);
|
||||||
|
setResizable(false);
|
||||||
|
setHeadingText("Change Columns Position");
|
||||||
|
//getHeader().setIcon(Resources.IMAGES.side_list());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void initTools() {
|
||||||
|
super.initTools();
|
||||||
|
|
||||||
|
closeBtn.addSelectHandler(new SelectHandler() {
|
||||||
|
|
||||||
|
public void onSelect(SelectEvent event) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
hide();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,342 @@
|
||||||
|
package org.gcube.portlets.user.td.columnwidget.client;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.td.columnwidget.client.properties.ColumnDataProperties;
|
||||||
|
import org.gcube.portlets.user.td.columnwidget.client.resources.ResourceBundle;
|
||||||
|
import org.gcube.portlets.user.td.columnwidget.client.utils.UtilsGXT3;
|
||||||
|
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.tr.ColumnData;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ChangeColumnsPositionSession;
|
||||||
|
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 com.sencha.gxt.dnd.core.client.DndDragStartEvent.DndDragStartHandler;
|
||||||
|
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.shared.UmbrellaException;
|
||||||
|
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.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.event.StoreDataChangeEvent;
|
||||||
|
import com.sencha.gxt.data.shared.event.StoreDataChangeEvent.StoreDataChangeHandler;
|
||||||
|
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.dnd.core.client.DND.Feedback;
|
||||||
|
import com.sencha.gxt.dnd.core.client.DndDragStartEvent;
|
||||||
|
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.HBoxLayoutContainer;
|
||||||
|
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.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.GridSelectionModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change columns position
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author giancarlo
|
||||||
|
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PositionColumnPanel extends FramedPanel {
|
||||||
|
private static final String WIDTH = "640px";
|
||||||
|
private static final String HEIGHT = "520px";
|
||||||
|
private EventBus eventBus;
|
||||||
|
private PositionColumnDialog parent;
|
||||||
|
private TRId trId;
|
||||||
|
|
||||||
|
private TextButton reorder;
|
||||||
|
|
||||||
|
private ListLoader<ListLoadConfig, ListLoadResult<ColumnData>> loader;
|
||||||
|
private Grid<ColumnData> grid;
|
||||||
|
private GridSelectionModel<ColumnData> sm;
|
||||||
|
|
||||||
|
private ChangeColumnsPositionSession changeColumnsPositionSession;
|
||||||
|
|
||||||
|
private ListStore<ColumnData> store;
|
||||||
|
|
||||||
|
public PositionColumnPanel(TRId trId, EventBus eventBus) {
|
||||||
|
this.trId = trId;
|
||||||
|
this.eventBus = eventBus;
|
||||||
|
Log.debug("ReorderColumnsPanel(): [" + trId.toString() + "]");
|
||||||
|
init();
|
||||||
|
build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
setWidth(WIDTH);
|
||||||
|
setHeight(HEIGHT);
|
||||||
|
setHeaderVisible(false);
|
||||||
|
setBodyBorder(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void build() {
|
||||||
|
ColumnDataProperties props = GWT.create(ColumnDataProperties.class);
|
||||||
|
|
||||||
|
ColumnConfig<ColumnData, String> labelCol = new ColumnConfig<ColumnData, String>(
|
||||||
|
props.label());
|
||||||
|
labelCol.setHeader("Columns");
|
||||||
|
|
||||||
|
//IdentityValueProvider<ColumnData> identity = new IdentityValueProvider<ColumnData>();
|
||||||
|
sm = new GridSelectionModel<ColumnData>();
|
||||||
|
|
||||||
|
List<ColumnConfig<ColumnData, ?>> l = new ArrayList<ColumnConfig<ColumnData, ?>>();
|
||||||
|
l.add(labelCol);
|
||||||
|
ColumnModel<ColumnData> cm = new ColumnModel<ColumnData>(l);
|
||||||
|
|
||||||
|
store = new ListStore<ColumnData>(props.id());
|
||||||
|
|
||||||
|
store.addStoreDataChangeHandler(new StoreDataChangeHandler<ColumnData>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDataChange(StoreDataChangeEvent<ColumnData> event) {
|
||||||
|
/*List<ColumnData> cols = event.getSource().getAll();
|
||||||
|
Log.debug("Columns:" + cols.size());
|
||||||
|
for (ColumnData c : cols) {
|
||||||
|
if (c.getName().compareTo(columnName) == 0) {
|
||||||
|
sm.select(c, false);
|
||||||
|
sm.refresh();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
RpcProxy<ListLoadConfig, ListLoadResult<ColumnData>> proxy = new RpcProxy<ListLoadConfig, ListLoadResult<ColumnData>>() {
|
||||||
|
|
||||||
|
public void load(ListLoadConfig loadConfig,
|
||||||
|
final AsyncCallback<ListLoadResult<ColumnData>> callback) {
|
||||||
|
loadData(loadConfig, callback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
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.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);
|
||||||
|
|
||||||
|
GridDragSource<ColumnData> ds=new GridDragSource<ColumnData>(grid);
|
||||||
|
ds.addDragStartHandler(new DndDragStartHandler() {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDragStart(DndDragStartEvent event) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
ArrayList<ColumnData> draggingSelection = (ArrayList<ColumnData>) event.getData();
|
||||||
|
Log.debug("Start Drag: "+draggingSelection);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
GridDropTarget<ColumnData> dt = new GridDropTarget<ColumnData>(grid);
|
||||||
|
dt.setFeedback(Feedback.BOTH);
|
||||||
|
dt.setAllowSelfAsSource(true);
|
||||||
|
|
||||||
|
|
||||||
|
// Delete Button
|
||||||
|
reorder = new TextButton("Apply");
|
||||||
|
reorder.setIcon(ResourceBundle.INSTANCE.columnReorder());
|
||||||
|
reorder.setIconAlign(IconAlign.RIGHT);
|
||||||
|
reorder.setTitle("Apply Position Columns");
|
||||||
|
|
||||||
|
SelectHandler deleteHandler = new SelectHandler() {
|
||||||
|
|
||||||
|
public void onSelect(SelectEvent event) {
|
||||||
|
onReorderColumns();
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
reorder.addSelectHandler(deleteHandler);
|
||||||
|
|
||||||
|
HTML columnsLabel = new HTML("<p>Use drag and drop in order to change the position of the columns:</p>");
|
||||||
|
HBoxLayoutContainer hBox = new HBoxLayoutContainer();
|
||||||
|
hBox.add(reorder, new BoxLayoutData(new Margins(2, 5, 2, 5)));
|
||||||
|
|
||||||
|
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
||||||
|
v.setScrollMode(ScrollMode.AUTOY);
|
||||||
|
v.setAdjustForScroll(true);
|
||||||
|
v.add(columnsLabel, new VerticalLayoutData(-1, -1, new Margins(2, 1, 5,
|
||||||
|
1)));
|
||||||
|
v.add(grid, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||||
|
v.add(hBox, new VerticalLayoutData(-1, -1, new Margins(10, 0, 10, 0)));
|
||||||
|
add(v, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ArrayList<ColumnData> getReorderedColumns() {
|
||||||
|
return new ArrayList<ColumnData>(grid.getStore().getAll());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(TRId trId) {
|
||||||
|
this.trId = trId;
|
||||||
|
loader.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void loadData(ListLoadConfig loadConfig,
|
||||||
|
final AsyncCallback<ListLoadResult<ColumnData>> callback) {
|
||||||
|
TDGWTServiceAsync.INSTANCE.getColumns(trId,
|
||||||
|
new AsyncCallback<ArrayList<ColumnData>>() {
|
||||||
|
|
||||||
|
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.error("load columns failure:"
|
||||||
|
+ caught.getLocalizedMessage());
|
||||||
|
UtilsGXT3.alert("Error retrieving columns",
|
||||||
|
"Error retrieving columns");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callback.onFailure(caught);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSuccess(ArrayList<ColumnData> result) {
|
||||||
|
try {
|
||||||
|
Log.debug("loaded " + result.size() + " ColumnData");
|
||||||
|
callback.onSuccess(new ListLoadResultBean<ColumnData>(
|
||||||
|
result));
|
||||||
|
|
||||||
|
} catch (UmbrellaException e) {
|
||||||
|
Log.debug("Umbrella exception "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
} catch (com.google.web.bindery.event.shared.UmbrellaException e) {
|
||||||
|
Log.debug("Umbrella exception "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onReorderColumns() {
|
||||||
|
ArrayList<ColumnData> columns = getReorderedColumns();
|
||||||
|
if (columns == null || columns.size() < 1) {
|
||||||
|
UtilsGXT3.alert("Attention", "Attention no column change!");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
callReorderColumn(columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void callReorderColumn(ArrayList<ColumnData> columns) {
|
||||||
|
|
||||||
|
changeColumnsPositionSession = new ChangeColumnsPositionSession(trId, columns);
|
||||||
|
|
||||||
|
Log.debug("ChangeColumnsSession: "+changeColumnsPositionSession);
|
||||||
|
/*
|
||||||
|
TDGWTServiceAsync.INSTANCE.startChangeColumnsPosition(changeColumnsPositionSession,
|
||||||
|
new AsyncCallback<String>() {
|
||||||
|
|
||||||
|
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 changing the position of the columns: "
|
||||||
|
+ caught.getLocalizedMessage());
|
||||||
|
UtilsGXT3
|
||||||
|
.alert("Error",
|
||||||
|
"Error changing the position of the columns! "+caught.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSuccess(String taskId) {
|
||||||
|
//openMonitorDialog(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
if (parent != null) {
|
||||||
|
parent.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -64,6 +64,13 @@ public interface ResourceBundle extends ClientBundle {
|
||||||
@Source("column-type_32.png")
|
@Source("column-type_32.png")
|
||||||
ImageResource columnType32();
|
ImageResource columnType32();
|
||||||
|
|
||||||
|
@Source("column-reorder.png")
|
||||||
|
ImageResource columnReorder();
|
||||||
|
|
||||||
|
@Source("column-reorder_32.png")
|
||||||
|
ImageResource columnReorder32();
|
||||||
|
|
||||||
|
|
||||||
@Source("column-replace.png")
|
@Source("column-replace.png")
|
||||||
ImageResource replace();
|
ImageResource replace();
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 857 B |
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 857 B |
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
Loading…
Reference in New Issue