]> git.argeo.org Git - gpl/argeo-slc.git/blob - cms/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/commands/UnregisterRemoteRepo.java
Adapt to changes in Argeo Commons.
[gpl/argeo-slc.git] / cms / org.argeo.slc.client.ui.dist / src / org / argeo / slc / client / ui / dist / commands / UnregisterRemoteRepo.java
1 package org.argeo.slc.client.ui.dist.commands;
2
3 import javax.jcr.Node;
4 import javax.jcr.Property;
5 import javax.jcr.Repository;
6 import javax.jcr.RepositoryException;
7 import javax.jcr.Session;
8
9 import org.argeo.api.NodeConstants;
10 import org.argeo.cms.ArgeoTypes;
11 import org.argeo.cms.ui.workbench.util.CommandUtils;
12 import org.argeo.jcr.JcrUtils;
13 import org.argeo.slc.SlcException;
14 import org.argeo.slc.client.ui.dist.DistPlugin;
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.MessageDialog;
19 import org.eclipse.jface.resource.ImageDescriptor;
20
21 /**
22 * Un-register a remote repository by deleting the corresponding RepoNode from
23 * the node Repository. It does not affect the repository instance
24 */
25 public class UnregisterRemoteRepo extends AbstractHandler {
26 // private static final Log log = LogFactory
27 // .getLog(UnregisterRemoteRepo.class);
28
29 public final static String ID = DistPlugin.PLUGIN_ID + ".unregisterRemoteRepo";
30 public final static String DEFAULT_LABEL = "Unregister";
31 public final static ImageDescriptor DEFAULT_ICON = DistPlugin.getImageDescriptor("icons/removeItem.gif");
32
33 public final static String PARAM_REPO_PATH = DistPlugin.PLUGIN_ID + ".repoNodePath";
34
35 // DEPENCY INJECTION
36 private Repository nodeRepository;
37
38 public Object execute(ExecutionEvent event) throws ExecutionException {
39 Session session = null;
40 String repoPath = event.getParameter(PARAM_REPO_PATH);
41 if (repoPath == null)
42 return null;
43
44 try {
45 session = nodeRepository.login(NodeConstants.HOME_WORKSPACE);
46 Node rNode = session.getNode(repoPath);
47 if (rNode.isNodeType(ArgeoTypes.ARGEO_REMOTE_REPOSITORY)) {
48
49 String alias = rNode.getProperty(Property.JCR_TITLE).getString();
50 String msg = "Your are about to unregister remote repository: " + alias + "\n"
51 + "Are you sure you want to proceed ?";
52
53 boolean result = MessageDialog.openConfirm(
54 DistPlugin.getDefault().getWorkbench().getDisplay().getActiveShell(), "Confirm Delete", msg);
55
56 if (result) {
57 rNode.remove();
58 session.save();
59 }
60 CommandUtils.callCommand(RefreshDistributionsView.ID);
61 }
62 } catch (RepositoryException e) {
63 throw new SlcException("Unexpected error while unregistering remote repository.", e);
64 } finally {
65 JcrUtils.logoutQuietly(session);
66 }
67 return null;
68 }
69
70 // DEPENCY INJECTION
71 public void setNodeRepository(Repository nodeRepository) {
72 this.nodeRepository = nodeRepository;
73 }
74 }