]> git.argeo.org Git - lgpl/argeo-commons.git/blob - eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/commands/ImportFileSystem.java
+ Introduce an Abstract JCR View to enable specific view with the same commands
[lgpl/argeo-commons.git] / eclipse / runtime / org.argeo.eclipse.ui.jcr / src / main / java / org / argeo / eclipse / ui / jcr / commands / ImportFileSystem.java
1 package org.argeo.eclipse.ui.jcr.commands;
2
3 import javax.jcr.Node;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.argeo.eclipse.ui.dialogs.Error;
8 import org.argeo.eclipse.ui.jcr.views.AbstractJcrBrowser;
9 import org.argeo.eclipse.ui.jcr.wizards.ImportFileSystemWizard;
10 import org.eclipse.core.commands.AbstractHandler;
11 import org.eclipse.core.commands.ExecutionEvent;
12 import org.eclipse.core.commands.ExecutionException;
13 import org.eclipse.jface.viewers.ISelection;
14 import org.eclipse.jface.viewers.IStructuredSelection;
15 import org.eclipse.jface.wizard.WizardDialog;
16 import org.eclipse.ui.handlers.HandlerUtil;
17
18 public class ImportFileSystem extends AbstractHandler {
19 private static Log log = LogFactory.getLog(ImportFileSystem.class);
20
21 public Object execute(ExecutionEvent event) throws ExecutionException {
22 ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
23 .getActivePage().getSelection();
24 AbstractJcrBrowser view = (AbstractJcrBrowser) HandlerUtil
25 .getActiveWorkbenchWindow(event).getActivePage()
26 .findView(HandlerUtil.getActivePartId(event));
27 if (selection != null && !selection.isEmpty()
28 && selection instanceof IStructuredSelection) {
29 Object obj = ((IStructuredSelection) selection).getFirstElement();
30 try {
31 if (obj instanceof Node) {
32 Node folder = (Node) obj;
33 // if (!folder.getPrimaryNodeType().getName()
34 // .equals(NodeType.NT_FOLDER)) {
35 // Error.show("Can only import to a folder node");
36 // return null;
37 // }
38 ImportFileSystemWizard wizard = new ImportFileSystemWizard(
39 folder);
40 WizardDialog dialog = new WizardDialog(
41 HandlerUtil.getActiveShell(event), wizard);
42 dialog.open();
43 view.refresh(folder);
44 } else {
45 Error.show("Can only import to a node");
46 }
47 } catch (Exception e) {
48 Error.show("Cannot import files to " + obj, e);
49 }
50 }
51 return null;
52 }
53
54 }