X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore.ui%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fprocore%2Fui%2FProCoreUserAgent.java;fp=bundles%2Forg.simantics.db.procore.ui%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fprocore%2Fui%2FProCoreUserAgent.java;h=dc93b2f9d9a45918a546a42383fa396523104422;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 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 new file mode 100644 index 000000000..dc93b2f9d --- /dev/null +++ b/bundles/org.simantics.db.procore.ui/src/org/simantics/db/procore/ui/ProCoreUserAgent.java @@ -0,0 +1,59 @@ +package org.simantics.db.procore.ui; + +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +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(IWorkbench workbench) { + IWorkbenchWindow wbw = workbench.getActiveWorkbenchWindow(); + Shell shell = null; + if (null != wbw) { + shell = wbw.getShell(); + } else { + 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; + } + private IWorkbench workbench; + public ProCoreUserAgent(IWorkbench workbench) { + this.workbench = workbench; + } + private Shell getShell() { + return getShell(workbench); + } + @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; + } +} \ No newline at end of file