ref #7268 Added confirm dialog to p2 update handler + i18n
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 20 Feb 2018 14:41:30 +0000 (15:41 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 20 Feb 2018 14:41:30 +0000 (15:41 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/update/UpdateHandler.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/Messages.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/messages.properties
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/messages_de.properties

index 5cf51b0441a5924fb384553209b51f50e7f0c247..7d1ee7e0aa7b0d0130b41aaaeb6da7165a120119 100644 (file)
@@ -12,6 +12,7 @@ package eu.etaxonomy.taxeditor.handler.update;
 
 import java.net.URI;
 
+import org.apache.log4j.Logger;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
@@ -28,6 +29,8 @@ import org.eclipse.equinox.p2.operations.UpdateOperation;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.swt.widgets.Shell;
 
+import eu.etaxonomy.taxeditor.l10n.Messages;
+
 /**
  * UpdateHandler invokes the check for updates UI
  *
@@ -35,24 +38,62 @@ import org.eclipse.swt.widgets.Shell;
  */
 public class UpdateHandler {
 
+    private Logger logger = Logger.getLogger(getClass());
+
+    private UpdateOperation operation;
+
     @Execute
     public void execute(final IProvisioningAgent agent, final Shell shell, final UISynchronize sync,
             final IWorkbench workbench) {
-        Job updateJob = new Job("Update Job") {
+        Job checkUpdateJob = new Job(Messages.UpdateHandler_CHECK_UPDATE_JOB) {
             @Override
             protected IStatus run(final IProgressMonitor monitor) {
-                return checkForUpdates(agent, shell, sync, workbench, monitor);
+                return checkForUpdates(agent, shell, sync, monitor);
             }
         };
-        updateJob.schedule();
+        checkUpdateJob.schedule();
+
+
+        checkUpdateJob.addJobChangeListener(new JobChangeAdapter() {
+            @Override
+            public void done(IJobChangeEvent event) {
+                if (event.getResult().isOK()) {
+                    sync.syncExec(new Runnable() {
+
+                        @Override
+                        public void run() {
+                            if(MessageDialog.openConfirm(shell, Messages.UpdateHandler_UPDATES_FOUND_TITLE, Messages.UpdateHandler_UPDATES_FOUND_MESSAGE)){
+                                Job installUpdateJob = new Job(Messages.UpdateHandler_INSTALL_JOB) {
+                                    @Override
+                                    protected IStatus run(final IProgressMonitor monitor) {
+                                        // run installation
+                                        ProvisioningJob provisioningJob = operation.getProvisioningJob(monitor);
+
+                                        // updates cannot run from within Eclipse IDE!!!
+                                        if (provisioningJob == null) {
+                                            logger.error("Trying to update from the Eclipse IDE? This won't work!"); //$NON-NLS-1$
+                                            return Status.CANCEL_STATUS;
+                                        }
+                                        configureProvisioningJob(provisioningJob, shell, sync, workbench);
+                                        provisioningJob.schedule();
+                                        return Status.OK_STATUS;
+                                    }
+                                };
+                                installUpdateJob.schedule();
+                            }
+                        }
+                    });
+                }
+            }
+        });
     }
 
     private IStatus checkForUpdates(final IProvisioningAgent agent, final Shell shell, final UISynchronize sync,
-            final IWorkbench workbench, IProgressMonitor monitor) {
+            IProgressMonitor monitor) {
 
         // configure update operation
         final ProvisioningSession session = new ProvisioningSession(agent);
-        final UpdateOperation operation = new UpdateOperation(session);
+        operation = new UpdateOperation(session);
         configureUpdate(operation);
 
         // check for updates, this causes I/O
@@ -63,20 +104,7 @@ public class UpdateHandler {
             showMessage(shell, sync);
             return Status.CANCEL_STATUS;
         }
-
-        // run installation
-        final ProvisioningJob provisioningJob = operation.getProvisioningJob(monitor);
-
-        // updates cannot run from within Eclipse IDE!!!
-        if (provisioningJob == null) {
-            System.err.println("Trying to update from the Eclipse IDE? This won't work!");
-            return Status.CANCEL_STATUS;
-        }
-        configureProvisioningJob(provisioningJob, shell, sync, workbench);
-
-        provisioningJob.schedule();
         return Status.OK_STATUS;
-
     }
 
     private void configureProvisioningJob(ProvisioningJob provisioningJob, final Shell shell, final UISynchronize sync,
@@ -92,14 +120,13 @@ public class UpdateHandler {
 
                         @Override
                         public void run() {
-                            boolean restart = MessageDialog.openQuestion(shell, "Updates installed, restart?",
-                                    "Updates have been installed. Do you want to restart?");
+                            boolean restart = MessageDialog.openQuestion(shell, Messages.UpdateHandler_UPDATE_INSTALLED_TITLE,
+                                    Messages.UpdateHandler_UPDATE_INSTALLED_TITLE_MESSAGE);
                             if (restart) {
                                 workbench.restart();
                             }
                         }
                     });
-
                 }
                 super.done(event);
             }
@@ -108,14 +135,10 @@ public class UpdateHandler {
     }
 
     private void showMessage(final Shell parent, final UISynchronize sync) {
-        sync.syncExec(new Runnable() {
-
-            @Override
-            public void run() {
-                MessageDialog.openWarning(parent, "No update",
-                        "No updates for the current installation have been found.");
-            }
-        });
+        sync.syncExec(()->
+        MessageDialog.openWarning(parent, Messages.UpdateHandler_NO_UPDATE_TITLE,
+                        Messages.UpdateHandler_NO_UPDATE_MESSAGE)
+        );
     }
 
     private UpdateOperation configureUpdate(final UpdateOperation operation) {
index f95d6f1ed9bf06bdd3b6eee121e5411f7bbd4713..2c3c2dfc73a28cd6aa0239a1ac1d4112b579251d 100644 (file)
@@ -70,6 +70,30 @@ public class Messages extends NLS {
     public static String ChangeConnectionHandler_REALLY_CREATE_DATAMODEL;
     public static String ChangeConnectionHandler_DATASOURCE_NOT_AVAILABLE;
     public static String ChangeConnectionHandler_NOT_AVAILABLE_REASONS;
+    public static String UpdateHandler_CHECK_UPDATE_JOB;
+
+
+    public static String UpdateHandler_INSTALL_JOB;
+
+
+    public static String UpdateHandler_NO_UPDATE_MESSAGE;
+
+
+    public static String UpdateHandler_NO_UPDATE_TITLE;
+
+
+    public static String UpdateHandler_UPDATE_INSTALLED_TITLE;
+
+
+    public static String UpdateHandler_UPDATE_INSTALLED_TITLE_MESSAGE;
+
+
+    public static String UpdateHandler_UPDATES_FOUND_MESSAGE;
+
+
+    public static String UpdateHandler_UPDATES_FOUND_TITLE;
+
+
     public static String UriWithLabelElement_COULD_NOT_OPEN_BROWSER;
     public static String UriWithLabelElement_INVALID_URL;
     public static String UriWithLabelElement_OPEN_EXTERNAL_BROWSER;
index 102215f398c5290bb38ea44f408a6ec16f51b713..96b6cc09aea3d61562fae60b9df85fd9286d6d37 100644 (file)
@@ -33,6 +33,14 @@ DatabaseRepairPage_toolTip_specimen=Caches of all Derived Units und Field Units
 DatabaseRepairPage_TeamOrPerson=Persons and Teams
 DatabaseRepairPage_toolTip_teamOrPerson=Caches of all Persons and Teams are recalculated.
 
+UpdateHandler_CHECK_UPDATE_JOB=Check Update Job
+UpdateHandler_INSTALL_JOB=Install Update Job
+UpdateHandler_NO_UPDATE_MESSAGE=No updates for the current installation have been found.
+UpdateHandler_NO_UPDATE_TITLE=No updates found
+UpdateHandler_UPDATE_INSTALLED_TITLE=Updates installed
+UpdateHandler_UPDATE_INSTALLED_TITLE_MESSAGE=Updates have been installed. Do you want to restart?
+UpdateHandler_UPDATES_FOUND_MESSAGE=Do you want to install the updates now?
+UpdateHandler_UPDATES_FOUND_TITLE=Updates found
 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
@@ -197,7 +205,7 @@ ImportFromFileAndChooseVocIdWizardPage_AreaVoc=Area Vocabulary
 ImportFromFileAndChooseVocIdWizardOage_AreaVoc_toolTip=Please choose a vocabulary for the used areas.
 ExcelDistributionUpdateWizard_ConfiguratorWizard_label=Configure Excel distribution update
 AbstractImportWizard_ConfigurationLabel=Configure the Import
-TCSImportWizard_ConfiguratorWizard_label=Konfiguration des TCS Imports
+TCSImportWizard_ConfiguratorWizard_label=Configure the TCS import
 FeatureTreeEditorComposite_ADD_FEATURE=Add a feature to this feature tree.
 FeatureTreeEditorComposite_FEATURE_TREE=Feature Tree
 FeatureTreeEditorComposite_OPEN_TREE=Open Tree
index d7f1b720a494c42fc9bb8647f40f334f23497610..4515382b41785fa435b2f7593c985ea2034ac9cc 100644 (file)
@@ -33,6 +33,14 @@ DatabaseRepairPage_toolTip_specimen=Die Caches aller Derived Units und Field Uni
 DatabaseRepairPage_TeamOrPerson=Personen und Teams
 DatabaseRepairPage_toolTip_teamOrPerson=Die Caches aller Personen und Teams werden aktualisiert.
 
+UpdateHandler_CHECK_UPDATE_JOB=Check Update Job
+UpdateHandler_INSTALL_JOB=Install Update Job
+UpdateHandler_NO_UPDATE_MESSAGE=Es wurden keine Updates für diese Installation gefunden.
+UpdateHandler_NO_UPDATE_TITLE=Keine Updates vorhanden
+UpdateHandler_UPDATE_INSTALLED_TITLE=Updates installed
+UpdateHandler_UPDATE_INSTALLED_TITLE_MESSAGE=Updates wurden installiert. Wollen Sie neu starten?
+UpdateHandler_UPDATES_FOUND_MESSAGE=Wollen Sie die Updates jetzt installieren?
+UpdateHandler_UPDATES_FOUND_TITLE=Updates gefunden
 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
@@ -169,7 +177,6 @@ DatabasePreferncesPage_Is_redList=Rote Liste 2020
 DatabasePreferncesPage_Determination_only_for_field_unnits=Determinations nur für Field Units
 DatabasePreferncesPage_Show_Collecting_Areas_in_general_section=Zeige Sammelgebiete im allgemeinen Teil
 DatabasePreferncesPage_Taxon_Associations=Zeige Taxon Assoziationen eines Specimen im Details View
-DatabasePreferncesPage_Life_Form=Zeige Life-Form im Details-View von Field Units an
 
 DatabasePreferencesPage_Biocase_Provider=Biocase Provider
 DatabasePreferencesPage_details_view_configuration=Details View
@@ -191,13 +198,13 @@ DatabasePreferencesPage_Show_NameRelations=Zeige Namensrelationen
 DatabasePreferencesPage_Define_Default_NomenclaturalCode=Nomenklatorischer Standard Code
 DatabasePreferencesPage_UseLocalPreferences=Erlaube das lokale Überschreiben
 DatabasePreferencesPage_Specimen_Or_Observation=Belege und Observationen
+DatabasePreferncesPage_Life_Form=Zeige Life-Form im Details-View von Field Units an
 DatabasePreferencesPage_SetPublishFlag=Konfiguriere das Handling des Publish Flags bei neuen Taxa
 
 ImportFromFileAndChooseVocIdWizardPage_AreaVoc=Gebiets Vokabular
 ImportFromFileAndChooseVocIdWizardOage_AreaVoc_toolTip=Bitte wählen Sie ein Vokabular für die genutzten Areas aus.
 ExcelDistributionUpdateWizard_ConfiguratorWizard_label=Konfiguration des Excel Distribution Updates
 AbstractImportWizard_ConfigurationLabel=Konfiguration des Imports
-
 TCSImportWizard_ConfiguratorWizard_label=Konfiguration des TCS Imports
 FeatureTreeEditorComposite_ADD_FEATURE=Merkmal zum Merkmalsbaum hinzufügen
 FeatureTreeEditorComposite_FEATURE_TREE=Merkmalsbaum
@@ -235,7 +242,6 @@ NameDetailsViewConfiguration_useLocalSettings=Verwende die lokalen Eigenschaften
 
 SetPublishConfiguration_Publish=Setze das Publish Flag
 SetPublishConfiguration_Publish_tooltip=Wenn das Publish Flag gesetzt ist, werden die Taxa veröffentlicht, sowohl im Datenportal als auch bei Print Publikationen
-
 SetPublishConfiguration_Description_Configurator=Konfigurieren Sie, wie das Setzen des Publish Flags durchgeführt werden soll.
 SetPublishConfiguration_IncludeAcceptedTaxa=Akzeptierte Taxa
 SetPublishConfiguration_IncludeSharedtaxa=Mehrfach verwendete Taxa mit einbeziehen