Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 272752 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jpt/ui/internal/views/AbstractJpaView.java (-2 / +5 lines)
Lines 8-13 Link Here
8
 ********************************************************************************/
8
 ********************************************************************************/
9
package org.eclipse.jpt.ui.internal.views;
9
package org.eclipse.jpt.ui.internal.views;
10
10
11
import org.eclipse.jpt.ui.JptUiPlugin;
11
import org.eclipse.jpt.ui.WidgetFactory;
12
import org.eclipse.jpt.ui.WidgetFactory;
12
import org.eclipse.jpt.ui.internal.selection.JpaSelection;
13
import org.eclipse.jpt.ui.internal.selection.JpaSelection;
13
import org.eclipse.jpt.ui.internal.selection.JpaSelectionManager;
14
import org.eclipse.jpt.ui.internal.selection.JpaSelectionManager;
Lines 81-86 Link Here
81
	@Override
82
	@Override
82
	public final void createPartControl(Composite parent) {
83
	public final void createPartControl(Composite parent) {
83
		this.scrolledForm = getFormWidgetFactory().createScrolledForm(parent);
84
		this.scrolledForm = getFormWidgetFactory().createScrolledForm(parent);
85
		JptUiPlugin.instance().tagControl(this.scrolledForm);
84
		this.scrolledForm.getBody().setLayout(new GridLayout());
86
		this.scrolledForm.getBody().setLayout(new GridLayout());
85
87
86
		this.pageBook = new PageBook(this.scrolledForm.getBody(), SWT.NONE);
88
		this.pageBook = new PageBook(this.scrolledForm.getBody(), SWT.NONE);
Lines 157-163 Link Here
157
		this.scrolledForm.reflow(true);
159
		this.scrolledForm.reflow(true);
158
	}
160
	}
159
161
160
	protected void subcreatePartControl(Composite parent) {
162
	protected void subcreatePartControl(@SuppressWarnings("unused") Composite parent) {
161
		// no op - for subclasses to override if wished
163
		// no op - for subclasses to override if wished
162
	}
164
	}
163
}
165
166
}
(-)src/org/eclipse/jpt/ui/JptUiPlugin.java (-1 / +76 lines)
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
}
(-)src/org/eclipse/jpt/core/internal/JpaModelManager.java (+19 lines)
Lines 89-94 Link Here
89
	 * which will forward them to the JPA projects.
89
	 * which will forward them to the JPA projects.
90
	 */
90
	 */
91
	private final IElementChangedListener javaElementChangeListener;
91
	private final IElementChangedListener javaElementChangeListener;
92
	private boolean javaElementChangeListenerIsActive;
92
	
93
	
93
	
94
	
94
	// ********** singleton **********
95
	// ********** singleton **********
Lines 113-118 Link Here
113
		this.resourceChangeListener = new ResourceChangeListener();
114
		this.resourceChangeListener = new ResourceChangeListener();
114
		this.facetedProjectListener = new FacetedProjectListener();
115
		this.facetedProjectListener = new FacetedProjectListener();
115
		this.javaElementChangeListener = new JavaElementChangeListener();
116
		this.javaElementChangeListener = new JavaElementChangeListener();
117
		this.javaElementChangeListenerIsActive = true;
116
	}
118
	}
117
119
118
120
Lines 186-191 Link Here
186
	}
188
	}
187
189
188
	/**
190
	/**
191
	 * Return whether the model manager's Java change listener is active.
192
	 */
193
	public boolean javaElementChangeListenerIsActive() {
194
		return this.javaElementChangeListenerIsActive;
195
	}
196
197
	/**
198
	 * Set whether the model manager's Java change listener is active.
199
	 */
200
	public void setJavaElementChangeListenerIsActive(boolean javaElementChangeListenerIsActive) {
201
		this.javaElementChangeListenerIsActive = javaElementChangeListenerIsActive;
202
	}
203
204
	/**
189
	 * Log the specified status.
205
	 * Log the specified status.
190
	 */
206
	 */
191
	public void log(IStatus status) {
207
	public void log(IStatus status) {
Lines 454-459 Link Here
454
	 * Forward the event to the JPA model.
470
	 * Forward the event to the JPA model.
455
	 */
471
	 */
456
	/* private */ void javaElementChanged(ElementChangedEvent event) {
472
	/* private */ void javaElementChanged(ElementChangedEvent event) {
473
		if ( ! this.javaElementChangeListenerIsActive) {
474
			return;  // ignore Java events
475
		}
457
		if (this.eventIndicatesProjectAddedButNotOpen(event)) {
476
		if (this.eventIndicatesProjectAddedButNotOpen(event)) {
458
			return;
477
			return;
459
		}
478
		}

Return to bug 272752