X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=blobdiff_plain;f=org.argeo.library.ui%2Fsrc%2Forg%2Fargeo%2Flibrary%2Fui%2FDocumentsContextMenu.java;fp=org.argeo.library.ui%2Fsrc%2Forg%2Fargeo%2Flibrary%2Fui%2FDocumentsContextMenu.java;h=0000000000000000000000000000000000000000;hp=03de2514131690415885b109bebb8a0394f4ccc5;hb=6e56ffa34cb02ab04d028423aea342e3dfed4358;hpb=c285180bece610b2c2921d44fe14b6dde2123efa diff --git a/org.argeo.library.ui/src/org/argeo/library/ui/DocumentsContextMenu.java b/org.argeo.library.ui/src/org/argeo/library/ui/DocumentsContextMenu.java deleted file mode 100644 index 03de251..0000000 --- a/org.argeo.library.ui/src/org/argeo/library/ui/DocumentsContextMenu.java +++ /dev/null @@ -1,177 +0,0 @@ -package org.argeo.library.ui; - -import static org.argeo.library.ui.DocumentsUiService.ACTION_ID_BOOKMARK_FOLDER; -import static org.argeo.library.ui.DocumentsUiService.ACTION_ID_CREATE_FOLDER; -import static org.argeo.library.ui.DocumentsUiService.ACTION_ID_DELETE; -import static org.argeo.library.ui.DocumentsUiService.ACTION_ID_DOWNLOAD_FOLDER; -import static org.argeo.library.ui.DocumentsUiService.ACTION_ID_RENAME; -import static org.argeo.library.ui.DocumentsUiService.ACTION_ID_SHARE_FOLDER; -import static org.argeo.library.ui.DocumentsUiService.ACTION_ID_UPLOAD_FILE; - -import java.nio.file.Files; -import java.nio.file.Path; - -import org.argeo.suite.ui.widgets.AbstractConnectContextMenu; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Control; - -/** Generic popup context menu to manage NIO Path in a Viewer. */ -public class DocumentsContextMenu extends AbstractConnectContextMenu { - // Local context - private final DocumentsFolderComposite browser; - private final DocumentsUiService uiService; -// private final Repository repository; - - private final static String[] DEFAULT_ACTIONS = { ACTION_ID_CREATE_FOLDER, ACTION_ID_BOOKMARK_FOLDER, - ACTION_ID_SHARE_FOLDER, ACTION_ID_DOWNLOAD_FOLDER, ACTION_ID_UPLOAD_FILE, ACTION_ID_RENAME, - ACTION_ID_DELETE }; - - private Path currFolderPath; - - public DocumentsContextMenu(DocumentsFolderComposite browser, - DocumentsUiService documentsUiService) { - super(browser.getDisplay(), DEFAULT_ACTIONS); - this.browser = browser; - this.uiService = documentsUiService; -// this.repository = repository; - - createControl(); - } - - public void setCurrFolderPath(Path currFolderPath) { - this.currFolderPath = currFolderPath; - } - - protected boolean aboutToShow(Control source, Point location, IStructuredSelection selection) { - boolean emptySel = true; - boolean multiSel = false; - boolean isFolder = true; - if (selection != null && !selection.isEmpty()) { - emptySel = false; - multiSel = selection.size() > 1; - if (!multiSel && selection.getFirstElement() instanceof Path) { - isFolder = Files.isDirectory((Path) selection.getFirstElement()); - } - } - if (emptySel) { - setVisible(true, ACTION_ID_CREATE_FOLDER, ACTION_ID_UPLOAD_FILE, ACTION_ID_BOOKMARK_FOLDER); - setVisible(false, ACTION_ID_SHARE_FOLDER, ACTION_ID_DOWNLOAD_FOLDER, ACTION_ID_RENAME, ACTION_ID_DELETE - ); - } else if (multiSel) { - setVisible(true, ACTION_ID_CREATE_FOLDER, ACTION_ID_UPLOAD_FILE, ACTION_ID_DELETE, - ACTION_ID_BOOKMARK_FOLDER); - setVisible(false, ACTION_ID_SHARE_FOLDER, ACTION_ID_DOWNLOAD_FOLDER, ACTION_ID_RENAME); - } else if (isFolder) { - setVisible(true, ACTION_ID_CREATE_FOLDER, ACTION_ID_UPLOAD_FILE, ACTION_ID_RENAME, ACTION_ID_DELETE, - ACTION_ID_BOOKMARK_FOLDER); - setVisible(false, - // to be implemented - ACTION_ID_SHARE_FOLDER, ACTION_ID_DOWNLOAD_FOLDER); - } else { - setVisible(true, ACTION_ID_CREATE_FOLDER, ACTION_ID_UPLOAD_FILE, ACTION_ID_RENAME, - ACTION_ID_DELETE); - setVisible(false, ACTION_ID_SHARE_FOLDER, ACTION_ID_DOWNLOAD_FOLDER, ACTION_ID_BOOKMARK_FOLDER); - } - return true; - } - - public void show(Control source, Point location, IStructuredSelection selection, Path currFolderPath) { - // TODO find a better way to retrieve the parent path (cannot be deduced - // from table content because it will fail on an empty folder) - this.currFolderPath = currFolderPath; - super.show(source, location, selection); - - } - - @Override - protected boolean performAction(String actionId) { - switch (actionId) { - case ACTION_ID_CREATE_FOLDER: - createFolder(); - break; - case ACTION_ID_BOOKMARK_FOLDER: - bookmarkFolder(); - break; - case ACTION_ID_RENAME: - renameItem(); - break; - case ACTION_ID_DELETE: - deleteItems(); - break; -// case ACTION_ID_OPEN: -// openFile(); -// break; - case ACTION_ID_UPLOAD_FILE: - uploadFiles(); - break; - default: - throw new IllegalArgumentException("Unimplemented action " + actionId); - // case ACTION_ID_SHARE_FOLDER: - // return "Share Folder"; - // case ACTION_ID_DOWNLOAD_FOLDER: - // return "Download as zip archive"; - } - browser.setFocus(); - return false; - } - - @Override - protected String getLabel(String actionId) { - return uiService.getLabel(actionId); - } - - private void openFile() { - IStructuredSelection selection = ((IStructuredSelection) browser.getViewer().getSelection()); - if (selection.isEmpty() || selection.size() > 1) - // Should never happen - return; - Path toOpenPath = ((Path) selection.getFirstElement()); - uiService.openFile(toOpenPath); - } - - private void deleteItems() { - IStructuredSelection selection = ((IStructuredSelection) browser.getViewer().getSelection()); - if (selection.isEmpty()) - return; - else if (uiService.deleteItems(getParentShell(), selection)) - browser.refresh(); - } - - private void renameItem() { - IStructuredSelection selection = ((IStructuredSelection) browser.getViewer().getSelection()); - if (selection.isEmpty() || selection.size() > 1) - // Should never happen - return; - Path toRenamePath = ((Path) selection.getFirstElement()); - if (uiService.renameItem(getParentShell(), currFolderPath, toRenamePath)) - browser.refresh(); - } - - private void createFolder() { - if (uiService.createFolder(getParentShell(), currFolderPath)) - browser.refresh(); - } - - private void bookmarkFolder() { - Path toBookmarkPath = null; - IStructuredSelection selection = ((IStructuredSelection) browser.getViewer().getSelection()); - if (selection.isEmpty()) - toBookmarkPath = currFolderPath; - else if (selection.size() > 1) - toBookmarkPath = currFolderPath; - else if (selection.size() == 1) { - Path currSelected = ((Path) selection.getFirstElement()); - if (Files.isDirectory(currSelected)) - toBookmarkPath = currSelected; - else - return; - } - //uiService.bookmarkFolder(toBookmarkPath, repository, null); - } - - private void uploadFiles() { - if (uiService.uploadFiles(getParentShell(), currFolderPath)) - browser.refresh(); - } -}