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: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.modules.profiler.j2ee.selector;
042:
043: import org.netbeans.api.project.Project;
044: import org.netbeans.modules.profiler.j2ee.WebProjectUtils;
045: import org.netbeans.modules.profiler.selector.spi.nodes.SelectorChildren;
046: import org.openide.util.NbBundle;
047: import java.util.ArrayList;
048: import java.util.List;
049: import org.netbeans.modules.profiler.j2ee.selector.nodes.web.WebProjectChildren;
050: import org.netbeans.modules.profiler.selector.spi.SelectionTreeBuilder;
051: import org.netbeans.modules.profiler.selector.spi.nodes.ProjectNode;
052: import org.netbeans.modules.profiler.selector.spi.nodes.SelectorNode;
053:
054: /**
055: *
056: * @author Jaroslav Bachorik
057: */
058: public class PlainWebSelectionTreeBuilder implements
059: SelectionTreeBuilder {
060: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
061:
062: // -----
063: // I18N String constants
064: private static final String DISPLAY_NAME = NbBundle.getMessage(
065: PlainWebSelectionTreeBuilder.class,
066: "PlainWebSelectionTreeBuilder_DisplayName"); // NOI18N
067:
068: // -----
069:
070: //~ Constructors -------------------------------------------------------------------------------------------------------------
071:
072: /** Creates a new instance of PlainWebSelectionTreeBuilder */
073: public PlainWebSelectionTreeBuilder() {
074: }
075:
076: //~ Methods ------------------------------------------------------------------------------------------------------------------
077:
078: public boolean isDefault() {
079: return false;
080: }
081:
082: public String getDisplayName() {
083: return DISPLAY_NAME;
084: }
085:
086: public String getID() {
087: return "J2EE/WEB"; // NOI18N
088: }
089:
090: public boolean isPreferred(Project project) {
091: return isWebProject(project);
092: }
093:
094: public List<SelectorNode> buildSelectionTree(final Project project,
095: final boolean includeSubprojects) {
096: List<SelectorNode> nodes = new ArrayList<SelectorNode>();
097: SelectorNode root = new ProjectNode(project, includeSubprojects) {
098: @Override
099: protected SelectorChildren getChildren() {
100: return new WebProjectChildren(project);
101: }
102: };
103:
104: nodes.add(root);
105:
106: return nodes;
107: }
108:
109: public boolean supports(Project project) {
110: return isWebProject(project);
111: }
112:
113: public String toString() {
114: return getDisplayName();
115: }
116:
117: private boolean isWebProject(Project project) {
118: if (project == null) {
119: return false;
120: }
121:
122: return !WebProjectUtils.getDeploymentDescriptorFileObjects(
123: project, true).isEmpty();
124: }
125: }
|