]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Handler.java
Externalize strings in org.simantics.db.procore.ui
[simantics/platform.git] / bundles / org.simantics.db.procore.ui / src / org / simantics / db / procore / ui / internal / Handler.java
index 252bf2370d711fd0fdd408a19874861656f0fd39..3dd9e4d73fbe65fd8d81ec342be7ff29b18d8434 100644 (file)
@@ -10,6 +10,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.simantics.db.common.utils.Logger;
@@ -17,11 +18,11 @@ import org.simantics.db.server.Auxiliary;
 import org.simantics.db.server.ProCoreException;
 
 abstract class Handler {
-    protected final String title = "Database Server";
+    protected final String title = Messages.Handler_DatabaseServer;
     abstract boolean start(Shell shell, ProCoreException e) throws ProCoreException;
     protected void checkFolderGiven(Shell shell, ProCoreException e) throws ProCoreException {
         if (null == e.getDbFolder()) {
-            String msg = "No database folder given.";
+            String msg = Messages.Handler_NoDatabaseFolderGiven;
             MessageDialog.openWarning(shell, title, msg);
             throw new ProCoreException(msg);
         }
@@ -82,18 +83,18 @@ final class DatabaseVersionHandler extends Handler {
     }
 }
 class HandlerUtil {
-    private static String NL = System.getProperty("line.separator");
+    private static String NL = System.getProperty("line.separator"); //$NON-NLS-1$
     private static boolean isFolder(final Shell shell, final File dbFolder, String title) {
         if (dbFolder.isDirectory())
             return true;
-        MessageDialog.openWarning(shell, title, "Database folder does not exist. folder=" + dbFolder);
+        MessageDialog.openWarning(shell, title, Messages.Handler_WarningMsgDatabaseFolderNotExists + dbFolder);
         return false;
     }
     public static boolean saveWithQuestion(final Shell shell, final File dbFolder, String title, String msg) {
         if (!isFolder(shell, dbFolder, title))
             return false; // Save not possible.
-        String question = ((null != msg) ? (msg + NL) : "")
-        + "Do you want to save database?" + NL + "folder=" + dbFolder;
+        String question = NLS.bind(Messages.Handler_SaveDatabase,new Object[] {((null != msg) ? (msg + NL) : ""),  //$NON-NLS-1$
+        NL , dbFolder}); 
         boolean yes = MessageDialog.openQuestion(shell, title, question);
         if (!yes)
             return true;
@@ -101,20 +102,20 @@ class HandlerUtil {
             Path saveFolder;
             SaveDatabase(File dbFolder) {
                 super(dbFolder);
-                beginMessage = "Saving database.";
-                okMessage = "Database has been saved.";
-                failMessage = "Failed to save database.";
-                cancelMessage = "Save cancelled.";
+                beginMessage = Messages.Handler_SavingDatabaseBeginMsg;
+                okMessage = Messages.Handler_SavingDatabaseOkMsg;
+                failMessage = Messages.Handler_SavingDatabaseFailMsg;
+                cancelMessage = Messages.Handler_SavingDatabaseCancelledMsg;
             }
             @Override
             public void execute() throws Throwable {
                 saveFolder = Auxiliary.saveDatabase(dbFolder);
                 if (null == saveFolder || !Files.isDirectory(saveFolder))
-                    throw new ProCoreException("Save folder not ok.");
+                    throw new ProCoreException("Save folder not ok."); //$NON-NLS-1$
             }
             @Override
             public String getMessage() {
-                return NL + "folder=" + saveFolder;
+                return NLS.bind( Messages.Handler_FolderEquals ,new Object[] { NL , saveFolder});
             }
         }
         SaveDatabase save = new SaveDatabase(dbFolder);
@@ -126,15 +127,14 @@ class HandlerUtil {
         boolean ok = saveWithQuestion(shell, dbFolder, title, msg);
         if (ok)
             return true;
-        String question = "Save failed. Do you want me to contine?";
+        String question = Messages.Handler_SaveContinue;
         return Util.confirm(shell, title, question);
     }
 
     public static boolean delete(final Shell shell, final File dbFolder, String title, String msg) {
         if (!isFolder(shell, dbFolder, title))
             return false; // Delete not possible.
-        String question = ((null != msg) ? (msg + NL) : "")
-        + "Do you want to delete database?" + NL + "folder=" + dbFolder;
+        String question = NLS.bind(Messages.Handler_DeleteDatabase, new Object[] {((null != msg) ? (msg + NL) : ""), NL , dbFolder}); //$NON-NLS-1$
         boolean yes = MessageDialog.openQuestion(shell, title, question);
         if (!yes)
             return false;
@@ -142,10 +142,10 @@ class HandlerUtil {
         final class DeleteDatabase extends ExecutorDatabase {
             DeleteDatabase(File dbFolder) {
                 super(dbFolder);
-                beginMessage = "Deleting database.";
-                okMessage = "Database has been deleted.";
-                failMessage = "Failed to delete database.";
-                cancelMessage = "Delete cancelled.";
+                beginMessage = Messages.Handler_DeletingDatabase;
+                okMessage = Messages.Handler_DatabaseHasBeenDeleted;
+                failMessage = Messages.Handler_FailedDeleteDatabase;
+                cancelMessage = Messages.Handler_DeleteCancelled;
             }
             @Override
             public void execute() throws Throwable {
@@ -162,14 +162,14 @@ class HandlerUtil {
             return false; // Purge not possible.
         try {
             if (Auxiliary.purgeDatabaseDone(dbFolder)) {
-                MessageDialog.openInformation(shell, title, "Database already purged." + NL + "folder=" + dbFolder);
+                MessageDialog.openInformation(shell, title, NLS.bind(Messages.Handler_DatabaseAlreadyPurged, new Object[] { NL, dbFolder}));
                 return true; // Already clean.
             }
         } catch (ProCoreException e) {
-            Logger.defaultLogError("Failed to query database purge state.", e);
+            Logger.defaultLogError("Failed to query database purge state.", e); //$NON-NLS-1$
         }
-        String question = ((null != msg) ? (msg + NL) : "")
-        + "Do you want to purge database?";
+        String question = ((null != msg) ? (msg + NL) : "") //$NON-NLS-1$
+        + Messages.Handler_PurgeDatabaseQuestion;
         boolean yes = MessageDialog.openQuestion(shell, title, question);
         if (!yes)
             return false;
@@ -182,10 +182,10 @@ class HandlerUtil {
         final class PurgeDatabase extends ExecutorDatabase {
             PurgeDatabase(File dbFolder) {
                 super(dbFolder);
-                beginMessage = "Purging database.";
-                okMessage = "Database has been purged.";
-                failMessage = "Failed to purge database.";
-                cancelMessage = "Purge cancelled.";
+                beginMessage = Messages.Handler_PurgingDatabase;
+                okMessage = Messages.Handler_DatabaseHasBeenPurged;
+                failMessage = Messages.Handler_FailedToPurgeDatabase;
+                cancelMessage = Messages.Handler_PurgeCancelled;
             }
             @Override
             public void execute() throws Throwable {
@@ -199,20 +199,19 @@ class HandlerUtil {
     }
     public static boolean recoverFromGuardFileVersion(final Shell shell, final File dbFolder, String title, String msg)
     throws ProCoreException {
-        String question = ((null != msg) ? msg : "")
-        + NL + "Guard file version mismatch indicates that the database was made with different server version."
-        + "It would be best to open the database with the same version it was made.";
+        String question = NLS.bind(Messages.Handler_GuardFileMisMatchQuestion, new Object[] { ((null != msg) ? msg : ""),  //$NON-NLS-1$
+        NL}); 
         MessageDialog.openWarning(shell, title, question);
         return false;
     }
     public static boolean recoverFromDatabaseLastExit(final Shell shell, final File dbFolder, String title, String msg)
     throws ProCoreException {
-        String message = ((null != msg) ? msg : "") + NL + "What should I try to do?";
+        String message = NLS.bind(Messages.Handler_MessageWhatToDo, new Object[] {((null != msg) ? msg : "") , NL }) ;  //$NON-NLS-1$
         ArrayList<Util.Choice> choices = new ArrayList<Util.Choice>();
-        choices.add(new Util.Choice("Cancel", "Cancel i.e. do nothing. Choose this if you want to manually analyze and correct the situation. This is the safest choice."));
-        choices.add(new Util.Choice("Ignore", "Ignore the exit status. Choose this if you do not know what you are doing. This is fast way to recover and is the safest choice except for cancel."));
-        choices.add(new Util.Choice("Remove", "Remove history. Choose this you know what you are doing. This is fast way to recover but can leave tricky semantic errors in the database. Furhermore, depending on the reason for the non clean exit status, this can fail and corrupt data. However, depending on how the client and/or server died, this could be the right choice."));
-        choices.add(new Util.Choice("Recover", "Recover using journal. Choose this if you are willing to wait and know that the other choices won't work."));
+        choices.add(new Util.Choice(Messages.Handler_Cancel, Messages.Handler_CancelDescription));
+        choices.add(new Util.Choice(Messages.Handler_Ignore, Messages.Handler_IgnoreDescription));
+        choices.add(new Util.Choice(Messages.Handler_Remove, Messages.Handler_RemoveDescription));
+        choices.add(new Util.Choice(Messages.Handler_Recover, Messages.Handler_RecoverDescription));
         Util.Choice[] t = new Util.Choice[choices.size()];
         int choice = Util.select(shell, title, message, choices.toArray(t), 0);
         switch (choice) {
@@ -229,10 +228,10 @@ class HandlerUtil {
         final class IgnoreExitDatabase extends ExecutorDatabase {
             IgnoreExitDatabase(File dbFolder) {
                 super(dbFolder);
-                beginMessage = "Ignoring last exit status.";
-                okMessage = "Ignore done.";
-                failMessage = "Failed to start.";
-                cancelMessage = "Ignore cancelled.";
+                beginMessage = Messages.Handler_IgnoreExitDatabaseBeginMsg;
+                okMessage = Messages.Handler_IgnoreExitDatabaseOkMsg;
+                failMessage = Messages.Handler_IgnoreExitDatabaseBeginFailMsg;
+                cancelMessage = Messages.Handler_IgnoreExitDatabaseCancelMsg;
             }
             @Override
             public void execute() throws Throwable {
@@ -251,10 +250,10 @@ class HandlerUtil {
         final class IgnoreProtocolDatabase extends ExecutorDatabase {
             IgnoreProtocolDatabase(File dbFolder) {
                 super(dbFolder);
-                beginMessage = "Ignoring protocol version mismatch.";
-                okMessage = "Ignore done.";
-                failMessage = "Failed to start.";
-                cancelMessage = "Ignore cancelled.";
+                beginMessage = Messages.Handler_IgnoreProtocolDatabaseBeginMsg;
+                okMessage = Messages.Handler_IgnoreProtocolDatabaseOkMsg;
+                failMessage = Messages.Handler_IgnoreProtocolDatabaseFailMsg;
+                cancelMessage = Messages.Handler_IgnoreProtocolDatabaseCancelMsg;
             }
             @Override
             public void execute() throws Throwable {
@@ -268,13 +267,7 @@ class HandlerUtil {
     }
     public static boolean recoverFromProtocol(final Shell shell, final File dbFolder, String title, String msg)
     throws ProCoreException {
-        String question = ((null != msg) ? msg : "")
-        + NL + "Protocol version mismatch indicates that server and client versions differ."
-        + " It would be best to open the database using the same server and client version."
-        + " But if you insist I can ignore the mismatch and try to muddle along."
-        + " If this works then you should export the data and get matching client and server versions."
-        + " Otherwise there could later be strange errors caused by this version mismatch."
-        + " Shoud I try?";
+        String question = ((null != msg) ? msg : "") + NL + Messages.Handler_ProCoreExceptionQuestion; //$NON-NLS-1$
         boolean yes = Util.openDefaultNo(shell, title, question, MessageDialog.QUESTION);
         if (!yes)
             return false;
@@ -288,10 +281,7 @@ class HandlerUtil {
 //    }
     public static boolean recoverFromDatabaseVersion(final Shell shell, final File dbFolder, String title, String msg)
     throws ProCoreException {
-        String question = ((null != msg) ? msg : "")
-        + NL + "Database version mismatch indicates that the database was made with different server version."
-        + " It would be best to open the database with the same version it was made."
-        + " But if you insist I can try to recover database from journal.";
+        String question = ((null != msg) ? msg : "") + NL + Messages.Handler_ProCoreException2; //$NON-NLS-1$
         boolean yes = Util.openDefaultNo(shell, title, question, MessageDialog.QUESTION);
         if (!yes)
             return false;
@@ -302,11 +292,11 @@ class HandlerUtil {
         if (!isFolder(shell, dbFolder, title))
             return false; // Recovery not possible.
         if (!Auxiliary.canReadJournal(dbFolder)) {
-            MessageDialog.openWarning(shell, title, "Journal file does not exist or isn't readable." + NL + "folder=" + dbFolder);
+            MessageDialog.openWarning(shell, title, NLS.bind(Messages.Handler_JournalFileNotExists ,new Object[] { NL , dbFolder})); 
             return false; // Recovery not possible.
         }
-        String question = ((null != msg) ? msg : "")
-        + NL + "Do you want me to try to recreate the database from journal?";
+        String question = ((null != msg) ? msg : "") //$NON-NLS-1$
+        + NL + Messages.Handler_RecreateDatabaseFromJournalQuestion;
         boolean yes = MessageDialog.openQuestion(shell, title, question);
         if (!yes)
             return false;
@@ -319,10 +309,10 @@ class HandlerUtil {
         final class RecoverDatabase extends ExecutorDatabase {
             RecoverDatabase(File dbFolder) {
                 super(dbFolder);
-                beginMessage = "Recovering database.";
-                okMessage = "Database has been recovered.";
-                failMessage = "Failed to recover database.";
-                cancelMessage = "Recovery cancelled.";
+                beginMessage = Messages.Handler_RecoveringDatabaseBeginMsg;
+                okMessage = Messages.Handler_RecoveringDatabaseRecoverdMsg;
+                failMessage = Messages.Handler_RecoveringDatabaseFailedMsg;
+                cancelMessage = Messages.Handler_RecoveringDatabaseCancelledMsg;
             }
             @Override
             public void execute() throws Throwable {
@@ -359,10 +349,10 @@ class HandlerUtil {
         public void showDone(Shell shell);
     }
     static abstract class ExecutorBase implements Executor {
-        protected String beginMessage = "Task begin.";
-        protected String okMessage = "Task ok.";
-        protected String failMessage = "Task failed.";
-        protected String cancelMessage = "Task cancelled.";
+        protected String beginMessage = Messages.Handler_ExecutorBaseBeginMsg;
+        protected String okMessage = Messages.Handler_ExecutorBaseOkMsg;
+        protected String failMessage = Messages.Handler_ExecutorBaseFailedMsg;
+        protected String cancelMessage = Messages.Handler_ExecutorBaseCancelledMsg;
         protected boolean done = false;
         protected boolean ok = false;
         protected boolean cancelled = false;
@@ -437,7 +427,7 @@ class HandlerUtil {
             this.dbFolder = dbFolder;
         }
         String getMessage() {
-            return NL + "folder=" + dbFolder;
+            return NLS.bind( Messages.Handler_FolderEquals ,new Object[] { NL , dbFolder});
         }
         @Override
         public String getMessageBegin() {
@@ -472,7 +462,7 @@ class HandlerUtil {
                         return;
                     executor.setCancelled();
                     thread.interrupt();
-                    monitor.subTask("Waiting for cancellation to finish.");
+                    monitor.subTask(Messages.Handler_MonitorWaitingForCancellationToFinish);
                     while (!executor.isDone())
                         sleep(100);
                 } finally {