Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbvosburgh2009-06-17 18:24:16 +0000
committerbvosburgh2009-06-17 18:24:16 +0000
commitbf3c28fe5902eb91a46a9e38c00667e85e37fcdd (patch)
treee1974ecdbdbc46b06c2cdd567f3da820a24ebd23 /jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JptUiPlugin.java
parent0f0eac457316d5287aa9f38e8cdd68e91250ccf0 (diff)
downloadwebtools.dali-bf3c28fe5902eb91a46a9e38c00667e85e37fcdd.tar.gz
webtools.dali-bf3c28fe5902eb91a46a9e38c00667e85e37fcdd.tar.xz
webtools.dali-bf3c28fe5902eb91a46a9e38c00667e85e37fcdd.zip
[272752] improve interaction with Java change events
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JptUiPlugin.java')
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JptUiPlugin.java98
1 files changed, 97 insertions, 1 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JptUiPlugin.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JptUiPlugin.java
index ebbfc821be..e24a78f905 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JptUiPlugin.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JptUiPlugin.java
@@ -13,10 +13,17 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jpt.core.JpaPlatform;
+import org.eclipse.jpt.core.internal.JpaModelManager;
import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry;
import org.eclipse.jpt.ui.navigator.JpaNavigatorProvider;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
/**
*
@@ -30,13 +37,18 @@ import org.eclipse.ui.plugin.AbstractUIPlugin;
@SuppressWarnings("nls")
public class JptUiPlugin extends AbstractUIPlugin
{
+ private final Listener focusListener;
+
private static JptUiPlugin INSTANCE;
/**
* The plug-in identifier of JPA UI support
* (value <code>"org.eclipse.jpt.ui"</code>).
*/
- public final static String PLUGIN_ID = "org.eclipse.jpt.ui"; //$NON-NLS-1$
+ public static final String PLUGIN_ID = "org.eclipse.jpt.ui"; //$NON-NLS-1$
+
+ private static final String FOCUS_DATA_KEY = PLUGIN_ID + ".focus";
+ private static final Object FOCUS_DATA = new Object();
/**
* Returns the singleton JPT UI plug-in.
@@ -86,9 +98,68 @@ public class JptUiPlugin extends AbstractUIPlugin
public JptUiPlugin() {
super();
+ this.focusListener = this.buildFocusListener();
INSTANCE = this;
}
+ private Listener buildFocusListener() {
+ return new Listener() {
+ public void handleEvent(Event event) {
+ JptUiPlugin.this.focusIn((Control) event.widget);
+ }
+ };
+ }
+
+ /**
+ * This method is called whenever a "focus in" event is generated.
+ * If the control gaining focus is part of one of our composites (typically
+ * a JPA Details View), we stop listening to Java change events
+ * (and assume all changes to the Java model are generated by us).
+ * If the control gaining focus is *not* part of one of our composites,
+ * we start listening to the Java change events again.
+ */
+ void focusIn(Control control) {
+ while (control != null) {
+ if (control.getData(FOCUS_DATA_KEY) == FOCUS_DATA) {
+ this.focusIn();
+ return;
+ }
+ control = control.getParent();
+ }
+ this.focusOut();
+ }
+
+ /**
+ * This method is called whenever a Dali UI control that affects Java
+ * source code gains the UI focus. When this happens we deactivate
+ * the Dali Java change listener so we ignore any changes to the Java
+ * source code that probably originated from Dali. This means we will miss
+ * any changes to the Java source code that is caused by non-UI activity;
+ * but, we hope, these changes are unrelated to JPA annotations etc.
+ * @see #focusOut()
+ */
+ private void focusIn() {
+ JpaModelManager.instance().setJavaElementChangeListenerIsActive(false);
+ }
+
+ /**
+ * This method is called whenever a non-Dali UI control gains the UI focus.
+ * When this happens we activate the Dali Java change listener so that we
+ * begin to keep the Dali model synchronized with the Java source code.
+ * @see #focusIn()
+ */
+ private void focusOut() {
+ JpaModelManager.instance().setJavaElementChangeListenerIsActive(true);
+ }
+
+ /**
+ * Tag the specified control so that whenever it (or any of its children,
+ * grandchildren, etc.) has the focus, the Dali model ignores any Java
+ * change events.
+ */
+ public void controlAffectsJavaSource(Control control) {
+ control.setData(FOCUS_DATA_KEY, FOCUS_DATA);
+ }
/**
* Return the JPA platform UI corresponding to the given JPA platform
@@ -102,4 +173,29 @@ public class JptUiPlugin extends AbstractUIPlugin
return platform == null ? null : platform.getNavigatorProvider();
}
+
+ // ********** plug-in implementation **********
+
+ /**
+ * Register our SWT listener with the display so we receive notification
+ * of every "focus in" event.
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ Display.getDefault().addFilter(SWT.FocusIn, this.focusListener);
+ }
+
+ /**
+ * Unregister our SWT listener with the display.
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ try {
+ Display.getDefault().removeFilter(SWT.FocusIn, this.focusListener);
+ } finally {
+ super.stop(context);
+ }
+ }
+
}

Back to the top