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: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.netbeans.modules.visualweb.project.jsfloader.test;
029:
030: import java.beans.PropertyChangeListener;
031: import java.beans.PropertyChangeSupport;
032: import java.util.ArrayList;
033: import java.util.Collection;
034: import java.util.concurrent.Future;
035: import org.netbeans.api.project.Project;
036: import org.netbeans.api.project.ProjectUtils;
037: import org.netbeans.api.project.ui.OpenProjects;
038: import org.netbeans.modules.project.uiapi.OpenProjectsTrampoline;
039:
040: /**
041: *
042: * @author joelle
043: */
044: public class MockOpenProjectsTrampoline implements
045: OpenProjectsTrampoline {
046: /** Property change listeners registered through API */
047: private PropertyChangeSupport pchSupport;
048:
049: private final Collection<Project> openProjects = new ArrayList<Project>();
050:
051: public MockOpenProjectsTrampoline() {
052:
053: }
054:
055: public Project[] getOpenProjectsAPI() {
056: Project[] projects = new Project[openProjects.size()];
057: openProjects.toArray(projects);
058: return projects;
059: }
060:
061: public void openAPI(Project[] projects, boolean openRequiredProjects) {
062: Project[] oldProjects = getOpenProjectsAPI();
063: for (Project project : projects) {
064: openProjects.add(project);
065: mainProject = project;
066: }
067: Project[] newProjects = getOpenProjectsAPI();
068: if (pchSupport != null) {
069: pchSupport.firePropertyChange(
070: OpenProjects.PROPERTY_OPEN_PROJECTS, oldProjects,
071: newProjects);
072: }
073: }
074:
075: public void closeAPI(Project[] projects) {
076: Project[] oldProjects = getOpenProjectsAPI();
077: for (Project project : projects) {
078: openProjects.remove(project);
079: }
080: Project[] newProjects = getOpenProjectsAPI();
081: if (pchSupport != null) {
082: pchSupport.firePropertyChange(
083: OpenProjects.PROPERTY_OPEN_PROJECTS, oldProjects,
084: newProjects);
085: }
086: }
087:
088: public void addPropertyChangeListenerAPI(
089: PropertyChangeListener listener, Object source) {
090: if (pchSupport == null) {
091: pchSupport = new PropertyChangeSupport(this );
092: }
093: pchSupport.addPropertyChangeListener(listener);
094: }
095:
096: public void removePropertyChangeListenerAPI(
097: PropertyChangeListener listener) {
098: if (pchSupport == null) {
099: pchSupport = new PropertyChangeSupport(this );
100: }
101: pchSupport.removePropertyChangeListener(listener);
102: }
103:
104: private Project mainProject;
105:
106: public Project getMainProject() {
107: return mainProject;
108: }
109:
110: public void setMainProject(Project project) {
111: if (project != null && !openProjects.contains(project)) {
112: throw new IllegalArgumentException("Project "
113: + ProjectUtils.getInformation(project)
114: .getDisplayName()
115: + " is not open and cannot be set as main.");
116: }
117: this .mainProject = project;
118: }
119:
120: public Future<Project[]> openProjectsAPI() {
121: return null;
122: }
123: }
|