KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > resources > SootDeltaVisitor


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20
21 package ca.mcgill.sable.soot.resources;
22
23
24
25 import org.eclipse.core.resources.*;
26 import org.eclipse.core.runtime.*;
27 import org.eclipse.ui.IEditorReference;
28
29
30 import ca.mcgill.sable.soot.*;
31 import ca.mcgill.sable.soot.editors.*;
32
33
34
35 public class SootDeltaVisitor implements IResourceDeltaVisitor {
36
37     /* (non-Javadoc)
38      * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
39      */

40     public boolean visit(IResourceDelta delta) throws CoreException {
41         switch (delta.getKind()) {
42             case IResourceDelta.CHANGED: {
43             
44                 int flags = delta.getFlags();
45                 if ((flags & IResourceDelta.CONTENT) != 0) {
46                     if (delta.getResource() instanceof IFile){
47                         SootPlugin.getDefault().getManager().updateFileChangedFlag((IFile)delta.getResource());
48                         if (delta.getResource().getFullPath().getFileExtension().equals(SootResourceManager.JIMPLE_FILE_EXT)){
49                             updateJimpleOutline((IFile)delta.getResource());
50                         }
51                     }
52                     
53                 }
54                 
55                 break;
56             }
57             case IResourceDelta.ADDED: {
58                 SootPlugin.getDefault().getManager().addToLists(delta.getResource());
59                 if (delta.getResource() instanceof IFile){
60                     if (delta.getResource().getFullPath().getFileExtension().equals(SootResourceManager.JIMPLE_FILE_EXT)){
61                         updateJimpleOutline((IFile)delta.getResource());
62                     }
63                 }
64             }
65         }
66         return true;
67     }
68
69     // only updates after a save or Soot run
70
// (if editor is currently "dirty" the outline will be potenially incorrect
71
private void updateJimpleOutline(IFile file) {
72         
73         
74         IEditorReference [] refs = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
75         for (int i = 0; i < refs.length; i++){
76             if (refs[i] == null) continue;
77             if (refs[i].getName() == null) continue;
78             if (refs[i].getName().equals(file.getName())){
79                 JimpleEditor ed = (JimpleEditor) refs[i].getEditor(true).getAdapter(JimpleEditor.class);
80                 if (ed != null){
81                     if (ed.getPage() != null){
82                         ed.getPage().getContentOutline();
83                         ed.getPage().getViewer().setInput(ed.getPage().getContentOutline());
84                         ed.getPage().getViewer().refresh();
85                         ed.getPage().getViewer().expandAll();
86                     }
87                 }
88             }
89         }
90
91         
92     }
93     
94 }
95
Popular Tags