2014-02-17 19:20:45 +01:00
|
|
|
package org.gcube.portlets.user.workspace.client.view.trash;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
import org.gcube.portlets.user.workspace.client.AppController;
|
|
|
|
import org.gcube.portlets.user.workspace.client.event.TrashEvent;
|
2014-02-17 19:20:45 +01:00
|
|
|
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.model.FileTrashedModel;
|
|
|
|
import org.gcube.portlets.user.workspace.client.resources.Resources;
|
2014-05-13 17:46:02 +02:00
|
|
|
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation;
|
2014-02-17 19:20:45 +01:00
|
|
|
|
|
|
|
import com.extjs.gxt.ui.client.Style.ButtonScale;
|
|
|
|
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
|
2014-05-13 17:46:02 +02:00
|
|
|
import com.extjs.gxt.ui.client.Style.IconAlign;
|
2014-05-16 18:11:15 +02:00
|
|
|
import com.extjs.gxt.ui.client.Style.Scroll;
|
2014-02-17 19:20:45 +01:00
|
|
|
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;
|
2014-05-13 17:46:02 +02:00
|
|
|
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
2014-02-17 19:20:45 +01:00
|
|
|
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;
|
2014-05-13 17:46:02 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.MessageBox;
|
|
|
|
import com.extjs.gxt.ui.client.widget.button.Button;
|
2014-02-17 19:20:45 +01:00
|
|
|
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;
|
2014-05-13 18:43:35 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.grid.filters.DateFilter;
|
2014-02-17 19:20:45 +01:00
|
|
|
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;
|
2014-05-13 17:46:02 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.menu.SeparatorMenuItem;
|
|
|
|
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
|
2014-02-17 19:20:45 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
2014-05-14 12:19:56 +02:00
|
|
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
2014-02-17 19:20:45 +01:00
|
|
|
|
|
|
|
public class TrashInfoContainer extends LayoutContainer {
|
|
|
|
|
|
|
|
private Grid<FileTrashedModel> grid;
|
|
|
|
private ContentPanel cp;
|
|
|
|
private GroupingStore<FileTrashedModel> store = new GroupingStore<FileTrashedModel>();
|
|
|
|
private ListStore<FileTrashedModel> typeStoreOperation = new ListStore<FileTrashedModel>();
|
|
|
|
private GridDropTarget gridDropTarget;
|
2014-05-13 17:46:02 +02:00
|
|
|
private Button buttonDelete;
|
|
|
|
private Button buttonRestore;
|
2014-05-13 18:43:35 +02:00
|
|
|
private Button buttonRestoreAll;
|
|
|
|
private Button buttonEmptyTrash;
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
public TrashInfoContainer() {
|
|
|
|
initContentPanel();
|
|
|
|
initGrid();
|
|
|
|
createToolBar();
|
2014-05-14 12:13:54 +02:00
|
|
|
// initDropTarget();
|
2014-05-13 17:46:02 +02:00
|
|
|
activeButtonOnSelection(false);
|
2014-02-17 19:20:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-15 16:42:41 +02:00
|
|
|
*
|
2014-02-17 19:20:45 +01:00
|
|
|
*/
|
|
|
|
private void initDropTarget() {
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
this.gridDropTarget = new GridDropTarget(grid){
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see com.extjs.gxt.ui.client.dnd.GridDropTarget#onDragDrop(com.extjs.gxt.ui.client.event.DNDEvent)
|
|
|
|
*/
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
@Override
|
|
|
|
protected void onDragDrop(DNDEvent e) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
List<FileModel> listFileModel = getDragSource(e);
|
|
|
|
|
|
|
|
List<String> ids = new ArrayList<String>();
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
for (FileModel fileModel : listFileModel) {
|
|
|
|
fileModel.setIcon();
|
|
|
|
ids.add(fileModel.getIdentifier());
|
|
|
|
}
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
System.out.println("** Trash Event move handleInsertDrop is completed");
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
super.onDragDrop(e);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
}
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
private List<FileModel> getDragSource(DNDEvent event){
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
List<FileModel> listDraggedFile = new ArrayList<FileModel>();
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
if(event.getData() != null){
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
List<BaseModelData> listItemsSource = event.getData();
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
System.out.println("Trash - Number of move " + listItemsSource.size());
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
// FileModel sourceFileModel = null; //for print
|
|
|
|
|
|
|
|
for(int i=0; i<listItemsSource.size(); i++){
|
|
|
|
|
|
|
|
if(listItemsSource.get(i) instanceof TreeStoreModel){ //DRAG FROM TREE
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
// System.out.println("qui 1");
|
2016-09-15 16:42:41 +02:00
|
|
|
//
|
2014-02-17 19:20:45 +01:00
|
|
|
// TreeStoreModel itemSource = (TreeStoreModel) listItemsSource.get(i);
|
2016-09-15 16:42:41 +02:00
|
|
|
//
|
2014-02-17 19:20:45 +01:00
|
|
|
// listDraggedFile.add((FileModel) itemSource.getModel());
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
// sourceFileModel = (FileModel) itemSource.getModel();
|
2016-09-15 16:42:41 +02:00
|
|
|
//
|
2014-02-17 19:20:45 +01:00
|
|
|
// if(sourceFileModel.getParentFileModel()!=null)
|
2016-09-15 16:42:41 +02:00
|
|
|
//
|
2014-02-17 19:20:45 +01:00
|
|
|
// 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 ");
|
2016-09-15 16:42:41 +02:00
|
|
|
|
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
}else if(listItemsSource.get(i) instanceof FileGridModel){ //DRAG FROM GRID
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
listDraggedFile.add((FileModel) listItemsSource.get(i));
|
|
|
|
// FileGridModel fileGrid = listItemsSource.get(i);
|
|
|
|
// System.out.println("qui 2");
|
|
|
|
// System.out.println("class "+listItemsSource.get(i).getClass());
|
|
|
|
}
|
|
|
|
// System.out.println("Trash Child count: " + itemSource.getChildCount());
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
}
|
|
|
|
}
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
return listDraggedFile;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-05-16 18:11:15 +02:00
|
|
|
cp.setScrollMode(Scroll.AUTOY);
|
2014-02-17 19:20:45 +01:00
|
|
|
add(cp);
|
|
|
|
}
|
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
private boolean checkSelection(){
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
if(grid.getSelectionModel().getSelectedItems().size()==0){
|
|
|
|
MessageBox.info("Attention", "You must pick at least one item", null);
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
private void createToolBar() {
|
|
|
|
|
|
|
|
ToolBar bar = new ToolBar();
|
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
buttonRestore = new Button(WorkspaceTrashOperation.RESTORE.getLabel(),Resources.getIconUndo());
|
|
|
|
buttonRestore.setToolTip(WorkspaceTrashOperation.RESTORE.getOperationDescription());
|
|
|
|
buttonRestore.setScale(ButtonScale.SMALL);
|
|
|
|
buttonRestore.setIconAlign(IconAlign.TOP);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
buttonRestore.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
|
|
|
if(checkSelection())
|
|
|
|
AppController.getEventBus().fireEvent(new TrashEvent(WorkspaceTrashOperation.RESTORE, grid.getSelectionModel().getSelectedItems()));
|
|
|
|
}
|
|
|
|
});
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
bar.add(buttonRestore);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
|
|
|
|
buttonDelete = new Button(WorkspaceTrashOperation.DELETE_PERMANENTLY.getLabel(),Resources.getIconDeleteItem());
|
|
|
|
buttonDelete.setToolTip(WorkspaceTrashOperation.DELETE_PERMANENTLY.getOperationDescription());
|
|
|
|
buttonDelete.setScale(ButtonScale.SMALL);
|
|
|
|
buttonDelete.setIconAlign(IconAlign.TOP);
|
|
|
|
buttonDelete.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
if(checkSelection())
|
|
|
|
AppController.getEventBus().fireEvent(new TrashEvent(WorkspaceTrashOperation.DELETE_PERMANENTLY, grid.getSelectionModel().getSelectedItems()));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
bar.add(buttonDelete);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
|
|
|
|
bar.add(new SeparatorMenuItem());
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 18:43:35 +02:00
|
|
|
buttonRestoreAll = new Button(WorkspaceTrashOperation.RESTORE_ALL.getLabel(),Resources.getIconRecycle());
|
2014-05-13 17:46:02 +02:00
|
|
|
buttonRestoreAll.setToolTip(WorkspaceTrashOperation.RESTORE_ALL.getOperationDescription());
|
|
|
|
buttonRestoreAll.setScale(ButtonScale.SMALL);
|
|
|
|
buttonRestoreAll.setIconAlign(IconAlign.TOP);
|
|
|
|
buttonRestoreAll.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
|
|
|
AppController.getEventBus().fireEvent(new TrashEvent(WorkspaceTrashOperation.RESTORE_ALL, null));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-09-24 15:53:36 +02:00
|
|
|
//bar.add(buttonRestoreAll);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 18:43:35 +02:00
|
|
|
buttonEmptyTrash = new Button(WorkspaceTrashOperation.EMPTY_TRASH.getLabel(),Resources.getTrashEmpty());
|
2014-05-13 17:46:02 +02:00
|
|
|
buttonEmptyTrash.setToolTip(WorkspaceTrashOperation.EMPTY_TRASH.getOperationDescription());
|
|
|
|
buttonEmptyTrash.setScale(ButtonScale.SMALL);
|
|
|
|
buttonEmptyTrash.setIconAlign(IconAlign.TOP);
|
|
|
|
buttonEmptyTrash.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
2014-02-17 19:20:45 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
AppController.getEventBus().fireEvent(new TrashEvent(WorkspaceTrashOperation.EMPTY_TRASH, null));
|
2014-02-17 19:20:45 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
bar.add(buttonEmptyTrash);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
bar.add(new FillToolItem());
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
Button buttonRefresh = new Button(WorkspaceTrashOperation.REFRESH.getLabel(),Resources.getIconRefresh());
|
|
|
|
buttonRefresh.setToolTip(WorkspaceTrashOperation.REFRESH.getOperationDescription());
|
|
|
|
buttonRefresh.setScale(ButtonScale.SMALL);
|
|
|
|
buttonRefresh.setIconAlign(IconAlign.TOP);
|
|
|
|
buttonRefresh.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
|
|
|
AppController.getEventBus().fireEvent(new TrashEvent(WorkspaceTrashOperation.REFRESH, null));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
bar.add(buttonRefresh);
|
2014-02-17 19:20:45 +01:00
|
|
|
cp.setTopComponent(bar);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void initGrid() {
|
|
|
|
|
2018-09-24 15:53:09 +02:00
|
|
|
ColumnConfig icon = new ColumnConfig(FileGridModel.ICON, "", 40);
|
|
|
|
ColumnConfig name = createSortableColumnConfig(FileGridModel.NAME, FileGridModel.NAME, 190);
|
2016-09-15 16:42:41 +02:00
|
|
|
ColumnConfig type = createSortableColumnConfig(FileGridModel.TYPE, FileGridModel.TYPE, 80);
|
2018-09-24 15:53:09 +02:00
|
|
|
ColumnConfig originalPath = createSortableColumnConfig(FileTrashedModel.STOREINFO.ORIGINALPATH.toString(), "Original Path", 190);
|
2014-05-14 12:19:56 +02:00
|
|
|
ColumnConfig deleteDate = createSortableColumnConfig(FileTrashedModel.STOREINFO.DELETEDATE.toString(), "Deleted Date", 90);
|
|
|
|
deleteDate.setDateTimeFormat(DateTimeFormat.getFormat("dd MMM hh:mm aaa yyyy"));
|
2014-05-13 11:27:30 +02:00
|
|
|
ColumnConfig deleteUser = createSortableColumnConfig(FileTrashedModel.STOREINFO.DELETEUSER.toString(), "Deleted By", 150);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
ColumnModel cm = new ColumnModel(Arrays.asList(icon, name, type, originalPath, deleteDate, deleteUser));
|
|
|
|
|
|
|
|
final ColumnModel columnModel = cm;
|
|
|
|
|
|
|
|
grid = new Grid<FileTrashedModel>(this.store, cm);
|
|
|
|
|
|
|
|
GroupingView view = new GroupingView();
|
2014-05-13 18:43:35 +02:00
|
|
|
view.setShowGroupedColumn(false);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
this.grid.setView(view);
|
2014-05-14 12:19:56 +02:00
|
|
|
this.grid.setContextMenu(null);
|
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
|
2016-09-15 16:42:41 +02:00
|
|
|
GridCellRenderer<FileModel> folderRender = new GridCellRenderer<FileModel>() {
|
2014-02-17 19:20:45 +01:00
|
|
|
@Override
|
|
|
|
public String render(FileModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<FileModel> store, Grid<FileModel> grid) {
|
2016-09-15 16:42:41 +02:00
|
|
|
String val = model.get(property);
|
2014-02-17 19:20:45 +01:00
|
|
|
String color = "black";
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
if(val != null && val.equals(GXTFolderItemTypeEnum.FOLDER.toString())){
|
|
|
|
// color = "#EEC900";
|
|
|
|
return "<span qtitle='" + columnModel.getColumnById(property).getHeader() + "' qtip='" + val + "' style='font-weight: bold;color:" + color + "'>" + val + "</span>";
|
|
|
|
}else{
|
|
|
|
if(val==null)
|
|
|
|
val = "";
|
|
|
|
return "<span qtitle='" + columnModel.getColumnById(property).getHeader() + "' qtip='" + val + "' style='color:" + color + "'>" + val + "</span>";
|
|
|
|
}
|
2016-09-15 16:42:41 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
type.setRenderer(folderRender);
|
|
|
|
|
|
|
|
GridFilters filters = new GridFilters();
|
|
|
|
filters.setLocal(true);
|
|
|
|
|
2016-09-15 16:42:41 +02:00
|
|
|
|
|
|
|
StringFilter nameFilter = new StringFilter(FileGridModel.NAME);
|
|
|
|
StringFilter typeFilter = new StringFilter(FileGridModel.TYPE);
|
2014-05-13 18:43:35 +02:00
|
|
|
DateFilter dateFilter = new DateFilter(FileTrashedModel.STOREINFO.DELETEDATE.toString());
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
filters.addFilter(nameFilter);
|
2014-05-13 18:43:35 +02:00
|
|
|
filters.addFilter(typeFilter);
|
|
|
|
filters.addFilter(dateFilter);
|
2014-02-17 19:20:45 +01:00
|
|
|
|
|
|
|
grid.addPlugin(filters);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<FileTrashedModel>() {
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
@Override
|
|
|
|
public void selectionChanged(SelectionChangedEvent<FileTrashedModel> se) {
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
boolean selection = grid.getSelectionModel().getSelectedItems().size()>0;
|
2014-05-13 18:43:35 +02:00
|
|
|
activeButtonOnSelection(selection);
|
2014-05-13 17:46:02 +02:00
|
|
|
}
|
|
|
|
});
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 18:43:35 +02:00
|
|
|
grid.getView().setAutoFill(true);
|
2014-02-17 19:20:45 +01:00
|
|
|
grid.setBorders(true);
|
|
|
|
grid.setStripeRows(true);
|
2014-05-13 18:43:35 +02:00
|
|
|
grid.getView().setShowDirtyCells(false);
|
2014-02-17 19:20:45 +01:00
|
|
|
grid.setColumnLines(true);
|
|
|
|
grid.setColumnReordering(true);
|
|
|
|
grid.setStyleAttribute("borderTop", "none");
|
|
|
|
cp.add(grid);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
|
|
|
|
}
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 18:43:35 +02:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
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<FileTrashedModel> trashFiles) {
|
|
|
|
|
|
|
|
initContentPanel();
|
|
|
|
initGrid();
|
|
|
|
updateTrash(trashFiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateTrash(List<FileTrashedModel> trashFiles) {
|
|
|
|
|
|
|
|
store.removeAll();
|
|
|
|
typeStoreOperation.removeAll();
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 11:27:30 +02:00
|
|
|
for (FileTrashedModel fileTrashedModel : trashFiles) {
|
|
|
|
fileTrashedModel.setIcon();
|
2018-10-04 12:14:28 +02:00
|
|
|
// GWT.log("TrashFile: "+fileTrashedModel);
|
|
|
|
// //Workaround remove this
|
|
|
|
// if(fileTrashedModel.isDirectory())
|
|
|
|
// fileTrashedModel.setFolderItemType(GXTFolderItemTypeEnum.FOLDER);
|
2014-05-13 11:27:30 +02:00
|
|
|
}
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
store.add(trashFiles);
|
2014-05-13 18:43:35 +02:00
|
|
|
activeButtonsOnNotEmtpy(store.getModels().size()>0);
|
|
|
|
}
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 18:43:35 +02:00
|
|
|
/**
|
|
|
|
* @param b
|
|
|
|
*/
|
|
|
|
private void activeButtonsOnNotEmtpy(boolean isNotEmpty) {
|
|
|
|
buttonRestoreAll.setEnabled(isNotEmpty);
|
|
|
|
buttonEmptyTrash.setEnabled(isNotEmpty);
|
2014-02-17 19:20:45 +01:00
|
|
|
}
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 18:43:35 +02:00
|
|
|
/**
|
|
|
|
* @param multi
|
|
|
|
*/
|
|
|
|
protected void activeButtonOnSelection(boolean bool) {
|
|
|
|
buttonDelete.setEnabled(bool);
|
|
|
|
buttonRestore.setEnabled(bool);
|
|
|
|
}
|
2014-02-17 19:20:45 +01:00
|
|
|
private void updateStore(ListStore<FileTrashedModel> 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-15 16:42:41 +02:00
|
|
|
*
|
2014-02-17 19:20:45 +01:00
|
|
|
* @param identifier
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public FileTrashedModel getFileModelByIdentifier(String identifier){
|
2016-09-15 16:42:41 +02:00
|
|
|
|
|
|
|
return store.findModel(FileGridModel.IDENTIFIER, identifier);
|
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
}
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
/**
|
2016-09-15 16:42:41 +02:00
|
|
|
*
|
2014-02-17 19:20:45 +01:00
|
|
|
* @param identifier (MANDATORY)
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean deleteItem(String identifier) {
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
FileTrashedModel fileTarget = getFileModelByIdentifier(identifier);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
if(fileTarget!=null){
|
|
|
|
return deleteItem(fileTarget);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
System.out.println("Delete Error: file target with " + identifier + " identifier not exist in store" );
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
/**
|
2016-09-15 16:42:41 +02:00
|
|
|
*
|
2014-02-17 19:20:45 +01:00
|
|
|
* @param fileTarget (MANDATORY)
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private boolean deleteItem(FileTrashedModel fileTarget) {
|
|
|
|
|
|
|
|
Record record = store.getRecord(fileTarget);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
if (record != null) {
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
FileTrashedModel item = (FileTrashedModel) record.getModel();
|
|
|
|
store.remove(item);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
System.out.println("Record Error: file target with "
|
|
|
|
+ fileTarget.getIdentifier()
|
|
|
|
+ " identifier not exist in store");
|
|
|
|
|
2014-05-13 18:43:35 +02:00
|
|
|
activeButtonsOnNotEmtpy(store.getModels().size()>0);
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
2016-09-15 16:42:41 +02:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
/**
|
2016-09-15 16:42:41 +02:00
|
|
|
*
|
2014-05-13 17:46:02 +02:00
|
|
|
* @return the number of items contained into trash
|
|
|
|
*/
|
|
|
|
public int trashSize(){
|
|
|
|
return store.getCount();
|
|
|
|
}
|
2014-02-17 19:20:45 +01:00
|
|
|
|
2014-05-16 18:11:15 +02:00
|
|
|
protected GroupingStore<FileTrashedModel> getStore() {
|
|
|
|
return store;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ContentPanel getCp() {
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
}
|