quynguyen@1759
|
1 |
/*
|
quynguyen@1759
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
quynguyen@1759
|
3 |
*
|
jglick@2927
|
4 |
* Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
|
jglick@2927
|
5 |
*
|
jglick@2927
|
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
|
jglick@2927
|
7 |
* Other names may be trademarks of their respective owners.
|
quynguyen@1759
|
8 |
*
|
quynguyen@1759
|
9 |
* The contents of this file are subject to the terms of either the GNU
|
quynguyen@1759
|
10 |
* General Public License Version 2 only ("GPL") or the Common
|
quynguyen@1759
|
11 |
* Development and Distribution License("CDDL") (collectively, the
|
quynguyen@1759
|
12 |
* "License"). You may not use this file except in compliance with the
|
quynguyen@1759
|
13 |
* License. You can obtain a copy of the License at
|
quynguyen@1759
|
14 |
* http://www.netbeans.org/cddl-gplv2.html
|
quynguyen@1759
|
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
quynguyen@1759
|
16 |
* specific language governing permissions and limitations under the
|
quynguyen@1759
|
17 |
* License. When distributing the software, include this License Header
|
quynguyen@1759
|
18 |
* Notice in each file and include the License file at
|
jglick@2927
|
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
|
quynguyen@1759
|
20 |
* particular file as subject to the "Classpath" exception as provided
|
jglick@2927
|
21 |
* by Oracle in the GPL Version 2 section of the License file that
|
quynguyen@1759
|
22 |
* accompanied this code. If applicable, add the following below the
|
quynguyen@1759
|
23 |
* License Header, with the fields enclosed by brackets [] replaced by
|
quynguyen@1759
|
24 |
* your own identifying information:
|
quynguyen@1759
|
25 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
quynguyen@1759
|
26 |
*
|
quynguyen@1759
|
27 |
* Contributor(s):
|
quynguyen@1759
|
28 |
*
|
quynguyen@1759
|
29 |
* Portions Copyrighted 2007 Sun Microsystems, Inc.
|
quynguyen@1759
|
30 |
*/
|
quynguyen@1759
|
31 |
package org.netbeans.modules.visualweb.project.jsfloader.test;
|
quynguyen@1759
|
32 |
|
quynguyen@1759
|
33 |
import java.beans.PropertyChangeListener;
|
quynguyen@1759
|
34 |
import java.beans.PropertyChangeSupport;
|
quynguyen@1759
|
35 |
import java.util.ArrayList;
|
quynguyen@1759
|
36 |
import java.util.Collection;
|
mkubec@2113
|
37 |
import java.util.concurrent.Future;
|
quynguyen@1759
|
38 |
import org.netbeans.api.project.Project;
|
quynguyen@1759
|
39 |
import org.netbeans.api.project.ProjectUtils;
|
quynguyen@1759
|
40 |
import org.netbeans.api.project.ui.OpenProjects;
|
quynguyen@1759
|
41 |
import org.netbeans.modules.project.uiapi.OpenProjectsTrampoline;
|
quynguyen@1759
|
42 |
|
quynguyen@1759
|
43 |
/**
|
quynguyen@1759
|
44 |
*
|
quynguyen@1759
|
45 |
* @author joelle
|
quynguyen@1759
|
46 |
*/
|
jglick@2753
|
47 |
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.modules.project.uiapi.OpenProjectsTrampoline.class)
|
quynguyen@1759
|
48 |
public class MockOpenProjectsTrampoline implements OpenProjectsTrampoline {
|
quynguyen@1759
|
49 |
/** Property change listeners registered through API */
|
quynguyen@1759
|
50 |
private PropertyChangeSupport pchSupport;
|
quynguyen@1759
|
51 |
|
quynguyen@1759
|
52 |
private final Collection<Project> openProjects = new ArrayList<Project>();
|
quynguyen@1759
|
53 |
|
quynguyen@1759
|
54 |
public MockOpenProjectsTrampoline() {
|
quynguyen@1759
|
55 |
|
quynguyen@1759
|
56 |
}
|
quynguyen@1759
|
57 |
|
quynguyen@1759
|
58 |
public Project[] getOpenProjectsAPI() {
|
quynguyen@1759
|
59 |
Project[] projects = new Project[openProjects.size()];
|
quynguyen@1759
|
60 |
openProjects.toArray(projects);
|
quynguyen@1759
|
61 |
return projects;
|
quynguyen@1759
|
62 |
}
|
quynguyen@1759
|
63 |
|
quynguyen@1759
|
64 |
public void openAPI(Project[] projects, boolean openRequiredProjects) {
|
quynguyen@1759
|
65 |
Project[] oldProjects = getOpenProjectsAPI();
|
quynguyen@1759
|
66 |
for (Project project : projects) {
|
quynguyen@1759
|
67 |
openProjects.add(project);
|
quynguyen@1759
|
68 |
mainProject = project;
|
quynguyen@1759
|
69 |
}
|
quynguyen@1759
|
70 |
Project[] newProjects = getOpenProjectsAPI();
|
quynguyen@1759
|
71 |
if (pchSupport != null) {
|
quynguyen@1759
|
72 |
pchSupport.firePropertyChange(OpenProjects.PROPERTY_OPEN_PROJECTS, oldProjects, newProjects);
|
quynguyen@1759
|
73 |
}
|
quynguyen@1759
|
74 |
}
|
quynguyen@1759
|
75 |
|
quynguyen@1759
|
76 |
public void closeAPI(Project[] projects) {
|
quynguyen@1759
|
77 |
Project[] oldProjects = getOpenProjectsAPI();
|
quynguyen@1759
|
78 |
for (Project project : projects) {
|
quynguyen@1759
|
79 |
openProjects.remove(project);
|
quynguyen@1759
|
80 |
}
|
quynguyen@1759
|
81 |
Project[] newProjects = getOpenProjectsAPI();
|
quynguyen@1759
|
82 |
if (pchSupport != null) {
|
quynguyen@1759
|
83 |
pchSupport.firePropertyChange(OpenProjects.PROPERTY_OPEN_PROJECTS, oldProjects, newProjects);
|
quynguyen@1759
|
84 |
}
|
quynguyen@1759
|
85 |
}
|
quynguyen@1759
|
86 |
|
quynguyen@1759
|
87 |
public void addPropertyChangeListenerAPI(PropertyChangeListener listener, Object source) {
|
quynguyen@1759
|
88 |
if (pchSupport == null) {
|
quynguyen@1759
|
89 |
pchSupport = new PropertyChangeSupport(this);
|
quynguyen@1759
|
90 |
}
|
quynguyen@1759
|
91 |
pchSupport.addPropertyChangeListener(listener);
|
quynguyen@1759
|
92 |
}
|
quynguyen@1759
|
93 |
|
quynguyen@1759
|
94 |
public void removePropertyChangeListenerAPI(PropertyChangeListener listener) {
|
quynguyen@1759
|
95 |
if (pchSupport == null) {
|
quynguyen@1759
|
96 |
pchSupport = new PropertyChangeSupport(this);
|
quynguyen@1759
|
97 |
}
|
quynguyen@1759
|
98 |
pchSupport.removePropertyChangeListener(listener);
|
quynguyen@1759
|
99 |
}
|
quynguyen@1759
|
100 |
|
quynguyen@1759
|
101 |
private Project mainProject;
|
quynguyen@1759
|
102 |
|
quynguyen@1759
|
103 |
public Project getMainProject() {
|
quynguyen@1759
|
104 |
return mainProject;
|
quynguyen@1759
|
105 |
}
|
quynguyen@1759
|
106 |
|
quynguyen@1759
|
107 |
public void setMainProject(Project project) {
|
quynguyen@1759
|
108 |
if (project != null && !openProjects.contains(project)) {
|
quynguyen@1759
|
109 |
throw new IllegalArgumentException("Project " + ProjectUtils.getInformation(project).getDisplayName() + " is not open and cannot be set as main.");
|
quynguyen@1759
|
110 |
}
|
quynguyen@1759
|
111 |
this.mainProject = project;
|
quynguyen@1759
|
112 |
}
|
mkubec@2113
|
113 |
|
mkubec@2113
|
114 |
public Future<Project[]> openProjectsAPI() {
|
mkubec@2113
|
115 |
return null;
|
mkubec@2113
|
116 |
}
|
jglick@3214
|
117 |
@Override
|
jglick@3214
|
118 |
public void openAPI(Project[] prjcts, boolean bln, boolean bln1) {
|
jglick@3214
|
119 |
throw new UnsupportedOperationException("Not supported yet.");
|
jglick@3214
|
120 |
}
|
quynguyen@1759
|
121 |
}
|