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-2006 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:
042: package org.netbeans.modules.languages.features;
043:
044: import java.util.HashSet;
045: import java.util.Iterator;
046: import java.util.List;
047: import java.util.Set;
048: import javax.swing.JMenu;
049: import javax.swing.text.JTextComponent;
050:
051: import org.netbeans.api.languages.ParseException;
052: import org.netbeans.modules.editor.NbEditorKit.GenerateFoldPopupAction;
053: import org.netbeans.modules.languages.Feature;
054: import org.netbeans.modules.languages.Language;
055: import org.netbeans.modules.languages.LanguagesManager;
056:
057: /**
058: *
059: * @author Jan Jancura
060: */
061: public class LanguagesGenerateFoldPopupAction extends
062: GenerateFoldPopupAction {
063:
064: public static final String EXPAND_PREFIX = "Expand:";
065: public static final String COLLAPSE_PREFIX = "Collapse:";
066:
067: protected void addAdditionalItems(JTextComponent target, JMenu menu) {
068: try {
069: String mimeType = (java.lang.String) target.getDocument()
070: .getProperty("mimeType");
071: Language l = LanguagesManager.getDefault().getLanguage(
072: mimeType);
073: Set expands = new HashSet();
074: addFoldTypes(target, menu, l, expands);
075: Iterator<Language> it = l.getImportedLanguages().iterator();
076: while (it.hasNext())
077: addFoldTypes(target, menu, it.next(), expands);
078: } catch (ParseException ex) {
079: }
080: }
081:
082: private void addFoldTypes(JTextComponent target, JMenu menu,
083: Language language, Set expands) {
084: List<Feature> features = language.getFeatureList().getFeatures(
085: LanguagesFoldManager.FOLD);
086: Iterator<Feature> it = features.iterator();
087: while (it.hasNext()) {
088: Feature fold = it.next();
089: String expand = LocalizationSupport.localize(language,
090: (String) fold.getValue("expand_type_action_name"));
091: if (expand == null)
092: continue;
093: if (expands.contains(expand))
094: continue;
095: expands.add(expand);
096: String collapse = LocalizationSupport
097: .localize(language, (String) fold
098: .getValue("collapse_type_action_name"));
099: if (collapse == null)
100: continue;
101: addAction(target, menu, EXPAND_PREFIX + expand);
102: addAction(target, menu, COLLAPSE_PREFIX + collapse);
103: setAddSeparatorBeforeNextAction(true);
104: }
105: }
106: }
|