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