|
34 | 34 | import org.eclipse.jface.text.source.projection.ProjectionSupport;
|
35 | 35 | import org.eclipse.jface.text.source.projection.ProjectionViewer;
|
36 | 36 | import org.eclipse.jface.util.PropertyChangeEvent;
|
| 37 | +import org.eclipse.jface.viewers.IPostSelectionProvider; |
| 38 | +import org.eclipse.jface.viewers.ISelectionChangedListener; |
| 39 | +import org.eclipse.jface.viewers.ISelectionProvider; |
37 | 40 | import org.eclipse.swt.custom.StyledText;
|
38 | 41 | import org.eclipse.swt.graphics.Point;
|
39 | 42 | import org.eclipse.swt.widgets.Composite;
|
@@ -81,6 +84,52 @@ public class JavaScriptLightWeightEditor extends AbstractDecoratedTextEditor {
|
81 | 84 | /** The bracket inserter. */
|
82 | 85 | private BracketInserter fBracketInserter = new BracketInserter(this);
|
83 | 86 |
|
| 87 | + /** |
| 88 | + * Internal implementation class for a change listener. |
| 89 | + * |
| 90 | + */ |
| 91 | + protected abstract class AbstractSelectionChangedListener implements ISelectionChangedListener { |
| 92 | + |
| 93 | + /** |
| 94 | + * Installs this selection changed listener with the given selection |
| 95 | + * provider. If the selection provider is a post selection provider, |
| 96 | + * post selection changed events are the preferred choice, otherwise |
| 97 | + * normal selection changed events are requested. |
| 98 | + * |
| 99 | + * @param selectionProvider |
| 100 | + */ |
| 101 | + public void install(ISelectionProvider selectionProvider) { |
| 102 | + if (selectionProvider == null) |
| 103 | + return; |
| 104 | + |
| 105 | + if (selectionProvider instanceof IPostSelectionProvider) { |
| 106 | + IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider; |
| 107 | + provider.addPostSelectionChangedListener(this); |
| 108 | + } else { |
| 109 | + selectionProvider.addSelectionChangedListener(this); |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Removes this selection changed listener from the given selection |
| 115 | + * provider. |
| 116 | + * |
| 117 | + * @param selectionProvider |
| 118 | + * the selection provider |
| 119 | + */ |
| 120 | + public void uninstall(ISelectionProvider selectionProvider) { |
| 121 | + if (selectionProvider == null) |
| 122 | + return; |
| 123 | + |
| 124 | + if (selectionProvider instanceof IPostSelectionProvider) { |
| 125 | + IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider; |
| 126 | + provider.removePostSelectionChangedListener(this); |
| 127 | + } else { |
| 128 | + selectionProvider.removeSelectionChangedListener(this); |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + |
84 | 133 | /**
|
85 | 134 | * This editor's projection support
|
86 | 135 | *
|
|
0 commit comments