enhancement on trash

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@90083 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2014-01-14 13:26:41 +00:00
parent 090993da69
commit 62fc62aed3
4 changed files with 154 additions and 43 deletions

View File

@ -1,21 +1,26 @@
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.FileGridModel;
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.BaseModel;
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.store.TreeStoreModel;
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;
@ -24,8 +29,6 @@ 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.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.grid.filters.GridFilters;
import com.extjs.gxt.ui.client.widget.grid.filters.StringFilter;
@ -38,10 +41,7 @@ public class TrashInfoContainer extends LayoutContainer {
/**
*
*/
private static final String OPERATION_NAME = "Type";
/**
*
*/
private Grid<FileModel> grid;
private ContentPanel cp;
@ -49,11 +49,85 @@ public class TrashInfoContainer extends LayoutContainer {
private boolean groupingEnabled;
private ListStore<FileModel> typeStoreOperation = new ListStore<FileModel>();
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<FileModel> listFileModel = getDragSource(e);
for (FileModel fileModel : listFileModel) {
fileModel.setIcon();
}
System.out.println("** Trash Event move handleInsertDrop is completed");
super.onDragDrop(e);
}
private List<FileModel> getDragSource(DNDEvent event){
List<FileModel> listDraggedFile = new ArrayList<FileModel>();
if(event.getData() != null){
List<BaseModelData> listItemsSource = event.getData();
System.out.println("Trash - Number of move " + listItemsSource.size());
FileModel sourceFileModel = null; //for print
for(int i=0; i<listItemsSource.size(); i++){
/*
if(listItemsSource.get(i) instanceof TreeStoreModel){
System.out.println("qui 1");
TreeStoreModel itemSource = (TreeStoreModel) listItemsSource.get(i);
listDraggedFile.add((FileModel) itemSource.getModel());
sourceFileModel = (FileModel) itemSource.getModel();
if(sourceFileModel.getParentFileModel()!=null)
System.out.println("Trash Source Name " + sourceFileModel.getName() + " id " + sourceFileModel.getIdentifier() + " end drag " + " Parent Name: " + sourceFileModel.getParentFileModel().getName() + "id " + sourceFileModel.getParentFileModel().getIdentifier());
else
System.out.println("Trash Source Name " + sourceFileModel.getName() + " id " + sourceFileModel.getIdentifier() + " end drag ");
}else
{
System.out.println("qui 2");
System.out.println("class "+listItemsSource.get(i).getClass());
}*/
// System.out.println("Trash Child count: " + itemSource.getChildCount());
}
}
return listDraggedFile;
}
};
}
private void initContentPanel() {
@ -89,23 +163,24 @@ public class TrashInfoContainer extends LayoutContainer {
}
});
bar.add(buttonGrouping);
// bar.add(buttonGrouping);
cp.setTopComponent(bar);
}
public void initGrid() {
store.groupBy(ConstantsExplorer.SHORTCUTCATEGORY);
groupingEnabled = true;
// store.groupBy(ConstantsExplorer.SHORTCUTCATEGORY);
// groupingEnabled = true;
ColumnConfig icon = createSortableColumnConfig(ConstantsExplorer.ICON, "", 25);
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 category = createSortableColumnConfig(ConstantsExplorer.SHORTCUTCATEGORY, ConstantsExplorer.SHORTCUTCATEGORY, 100);
ColumnConfig ownerFullName = createSortableColumnConfig(ConstantsExplorer.OWNERFULLNAME, ConstantsExplorer.OWNER, 100);
ColumnModel cm = new ColumnModel(Arrays.asList(icon, name, ownerFullName, type, category));
ColumnModel cm = new ColumnModel(Arrays.asList(icon, name, type, ownerFullName));
final ColumnModel columnModel = cm;
@ -115,19 +190,19 @@ public class TrashInfoContainer extends LayoutContainer {
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 + ")";
}
});
// 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<FileGridModel> folderRender = new GridCellRenderer<FileGridModel>() {
GridCellRenderer<FileModel> folderRender = new GridCellRenderer<FileModel>() {
@Override
public String render(FileGridModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<FileGridModel> store, Grid<FileGridModel> grid) {
public String render(FileModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<FileModel> store, Grid<FileModel> grid) {
String val = model.get(property);
String color = "black";
@ -163,6 +238,7 @@ public class TrashInfoContainer extends LayoutContainer {
grid.setColumnReordering(true);
grid.setStyleAttribute("borderTop", "none");
cp.add(grid);
}
@ -197,7 +273,7 @@ public class TrashInfoContainer extends LayoutContainer {
if (store instanceof GroupingStore) {
groupingStore = (GroupingStore<FileModel>) store;
if (groupingStore != null) {
groupingStore.groupBy(OPERATION_NAME);
groupingStore.groupBy(ConstantsExplorer.SHORTCUTCATEGORY);
}
this.groupingEnabled = true;
}

View File

@ -4,6 +4,7 @@ import java.util.List;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.client.model.FileModel;
import org.gcube.portlets.user.workspace.client.resources.Resources;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
@ -24,7 +25,7 @@ public class WindowTrash extends Window {
private WindowTrash() {
initAccounting();
// setIcon(fileModel.getAbstractPrototypeIcon()); //TODO
setIcon(Resources.getTrash()); //TODO
setHeading("Trash");
// addResizeListner();
}
@ -62,7 +63,7 @@ public class WindowTrash extends Window {
// }
private void initAccounting() {
setModal(true);
// setModal(true);
setLayout(new FitLayout());
setSize(700, 350);
setResizable(true);

View File

@ -40,6 +40,7 @@ import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.store.StoreSorter;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.store.TreeStoreModel;
import com.extjs.gxt.ui.client.widget.Component;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
@ -356,22 +357,45 @@ public class AsyncTreePanel extends LayoutContainer {
if (zone == null) {
return true; // let it check from super-class
}
Component com = event.getDragSource().getComponent();
if(com instanceof TreePanel<?>){
TreePanel<FileModel> source = (TreePanel<FileModel>) event.getDragSource().getComponent();
List<FileModel> selection = source.getSelectionModel().getSelection();
TreePanel<FileModel> source = (TreePanel<FileModel>) event.getDragSource().getComponent();
List<FileModel> selection = source.getSelectionModel().getSelection();
for (FileModel model : selection) {
// check the "model" against "zone" and return false
// if "zone" is not a valid drop target for "model", otherwise check the next "model"
// example:
if (source.getStore().getParent(model) == zone.getModel())
return false;
// if(source.getStore().getParent(model) == target.getModel())
// return false;
}
for (FileModel model : selection) {
// check the "model" against "zone" and return false
// if "zone" is not a valid drop target for "model", otherwise check the next "model"
// example:
if (source.getStore().getParent(model) == zone.getModel())
return false;
// if(source.getStore().getParent(model) == target.getModel())
// return false;
return true;
}
return true;
return false;
// TreePanel<FileModel> source = (TreePanel<FileModel>) event.getDragSource().getComponent();
// List<FileModel> selection = source.getSelectionModel().getSelection();
//
// for (FileModel model : selection) {
// // check the "model" against "zone" and return false
// // if "zone" is not a valid drop target for "model", otherwise check the next "model"
// // example:
// if (source.getStore().getParent(model) == zone.getModel())
// return false;
//
//// if(source.getStore().getParent(model) == target.getModel())
//// return false;
// }
//
// return true;
}
//Called when drop on folder
@ -389,7 +413,13 @@ public class AsyncTreePanel extends LayoutContainer {
FileModel destination = getDragDestination(item, DragType.APPEND);
if(destination != null){
eventBus.fireEvent(new MoveItemEvent(listFileModel.get(0), (FolderModel) destination));
//REMOVE THIS COMMENT TODO
// eventBus.fireEvent(new MoveItemEvent(listFileModel.get(0), (FolderModel) destination));
System.out.println("Destination: " +destination.getName() + " id "+ destination.getIdentifier());
}
@ -430,7 +460,11 @@ public class AsyncTreePanel extends LayoutContainer {
System.out.println("Destination: " +destination.getName() + " id "+ destination.getIdentifier());
eventBus.fireEvent(new MoveItemEvent(listFileModel.get(0), (FolderModel) destination));
//REMOVE THIS COMMENT TODO
// eventBus.fireEvent(new MoveItemEvent(listFileModel.get(0), (FolderModel) destination));
}
}

View File

@ -74,10 +74,10 @@ public class WsUtil {
/*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING
* COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/
user=TEST_USER;
// user=TEST_USER;
//UNCOMMENT THIS IN DEVELOP ENVIROMENT
// user = "francesco.mangiacrapa";
user = "francesco.mangiacrapa";
logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
logger.warn("session id: "+sessionID);