Minor Update

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@93006 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-03-11 19:12:55 +00:00 committed by Giancarlo Panichi
parent 90982cda43
commit 62a697a5a5
1 changed files with 105 additions and 56 deletions

View File

@ -215,6 +215,60 @@ public class TabularDataXGridPanel extends ContentPanel {
return null; return null;
} }
/**
* getSelectedRowsId
*
* @return List<String> list of identifiers of the selected rows
*/
public ArrayList<String> getSelectedRowsId() {
if (grid != null) {
ColumnModel<DataRow> columnModel = grid
.getColumnModel();
List<ColumnConfig<DataRow, ?>> columns = columnModel
.getColumns();
DataRowColumnConfig<?> c = null;
boolean columnIdRetrieved = false;
for (ColumnConfig<DataRow, ?> col : columns) {
c = (DataRowColumnConfig<?>) col;
ColumnType ctype = c.getDefinition().getType();
if (ctype == ColumnType.COLUMNID) {
columnIdRetrieved = true;
break;
}
}
if (columnIdRetrieved) {
ColumnDefinition cd = c.getDefinition();
Log.debug("CD - Definition:" + cd.getId()
+ " ColumnLocalId:" + cd.getColumnLocalId()
+ " Label:" + cd.getLabel() + " Key:"
+ cd.getKey());
List<Row> rowsSelected = getSelectedRows();
Log.debug("Retriving rows selected");
String rowS = "";
ArrayList<String> rows = new ArrayList<String>();
if (rowsSelected != null) {
for (Row row : rowsSelected) {
rowS = row.getFieldAsText(cd.getLabel());
Log.debug("Selected Row:" + rowS);
rows.add(rowS);
}
} else {
Log.debug("no selected rows retrived");
}
return rows;
} else {
Log.debug("no COLUMNID retrived");
return null;
}
} else {
return null;
}
}
protected void bindEventBus() { protected void bindEventBus() {
eventBus.addHandler(OpenTableEvent.TYPE, new OpenTableEventHandler() { eventBus.addHandler(OpenTableEvent.TYPE, new OpenTableEventHandler() {
@ -262,13 +316,12 @@ public class TabularDataXGridPanel extends ContentPanel {
unmask(); unmask();
} }
protected void setupGrid(TableDefinition tableDefinition) { protected void setupGrid(TableDefinition tableDefinition) {
this.tableDefinition=tableDefinition; this.tableDefinition = tableDefinition;
ColumnDefinition modelKeyColumn = tableDefinition.getModelKeyColumn(); ColumnDefinition modelKeyColumn = tableDefinition.getModelKeyColumn();
store = new ListStore<DataRow>( store = new ListStore<DataRow>(new DataRowModelKeyProvider(
new DataRowModelKeyProvider(modelKeyColumn.getKey())); modelKeyColumn.getKey()));
store.addStoreUpdateHandler(new StoreUpdateEvent.StoreUpdateHandler<DataRow>() { store.addStoreUpdateHandler(new StoreUpdateEvent.StoreUpdateHandler<DataRow>() {
@ -326,13 +379,12 @@ public class TabularDataXGridPanel extends ContentPanel {
editing = new GridInlineEditing<DataRow>(grid); editing = new GridInlineEditing<DataRow>(grid);
editing.setClicksToEdit(ClicksToEdit.TWO); editing.setClicksToEdit(ClicksToEdit.TWO);
for(ColumnConfig<DataRow, ?> c:columnsConfig){ for (ColumnConfig<DataRow, ?> c : columnsConfig) {
ColumnConfigGenerator.setEditor(editing, c); ColumnConfigGenerator.setEditor(editing, c);
} }
// numberer.initPlugin(grid); // numberer.initPlugin(grid);
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0))); container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));
ToolBar toolBar = new ToolBar(); ToolBar toolBar = new ToolBar();
@ -340,8 +392,8 @@ public class TabularDataXGridPanel extends ContentPanel {
toolBar.addStyleName(ThemeStyles.getStyle().borderTop()); toolBar.addStyleName(ThemeStyles.getStyle().borderTop());
toolBar.getElement().getStyle().setProperty("borderBottom", "none"); toolBar.getElement().getStyle().setProperty("borderBottom", "none");
container.add(toolBar, new VerticalLayoutData(1, 25, new Margins(0))); container.add(toolBar,
new VerticalLayoutData(1, 25, new Margins(0)));
container.forceLayout(); container.forceLayout();
@ -363,8 +415,6 @@ public class TabularDataXGridPanel extends ContentPanel {
setHeaderContextMenuHandler(); setHeaderContextMenuHandler();
} }
} else { } else {
// TODO we need to manually reset the sort // TODO we need to manually reset the sort
loader.clearSortInfo(); loader.clearSortInfo();
@ -373,7 +423,7 @@ public class TabularDataXGridPanel extends ContentPanel {
editing = new GridInlineEditing<DataRow>(grid); editing = new GridInlineEditing<DataRow>(grid);
editing.setClicksToEdit(ClicksToEdit.TWO); editing.setClicksToEdit(ClicksToEdit.TWO);
for(ColumnConfig<DataRow, ?> c:columnsConfig){ for (ColumnConfig<DataRow, ?> c : columnsConfig) {
ColumnConfigGenerator.setEditor(editing, c); ColumnConfigGenerator.setEditor(editing, c);
} }
@ -394,8 +444,6 @@ public class TabularDataXGridPanel extends ContentPanel {
grid.getView().setViewConfig(null); grid.getView().setViewConfig(null);
} }
} }
/** /**
@ -462,7 +510,8 @@ public class TabularDataXGridPanel extends ContentPanel {
/** /**
* *
* @param i index of column in ColumnModel * @param i
* index of column in ColumnModel
* @return id of column and equals to column name on service * @return id of column and equals to column name on service
*/ */
public String getColumnId(int i) { public String getColumnId(int i) {
@ -482,38 +531,38 @@ public class TabularDataXGridPanel extends ContentPanel {
} }
/**
*
* @param rows
*/
public void addRow(ArrayList<String> rows) {
if (grid != null && editing != null) {
List<ColumnKey> keys = tableDefinition.getKeys();
public void addRow(ArrayList<String> rows){ DataRow dataRow = new DataRow(keys.size());
if(grid!=null && editing!=null){ for (ColumnKey key : keys) {
List<ColumnKey> keys=tableDefinition.getKeys();
DataRow dataRow=new DataRow(keys.size());
for(ColumnKey key:keys){
dataRow.set(key, null); dataRow.set(key, null);
} }
editing.cancelEditing(); editing.cancelEditing();
int pos=0; int pos = 0;
if(rows!=null && rows.size()>0){ if (rows != null && rows.size() > 0) {
pos=new Integer(rows.get(0)); pos = new Integer(rows.get(0));
} }
store.add(pos, dataRow); store.add(pos, dataRow);
int row = store.indexOf(dataRow); int row = store.indexOf(dataRow);
editing.startEditing(new GridCell(row, pos)); editing.startEditing(new GridCell(row, pos));
} }
} }
protected class ExtendedLiveGridView extends LiveGridView<DataRow> { protected class ExtendedLiveGridView extends LiveGridView<DataRow> {
//TODO bug in gxt3 3.0.0 fixed in future // TODO bug in gxt3 3.0.0 fixed in future
/*@Override /*
public void refresh(boolean headerToo) { * @Override public void refresh(boolean headerToo) {
preventScrollToTopOnRefresh = true; * preventScrollToTopOnRefresh = true; super.refresh(headerToo); }
super.refresh(headerToo); */
}*/
}; };
} }