Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2008-05-14 15:52:48 +0000
committerpfullbright2008-05-14 15:52:48 +0000
commit96dd9ffe320fbd6ba7076c12b95bdccb162ddd38 (patch)
tree6d180b74129d94a6da41ef44aefd3ccf1a4a2ade
parent6e7f7339faeea9608f0e79c1b554ec19a30a2842 (diff)
downloadwebtools.dali-96dd9ffe320fbd6ba7076c12b95bdccb162ddd38.tar.gz
webtools.dali-96dd9ffe320fbd6ba7076c12b95bdccb162ddd38.tar.xz
webtools.dali-96dd9ffe320fbd6ba7076c12b95bdccb162ddd38.zip
[Bug 226571] - Text editor selection problems when text editor not active
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/DefaultJpaSelectionManager.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionManager.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/TextEditorSelectionParticipant.java55
3 files changed, 63 insertions, 4 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/DefaultJpaSelectionManager.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/DefaultJpaSelectionManager.java
index 086916d39c..b83bca658a 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/DefaultJpaSelectionManager.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/DefaultJpaSelectionManager.java
@@ -152,6 +152,10 @@ public class DefaultJpaSelectionManager
initPart(part);
}
+ public boolean isRegistered(IWorkbenchPart part) {
+ return selectionParticipants.get(part) != null;
+ }
+
public void select(JpaSelection newSelection, JpaSelectionParticipant source) {
if (currentSelection.equals(newSelection)) {
return;
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionManager.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionManager.java
index 0f4ba317f2..6ee3e33728 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionManager.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionManager.java
@@ -47,5 +47,11 @@ public interface JpaSelectionManager
* It should not be necessary to deregister a part, as that happens when the
* part is closed.
*/
- public void register(IWorkbenchPart part);
+ public void register(IWorkbenchPart part);
+
+ /**
+ * Returns true if the part is currently registered to respond to selections
+ * from this selection manager
+ */
+ public boolean isRegistered(IWorkbenchPart part);
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/TextEditorSelectionParticipant.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/TextEditorSelectionParticipant.java
index e838e26d78..1178f05401 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/TextEditorSelectionParticipant.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/TextEditorSelectionParticipant.java
@@ -22,6 +22,8 @@ import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IPropertyListener;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.texteditor.ITextEditor;
public class TextEditorSelectionParticipant
@@ -59,16 +61,21 @@ public class TextEditorSelectionParticipant
public void selectionChanged(JpaSelectionEvent evt) {
JpaSelection newSelection = evt.getSelection();
-
+
if ((newSelection == JpaSelection.NULL_SELECTION)
|| newSelection.equals(this.currentSelection)) {
return;
}
-
+
+ if (getActiveTextEditor() != textEditor) {
+ return;
+ }
+
this.forwardSelection = false;
TextRange textRange = newSelection.getSelectedNode().getSelectionTextRange();
if (textRange != null) {
this.textEditor.selectAndReveal(textRange.getOffset(), textRange.getLength());
+ this.currentSelection = newSelection;
}
this.forwardSelection = true;
}
@@ -103,7 +110,29 @@ public class TextEditorSelectionParticipant
return new DefaultJpaSelection(selectedNode);
}
-
+
+ private IWorkbenchPage getActivePage() {
+ return textEditor.getEditorSite().getWorkbenchWindow().getActivePage();
+ }
+
+ private IWorkbenchPart getActivePart() {
+ IWorkbenchPage activePage = getActivePage();
+ return (activePage == null) ? null: activePage.getActivePart();
+ }
+
+ private IEditorPart getActiveEditor() {
+ IWorkbenchPage activePage = getActivePage();
+ return (activePage == null) ? null: activePage.getActiveEditor();
+ }
+
+ private ITextEditor getActiveTextEditor() {
+ return getTextEditor(getActiveEditor());
+ }
+
+ private ITextEditor getTextEditor(IWorkbenchPart part) {
+ return (part == null) ? null : (ITextEditor) part.getAdapter(ITextEditor.class);
+ }
+
private JpaFile jpaFile() {
IEditorInput input = this.textEditor.getEditorInput();
if ( ! (input instanceof IFileEditorInput)) {
@@ -132,6 +161,26 @@ public class TextEditorSelectionParticipant
}
void editorSelectionChanged(SelectionChangedEvent event) {
+ // This is a bit kludgey. We check to see if the selection event
+ // occurred when a participating part is active (and so, ostensibly,
+ // *because* of the participating part). If so, we reselect the valid
+ // text.
+ IWorkbenchPart activePart = getActivePart();
+ if (getTextEditor(activePart) != textEditor && selectionManager.isRegistered(activePart)) {
+ if (currentSelection.isEmpty()) {
+ return;
+ }
+
+ this.forwardSelection = false;
+ TextRange textRange = currentSelection.getSelectedNode().getSelectionTextRange();
+ if (textRange != null) {
+ this.textEditor.selectAndReveal(textRange.getOffset(), textRange.getLength());
+ }
+ this.forwardSelection = true;
+
+ return;
+ }
+
JpaSelection newSelection = this.calculateSelection();
if (newSelection.equals(this.currentSelection)) {
return;

Back to the top