|
Lines 13-22
Link Here
|
| 13 |
import org.eclipse.core.runtime.Status; |
13 |
import org.eclipse.core.runtime.Status; |
| 14 |
import org.eclipse.jface.resource.ImageDescriptor; |
14 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 15 |
import org.eclipse.jpt.core.JpaPlatform; |
15 |
import org.eclipse.jpt.core.JpaPlatform; |
|
|
16 |
import org.eclipse.jpt.core.internal.JpaModelManager; |
| 16 |
import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; |
17 |
import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; |
| 17 |
import org.eclipse.jpt.ui.navigator.JpaNavigatorProvider; |
18 |
import org.eclipse.jpt.ui.navigator.JpaNavigatorProvider; |
|
|
19 |
import org.eclipse.swt.SWT; |
| 18 |
import org.eclipse.swt.graphics.Image; |
20 |
import org.eclipse.swt.graphics.Image; |
|
|
21 |
import org.eclipse.swt.widgets.Control; |
| 22 |
import org.eclipse.swt.widgets.Display; |
| 23 |
import org.eclipse.swt.widgets.Event; |
| 24 |
import org.eclipse.swt.widgets.Listener; |
| 19 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
25 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
|
26 |
import org.osgi.framework.BundleContext; |
| 20 |
|
27 |
|
| 21 |
/** |
28 |
/** |
| 22 |
* |
29 |
* |
|
Lines 30-42
Link Here
|
| 30 |
@SuppressWarnings("nls") |
37 |
@SuppressWarnings("nls") |
| 31 |
public class JptUiPlugin extends AbstractUIPlugin |
38 |
public class JptUiPlugin extends AbstractUIPlugin |
| 32 |
{ |
39 |
{ |
|
|
40 |
private final Listener focusListener; |
| 41 |
|
| 33 |
private static JptUiPlugin INSTANCE; |
42 |
private static JptUiPlugin INSTANCE; |
| 34 |
|
43 |
|
| 35 |
/** |
44 |
/** |
| 36 |
* The plug-in identifier of JPA UI support |
45 |
* The plug-in identifier of JPA UI support |
| 37 |
* (value <code>"org.eclipse.jpt.ui"</code>). |
46 |
* (value <code>"org.eclipse.jpt.ui"</code>). |
| 38 |
*/ |
47 |
*/ |
| 39 |
public final static String PLUGIN_ID = "org.eclipse.jpt.ui"; //$NON-NLS-1$ |
48 |
public static final String PLUGIN_ID = "org.eclipse.jpt.ui"; //$NON-NLS-1$ |
|
|
49 |
|
| 50 |
private static final String FOCUS_DATA_KEY = PLUGIN_ID + ".focus"; |
| 51 |
private static final Object FOCUS_DATA = new Object(); |
| 40 |
|
52 |
|
| 41 |
/** |
53 |
/** |
| 42 |
* Returns the singleton JPT UI plug-in. |
54 |
* Returns the singleton JPT UI plug-in. |
|
Lines 86-94
Link Here
|
| 86 |
|
98 |
|
| 87 |
public JptUiPlugin() { |
99 |
public JptUiPlugin() { |
| 88 |
super(); |
100 |
super(); |
|
|
101 |
this.focusListener = this.buildFocusListener(); |
| 89 |
INSTANCE = this; |
102 |
INSTANCE = this; |
| 90 |
} |
103 |
} |
| 91 |
|
104 |
|
|
|
105 |
private Listener buildFocusListener() { |
| 106 |
return new Listener() { |
| 107 |
public void handleEvent(Event event) { |
| 108 |
JptUiPlugin.this.focusIn((Control) event.widget); |
| 109 |
} |
| 110 |
}; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* This method is called whenever a "focus in" event is generated. |
| 115 |
* If the control gaining focus is part of one of our composites (typically |
| 116 |
* a JPA Details View), we stop listening to Java change events |
| 117 |
* (and assume all changes to the Java model are generated by us). |
| 118 |
* If the control gaining focus is *not* part of one of our composites, |
| 119 |
* we start listening to the Java change events again. |
| 120 |
*/ |
| 121 |
void focusIn(Control control) { |
| 122 |
while (control != null) { |
| 123 |
if (control.getData(FOCUS_DATA_KEY) == FOCUS_DATA) { |
| 124 |
this.focusIn(); |
| 125 |
return; |
| 126 |
} |
| 127 |
control = control.getParent(); |
| 128 |
} |
| 129 |
this.focusOut(); |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* This method is called whenever a Dali UI control that affects Java |
| 134 |
* source code gains the UI focus. When this happens we deactivate |
| 135 |
* the Dali Java change listener so we ignore any changes to the Java |
| 136 |
* source code that probably originated from Dali. This means we will miss |
| 137 |
* any changes to the Java source code that is caused by non-UI activity; |
| 138 |
* but, we hope, these changes are unrelated to JPA annotations etc. |
| 139 |
* @see #focusOut() |
| 140 |
*/ |
| 141 |
private void focusIn() { |
| 142 |
JpaModelManager.instance().setJavaElementChangeListenerIsActive(false); |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* This method is called whenever a non-Dali UI control gains the UI focus. |
| 147 |
* When this happens we activate the Dali Java change listener so that we |
| 148 |
* begin to keep the Dali model synchronized with the Java source code. |
| 149 |
* @see #focusIn() |
| 150 |
*/ |
| 151 |
private void focusOut() { |
| 152 |
JpaModelManager.instance().setJavaElementChangeListenerIsActive(true); |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* Tag the specified control so that whenever it (or any of its children, |
| 157 |
* grandchildren, etc.) has the focus, the Dali model ignores any Java |
| 158 |
* change events. |
| 159 |
*/ |
| 160 |
public void controlAffectsJavaSource(Control control) { |
| 161 |
control.setData(FOCUS_DATA_KEY, FOCUS_DATA); |
| 162 |
} |
| 92 |
|
163 |
|
| 93 |
/** |
164 |
/** |
| 94 |
* Return the JPA platform UI corresponding to the given JPA platform |
165 |
* Return the JPA platform UI corresponding to the given JPA platform |
|
Lines 102-105
Link Here
|
| 102 |
return platform == null ? null : platform.getNavigatorProvider(); |
173 |
return platform == null ? null : platform.getNavigatorProvider(); |
| 103 |
} |
174 |
} |
| 104 |
|
175 |
|
|
|
176 |
|
| 177 |
// ********** plug-in implementation ********** |
| 178 |
|
| 179 |
/** |
| 180 |
* Register our SWT listener with the display so we receive notification |
| 181 |
* of every "focus in" event. |
| 182 |
*/ |
| 183 |
@Override |
| 184 |
public void start(BundleContext context) throws Exception { |
| 185 |
super.start(context); |
| 186 |
Display.getDefault().addFilter(SWT.FocusIn, this.focusListener); |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Unregister our SWT listener with the display. |
| 191 |
*/ |
| 192 |
@Override |
| 193 |
public void stop(BundleContext context) throws Exception { |
| 194 |
try { |
| 195 |
Display.getDefault().removeFilter(SWT.FocusIn, this.focusListener); |
| 196 |
} finally { |
| 197 |
super.stop(context); |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 105 |
} |
201 |
} |