package org.gcube.portlets.user.workspace.client.view.trash; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.client.interfaces.GXTFolderItemTypeEnum; import org.gcube.portlets.user.workspace.client.model.FileModel; import org.gcube.portlets.user.workspace.client.resources.Resources; import com.extjs.gxt.ui.client.Style.ButtonScale; import com.extjs.gxt.ui.client.Style.HorizontalAlignment; import com.extjs.gxt.ui.client.data.BaseModelData; import com.extjs.gxt.ui.client.dnd.GridDropTarget; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.DNDEvent; import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.store.GroupingStore; import com.extjs.gxt.ui.client.store.ListStore; import com.extjs.gxt.ui.client.store.Record; import com.extjs.gxt.ui.client.widget.ContentPanel; import com.extjs.gxt.ui.client.widget.LayoutContainer; import com.extjs.gxt.ui.client.widget.button.ToggleButton; import com.extjs.gxt.ui.client.widget.grid.ColumnConfig; import com.extjs.gxt.ui.client.widget.grid.ColumnData; 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.GridCellRenderer; import com.extjs.gxt.ui.client.widget.grid.GroupingView; import com.extjs.gxt.ui.client.widget.grid.filters.GridFilters; import com.extjs.gxt.ui.client.widget.grid.filters.StringFilter; import com.extjs.gxt.ui.client.widget.layout.FitLayout; import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; import com.google.gwt.i18n.client.NumberFormat; public class TrashInfoContainer extends LayoutContainer { /** * */ private Grid grid; private ContentPanel cp; private GroupingStore store = new GroupingStore(); private boolean groupingEnabled; private ListStore typeStoreOperation = new ListStore(); private NumberFormat number = ConstantsExplorer.numberFormatterKB; private GridDropTarget gridDropTarget; public TrashInfoContainer() { initContentPanel(); initGrid(); createToolBar(); initDropTarget(); } /** * */ private void initDropTarget() { this.gridDropTarget = new GridDropTarget(grid){ /* (non-Javadoc) * @see com.extjs.gxt.ui.client.dnd.GridDropTarget#onDragDrop(com.extjs.gxt.ui.client.event.DNDEvent) */ @Override protected void onDragDrop(DNDEvent e) { // TODO Auto-generated method stub List listFileModel = getDragSource(e); for (FileModel fileModel : listFileModel) { fileModel.setIcon(); } System.out.println("** Trash Event move handleInsertDrop is completed"); super.onDragDrop(e); } private List getDragSource(DNDEvent event){ List listDraggedFile = new ArrayList(); if(event.getData() != null){ List listItemsSource = event.getData(); System.out.println("Trash - Number of move " + listItemsSource.size()); FileModel sourceFileModel = null; //for print for(int i=0; i() { @Override public void componentSelected(ButtonEvent ce) { if (buttonGrouping.isPressed()) enableGrouping(); else disableGrouping(); } }); // bar.add(buttonGrouping); cp.setTopComponent(bar); } public void initGrid() { // store.groupBy(ConstantsExplorer.SHORTCUTCATEGORY); // groupingEnabled = true; ColumnConfig icon = new ColumnConfig(ConstantsExplorer.ICON, "", 25); ColumnConfig name = createSortableColumnConfig(ConstantsExplorer.NAME, ConstantsExplorer.NAME, 300); ColumnConfig type = createSortableColumnConfig(ConstantsExplorer.TYPE, ConstantsExplorer.TYPE, 50); // ColumnConfig category = createSortableColumnConfig(ConstantsExplorer.SHORTCUTCATEGORY, ConstantsExplorer.SHORTCUTCATEGORY, 100); ColumnConfig ownerFullName = createSortableColumnConfig(ConstantsExplorer.OWNERFULLNAME, ConstantsExplorer.OWNER, 100); ColumnModel cm = new ColumnModel(Arrays.asList(icon, name, type, ownerFullName)); final ColumnModel columnModel = cm; grid = new Grid(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 + ")"; // } // }); GridCellRenderer folderRender = new GridCellRenderer() { @Override public String render(FileModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore store, Grid grid) { String val = model.get(property); String color = "black"; if(val != null && val.equals(GXTFolderItemTypeEnum.FOLDER.toString())){ // color = "#EEC900"; return "" + val + ""; }else{ if(val==null) val = ""; return "" + val + ""; } } }; type.setRenderer(folderRender); GridFilters filters = new GridFilters(); filters.setLocal(true); StringFilter nameFilter = new StringFilter(ConstantsExplorer.NAME); StringFilter authorFilter = new StringFilter(ConstantsExplorer.TYPE); filters.addFilter(nameFilter); filters.addFilter(authorFilter); grid.addPlugin(filters); grid.setBorders(true); grid.setStripeRows(true); grid.getView().setAutoFill(true); grid.setColumnLines(true); grid.setColumnReordering(true); grid.setStyleAttribute("borderTop", "none"); cp.add(grid); } public void setPanelSize(int width, int height) { if (width > 0 && height > 0 && grid != null) { cp.setSize(width, height); // grid.setSize(width, height); } } public TrashInfoContainer(List trashFiles) { initContentPanel(); initGrid(); updateTrash(trashFiles); } public void disableGrouping() { GroupingStore groupingStore = null; if (store instanceof GroupingStore) { groupingStore = (GroupingStore) store; if (groupingStore != null) { groupingStore.clearGrouping(); } this.groupingEnabled = false; } } public void enableGrouping() { GroupingStore groupingStore = null; if (store instanceof GroupingStore) { groupingStore = (GroupingStore) store; if (groupingStore != null) { groupingStore.groupBy(ConstantsExplorer.SHORTCUTCATEGORY); } this.groupingEnabled = true; } } public void updateTrash(List trashFiles) { store.removeAll(); typeStoreOperation.removeAll(); store.add(trashFiles); } private void updateStore(ListStore store) { resetStore(); this.grid.getStore().add(store.getModels()); } public void resetStore() { this.grid.getStore().removeAll(); } 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(); } public boolean isGroupingEnabled() { return groupingEnabled; } public void setGroupingEnabled(boolean groupingEnabled) { this.groupingEnabled = groupingEnabled; } /** * * @param identifier * @return */ public FileModel getFileModelByIdentifier(String identifier){ return store.findModel(ConstantsExplorer.IDENTIFIER, identifier); } /** * * @param identifier (MANDATORY) * @return */ public boolean deleteItem(String identifier) { FileModel fileTarget = getFileModelByIdentifier(identifier); if(fileTarget!=null){ return deleteItem(fileTarget); } else System.out.println("Delete Error: file target with " + identifier + " identifier not exist in store" ); return false; } /** * * @param fileTarget (MANDATORY) * @return */ private boolean deleteItem(FileModel fileTarget) { Record record = store.getRecord(fileTarget); if (record != null) { FileModel item = (FileModel) record.getModel(); store.remove(item); return true; } else System.out.println("Record Error: file target with " + fileTarget.getIdentifier() + " identifier not exist in store"); return false; } }