001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.model;
038:
039: import java.awt.print.PageFormat;
040: import java.io.File;
041: import java.io.IOException;
042: import java.util.Hashtable;
043: import java.util.List;
044:
045: import edu.rice.cs.drjava.model.compiler.CompilerModel;
046: import edu.rice.cs.drjava.model.debug.Debugger;
047: import edu.rice.cs.drjava.model.debug.Breakpoint;
048: import edu.rice.cs.drjava.model.definitions.DefinitionsEditorKit;
049: import edu.rice.cs.drjava.model.junit.JUnitModel;
050: import edu.rice.cs.drjava.model.repl.DefaultInteractionsModel;
051: import edu.rice.cs.drjava.model.repl.InteractionsDJDocument;
052: import edu.rice.cs.drjava.model.repl.InteractionsDocument;
053: import edu.rice.cs.drjava.model.repl.InteractionsScriptModel;
054: import edu.rice.cs.drjava.model.javadoc.JavadocModel;
055: import edu.rice.cs.drjava.project.DocumentInfoGetter;
056: import edu.rice.cs.drjava.project.MalformedProjectFileException;
057: import edu.rice.cs.plt.io.IOUtil;
058: import edu.rice.cs.util.FileOpenSelector;
059: import edu.rice.cs.util.OperationCanceledException;
060: import edu.rice.cs.util.docnavigation.IDocumentNavigator;
061: import edu.rice.cs.util.swing.DocumentIterator;
062: import edu.rice.cs.util.text.AbstractDocumentInterface;
063: import edu.rice.cs.util.text.ConsoleDocument;
064:
065: /** Handles the bulk of DrJava's program logic. The UI components interface with the GlobalModel through its
066: * public methods, and GlobalModel responds via the GlobalModelListener interface. This removes the dependency
067: * on the UI for the logical flow of the program's features. With the current implementation, we can finally test
068: * the compile an unit testing functionality of DrJava, along with many other things. An ongoing refactoring effort
069: * will be moving many GlobalModel functions into more specific sub-interfaces for particular behaviors:
070: *
071: * @see DefaultGlobalModel
072: * @see ILoadDocuments
073: * @see CompilerModel
074: * @see JUnitModel
075: * @see JavadocModel
076: *
077: * @version $Id: GlobalModel.java 4255 2007-08-28 19:17:37Z mgricken $
078: */
079: public interface GlobalModel extends ILoadDocuments {
080:
081: public static final Iterable<File> RUNTIME_CLASS_PATH = IOUtil
082: .attemptAbsoluteFiles(IOUtil.parsePath(System.getProperty(
083: "java.class.path", "")));
084:
085: //-------------------------- Listener Management --------------------------//
086:
087: /** Add a listener to this global model.
088: * @param listener a listener that reacts on events generated by the GlobalModel
089: */
090: public void addListener(GlobalModelListener listener);
091:
092: /** Remove a listener from this global model.
093: * @param listener a listener that reacts on events generated by the GlobalModel
094: */
095: public void removeListener(GlobalModelListener listener);
096:
097: //------------------------ Feature Model Accessors ------------------------//
098:
099: /** Returns the interactions model. */
100: public DefaultInteractionsModel getInteractionsModel();
101:
102: /** Gets the CompilerModel, which provides all methods relating to compilers. */
103: public CompilerModel getCompilerModel();
104:
105: /** Gets the JUnitModel, which provides all methods relating to JUnit testing. */
106: public JUnitModel getJUnitModel();
107:
108: /** Gets the JavadocModel, which provides all methods relating to Javadoc. */
109: public JavadocModel getJavadocModel();
110:
111: /** Gets the Debugger, which interfaces with the integrated debugger. */
112: public Debugger getDebugger();
113:
114: /** Gets the DocumentNavigator, which controls the document view. */
115: public IDocumentNavigator<OpenDefinitionsDocument> getDocumentNavigator();
116:
117: public void setDocumentNavigator(
118: IDocumentNavigator<OpenDefinitionsDocument> newnav);
119:
120: /** @return manager for breakpoint regions. */
121: public RegionManager<Breakpoint> getBreakpointManager();
122:
123: /** @return manager for bookmark regions. */
124: public RegionManager<DocumentRegion> getBookmarkManager();
125:
126: /** @return managers for find result regions. */
127: public List<RegionManager<MovingDocumentRegion>> getFindResultsManagers();
128:
129: /** @return new manager for find result regions. */
130: public RegionManager<MovingDocumentRegion> createFindResultsManager();
131:
132: /** Dispose a manager for find result regions. */
133: public void disposeFindResultsManager(
134: RegionManager<MovingDocumentRegion> rm);
135:
136: /** @return manager for browser history regions. */
137: public RegionManager<DocumentRegion> getBrowserHistoryManager();
138:
139: /** Add the current location to the browser history. */
140: public void addToBrowserHistory();
141:
142: // //---------------------------- Interpreter --------------------------------//
143: // /** Updates the security manager in DrJava. */
144: // public void enableSecurityManager();
145: //
146: // /** Updates the security manager in DrJava. */
147: // public void disableSecurityManager();
148: //
149: //---------------------------- File Management ----------------------------//
150:
151: /** Creates a new document in the definitions pane and adds it to the list of open documents.
152: * @return The new open document
153: */
154: public OpenDefinitionsDocument newFile();
155:
156: /**
157: * Creates a new junit test case.
158: * TODO: Move to JUnitModel?
159: * @param name the name of the new test case
160: * @param makeSetUp true iff an empty setUp() method should be included
161: * @param makeTearDown true iff an empty tearDown() method should be included
162: * @return the new open test case
163: */
164: public OpenDefinitionsDocument newTestCase(String name,
165: boolean makeSetUp, boolean makeTearDown);
166:
167: /**
168: * Closes an open definitions document, prompting to save if
169: * the document has been changed. Returns whether the file
170: * was successfully closed.
171: * @return true if the document was closed
172: */
173: public boolean closeFile(OpenDefinitionsDocument doc);
174:
175: /**
176: * Closes an open definitions document, without prompting to save if
177: * the document has been changed. Returns whether the file
178: * was successfully closed.
179: * @return true if the document was closed
180: */
181: public boolean closeFileWithoutPrompt(OpenDefinitionsDocument doc);
182:
183: /**
184: * Attempts to close all open documents.
185: * @return true if all documents were closed
186: */
187: public boolean closeAllFiles();
188:
189: /* Opens all files in specified folder. If rec is true, open all files in the tree rooted at dir. */
190: public void openFolder(File dir, boolean rec) throws IOException,
191: OperationCanceledException, AlreadyOpenException;
192:
193: /** Saves all open documents, prompting when necessary. */
194: public void saveAllFiles(FileSaveSelector com) throws IOException;
195:
196: /**Creates a new project with specified project file and default values for other properties.
197: * @param projFile the new project file (which does not yet exist in the file system).
198: */
199: public void createNewProject(File projFile);
200:
201: /**Configures a new project (created by createNewProject) and saves it to disk. */
202: public void configNewProject() throws IOException;
203:
204: /**Writes the project file to disk
205: * @param f where to save the project
206: * @param info Extra view-related information that should be included in the project file
207: */
208: public void saveProject(File f,
209: Hashtable<OpenDefinitionsDocument, DocumentInfoGetter> info)
210: throws IOException;
211:
212: /**Reloads a project without writing to disk.
213: * @param f project file; does not actually get touched
214: */
215: public void reloadProject(File f,
216: Hashtable<OpenDefinitionsDocument, DocumentInfoGetter> info)
217: throws IOException;
218:
219: /** Formats a string pathname for use in the document navigator. */
220: public String fixPathForNavigator(String path) throws IOException;
221:
222: /** Gives the title of the source bin for the navigator
223: * @return The text used for the source bin in the tree navigator
224: */
225: public String getSourceBinTitle();
226:
227: /** Gives the title of the external files bin for the navigator
228: * @return The text used for the external files bin in the tree navigator
229: */
230: public String getExternalBinTitle();
231:
232: /** Gives the title of the aux files bin for the navigator
233: * @return The text used for the aux files bin in the tree navigator
234: */
235: public String getAuxiliaryBinTitle();
236:
237: /** Adds a document to the list of auxiliary files. */
238: public void addAuxiliaryFile(OpenDefinitionsDocument doc);
239:
240: /** Removes a document from the list of auxiliary files. */
241: public void removeAuxiliaryFile(OpenDefinitionsDocument doc);
242:
243: /** Parses out the given project file, sets up the state and other configurations
244: * such as the Navigator and the classpath, and returns an array of files to open.
245: * @param file The project file to parse
246: */
247: public void openProject(File file) throws IOException,
248: MalformedProjectFileException;
249:
250: /** Performs any needed operations on the model before closing the project and its files. This is not responsible
251: * for actually closing the files since that is handled in MainFrame._closeProject()
252: */
253: public void closeProject(boolean qutting);
254:
255: /** Searches for a file with the given name on the current source roots and the augmented classpath.
256: * @param fileName Name of the source file to look for
257: * @return the file corresponding to the given name, or null if it cannot be found
258: */
259: public File getSourceFile(String fileName);
260:
261: /** Searches for a file with the given name on the provided paths. Returns null if the file is not found.
262: * @param fileName Name of the source file to look for
263: * @param paths An array of directories to search
264: */
265: public File findFileInPaths(String fileName, Iterable<File> paths);
266:
267: /** Gets a list of all sourceRoots for the open definitions documents, without duplicates. */
268: public Iterable<File> getSourceRootSet();
269:
270: // /** Return the absolute path of the file with the given index, or "(untitled)" if no file exists. */
271: // public String getDisplayFullPath(int index);
272:
273: /*------------------------------ Definitions ------------------------------*/
274:
275: /** Fetches the {@link javax.swing.text.EditorKit} implementation for use in the definitions pane. */
276: public DefinitionsEditorKit getEditorKit();
277:
278: /** Gets a DocumentIterator to allow navigating through open swing Documents.
279: * TODO: remove ugly swing dependency.
280: */
281: public DocumentIterator getDocumentIterator();
282:
283: /**
284: * Re-runs the global listeners on the active document.
285: */
286: public void refreshActiveDocument();
287:
288: /*---------------------------------- I/O ----------------------------------*/
289:
290: /** Gets the console document. */
291: public ConsoleDocument getConsoleDocument();
292:
293: /** TODO: remove this swing dependency.
294: * @return InteractionsDJDocument in use by the ConsoleDocument.
295: */
296: public InteractionsDJDocument getSwingConsoleDocument();
297:
298: /** Resets the console. Fires consoleReset() event. */
299: public void resetConsole();
300:
301: /** Prints System.out to the DrJava console. */
302: public void systemOutPrint(String s);
303:
304: /** Prints System.err to the DrJava console. */
305: public void systemErrPrint(String s);
306:
307: /** Prints the given string to the DrJava console as an echo of System.in */
308: public void systemInEcho(String s);
309:
310: //----------------------------- Interactions -----------------------------//
311:
312: /** Gets the (toolkit-independent) interactions document. */
313: public InteractionsDocument getInteractionsDocument();
314:
315: /** TODO: remove this swing dependency.
316: * @return InteractionsDJDocument in use by the InteractionsDocument.
317: */
318: public InteractionsDJDocument getSwingInteractionsDocument();
319:
320: /** Clears and resets the interactions pane in the specified working directory, provided that the operation has some effect. */
321: public void resetInteractions(File wd);
322:
323: /** Clears and resets the interactions pane in the specified working directory. */
324: public void resetInteractions(File wd, boolean forceReset);
325:
326: /** Blocks until the interpreter has registered. */
327: public void waitForInterpreter();
328:
329: /** Interprets the current given text at the prompt in the interactions pane. */
330: public void interpretCurrentInteraction();
331:
332: /** Returns the current classpath in use by the Interpreter JVM. This includes the original jvm classpath, the global
333: * drjava extra classpaths, and the project extra classpaths.
334: */
335: public Iterable<File> getInteractionsClassPath();
336:
337: // TODO: Move history methods to a more appropriate home.
338:
339: /** Interprets file selected in the FileOpenSelector. Assumes all strings have no trailing whitespace. Interprets
340: * the list of interactions as a single transaction so the first error aborts all processing.
341: */
342: public void loadHistory(FileOpenSelector selector)
343: throws IOException;
344:
345: /** Loads the history/histories from the given selector. */
346: public InteractionsScriptModel loadHistoryAsScript(
347: FileOpenSelector selector) throws IOException,
348: OperationCanceledException;
349:
350: /** Clears the interactions history. */
351: public void clearHistory();
352:
353: /** Saves the unedited version of the current history to a file
354: * @param selector File to save to
355: */
356: public void saveHistory(FileSaveSelector selector)
357: throws IOException;
358:
359: /** Saves the edited version of the current history to a file
360: * @param selector File to save to
361: * @param editedVersion Edited verison of the history which will be saved to file instead of the lines saved in the
362: * history. The saved file will still include any tags needed to recognize it as a saved interactions file.
363: */
364: public void saveHistory(FileSaveSelector selector,
365: String editedVersion) throws IOException;
366:
367: /** Returns the entire history as a String with semicolons as needed. */
368: public String getHistoryAsStringWithSemicolons();
369:
370: /** Returns the entire history as a String. */
371: public String getHistoryAsString();
372:
373: //------------------------------- Debugger -------------------------------//
374:
375: /** Called when the debugger wants to print a message. */
376: public void printDebugMessage(String s);
377:
378: /** Returns an available port number to use for debugging the interactions JVM.
379: * @throws IOException if unable to get a valid port number.
380: */
381: public int getDebugPort() throws IOException;
382:
383: //--------------------------------- Misc ---------------------------------//
384:
385: /** Get the class path to be used in all class-related operations.
386: * TODO: Insure that this is used wherever appropriate.
387: */
388: public Iterable<File> getClassPath();
389:
390: // TODO: comment
391: public PageFormat getPageFormat();
392:
393: // TODO: comment
394: public void setPageFormat(PageFormat format);
395:
396: /** Exits the program. Only quits if all documents are successfully closed. */
397: public void quit();
398:
399: /** Halts the program immediately. */
400: public void forceQuit();
401:
402: /** Returns the document count */
403: public int getDocumentCount();
404:
405: /** Returns the number of compiler errors produced by the last compilation. */
406: public int getNumCompErrors();
407:
408: /** Sets the number of compiler errors produced by the last compilation. */
409: public void setNumCompErrors(int num);
410:
411: /** Returnt an OOD given an AbstractDocumentInterface */
412: /**CHECK IF NEEDED! */
413: public OpenDefinitionsDocument getODDForDocument(
414: AbstractDocumentInterface doc);
415:
416: /** Returns a list of OpenDefinitionsDocuments that do not belong to the currently active project.<br>
417: * If no project is active, all documents are returned.
418: */
419: public List<OpenDefinitionsDocument> getNonProjectDocuments();
420:
421: /** Teturns a list of OpenDefinitionsDocuments that do belong to the currently active project.<br>
422: * If no project is active, no documents are returned.
423: */
424: public List<OpenDefinitionsDocument> getProjectDocuments();
425:
426: // /** Compiles all open files (all files in project (??) in project mode) */
427: // public void compileAll() throws IOException;
428:
429: /** @return true if the model has a project open, false otherwise. */
430: public boolean isProjectActive();
431:
432: // /** junits all the appropriate files */
433: // public void junitAll();
434:
435: /** @return the file that points to the current project file. Null if not currently in project view */
436: public File getProjectFile();
437:
438: /** @return the directory that the class files should be stored after compilation. */
439: public File[] getProjectFiles();
440:
441: /** @return the source root for the project. */
442: public File getProjectRoot();
443:
444: /** Sets project file to specifed value; used in "Save Project As ..." command in MainFrame. */
445: public void setProjectFile(File f);
446:
447: /** Sets the source root for the project. */
448: public void setProjectRoot(File f);
449:
450: /** @return the directory that the class files should be stored after compilation. */
451: public File getBuildDirectory();
452:
453: /** Sets the current build directory. */
454: public void setBuildDirectory(File f);
455:
456: /** @return the working directory for the Master JVM. */
457: public File getMasterWorkingDirectory();
458:
459: /** @return the working directory for the Slave JVM (only applied to project mode). */
460: public File getWorkingDirectory();
461:
462: /** Sets the working directory for the Slave JVM (only applies to project mode). */
463: public void setWorkingDirectory(File f);
464:
465: /** Sets the main file of the project. */
466: public void setMainClass(File f);
467:
468: /** Return the main file for the project If not in project mode, returns null. */
469: public File getMainClass();
470:
471: /** Returns only the project's extra classpaths.
472: * @return The classpath entries loaded along with the project
473: */
474: public Iterable<File> getExtraClassPath();
475:
476: /** Sets the set of classpath entries to use as the projects set of classpath entries. This is normally used by the
477: * project preferences.
478: */
479: public void setExtraClassPath(Iterable<File> cp);
480:
481: /** Sets the create jar file of the project. */
482: public void setCreateJarFile(File f);
483:
484: /** Return the create jar file for the project. If not in project mode, returns null. */
485: public File getCreateJarFile();
486:
487: /** Sets the create jar flags of the project. */
488: public void setCreateJarFlags(int f);
489:
490: /** Return the create jar file for the project. If not in project mode, returns 0. */
491: public int getCreateJarFlags();
492:
493: /** Returns true the given file is in the current project file. */
494: public boolean inProject(File f);
495:
496: /** A file is in the project if the source root is the same as the project root. This means that project files must
497: * be saved in the source root. (we query the model through the model's state)
498: */
499: public boolean inProjectPath(OpenDefinitionsDocument doc);
500:
501: /** Notifies the project state that the project has been changed. */
502: public void setProjectChanged(boolean changed);
503:
504: /** Returns true if the project state has been changed */
505: public boolean isProjectChanged();
506:
507: /** @return true iff no open document is out of sync with its primary class file. */
508: public boolean hasOutOfSyncDocuments();
509:
510: /** @return true iff no document in given list is out of sync with its primary class file. */
511: public boolean hasOutOfSyncDocuments(
512: List<OpenDefinitionsDocument> lod);
513:
514: /** Cleans the build directory. */
515: public void cleanBuildDirectory();
516:
517: /** @return a list of class files. */
518: public List<File> getClassFiles();
519:
520: /** Returns a collection of all documents currently open for editing. This is equivalent to the results of
521: * getDocumentForFile for the set of all files for which isAlreadyOpen returns true. The order of documents
522: * is the same as in the display of documents in the view.
523: * @return a List of the open definitions documents.
524: */
525: public List<OpenDefinitionsDocument> getOpenDefinitionsDocuments();
526:
527: /** Checks if any open definitions documents have been modified since last being saved.
528: * @return whether any documents have been modified
529: */
530: public boolean hasModifiedDocuments();
531:
532: /** Checks if any of the given documents have been modified since last being saved.
533: * @return whether any documents have been modified
534: */
535: public boolean hasModifiedDocuments(
536: List<OpenDefinitionsDocument> lod);
537:
538: /** Checks if any open definitions documents are untitled.
539: * @return whether any documents are untitled
540: */
541: public boolean hasUntitledDocuments();
542:
543: /** Returns the OpenDefinitionsDocument for the specified File, opening a new copy if one is not already open.
544: * @param file File contained by the document to be returned
545: * @return OpenDefinitionsDocument containing file
546: */
547: public OpenDefinitionsDocument getDocumentForFile(File file)
548: throws IOException;
549: }
|