KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > languages > features > ExpandFoldTypeAction


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.languages.features;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import javax.swing.text.JTextComponent JavaDoc;
29 import org.netbeans.api.editor.fold.FoldHierarchy;
30 import org.netbeans.api.editor.fold.FoldHierarchy;
31 import org.netbeans.api.editor.fold.FoldType;
32 import org.netbeans.api.editor.fold.FoldUtilities;
33 import org.netbeans.api.languages.LanguagesManager;
34 import org.netbeans.api.languages.ParseException;
35 import org.netbeans.editor.BaseAction;
36 import org.netbeans.modules.languages.Feature;
37 import org.netbeans.modules.languages.Language;
38 import org.netbeans.modules.languages.LanguagesManagerImpl;
39
40
41 /**
42  *
43  * @author Jan Jancura
44  */

45 public class ExpandFoldTypeAction extends BaseAction {
46
47     public ExpandFoldTypeAction (String JavaDoc name) {
48         super (name);
49         //putValue(SHORT_DESCRIPTION, NbBundle.getBundle(JavaKit.class).getString("expand-all-code-block-folds"));
50
//putValue(BaseAction.POPUP_MENU_TEXT, NbBundle.getBundle(JavaKit.class).getString("popup-expand-all-code-block-folds"));
51
}
52
53     public void actionPerformed (ActionEvent JavaDoc evt, JTextComponent JavaDoc target) {
54         FoldHierarchy hierarchy = FoldHierarchy.get (target);
55         // Hierarchy locking done in the utility method
56
try {
57             String JavaDoc mimeType = (java.lang.String JavaDoc) target.getDocument ().getProperty ("mimeType");
58             Language l = ((LanguagesManagerImpl) LanguagesManager.getDefault ()).getLanguage (mimeType);
59             if (expand (hierarchy, l)) return;
60             Iterator JavaDoc<Language> it = l.getImportedLanguages ().iterator ();
61             while (it.hasNext ())
62                 if (expand (hierarchy, it.next ()))
63                     return;
64         } catch (ParseException ex) {
65         }
66     }
67
68     private boolean expand (FoldHierarchy hierarchy, Language l) {
69         List JavaDoc<Feature> folds = l.getFeatures (Language.FOLD);
70         Iterator JavaDoc<Feature> it = folds.iterator ();
71         while (it.hasNext ()) {
72             Feature fold = it.next ();
73             String JavaDoc expand = (String JavaDoc) fold.getValue ("expand_type_action_name");;
74             if (expand == null) continue;
75             if (!expand.equals (getValue (NAME)))
76                 continue;
77             String JavaDoc collapse = (String JavaDoc) fold.getValue ("collapse_type_action_name");;
78             if (collapse == null) continue;
79             List JavaDoc<FoldType> types = new ArrayList JavaDoc<FoldType> ();
80             types.add (Folds.getFoldType (collapse));
81             FoldUtilities.expand (hierarchy, types);
82             return true;
83         }
84         return false;
85     }
86 }
87
88
Popular Tags