155 lines
4.4 KiB
Java
155 lines
4.4 KiB
Java
package org.gcube.portlets.user.workspace.client.view.windows;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
|
|
|
|
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
|
|
import com.extjs.gxt.ui.client.data.BaseModelData;
|
|
import com.extjs.gxt.ui.client.data.ModelData;
|
|
import com.extjs.gxt.ui.client.store.GroupingStore;
|
|
import com.extjs.gxt.ui.client.store.ListStore;
|
|
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
|
import com.extjs.gxt.ui.client.widget.LayoutContainer;
|
|
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
|
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
|
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
|
import com.extjs.gxt.ui.client.widget.grid.GridGroupRenderer;
|
|
import com.extjs.gxt.ui.client.widget.grid.GroupColumnData;
|
|
import com.extjs.gxt.ui.client.widget.grid.GroupingView;
|
|
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
|
|
|
public class AccoutingInfoContainer extends LayoutContainer {
|
|
|
|
|
|
protected static final String DATE = "Date";
|
|
protected static final String AUTHOR = "Author";
|
|
protected static final String OPERATION = "Operation";
|
|
protected static final String DESCRIPTION = "Description";
|
|
private ColumnModel cm;
|
|
private Grid<ModelData> grid;
|
|
private ContentPanel cp;
|
|
private GroupingStore<ModelData> store = new GroupingStore<ModelData>();
|
|
|
|
public AccoutingInfoContainer(){
|
|
initContentPanel();
|
|
initGrid();
|
|
}
|
|
|
|
public void initGrid() {
|
|
|
|
store.groupBy(OPERATION);
|
|
|
|
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
|
|
|
|
ColumnConfig descr = createSortableColumnConfig(DESCRIPTION, DESCRIPTION, 230);
|
|
columns.add(descr);
|
|
|
|
ColumnConfig oper = createSortableColumnConfig(OPERATION, OPERATION, 70);
|
|
columns.add(oper);
|
|
|
|
ColumnConfig auth = createSortableColumnConfig(OPERATION, AUTHOR, 70);
|
|
columns.add(auth);
|
|
|
|
ColumnConfig date = createSortableColumnConfig(DATE, DATE, 70);
|
|
columns.add(date);
|
|
|
|
cm = new ColumnModel(columns);
|
|
|
|
final ColumnModel columnModel = cm;
|
|
|
|
grid = new Grid<ModelData>(this.store, cm);
|
|
|
|
GroupingView view = new GroupingView();
|
|
view.setShowGroupedColumn(true);
|
|
this.grid.setView(view);
|
|
|
|
view.setGroupRenderer(new GridGroupRenderer() {
|
|
public String render(GroupColumnData data) {
|
|
String f = columnModel.getColumnById(data.field).getHeader();
|
|
String l = data.models.size() == 1 ? "Item" : "Items";
|
|
return f + ": " + data.group + " (" + data.models.size() + " " + l + ")";
|
|
}
|
|
});
|
|
|
|
grid.setBorders(true);
|
|
grid.setStripeRows(true);
|
|
grid.getView().setAutoFill(true);
|
|
grid.setColumnLines(true);
|
|
grid.setColumnReordering(true);
|
|
grid.setStyleAttribute("borderTop", "none");
|
|
|
|
cp.add(grid);
|
|
|
|
}
|
|
|
|
public AccoutingInfoContainer(List<GxtAccountingField> accountings) {
|
|
|
|
initContentPanel();
|
|
initGrid();
|
|
updateListAccounting(accountings);
|
|
}
|
|
|
|
|
|
private void updateListAccounting(List<GxtAccountingField> accountings){
|
|
|
|
List<BaseModelData> listModelData = new ArrayList<BaseModelData>();
|
|
|
|
store.removeAll();
|
|
|
|
for (GxtAccountingField gxtAccountingField : accountings) {
|
|
BaseModelData baseModel = new BaseModelData();
|
|
|
|
baseModel.set(DESCRIPTION, gxtAccountingField.getDescription());
|
|
baseModel.set(OPERATION, gxtAccountingField.getOperation());
|
|
baseModel.set(AUTHOR, gxtAccountingField.getUser());
|
|
baseModel.set(DATE, gxtAccountingField.getDate());
|
|
|
|
listModelData.add(baseModel);
|
|
}
|
|
|
|
store.add(listModelData);
|
|
}
|
|
|
|
private void initContentPanel() {
|
|
setLayout(new FitLayout());
|
|
getAriaSupport().setPresentation(true);
|
|
cp = new ContentPanel();
|
|
cp.setHeaderVisible(false);
|
|
cp.setBodyBorder(true);
|
|
cp.setLayout(new FitLayout());
|
|
cp.setButtonAlign(HorizontalAlignment.CENTER);
|
|
cp.setLayout(new FitLayout());
|
|
// cp.getHeader().setIconAltText("Grid Icon");
|
|
cp.setSize(500, 250);
|
|
|
|
add(cp);
|
|
}
|
|
|
|
public void updateStore(ListStore<ModelData> store){
|
|
|
|
this.grid.getStore().removeAll();
|
|
// for (ModelData modelData : store.getModels()){
|
|
// this.grid.getStore().add(modelData);
|
|
// }
|
|
|
|
this.grid.getStore().add(store.getModels());
|
|
|
|
// cp.layout();
|
|
}
|
|
|
|
public ColumnConfig createSortableColumnConfig(String id, String name, int width)
|
|
{
|
|
ColumnConfig columnConfig = new ColumnConfig(id, name, width);
|
|
columnConfig.setSortable(true);
|
|
|
|
return columnConfig;
|
|
}
|
|
|
|
public void setHeaderTitle(String title) {
|
|
cp.setHeading(title);
|
|
// cp.layout();
|
|
}
|
|
|
|
} |