1 19 20 package org.netbeans.modules.web.core.syntax.completion; 21 22 23 import java.awt.Graphics ; 24 import java.io.IOException ; 25 import javax.swing.text.*; 26 import java.awt.Color ; 27 import java.awt.Component ; 28 import java.io.ByteArrayOutputStream ; 29 import java.io.InputStream ; 30 import java.net.MalformedURLException ; 31 import java.net.URL ; 32 33 import javax.servlet.jsp.tagext.*; 34 35 import org.netbeans.editor.*; 36 import org.netbeans.editor.Utilities; 37 import org.netbeans.editor.ext.ExtFormatter; 38 import org.netbeans.modules.editor.NbEditorUtilities; 39 import org.netbeans.modules.web.core.syntax.spi.AutoTagImporterProvider; 40 import org.openide.util.NbBundle; 41 import org.netbeans.modules.web.core.syntax.*; 42 import org.openide.filesystems.FileObject; 43 import org.openide.filesystems.Repository; 44 import org.openide.loaders.DataFolder; 45 import org.openide.loaders.FolderLookup; 46 import org.openide.util.Lookup; 47 48 49 50 54 55 56 59 public class JspCompletionItem { 60 61 private static final int DIRECTIVE_SORT_PRIORITY = 5; 62 private static final int DEFAULT_SORT_PRIORITY = 10; 63 64 public static abstract class JspResultItem extends org.netbeans.modules.web.core.syntax.completion.ResultItem { 65 67 protected String help; 68 protected String text; 69 private static ResultItemPaintComponent component = null; 70 71 public JspResultItem( String text ) { 72 this.text = text; 73 help = null; 74 } 75 76 public JspResultItem( String text, String help ) { 77 this( text ); 78 this.help = help; 79 } 80 81 public String getItemText() { 82 return text; 83 } 84 85 protected Object getAssociatedObject() { 86 return text; 87 } 88 89 public int getSortPriority() { 90 return DEFAULT_SORT_PRIORITY; 91 } 92 93 public CharSequence getInsertPrefix() { 94 return getItemText(); 95 } 96 97 public Component getPaintComponent(boolean isSelected) { 98 if (component == null) { 99 component = new ResultItemPaintComponent.StringPaintComponent(); 100 } 101 component.setSelected(isSelected); 102 component.setString(text); 103 return component; 104 } 105 106 108 public URL getHelpURL(){ 109 if (help == null || help.equals("")) 110 return null; 111 try{ 112 return new URL (help); 113 } catch (java.io.IOException e){ 114 } 115 return null; 116 } 117 118 121 public String getHelp(){ 122 return help; 123 } 124 125 127 public boolean hasHelp(){ 128 return (help != null && help.length() > 0); 129 } 130 131 public void setHelp(String help){ 132 this.help = help; 133 } 134 135 protected boolean substituteText( JTextComponent c, int offset, int len, String fill, int moveBack) { 136 BaseDocument doc = (BaseDocument)c.getDocument(); 137 try { 138 doc.atomicLock(); 139 try { 140 String currentText = doc.getText(offset, (doc.getLength() - offset) < fill.length() ? (doc.getLength() - offset) : fill.length()) ; 142 if(!fill.substring(0, fill.length() - 1).equals(currentText)) { 143 doc.remove( offset, len ); 145 doc.insertString( offset, fill, null); 146 } else { 147 c.setCaretPosition(c.getCaret().getDot() + fill.length() - len); 148 } 149 150 ExtFormatter f = (ExtFormatter)doc.getFormatter(); 152 int[] fmtBlk = f.getReformatBlock(c, fill); 153 if (fmtBlk != null) { 154 fmtBlk[0] = Utilities.getRowStart(doc, fmtBlk[0]); 155 fmtBlk[1] = Utilities.getRowEnd(doc, fmtBlk[1]); 156 f.reformat(doc, fmtBlk[0], fmtBlk[1], true); 157 } 158 } finally { 159 doc.atomicUnlock(); 160 } 161 if (moveBack != 0) { 162 Caret caret = c.getCaret(); 163 int dot = caret.getDot(); 164 caret.setDot(dot - moveBack); 165 } 166 } catch( BadLocationException exc ) { 167 return false; } catch( IOException exc ) { 169 return false; } 171 return true; 172 } 173 174 public String getPaintText() { 175 return getItemText(); 176 } 177 178 } 179 180 181 public static class PrefixTag extends JspResultItem { 182 183 private TagInfo tagInfo; 184 private boolean isEmpty = false; 185 186 private boolean hasAttributes = false; 187 188 private static ResultItemPaintComponent.JspTagPaintComponent component = null; 189 private static ResultItemPaintComponent.JspTagPaintComponent componentEmpty = null; 190 191 PrefixTag( String text ) { 192 super(text); 193 } 194 195 PrefixTag(String prefix, TagInfo ti, SyntaxElement.Tag set) { 196 this(prefix + ":" + ti.getTagName()); tagInfo = ti; 198 if ((tagInfo != null) && 199 (tagInfo.getBodyContent().equalsIgnoreCase(TagInfo.BODY_CONTENT_EMPTY))) 200 isEmpty = true; 201 if (tagInfo != null) 202 setHelp(tagInfo.getInfoString()); 203 204 if (set != null) hasAttributes = !(set.getAttributes().size() == 0); 206 } 207 208 PrefixTag(String prefix, TagInfo ti) { 209 this(prefix, ti, (SyntaxElement.Tag)null); 210 } 211 212 public boolean hasHelp(){ 213 return true; 214 } 215 216 public TagInfo getTagInfo() { 217 return tagInfo; 218 } 219 220 public String getHelp(){ 221 URL url = super.getHelpURL(); 222 if (url != null){ 223 String surl = url.toString(); 224 int first = surl.indexOf('#') + 1; 225 String help = constructHelp(url); 226 if (first > 0){ 227 int last = surl.lastIndexOf('#') + 1; 228 String from = surl.substring( first , last - 1 ); 229 String to = surl.substring(last); 230 first = help.indexOf(from); 231 if (first > 0){ 232 first = first + from.length() + 2; 233 if (first < help.length()) 234 help = help.substring(first); 235 } 236 last = help.indexOf(to); 237 if (last > 0) 238 help = help.substring(0, last); 239 return help; 240 } 241 242 help = help.substring(help.indexOf("<h2>")); help = help.substring(0, help.lastIndexOf("<h4>")); return help; 245 } 246 return constructHelp(tagInfo); 247 } 248 249 public Component getPaintComponent(boolean isSelected) { 250 ResultItemPaintComponent comp = (isEmpty ? componentEmpty : component); 251 252 if (comp == null) { 253 comp = new ResultItemPaintComponent.JspTagPaintComponent(isEmpty); 254 } 255 comp.setSelected(isSelected); 256 comp.setString(text); 257 return comp; 258 } 259 260 public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) { 261 String suffix = isEmpty? "/>": ">"; 263 if(hasAttributes) suffix = ""; 264 265 if (!getItemText().startsWith("/")) { if (!shift) 267 return substituteText(c, offset, len, getItemText(), 0); 269 boolean hasAttrs = true; 270 if (tagInfo != null) { 271 TagAttributeInfo[] tAttrs = tagInfo.getAttributes(); 272 hasAttrs = (tAttrs != null)? (tAttrs.length > 0): true; 273 } 274 if (hasAttrs) 275 return substituteText(c, offset, len, getItemText() + ( hasAttributes ? "" : " ") + suffix , suffix.length()); else 277 return substituteText(c, offset, len, getItemText() + suffix, 0); 278 } else 279 return substituteText(c, offset, len, getItemText().substring(1) + ">", 0); } 282 283 protected boolean substituteText( JTextComponent c, int offset, int len, String fill, int moveBack) { 284 BaseDocument doc = (BaseDocument)c.getDocument(); 285 boolean value = false; 286 try { 287 doc.atomicLock(); 288 value = super.substituteText(c, offset, len, fill, moveBack); 289 FileObject f = Repository.getDefault().getDefaultFileSystem(). 290 findResource("Editors/" + NbEditorUtilities.getFileObject(c.getDocument()).getMIMEType()+"/AutoTagImportProviders"); 291 if (f != null){ 292 DataFolder folder = DataFolder.findFolder(f); 293 FolderLookup l = new FolderLookup(folder); 294 Lookup.Result result = l.getLookup().lookup(new Lookup.Template(AutoTagImporterProvider.class)); 295 if (result != null){ 296 for(Object instance : result.allInstances()){ 297 ((AutoTagImporterProvider)instance).importLibrary(c.getDocument(), 298 tagInfo.getTagLibrary().getPrefixString(), tagInfo.getTagLibrary().getURI()); 299 } 300 } 301 } 302 } finally { 303 doc.atomicUnlock(); 304 } 305 return value; 306 } 307 } 308 309 310 public abstract static class TagDirective extends JspResultItem { 311 312 protected static ResultItemPaintComponent component = null; 313 314 TagDirective( String text ) { 315 super(text); 316 } 317 318 public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) { 319 return substituteText(c, offset, len, getItemText() + " ", 0); } 321 322 public boolean instantSubstitutionEnabled(JTextComponent c) { 323 return true; 324 } 325 326 public Component getPaintComponent(boolean isSelected) { 327 if (component == null) { 328 component = new ResultItemPaintComponent.JspTagPaintComponent(false); 329 } 330 component.setSelected(isSelected); 331 component.setString(text); 332 return component; 333 } 334 335 336 } 337 338 339 public static class Tag extends JspResultItem { 340 341 protected static ResultItemPaintComponent.JspTagPaintComponent component = null; 342 343 private TagInfo ti = null; 344 345 public Tag( String text ) { 346 super(text); 347 } 348 349 public Tag( String text, TagInfo ti) { 350 this(text); 351 this.ti = ti; 352 if (ti != null) 353 setHelp(ti.getInfoString()); 354 } 355 356 public boolean hasHelp(){ 357 return true; 358 } 359 360 public TagInfo getTagInfo() { 361 return ti; 362 } 363 364 public String getHelp(){ 365 URL url = super.getHelpURL(); 366 if (url != null){ 367 String surl = url.toString(); 368 int first = surl.indexOf('#') + 1; 369 String help = constructHelp(url); 370 if (first > 0){ 371 int last = surl.lastIndexOf('#') + 1; 372 String from = surl.substring( first , last - 1 ); 373 String to = surl.substring(last); 374 first = help.indexOf(from); 375 if (first > 0){ 376 first = first + from.length() + 2; 377 if (first < help.length()) 378 help = help.substring(first); 379 } 380 last = help.indexOf(to); 381 if (last > 0) 382 help = help.substring(0, last); 383 return help; 384 } 385 386 help = help.substring(help.indexOf("<h2>")); help = help.substring(0, help.lastIndexOf("<h4>")); return help; 389 } 390 return constructHelp(ti); 391 } 392 393 public Component getPaintComponent(boolean isSelected) { 394 if (component == null) { 395 component = new ResultItemPaintComponent.JspTagPaintComponent(false); 396 } 397 component.setSelected(isSelected); 398 component.setString(text); 399 return component; 400 } 401 402 public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) { 403 if (!getItemText().startsWith("/")) return substituteText(c, offset, len, getItemText() + " ", 0); else 406 return substituteText(c, offset, len, getItemText().substring(1) + ">", 0); } 408 409 public boolean substituteCommonText( JTextComponent c, int offset, int len, int subLen ) { 410 if (!getItemText().startsWith("/")) { return substituteText(c, offset, len, getItemText().substring(subLen), 0); } else { 413 return substituteText(c, offset, len, getItemText().substring(1, subLen), 0); } 415 } 416 } 417 418 419 static class Directive extends TagDirective { 420 TagInfo tagInfo; 421 422 Directive(String text){ 423 super(text); 424 tagInfo = null; 425 } 426 427 Directive(String text, TagInfo tagInfo ) { 428 super(text); 429 this.tagInfo = tagInfo; 430 if (tagInfo != null) 431 setHelp(tagInfo.getInfoString()); 432 } 433 434 public int getSortPriority() { 435 return DIRECTIVE_SORT_PRIORITY; 436 } 437 438 public String getHelp(){ 439 if (getHelpURL() != null){ 440 String text = constructHelp(getHelpURL()); 441 if (text != null){ 442 text = text.substring(text.indexOf("<h2>")); text = text.substring(0, text.lastIndexOf("<h4>")); return text; 445 } 446 } 447 return constructHelp(tagInfo); 448 } 449 450 public TagInfo getTagInfo(){ 451 return tagInfo; 452 } 453 454 public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) { 455 return substituteText(c, offset, len, "%@ " + getItemText() + " %>", 3); } 457 458 public boolean substituteCommonText( JTextComponent c, int offset, int len, int subLen ) { 459 len = len - 2; 460 offset = offset + 2; 461 return super.substituteCommonText(c, offset, len, subLen); 462 } 463 464 public Component getPaintComponent(boolean isSelected) { 465 if (component == null) { 466 component = new ResultItemPaintComponent.JspDirectivePaintComponent(); 467 } 468 component.setSelected(isSelected); 469 component.setString(getItemText()); 470 return component; 471 } 472 473 } 474 475 476 public static class Attribute extends JspResultItem { 477 private TagAttributeInfo tagAttributeInfo; 478 private boolean required; 479 480 private static ResultItemPaintComponent.JspTagPaintComponent component = null; 481 private static ResultItemPaintComponent.JspTagPaintComponent componentRequired = null; 482 483 Attribute( String text ) { 484 super(text); 485 tagAttributeInfo = null; 486 required = false; 487 } 488 489 Attribute(TagAttributeInfo tai) { 490 super(tai.getName()); 491 required = tai.isRequired(); 492 tagAttributeInfo = tai; 493 if (tai.getTypeName() == null && tai.isFragment()) 494 setHelp("fragment"); else 496 setHelp(tai.getTypeName()); 497 } 498 499 public Component getPaintComponent(boolean isSelected) { 500 ResultItemPaintComponent comp = (required ? componentRequired : component); 501 502 if (comp == null) { 503 comp = new ResultItemPaintComponent.AttributePaintComponent(required); 504 } 505 506 comp.setSelected(isSelected); 507 comp.setString(getItemText()); 508 return comp; 509 } 510 511 public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) { 512 return substituteText(c, offset, len, getItemText() + "=\"\"", 1); } 515 516 public String getHelp() { 517 URL url = super.getHelpURL(); 518 if (url != null){ 519 String surl = url.toString(); 520 int first = surl.indexOf('#') + 1; 521 int last = surl.lastIndexOf('#') + 1; 522 String from; 523 524 if (first < last){ 525 from = surl.substring( first , last - 1 ); 526 } else { 527 from = surl.substring( first ); 528 } 529 String text = constructHelp(getHelpURL()); 530 first = text.indexOf(from); 531 if (first > 0){ 532 first = first + from.length() + 2; 533 if (first < text.length()) 534 text = text.substring(first); 535 } 536 537 String to = surl.substring(last); 538 last = text.indexOf(to); 539 if (last > 0) 540 text = text.substring(0, last); 541 return text; 542 } 543 if (tagAttributeInfo != null){ 544 StringBuffer text = new StringBuffer (); 545 text.append("<table border=\"0\"><tr><td><b>Name:</b></td><td>"); text.append(tagAttributeInfo.getName()); text.append("</td></tr><tr><td><b>Required:</b></td><td>"); text.append(tagAttributeInfo.isRequired()); text.append("</td></tr><tr><td><b>Request-time:</b></td><td>"); text.append(tagAttributeInfo.canBeRequestTime()); text.append("</td></tr><tr><td><b>Fragment:</b></td><td>"); text.append(tagAttributeInfo.isFragment()); text.append("</td></tr></table>"); return text.toString(); 555 } 556 return super.getHelp(); 557 } 558 559 public URL getHelpURL(){ 560 URL url = super.getHelpURL(); 561 if (url != null){ 562 String surl = url.toString(); 563 int index = surl.lastIndexOf('#'); if (index > 0) 565 surl = surl.substring(0, index); 566 try { 567 url = new URL (surl); 568 } catch (MalformedURLException e){ 569 } 570 } 571 return url; 572 } 573 574 } 575 576 577 static class AttributeValue extends JspResultItem { 578 579 AttributeValue( String text ) { 580 super(text); 582 } 583 584 public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) { 585 return substituteText(c, offset, len, getItemText(), 0); 586 } 587 } 588 589 590 public static class FileAttributeValue extends JspResultItem { 591 private javax.swing.ImageIcon icon; 592 private Color color; 593 594 FileAttributeValue(String text, Color color){ 595 this(text, color, null); 596 } 597 598 FileAttributeValue(String text, Color color, javax.swing.ImageIcon icon){ 599 super(text); 600 this.color = color; 601 this.icon = icon; 602 } 603 604 public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) { 605 return substituteText(c, offset, len, getItemText(), 0); 606 } 607 608 public Component getPaintComponent(final boolean isSelected) { 609 return new ResultItemPaintComponent() { 610 public void draw(Graphics g) { 611 drawIcon(g, FileAttributeValue.this.icon); 612 drawString(g, text, FileAttributeValue.this.color); 613 } 614 615 public boolean isSelected() { 616 return isSelected; 617 } 618 }; 619 } 620 } 621 622 private static String constructHelp(URL url){ 623 if (url == null ) 624 return null; 625 try{ 626 InputStream is = url.openStream(); 627 byte buffer[] = new byte[1000]; 628 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 629 int count = 0; 630 do { 631 count = is.read(buffer); 632 if (count > 0) baos.write(buffer, 0, count); 633 } while (count > 0); 634 635 is.close(); 636 String text = baos.toString(); 637 baos.close(); 638 return text; 639 } catch (java.io.IOException e){ 640 return null; 641 } 642 } 643 644 private static String constructHelp(TagInfo tagInfo){ 645 if (tagInfo == null) return null; 646 647 StringBuffer sb = new StringBuffer (); 648 sb.append("<h2>").append(getString("LBL_TagName")).append(" "); sb.append(tagInfo.getTagName()).append("</h2>"); String val = tagInfo.getDisplayName(); 651 if (val != null) { 652 sb.append("<p>").append(getString("LBL_DisplayName")); sb.append("<i>").append(val).append("</i>"); } 655 val = tagInfo.getInfoString(); 656 if (val != null) 657 sb.append("<hr>").append(val).append("<hr>"); 659 sb.append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"1\">"); sb.append("<tr bgcolor=\"#CCCCFF\"><td colspan=\"2\"><font size=\"+2\"><b>"); sb.append("Tag Information</b></font></td></tr>"); sb.append("<tr><td>Tag Class</td><td>"); if (tagInfo.getTagClassName() != null && !tagInfo.getClass().equals("") ) 664 sb.append(tagInfo.getTagClassName()); 665 else 666 sb.append("<i>None</i>"); sb.append("</td></tr><tr><td>Body Content</td><td>"); sb.append(tagInfo.getBodyContent()); 669 sb.append("</td></tr><tr><td>Display Name</td><td>"); if (tagInfo.getDisplayName() != null && !tagInfo.getDisplayName().equals("")){ 671 sb.append(tagInfo.getDisplayName()); 672 } else 673 sb.append("<i>None</i>"); sb.append("</td></tr></table><br>"); 676 sb.append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"1\">"); sb.append("<tr bgcolor=\"#CCCCFF\"><td colspan=\"3\"><font size=\"+2\"><b>Attributes</b></font></td></tr>"); 679 TagAttributeInfo [] attrs = tagInfo.getAttributes(); 680 if (attrs != null && attrs.length > 0){ 681 sb.append("<tr><td><b>Name</b></td><td><b>Required</b></td><td><b>Request-time</b></td></tr>"); for (int i = 0; i < attrs.length; i++){ 683 sb.append("<tr><td>"); sb.append(attrs[i].getName()); 685 sb.append("</td><td>"); sb.append(attrs[i].isRequired()); 687 sb.append("</td><td>"); sb.append(attrs[i].canBeRequestTime()); 689 sb.append("</td></tr>"); } 691 } else { 692 sb.append("<tr><td colspan=\"3\"><i>No Attributes Defined.</i></td></tr>"); } 694 sb.append("</table><br>"); sb.append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"1\">"); sb.append("<tr bgcolor=\"#CCCCFF\"><td colspan=\"4\"><font size=\"+2\"><b>Variables</b></font></td></tr>"); TagVariableInfo [] variables = tagInfo.getTagVariableInfos(); 698 if (variables != null && variables.length > 0){ 699 sb.append("<tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Declare</b></td><td><b>Scope</b></td></tr>"); for (int i = 0; i < variables.length; i++){ 701 sb.append("<tr><td>"); if (variables[i].getNameGiven() != null && !variables[i].getNameGiven().equals("")){ sb.append(variables[i].getNameGiven()); 704 } else { 705 if(variables[i].getNameFromAttribute() != null && !variables[i].getNameFromAttribute().equals("")) sb.append("<i>From attribute '").append(variables[i].getNameFromAttribute()).append("'</i>"); else 708 sb.append("<i>Unknown</i>"); } 710 sb.append("</td><td><code>"); if (variables[i].getClassName() == null || variables[i].getClassName().equals("") ) 712 sb.append("java.lang.String"); else 714 sb.append(variables[i].getClassName()); 715 sb.append("</code></td></tr>"); sb.append("</td><td>"); sb.append(variables[i].getDeclare()); 718 sb.append("</td></tr>"); sb.append("</td><td>"); switch (variables[i].getScope()){ 721 case VariableInfo.AT_BEGIN: 722 sb.append("AT_BEGIN"); break; case VariableInfo.AT_END: 724 sb.append("AT_END"); break; default: 726 sb.append("NESTED"); } 728 sb.append("</td></tr>"); } 730 } else { 731 sb.append("<tr><td colspan=\"4\"><i>No Variables Defined.</i></td></tr>"); } 733 sb.append("</table><br>"); return sb.toString(); 735 } 736 737 private static String getString(String key){ 738 return NbBundle.getMessage(JspCompletionItem.class, key); 739 } 740 741 742 744 public interface ELItem{}; 745 746 public static class ELImplicitObject extends JspResultItem implements ELItem { 747 748 private static ResultItemPaintComponent.ELImplicitObjectPaintComponent paintComponent = null; 749 750 int type; 751 752 ELImplicitObject(String text, int type){ 753 super(text); 754 this.type = type; 755 } 756 757 public int getSortPriority() { 758 return 15; 759 } 760 761 public Component getPaintComponent(boolean isSelected) { 762 if (paintComponent == null) 763 paintComponent = new ResultItemPaintComponent.ELImplicitObjectPaintComponent(); 764 paintComponent.setString(text); 765 paintComponent.setType(type); 766 return paintComponent; 767 } 768 769 public String getItemText() { 770 String result = text; 771 if (type == org.netbeans.modules.web.core.syntax.completion.ELImplicitObjects.MAP_TYPE) 772 result = result + "[]"; 773 return result; } 775 776 public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) { 777 if (type == org.netbeans.modules.web.core.syntax.completion.ELImplicitObjects.MAP_TYPE) 778 return substituteText(c, offset, len, getItemText(), 1); 779 else 780 return substituteText(c, offset, len, getItemText(), 0); 781 } 782 } 783 784 785 public static class ELBean extends JspResultItem implements ELItem { 786 787 private static ResultItemPaintComponent.ELBeanPaintComponent paintComponent = null; 788 789 protected String type; 790 791 public ELBean( String text, String type ) { 792 super(text); 793 if (type.lastIndexOf('.')> -1 ) 794 this.type = type.substring(type.lastIndexOf('.')+1); 795 else 796 this.type = type; 797 } 798 799 public int getSortPriority() { 800 return 10; 801 } 802 803 public Component getPaintComponent(boolean isSelected) { 804 if (paintComponent == null) 805 paintComponent = new ResultItemPaintComponent.ELBeanPaintComponent(); 806 paintComponent.setString(text); 807 paintComponent.setTypeName(type); 808 return paintComponent; 809 } 810 } 811 812 public static class ELProperty extends ELBean implements ELItem { 813 814 private static ResultItemPaintComponent.ELPropertyPaintComponent paintComponent = null; 815 816 public ELProperty( String text, String type ) { 817 super(text, type); 818 } 819 820 public Component getPaintComponent(boolean isSelected) { 821 if (paintComponent == null) 822 paintComponent = new ResultItemPaintComponent.ELPropertyPaintComponent(); 823 paintComponent.setString(text); 824 paintComponent.setTypeName(type); 825 return paintComponent; 826 } 827 } 828 829 public static class ELFunction extends ELBean implements ELItem { 830 831 private static ResultItemPaintComponent.ELFunctionPaintComponent paintComponent = null; 832 833 private String prefix; 834 private String parameters; 835 836 837 public ELFunction( String prefix, String name, String type, String parameters) { 838 super(name, type); 839 this.prefix = prefix; 840 this.parameters = parameters; 841 } 842 843 public Component getPaintComponent(boolean isSelected) { 844 if (paintComponent == null) 845 paintComponent = new ResultItemPaintComponent.ELFunctionPaintComponent(); 846 paintComponent.setString(text); 847 paintComponent.setTypeName(type); 848 paintComponent.setPrefix(prefix); 849 paintComponent.setParameters(parameters); 850 return paintComponent; 851 } 852 853 public int getSortPriority() { 854 return 12; 855 } 856 857 public String getItemText() { 858 return prefix+":"+text+"()"; } 860 861 public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) { 862 return substituteText(c, offset, len, getItemText(), 1); 863 } 864 } 865 866 } 867 | Popular Tags |