]> 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/MarkAsRelevantCategory.java
Clean session management.
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / commands / MarkAsRelevantCategory.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 java.util.Iterator;
19
20 import javax.jcr.Node;
21 import javax.jcr.RepositoryException;
22
23 import org.argeo.ArgeoException;
24 import org.argeo.slc.client.ui.dist.DistPlugin;
25 import org.argeo.slc.jcr.SlcTypes;
26 import org.eclipse.core.commands.AbstractHandler;
27 import org.eclipse.core.commands.ExecutionEvent;
28 import org.eclipse.core.commands.ExecutionException;
29 import org.eclipse.jface.dialogs.MessageDialog;
30 import org.eclipse.jface.resource.ImageDescriptor;
31 import org.eclipse.jface.viewers.ISelection;
32 import org.eclipse.jface.viewers.IStructuredSelection;
33 import org.eclipse.ui.IEditorPart;
34 import org.eclipse.ui.IWorkbenchPart;
35
36 /**
37 * Add the {@code SlcNames.SLC_RELEVANT_CATEGORY} mixin to the selected node
38 */
39 public class MarkAsRelevantCategory extends AbstractHandler {
40 // private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
41
42 public final static String ID = DistPlugin.ID + ".markAsRelevantCategory";
43 public final static String DEFAULT_LABEL = "Mark as relevant category base";
44 public final static String DEFAULT_REMOVE_LABEL = "Remove this category from relevant list";
45 public final static ImageDescriptor DEFAULT_ICON = DistPlugin
46 .getImageDescriptor("icons/addItem.gif");
47 public final static ImageDescriptor DEFAULT_REMOVE_ICON = DistPlugin
48 .getImageDescriptor("icons/removeMark.gif");
49
50 public Object execute(ExecutionEvent event) throws ExecutionException {
51 try {
52 IWorkbenchPart activePart = DistPlugin.getDefault().getWorkbench()
53 .getActiveWorkbenchWindow().getActivePage().getActivePart();
54
55 if (activePart instanceof IEditorPart) {
56 ISelection selector = ((IEditorPart) activePart)
57 .getEditorSite().getSelectionProvider().getSelection();
58 if (selector != null
59 && selector instanceof IStructuredSelection) {
60 Iterator<?> it = ((IStructuredSelection) selector)
61 .iterator();
62
63 Node node = (Node) it.next();
64 if (node.isNodeType(SlcTypes.SLC_RELEVANT_CATEGORY)) {
65 String msg = "Your are about to unlist this category from the relevant category list for current workspace"
66 + ".\n" + "Are you sure you want to proceed?";
67 if (MessageDialog.openConfirm(DistPlugin.getDefault()
68 .getWorkbench().getDisplay().getActiveShell(),
69 "Confirm", msg)) {
70 node.removeMixin(SlcTypes.SLC_RELEVANT_CATEGORY);
71 node.getSession().save();
72 }
73 } else {
74 String msg = "Your are about to mark this group as category base in the current workspace"
75 + ".\n" + "Are you sure you want to proceed?";
76
77 if (MessageDialog.openConfirm(DistPlugin.getDefault()
78 .getWorkbench().getDisplay().getActiveShell(),
79 "Confirm", msg)) {
80 node.addMixin(SlcTypes.SLC_RELEVANT_CATEGORY);
81 node.getSession().save();
82 }
83 }
84 }
85 }
86 } catch (RepositoryException re) {
87 throw new ArgeoException(
88 "Unexpected error while deleting artifacts.", re);
89 }
90 return null;
91 }
92 }