KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > mimelookup > impl > InstanceProviderLookup


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.editor.mimelookup.impl;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.logging.Logger JavaDoc;
27 import org.netbeans.spi.editor.mimelookup.InstanceProvider;
28 import org.openide.util.lookup.AbstractLookup;
29 import org.openide.util.lookup.InstanceContent;
30
31 /**
32  *
33  * @author vita
34  */

35 public final class InstanceProviderLookup extends AbstractLookup {
36
37     private static final Logger JavaDoc LOG = Logger.getLogger(InstanceProvider.class.getName());
38     
39     private InstanceContent content;
40     private InstanceProvider instanceProvider;
41     
42     private CompoundFolderChildren children;
43     private PCL listener = new PCL();
44
45     private final String JavaDoc LOCK = new String JavaDoc("InstanceProviderLookup.LOCK"); //NOI18N
46

47     /** Creates a new instance of InstanceProviderLookup */
48     public InstanceProviderLookup(String JavaDoc [] paths, InstanceProvider instanceProvider) {
49         this(paths, instanceProvider, new InstanceContent());
50     }
51     
52     private InstanceProviderLookup(String JavaDoc [] paths, InstanceProvider instanceProvider, InstanceContent content) {
53         super(content);
54         
55         this.content = content;
56         this.instanceProvider = instanceProvider;
57         
58         this.children = new CompoundFolderChildren(paths, true);
59         this.children.addPropertyChangeListener(listener);
60         
61         rebuild();
62     }
63
64     private void rebuild() {
65         List JavaDoc files = children.getChildren();
66         Object JavaDoc instance = instanceProvider.createInstance(files);
67         content.set(Collections.singleton(instance), null);
68     }
69     
70     private class PCL implements PropertyChangeListener JavaDoc {
71         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
72             rebuild();
73         }
74     } // End of PCL class
75
}
76
Popular Tags