From b3d5a93100324cb02748bff3877821c1305e22e3 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 16 Jan 2020 13:35:09 +0200 Subject: [PATCH] Removed org.simantics.db.procore.ui as it is not used anymore org.simantics.db.procore.ui essentially contained ProCoreUserAgent which is no longer invoked in any case because procore is no longer an alternative. This is also related to #405 because the UI class contained MessageDialog use that was no longer allowed in Eclipse 4.13 and onwards. gitlab #446 gitlab #405 Change-Id: I8e61394d1410f4396424e006c4b09dbd8f413cf1 --- .../org.simantics.db.procore.ui/.classpath | 7 - bundles/org.simantics.db.procore.ui/.project | 28 - .../.settings/org.eclipse.jdt.core.prefs | 7 - .../.settings/org.eclipse.pde.core.prefs | 3 - .../META-INF/MANIFEST.MF | 23 - ...mantics.db.procore.ui.ProCoreUserAgent.xml | 7 - .../build.properties | 4 - .../simantics/db/procore/ui/Auxiliary.java | 45 -- .../db/procore/ui/ProCoreUserAgent.java | 45 -- .../db/procore/ui/internal/Activator.java | 30 -- .../db/procore/ui/internal/Handler.java | 481 ------------------ .../db/procore/ui/internal/Messages.java | 73 --- .../simantics/db/procore/ui/internal/UI.java | 70 --- .../db/procore/ui/internal/Util.java | 111 ---- .../procore/ui/internal/messages.properties | 59 --- bundles/pom.xml | 1 - .../feature.xml | 7 - 17 files changed, 1001 deletions(-) delete mode 100644 bundles/org.simantics.db.procore.ui/.classpath delete mode 100644 bundles/org.simantics.db.procore.ui/.project delete mode 100644 bundles/org.simantics.db.procore.ui/.settings/org.eclipse.jdt.core.prefs delete mode 100644 bundles/org.simantics.db.procore.ui/.settings/org.eclipse.pde.core.prefs delete mode 100644 bundles/org.simantics.db.procore.ui/META-INF/MANIFEST.MF delete mode 100644 bundles/org.simantics.db.procore.ui/OSGI-INF/org.simantics.db.procore.ui.ProCoreUserAgent.xml delete mode 100644 bundles/org.simantics.db.procore.ui/build.properties delete mode 100644 bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/Auxiliary.java delete mode 100644 bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/ProCoreUserAgent.java delete mode 100644 bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Activator.java delete mode 100644 bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Handler.java delete mode 100644 bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Messages.java delete mode 100644 bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/UI.java delete mode 100644 bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Util.java delete mode 100644 bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/messages.properties diff --git a/bundles/org.simantics.db.procore.ui/.classpath b/bundles/org.simantics.db.procore.ui/.classpath deleted file mode 100644 index eca7bdba8..000000000 --- a/bundles/org.simantics.db.procore.ui/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/bundles/org.simantics.db.procore.ui/.project b/bundles/org.simantics.db.procore.ui/.project deleted file mode 100644 index 2a8657d08..000000000 --- a/bundles/org.simantics.db.procore.ui/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.simantics.db.procore.ui - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/bundles/org.simantics.db.procore.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.db.procore.ui/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 0c68a61dc..000000000 --- a/bundles/org.simantics.db.procore.ui/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.db.procore.ui/.settings/org.eclipse.pde.core.prefs b/bundles/org.simantics.db.procore.ui/.settings/org.eclipse.pde.core.prefs deleted file mode 100644 index f29e940a0..000000000 --- a/bundles/org.simantics.db.procore.ui/.settings/org.eclipse.pde.core.prefs +++ /dev/null @@ -1,3 +0,0 @@ -eclipse.preferences.version=1 -pluginProject.extensions=false -resolve.requirebundle=false diff --git a/bundles/org.simantics.db.procore.ui/META-INF/MANIFEST.MF b/bundles/org.simantics.db.procore.ui/META-INF/MANIFEST.MF deleted file mode 100644 index bab8294d8..000000000 --- a/bundles/org.simantics.db.procore.ui/META-INF/MANIFEST.MF +++ /dev/null @@ -1,23 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: ProCore User Interface -Bundle-SymbolicName: org.simantics.db.procore.ui -Bundle-Vendor: VTT Technical Research Centre of Finland -Bundle-Version: 1.1.6.qualifier -Bundle-ActivationPolicy: lazy -Bundle-Activator: org.simantics.db.procore.ui.internal.Activator -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Export-Package: org.simantics.db.procore.ui -Import-Package: - org.eclipse.core.runtime, - org.eclipse.jface.dialogs, - org.eclipse.jface.operation, - org.eclipse.osgi.util;version="1.1.0", - org.eclipse.swt.widgets, - org.osgi.framework;version="1.3.0", - org.simantics.db, - org.simantics.db.common.utils, - org.simantics.db.exception, - org.simantics.db.server;visibility:=reexport -Require-Bundle: org.simantics.db.procore;bundle-version="1.2.1" -Automatic-Module-Name: org.simantics.db.procore.ui diff --git a/bundles/org.simantics.db.procore.ui/OSGI-INF/org.simantics.db.procore.ui.ProCoreUserAgent.xml b/bundles/org.simantics.db.procore.ui/OSGI-INF/org.simantics.db.procore.ui.ProCoreUserAgent.xml deleted file mode 100644 index 52b6ac960..000000000 --- a/bundles/org.simantics.db.procore.ui/OSGI-INF/org.simantics.db.procore.ui.ProCoreUserAgent.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/bundles/org.simantics.db.procore.ui/build.properties b/bundles/org.simantics.db.procore.ui/build.properties deleted file mode 100644 index 34d2e4d2d..000000000 --- a/bundles/org.simantics.db.procore.ui/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . diff --git a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/Auxiliary.java b/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/Auxiliary.java deleted file mode 100644 index 36d896673..000000000 --- a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/Auxiliary.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.simantics.db.procore.ui; - -import java.io.File; - -import org.eclipse.swt.widgets.Shell; -import org.simantics.db.exception.InternalException; -import org.simantics.db.procore.ui.internal.UI; - -public class Auxiliary { - /** - * @param shell for the user interface. - * @param exception thrown from server. - * @return true if server can be started. - */ - public static boolean beforeStart(Shell shell, File folder) throws InternalException { - boolean skipPurge = "true".equals(System.getProperty("org.simantics.db.procore.ui.skipPurge")); //$NON-NLS-1$ //$NON-NLS-2$ - if (skipPurge) - return true; - return UI.purge(shell, folder); - } - /** - * @param shell for the user interface. - * @param exception thrown from server start. - * @return true if problem with server start was successfully fixed. - */ - public static boolean handleStart(Shell shell, InternalException exception) throws InternalException { - return UI.handleStart(shell, exception); - } - /** - * @param shell for the user interface. - * @param folder of the database. - * @return true if deletion was successful. - */ - public static boolean delete(Shell shell, File folder) { - return UI.delete(shell, folder); - } - /** - * @param shell for the user interface. - * @param folder of the database. - * @return true if purge was successful. - */ - public static boolean purge(Shell shell, File folder) { - return UI.purge(shell, folder); - } -} diff --git a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/ProCoreUserAgent.java b/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/ProCoreUserAgent.java deleted file mode 100644 index acce69ad7..000000000 --- a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/ProCoreUserAgent.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.simantics.db.procore.ui; - -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.simantics.db.DatabaseUserAgent; -import org.simantics.db.exception.InternalException; -import org.simantics.db.procore.ProCoreDriver; - -public final class ProCoreUserAgent implements DatabaseUserAgent { - private static Shell getShell() { - Shell shell = null; - Display d = getDisplay(); - if (d == null) - return null; - shell = d.getActiveShell(); - if (null == shell) { - Shell[] shells = d.getShells(); - if (null != shells && shells.length > 0) - shell = shells[0]; - } - return shell; - } - private static Display getDisplay() { - Display d = Display.getCurrent(); - if (d == null) - d = Display.getDefault(); - return d; - } - @Override - public boolean handleStart(InternalException exception) { - Shell shell = getShell(); - if (null == shell) - return false; // no can do - try { - return Auxiliary.handleStart(shell, exception); - } catch (InternalException e) { - return false; // no could do - } - } - - @Override - public String getId() { - return ProCoreDriver.ProCoreDriverName; - } -} diff --git a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Activator.java b/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Activator.java deleted file mode 100644 index bee15d6ba..000000000 --- a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Activator.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.simantics.db.procore.ui.internal; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -public class Activator implements BundleActivator { - - private static BundleContext context; - - static BundleContext getContext() { - return context; - } - - /* - * (non-Javadoc) - * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext bundleContext) throws Exception { - Activator.context = bundleContext; - } - - /* - * (non-Javadoc) - * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext bundleContext) throws Exception { - Activator.context = null; - } - -} diff --git a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Handler.java b/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Handler.java deleted file mode 100644 index 3dd9e4d73..000000000 --- a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Handler.java +++ /dev/null @@ -1,481 +0,0 @@ -package org.simantics.db.procore.ui.internal; - -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; - -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; -import org.simantics.db.server.Auxiliary; -import org.simantics.db.server.ProCoreException; - -abstract class Handler { - 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 = Messages.Handler_NoDatabaseFolderGiven; - MessageDialog.openWarning(shell, title, msg); - throw new ProCoreException(msg); - } - } -} -final class DefaultHandler extends Handler { - @Override - boolean start(Shell shell, ProCoreException e) throws ProCoreException { - String warning = Util.getMessage(e); - MessageDialog.openError(shell, title, warning); - return false; - } -} -final class GuardFileVersionHandler extends Handler { - @Override - boolean start(Shell shell, ProCoreException e) throws ProCoreException { - checkFolderGiven(shell, e); - return HandlerUtil.recoverFromGuardFileVersion(shell, e.getDbFolder(), title, e.getMessage()); - } -} -final class DatabaseCorruptedHandler extends Handler { - @Override - boolean start(Shell shell, ProCoreException e) throws ProCoreException { - checkFolderGiven(shell, e); - return HandlerUtil.recoverFromJournal(shell, e.getDbFolder(), title, e.getMessage()); - } -} -final class DatabaseLastExitHandler extends Handler { - @Override - boolean start(Shell shell, ProCoreException e) throws ProCoreException { - checkFolderGiven(shell, e); - return HandlerUtil.recoverFromDatabaseLastExit(shell, e.getDbFolder(), title, e.getMessage()); - - } -} -final class DatabaseProtocolHandler extends Handler { - @Override - boolean start(Shell shell, ProCoreException e) throws ProCoreException { - checkFolderGiven(shell, e); - return HandlerUtil.recoverFromProtocol(shell, e.getDbFolder(), title, e.getMessage()); - - } -} -final class DatabaseStartHandler extends Handler { - @Override - boolean start(Shell shell, ProCoreException e) throws ProCoreException { - checkFolderGiven(shell, e); - String warning = e.getMessage(); - MessageDialog.openError(shell, title, warning); - return false; - } -} -final class DatabaseVersionHandler extends Handler { - @Override - boolean start(Shell shell, ProCoreException e) throws ProCoreException { - checkFolderGiven(shell, e); - return HandlerUtil.recoverFromDatabaseVersion(shell, e.getDbFolder(), title, e.getMessage()); - } -} -class HandlerUtil { - 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, 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 = 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; - final class SaveDatabase extends ExecutorDatabase { - Path saveFolder; - SaveDatabase(File dbFolder) { - super(dbFolder); - 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."); //$NON-NLS-1$ - } - @Override - public String getMessage() { - return NLS.bind( Messages.Handler_FolderEquals ,new Object[] { NL , saveFolder}); - } - } - SaveDatabase save = new SaveDatabase(dbFolder); - execute(shell, save); - save.showDone(shell); - return save.ok; - } - static boolean saveWithCheck(final Shell shell, final File dbFolder, String title, String msg) { - boolean ok = saveWithQuestion(shell, dbFolder, title, msg); - if (ok) - return true; - 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 = 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; - saveWithQuestion(shell, dbFolder, title, null); - final class DeleteDatabase extends ExecutorDatabase { - DeleteDatabase(File dbFolder) { - super(dbFolder); - beginMessage = Messages.Handler_DeletingDatabase; - okMessage = Messages.Handler_DatabaseHasBeenDeleted; - failMessage = Messages.Handler_FailedDeleteDatabase; - cancelMessage = Messages.Handler_DeleteCancelled; - } - @Override - public void execute() throws Throwable { - Auxiliary.deleteDatabase(dbFolder); - } - } - DeleteDatabase delete = new DeleteDatabase(dbFolder); - execute(shell, delete); - delete.showDone(shell); - return delete.ok; - } - public static boolean purge(final Shell shell, final File dbFolder, String title, String msg) { - if (!isFolder(shell, dbFolder, title)) - return false; // Purge not possible. - try { - if (Auxiliary.purgeDatabaseDone(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); //$NON-NLS-1$ - } - String question = ((null != msg) ? (msg + NL) : "") //$NON-NLS-1$ - + Messages.Handler_PurgeDatabaseQuestion; - boolean yes = MessageDialog.openQuestion(shell, title, question); - if (!yes) - return false; - return purgeWithSave(shell, dbFolder, title); - } - private static boolean purgeWithSave(final Shell shell, final File dbFolder, String title) { - boolean ok = saveWithCheck(shell, dbFolder, title, null); - if (!ok) - return false; - final class PurgeDatabase extends ExecutorDatabase { - PurgeDatabase(File dbFolder) { - super(dbFolder); - beginMessage = Messages.Handler_PurgingDatabase; - okMessage = Messages.Handler_DatabaseHasBeenPurged; - failMessage = Messages.Handler_FailedToPurgeDatabase; - cancelMessage = Messages.Handler_PurgeCancelled; - } - @Override - public void execute() throws Throwable { - Auxiliary.purgeDatabase(dbFolder); - } - } - PurgeDatabase purge = new PurgeDatabase(dbFolder); - execute(shell, purge); - purge.showDone(shell); - return purge.ok; - } - public static boolean recoverFromGuardFileVersion(final Shell shell, final File dbFolder, String title, String msg) - throws ProCoreException { - 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 = NLS.bind(Messages.Handler_MessageWhatToDo, new Object[] {((null != msg) ? msg : "") , NL }) ; //$NON-NLS-1$ - ArrayList choices = new ArrayList(); - 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) { - default: return false; - case 1: return ignoreExitStatusWithSave(shell, dbFolder, title); - case 2: return purgeWithSave(shell, dbFolder, title); - case 3: return recoverFromJournalWithSave(shell, dbFolder, title); - } - } - public static boolean ignoreExitStatusWithSave(final Shell shell, final File dbFolder, String title) { - boolean ok = saveWithCheck(shell, dbFolder, title, null); - if (!ok) - return false; - final class IgnoreExitDatabase extends ExecutorDatabase { - IgnoreExitDatabase(File dbFolder) { - super(dbFolder); - beginMessage = Messages.Handler_IgnoreExitDatabaseBeginMsg; - okMessage = Messages.Handler_IgnoreExitDatabaseOkMsg; - failMessage = Messages.Handler_IgnoreExitDatabaseBeginFailMsg; - cancelMessage = Messages.Handler_IgnoreExitDatabaseCancelMsg; - } - @Override - public void execute() throws Throwable { - Auxiliary.ignoreExit(dbFolder); - } - } - IgnoreExitDatabase recover = new IgnoreExitDatabase(dbFolder); - execute(shell, recover); - recover.showDone(shell); - return recover.ok; - } - public static boolean ignoreProtocolVersionWithSave(final Shell shell, final File dbFolder, String title) { - boolean ok = saveWithCheck(shell, dbFolder, title, null); - if (!ok) - return false; - final class IgnoreProtocolDatabase extends ExecutorDatabase { - IgnoreProtocolDatabase(File dbFolder) { - super(dbFolder); - beginMessage = Messages.Handler_IgnoreProtocolDatabaseBeginMsg; - okMessage = Messages.Handler_IgnoreProtocolDatabaseOkMsg; - failMessage = Messages.Handler_IgnoreProtocolDatabaseFailMsg; - cancelMessage = Messages.Handler_IgnoreProtocolDatabaseCancelMsg; - } - @Override - public void execute() throws Throwable { - Auxiliary.ignoreProtocol(dbFolder); - } - } - IgnoreProtocolDatabase ignore = new IgnoreProtocolDatabase(dbFolder); - execute(shell, ignore); - ignore.showDone(shell); - return ignore.ok; - } - public static boolean recoverFromProtocol(final Shell shell, final File dbFolder, String title, String msg) - throws ProCoreException { - 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; - return ignoreProtocolVersionWithSave(shell, dbFolder, title); - } -// public static boolean recoverFromProtocolWithSave(final Shell shell, final File dbFolder, String title) { -// boolean ok = saveWithCheck(shell, dbFolder, title, null); -// if (!ok) -// return false; -// return ignoreProtocolVersionWithSave(shell, dbFolder, title); -// } - public static boolean recoverFromDatabaseVersion(final Shell shell, final File dbFolder, String title, String msg) - throws ProCoreException { - 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; - return recoverFromJournalWithSave(shell, dbFolder, title); - } - public static boolean recoverFromJournal(final Shell shell, final File dbFolder, String title, String msg) - throws ProCoreException { - if (!isFolder(shell, dbFolder, title)) - return false; // Recovery not possible. - if (!Auxiliary.canReadJournal(dbFolder)) { - MessageDialog.openWarning(shell, title, NLS.bind(Messages.Handler_JournalFileNotExists ,new Object[] { NL , dbFolder})); - return false; // Recovery not possible. - } - String question = ((null != msg) ? msg : "") //$NON-NLS-1$ - + NL + Messages.Handler_RecreateDatabaseFromJournalQuestion; - boolean yes = MessageDialog.openQuestion(shell, title, question); - if (!yes) - return false; - return recoverFromJournalWithSave(shell, dbFolder, title); - } - public static boolean recoverFromJournalWithSave(final Shell shell, final File dbFolder, String title) { - boolean ok = saveWithCheck(shell, dbFolder, title, null); - if (!ok) - return false; - final class RecoverDatabase extends ExecutorDatabase { - RecoverDatabase(File dbFolder) { - super(dbFolder); - beginMessage = Messages.Handler_RecoveringDatabaseBeginMsg; - okMessage = Messages.Handler_RecoveringDatabaseRecoverdMsg; - failMessage = Messages.Handler_RecoveringDatabaseFailedMsg; - cancelMessage = Messages.Handler_RecoveringDatabaseCancelledMsg; - } - @Override - public void execute() throws Throwable { - Auxiliary.replaceFromJournal(dbFolder); - } - } - RecoverDatabase recover = new RecoverDatabase(dbFolder); - execute(shell, recover); - recover.showDone(shell); - return recover.ok; - } - private static void sleep(long millsec) throws InterruptedException { - Display display = UI.getDisplay(); - boolean isUIThread = (null == display) ? false : (Thread.currentThread() == display.getThread()); - Thread.sleep(100); - if (!isUIThread) - return; - int count = 0; - while (++count < 1000 && display.readAndDispatch()) - continue; - } - interface Executor extends Runnable { - public String getMessageBegin(); - public String getMessageCancel(); - public String getMessageFail(Throwable throwable); - public String getMessageFail(); - public String getMessageOk(); - public boolean isDone(); - public boolean isForkable(); - public boolean isCancelable(); - public void execute() throws Throwable; - public void setCancelled(); - public void setDone(); - public void showDone(Shell shell); - } - static abstract class ExecutorBase implements Executor { - 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; - protected boolean forkable = true; - protected boolean cancelable = false; - protected Throwable throwable = null; - public void run() { - try { - execute(); - ok = true; - } catch (Throwable t) { - throwable = t; - } finally { - done = true; - } - } - @Override - public String getMessageBegin() { - return beginMessage; - } - @Override - public String getMessageCancel() { - return cancelMessage; - } - @Override - public String getMessageFail(Throwable throwable) { - return failMessage + NL + throwable.getMessage(); - } - @Override - public String getMessageFail() { - return failMessage; - } - @Override - public String getMessageOk() { - return okMessage; - } - @Override - public boolean isDone() { - return done; - } - @Override - public void setCancelled() { - cancelled = true; - } - @Override - public void setDone() { - done = true; - } - @Override - public boolean isForkable() { - return forkable; - } - @Override - public boolean isCancelable() { - return cancelable; - } - @Override - public void showDone(Shell shell) { - if (null != throwable) - Util.showError(shell, getMessageFail(throwable)); - else if (ok) - Util.showInfo(shell, getMessageOk()); - else if (cancelled) - Util.showInfo(shell, getMessageCancel()); - else - Util.showWarning(shell, getMessageFail()); - } - } - static abstract class ExecutorDatabase extends ExecutorBase { - protected final File dbFolder; - ExecutorDatabase(File dbFolder) { - this.dbFolder = dbFolder; - } - String getMessage() { - return NLS.bind( Messages.Handler_FolderEquals ,new Object[] { NL , dbFolder}); - } - @Override - public String getMessageBegin() { - return super.getMessageBegin() + getMessage(); - } - @Override - public String getMessageCancel() { - return super.getMessageCancel() + getMessage(); - } - @Override - public String getMessageFail(Throwable t) { - return super.getMessageFail(t) + getMessage(); - } - @Override - public String getMessageOk() { - return super.getMessageOk() + getMessage(); - } - } - private static void execute(final Shell shell, final Executor executor) { - final Thread thread = new Thread(executor); - thread.start(); - IRunnableWithProgress progress = new IRunnableWithProgress() { - @Override - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - try { - monitor.beginTask(executor.getMessageBegin(), IProgressMonitor.UNKNOWN); - while (!monitor.isCanceled() && !executor.isDone()) { - monitor.worked(1); - sleep(100); - } - if (executor.isDone()) - return; - executor.setCancelled(); - thread.interrupt(); - monitor.subTask(Messages.Handler_MonitorWaitingForCancellationToFinish); - while (!executor.isDone()) - sleep(100); - } finally { - monitor.done(); - } - } - }; - boolean fork = executor.isForkable(); - boolean cancelable = executor.isCancelable(); - try { - new ProgressMonitorDialog(shell).run(fork, cancelable, progress); - } catch (InvocationTargetException e) { - } catch (InterruptedException e) { - } - } -} \ No newline at end of file diff --git a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Messages.java b/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Messages.java deleted file mode 100644 index 498d3be29..000000000 --- a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Messages.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.simantics.db.procore.ui.internal; - -import org.eclipse.osgi.util.NLS; - -public class Messages extends NLS { - private static final String BUNDLE_NAME = "org.simantics.db.procore.ui.internal.messages"; //$NON-NLS-1$ - public static String Handler_Cancel; - public static String Handler_CancelDescription; - public static String Handler_DatabaseAlreadyPurged; - public static String Handler_DatabaseHasBeenDeleted; - public static String Handler_DatabaseHasBeenPurged; - public static String Handler_DatabaseServer; - public static String Handler_DeleteCancelled; - public static String Handler_DeleteDatabase; - public static String Handler_DeletingDatabase; - public static String Handler_ExecutorBaseBeginMsg; - public static String Handler_ExecutorBaseCancelledMsg; - public static String Handler_ExecutorBaseFailedMsg; - public static String Handler_ExecutorBaseOkMsg; - public static String Handler_FailedDeleteDatabase; - public static String Handler_FailedToPurgeDatabase; - public static String Handler_FolderEquals; - public static String Handler_GuardFileMisMatchQuestion; - public static String Handler_Ignore; - public static String Handler_IgnoreDescription; - public static String Handler_IgnoreExitDatabaseBeginFailMsg; - public static String Handler_IgnoreExitDatabaseBeginMsg; - public static String Handler_IgnoreExitDatabaseCancelMsg; - public static String Handler_IgnoreExitDatabaseOkMsg; - public static String Handler_IgnoreProtocolDatabaseBeginMsg; - public static String Handler_IgnoreProtocolDatabaseCancelMsg; - public static String Handler_IgnoreProtocolDatabaseFailMsg; - public static String Handler_IgnoreProtocolDatabaseOkMsg; - public static String Handler_JournalFileNotExists; - public static String Handler_MessageWhatToDo; - public static String Handler_MonitorWaitingForCancellationToFinish; - public static String Handler_NoDatabaseFolderGiven; - public static String Handler_ProCoreException2; - public static String Handler_ProCoreExceptionQuestion; - public static String Handler_PurgeCancelled; - public static String Handler_PurgeDatabaseQuestion; - public static String Handler_PurgingDatabase; - public static String Handler_Recover; - public static String Handler_RecoverDescription; - public static String Handler_RecoveringDatabaseBeginMsg; - public static String Handler_RecoveringDatabaseCancelledMsg; - public static String Handler_RecoveringDatabaseFailedMsg; - public static String Handler_RecoveringDatabaseRecoverdMsg; - public static String Handler_RecreateDatabaseFromJournalQuestion; - public static String Handler_Remove; - public static String Handler_RemoveDescription; - public static String Handler_SaveContinue; - public static String Handler_SaveDatabase; - public static String Handler_SavingDatabaseBeginMsg; - public static String Handler_SavingDatabaseCancelledMsg; - public static String Handler_SavingDatabaseFailMsg; - public static String Handler_SavingDatabaseOkMsg; - public static String Handler_WarningMsgDatabaseFolderNotExists; - public static String UI_DatabaseDelete; - public static String UI_DatabasePurge; - public static String Util_Error; - public static String Util_Information; - public static String Util_No; - public static String Util_Warning; - public static String Util_Yes; - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} diff --git a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/UI.java b/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/UI.java deleted file mode 100644 index a36c6a20d..000000000 --- a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/UI.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.simantics.db.procore.ui.internal; - -import java.io.File; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.simantics.db.common.utils.Logger; -import org.simantics.db.exception.InternalException; -import org.simantics.db.server.DatabaseCorruptedException; -import org.simantics.db.server.DatabaseLastExitException; -import org.simantics.db.server.DatabaseProtocolException; -import org.simantics.db.server.DatabaseStartException; -import org.simantics.db.server.DatabaseVersionException; -import org.simantics.db.server.GuardFileVersionException; -import org.simantics.db.server.ProCoreException; - -public class UI { - public static boolean delete(Shell shell, File folder) { - return HandlerUtil.delete(shell, folder, Messages.UI_DatabaseDelete, null); - } - public static boolean purge(Shell shell, File folder) { - return HandlerUtil.purge(shell, folder, Messages.UI_DatabasePurge, null); - } - public static boolean handleStart(Shell shell, InternalException e) throws ProCoreException { - if (!(e instanceof ProCoreException)) - return false; // Can not fix this exception. - ProCoreException pce = (ProCoreException)e; - Handler handler = getStart(pce); - assert(null != handler); - return handler.start(shell, pce); - } - public static Display getDisplay() { - Display d = Display.getCurrent(); - if (d == null) - d = Display.getDefault(); - return d; - } - static Map startHandlers = new HashMap(); - static { - startHandlers.put(GuardFileVersionException.getHandlerId(), new GuardFileVersionHandler()); - startHandlers.put(DatabaseCorruptedException.getHandlerId(), new DatabaseCorruptedHandler()); - startHandlers.put(DatabaseStartException.getHandlerId(), new DatabaseStartHandler()); - startHandlers.put(DatabaseVersionException.getHandlerId(), new DatabaseVersionHandler()); - startHandlers.put(DatabaseLastExitException.getHandlerId(), new DatabaseLastExitHandler()); - startHandlers.put(DatabaseProtocolException.getHandlerId(), new DatabaseProtocolHandler()); - } - private static long getId(E pe) { - long id = 0; - try { - Method m = pe.getClass().getMethod("getHandlerId"); //$NON-NLS-1$ - Object value = m.invoke(null); - id = (long)value; - } catch (RuntimeException e) { - Logger.defaultLogError(e); - } catch (Exception e) { - Logger.defaultLogError(e); - } - return id; - } - private static Handler getStart(E e) { - Handler h = startHandlers.get(getId(e)); - if (null == h) - return new DefaultHandler(); - else - return h; - } -} diff --git a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Util.java b/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Util.java deleted file mode 100644 index 9c4a5e423..000000000 --- a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/Util.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.simantics.db.procore.ui.internal; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.simantics.db.common.utils.Logger; - -public class Util { - static void showInfo(Shell shell, String message) { - MessageDialog.openInformation(shell, Messages.Util_Information, message); - } - static void showWarning(Shell shell, String message) { - MessageDialog.openWarning(shell, Messages.Util_Warning, message); - } - public static void showError(Shell shell, String message) { - Util.showError(shell, message, null); - } - static void showError(Shell shell, String message, Throwable t) { - Logger.defaultLogError(message, t); - if (null != t) - message += "\n" + t.getMessage(); //$NON-NLS-1$ - MessageDialog.openError(shell, Messages.Util_Error, message); - } - public static void logError(String message) { - Util.logError(message, null); - } - public static void logError(String message, Throwable cause) { - Logger.defaultLogError(message, cause); - } - public static void trace(Class clazz) { - trace(clazz, null); - } - public static void trace(String message) { - trace(null, message); - } - public static void trace(Class clazz, String message) { - String s = ""; //$NON-NLS-1$ - if (null != clazz) - s += clazz.getSimpleName() + " called.\n"; //$NON-NLS-1$ - if (null != message) - s += message; - Logger.defaultLogInfo(s); - } - private static String NL = System.getProperty("line.separator"); //$NON-NLS-1$ - static class Choice { - public Choice(String button, String text) { - this.button = button; - this.text = text; - } - public String button; - public String text; - } - public static int select(final Shell shell, final String title, String message, Choice[] choices, int def) { - assert(choices.length > 0); - if (def < 0 || def >= choices.length) - def = 0; - final String[] labels = new String[choices.length]; - final StringBuilder sb = new StringBuilder(message.length() + 256); - sb.append(message); - for (int i=0; i= labels.length) - answer = 0; - return answer; - } - public static boolean confirm(Shell shell, String title, String message) { - String[] labels = new String[2]; - labels[0] = Messages.Util_Yes; - labels[1] = Messages.Util_No; - MessageDialog dialog = new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, labels, 1); - int answer = dialog.open(); - return answer == 0; - } - public static boolean openDefaultNo(Shell shell, String title, String message, int style) { - String[] labels = new String[2]; - labels[0] = Messages.Util_Yes; - labels[1] = Messages.Util_No; - MessageDialog dialog = new MessageDialog(shell, title, null, message, style, labels, 1); - int answer = dialog.open(); - return answer == 0; - } - public static String getMessage(Throwable t) { - StringBuilder s = new StringBuilder(t.getMessage()); - final int LIMIT = 10; - int i = 0; - for (Throwable c = t.getCause(); null != c && i < LIMIT; ++i, c = c.getCause()) - s.append(NL + "cause: " + c.getMessage()); //$NON-NLS-1$ - return s.toString(); - } -} diff --git a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/messages.properties b/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/messages.properties deleted file mode 100644 index 4f0950fa3..000000000 --- a/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/internal/messages.properties +++ /dev/null @@ -1,59 +0,0 @@ -Handler_Cancel=Cancel -Handler_CancelDescription=Cancel i.e. do nothing. Choose this if you want to manually analyze and correct the situation. This is the safest choice. -Handler_DatabaseAlreadyPurged=Database already purged.{0}folder={1} -Handler_DatabaseHasBeenDeleted=Database has been deleted. -Handler_DatabaseHasBeenPurged=Database has been purged. -Handler_DatabaseServer=Database Server -Handler_DeleteCancelled=Delete cancelled. -Handler_DeleteDatabase={0}Do you want to delete database?{1}folder={2} -Handler_DeletingDatabase=Deleting database. -Handler_ExecutorBaseBeginMsg=Task begin. -Handler_ExecutorBaseCancelledMsg=Task cancelled. -Handler_ExecutorBaseFailedMsg=Task failed. -Handler_ExecutorBaseOkMsg=Task ok. -Handler_FailedDeleteDatabase=Failed to delete database. -Handler_FailedToPurgeDatabase=Failed to purge database. -Handler_FolderEquals={0}folder={1} -Handler_GuardFileMisMatchQuestion={0}{1}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. -Handler_Ignore=Ignore -Handler_IgnoreDescription=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. -Handler_IgnoreExitDatabaseBeginFailMsg=Failed to start. -Handler_IgnoreExitDatabaseBeginMsg=Ignoring last exit status. -Handler_IgnoreExitDatabaseCancelMsg=Ignore cancelled. -Handler_IgnoreExitDatabaseOkMsg=Ignore done. -Handler_IgnoreProtocolDatabaseBeginMsg=Ignoring protocol version mismatch. -Handler_IgnoreProtocolDatabaseCancelMsg=Ignore cancelled. -Handler_IgnoreProtocolDatabaseFailMsg=Failed to start. -Handler_IgnoreProtocolDatabaseOkMsg=Ignore done. -Handler_JournalFileNotExists=Journal file does not exist or isn't readable.{0}folder={1} -Handler_MessageWhatToDo={0}{1}What should I try to do? -Handler_MonitorWaitingForCancellationToFinish=Waiting for cancellation to finish. -Handler_NoDatabaseFolderGiven=No database folder given. -Handler_ProCoreExceptionQuestion=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? -Handler_ProCoreException2=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.Journal file does not exist or isn't readable. -Handler_PurgeCancelled=Purge cancelled. -Handler_PurgeDatabaseQuestion=Do you want to purge database? -Handler_PurgingDatabase=Purging database. -Handler_Recover=Recover -Handler_RecoverDescription=Recover using journal. Choose this if you are willing to wait and know that the other choices won't work. -Handler_RecoveringDatabaseBeginMsg=Recovering database. -Handler_RecoveringDatabaseCancelledMsg=Recovery cancelled. -Handler_RecoveringDatabaseFailedMsg=Failed to recover database. -Handler_RecoveringDatabaseRecoverdMsg=Database has been recovered. -Handler_RecreateDatabaseFromJournalQuestion=Do you want me to try to recreate the database from journal? -Handler_Remove=Remove -Handler_RemoveDescription=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. -Handler_SaveContinue=Save failed. Do you want me to contine? -Handler_SaveDatabase={0}Do you want to save database?{1}folder={2} -Handler_SavingDatabaseBeginMsg=Saving database. -Handler_SavingDatabaseCancelledMsg=Save cancelled. -Handler_SavingDatabaseFailMsg=Failed to save database. -Handler_SavingDatabaseOkMsg=Database has been saved. -Handler_WarningMsgDatabaseFolderNotExists=Database folder does not exist. folder= -UI_DatabaseDelete=Database Delete -UI_DatabasePurge=Database Purge -Util_Error=Error -Util_Information=Information -Util_No=No -Util_Warning=Warning -Util_Yes=Yes diff --git a/bundles/pom.xml b/bundles/pom.xml index d8cdbb346..bd16daf91 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -88,7 +88,6 @@ org.simantics.db.layer0 org.simantics.db.management org.simantics.db.procore - org.simantics.db.procore.ui org.simantics.db.server org.simantics.db.services org.simantics.db.testing diff --git a/features/org.simantics.platform.ui.feature/feature.xml b/features/org.simantics.platform.ui.feature/feature.xml index d4e711da1..f5148b1d7 100644 --- a/features/org.simantics.platform.ui.feature/feature.xml +++ b/features/org.simantics.platform.ui.feature/feature.xml @@ -113,11 +113,4 @@ reusable components implemented on top of the platform. version="0.0.0" unpack="false"/> - - -- 2.43.2