Fix Ticket #4729
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / handler / FixClassificationHierarchyHandler.java
1 package eu.etaxonomy.taxeditor.navigation.navigator.handler;
2
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;
10
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.store.CdmStore;
15
16 public class FixClassificationHierarchyHandler extends AbstractHandler {
17
18 private static final Logger logger = Logger.getLogger(FixClassificationHierarchyHandler.class);
19
20 /*
21 * (non-Javadoc)
22 *
23 * @see
24 * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
25 * ExecutionEvent)
26 */
27 @Override
28 public Object execute(ExecutionEvent event) throws ExecutionException {
29 ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
30 if (currentSelection instanceof IStructuredSelection) {
31 Object selectedElement = ((IStructuredSelection) currentSelection).getFirstElement();
32 if (selectedElement instanceof Classification) {
33
34 Classification classification = (Classification) selectedElement;
35 try {
36 IClassificationService service = CdmStore.getService(IClassificationService.class);
37
38 // Map<String, List<TaxonNode>> sortedGenusList =
39 // service.getSortedGenusList(classification.getAllNodes());
40
41 Classification newClassification = service.createHierarchyInClassification(classification, null);
42
43 MessagingUtils.messageDialog("Fix Hierarchy successful",
44 FixClassificationHierarchyHandler.class, "Operation 'Fix Hierarchy' was successful. New classification is " + newClassification.getTitleCache());
45
46 } catch (Exception e) {
47 MessagingUtils.messageDialog("Failed to open Editor", FixClassificationHierarchyHandler.class,
48 "Could not open ChecklistView. The hierarchy is corrupted!", e);
49 }
50 }
51 }
52 return null;
53 }
54 }