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.navigation;
029:
030: import java.beans.PropertyChangeListener;
031: import java.util.ArrayList;
032: import java.util.Collection;
033: import java.util.HashMap;
034: import java.util.Map;
035: import java.util.Map.Entry;
036: import java.util.Set;
037: import java.util.concurrent.Future;
038: import org.netbeans.api.project.Project;
039: import org.netbeans.api.project.ProjectUtils;
040: import org.netbeans.modules.project.uiapi.OpenProjectsTrampoline;
041:
042: /**
043: *
044: * @author joelle
045: */
046: public class MockOpenProjectsTrampoline implements
047: OpenProjectsTrampoline {
048:
049: private Collection<Project> openProjects = new ArrayList<Project>();
050:
051: public MockOpenProjectsTrampoline() {
052: }
053:
054: public Project[] getOpenProjectsAPI() {
055: Project[] projects = new Project[openProjects.size()];
056: openProjects.toArray(projects);
057: return projects;
058: }
059:
060: public void openAPI(Project[] projects, boolean openRequiredProjects) {
061: for (Project project : projects) {
062: openProjects.add(project);
063: mainProject = project;
064: }
065: }
066:
067: public void closeAPI(Project[] projects) {
068: for (Project project : projects) {
069: openProjects.remove(project);
070: listeners.remove(project);
071: }
072: }
073:
074: Map<Object, PropertyChangeListener> listeners = new HashMap<Object, PropertyChangeListener>();
075:
076: public void addPropertyChangeListenerAPI(
077: PropertyChangeListener listener, Object source) {
078: listeners.put(source, listener);
079: }
080:
081: public void removePropertyChangeListenerAPI(
082: PropertyChangeListener listener) {
083: if (listeners.containsValue(listener)) {
084: Set<Entry<Object, PropertyChangeListener>> entries = listeners
085: .entrySet();
086: for (Entry<Object, PropertyChangeListener> entry : entries) {
087: if (entry.getValue().equals(listener)) {
088: Object object = entry.getKey();
089: listeners.remove(object);
090: }
091: }
092: }
093: }
094:
095: private Project mainProject;
096:
097: public Project getMainProject() {
098: return mainProject;
099: }
100:
101: public void setMainProject(Project project) {
102: if (project != null && !openProjects.contains(project)) {
103: throw new IllegalArgumentException("Project "
104: + ProjectUtils.getInformation(mainProject)
105: .getDisplayName()
106: + " is not open and cannot be set as main.");
107: }
108: this .mainProject = project;
109: }
110:
111: public Future<Project[]> openProjectsAPI() {
112: return null;
113: }
114: }
|