diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/util/RequestBuilderWorkspaceValidateItem.java b/src/main/java/org/gcube/portlets/user/workspace/client/util/RequestBuilderWorkspaceValidateItem.java index 560459a..2376178 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/util/RequestBuilderWorkspaceValidateItem.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/util/RequestBuilderWorkspaceValidateItem.java @@ -82,10 +82,15 @@ public class RequestBuilderWorkspaceValidateItem { if(!(status==200) && !(status==202)){ //NOT IS STATUS SC_ACCEPTED + if(status==401){ // SC_UNAUTHORIZED = 401; + GWT.log("Session expired"); + AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent()); + return; + } newBrowserWindow.close(); handleError("Sorry, an error occurred on retriving the file. "+response.getText()); //ERROR STATUS - }else{ //OK STATUS + }else { //OK STATUS if(callback!=null) callback.onSuccess(new WindowOpenParameter(targetWindow, "", params, true, newBrowserWindow)); diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/TrashInfoContainer.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/TrashInfoContainer.java new file mode 100644 index 0000000..5c08b98 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/TrashInfoContainer.java @@ -0,0 +1,299 @@ +package org.gcube.portlets.user.workspace.client.view.trash; + +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.event.ButtonEvent; +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.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; +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 static final String OPERATION_NAME = "Type"; + /** + * + */ + + private Grid grid; + private ContentPanel cp; + private GroupingStore store = new GroupingStore(); + private boolean groupingEnabled; + private ListStore typeStoreOperation = new ListStore(); + private NumberFormat number = ConstantsExplorer.numberFormatterKB; + + public TrashInfoContainer() { + initContentPanel(); + initGrid(); + createToolBar(); + } + + 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.getHeader().setIconAltText("Grid Icon"); + // cp.setSize(550, 280); + add(cp); + } + + private void createToolBar() { + + ToolBar bar = new ToolBar(); + final ToggleButton buttonGrouping = new ToggleButton("",Resources.getIconGridView()); + buttonGrouping.setToolTip("Grouping by Type"); + buttonGrouping.setScale(ButtonScale.SMALL); + buttonGrouping.toggle(true); + + buttonGrouping.addSelectionListener(new SelectionListener() { + + @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 = createSortableColumnConfig(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, ownerFullName, type, category)); + + 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(FileGridModel 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(OPERATION_NAME); + } + 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; + + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/WindowTrash.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/WindowTrash.java new file mode 100644 index 0000000..350a8fd --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/WindowTrash.java @@ -0,0 +1,118 @@ +package org.gcube.portlets.user.workspace.client.view.trash; + +import java.util.List; + +import org.gcube.portlets.user.workspace.client.ConstantsExplorer; +import org.gcube.portlets.user.workspace.client.model.FileModel; + +import com.extjs.gxt.ui.client.widget.Window; +import com.extjs.gxt.ui.client.widget.layout.FitLayout; + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * @May 23, 2013 + * + * Singleton + */ +public class WindowTrash extends Window { + + private List trashedFiles; + private TrashInfoContainer trashContainers; + private static WindowTrash INSTANCE = null; + + + private WindowTrash() { + initAccounting(); +// setIcon(fileModel.getAbstractPrototypeIcon()); //TODO + setHeading("Trash"); +// addResizeListner(); + } + + /** + * + * @return + */ + public static synchronized WindowTrash getInstance(){ + if(INSTANCE==null) + INSTANCE = new WindowTrash(); + + return INSTANCE; + } + +// public void addResizeListner(){ +// +// this.addListener(Events.Resize, new Listener() { +// +// @Override +// public void handleEvent(WindowEvent we ) +// { +// +// if(trashContainers!=null){ +//// System.out.println("Size in event: " + we.getWidth() + "x" + we.getHeight() ); +//// accountingsContainers.setPanelSize(we.getWidth()-14, we.getHeight()-30); +// } +// } +// +// }); +// } + + public WindowTrash(List trashFiles) { + updateTrashContainer(trashFiles); + } + + private void initAccounting() { + setModal(true); + setLayout(new FitLayout()); + setSize(700, 350); + setResizable(true); + setMaximizable(true); +// setCollapsible(true); + this.trashContainers = new TrashInfoContainer(); + add(trashContainers); + } + + public void setWindowTitle(String title) { + this.setHeading(title); + + } + + + /** + * + * @param fileModelId + * @return + */ + public boolean deleteFileFromTrash(String fileModelId){ + return this.trashContainers.deleteItem(fileModelId); + } + + + public void updateTrashContainer(List trashFiles) { + + this.trashContainers.resetStore(); + this.trashedFiles = trashFiles; + this.trashContainers.updateTrash(trashFiles); + } + + public List getTrashedFiles() { + return trashedFiles; + } + + public void maskAccountingInfo(boolean bool){ + +// if(accountingsContainers!=null){ +// +// if(bool) +// accountingsContainers.mask(ConstantsExplorer.LOADING, ConstantsExplorer.LOADINGSTYLE); +// else +// accountingsContainers.unmask(); +// } + + if(bool) + this.mask(ConstantsExplorer.LOADING, ConstantsExplorer.LOADINGSTYLE); + else + this.unmask(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java b/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java index 90684b6..7946eff 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java @@ -98,6 +98,12 @@ public class DownloadServlet extends HttpServlet{ wa = WsUtil.getWorkspace(session); } catch (Exception e) { + + if (e instanceof SessionExpiredException){ + sendErrorForStatus(resp, HttpServletResponse.SC_UNAUTHORIZED +": Session expired", HttpServletResponse.SC_UNAUTHORIZED); + return; + } + handleError(urlRedirectOnError, req, resp, itemId, HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Error during workspace retrieving"); // sendError(resp,HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Error during workspace retrieving"); return; @@ -621,6 +627,21 @@ public class DownloadServlet extends HttpServlet{ StringReader sr = new StringReader(resultMessage.toString()); IOUtils.copy(sr, response.getOutputStream()); +// response.getWriter().write(resultMessage.toString()); + logger.trace("response writed"); + response.flushBuffer(); + } + + + protected void sendErrorForStatus(HttpServletResponse response, String message, int status) throws IOException + { + response.setStatus(status); + HandlerResultMessage resultMessage = HandlerResultMessage.errorResult(message); + logger.trace("error message: "+resultMessage); + logger.trace("writing response..."); + StringReader sr = new StringReader(resultMessage.toString()); + IOUtils.copy(sr, response.getOutputStream()); + // response.getWriter().write(resultMessage.toString()); logger.trace("response writed"); response.flushBuffer();