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