|
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.handleFocusEvent(event); |
| 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 handleFocusEvent(Event event) { |
| 122 |
Control control = (Control) event.widget; |
| 123 |
while (control != null) { |
| 124 |
if (control.getData(FOCUS_DATA_KEY) == FOCUS_DATA) { |
| 125 |
this.focusIn(); |
| 126 |
return; |
| 127 |
} |
| 128 |
control = control.getParent(); |
| 129 |
} |
| 130 |
this.focusOut(); |
| 131 |
} |
| 132 |
|
| 133 |
private void focusIn() { |
| 134 |
JpaModelManager.instance().setJavaElementChangeListenerIsActive(false); |
| 135 |
} |
| 136 |
|
| 137 |
private void focusOut() { |
| 138 |
JpaModelManager.instance().setJavaElementChangeListenerIsActive(true); |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Tag the specified control so that whenever it (or any of its children, |
| 143 |
* grandchildren, etc.) has the focus, the Dali model ignores any Java |
| 144 |
* change events. |
| 145 |
*/ |
| 146 |
public void tagControl(Control control) { |
| 147 |
control.setData(FOCUS_DATA_KEY, FOCUS_DATA); |
| 148 |
} |
| 92 |
|
149 |
|
| 93 |
/** |
150 |
/** |
| 94 |
* Return the JPA platform UI corresponding to the given JPA platform |
151 |
* Return the JPA platform UI corresponding to the given JPA platform |
|
Lines 102-105
Link Here
|
| 102 |
return platform == null ? null : platform.getNavigatorProvider(); |
159 |
return platform == null ? null : platform.getNavigatorProvider(); |
| 103 |
} |
160 |
} |
| 104 |
|
161 |
|
|
|
162 |
|
| 163 |
// ********** plug-in implementation ********** |
| 164 |
|
| 165 |
@Override |
| 166 |
public void start(BundleContext context) throws Exception { |
| 167 |
super.start(context); |
| 168 |
Display.getDefault().addFilter(SWT.FocusIn, this.focusListener); |
| 169 |
} |
| 170 |
|
| 171 |
@Override |
| 172 |
public void stop(BundleContext context) throws Exception { |
| 173 |
try { |
| 174 |
Display.getDefault().removeFilter(SWT.FocusIn, this.focusListener); |
| 175 |
} finally { |
| 176 |
super.stop(context); |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 105 |
} |
180 |
} |