]> git.argeo.org Git - lgpl/argeo-commons.git/blob - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/ImportFileSystem.java
fix bug 85 : JCR explorer refresh was not implemented for TreeParent objects of type...
[lgpl/argeo-commons.git] / server / plugins / org.argeo.jcr.ui.explorer / src / main / java / org / argeo / jcr / ui / explorer / commands / ImportFileSystem.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.jcr.ui.explorer.commands;
17
18 import javax.jcr.Node;
19
20 import org.argeo.eclipse.ui.ErrorFeedback;
21 import org.argeo.eclipse.ui.TreeParent;
22 import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
23 import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
24 import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
25 import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser;
26 import org.argeo.jcr.ui.explorer.wizards.ImportFileSystemWizard;
27 import org.eclipse.core.commands.AbstractHandler;
28 import org.eclipse.core.commands.ExecutionEvent;
29 import org.eclipse.core.commands.ExecutionException;
30 import org.eclipse.jface.viewers.ISelection;
31 import org.eclipse.jface.viewers.IStructuredSelection;
32 import org.eclipse.jface.wizard.WizardDialog;
33 import org.eclipse.ui.handlers.HandlerUtil;
34
35 /** Import a local file system directory tree. */
36 public class ImportFileSystem extends AbstractHandler {
37 public Object execute(ExecutionEvent event) throws ExecutionException {
38 ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
39 .getActivePage().getSelection();
40 GenericJcrBrowser view = (GenericJcrBrowser) HandlerUtil
41 .getActiveWorkbenchWindow(event).getActivePage()
42 .findView(HandlerUtil.getActivePartId(event));
43 if (selection != null && !selection.isEmpty()
44 && selection instanceof IStructuredSelection) {
45 Object obj = ((IStructuredSelection) selection).getFirstElement();
46 try {
47 Node folder = null;
48 if (obj instanceof SingleJcrNode) {
49 folder = ((SingleJcrNode) obj).getNode();
50 } else if (obj instanceof WorkspaceNode) {
51 folder = ((WorkspaceNode) obj).getRootNode();
52 } else {
53 ErrorFeedback.show(JcrExplorerPlugin
54 .getMessage("warningInvalidNodeToImport"));
55 }
56 if (folder != null) {
57 ImportFileSystemWizard wizard = new ImportFileSystemWizard(
58 folder);
59 WizardDialog dialog = new WizardDialog(
60 HandlerUtil.getActiveShell(event), wizard);
61 dialog.open();
62 view.nodeAdded((TreeParent) obj);
63 }
64 } catch (Exception e) {
65 ErrorFeedback.show("Cannot import files to " + obj, e);
66 }
67 }
68 return null;
69 }
70 }