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