KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > syntax > JSPKit


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.web.core.syntax;
21
22
23 import java.util.Map JavaDoc;
24 import org.netbeans.api.lexer.LanguagePath;
25 import org.netbeans.modules.web.core.syntax.deprecated.Jsp11Syntax;
26 import org.netbeans.modules.web.core.syntax.deprecated.ELDrawLayerFactory;
27 import org.netbeans.modules.web.core.syntax.formatting.JspFormatter;
28 import java.awt.event.ActionEvent JavaDoc;
29 import java.beans.*;
30 import javax.swing.Action JavaDoc;
31 import javax.swing.JMenu JavaDoc;
32 import javax.swing.text.*;
33 import org.netbeans.api.html.lexer.HTMLTokenId;
34 import org.netbeans.api.java.lexer.JavaTokenId;
35 import org.netbeans.api.lexer.Language;
36 import org.netbeans.api.lexer.TokenHierarchy;
37 import org.netbeans.api.lexer.TokenSequence;
38 import org.netbeans.editor.BaseAction;
39 import org.netbeans.editor.BaseDocument;
40 import org.netbeans.editor.DrawLayer;
41 import org.netbeans.editor.DrawLayerFactory;
42 import org.netbeans.editor.Syntax;
43 import org.netbeans.editor.Utilities;
44 import org.netbeans.editor.ext.Completion;
45 import org.netbeans.editor.ext.ExtEditorUI;
46 import org.netbeans.editor.ext.ExtSyntaxSupport;
47 import org.netbeans.editor.ext.java.JavaSyntax;
48 import org.netbeans.modules.editor.NbEditorDocument;
49 import org.netbeans.modules.editor.NbEditorUtilities;
50 import org.netbeans.modules.web.core.syntax.folding.JspFoldTypes;
51 import org.netbeans.spi.jsp.lexer.JspParseData;
52 import org.netbeans.spi.lexer.TokenHierarchyControl;
53 import org.openide.ErrorManager;
54 import org.openide.text.CloneableEditorSupport;
55 import org.openide.util.NbBundle;
56 import org.openide.util.WeakListeners;
57 import org.openide.filesystems.FileObject;
58 import org.openide.loaders.DataObject;
59 import org.netbeans.editor.SyntaxSupport;
60 import org.netbeans.editor.BaseKit;
61 import org.netbeans.editor.Formatter;
62 import org.netbeans.editor.ext.CompletionJavaDoc;
63 import org.netbeans.editor.ext.ExtKit;
64 import org.netbeans.editor.ext.java.JavaDrawLayerFactory;
65 import org.netbeans.editor.ext.html.HTMLSyntax;
66 import org.netbeans.modules.editor.java.JavaKit;
67 import org.netbeans.modules.web.core.syntax.spi.JSPColoringData;
68 import org.netbeans.modules.web.core.syntax.spi.JspContextInfo;
69 import org.netbeans.api.editor.fold.FoldHierarchy;
70 import org.netbeans.api.editor.fold.FoldUtilities;
71 import org.netbeans.api.jsp.lexer.JspTokenId;
72 import org.netbeans.api.lexer.InputAttributes;
73 import org.netbeans.editor.BaseKit.InsertBreakAction;
74 import org.netbeans.editor.ext.ExtKit.ExtDefaultKeyTypedAction;
75 import org.netbeans.editor.ext.ExtKit.ExtDeleteCharAction;
76 import org.netbeans.modules.editor.NbEditorKit;
77 import org.netbeans.modules.editor.NbEditorKit.GenerateFoldPopupAction;
78
79 /**
80  * Editor kit implementation for JSP content type
81  *
82  * @author Miloslav Metelka, Petr Jiricka, Yury Kamen
83  * @author Marek.Fukala@Sun.COM
84  * @version 1.5
85  */

86 public class JSPKit extends NbEditorKit implements org.openide.util.HelpCtx.Provider{
87     
88     public static final String JavaDoc JSP_MIME_TYPE = "text/x-jsp"; // NOI18N
89
public static final String JavaDoc TAG_MIME_TYPE = "text/x-tag"; // NOI18N
90

91     //comment folds
92
public static final String JavaDoc collapseAllCommentsAction = "collapse-all-comment-folds"; //NOI18N
93
public static final String JavaDoc expandAllCommentsAction = "expand-all-comment-folds"; //NOI18N
94

95     //scripting folds
96
public static final String JavaDoc collapseAllScriptingAction = "collapse-all-scripting-folds"; //NOI18N
97
public static final String JavaDoc expandAllScriptingAction = "expand-all-scripting-folds"; //NOI18N
98

99     /** serialVersionUID */
100     private static final long serialVersionUID = 8933974837050367142L;
101     
102     public static final boolean debug = false;
103     
104     /** Default constructor */
105     public JSPKit() {
106         super();
107     }
108     
109     public String JavaDoc getContentType() {
110         return JSP_MIME_TYPE;
111     }
112     
113     /** Creates a new instance of the syntax coloring parser */
114     public Syntax createSyntax(Document doc) {
115         //TODO - place the coloring listener initialization to
116
//more appropriate place. The createSyntax method is likely
117
//going to be removed.
118
initLexerColoringListener(doc);
119         
120         DataObject dobj = NbEditorUtilities.getDataObject(doc);
121         FileObject fobj = (dobj != null) ? dobj.getPrimaryFile() : null;
122         
123         //String mimeType = NbEditorUtilities.getMimeType(doc);
124

125         Syntax contentSyntax = getSyntaxForLanguage(doc, JspUtils.getContentLanguage());
126         Syntax scriptingSyntax = getSyntaxForLanguage(doc, JspUtils.getScriptingLanguage());
127         final Jsp11Syntax newSyntax = new Jsp11Syntax(contentSyntax, scriptingSyntax);
128         
129         // tag library coloring data stuff
130
JSPColoringData data = data = JspUtils.getJSPColoringData(doc, fobj);
131         // construct the listener
132
PropertyChangeListener pList = new ColoringListener(doc, data, newSyntax);
133         // attach the listener
134
// PENDING - listen on the language
135
//jspdo.addPropertyChangeListener(WeakListeners.propertyChange(pList, jspdo));
136
if (data != null) {
137             data.addPropertyChangeListener(WeakListeners.propertyChange(pList, data));
138         }
139         return newSyntax;
140     }
141     
142     protected Action JavaDoc[] createActions() {
143         Action JavaDoc[] javaActions = new Action JavaDoc[] {
144             // new JspJavaGenerateGotoPopupAction(),
145
// new JavaKit.JavaJMIGotoSourceAction(),
146
// new JavaKit.JavaJMIGotoDeclarationAction(),
147
// new JavaKit.JavaGotoSuperImplementation(),
148
// the jsp editor has own action for switching beetween matching blocks
149
new MatchBraceAction(ExtKit.matchBraceAction, false),
150             new MatchBraceAction(ExtKit.selectionMatchBraceAction, true),
151             new JspGenerateFoldPopupAction(),
152             new CollapseAllCommentsFolds(),
153             new ExpandAllCommentsFolds(),
154             new CollapseAllScriptingFolds(),
155             new ExpandAllScriptingFolds(),
156             new JspInsertBreakAction(),
157             new JspDefaultKeyTypedAction(),
158             new JspDeleteCharAction(deletePrevCharAction, false),
159         };
160         
161         return TextAction.augmentList(super.createActions(), javaActions);
162     }
163     
164     private static class LexerColoringListener implements PropertyChangeListener {
165         
166         private Document doc;
167         private JSPColoringData data;
168         private JspParseData jspParseData;
169         
170         private LexerColoringListener(Document doc, JSPColoringData data, JspParseData jspParseData) {
171             this.doc = doc;
172             this.data = data; //hold ref to JSPColoringData so LCL is not GC'ed
173
this.jspParseData = jspParseData;
174         }
175         
176         public void propertyChange(PropertyChangeEvent evt) {
177             if (JSPColoringData.PROP_COLORING_CHANGE.equals(evt.getPropertyName())) {
178                 recolor();
179             }
180         }
181         private void recolor() {
182             jspParseData.updateParseData((Map JavaDoc<String JavaDoc,String JavaDoc>)data.getPrefixMapper(), data.isELIgnored(), data.isXMLSyntax());
183
184             TokenHierarchyControl thc = (TokenHierarchyControl)doc.getProperty(TokenHierarchyControl.class);
185             if(thc != null) {
186                 thc.rebuild();
187             }
188         }
189         
190     }
191     
192     private static class ColoringListener implements PropertyChangeListener {
193         private Document doc;
194         private Object JavaDoc parsedDataRef; // NOPMD: hold a reference to the data we are listening on
195
// so it does not get garbage collected
196
private Jsp11Syntax syntax;
197         //private JspDataObject jspdo;
198

199         public ColoringListener(Document doc, JSPColoringData data, Jsp11Syntax syntax) {
200             this.doc = doc;
201             // we must keep the reference to the structure we are listening on so it's not gc'ed
202
this.parsedDataRef = data;
203             this.syntax = syntax;
204             // syntax must keep a reference to this object so it's not gc'ed
205
syntax.listenerReference = this;
206             syntax.data = data;
207             /* jspdo = (JspDataObject)NbEditorUtilities.getDataObject(doc);*/
208         }
209         
210         private void recolor() {
211             if (doc instanceof BaseDocument)
212                 ((BaseDocument)doc).invalidateSyntaxMarks();
213         }
214         
215         public void propertyChange(PropertyChangeEvent evt) {
216             // System.out.println("**************** PCHL - propertyChange()");
217
if (syntax == null)
218                 return;
219             if (syntax.listenerReference != this) {
220                 syntax = null; // should help garbage collection
221
return;
222             }
223            /* if (JspDataObject.PROP_CONTENT_LANGUAGE.equals(evt.getPropertyName())) {
224                 syntax.setContentSyntax(JSPKit.getSyntaxForLanguage(doc, jspdo.getContentLanguage()));
225                 recolor();
226             }
227             if (JspDataObject.PROP_SCRIPTING_LANGUAGE.equals(evt.getPropertyName())) {
228                 syntax.setScriptingSyntax(JSPKit.getSyntaxForLanguage(doc, jspdo.getScriptingLanguage()));
229                 recolor();
230             }*/

231             if (JSPColoringData.PROP_COLORING_CHANGE.equals(evt.getPropertyName())) {
232                 recolor();
233             }
234         }
235     }
236     
237     public static Syntax getSyntaxForLanguage(Document doc, String JavaDoc language) {
238         EditorKit kit = CloneableEditorSupport.getEditorKit(language);
239         if (kit instanceof JavaKit) {
240             JavaKit jkit = (JavaKit)kit;
241             String JavaDoc sourceLevel = jkit.getSourceLevel((BaseDocument)doc);
242             //create a special javasyntax patched for use in JSPs (fix of #55628)
243
return new JavaSyntax(sourceLevel, true);
244         } else {
245             return new HTMLSyntax();
246         }
247     }
248     
249     /** Create syntax support */
250     public SyntaxSupport createSyntaxSupport(BaseDocument doc) {
251         DataObject dobj = NbEditorUtilities.getDataObject(doc);
252         if (dobj != null) {
253             if (dobj.getPrimaryFile() != null)
254                 return new JspSyntaxSupport(doc,
255                         JspContextInfo.getContextInfo(dobj.getPrimaryFile()).getCachedOpenInfo(doc, dobj.getPrimaryFile(), false).isXmlSyntax());
256         }
257         return new JspSyntaxSupport(doc, false);
258         
259     }
260     
261     /** This method now returns null since the code completion is got from
262      * code completion providers declared in the module layer.
263      */

264     public Completion createCompletion(ExtEditorUI extEditorUI) {
265         return null;
266     }
267     
268     /** This method now returns null since the code completion is got from
269      * code completion providers declared in the module layer.
270      */

271     public CompletionJavaDoc createCompletionJavaDoc(ExtEditorUI extEditorUI) {
272         return null;
273     }
274     
275     protected void initDocument(BaseDocument doc) {
276         doc.addLayer(new JavaDrawLayerFactory.JavaLayer(),
277                 JavaDrawLayerFactory.JAVA_LAYER_VISIBILITY);
278         doc.addDocumentListener(new JavaDrawLayerFactory.LParenWatcher());
279         doc.addLayer(new ELDrawLayerFactory.ELLayer(),
280                 ELDrawLayerFactory.EL_LAYER_VISIBILITY);
281         doc.addDocumentListener(new ELDrawLayerFactory.LParenWatcher());
282     }
283     
284     private void initLexerColoringListener(Document doc) {
285         DataObject dobj = NbEditorUtilities.getDataObject(doc);
286         FileObject fobj = (dobj != null) ? dobj.getPrimaryFile() : null;
287         JSPColoringData data = JspUtils.getJSPColoringData(doc, fobj);
288         
289         if(data == null) {
290             return ;
291         }
292         
293         JspParseData jspParseData = new JspParseData();
294         jspParseData.updateParseData((Map JavaDoc<String JavaDoc,String JavaDoc>)data.getPrefixMapper(), data.isELIgnored(), data.isXMLSyntax());
295         PropertyChangeListener lexerColoringListener = new LexerColoringListener(doc, data, jspParseData);
296         
297         data.addPropertyChangeListener(WeakListeners.propertyChange(lexerColoringListener, data));
298         //reference LCL from document to prevent LCL to be GC'ed
299
doc.putProperty(LexerColoringListener.class, lexerColoringListener);
300         
301         //add an instance of InputAttributes to the document property,
302
//lexer will use it to read coloring information
303
InputAttributes inputAttributes = new InputAttributes();
304         inputAttributes.setValue(JspTokenId.language(), JspParseData.class, jspParseData, false);
305         doc.putProperty(InputAttributes.class, inputAttributes);
306     }
307     
308     public Formatter createFormatter() {
309         return new JspFormatter(this.getClass());
310         
311     }
312     
313     // <RAVE> #62993
314
// Implement HelpCtx.Provider to provide help for CloneableEditor
315
public org.openide.util.HelpCtx getHelpCtx() {
316         return new org.openide.util.HelpCtx(JSPKit.class);
317     }
318     
319     
320     /** Implementation of MatchBraceAction, whic move the cursor in the matched block.
321      */

322     public static class MatchBraceAction extends ExtKit.MatchBraceAction {
323         
324         private boolean select; // whether the text between matched blocks should be selected
325
public MatchBraceAction(String JavaDoc name, boolean select) {
326             super(name, select);
327             this.select = select;
328         }
329         
330         public void actionPerformed(ActionEvent JavaDoc evt, JTextComponent target) {
331             if (target != null) {
332                 try {
333                     Caret caret = target.getCaret();
334                     BaseDocument doc = Utilities.getDocument(target);
335                     int dotPos = caret.getDot();
336                     dotPos--; //adjust position
337
ExtSyntaxSupport sup = (ExtSyntaxSupport)doc.getSyntaxSupport();
338                     
339                     TokenHierarchy hi = TokenHierarchy.get(doc);
340                     BaseKit kit = null;
341                     try {
342                         //are we in HTML or Java?
343
if(JspSyntaxSupport.tokenSequence(hi, HTMLTokenId.language(), dotPos) != null) {
344                             kit = getKit(getClass().forName("org.netbeans.modules.editor.html.HTMLKit")); //NOI18N
345
}
346                         if(JspSyntaxSupport.tokenSequence(hi, JavaTokenId.language(), dotPos) != null) {
347                             kit = getKit(getClass().forName("org.netbeans.modules.editor.java.JavaKit")); //NOI18N
348
}
349                     } catch (java.lang.ClassNotFoundException JavaDoc e){
350                         kit = null;
351                         ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
352                     }
353                     
354                     if (kit == null) {
355                         //just JSP - do the JSP brace match
356
if (dotPos > 0) {
357                             int[] matchBlk = sup.findMatchingBlock(dotPos - 1, false);
358                             if (matchBlk != null) {
359                                 if (select) {
360                                     caret.moveDot(matchBlk[1]);
361                                 } else {
362                                     caret.setDot(matchBlk[1]);
363                                 }
364                             }
365                         }
366                     } else {
367                         //we are in HTML or Java
368
Action JavaDoc action = kit.getActionByName(select ? ExtKit.selectionMatchBraceAction : ExtKit.matchBraceAction);
369                         if (action != null && action instanceof ExtKit.MatchBraceAction){
370                             ((ExtKit.MatchBraceAction)action).actionPerformed(evt, target);
371                         } else {
372                             super.actionPerformed(evt, target);
373                         }
374                     }
375                     
376                 } catch (BadLocationException e) {
377                     target.getToolkit().beep();
378                 }
379             }
380         }
381     }
382     
383     public static class JspGenerateFoldPopupAction extends GenerateFoldPopupAction {
384         
385         protected void addAdditionalItems(JTextComponent target, JMenu JavaDoc menu){
386             addAction(target, menu, collapseAllCommentsAction);
387             addAction(target, menu, expandAllCommentsAction);
388             setAddSeparatorBeforeNextAction(true);
389             addAction(target, menu, collapseAllScriptingAction);
390             addAction(target, menu, expandAllScriptingAction);
391         }
392     }
393     
394     public static class ExpandAllCommentsFolds extends BaseAction{
395         public ExpandAllCommentsFolds(){
396             super(expandAllCommentsAction);
397             putValue(SHORT_DESCRIPTION, NbBundle.getBundle(JSPKit.class).getString("expand-all-comment-folds"));
398             putValue(BaseAction.POPUP_MENU_TEXT, NbBundle.getBundle(JSPKit.class).getString("popup-expand-all-comment-folds"));
399         }
400         
401         public void actionPerformed(ActionEvent JavaDoc evt, JTextComponent target) {
402             FoldHierarchy hierarchy = FoldHierarchy.get(target);
403             // Hierarchy locking done in the utility method
404
FoldUtilities.expand(hierarchy, JspFoldTypes.COMMENT);
405             FoldUtilities.expand(hierarchy, JspFoldTypes.HTML_COMMENT);
406             
407         }
408     }
409     
410     public static class CollapseAllCommentsFolds extends BaseAction{
411         public CollapseAllCommentsFolds(){
412             super(collapseAllCommentsAction);
413             putValue(SHORT_DESCRIPTION, NbBundle.getBundle(JSPKit.class).getString("collapse-all-comment-folds"));
414             putValue(BaseAction.POPUP_MENU_TEXT, NbBundle.getBundle(JSPKit.class).getString("popup-collapse-all-comment-folds"));
415         }
416         
417         public void actionPerformed(ActionEvent JavaDoc evt, JTextComponent target) {
418             FoldHierarchy hierarchy = FoldHierarchy.get(target);
419             // Hierarchy locking done in the utility method
420
FoldUtilities.collapse(hierarchy, JspFoldTypes.COMMENT);
421             FoldUtilities.collapse(hierarchy, JspFoldTypes.HTML_COMMENT);
422         }
423     }
424     
425     public static class ExpandAllScriptingFolds extends BaseAction{
426         public ExpandAllScriptingFolds(){
427             super(expandAllScriptingAction);
428             putValue(SHORT_DESCRIPTION, NbBundle.getBundle(JSPKit.class).getString("expand-all-scripting-folds"));
429             putValue(BaseAction.POPUP_MENU_TEXT, NbBundle.getBundle(JSPKit.class).getString("popup-expand-all-scripting-folds"));
430         }
431         
432         public void actionPerformed(ActionEvent JavaDoc evt, JTextComponent target) {
433             FoldHierarchy hierarchy = FoldHierarchy.get(target);
434             // Hierarchy locking done in the utility method
435
FoldUtilities.expand(hierarchy, JspFoldTypes.SCRIPTLET);
436             FoldUtilities.expand(hierarchy, JspFoldTypes.DECLARATION);
437         }
438     }
439     
440     public static class CollapseAllScriptingFolds extends BaseAction{
441         public CollapseAllScriptingFolds(){
442             super(collapseAllScriptingAction);
443             putValue(SHORT_DESCRIPTION, NbBundle.getBundle(JSPKit.class).getString("collapse-all-scripting-folds"));
444             putValue(BaseAction.POPUP_MENU_TEXT, NbBundle.getBundle(JSPKit.class).getString("popup-collapse-all-scripting-folds"));
445         }
446         
447         public void actionPerformed(ActionEvent JavaDoc evt, JTextComponent target) {
448             FoldHierarchy hierarchy = FoldHierarchy.get(target);
449             // Hierarchy locking done in the utility method
450
FoldUtilities.collapse(hierarchy, JspFoldTypes.SCRIPTLET);
451             FoldUtilities.collapse(hierarchy, JspFoldTypes.DECLARATION);
452         }
453     }
454     
455     // private static TokenContextPath getTokenContextPath(Caret caret, Document doc){
456
// if (doc instanceof BaseDocument){
457
// int dotPos = caret.getDot();
458
// ExtSyntaxSupport sup = (ExtSyntaxSupport)((BaseDocument)doc).getSyntaxSupport();
459
// if (dotPos>0){
460
// try{
461
// TokenItem token = sup.getTokenChain(dotPos-1, dotPos);
462
// if (token != null){
463
// return token.getTokenContextPath();
464
// }
465
// }catch(BadLocationException ble){
466
// ErrorManager.getDefault().notify(ErrorManager.WARNING, ble);
467
// }
468
// }
469
// }
470
// return null;
471
// }
472

473     public static class JspInsertBreakAction extends InsertBreakAction {
474         public void actionPerformed(ActionEvent JavaDoc e, JTextComponent target) {
475             if (target!=null){
476                 TokenSequence javaTokenSequence = JspSyntaxSupport.tokenSequence(
477                         TokenHierarchy.get(target.getDocument()),
478                         JavaTokenId.language(),
479                         target.getCaret().getDot() - 1);
480                 
481                 if (javaTokenSequence != null){
482                     JavaKit jkit = (JavaKit)getKit(JavaKit.class);
483                     if (jkit!=null){
484                         Action JavaDoc action = jkit.getActionByName(DefaultEditorKit.insertBreakAction);
485                         if (action != null && action instanceof JavaKit.JavaInsertBreakAction){
486                             ((JavaKit.JavaInsertBreakAction)action).actionPerformed(e, target);
487                             return;
488                         }
489                     }
490                 }
491             }
492             super.actionPerformed(e, target);
493         }
494     }
495     
496     public static class JspDefaultKeyTypedAction extends ExtDefaultKeyTypedAction {
497         public void actionPerformed(ActionEvent JavaDoc e, JTextComponent target) {
498             if (target!=null){
499                 TokenSequence javaTokenSequence = JspSyntaxSupport.tokenSequence(
500                         TokenHierarchy.get(target.getDocument()),
501                         JavaTokenId.language(),
502                         target.getCaret().getDot() - 1);
503                 
504                 if (javaTokenSequence != null){
505                     JavaKit jkit = (JavaKit)getKit(JavaKit.class);
506                     if (jkit!=null){
507                         Action JavaDoc action = jkit.getActionByName(DefaultEditorKit.defaultKeyTypedAction);
508                         if (action != null && action instanceof JavaKit.JavaDefaultKeyTypedAction){
509                             ((JavaKit.JavaDefaultKeyTypedAction)action).actionPerformed(e, target);
510                             return;
511                         }
512                     }
513                 }
514             }
515             super.actionPerformed(e, target);
516         }
517     }
518     
519     public static class JspDeleteCharAction extends ExtDeleteCharAction {
520         
521         public JspDeleteCharAction(String JavaDoc nm, boolean nextChar) {
522             super(nm, nextChar);
523         }
524         
525         public void actionPerformed(ActionEvent JavaDoc e, JTextComponent target) {
526             if (target!=null){
527                 TokenSequence javaTokenSequence = JspSyntaxSupport.tokenSequence(
528                         TokenHierarchy.get(target.getDocument()),
529                         JavaTokenId.language(),
530                         target.getCaret().getDot() - 1);
531                 
532                 if (javaTokenSequence != null){
533                     JavaKit jkit = (JavaKit)getKit(JavaKit.class);
534                     if (jkit!=null){
535                         Action JavaDoc action = jkit.getActionByName(DefaultEditorKit.deletePrevCharAction);
536                         if (action != null && action instanceof JavaKit.JavaDeleteCharAction){
537                             ((JavaKit.JavaDeleteCharAction)action).actionPerformed(e, target);
538                             return;
539                         }
540                     }
541                 }
542             }
543             super.actionPerformed(e, target);
544         }
545     }
546     
547     // public static class JspJavaGenerateGotoPopupAction extends JavaKit.JavaGenerateGoToPopupAction {
548
//
549
// protected void addAction(JTextComponent target, JMenu menu,
550
// String actionName) {
551
// BaseKit kit = Utilities.getKit(target);
552
// if (kit == null) return;
553
// Action a = kit.getActionByName(actionName);
554
// if (a!=null){
555
// //test context only for context-aware actions
556
// if(ExtKit.gotoSourceAction.equals(actionName) ||
557
// ExtKit.gotoDeclarationAction.equals(actionName) ||
558
// ExtKit.gotoSuperImplementationAction.equals(actionName))
559
// a.setEnabled(isJavaContext(target));
560
//
561
// addAction(target, menu, a);
562
// } else { // action-name is null, add the separator
563
// menu.addSeparator();
564
// }
565
// }
566
//
567
// private boolean isJavaContext(JTextComponent target) {
568
// JspSyntaxSupport sup = (JspSyntaxSupport)Utilities.getSyntaxSupport(target);
569
// int carretOffset = target.getCaret().getDot();
570
// try {
571
// TokenItem tok = sup.getTokenChain(carretOffset, carretOffset + 1);
572
// return tok.getTokenContextPath().contains(JavaTokenContext.contextPath);
573
// }catch(BadLocationException e) {
574
// //do nothing
575
// return true;
576
// }
577
// }
578
//
579
// }
580

581     
582 }
583
584
Popular Tags