1 package eu
.etaxonomy
.taxeditor
.editor
.handler
;
3 import org
.apache
.log4j
.Logger
;
4 import org
.eclipse
.core
.commands
.AbstractHandler
;
5 import org
.eclipse
.core
.commands
.ExecutionEvent
;
6 import org
.eclipse
.core
.commands
.ExecutionException
;
7 import org
.eclipse
.jface
.viewers
.ISelection
;
8 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
9 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
11 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
12 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
13 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
14 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
15 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
16 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
18 public class FixClassificationHierarchyHandler
extends AbstractHandler
{
20 private static final Logger logger
= Logger
.getLogger(FixClassificationHierarchyHandler
.class);
26 * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
30 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
31 boolean isChecklistEditorActivated
= PreferencesUtil
.getPreferenceStore().getBoolean(
32 IPreferenceKeys
.DISTRIBUTION_AREA_PREFRENCES_ACTIVE
);
33 if (isChecklistEditorActivated
) {
34 ISelection currentSelection
= HandlerUtil
.getCurrentSelection(event
);
35 if (currentSelection
instanceof IStructuredSelection
) {
36 Object selectedElement
= ((IStructuredSelection
) currentSelection
).getFirstElement();
37 if (selectedElement
instanceof Classification
) {
39 Classification classification
= (Classification
) selectedElement
;
41 IClassificationService service
= CdmStore
.getService(IClassificationService
.class);
43 // Map<String, List<TaxonNode>> sortedGenusList =
44 // service.getSortedGenusList(classification.getAllNodes());
46 Classification newClassification
= service
.createHierarchyInClassification(classification
, null);
48 MessagingUtils
.messageDialog("Fix Hierarchy successful",
49 FixClassificationHierarchyHandler
.class, "Operation 'Fix Hierarchy' was successful. New classification is " + newClassification
.getTitleCache());
51 } catch (Exception e
) {
52 MessagingUtils
.messageDialog("Failed to open Editor", FixClassificationHierarchyHandler
.class,
53 "Could not open ChecklistView. The hierarchy is corrupted!", e
);