1 package org.simantics.db.procore.ui.internal;
4 import java.lang.reflect.Method;
5 import java.util.HashMap;
8 import org.eclipse.swt.widgets.Display;
9 import org.eclipse.swt.widgets.Shell;
10 import org.simantics.db.common.utils.Logger;
11 import org.simantics.db.exception.InternalException;
12 import org.simantics.db.server.DatabaseCorruptedException;
13 import org.simantics.db.server.DatabaseLastExitException;
14 import org.simantics.db.server.DatabaseProtocolException;
15 import org.simantics.db.server.DatabaseStartException;
16 import org.simantics.db.server.DatabaseVersionException;
17 import org.simantics.db.server.GuardFileVersionException;
18 import org.simantics.db.server.ProCoreException;
21 public static boolean delete(Shell shell, File folder) {
22 return HandlerUtil.delete(shell, folder, "Database Delete", null);
24 public static boolean purge(Shell shell, File folder) {
25 return HandlerUtil.purge(shell, folder, "Database Purge", null);
27 public static boolean handleStart(Shell shell, InternalException e) throws ProCoreException {
28 if (!(e instanceof ProCoreException))
29 return false; // Can not fix this exception.
30 ProCoreException pce = (ProCoreException)e;
31 Handler handler = getStart(pce);
32 assert(null != handler);
33 return handler.start(shell, pce);
35 public static Display getDisplay() {
36 Display d = Display.getCurrent();
38 d = Display.getDefault();
41 static Map<Long, Handler> startHandlers = new HashMap<Long, Handler>();
43 startHandlers.put(GuardFileVersionException.getHandlerId(), new GuardFileVersionHandler());
44 startHandlers.put(DatabaseCorruptedException.getHandlerId(), new DatabaseCorruptedHandler());
45 startHandlers.put(DatabaseStartException.getHandlerId(), new DatabaseStartHandler());
46 startHandlers.put(DatabaseVersionException.getHandlerId(), new DatabaseVersionHandler());
47 startHandlers.put(DatabaseLastExitException.getHandlerId(), new DatabaseLastExitHandler());
48 startHandlers.put(DatabaseProtocolException.getHandlerId(), new DatabaseProtocolHandler());
50 private static <E extends ProCoreException> long getId(E pe) {
53 Method m = pe.getClass().getMethod("getHandlerId");
54 Object value = m.invoke(null);
56 } catch (RuntimeException e) {
57 Logger.defaultLogError(e);
58 } catch (Exception e) {
59 Logger.defaultLogError(e);
63 private static <E extends ProCoreException> Handler getStart(E e) {
64 Handler h = startHandlers.get(getId(e));
66 return new DefaultHandler();