KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > GlobalModel


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32 END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model;
35
36 import java.awt.print.PageFormat JavaDoc;
37 import java.io.File JavaDoc;
38 import java.io.IOException JavaDoc;
39 import java.util.Hashtable JavaDoc;
40 import java.util.List JavaDoc;
41
42 import edu.rice.cs.drjava.model.compiler.CompilerModel;
43 import edu.rice.cs.drjava.model.debug.Debugger;
44 import edu.rice.cs.drjava.model.debug.Breakpoint;
45 import edu.rice.cs.drjava.model.definitions.DefinitionsEditorKit;
46 import edu.rice.cs.drjava.model.junit.JUnitModel;
47 import edu.rice.cs.drjava.model.repl.DefaultInteractionsModel;
48 import edu.rice.cs.drjava.model.repl.InteractionsDJDocument;
49 import edu.rice.cs.drjava.model.repl.InteractionsDocument;
50 import edu.rice.cs.drjava.model.repl.InteractionsScriptModel;
51 import edu.rice.cs.drjava.project.DocumentInfoGetter;
52 import edu.rice.cs.drjava.project.MalformedProjectFileException;
53 import edu.rice.cs.util.ClassPathVector;
54 import edu.rice.cs.util.FileOpenSelector;
55 import edu.rice.cs.util.OperationCanceledException;
56 import edu.rice.cs.util.docnavigation.IDocumentNavigator;
57 import edu.rice.cs.util.swing.DocumentIterator;
58 import edu.rice.cs.util.text.AbstractDocumentInterface;
59 import edu.rice.cs.util.text.ConsoleDocument;
60
61 /** Handles the bulk of DrJava's program logic. The UI components interface with the GlobalModel through its
62  * public methods, and GlobalModel responds via the GlobalModelListener interface. This removes the dependency
63  * on the UI for the logical flow of the program's features. With the current implementation, we can finally test
64  * the compile an unit testing functionality of DrJava, along with many other things. An ongoing refactoring effort
65  * will be moving many GlobalModel functions into more specific sub-interfaces for particular behaviors:
66  *
67  * @see DefaultGlobalModel
68  * @see ILoadDocuments
69  * @see CompilerModel
70  * @see JUnitModel
71  * @see JavadocModel
72  *
73  * @version $Id: GlobalModel.java 4076 2007-01-19 23:01:04Z dlsmith $
74  */

75 public interface GlobalModel extends ILoadDocuments {
76
77   //-------------------------- Listener Management --------------------------//
78

79   /** Add a listener to this global model.
80    * @param listener a listener that reacts on events generated by the GlobalModel
81    */

82   public void addListener(GlobalModelListener listener);
83
84   /** Remove a listener from this global model.
85    * @param listener a listener that reacts on events generated by the GlobalModel
86    */

87   public void removeListener(GlobalModelListener listener);
88
89   //------------------------ Feature Model Accessors ------------------------//
90

91   /** Returns the interactions model. */
92   public DefaultInteractionsModel getInteractionsModel();
93
94   /** Gets the CompilerModel, which provides all methods relating to compilers. */
95   public CompilerModel getCompilerModel();
96
97   /** Gets the JUnitModel, which provides all methods relating to JUnit testing. */
98   public JUnitModel getJUnitModel();
99
100   /** Gets the JavadocModel, which provides all methods relating to Javadoc. */
101   public JavadocModel getJavadocModel();
102
103   /** Gets the Debugger, which interfaces with the integrated debugger. */
104   public Debugger getDebugger();
105   
106   /** Gets the DocumentNavigator, which controls the document view. */
107   public IDocumentNavigator<OpenDefinitionsDocument> getDocumentNavigator();
108    
109   public void setDocumentNavigator(IDocumentNavigator<OpenDefinitionsDocument> newnav);
110   
111   /** @return manager for breakpoint regions. */
112   public RegionManager<Breakpoint> getBreakpointManager();
113   
114   /** @return manager for bookmark regions. */
115   public RegionManager<DocumentRegion> getBookmarkManager();
116   
117   /** @return managers for find result regions. */
118   public List JavaDoc<RegionManager<MovingDocumentRegion>> getFindResultsManagers();
119   
120   /** @return new manager for find result regions. */
121   public RegionManager<MovingDocumentRegion> createFindResultsManager();
122   
123   /** Dispose a manager for find result regions. */
124   public void disposeFindResultsManager(RegionManager<MovingDocumentRegion> rm);
125   
126   /** @return manager for browser history regions. */
127   public RegionManager<DocumentRegion> getBrowserHistoryManager();
128
129   /** Add the current location to the browser history. */
130   public void addToBrowserHistory();
131   
132 // //---------------------------- Interpreter --------------------------------//
133
// /** Updates the security manager in DrJava. */
134
// public void enableSecurityManager();
135
//
136
// /** Updates the security manager in DrJava. */
137
// public void disableSecurityManager();
138
//
139
//---------------------------- File Management ----------------------------//
140

141   /** Creates a new document in the definitions pane and adds it to the list of open documents.
142    * @return The new open document
143    */

144   public OpenDefinitionsDocument newFile();
145
146   /**
147    * Creates a new junit test case.
148    * TODO: Move to JUnitModel?
149    * @param name the name of the new test case
150    * @param makeSetUp true iff an empty setUp() method should be included
151    * @param makeTearDown true iff an empty tearDown() method should be included
152    * @return the new open test case
153    */

154   public OpenDefinitionsDocument newTestCase(String JavaDoc name, boolean makeSetUp, boolean makeTearDown);
155
156   /**
157    * Closes an open definitions document, prompting to save if
158    * the document has been changed. Returns whether the file
159    * was successfully closed.
160    * @return true if the document was closed
161    */

162   public boolean closeFile(OpenDefinitionsDocument doc);
163   
164   /**
165    * Closes an open definitions document, without prompting to save if
166    * the document has been changed. Returns whether the file
167    * was successfully closed.
168    * @return true if the document was closed
169    */

170   public boolean closeFileWithoutPrompt(OpenDefinitionsDocument doc);
171
172   /**
173    * Attempts to close all open documents.
174    * @return true if all documents were closed
175    */

176   public boolean closeAllFiles();
177
178   /* Opens all files in specified folder. If rec is true, open all files in the tree rooted at dir. */
179   public void openFolder(File JavaDoc dir, boolean rec) throws IOException JavaDoc, OperationCanceledException, AlreadyOpenException;
180
181   /** Saves all open documents, prompting when necessary. */
182   public void saveAllFiles(FileSaveSelector com) throws IOException JavaDoc;
183   
184   /**Creates a new project with specified project file and default values for other properties.
185    * @param projFile the new project file (which does not yet exist in the file system).
186    */

187   public void createNewProject(File JavaDoc projFile);
188   
189   /**Configures a new project (created by createNewProject) and saves it to disk. */
190   public void configNewProject() throws IOException JavaDoc;
191   
192   /**Writes the project file to disk
193    * @param f where to save the project
194    * @param info Extra view-related information that should be included in the project file
195    */

196   public void saveProject(File JavaDoc f, Hashtable JavaDoc<OpenDefinitionsDocument,DocumentInfoGetter> info) throws IOException JavaDoc;
197   
198   /**Reloads a project without writing to disk.
199    * @param f project file; does not actually get touched
200    */

201   public void reloadProject(File JavaDoc f, Hashtable JavaDoc<OpenDefinitionsDocument,DocumentInfoGetter> info) throws IOException JavaDoc;
202   
203   /** Formats a string pathname for use in the document navigator. */
204   public String JavaDoc fixPathForNavigator(String JavaDoc path) throws IOException JavaDoc;
205
206   /** Gives the title of the source bin for the navigator
207    * @return The text used for the source bin in the tree navigator
208    */

209   public String JavaDoc getSourceBinTitle();
210   
211   /** Gives the title of the external files bin for the navigator
212    * @return The text used for the external files bin in the tree navigator
213    */

214   public String JavaDoc getExternalBinTitle();
215   
216   /** Gives the title of the aux files bin for the navigator
217    * @return The text used for the aux files bin in the tree navigator
218    */

219   public String JavaDoc getAuxiliaryBinTitle();
220   
221   /** Adds a document to the list of auxiliary files. */
222   public void addAuxiliaryFile(OpenDefinitionsDocument doc);
223   
224   /** Removes a document from the list of auxiliary files. */
225   public void removeAuxiliaryFile(OpenDefinitionsDocument doc);
226   
227   /** Parses out the given project file, sets up the state and other configurations
228    * such as the Navigator and the classpath, and returns an array of files to open.
229    * @param file The project file to parse
230    */

231   public void openProject(File JavaDoc file) throws IOException JavaDoc, MalformedProjectFileException;
232
233   /** Performs any needed operations on the model before closing the project and its files. This is not responsible
234    * for actually closing the files since that is handled in MainFrame._closeProject()
235    */

236   public void closeProject(boolean qutting);
237   
238   /** Searches for a file with the given name on the current source roots and the augmented classpath.
239    * @param fileName Name of the source file to look for
240    * @return the file corresponding to the given name, or null if it cannot be found
241    */

242   public File JavaDoc getSourceFile(String JavaDoc fileName);
243
244   /** Searches for a file with the given name on the provided paths. Returns null if the file is not found.
245    * @param fileName Name of the source file to look for
246    * @param paths An array of directories to search
247    */

248   public File JavaDoc findFileInPaths(String JavaDoc fileName, List JavaDoc<File JavaDoc> paths);
249
250   /** Gets an array of all sourceRoots for the open definitions documents, without duplicates. */
251   public File JavaDoc[] getSourceRootSet();
252
253 // /** Return the absolute path of the file with the given index, or "(untitled)" if no file exists. */
254
// public String getDisplayFullPath(int index);
255

256   /*------------------------------ Definitions ------------------------------*/
257
258   /** Fetches the {@link javax.swing.text.EditorKit} implementation for use in the definitions pane. */
259   public DefinitionsEditorKit getEditorKit();
260
261   /** Gets a DocumentIterator to allow navigating through open swing Documents.
262    * TODO: remove ugly swing dependency.
263    */

264   public DocumentIterator getDocumentIterator();
265
266   /*---------------------------------- I/O ----------------------------------*/
267
268   /** Gets the console document. */
269   public ConsoleDocument getConsoleDocument();
270
271   /** TODO: remove this swing dependency.
272    * @return InteractionsDJDocument in use by the ConsoleDocument.
273    */

274   public InteractionsDJDocument getSwingConsoleDocument();
275
276   /** Resets the console. Fires consoleReset() event. */
277   public void resetConsole();
278
279   /** Prints System.out to the DrJava console. */
280   public void systemOutPrint(String JavaDoc s);
281
282   /** Prints System.err to the DrJava console. */
283   public void systemErrPrint(String JavaDoc s);
284   
285   /** Prints the given string to the DrJava console as an echo of System.in */
286   public void systemInEcho(String JavaDoc s);
287
288   //----------------------------- Interactions -----------------------------//
289

290   /** Gets the (toolkit-independent) interactions document. */
291   public InteractionsDocument getInteractionsDocument();
292
293   /** TODO: remove this swing dependency.
294    * @return InteractionsDJDocument in use by the InteractionsDocument.
295    */

296   public InteractionsDJDocument getSwingInteractionsDocument();
297
298   /** Clears and resets the interactions pane in the specified working directory, provided that the operation has some effect. */
299   public void resetInteractions(File JavaDoc wd);
300   
301   /** Clears and resets the interactions pane in the specified working directory. */
302   public void resetInteractions(File JavaDoc wd, boolean forceReset);
303
304   /** Blocks until the interpreter has registered. */
305   public void waitForInterpreter();
306
307   /** Interprets the current given text at the prompt in the interactions pane. */
308   public void interpretCurrentInteraction();
309
310   /** Returns the current classpath in use by the Interpreter JVM. This includes the original jvm classpath, the global
311    * drjava extra classpaths, and the project extra classpaths.
312    */

313   public ClassPathVector getInteractionsClassPath();
314
315   // TODO: Move history methods to a more appropriate home.
316

317   /** Interprets file selected in the FileOpenSelector. Assumes all strings have no trailing whitespace. Interprets
318    * the list of interactions as a single transaction so the first error aborts all processing.
319    */

320   public void loadHistory(FileOpenSelector selector) throws IOException JavaDoc;
321
322   /** Loads the history/histories from the given selector. */
323   public InteractionsScriptModel loadHistoryAsScript(FileOpenSelector selector)
324     throws IOException JavaDoc, OperationCanceledException;
325
326   /** Clears the interactions history. */
327   public void clearHistory();
328
329   /** Saves the unedited version of the current history to a file
330    * @param selector File to save to
331    */

332   public void saveHistory(FileSaveSelector selector) throws IOException JavaDoc;
333
334   /** Saves the edited version of the current history to a file
335    * @param selector File to save to
336    * @param editedVersion Edited verison of the history which will be saved to file instead of the lines saved in the
337    * history. The saved file will still include any tags needed to recognize it as a saved interactions file.
338    */

339   public void saveHistory(FileSaveSelector selector, String JavaDoc editedVersion) throws IOException JavaDoc;
340
341   /** Returns the entire history as a String with semicolons as needed. */
342   public String JavaDoc getHistoryAsStringWithSemicolons();
343
344   /** Returns the entire history as a String. */
345   public String JavaDoc getHistoryAsString();
346
347   //------------------------------- Debugger -------------------------------//
348

349   /** Called when the debugger wants to print a message. */
350   public void printDebugMessage(String JavaDoc s);
351
352   /** Returns an available port number to use for debugging the interactions JVM.
353    * @throws IOException if unable to get a valid port number.
354    */

355   public int getDebugPort() throws IOException JavaDoc;
356
357   //--------------------------------- Misc ---------------------------------//
358

359   /** Get the class path to be used in all class-related operations.
360    * TODO: Insure that this is used wherever appropriate.
361    */

362   public ClassPathVector getClassPath();
363
364   // TODO: comment
365
public PageFormat JavaDoc getPageFormat();
366
367   // TODO: comment
368
public void setPageFormat(PageFormat JavaDoc format);
369
370   /** Exits the program. Only quits if all documents are successfully closed. */
371   public void quit();
372   
373   /** Halts the program immediately. */
374   public void forceQuit();
375   
376   /** Returns the document count */
377   public int getDocumentCount();
378   
379   /** Returns the number of compiler errors produced by the last compilation. */
380   public int getNumCompErrors();
381   
382    /** Sets the number of compiler errors produced by the last compilation. */
383   public void setNumCompErrors(int num);
384   
385   /** Returnt an OOD given an AbstractDocumentInterface */
386   /**CHECK IF NEEDED! */
387   public OpenDefinitionsDocument getODDForDocument(AbstractDocumentInterface doc);
388   
389   /** Returns a list of OpenDefinitionsDocuments that do not belong to the currently active project.<br>
390    * If no project is active, all documents are returned.
391    */

392   public List JavaDoc<OpenDefinitionsDocument> getNonProjectDocuments();
393
394   /** Teturns a list of OpenDefinitionsDocuments that do belong to the currently active project.<br>
395    * If no project is active, no documents are returned.
396    */

397   public List JavaDoc<OpenDefinitionsDocument> getProjectDocuments();
398   
399 // /** Compiles all open files (all files in project (??) in project mode) */
400
// public void compileAll() throws IOException;
401

402   /** @return true if the model has a project open, false otherwise. */
403   public boolean isProjectActive();
404   
405 // /** junits all the appropriate files */
406
// public void junitAll();
407

408   /** @return the file that points to the current project file. Null if not currently in project view */
409   public File JavaDoc getProjectFile();
410   
411   /** @return the directory that the class files should be stored after compilation. */
412   public File JavaDoc[] getProjectFiles();
413
414   /** @return the source root for the project. */
415   public File JavaDoc getProjectRoot();
416   
417   /** Sets project file to specifed value; used in "Save Project As ..." command in MainFrame. */
418   public void setProjectFile(File JavaDoc f);
419   
420   /** Sets the source root for the project. */
421   public void setProjectRoot(File JavaDoc f);
422
423   /** @return the directory that the class files should be stored after compilation. */
424   public File JavaDoc getBuildDirectory();
425   
426    /** Sets the current build directory. */
427   public void setBuildDirectory(File JavaDoc f);
428   
429   /** @return the working directory for the Master JVM. */
430   public File JavaDoc getMasterWorkingDirectory();
431   
432   /** @return the working directory for the Slave JVM (only applied to project mode). */
433   public File JavaDoc getWorkingDirectory();
434   
435    /** Sets the working directory for the Slave JVM (only applies to project mode). */
436   public void setWorkingDirectory(File JavaDoc f);
437
438   /** Sets the main file of the project. */
439   public void setMainClass(File JavaDoc f);
440   
441   /** Return the main file for the project If not in project mode, returns null. */
442   public File JavaDoc getMainClass();
443
444   /** Returns only the project's extra classpaths.
445     * @return The classpath entries loaded along with the project
446     */

447   public ClassPathVector getExtraClassPath();
448   
449   /** Sets the set of classpath entries to use as the projects set of classpath entries. This is normally used by the
450     * project preferences.
451     */

452   public void setExtraClassPath(ClassPathVector cp);
453   
454   /** Sets the create jar file of the project. */
455   public void setCreateJarFile(File JavaDoc f);
456   
457   /** Return the create jar file for the project. If not in project mode, returns null. */
458   public File JavaDoc getCreateJarFile();
459
460   /** Sets the create jar flags of the project. */
461   public void setCreateJarFlags(int f);
462   
463   /** Return the create jar file for the project. If not in project mode, returns 0. */
464   public int getCreateJarFlags();
465   
466   /** Returns true the given file is in the current project file. */
467   public boolean inProject(File JavaDoc f);
468   
469   /** A file is in the project if the source root is the same as the project root. This means that project files must
470    * be saved in the source root. (we query the model through the model's state)
471    */

472   public boolean inProjectPath(OpenDefinitionsDocument doc);
473   
474   /** Notifies the project state that the project has been changed. */
475   public void setProjectChanged(boolean changed);
476   
477   /** Returns true if the project state has been changed */
478   public boolean isProjectChanged();
479   
480   /** @return true iff no open document is out of sync with its primary class file. */
481   public boolean hasOutOfSyncDocuments();
482   
483   /** Cleans the build directory. */
484   public void cleanBuildDirectory();
485   
486   /** @return a list of class files. */
487   public List JavaDoc<File JavaDoc> getClassFiles();
488   
489   /** Returns a collection of all documents currently open for editing. This is equivalent to the results of
490    * getDocumentForFile for the set of all files for which isAlreadyOpen returns true. The order of documents
491    * is the same as in the display of documents in the view.
492    * @return a List of the open definitions documents.
493    */

494   public List JavaDoc<OpenDefinitionsDocument> getOpenDefinitionsDocuments();
495   
496   /** Checks if any open definitions documents have been modified since last being saved.
497    * @return whether any documents have been modified
498    */

499    public boolean hasModifiedDocuments();
500    
501    /** Checks if any open definitions documents are untitled.
502    * @return whether any documents are untitled
503    */

504   public boolean hasUntitledDocuments();
505   
506    /** Returns the OpenDefinitionsDocument for the specified File, opening a new copy if one is not already open.
507    * @param file File contained by the document to be returned
508    * @return OpenDefinitionsDocument containing file
509    */

510    public OpenDefinitionsDocument getDocumentForFile(File JavaDoc file) throws IOException JavaDoc;
511 }
512
Popular Tags