+package eu.etaxonomy.taxeditor.editor.handler;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+public class FixClassificationHierarchyHandler extends AbstractHandler {
+
+ private static final Logger logger = Logger.getLogger(FixClassificationHierarchyHandler.class);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
+ * ExecutionEvent)
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ boolean isChecklistEditorActivated = PreferencesUtil.getPreferenceStore().getBoolean(
+ IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE);
+ if (isChecklistEditorActivated) {
+ ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+ if (currentSelection instanceof IStructuredSelection) {
+ Object selectedElement = ((IStructuredSelection) currentSelection).getFirstElement();
+ if (selectedElement instanceof Classification) {
+
+ Classification classification = (Classification) selectedElement;
+ try {
+ IClassificationService service = CdmStore.getService(IClassificationService.class);
+
+ // Map<String, List<TaxonNode>> sortedGenusList =
+ // service.getSortedGenusList(classification.getAllNodes());
+
+ Classification newClassification = service.createHierarchyInClassification(classification, null);
+
+ MessagingUtils.messageDialog("Fix Hierarchy successful",
+ FixClassificationHierarchyHandler.class, "Operation 'Fix Hierarchy' was successful. New classification is " + newClassification.getTitleCache());
+
+ } catch (Exception e) {
+ MessagingUtils.messageDialog("Failed to open Editor", FixClassificationHierarchyHandler.class,
+ "Could not open ChecklistView. The hierarchy is corrupted!", e);
+ }
+ }
+ }
+ }
+ return null;
+ }
+}