]> 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
Do not clean OSGi runtime
[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.wizard.WizardDialog;
21 import org.eclipse.ui.handlers.HandlerUtil;
22
23 /** Wraps a {@link RepoSync} as an Eclipse command. */
24 public class Fetch extends AbstractHandler {
25 // private final static Log log = LogFactory.getLog(Fetch.class);
26
27 public final static String ID = DistPlugin.ID + ".fetch";
28 public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
29 public final static String DEFAULT_LABEL = "Fetch...";
30 public final static String DEFAULT_ICON_PATH = "icons/fetchRepo.png";
31
32 // DEPENDENCY INJECTION
33 private Keyring keyring;
34 private RepositoryFactory repositoryFactory;
35 private Repository nodeRepository;
36
37 public Object execute(ExecutionEvent event) throws ExecutionException {
38 Session currSession = null;
39 try {
40 // Target Repository
41 String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
42 currSession = nodeRepository.login();
43 Node targetRepoNode = currSession.getNode(targetRepoPath);
44
45 FetchWizard wizard = new FetchWizard(keyring, repositoryFactory,
46 nodeRepository);
47 wizard.setTargetRepoNode(targetRepoNode);
48 WizardDialog dialog = new WizardDialog(
49 HandlerUtil.getActiveShell(event), wizard);
50
51 int result = dialog.open();
52 if (result == Dialog.OK)
53 CommandHelpers.callCommand(RefreshDistributionsView.ID);
54 return null;
55 } catch (RepositoryException e) {
56 throw new SlcException("Unexpected error while fetching data", e);
57 } finally {
58 JcrUtils.logoutQuietly(currSession);
59 }
60 }
61
62 // DEPENDENCY INJECTION
63 public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
64 this.repositoryFactory = repositoryFactory;
65 }
66
67 public void setKeyring(Keyring keyring) {
68 this.keyring = keyring;
69 }
70
71 public void setNodeRepository(Repository repository) {
72 this.nodeRepository = repository;
73 }
74 }