@@ -46,9 +46,9 @@ public class AnnotationManager implements ISelectionChangedListener {
4646 private SourceViewer sourceViewer ;
4747 private ProgramNavigationPainter painter ;
4848 private static boolean isActive = false ;
49+ private boolean isEnabled ;
4950 private IBreadcrumb upBreadcrumb ;
5051 private IBreadcrumb downBreadcrumb ;
51- private ShowDataInBreadcrumbAction crumbs ;
5252
5353 // the visitor for the editor
5454 private Visitor visitor ;
@@ -62,6 +62,7 @@ public class AnnotationManager implements ISelectionChangedListener {
6262 * @param anEditor
6363 */
6464 public AnnotationManager (AbstractDecoratedTextEditor anEditor ) {
65+ isEnabled = true ;
6566 parseCU (anEditor );
6667 sourceViewer = EclipseHacks .getSourceViewer (anEditor );
6768 painter = new ProgramNavigationPainter (sourceViewer );
@@ -72,74 +73,74 @@ public AnnotationManager(AbstractDecoratedTextEditor anEditor) {
7273
7374 public void selectionChanged (ITextSelection selection ) {
7475 painter .removeAllAnnotations ();
75- try {
76- DataNode one = getNode (selection .getOffset ());
77- Finder finder = Finder .getInstance ();
78- if (one != null ) {
79- addAnnotation (one );
80- currentSearch = one .getKey ();
81- linkAnnotation .setDataNode (one );
82- IWorkbenchPage activePage = PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getActivePage ();
83- IEditorPart activeEditor = activePage .getActiveEditor ();
84- JavaEditor j = (JavaEditor ) activeEditor ;
85- upBreadcrumb = j .getBreadcrumb ();
86- downBreadcrumb = j .getBreadcrumb2 ();
87- if (!isActive ) {
88- isActive = true ;
89- upBreadcrumb .setText (null );
90- downBreadcrumb .setText (null );
91- crumbs = new ShowDataInBreadcrumbAction (j , activePage );
92- crumbs .run ();
93- }
94- DataCallHierarchy call = new DataCallHierarchy ();
95- Set <IMethod > searchUp = null ;
96- Set <IMethod > searchDown = null ;
97- if ((finder .upSearch (one ) != null || finder .downSearch (one ) != null || one .getInvocationMethod () != null ) && currentSearch != null ) {
98- searchUp = call .searchProject (one , Finder .UP );
99- searchDown = call .searchProject (one , Finder .DOWN );
100- if (one .isParameterSelected (selection .getOffset ())) {
101- linkAnnotation .searchResultsDown = searchDown ;
102- linkAnnotation .searchResultsUp = searchUp ;
103- addLinkAnnotation (one );
76+ if (isEnabled ) {
77+ try {
78+ DataNode one = getNode (selection .getOffset ());
79+ Finder finder = Finder .getInstance ();
80+ if (one != null ) {
81+ addAnnotation (one );
82+ currentSearch = one .getKey ();
83+ linkAnnotation .setDataNode (one );
84+ IWorkbenchPage activePage = PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getActivePage ();
85+ IEditorPart activeEditor = activePage .getActiveEditor ();
86+ JavaEditor j = (JavaEditor ) activeEditor ;
87+ upBreadcrumb = j .getBreadcrumb ();
88+ downBreadcrumb = j .getBreadcrumb2 ();
89+ if (!isActive ) {
90+ isActive = true ;
91+ upBreadcrumb .setText (null );
92+ downBreadcrumb .setText (null );
10493 }
105- }
106-
107- //Adds all occurrences of data node off screen
108- ArrayList <Object > textUp = new ArrayList <Object >();
109- ArrayList <Object > textDown = new ArrayList <Object >();
110- for (DataNode dn : finder .getOccurrences (new Position (one .getStartPosition (), one .getLength ()))) {
111- addLinkAnnotation (dn );
112- int [] offScreen = new int [3 ];
113- int line = sourceViewer .widgetLineOfWidgetOffset (dn .getStartPosition ())+1 ;
114- offScreen [0 ] = line ;
115- offScreen [1 ] = dn .getStartPosition ();
116- offScreen [2 ] = dn .getLength ();
117- if (dn .getStartPosition () < sourceViewer .getTopIndexStartOffset ()) {
118- textUp .add (offScreen );
94+ DataCallHierarchy call = new DataCallHierarchy ();
95+ Set <IMethod > searchUp = null ;
96+ Set <IMethod > searchDown = null ;
97+ if ((finder .upSearch (one ) != null || finder .downSearch (one ) != null || one .getInvocationMethod () != null ) && currentSearch != null ) {
98+ searchUp = call .searchProject (one , Finder .UP );
99+ searchDown = call .searchProject (one , Finder .DOWN );
100+ if (one .isParameterSelected (selection .getOffset ())) {
101+ linkAnnotation .searchResultsDown = searchDown ;
102+ linkAnnotation .searchResultsUp = searchUp ;
103+ addLinkAnnotation (one );
104+ }
119105 }
120- else if (dn .getStartPosition () > sourceViewer .getBottomIndexEndOffset ()) {
121- textDown .add (offScreen );
106+
107+ //Adds all occurrences of data node off screen
108+ ArrayList <Object > textUp = new ArrayList <Object >();
109+ ArrayList <Object > textDown = new ArrayList <Object >();
110+ for (DataNode dn : finder .getOccurrences (new Position (one .getStartPosition (), one .getLength ()))) {
111+ addLinkAnnotation (dn );
112+ int [] offScreen = new int [3 ];
113+ int line = sourceViewer .widgetLineOfWidgetOffset (dn .getStartPosition ())+1 ;
114+ offScreen [0 ] = line ;
115+ offScreen [1 ] = dn .getStartPosition ();
116+ offScreen [2 ] = dn .getLength ();
117+ if (dn .getStartPosition () < sourceViewer .getTopIndexStartOffset ()) {
118+ textUp .add (offScreen );
119+ }
120+ else if (dn .getStartPosition () > sourceViewer .getBottomIndexEndOffset ()) {
121+ textDown .add (offScreen );
122+ }
122123 }
124+ if (searchUp != null ) {
125+ textUp .addAll (searchUp );
126+ ((EditorBreadcrumb )upBreadcrumb ).setSearchMethod (call .getCurrentMethod (one .getStartPosition ()));
127+ ((EditorBreadcrumb )upBreadcrumb ).setSearchIndex (one .getParameterIndex ());
128+ linkAnnotation .setSearchMethod (call .getCurrentMethod (one .getStartPosition ()));
129+ }
130+ if (searchDown != null ) {
131+ textDown .addAll (searchDown );
132+ ((EditorBreadcrumb )downBreadcrumb ).setSearchIndex (one .getParameterIndex ());
133+ }
134+ upBreadcrumb .setText (textUp );
135+ downBreadcrumb .setText (textDown );
123136 }
124- if (searchUp != null ) {
125- textUp .addAll (searchUp );
126- ((EditorBreadcrumb )upBreadcrumb ).setSearchMethod (call .getCurrentMethod (one .getStartPosition ()));
127- ((EditorBreadcrumb )upBreadcrumb ).setSearchIndex (one .getParameterIndex ());
128- linkAnnotation .setSearchMethod (call .getCurrentMethod (one .getStartPosition ()));
129- }
130- if (searchDown != null ) {
131- textDown .addAll (searchDown );
132- ((EditorBreadcrumb )downBreadcrumb ).setSearchIndex (one .getParameterIndex ());
137+ else {
138+ removeAnnotations ();
133139 }
134- upBreadcrumb .setText (textUp );
135- downBreadcrumb .setText (textDown );
136- }
137- else {
140+ } catch (Exception e ) {
141+ Activator .logError (e );
138142 removeAnnotations ();
139143 }
140- } catch (Exception e ) {
141- Activator .logError (e );
142- removeAnnotations ();
143144 }
144145 }
145146
@@ -239,25 +240,31 @@ public void removeAnnotations() {
239240 try {
240241 if (highlightAnnotation != null ) {
241242 painter .removeAllAnnotations ();
243+ painter .dispose ();
242244 }
243245 } catch (Exception ignore ) {
246+ System .out .println ("ignore" );
244247 }
245248 }
246249
250+ /**
251+ * Keeps track of if tool is enabled or disabled.
252+ */
253+ public void setEnabled (boolean flag ){
254+ isEnabled = flag ;
255+ }
256+
247257 public void dispose () {
248258 painter .dispose ();
249259 currentSearch = null ;
250260 }
251261
252262 public void deactivate () {
253263 isActive = false ;
254- crumbs .stop ();
255- upBreadcrumb .dispose ();
256- downBreadcrumb .dispose ();
264+ isEnabled = false ;
257265 removeAnnotations ();
258- dispose ();
259266 }
260-
267+
261268 public void selectionChanged (SelectionChangedEvent event ) {
262269 selectionChanged ((ITextSelection ) event .getSelection ());
263270 }
0 commit comments