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