001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.project.ui;
042:
043: import java.awt.Image;
044: import java.beans.PropertyChangeListener;
045: import java.net.URL;
046: import java.util.Collection;
047: import java.util.Collections;
048: import java.util.Iterator;
049: import javax.swing.Action;
050: import javax.swing.Icon;
051: import org.netbeans.api.project.Project;
052: import org.netbeans.api.project.ProjectInformation;
053: import org.netbeans.spi.project.ui.LogicalViewProvider;
054: import org.netbeans.spi.project.ui.support.CommonProjectActions;
055: import org.openide.actions.CustomizeAction;
056: import org.openide.filesystems.FileObject;
057: import org.openide.filesystems.FileUtil;
058: import org.openide.filesystems.URLMapper;
059: import org.openide.loaders.DataObject;
060: import org.openide.nodes.AbstractNode;
061: import org.openide.nodes.Children;
062: import org.openide.nodes.Node;
063: import org.openide.util.Lookup;
064: import org.openide.util.NbBundle;
065: import org.openide.util.Utilities;
066: import org.openide.util.actions.SystemAction;
067: import org.openide.util.lookup.Lookups;
068: import org.openidex.search.SearchInfo;
069:
070: /**
071: * Dummy project that shows a wait node while the real project list is
072: * loaded
073: *
074: * @author Tim Boudreau, Jaroslav Tulach
075: */
076: final class LazyProject implements Project, ProjectInformation,
077: SearchInfo, LogicalViewProvider {
078: URL url;
079: String displayName;
080: ExtIcon icon;
081:
082: public LazyProject(URL url, String displayName, ExtIcon icon) {
083: super ();
084: this .url = url;
085: this .displayName = displayName;
086: this .icon = icon;
087: }
088:
089: public FileObject getProjectDirectory() {
090: FileObject fo = URLMapper.findFileObject(url);
091: if (fo == null) {
092: OpenProjectList.LOGGER.warning("Project dir with " + url
093: + " not found!");
094: fo = FileUtil.createMemoryFileSystem().getRoot();
095: }
096: return fo;
097: }
098:
099: public Lookup getLookup() {
100: return Lookups.fixed(this );
101: }
102:
103: public String getName() {
104: return displayName;
105: }
106:
107: public String getDisplayName() {
108: return displayName;
109: }
110:
111: public Icon getIcon() {
112: return icon.getIcon();
113: }
114:
115: public Project getProject() {
116: return this ;
117: }
118:
119: public void addPropertyChangeListener(
120: PropertyChangeListener listener) {
121: }
122:
123: public void removePropertyChangeListener(
124: PropertyChangeListener listener) {
125: }
126:
127: public boolean canSearch() {
128: return false;
129: }
130:
131: public Iterator<DataObject> objectsToSearch() {
132: return Collections.<DataObject> emptyList().iterator();
133: }
134:
135: public Node createLogicalView() {
136: return new ProjNode(Lookups.singleton(this ));
137: }
138:
139: public Node findPath(Node root, Object target) {
140: return null;
141: }
142:
143: private final class ProjNode extends AbstractNode {
144: public ProjNode(Lookup lookup) {
145: super (new ProjCh(), lookup);
146:
147: setName(url.toExternalForm());
148: setDisplayName(displayName);
149: }
150:
151: @Override
152: public Image getIcon(int type) {
153: return Utilities.icon2Image(icon.getIcon());
154: }
155:
156: @Override
157: public Image getOpenedIcon(int type) {
158: return getIcon(type);
159: }
160:
161: @Override
162: public Action getPreferredAction() {
163: OpenProjectList.preferredProject(LazyProject.this );
164: return super .getPreferredAction();
165: }
166:
167: @Override
168: public boolean hasCustomizer() {
169: return false;
170: }
171:
172: @Override
173: public Action[] getActions(boolean context) {
174: OpenProjectList.preferredProject(LazyProject.this );
175: return new Action[] {
176: SystemAction.get(LazyProjectInitializing.class),
177: CommonProjectActions.closeProjectAction(),
178: SystemAction.get(CustomizeAction.class), };
179: }
180: } // end of ProjNode
181:
182: private final class ProjCh extends Children.Array {
183: @Override
184: protected Collection<Node> initCollection() {
185: AbstractNode n = new AbstractNode(Children.LEAF);
186: n.setName("init"); // NOI18N
187: n.setDisplayName(NbBundle.getMessage(ProjCh.class,
188: "MSG_ProjChInit"));
189: n
190: .setIconBaseWithExtension("org/netbeans/modules/project/ui/resources/wait.gif");
191: return Collections.singletonList((Node) n);
192: }
193:
194: @Override
195: protected void addNotify() {
196: super.addNotify();
197: OpenProjectList.preferredProject(LazyProject.this);
198: }
199: }
200: }
|