2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.client
.ui
.dist
.commands
;
18 import java
.util
.Iterator
;
20 import javax
.jcr
.Node
;
21 import javax
.jcr
.RepositoryException
;
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
;
37 * Add the {@code SlcNames.SLC_RELEVANT_CATEGORY} mixin to the selected node
39 public class MarkAsRelevantCategory
extends AbstractHandler
{
40 // private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
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");
50 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
52 IWorkbenchPart activePart
= DistPlugin
.getDefault().getWorkbench()
53 .getActiveWorkbenchWindow().getActivePage().getActivePart();
55 if (activePart
instanceof IEditorPart
) {
56 ISelection selector
= ((IEditorPart
) activePart
)
57 .getEditorSite().getSelectionProvider().getSelection();
59 && selector
instanceof IStructuredSelection
) {
60 Iterator
<?
> it
= ((IStructuredSelection
) selector
)
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(),
70 node
.removeMixin(SlcTypes
.SLC_RELEVANT_CATEGORY
);
71 node
.getSession().save();
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?";
77 if (MessageDialog
.openConfirm(DistPlugin
.getDefault()
78 .getWorkbench().getDisplay().getActiveShell(),
80 node
.addMixin(SlcTypes
.SLC_RELEVANT_CATEGORY
);
81 node
.getSession().save();
86 } catch (RepositoryException re
) {
87 throw new ArgeoException(
88 "Unexpected error while deleting artifacts.", re
);