Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Butzke2012-09-18 19:50:02 +0000
committerKaren Butzke2012-09-18 19:50:02 +0000
commita588d2c21918e52166fc5dfb193da389b082c0e5 (patch)
treed5325cbf114e2c172f0681f2ad2cd6a6faf4ac2e
parentb5c90da8bd98275fa0f0625e96b61674cc95fba5 (diff)
downloadwebtools.dali-a588d2c21918e52166fc5dfb193da389b082c0e5.tar.gz
webtools.dali-a588d2c21918e52166fc5dfb193da389b082c0e5.tar.xz
webtools.dali-a588d2c21918e52166fc5dfb193da389b082c0e5.zip
Fixed selection issues editing in the JPA Details view and the Java source that were caused by my changes to not build a CompilationUnit during validation, code completion or selection changes.
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/plugin/JptJpaUiPlugin.java44
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaTextEditorManager.java13
3 files changed, 64 insertions, 6 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
index 672b586cab..e0ee3e113e 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
@@ -937,7 +937,20 @@ public abstract class AbstractJavaPersistentType
return JavaPersistentType.class;
}
+ /**
+ * This method is called by JpaTextEditorManager only when the focus is not in the JPA Details view.
+ * See JptJpaUiPlugin.getFocusIsNonDali()
+ * <p>
+ * We are suppressing java events when the focus is in the JPA Details view so we don't
+ * want this synchronizeWithJavaSource() to be called in that case.
+ * When the user moves from the JPA Details view back to the Java source we need to call
+ * synchronizeWithJavaSource() in order for our cached text ranges to be updated appropriately.
+ * <p>
+ * Also need the synchronizeWithJavaSource() when editing directly in the java source,
+ * the textRange gets updated after the java delay which is after we are notified of a selection change.
+ */
public JpaStructureNode getStructureNode(int offset) {
+ this.resourceType.getJavaResourceCompilationUnit().synchronizeWithJavaSource();
if (this.contains(offset)) {
for (JavaPersistentAttribute persistentAttribute : this.getAttributes()) {
if (persistentAttribute.contains(offset)) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/plugin/JptJpaUiPlugin.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/plugin/JptJpaUiPlugin.java
index f52a36aaed..de2d6ae35b 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/plugin/JptJpaUiPlugin.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/plugin/JptJpaUiPlugin.java
@@ -12,6 +12,7 @@ package org.eclipse.jpt.jpa.ui.internal.plugin;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jpt.common.core.internal.utility.JptPlugin;
import org.eclipse.jpt.common.ui.internal.JptUIPlugin;
+import org.eclipse.jpt.common.utility.BooleanReference;
import org.eclipse.jpt.common.utility.internal.AbstractBooleanReference;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.JpaProjectManager;
@@ -37,7 +38,8 @@ public class JptJpaUiPlugin
/**
* @see #focusIn(Control)
*/
- private final AsyncEventListenerFlag asyncEventListenerFlag = new AsyncEventListenerFlag();
+ private final ControlIsNonDaliListenerFlag controlIsNonDaliFlag = new ControlIsNonDaliListenerFlag();
+ private final AsyncEventListenerFlag asyncEventListenerFlag = new AsyncEventListenerFlag(this.controlIsNonDaliFlag);
private Display display;
private final Listener focusListener = new FocusListener();
@@ -132,6 +134,16 @@ public class JptJpaUiPlugin
// ********** focus event handling **********
/**
+ * Return true if the focus is not in a Dali view.
+ * <p>
+ * Currently only the JpaTextEditorManager is using this listen
+ * to TextEditor selection change events if the focus is in the JPA Details view.
+ */
+ public boolean getFocusIsNonDali() {
+ return this.controlIsNonDaliFlag.getValue();
+ }
+
+ /**
* This method is called whenever a {@link SWT#FocusIn} event is generated.
* <p>
* If the control gaining focus is part of one the Dali composites
@@ -148,7 +160,7 @@ public class JptJpaUiPlugin
* to keep the Dali model synchronized with the Java source code.
*/
/* CU private */ void focusIn(Control control) {
- this.asyncEventListenerFlag.setValue(this.controlIsNonDali(control));
+ this.controlIsNonDaliFlag.setValue(this.controlIsNonDali(control));
}
/**
@@ -211,21 +223,43 @@ public class JptJpaUiPlugin
/* CU private */ static class AsyncEventListenerFlag
extends AbstractBooleanReference
{
- private volatile boolean value = true;
+ private final BooleanReference controlIsNonDaliListenerFlag;
@SuppressWarnings("restriction")
private static final String JAVA_RECONCILER_THREAD_NAME = org.eclipse.jdt.internal.ui.text.JavaReconciler.class.getName();
- AsyncEventListenerFlag() {
+ AsyncEventListenerFlag(BooleanReference controlIsNonDaliListenerFlag) {
super();
+ this.controlIsNonDaliListenerFlag = controlIsNonDaliListenerFlag;
}
public boolean getValue() {
if (Thread.currentThread().getName().equals(JAVA_RECONCILER_THREAD_NAME)) {
- return this.value;
+ return this.controlIsNonDaliListenerFlag.getValue();
}
return true;
}
+ }
+
+ // ********** control is non dali listener listener flag **********
+
+ /**
+ * This flag's value is determined by the current UI focus (i.e. whether the
+ * focus is somewhere other than a Dali view, currently only the JPA Details view);
+ * otherwise the flag's value is <code>true</code>.
+ */
+ /* CU private */ static class ControlIsNonDaliListenerFlag
+ extends AbstractBooleanReference
+ {
+ private volatile boolean value = true;
+
+ ControlIsNonDaliListenerFlag() {
+ super();
+ }
+
+ public boolean getValue() {
+ return this.value;
+ }
public boolean setValue(boolean value) {
boolean old = this.value;
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaTextEditorManager.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaTextEditorManager.java
index 9ecbd7959f..780156e8c3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaTextEditorManager.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaTextEditorManager.java
@@ -34,6 +34,7 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.ui.JpaFileModel;
+import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.selection.JpaEditorManager;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
@@ -217,7 +218,17 @@ class JpaTextEditorManager
{
@Override
public void selectionChanged(SelectionChangedEvent event) {
- JpaTextEditorManager.this.setJpaSelection(event.getSelection());
+ //If the focus is in the JPA Details view we do not want to handle
+ //TextEditor selection events. When in the Details View we are not
+ //listening for java change events so our cached text ranges are not updated.
+ //We do not want the selection to change while editing in the details view
+ //or the details view can be changed out from under us.
+ //AbstractJavaPersistentType.getStructureNode(int) will cause a
+ //synchronizeWithJavaSource() to be run, and we don't want that to happen
+ //when we have focus.
+ if (JptJpaUiPlugin.instance().getFocusIsNonDali()) {
+ JpaTextEditorManager.this.setJpaSelection(event.getSelection());
+ }
}
}

Back to the top