commit 1183a87f45615e6ba6e2ee62d50e436620a7f765
Author: Katja Luther <k.luther@bgbm.org>
Date:   Thu Dec 8 11:31:19 2016 +0100

    ref #4766: sortindex updater integration in admin menu

diff --git a/eu.etaxonomy.taxeditor.application/OSGI-INF/l10n/plugin.properties b/eu.etaxonomy.taxeditor.application/OSGI-INF/l10n/plugin.properties
index 8110d546d..d1ad81663 100644
--- a/eu.etaxonomy.taxeditor.application/OSGI-INF/l10n/plugin.properties
+++ b/eu.etaxonomy.taxeditor.application/OSGI-INF/l10n/plugin.properties
@@ -46,6 +46,7 @@ command.label.20 = About the EDIT Platform
 command.label.21 = New
 command.label.22 = Save
 command.label.23 = Database Preferences
+command.label.24 = Database Repair Functionality
 product.name = EDIT Taxonomic Editor
 command.name = Parser Help
 command.name.0 = About the EDIT Platform
diff --git a/eu.etaxonomy.taxeditor.application/OSGI-INF/l10n/plugin_de.properties b/eu.etaxonomy.taxeditor.application/OSGI-INF/l10n/plugin_de.properties
index 0d736515a..ba37a6c3f 100644
--- a/eu.etaxonomy.taxeditor.application/OSGI-INF/l10n/plugin_de.properties
+++ b/eu.etaxonomy.taxeditor.application/OSGI-INF/l10n/plugin_de.properties
@@ -46,6 +46,7 @@ command.label.20 = \u00dcber die EDIT Platform
 command.label.21 = Neu
 command.label.22 = Speichern
 command.label.23 = Datenbank Präferenzen
+command.label.24 = Datenbank Reparatur Funktionalität
 product.name = EDIT Taxonomischer Editor
 command.name = Parser Hilfe
 command.name.0 = \u00dcber die EDIT Platform
diff --git a/eu.etaxonomy.taxeditor.application/plugin.xml b/eu.etaxonomy.taxeditor.application/plugin.xml
index a2ca946d7..d5ced8dd8 100644
--- a/eu.etaxonomy.taxeditor.application/plugin.xml
+++ b/eu.etaxonomy.taxeditor.application/plugin.xml
@@ -228,6 +228,22 @@
                </and>
             </visibleWhen>
          </command>
+         <command
+               commandId="eu.etaxonomy.taxeditor.application.DatabaseRepairFunctionality"
+               label="%command.label.24"
+               style="push">
+                <visibleWhen
+                  checkEnabled="true">
+               <and>
+                  <reference
+                        definitionId="hasROLE_PROJECT_MANAGER">
+                  </reference>
+                  <reference
+                        definitionId="isCdmStoreConnected">
+                  </reference>
+               </and>
+            </visibleWhen>
+         </command>
       </menuContribution>
       <menuContribution
             locationURI="menu:org.eclipse.ui.main.menu.help">
diff --git a/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/messages.properties b/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/messages.properties
index 93bb1a95f..36180a8d2 100644
--- a/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/messages.properties
+++ b/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/messages.properties
@@ -15,6 +15,13 @@ LanguageEditorPreferencePage_PleaseRestart=Please Restart
 LanguageEditorPreferencePage_RestartRequired=After changing the default language, a restart is required,\nin order for the new settings to take effect.
 OrderPreferencePage_NewNavigatorWindowRequired=After changing the order of the taxon nodes, closing and reopen of the taxon navigator is required.
 OrderPreferencePage_PleaseReopenNavigator=Please close and reopen the taxon navigator.
+DatabaseRepairPage_chooseParameter=Please choose the trees where the sortIndex should be recalculated.
+DatabaseRepairPage_updateTaxonNodes=Taxonomic Tree
+DatabaseRepairPage_toolTip_taxonNode=The sort indexes of the taxonomic tree will be recalculated.
+DatabaseRepairPage_PolytomousKeyNode=Polytomous Key
+DatabaseRepairPage_toolTip_polytomousKeyNode=The sort indexes of all polytomous keys are recalculated.
+DatabaseRepairPage_featureNodes=Feature Tree
+DatabaseRepairPage_toolTipFeatureNodes=The sort indexes of the feature tree will be recalculated.
 UriWithLabelElement_URL_NOT_SAVED=URI won't be saved\! 
 UriWithLabelElement_COULD_NOT_OPEN_BROWSER=Could not open external browser. URI is invalid.
 UriWithLabelElement_INVALID_URL=Invalid URI
diff --git a/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/messages_de.properties b/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/messages_de.properties
index 88ae30acd..b37f84878 100644
--- a/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/messages_de.properties
+++ b/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/messages_de.properties
@@ -14,7 +14,15 @@ LanguageEditorPreferencePage_EditorHasToRestart=Der Anwendung muss neu gestartet
 LanguageEditorPreferencePage_PleaseRestart=Bitte neu starten
 LanguageEditorPreferencePage_RestartRequired=Nach dem Wechsel der Standardsprache ist ein Neustart erforderlich.
 OrderPreferencePage_NewNavigatorWindowRequired=Nach dem Ändern der Taxon Sortierung, ist das Schließen und erneute Öffnen des Taxonnavigators erforderlich.
-OrderPreferencePage_PleaseReopenNavigator=Bitte schließen sie den Taxonnavigator und öffnen ihn erneut.
+OrderPreferencePage_PleaseReopenNavigator=Bitte schließen Sie den Taxonnavigator und öffnen ihn erneut.
+DatabaseRepairPage_chooseParameter=Bitte wählen Sie, für welche Bäume der SortIndex neu berechnet werden soll.
+DatabaseRepairPage_updateTaxonNodes=Taxonomischer Baum
+DatabaseRepairPage_toolTip_taxonNode=Die Sortier Indizes des Taxonomischen Baums werden aktualisiert.
+DatabaseRepairPage_PolytomousKeyNode=Polytome Schlüssel
+DatabaseRepairPage_toolTip_polytomousKeyNode=Die Sortier Indizes aller Polytomen Schlüssel werden aktualisiert.
+DatabaseRepairPage_featureNodes=Merkmalsbaum
+DatabaseRepairPage_toolTipFeatureNodes=Die Sortier Indizes des Merkmalsbaumes werden aktualisiert. 
+
 UriWithLabelElement_URL_NOT_SAVED=URI wird nicht gespeichert\! 
 UriWithLabelElement_COULD_NOT_OPEN_BROWSER=Externer Browser konnte nicht geöffnet werden. URI ist ung\u00FCtlig.
 UriWithLabelElement_INVALID_URL=Ung\u00FCltige URI
diff --git a/eu.etaxonomy.taxeditor.store/plugin.xml b/eu.etaxonomy.taxeditor.store/plugin.xml
index 9e449ab2a..125c8ddfe 100755
--- a/eu.etaxonomy.taxeditor.store/plugin.xml
+++ b/eu.etaxonomy.taxeditor.store/plugin.xml
@@ -822,6 +822,11 @@
             id="eu.etaxonomy.taxeditor.application.DatabaseSettings"
             name="%command.label.23">
       </command>
+      <command
+            defaultHandler="eu.etaxonomy.taxeditor.handler.OpenDatabaseRepairWizardHandler"
+            id="eu.etaxonomy.taxeditor.application.DatabaseRepairFunctionality"
+            name="%command.label.24">
+      </command>
    </extension>
    <extension
          point="org.eclipse.ui.commands">
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/Messages.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/Messages.java
index 375699278..0e499cc2b 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/Messages.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/Messages.java
@@ -18,12 +18,20 @@ import org.eclipse.osgi.util.NLS;
  */
 public class Messages extends NLS {
     private static final String BUNDLE_NAME = "OSGI-INF/l10n/messages"; //$NON-NLS-1$
+
     public static String AuthenticatedUserBar_LOGGED_IN_AS;
     public static String AuthenticatedUserBar_NOT_LOGGED_IN;
     public static String LanguageEditorPreferencePage_ChooseDefaultLanguage;
     public static String LanguageEditorPreferencePage_EditorHasToRestart;
     public static String LanguageEditorPreferencePage_PleaseRestart;
     public static String LanguageEditorPreferencePage_RestartRequired;
+    public static String DatabaseRepairPage_chooseParameter;
+    public static String DatabaseRepairPage_updateTaxonNodes;
+    public static String DatabaseRepairPage_toolTip_taxonNode;
+    public static String DatabaseRepairPage_PolytomousKeyNode;
+    public static String DatabaseRepairPage_toolTip_polytomousKeyNode;
+    public static String DatabaseRepairPage_featureNodes;
+    public static String DatabaseRepairPage_toolTipFeatureNodes;
     public static String LoginDialog_CANCEL_MESSAGE;
     public static String LoginDialog_LOGIN;
     public static String LoginDialog_PASSWORD;
@@ -118,7 +126,7 @@ public class Messages extends NLS {
 	public static String RemotingLoginDialog_STATUS_REMOTING_NOT_ACTIVATED;
 	public static String RemotingLoginDialog_STATUS_RETRIEVING;
 	public static String RemotingLoginDialog_STATUS_STARTED;
-	public static String RemotingLoginDialog_UPDATE_EDITOR;	
+	public static String RemotingLoginDialog_UPDATE_EDITOR;
 	public static String RemotingLoginDialog_COULD_NOT_STOP_SERVER;
 	public static String RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE;
 	public static String RemotingLoginDialog_ERROR_STARTING_SERVER;
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databasePreferences/wizard/DatabaseRepairPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databasePreferences/wizard/DatabaseRepairPage.java
new file mode 100755
index 000000000..99e73164f
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databasePreferences/wizard/DatabaseRepairPage.java
@@ -0,0 +1,100 @@
+/**
+* Copyright (C) 2016 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.databasePreferences.wizard;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+
+import eu.etaxonomy.cdm.io.common.SortIndexUpdaterConfigurator;
+import eu.etaxonomy.taxeditor.Messages;
+
+/**
+ * @author k.luther
+ * @date 06.12.2016
+ *
+ */
+public class DatabaseRepairPage extends WizardPage {
+
+    SortIndexUpdaterConfigurator config = null;
+    /**
+     * @param pageName
+     */
+    protected DatabaseRepairPage(String pageName, SortIndexUpdaterConfigurator config){
+        super(pageName);
+        this.config = config;
+        setMessage(Messages.DatabaseRepairPage_chooseParameter);
+    }
+
+
+
+
+
+
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void createControl(Composite parent) {
+        final Composite composite = new Composite(parent, SWT.NULL);
+
+        GridLayout gridLayout = new GridLayout();
+        composite.setLayout(gridLayout);
+
+        Button checkBoxTaxonNode = new Button(composite, SWT.CHECK);
+        checkBoxTaxonNode.setSelection(config.isDoTaxonNode());
+        checkBoxTaxonNode.setText(Messages.DatabaseRepairPage_updateTaxonNodes);
+        checkBoxTaxonNode
+                .setToolTipText(Messages.DatabaseRepairPage_toolTip_taxonNode);
+        checkBoxTaxonNode.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                config.setDoTaxonNode(!config.isDoTaxonNode());
+            }
+        });
+
+        Button checkBoxPolytomousKeyNode = new Button(composite, SWT.CHECK);
+        checkBoxPolytomousKeyNode.setSelection(config.isDoPolytomousKeyNode());
+        checkBoxPolytomousKeyNode.setText(Messages.DatabaseRepairPage_PolytomousKeyNode);
+        checkBoxPolytomousKeyNode
+        .setToolTipText(Messages.DatabaseRepairPage_toolTip_polytomousKeyNode);
+        checkBoxPolytomousKeyNode.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                config.setDoPolytomousKeyNode(!config.isDoPolytomousKeyNode());
+            }
+        });
+
+        Button checkBoxFeatureNode = new Button(composite, SWT.CHECK);
+        checkBoxFeatureNode.setSelection(config.isDoFeatureNode());
+        checkBoxFeatureNode.setText(Messages.DatabaseRepairPage_featureNodes);
+        checkBoxFeatureNode
+        .setToolTipText(Messages.DatabaseRepairPage_toolTipFeatureNodes);
+        checkBoxFeatureNode.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                config.setDoFeatureNode(!config.isDoFeatureNode());
+            }
+        });
+
+
+
+        setControl(composite);
+
+    }
+
+
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databasePreferences/wizard/DatabaseRepairWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databasePreferences/wizard/DatabaseRepairWizard.java
new file mode 100755
index 000000000..cd9c39e9b
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databasePreferences/wizard/DatabaseRepairWizard.java
@@ -0,0 +1,60 @@
+/**
+* Copyright (C) 2016 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.databasePreferences.wizard;
+
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.wizard.Wizard;
+
+import eu.etaxonomy.cdm.config.ICdmSource;
+import eu.etaxonomy.cdm.io.common.SortIndexUpdaterConfigurator;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author k.luther
+ * @date 06.12.2016
+ *
+ */
+public class DatabaseRepairWizard extends Wizard {
+    private final DatabaseRepairPage repairPage;
+    SortIndexUpdaterConfigurator config;
+
+    public DatabaseRepairWizard() {
+        setWindowTitle("Database Repair Wizard");
+        config = SortIndexUpdaterConfigurator.NewInstance(null);
+        repairPage = new DatabaseRepairPage("Database Repair",config);
+
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean performFinish() {
+        if (repairPage.isPageComplete()){
+            if (config == null){
+                ICdmSource source= CdmStore.getActiveCdmSource();
+                config = SortIndexUpdaterConfigurator.NewInstance(null);
+                config.setDoFeatureNode(false);
+                config.setDoPolytomousKeyNode(false);
+
+             }
+             Job updateJob = CdmStore.getImportManager().createIOServiceJob(config);
+
+             CdmStore.getImportManager().run(updateJob);
+        }
+        return true;
+    }
+
+    @Override
+    public void addPages() {
+        addPage(repairPage);
+    }
+
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenDatabaseRepairWizardHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenDatabaseRepairWizardHandler.java
new file mode 100755
index 000000000..7c619b511
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenDatabaseRepairWizardHandler.java
@@ -0,0 +1,44 @@
+/**
+* Copyright (C) 2016 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.wizard.WizardDialog;
+
+import eu.etaxonomy.taxeditor.databasePreferences.wizard.DatabaseRepairWizard;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
+
+
+
+/**
+ * @author k.luther
+ * @date 06.12.2016
+ *
+ */
+public class OpenDatabaseRepairWizardHandler extends AbstractHandler {
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        DatabaseRepairWizard databaseRepairWizard = new DatabaseRepairWizard();
+        WizardDialog dialog = new WizardDialog(StoreUtil.getShell(),
+                databaseRepairWizard);
+
+        dialog.open();
+
+        return null;
+    }
+
+
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ImportManager.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ImportManager.java
index 539db22f7..6e6b00bb3 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ImportManager.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ImportManager.java
@@ -12,12 +12,10 @@ package eu.etaxonomy.taxeditor.io;
 
 import java.io.File;
 import java.io.InputStream;
-import java.net.URI;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.List;
-import java.util.Set;
 import java.util.UUID;
 
 import org.apache.commons.io.IOUtils;
@@ -36,13 +34,13 @@ import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
 import eu.etaxonomy.cdm.io.common.IImportConfigurator;
 import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
 import eu.etaxonomy.cdm.io.common.ImportResult;
+import eu.etaxonomy.cdm.io.common.SortIndexUpdaterConfigurator;
 import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator;
 import eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator;
 import eu.etaxonomy.cdm.io.jaxb.JaxbImportConfigurator;
 import eu.etaxonomy.cdm.io.reference.endnote.in.EndnoteImportConfigurator;
 import eu.etaxonomy.cdm.io.sdd.in.SDDImportConfigurator;
 import eu.etaxonomy.cdm.io.service.IIOService;
-import eu.etaxonomy.cdm.io.specimen.SpecimenImportConfiguratorBase;
 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportState;
 import eu.etaxonomy.cdm.io.specimen.excel.in.SpecimenCdmExcelImportConfigurator;
@@ -395,7 +393,7 @@ public class ImportManager extends AbstractIOManager<IImportConfigurator> implem
 	public SpecimenCdmExcelImportConfigurator SpecimenCdmExcelImportConfigurator() {
 		return (SpecimenCdmExcelImportConfigurator) getConfigurator(TYPE.SpecimenCdmExcel);
 	}
-	
+
 	public DwcaImportConfigurator DwcaImportConfigurator() {
 		return (DwcaImportConfigurator) getConfigurator(TYPE.Gbif);
 	}
@@ -444,7 +442,7 @@ public class ImportManager extends AbstractIOManager<IImportConfigurator> implem
 	        return job;
 
 	}
-	
+
 	public Job createIOServiceJob(final Abcd206ImportConfigurator<Abcd206ImportState, InputStream> configurator) {
 		 Assert.isNotNull(configurator, "Configuration may not be null");
 	        final Display display = Display.getDefault();
@@ -503,7 +501,38 @@ public class ImportManager extends AbstractIOManager<IImportConfigurator> implem
 	        return job;
 	}
 
-	
+    public Job createIOServiceJob(final SortIndexUpdaterConfigurator configurator) {
+        Assert.isNotNull(configurator, "Configuration may not be null");
+        final Display display = Display.getDefault();
+        Job job = new Job("Update: " + configurator.getClass().getSimpleName()) {
+
+            @Override
+            protected IStatus run(IProgressMonitor monitor) {
+                monitor.beginTask("Updating data", IProgressMonitor.UNKNOWN);
+                IIOService ioService = CdmApplicationState.getIOService();
+
+                ioService.updateSortIndex(configurator);
+
+                monitor.done();
+
+                display.asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        CdmStore.getContextManager().notifyContextRefresh();
+                    }
+                });
+
+                return Status.OK_STATUS;
+            }
+        };
+
+        return job;
+
+    }
+
+
+
 
 
 }
