]> git.argeo.org Git - lgpl/argeo-commons.git/blob - commands/GetNodeSize.java
Prepare next development cycle
[lgpl/argeo-commons.git] / commands / GetNodeSize.java
1 package org.argeo.jcr.ui.explorer.commands;
2
3 import javax.jcr.Node;
4
5 import org.argeo.eclipse.ui.ErrorFeedback;
6 import org.argeo.jcr.JcrUtils;
7 import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
8 import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
9 import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
10 import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser;
11 import org.eclipse.core.commands.AbstractHandler;
12 import org.eclipse.core.commands.ExecutionEvent;
13 import org.eclipse.core.commands.ExecutionException;
14 import org.eclipse.jface.dialogs.MessageDialog;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.swt.widgets.Shell;
18 import org.eclipse.ui.handlers.HandlerUtil;
19
20 /** Opens the generic node editor. */
21 public class GetNodeSize extends AbstractHandler {
22 // private final static Log log = LogFactory.getLog(GetNodeSize.class);
23
24 public final static String ID = "org.argeo.jcr.ui.explorer.getNodeSize";
25 public final static String DEFAULT_ICON_REL_PATH = "icons/getSize.gif";
26 public final static String DEFAULT_LABEL = JcrExplorerPlugin
27 .getMessage("getNodeSizeCmdLbl");
28
29 public Object execute(ExecutionEvent event) throws ExecutionException {
30 // JcrUtils.getRepositoryByAlias(repositoryRegister,
31 // ArgeoJcrConstants.ALIAS_NODE);
32
33 ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
34 .getActivePage().getSelection();
35 GenericJcrBrowser view = (GenericJcrBrowser) HandlerUtil
36 .getActiveWorkbenchWindow(event).getActivePage()
37 .findView(HandlerUtil.getActivePartId(event));
38
39 if (selection != null && !selection.isEmpty()
40 && selection instanceof IStructuredSelection) {
41
42 // We only get
43 IStructuredSelection iss = (IStructuredSelection) selection;
44 if (iss.size() > 1)
45 ErrorFeedback.show(JcrExplorerPlugin
46 .getMessage("warningInvalidMultipleSelection"), null);
47
48 long size = 0;
49 Node node;
50 if (iss.getFirstElement() instanceof SingleJcrNode)
51 node = ((SingleJcrNode) iss.getFirstElement()).getNode();
52 else if (iss.getFirstElement() instanceof WorkspaceNode)
53 node = ((WorkspaceNode) iss.getFirstElement()).getRootNode();
54 else
55 // unvalid object type
56 return null;
57
58 size = JcrUtils.getNodeApproxSize(node);
59
60 String[] labels = { "OK" };
61 Shell shell = HandlerUtil.getActiveWorkbenchWindow(event)
62 .getShell();
63 MessageDialog md = new MessageDialog(shell, "Node size", null,
64 "Node size is: " + size / 1024 + " KB",
65 MessageDialog.INFORMATION, labels, 0);
66 md.open();
67 }
68 return null;
69 }
70 }