visualweb.project.jsfloader/test/unit/src/org/netbeans/modules/visualweb/project/jsfloader/test/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.project.jsfloader.test;
    32 
    33 import java.beans.PropertyChangeListener;
    34 import java.beans.PropertyChangeSupport;
    35 import java.util.ArrayList;
    36 import java.util.Collection;
    37 import java.util.concurrent.Future;
    38 import org.netbeans.api.project.Project;
    39 import org.netbeans.api.project.ProjectUtils;
    40 import org.netbeans.api.project.ui.OpenProjects;
    41 import org.netbeans.modules.project.uiapi.OpenProjectsTrampoline;
    42 
    43 /**
    44  *
    45  * @author joelle
    46  */
    47 @org.openide.util.lookup.ServiceProvider(service=org.netbeans.modules.project.uiapi.OpenProjectsTrampoline.class)
    48 public class MockOpenProjectsTrampoline implements OpenProjectsTrampoline {
    49     /** Property change listeners registered through API */
    50     private PropertyChangeSupport pchSupport;
    51     
    52     private final Collection<Project> openProjects = new ArrayList<Project>();
    53 
    54     public MockOpenProjectsTrampoline() {
    55         
    56     }
    57 
    58     public Project[] getOpenProjectsAPI() {
    59         Project[] projects = new Project[openProjects.size()];
    60         openProjects.toArray(projects);
    61         return projects;
    62     }
    63 
    64     public void openAPI(Project[] projects, boolean openRequiredProjects) {
    65         Project[] oldProjects = getOpenProjectsAPI();
    66         for (Project project : projects) {
    67             openProjects.add(project);
    68             mainProject = project;
    69         }
    70         Project[] newProjects = getOpenProjectsAPI();
    71         if (pchSupport != null) {
    72             pchSupport.firePropertyChange(OpenProjects.PROPERTY_OPEN_PROJECTS, oldProjects, newProjects);
    73         }
    74     }
    75 
    76     public void closeAPI(Project[] projects) {
    77         Project[] oldProjects = getOpenProjectsAPI();
    78         for (Project project : projects) {
    79             openProjects.remove(project);
    80         }
    81         Project[] newProjects = getOpenProjectsAPI();
    82         if (pchSupport != null) {
    83             pchSupport.firePropertyChange(OpenProjects.PROPERTY_OPEN_PROJECTS, oldProjects, newProjects);
    84         }
    85     }
    86 
    87     public void addPropertyChangeListenerAPI(PropertyChangeListener listener, Object source) {
    88         if (pchSupport == null) {
    89             pchSupport = new PropertyChangeSupport(this);
    90         }
    91         pchSupport.addPropertyChangeListener(listener);
    92     }
    93 
    94     public void removePropertyChangeListenerAPI(PropertyChangeListener listener) {
    95         if (pchSupport == null) {
    96             pchSupport = new PropertyChangeSupport(this);
    97         }
    98         pchSupport.removePropertyChangeListener(listener);
    99     }
   100     
   101     private Project mainProject;
   102 
   103     public Project getMainProject() {
   104         return mainProject;
   105     }
   106 
   107     public void setMainProject(Project project) {
   108         if (project != null && !openProjects.contains(project)) {
   109             throw new IllegalArgumentException("Project " + ProjectUtils.getInformation(project).getDisplayName() + " is not open and cannot be set as main.");
   110         }
   111         this.mainProject = project;
   112     }
   113 
   114     public Future<Project[]> openProjectsAPI() {
   115         return null;
   116     }
   117     @Override
   118     public void openAPI(Project[] prjcts, boolean bln, boolean bln1) {
   119         throw new UnsupportedOperationException("Not supported yet.");
   120     }
   121 }