Added rows editing

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@92988 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-03-11 16:27:13 +00:00 committed by Giancarlo Panichi
parent 439da80030
commit 90982cda43
3 changed files with 75 additions and 10 deletions

View File

@ -3,6 +3,8 @@
*/
package org.gcube.portlets.user.tdwx.client;
import java.util.ArrayList;
import org.gcube.portlets.user.tdwx.client.event.CloseTableEvent;
import org.gcube.portlets.user.tdwx.client.event.FailureEvent;
import org.gcube.portlets.user.tdwx.client.event.FailureEventHandler;
@ -145,6 +147,11 @@ public class TabularDataX {
return new TableId(defaultDataSourceFactoryName, tableKey);
}
public void addRow(ArrayList<String> rows){
if(gridPanel!=null){
gridPanel.addRow(rows);
}
}
/**
*

View File

@ -46,6 +46,7 @@ import com.sencha.gxt.core.client.resources.ThemeStyles;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.data.client.loader.HttpProxy;
import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.data.shared.event.StoreUpdateEvent;
import com.sencha.gxt.data.shared.loader.PagingLoadConfig;
import com.sencha.gxt.data.shared.loader.PagingLoadConfigBean;
import com.sencha.gxt.data.shared.loader.PagingLoadResult;
@ -58,8 +59,11 @@ import com.sencha.gxt.widget.core.client.event.HeaderContextMenuEvent.HeaderCont
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.Grid.GridCell;
import com.sencha.gxt.widget.core.client.grid.LiveGridView;
import com.sencha.gxt.widget.core.client.grid.LiveToolItem;
import com.sencha.gxt.widget.core.client.grid.editing.ClicksToEdit;
import com.sencha.gxt.widget.core.client.grid.editing.GridInlineEditing;
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;
@ -83,7 +87,10 @@ public class TabularDataXGridPanel extends ContentPanel {
protected com.google.web.bindery.event.shared.EventBus externalBus;
protected ListStore<DataRow> store;
protected Grid<DataRow> grid;
protected GridInlineEditing<DataRow> editing;
protected TableDefinition tableDefinition;
protected VerticalLayoutContainer container;
protected ExtendedLiveGridView liveGridView;
@ -255,11 +262,22 @@ public class TabularDataXGridPanel extends ContentPanel {
unmask();
}
protected void setupGrid(TableDefinition tableDefinition) {
protected void setupGrid(TableDefinition tableDefinition) {
this.tableDefinition=tableDefinition;
ColumnDefinition modelKeyColumn = tableDefinition.getModelKeyColumn();
ListStore<DataRow> store = new ListStore<DataRow>(
store = new ListStore<DataRow>(
new DataRowModelKeyProvider(modelKeyColumn.getKey()));
store.addStoreUpdateHandler(new StoreUpdateEvent.StoreUpdateHandler<DataRow>() {
@Override
public void onUpdate(StoreUpdateEvent<DataRow> event) {
Log.debug("UPDATE ROWS");
Log.debug(event.getItems().toString());
}
});
List<ColumnConfig<DataRow, ?>> columnsConfig = new ArrayList<ColumnConfig<DataRow, ?>>();
@ -274,10 +292,8 @@ public class TabularDataXGridPanel extends ContentPanel {
// IdentityValueProvider<DataRow> identity = new
// IdentityValueProvider<DataRow>();
// LiveRowNumberer<DataRow> numberer = new
// LiveRowNumberer<DataRow>(identity);
// columnsConfig.add(numberer);
ColumnModel<DataRow> columnModel = new ColumnModel<DataRow>(
@ -306,11 +322,19 @@ public class TabularDataXGridPanel extends ContentPanel {
grid.setLoadMask(true);
grid.setLoader(loader);
grid.setView(liveGridView);
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));
editing = new GridInlineEditing<DataRow>(grid);
editing.setClicksToEdit(ClicksToEdit.TWO);
for(ColumnConfig<DataRow, ?> c:columnsConfig){
ColumnConfigGenerator.setEditor(editing, c);
}
// numberer.initPlugin(grid);
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));
ToolBar toolBar = new ToolBar();
toolBar.add(new LiveToolItem(grid));
toolBar.addStyleName(ThemeStyles.getStyle().borderTop());
@ -339,13 +363,20 @@ public class TabularDataXGridPanel extends ContentPanel {
setHeaderContextMenuHandler();
}
} else {
// TODO we need to manually reset the sort
loader.clearSortInfo();
reader.setDefinition(tableDefinition);
grid.reconfigure(store, columnModel);
editing = new GridInlineEditing<DataRow>(grid);
editing.setClicksToEdit(ClicksToEdit.TWO);
for(ColumnConfig<DataRow, ?> c:columnsConfig){
ColumnConfigGenerator.setEditor(editing, c);
}
// TODO workaround: the loader is called only if the scroll bar is
// in the middle
if (loader.getOffset() == 0)
@ -450,6 +481,31 @@ public class TabularDataXGridPanel extends ContentPanel {
return columnId;
}
public void addRow(ArrayList<String> rows){
if(grid!=null && editing!=null){
List<ColumnKey> keys=tableDefinition.getKeys();
DataRow dataRow=new DataRow(keys.size());
for(ColumnKey key:keys){
dataRow.set(key, null);
}
editing.cancelEditing();
int pos=0;
if(rows!=null && rows.size()>0){
pos=new Integer(rows.get(0));
}
store.add(pos, dataRow);
int row = store.indexOf(dataRow);
editing.startEditing(new GridCell(row, pos));
}
}
protected class ExtendedLiveGridView extends LiveGridView<DataRow> {
//TODO bug in gxt3 3.0.0 fixed in future
/*@Override

View File

@ -19,6 +19,8 @@ import com.sencha.gxt.widget.core.client.form.NumberPropertyEditor;
import com.sencha.gxt.widget.core.client.form.TextField;
import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
import com.sencha.gxt.widget.core.client.grid.editing.AbstractGridEditing;
import com.sencha.gxt.widget.core.client.grid.editing.GridInlineEditing;
import com.sencha.gxt.widget.core.client.grid.editing.GridRowEditing;
/**
*
@ -115,7 +117,7 @@ public class ColumnConfigGenerator {
return new DataRowColumnConfig<T>(columnDefinition);
}
public static void setEditor(AbstractGridEditing<DataRow> editableGrid,
public static void setEditor(GridInlineEditing<DataRow> editableGrid,
ColumnConfig<DataRow, ?> columnConfig) {
if (!(columnConfig instanceof DataRowColumnConfig<?>))
throw new IllegalArgumentException(
@ -124,7 +126,7 @@ public class ColumnConfigGenerator {
}
@SuppressWarnings("unchecked")
public static void setEditor(AbstractGridEditing<DataRow> editableGrid,
public static void setEditor(GridInlineEditing<DataRow> editableGrid,
DataRowColumnConfig<?> columnConfig) {
if (columnConfig.getDefinition().isEditable()) {
switch (columnConfig.getDefinition().getValueType()) {