]> 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/UnregisterRemoteRepo.java
Fixed RPMs.
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / commands / UnregisterRemoteRepo.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
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.slc.client.ui.dist.commands;
17
18 import javax.jcr.Node;
19 import javax.jcr.Property;
20 import javax.jcr.Repository;
21 import javax.jcr.RepositoryException;
22 import javax.jcr.Session;
23
24 import org.argeo.jcr.ArgeoTypes;
25 import org.argeo.jcr.JcrUtils;
26 import org.argeo.slc.SlcException;
27 import org.argeo.slc.client.ui.dist.DistPlugin;
28 import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
29 import org.eclipse.core.commands.AbstractHandler;
30 import org.eclipse.core.commands.ExecutionEvent;
31 import org.eclipse.core.commands.ExecutionException;
32 import org.eclipse.jface.dialogs.MessageDialog;
33
34 /**
35 * Unregisters a remote repository by deleting the corresponding RepoNode from
36 * the NodeRepository. It does not affect the repository instance
37 */
38
39 public class UnregisterRemoteRepo extends AbstractHandler {
40 // private static final Log log = LogFactory
41 // .getLog(UnregisterRemoteRepo.class);
42 public final static String ID = DistPlugin.ID + ".unregisterRemoteRepo";
43 public final static String DEFAULT_LABEL = "Unregister this repository";
44 public final static String DEFAULT_ICON_PATH = "icons/removeItem.gif";
45 public final static String PARAM_REPO_PATH = DistPlugin.ID
46 + ".repoNodePath";
47
48 // DEPENCY INJECTION
49 private Repository nodeRepository;
50
51 public Object execute(ExecutionEvent event) throws ExecutionException {
52 Session session = null;
53 String repoPath = event.getParameter(PARAM_REPO_PATH);
54 if (repoPath == null)
55 return null;
56
57 try {
58 session = nodeRepository.login();
59 Node rNode = session.getNode(repoPath);
60 if (rNode.isNodeType(ArgeoTypes.ARGEO_REMOTE_REPOSITORY)) {
61
62 String alias = rNode.getProperty(Property.JCR_TITLE)
63 .getString();
64 String msg = "Your are about to unregister remote repository: "
65 + alias + "\n" + "Are you sure you want to proceed ?";
66
67 boolean result = MessageDialog.openConfirm(DistPlugin
68 .getDefault().getWorkbench().getDisplay()
69 .getActiveShell(), "Confirm Delete", msg);
70
71 if (result) {
72 rNode.remove();
73 session.save();
74 }
75 CommandHelpers.callCommand(RefreshDistributionsView.ID);
76 }
77
78 // } catch (Exception e) {
79 } catch (RepositoryException e) {
80 throw new SlcException(
81 "Unexpected error while deleting artifacts.", e);
82 } finally {
83 JcrUtils.logoutQuietly(session);
84 }
85 return null;
86 }
87
88 // DEPENCY INJECTION
89 public void setNodeRepository(Repository nodeRepository) {
90 this.nodeRepository = nodeRepository;
91 }
92 }