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: package org.netbeans.modules.php.editor.completion;
042:
043: import java.util.Set;
044: import javax.swing.ImageIcon;
045: import org.netbeans.modules.gsf.api.Element;
046: import org.netbeans.modules.gsf.api.ElementKind;
047: import org.netbeans.modules.gsf.api.HtmlFormatter;
048: import org.netbeans.modules.gsf.api.Modifier;
049:
050: /**
051: * Completion proposal for the PHP code block.
052: *
053: * @author Victor G. Vasilyev
054: */
055: class PHPBlockItem extends CompletionItem {
056: // private static final String ICON_FILE =
057: // "org/netbeans/modules/php/editor/completion/php_block.png"; //NOI18N
058: private static final ImageIcon ICON = null;
059: // new ImageIcon(org.openide.util.Utilities.loadImage(ICON_FILE));
060:
061: private static final String NAME = "<?php >";
062: private static final String INSERTED_TEXT = "<?php >";
063: private static final String CUSTOM_INSERT_TEMPLATE = "<?php ${cursor} ?>";
064: private static final String RIGHT_SIDE_HTML = "PHP Code Block";
065: private static final String DOCUMENTATION = "<html>"
066: + "<h2>The PHP Code Block.</h2>"
067: + "<b><?php</b> | <b>?></b>";
068:
069: public PHPBlockItem(CodeCompletionContext context) {
070: super (context.getCaretOffset(), context.getFormatter());
071: }
072:
073: public String getName() {
074: return NAME;
075: }
076:
077: public String getInsertPrefix() {
078: // It seems, if the getCustomInsertTemplate() method will return
079: // non-null value and CUSTOM_INSERT_TEMPLATE will be actually used
080: // instead then the returned value should be non-null only to make this
081: // completion proposal applicable. Actually, the returned value will
082: // never be used elsewhere.
083: // i.e. non-null value indicates that this completion proposal
084: // is applicable for inserting.
085: return INSERTED_TEXT;
086: }
087:
088: public String getLhsHtml() {
089: HtmlFormatter formatter = getFormatter();
090: formatter.reset();
091: formatter.name(getKind(), true);
092: formatter.appendText(getName());
093: formatter.name(getKind(), false);
094: return formatter.getText();
095: }
096:
097: public String getRhsHtml() {
098: return RIGHT_SIDE_HTML;
099: }
100:
101: public ElementKind getKind() {
102: return ElementKind.OTHER;
103: }
104:
105: public ImageIcon getIcon() {
106: return ICON;
107: }
108:
109: public Set<Modifier> getModifiers() {
110: return null;
111: }
112:
113: public boolean isSmart() {
114: return false;
115: }
116:
117: @Override
118: public String getCustomInsertTemplate() {
119: return CUSTOM_INSERT_TEMPLATE;
120: }
121:
122: @Override
123: public Element getElement() {
124: return new DocumentableElement() {
125:
126: public String getIn() {
127: return null;
128: }
129:
130: public ElementKind getKind() {
131: return getKind();
132: }
133:
134: public Set<Modifier> getModifiers() {
135: return getModifiers();
136: }
137:
138: public String getName() {
139: return getName();
140: }
141:
142: public String getDocumentation() {
143: return DOCUMENTATION;
144: }
145: };
146: }
147:
148: }
|