]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/Fetch.java
Fix some glitches in the normalization
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / commands / Fetch.java
1 package org.argeo.slc.client.ui.dist.commands;
2
3 import javax.jcr.Node;
4 import javax.jcr.Repository;
5 import javax.jcr.RepositoryException;
6 import javax.jcr.RepositoryFactory;
7 import javax.jcr.Session;
8
9 import org.argeo.jcr.JcrUtils;
10 import org.argeo.slc.SlcException;
11 import org.argeo.slc.client.ui.dist.DistPlugin;
12 import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
13 import org.argeo.slc.client.ui.dist.wizards.FetchWizard;
14 import org.argeo.slc.repo.RepoSync;
15 import org.argeo.util.security.Keyring;
16 import org.eclipse.core.commands.AbstractHandler;
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.jface.dialogs.Dialog;
20 import org.eclipse.jface.resource.ImageDescriptor;
21 import org.eclipse.jface.wizard.WizardDialog;
22 import org.eclipse.ui.handlers.HandlerUtil;
23
24 /**
25 * Wrap a {@link RepoSync} as an Eclipse command. Open a wizard that enable
26 * definition of the fetch process parameters
27 */
28 public class Fetch extends AbstractHandler {
29 // private final static Log log = LogFactory.getLog(Fetch.class);
30
31 public final static String ID = DistPlugin.ID + ".fetch";
32 public final static String DEFAULT_LABEL = "Fetch...";
33 public final static ImageDescriptor DEFAULT_ICON = DistPlugin
34 .getImageDescriptor("icons/fetchRepo.png");
35
36 public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
37
38 // DEPENDENCY INJECTION
39 private Keyring keyring;
40 private RepositoryFactory repositoryFactory;
41 private Repository nodeRepository;
42
43 public Object execute(ExecutionEvent event) throws ExecutionException {
44
45 Session currSession = null;
46 try {
47 // Target Repository
48 String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
49 currSession = nodeRepository.login();
50 Node targetRepoNode = currSession.getNode(targetRepoPath);
51
52 FetchWizard wizard = new FetchWizard(keyring, repositoryFactory,
53 nodeRepository);
54 wizard.setTargetRepoNode(targetRepoNode);
55 WizardDialog dialog = new WizardDialog(
56 HandlerUtil.getActiveShell(event), wizard);
57
58 int result = dialog.open();
59 if (result == Dialog.OK)
60 CommandHelpers.callCommand(RefreshDistributionsView.ID);
61 return null;
62 } catch (RepositoryException e) {
63 throw new SlcException("Unable te retrieve repo node from path", e);
64 } finally {
65 JcrUtils.logoutQuietly(currSession);
66 }
67 }
68
69 // DEPENDENCY INJECTION
70 public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
71 this.repositoryFactory = repositoryFactory;
72 }
73
74 public void setKeyring(Keyring keyring) {
75 this.keyring = keyring;
76 }
77
78 public void setNodeRepository(Repository repository) {
79 this.nodeRepository = repository;
80 }
81 }