]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/ProCoreUserAgent.java
acce69ad72c73fac24c0d5e4f4d31037fbc6d4ba
[simantics/platform.git] / bundles / org.simantics.db.procore.ui / src / org / simantics / db / procore / ui / ProCoreUserAgent.java
1 package org.simantics.db.procore.ui;
2
3 import org.eclipse.swt.widgets.Display;
4 import org.eclipse.swt.widgets.Shell;
5 import org.simantics.db.DatabaseUserAgent;
6 import org.simantics.db.exception.InternalException;
7 import org.simantics.db.procore.ProCoreDriver;
8
9 public final class ProCoreUserAgent implements DatabaseUserAgent {
10     private static Shell getShell() {
11         Shell shell = null;
12         Display d = getDisplay();
13         if (d == null)
14             return null;
15         shell = d.getActiveShell();
16         if (null == shell) {
17             Shell[] shells = d.getShells();
18             if (null != shells && shells.length > 0)
19                 shell = shells[0];
20         }
21         return shell;
22     }
23     private static Display getDisplay() {
24         Display d = Display.getCurrent();
25         if (d == null)
26             d = Display.getDefault();
27         return d;
28     }
29         @Override
30         public boolean handleStart(InternalException exception) {
31             Shell shell = getShell();
32             if (null == shell)
33                 return false; // no can do
34             try {
35                 return Auxiliary.handleStart(shell, exception);
36             } catch (InternalException e) {
37                 return false; // no could do
38             }
39         }
40
41         @Override
42         public String getId() {
43             return ProCoreDriver.ProCoreDriverName;
44         }
45 }