KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > project > ui > OpenProjectsTrampolineImpl


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.modules.project.ui;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.beans.PropertyChangeSupport JavaDoc;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.api.project.ui.OpenProjects;
27 import org.netbeans.modules.project.uiapi.OpenProjectsTrampoline;
28
29 /**
30  * List of projects open in the GUI.
31  * @author Petr Hrebejk
32  */

33 public final class OpenProjectsTrampolineImpl implements OpenProjectsTrampoline, PropertyChangeListener JavaDoc {
34
35     /** Property change listeners registered through API */
36     private PropertyChangeSupport JavaDoc pchSupport;
37     
38     private boolean listenersRegistered;
39     
40     public OpenProjectsTrampolineImpl() {
41         pchSupport = new PropertyChangeSupport JavaDoc( this );
42     }
43     
44     public Project[] getOpenProjectsAPI() {
45         return OpenProjectList.getDefault().getOpenProjects();
46     }
47
48     public void openAPI (Project[] projects, boolean openRequiredProjects) {
49         OpenProjectList.getDefault().open (projects, openRequiredProjects);
50     }
51
52     public void closeAPI(Project[] projects) {
53         OpenProjectList.getDefault().close(projects, false);
54     }
55
56     public void addPropertyChangeListenerAPI( PropertyChangeListener JavaDoc listener ) {
57         boolean shouldRegisterListener;
58         
59         synchronized (this) {
60             if (shouldRegisterListener = !listenersRegistered) {
61                 listenersRegistered = true;
62             }
63         }
64         
65         if (shouldRegisterListener) {
66             //make sure we are listening on OpenProjectList so the events are be propagated.
67
//see issue #65928:
68
OpenProjectList.getDefault().addPropertyChangeListener( this );
69         }
70         
71         pchSupport.addPropertyChangeListener( listener );
72     }
73     
74     public void removePropertyChangeListenerAPI( PropertyChangeListener JavaDoc listener ) {
75         pchSupport.removePropertyChangeListener( listener );
76     }
77     
78     public void propertyChange( PropertyChangeEvent JavaDoc e ) {
79         
80         if ( e.getPropertyName().equals( OpenProjectList.PROPERTY_OPEN_PROJECTS ) ) {
81             pchSupport.firePropertyChange( OpenProjects.PROPERTY_OPEN_PROJECTS, e.getOldValue(), e.getNewValue() );
82         }
83         if ( e.getPropertyName().equals( OpenProjectList.PROPERTY_MAIN_PROJECT ) ) {
84             pchSupport.firePropertyChange( OpenProjects.PROPERTY_MAIN_PROJECT, e.getOldValue(), e.getNewValue() );
85         }
86     }
87         
88     public Project getMainProject() {
89         return OpenProjectList.getDefault().getMainProject();
90     }
91     
92     public void setMainProject(Project project) {
93         OpenProjectList.getDefault().setMainProject(project);
94     }
95     
96 }
97
Popular Tags