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