001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2003 Jennifer Lhotak
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: */
019:
020: package ca.mcgill.sable.soot.launching;
021:
022: import java.util.ArrayList;
023: import java.util.Iterator;
024:
025: import org.eclipse.core.resources.IFile;
026: import org.eclipse.core.resources.IFolder;
027: import org.eclipse.core.resources.IProject;
028: import org.eclipse.core.resources.IResource;
029: import org.eclipse.core.runtime.CoreException;
030: import org.eclipse.ui.IEditorPart;
031: import org.eclipse.ui.IWorkbenchPage;
032: import org.eclipse.ui.IWorkbenchWindow;
033: import org.eclipse.ui.part.*;
034:
035: import ca.mcgill.sable.soot.SootPlugin;
036:
037: /**
038: * Handles Soot ouptut dir. Potentially will do something with
039: * Soot generated files such as open them automatically.
040: */
041: public class SootOutputFilesHandler {
042:
043: private IFolder sootOutputFolder;
044: private ArrayList oldFilelist;
045: private ArrayList newFilelist;
046: private IWorkbenchWindow window;
047: private ArrayList beforeFileList;
048:
049: /**
050: * Constructor for SootOutputFilesHandler.
051: */
052: public SootOutputFilesHandler(IWorkbenchWindow window) {
053: super ();
054: setWindow(window);
055: }
056:
057: public void resetSootOutputFolder(IProject project) {
058: try {
059: setSootOutputFolder(project.getFolder("sootOutput"));
060: if (!getSootOutputFolder().exists()) {
061: getSootOutputFolder().create(false, true, null);
062: }
063: } catch (Exception e1) {
064: System.out.println(e1.getMessage());
065: }
066: }
067:
068: public void refreshAll(IProject project) {
069: try {
070: project.refreshLocal(IResource.DEPTH_INFINITE, null);
071: } catch (CoreException e) {
072: System.out.println(e.getMessage());
073: }
074: }
075:
076: public void refreshFolder() {
077: try {
078: getSootOutputFolder().refreshLocal(
079: IResource.DEPTH_INFINITE, null);
080: } catch (CoreException e1) {
081: System.out.println(e1.getMessage());
082: }
083: }
084:
085: public void handleFilesChanged() {
086:
087: // files that were showing close
088: if (getOldFilelist() != null) {
089: Iterator it = getOldFilelist().iterator();
090: while (it.hasNext()) {
091: Object temp = it.next();
092: if (temp instanceof IEditorPart) {
093: getWindow().getActivePage().closeEditor(
094: (IEditorPart) temp, true);
095: }
096: }
097: }
098:
099: try {
100: IResource[] children = getSootOutputFolder().members();
101:
102: IWorkbenchWindow window = SootPlugin.getDefault()
103: .getWorkbench().getActiveWorkbenchWindow();
104: } catch (Exception e) {
105: System.out.println("Open Editor ex: " + e.getMessage());
106: System.out.println(e.getStackTrace());
107: }
108: // new files show
109: }
110:
111: /**
112: * Returns the sootOuputFolder.
113: * @return IFolder
114: */
115: public IFolder getSootOutputFolder() {
116: return sootOutputFolder;
117: }
118:
119: /**
120: * Sets the sootOuputFolder.
121: * @param sootOuputFolder The sootOuputFolder to set
122: */
123: public void setSootOutputFolder(IFolder sootOutputFolder) {
124: this .sootOutputFolder = sootOutputFolder;
125: }
126:
127: /**
128: * Returns the newFilelist.
129: * @return ArrayList
130: */
131: public ArrayList getNewFilelist() {
132: return newFilelist;
133: }
134:
135: /**
136: * Returns the oldFilelist.
137: * @return ArrayList
138: */
139: public ArrayList getOldFilelist() {
140: return oldFilelist;
141: }
142:
143: /**
144: * Sets the newFilelist.
145: * @param newFilelist The newFilelist to set
146: */
147: public void setNewFilelist(ArrayList newFilelist) {
148: this .newFilelist = newFilelist;
149: }
150:
151: /**
152: * Sets the oldFilelist.
153: * @param oldFilelist The oldFilelist to set
154: */
155: public void setOldFilelist(ArrayList oldFilelist) {
156: this .oldFilelist = oldFilelist;
157: }
158:
159: /**
160: * Returns the window.
161: * @return IWorkbenchWindow
162: */
163: public IWorkbenchWindow getWindow() {
164: return window;
165: }
166:
167: /**
168: * Sets the window.
169: * @param window The window to set
170: */
171: public void setWindow(IWorkbenchWindow window) {
172: this.window = window;
173: }
174:
175: }
|