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.compiler;
038:
039: import java.io.File;
040: import java.util.List;
041:
042: import edu.rice.cs.drjava.model.EventNotifier;
043:
044: /**
045: * Keeps track of all listeners to a CompilerModel, and has the ability
046: * to notify them of some event.
047: * <p>
048: *
049: * This class has a specific role of managing CompilerListeners. Other
050: * classes with similar names use similar code to perform the same function for
051: * other interfaces, e.g. InteractionsEventNotifier and GlobalEventNotifier.
052: * These classes implement the appropriate interface definition so that they
053: * can be used transparently as composite packaging for a particular listener
054: * interface.
055: * <p>
056: *
057: * Components which might otherwise manage their own list of listeners use
058: * EventNotifiers instead to simplify their internal implementation. Notifiers
059: * should therefore be considered a private implementation detail of the
060: * components, and should not be used directly outside of the "host" component.
061: * <p>
062: *
063: * All methods in this class must use the synchronization methods
064: * provided by ReaderWriterLock. This ensures that multiple notifications
065: * (reads) can occur simultaneously, but only one thread can be adding
066: * or removing listeners (writing) at a time, and no reads can occur
067: * during a write.
068: * <p>
069: *
070: * <i>No</i> methods on this class should be synchronized using traditional
071: * Java synchronization!
072: * <p>
073: *
074: * @version $Id: CompilerEventNotifier.java 4255 2007-08-28 19:17:37Z mgricken $
075: */
076: class CompilerEventNotifier extends EventNotifier<CompilerListener>
077: implements CompilerListener {
078:
079: /** Called after a compile is started by the GlobalModel. */
080: public void compileStarted() {
081: // new ScrollableDialog(null, "CompilerEventNotifier.compileStarted() called for listeners " + _listeners, "", "").show();
082: _lock.startRead();
083: try {
084: for (CompilerListener cl : _listeners) {
085: cl.compileStarted();
086: }
087: } finally {
088: _lock.endRead();
089: }
090: }
091:
092: /** Called when a compile has finished running. */
093: public void compileEnded(File workDir,
094: List<? extends File> excludedFiles) {
095: _lock.startRead();
096: try {
097: for (CompilerListener cl : _listeners) {
098: cl.compileEnded(workDir, excludedFiles);
099: }
100: } finally {
101: _lock.endRead();
102: }
103: }
104:
105: /** Called when files are saved before compiling. It is up to the caller of this method to check if the
106: * documents have been saved, using IGetDocuments.hasModifiedDocuments().
107: */
108: public void saveBeforeCompile() {
109: _lock.startRead();
110: try {
111: for (CompilerListener cl : _listeners) {
112: cl.saveBeforeCompile();
113: }
114: } finally {
115: _lock.endRead();
116: }
117: }
118:
119: /** Called when files are saved before compiling. It is up to the caller of this method to check if the
120: * documents have been saved, using IGetDocuments.hasModifiedDocuments().
121: */
122: public void saveUntitled() {
123: _lock.startRead();
124: try {
125: for (CompilerListener cl : _listeners) {
126: cl.saveUntitled();
127: }
128: } finally {
129: _lock.endRead();
130: }
131: }
132: }
|