]>
git.argeo.org Git - gpl/argeo-slc.git/blob - legacy/argeo-commons/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/commands/GetNodeSize.java
1 package org
.argeo
.cms
.ui
.workbench
.internal
.jcr
.commands
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Iterator
;
9 import org
.argeo
.cms
.ui
.jcr
.model
.SingleJcrNodeElem
;
10 import org
.argeo
.cms
.ui
.jcr
.model
.WorkspaceElem
;
11 import org
.argeo
.cms
.ui
.workbench
.WorkbenchUiPlugin
;
12 import org
.argeo
.eclipse
.ui
.dialogs
.ErrorFeedback
;
13 import org
.argeo
.jcr
.JcrUtils
;
14 import org
.eclipse
.core
.commands
.AbstractHandler
;
15 import org
.eclipse
.core
.commands
.ExecutionEvent
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
18 import org
.eclipse
.jface
.viewers
.ISelection
;
19 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
21 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
23 /** Compute an approximative size for the selected node(s) */
24 public class GetNodeSize
extends AbstractHandler
{
25 // private final static Log log = LogFactory.getLog(GetNodeSize.class);
27 public final static String ID
= WorkbenchUiPlugin
.PLUGIN_ID
+ ".getNodeSize";
29 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
31 ISelection selection
= HandlerUtil
.getActiveWorkbenchWindow(event
)
32 .getActivePage().getSelection();
34 if (selection
!= null && !selection
.isEmpty()
35 && selection
instanceof IStructuredSelection
) {
39 Iterator
<?
> it
= ((IStructuredSelection
) selection
).iterator();
41 // TODO enhance this: as the size method is recursive, we keep track
42 // of nodes for which we already have computed size so that we don't
43 // count them twice. In a first approximation, we assume that the
44 // structure selection keep the nodes ordered.
45 List
<String
> importedPathes
= new ArrayList
<String
>();
47 nodesIt
: while (it
.hasNext()) {
48 Object obj
= it
.next();
51 if (obj
instanceof SingleJcrNodeElem
) {
52 node
= ((SingleJcrNodeElem
) obj
).getNode();
53 curPath
= node
.getSession().getWorkspace().getName();
54 curPath
+= "/" + node
.getPath();
55 } else if (obj
instanceof WorkspaceElem
) {
56 node
= ((WorkspaceElem
) obj
).getRootNode();
57 curPath
= node
.getSession().getWorkspace().getName();
59 // non valid object type
62 Iterator
<String
> itPath
= importedPathes
.iterator();
63 while (itPath
.hasNext()) {
64 String refPath
= itPath
.next();
65 if (curPath
.startsWith(refPath
))
66 // Already done : skip node
69 size
+= JcrUtils
.getNodeApproxSize(node
);
70 importedPathes
.add(curPath
);
72 } catch (Exception e
) {
73 ErrorFeedback
.show("Cannot Get size of selected node ", e
);
76 String
[] labels
= { "OK" };
77 Shell shell
= HandlerUtil
.getActiveWorkbenchWindow(event
)
79 MessageDialog md
= new MessageDialog(shell
, "Node size", null,
80 "Node size is: " + size
/ 1024 + " KB",
81 MessageDialog
.INFORMATION
, labels
, 0);