From b0fe7fdaa7feffc877ee06e5566b02d2a3483c01 Mon Sep 17 00:00:00 2001
From: Alexander Diewald <diewald@fortiss.org>
Date: Tue, 10 Jan 2017 15:51:58 +0000
Subject: [PATCH] Open a second shell before taking the screenshot of the
 "tick" button for boolean annotations in GTK environments. refs 2406

---
 .../EmulatedNativeCheckBoxLabelProvider.java  | 30 ++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/EmulatedNativeCheckBoxLabelProvider.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/EmulatedNativeCheckBoxLabelProvider.java
index 8285c86bd..be4035737 100644
--- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/EmulatedNativeCheckBoxLabelProvider.java
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/EmulatedNativeCheckBoxLabelProvider.java
@@ -36,9 +36,12 @@ import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableItem;
+import org.fortiss.tooling.base.ToolingBaseActivator;
 import org.fortiss.tooling.base.annotation.AnnotationEntry;
 import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
 import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 
 /**
  * <p>
@@ -61,7 +64,7 @@ import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart;
  * @author diewald
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating YELLOW Hash: 4C99360BCBA6F717DE35D5AE9554F25B
+ * @ConQAT.Rating YELLOW Hash: E432AD2266E44A4DE3B3DE4ACB2D852E
  */
 public class EmulatedNativeCheckBoxLabelProvider extends AnnotationLabelProvider {
 
@@ -176,6 +179,17 @@ public class EmulatedNativeCheckBoxLabelProvider extends AnnotationLabelProvider
 		shell.setSize(bsize);
 
 		shell.open();
+
+		// Work around a gtk display error that causes the widgets in the
+		// shell not being "visible". Opening a second Shell modifies some
+		// internal properties of the existing shell, such that the widgets
+		// become visible.
+		if(isBundleLoaded("org.eclipse.swt.gtk")) {
+			Shell shell2 = new Shell(control.getShell(), SWT.NO_TRIM);
+			shell2.open();
+			shell2.close();
+		}
+
 		GC gc = new GC(shell);
 		Image image = new Image(control.getDisplay(), bsize.x, bsize.y);
 		gc.copyArea(image, 0, 0);
@@ -191,6 +205,20 @@ public class EmulatedNativeCheckBoxLabelProvider extends AnnotationLabelProvider
 		return new Image(control.getDisplay(), imageData);
 	}
 
+	/** Returns whether any bundle containing the given qualifier has been loaded. */
+	private boolean isBundleLoaded(String bundleNameFragment) {
+		BundleContext bundleContext =
+				ToolingBaseActivator.getDefault().getBundle().getBundleContext();
+
+		for(Bundle bundle : bundleContext.getBundles()) {
+			if(bundle.getSymbolicName().contains(bundleNameFragment)) {
+				return true;
+			}
+		}
+
+		return false;
+	}
+
 	/** {@inheritDoc} */
 	@Override
 	public String getText(Object element) {
-- 
GitLab