1 package org
.argeo
.app
.ui
.library
;
3 import static org
.argeo
.app
.ui
.library
.DocumentsUiService
.ACTION_ID_BOOKMARK_FOLDER
;
4 import static org
.argeo
.app
.ui
.library
.DocumentsUiService
.ACTION_ID_CREATE_FOLDER
;
5 import static org
.argeo
.app
.ui
.library
.DocumentsUiService
.ACTION_ID_DELETE
;
6 import static org
.argeo
.app
.ui
.library
.DocumentsUiService
.ACTION_ID_DOWNLOAD_FOLDER
;
7 import static org
.argeo
.app
.ui
.library
.DocumentsUiService
.ACTION_ID_RENAME
;
8 import static org
.argeo
.app
.ui
.library
.DocumentsUiService
.ACTION_ID_SHARE_FOLDER
;
9 import static org
.argeo
.app
.ui
.library
.DocumentsUiService
.ACTION_ID_UPLOAD_FILE
;
11 import java
.nio
.file
.Files
;
12 import java
.nio
.file
.Path
;
14 import org
.argeo
.app
.ui
.widgets
.AbstractConnectContextMenu
;
15 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
16 import org
.eclipse
.swt
.graphics
.Point
;
17 import org
.eclipse
.swt
.widgets
.Control
;
19 /** Generic popup context menu to manage NIO Path in a Viewer. */
20 public class DocumentsContextMenu
extends AbstractConnectContextMenu
{
22 private final DocumentsFolderComposite browser
;
23 private final DocumentsUiService uiService
;
24 // private final Repository repository;
26 private final static String
[] DEFAULT_ACTIONS
= { ACTION_ID_CREATE_FOLDER
, ACTION_ID_BOOKMARK_FOLDER
,
27 ACTION_ID_SHARE_FOLDER
, ACTION_ID_DOWNLOAD_FOLDER
, ACTION_ID_UPLOAD_FILE
, ACTION_ID_RENAME
,
30 private Path currFolderPath
;
32 public DocumentsContextMenu(DocumentsFolderComposite browser
,
33 DocumentsUiService documentsUiService
) {
34 super(browser
.getDisplay(), DEFAULT_ACTIONS
);
35 this.browser
= browser
;
36 this.uiService
= documentsUiService
;
37 // this.repository = repository;
42 public void setCurrFolderPath(Path currFolderPath
) {
43 this.currFolderPath
= currFolderPath
;
46 protected boolean aboutToShow(Control source
, Point location
, IStructuredSelection selection
) {
47 boolean emptySel
= true;
48 boolean multiSel
= false;
49 boolean isFolder
= true;
50 if (selection
!= null && !selection
.isEmpty()) {
52 multiSel
= selection
.size() > 1;
53 if (!multiSel
&& selection
.getFirstElement() instanceof Path
) {
54 isFolder
= Files
.isDirectory((Path
) selection
.getFirstElement());
58 setVisible(true, ACTION_ID_CREATE_FOLDER
, ACTION_ID_UPLOAD_FILE
, ACTION_ID_BOOKMARK_FOLDER
);
59 setVisible(false, ACTION_ID_SHARE_FOLDER
, ACTION_ID_DOWNLOAD_FOLDER
, ACTION_ID_RENAME
, ACTION_ID_DELETE
61 } else if (multiSel
) {
62 setVisible(true, ACTION_ID_CREATE_FOLDER
, ACTION_ID_UPLOAD_FILE
, ACTION_ID_DELETE
,
63 ACTION_ID_BOOKMARK_FOLDER
);
64 setVisible(false, ACTION_ID_SHARE_FOLDER
, ACTION_ID_DOWNLOAD_FOLDER
, ACTION_ID_RENAME
);
65 } else if (isFolder
) {
66 setVisible(true, ACTION_ID_CREATE_FOLDER
, ACTION_ID_UPLOAD_FILE
, ACTION_ID_RENAME
, ACTION_ID_DELETE
,
67 ACTION_ID_BOOKMARK_FOLDER
);
70 ACTION_ID_SHARE_FOLDER
, ACTION_ID_DOWNLOAD_FOLDER
);
72 setVisible(true, ACTION_ID_CREATE_FOLDER
, ACTION_ID_UPLOAD_FILE
, ACTION_ID_RENAME
,
74 setVisible(false, ACTION_ID_SHARE_FOLDER
, ACTION_ID_DOWNLOAD_FOLDER
, ACTION_ID_BOOKMARK_FOLDER
);
79 public void show(Control source
, Point location
, IStructuredSelection selection
, Path currFolderPath
) {
80 // TODO find a better way to retrieve the parent path (cannot be deduced
81 // from table content because it will fail on an empty folder)
82 this.currFolderPath
= currFolderPath
;
83 super.show(source
, location
, selection
);
88 protected boolean performAction(String actionId
) {
90 case ACTION_ID_CREATE_FOLDER
:
93 case ACTION_ID_BOOKMARK_FOLDER
:
96 case ACTION_ID_RENAME
:
99 case ACTION_ID_DELETE
:
102 // case ACTION_ID_OPEN:
105 case ACTION_ID_UPLOAD_FILE
:
109 throw new IllegalArgumentException("Unimplemented action " + actionId
);
110 // case ACTION_ID_SHARE_FOLDER:
111 // return "Share Folder";
112 // case ACTION_ID_DOWNLOAD_FOLDER:
113 // return "Download as zip archive";
120 protected String
getLabel(String actionId
) {
121 return uiService
.getLabel(actionId
);
124 private void openFile() {
125 IStructuredSelection selection
= ((IStructuredSelection
) browser
.getViewer().getSelection());
126 if (selection
.isEmpty() || selection
.size() > 1)
127 // Should never happen
129 Path toOpenPath
= ((Path
) selection
.getFirstElement());
130 uiService
.openFile(toOpenPath
);
133 private void deleteItems() {
134 IStructuredSelection selection
= ((IStructuredSelection
) browser
.getViewer().getSelection());
135 if (selection
.isEmpty())
137 else if (uiService
.deleteItems(getParentShell(), selection
))
141 private void renameItem() {
142 IStructuredSelection selection
= ((IStructuredSelection
) browser
.getViewer().getSelection());
143 if (selection
.isEmpty() || selection
.size() > 1)
144 // Should never happen
146 Path toRenamePath
= ((Path
) selection
.getFirstElement());
147 if (uiService
.renameItem(getParentShell(), currFolderPath
, toRenamePath
))
151 private void createFolder() {
152 if (uiService
.createFolder(getParentShell(), currFolderPath
))
156 private void bookmarkFolder() {
157 Path toBookmarkPath
= null;
158 IStructuredSelection selection
= ((IStructuredSelection
) browser
.getViewer().getSelection());
159 if (selection
.isEmpty())
160 toBookmarkPath
= currFolderPath
;
161 else if (selection
.size() > 1)
162 toBookmarkPath
= currFolderPath
;
163 else if (selection
.size() == 1) {
164 Path currSelected
= ((Path
) selection
.getFirstElement());
165 if (Files
.isDirectory(currSelected
))
166 toBookmarkPath
= currSelected
;
170 //uiService.bookmarkFolder(toBookmarkPath, repository, null);
173 private void uploadFiles() {
174 if (uiService
.uploadFiles(getParentShell(), currFolderPath
))