1 19 20 package org.netbeans.modules.languages.features; 21 22 import java.awt.event.ActionEvent ; 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Map ; 28 import javax.swing.text.JTextComponent ; 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 45 public class ExpandFoldTypeAction extends BaseAction { 46 47 public ExpandFoldTypeAction (String name) { 48 super (name); 49 } 52 53 public void actionPerformed (ActionEvent evt, JTextComponent target) { 54 FoldHierarchy hierarchy = FoldHierarchy.get (target); 55 try { 57 String mimeType = (java.lang.String ) target.getDocument ().getProperty ("mimeType"); 58 Language l = ((LanguagesManagerImpl) LanguagesManager.getDefault ()).getLanguage (mimeType); 59 if (expand (hierarchy, l)) return; 60 Iterator <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 <Feature> folds = l.getFeatures (Language.FOLD); 70 Iterator <Feature> it = folds.iterator (); 71 while (it.hasNext ()) { 72 Feature fold = it.next (); 73 String expand = (String ) fold.getValue ("expand_type_action_name");; 74 if (expand == null) continue; 75 if (!expand.equals (getValue (NAME))) 76 continue; 77 String collapse = (String ) fold.getValue ("collapse_type_action_name");; 78 if (collapse == null) continue; 79 List <FoldType> types = new ArrayList <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 |