001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.spi.project.ui;
043:
044: import org.netbeans.modules.project.uiapi.ProjectOpenedTrampoline;
045:
046: /**
047: * A hook which can be run when a project is "opened" or "closed" in the GUI.
048: * <p>
049: * The meaning of these terms is intentionally left vague, but typically opening
050: * a project signals that the user may wish to work with it, so it would be a good
051: * idea to make sure caches are up to date, etc. It is perfectly possible to load
052: * and use (even run) projects which are <em>not</em> open, so any project type
053: * provider using this hook cannot rely on it for basic semantics.
054: * </p>
055: * <p>
056: * XXX run with mutex read or write held?
057: * </p>
058: * <p>
059: * {@link #projectOpened} and {@link #projectClosed} are always called in pairs,
060: * e.g. a project cannot be opened twice in a row without being closed in between.
061: * Also a project left open at the end of one VM session will receive
062: * {@link #projectClosed} before shutdown and (if an open project list is persisted)
063: * {@link #projectOpened} sometime during the next startup.
064: * </p>
065: * <p>
066: * An instance should be placed into a project's lookup to register it. (That means either
067: * directly placed in the {@link org.netbeans.api.project.Project}'s lookup or
068: * in the {@link org.netbeans.spi.project.LookupProvider} instance that extends the default
069: * project's Lookup, if applicable to the specific project type.)
070: * All instances found in the lookup will be notified on project open and close.
071: * </p>
072: * @see org.netbeans.api.project.Project#getLookup
073: * @author Jesse Glick
074: */
075: public abstract class ProjectOpenedHook {
076:
077: static {
078: ProjectOpenedTrampoline.DEFAULT = new ProjectOpenedTrampoline() {
079: public void projectOpened(ProjectOpenedHook hook) {
080: hook.projectOpened();
081: }
082:
083: public void projectClosed(ProjectOpenedHook hook) {
084: hook.projectClosed();
085: }
086: };
087: }
088:
089: /**
090: * Default constructor for use by subclasses.
091: */
092: protected ProjectOpenedHook() {
093: }
094:
095: /**
096: * Called when a project is opened in the GUI.
097: * <div class="nonnormative">
098: * <p>Typical things to do here:</p>
099: * <ul>
100: * <li><p>
101: * Update build scripts using
102: * <a href="@ANT/PROJECT@/org/netbeans/spi/project/support/ant/GeneratedFilesHelper.html#refreshBuildScript"><code>GeneratedFilesHelper.refreshBuildScript(...)</code></a>.
103: * </p></li>
104: * <li><p>Call <a href="@JAVA/API@/org/netbeans/api/java/classpath/GlobalPathRegistry.html#register"><code>GlobalPathRegistry.register(...)</code></a>
105: * with source, compile, and boot paths known to the project.</p></li>
106: * <li><p>Write property <code>user.properties.file</code> to <code>private.properties</code>
107: * with absolute file path of the <code>build.properties</code> from
108: * the IDE's user directory. This makes it easier for the user to run headless
109: * builds in some cases. The IDE's user directory is defined in
110: * <code>netbeans.user</code> property of IDE's VM.</p></li>
111: * </ul>
112: * </div>
113: */
114: protected abstract void projectOpened();
115:
116: /**
117: * Called when a project is closed in the GUI.
118: * <div class="nonnormative">
119: * <p>Typical things to do here:</p>
120: * <ul>
121: * <li><p>
122: * Call
123: * {@link org.netbeans.api.project.ProjectManager#saveProject}
124: * as a precaution in case the project was modified in an unusual
125: * way (e.g. using
126: * {@link org.netbeans.spi.project.AuxiliaryConfiguration}).
127: * </p></li>
128: * <li><p>Call <a href="@JAVA/API@/org/netbeans/api/java/classpath/GlobalPathRegistry.html#unregister"><code>GlobalPathRegistry.unregister(...)</code></a>
129: * with the same paths are were previously registered.</p></li>
130: * </ul>
131: * </div>
132: */
133: protected abstract void projectClosed();
134:
135: }
|