KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > project > ui > ProjectOpenedHook


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.spi.project.ui;
21
22 import org.netbeans.modules.project.uiapi.ProjectOpenedTrampoline;
23
24 /**
25  * A hook which can be run when a project is "opened" or "closed" in the GUI.
26  * <p>
27  * The meaning of these terms is intentionally left vague, but typically opening
28  * a project signals that the user may wish to work with it, so it would be a good
29  * idea to make sure caches are up to date, etc. It is perfectly possible to load
30  * and use (even run) projects which are <em>not</em> open, so any project type
31  * provider using this hook cannot rely on it for basic semantics.
32  * </p>
33  * <p>
34  * XXX run with mutex read or write held?
35  * </p>
36  * <p>
37  * {@link #projectOpened} and {@link #projectClosed} are always called in pairs,
38  * e.g. a project cannot be opened twice in a row without being closed in between.
39  * Also a project left open at the end of one VM session will receive
40  * {@link #projectClosed} before shutdown and (if an open project list is persisted)
41  * {@link #projectOpened} sometime during the next startup.
42  * </p>
43  * <p>
44  * An instance should be placed into a project's lookup to register it.
45  * All instances found in the lookup will be notified on project open and close.
46  * </p>
47  * @see org.netbeans.api.project.Project#getLookup
48  * @author Jesse Glick
49  */

50 public abstract class ProjectOpenedHook {
51     
52
53     static {
54         ProjectOpenedTrampoline.DEFAULT = new ProjectOpenedTrampoline() {
55             public void projectOpened(ProjectOpenedHook hook) {
56                 hook.projectOpened();
57             }
58             public void projectClosed(ProjectOpenedHook hook) {
59                 hook.projectClosed();
60             }
61         };
62     }
63
64     
65     /**
66      * Default constructor for use by subclasses.
67      */

68     protected ProjectOpenedHook() {}
69     
70     /**
71      * Called when a project is opened in the GUI.
72      * <div class="nonnormative">
73      * <p>Typical things to do here:</p>
74      * <ul>
75      * <li><p>
76      * Update build scripts using
77      * <a HREF="@ANT/PROJECT@/org/netbeans/spi/project/support/ant/GeneratedFilesHelper.html#refreshBuildScript"><code>GeneratedFilesHelper.refreshBuildScript(...)</code></a>.
78      * </p></li>
79      * <li><p>Call <a HREF="@JAVA/API@/org/netbeans/api/java/classpath/GlobalPathRegistry.html#register"><code>GlobalPathRegistry.register(...)</code></a>
80      * with source, compile, and boot paths known to the project.</p></li>
81      * <li><p>Write property <code>user.properties.file</code> to <code>private.properties</code>
82      * with absolute file path of the <code>build.properties</code> from
83      * the IDE's user directory. This makes it easier for the user to run headless
84      * builds in some cases. The IDE's user directory is defined in
85      * <code>netbeans.user</code> property of IDE's VM.</p></li>
86      * </ul>
87      * </div>
88      */

89     protected abstract void projectOpened();
90     
91     /**
92      * Called when a project is closed in the GUI.
93      * <div class="nonnormative">
94      * <p>Typical things to do here:</p>
95      * <ul>
96      * <li><p>
97      * Call
98      * {@link org.netbeans.api.project.ProjectManager#saveProject}
99      * as a precaution in case the project was modified in an unusual
100      * way (e.g. using
101      * {@link org.netbeans.spi.project.AuxiliaryConfiguration}).
102      * </p></li>
103      * <li><p>Call <a HREF="@JAVA/API@/org/netbeans/api/java/classpath/GlobalPathRegistry.html#unregister"><code>GlobalPathRegistry.unregister(...)</code></a>
104      * with the same paths are were previously registered.</p></li>
105      * </ul>
106      * </div>
107      */

108     protected abstract void projectClosed();
109     
110 }
111
Popular Tags