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: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2007 Sun Microsystems, Inc.
038: */
039:
040: package org.netbeans.modules.php.rt.providers.impl.nodes;
041:
042: import java.awt.Component;
043: import org.netbeans.modules.php.rt.providers.impl.DefaultServerCustomizer;
044: import org.netbeans.modules.php.rt.providers.impl.HostImpl;
045: import org.netbeans.modules.php.rt.providers.impl.ServerCustomizerComponent;
046: import org.netbeans.modules.php.rt.spi.providers.Host;
047: import org.openide.nodes.AbstractNode;
048: import org.openide.nodes.Children;
049: import org.openide.util.Lookup;
050: import org.openide.util.NbBundle;
051:
052: /**
053: *
054: * @author avk
055: */
056: public abstract class AbstractInfoNode extends AbstractNode {
057:
058: static final String ELLIPSIS = " ... "; // NOI18N
059: static final int SHOW_FIRST_CHARS_IN_NAME = 20;
060: static final int SHOW_LAST_CHARS_IN_NAME = 10;
061: static final int ALLOWED_CHARS_IN_NAME = SHOW_FIRST_CHARS_IN_NAME
062: + ELLIPSIS.length() + SHOW_LAST_CHARS_IN_NAME;
063:
064: static final String SERVER_CUSTOMIZER_DIALOG_TITLE = "LBL_Server_Customizer_Dialog_Title"; // NOI18N
065:
066: public AbstractInfoNode(Children children, Lookup lookup) {
067: super (children, lookup);
068: }
069:
070: protected String truncateName(String name) {
071: if (name.length() <= ALLOWED_CHARS_IN_NAME) {
072: return name;
073: }
074: return name.substring(0, SHOW_FIRST_CHARS_IN_NAME + 1)
075: + ELLIPSIS
076: + name.substring(name.length()
077: - SHOW_LAST_CHARS_IN_NAME);
078: }
079:
080: /**
081: * If you do not override org.netbeans.modules.php.rt.providers.impl.AbstractServerNode#getCustomizer()
082: * This Should create ServerCustomizerComponent panel with server specific fields.
083: * It will be Embeded into DefaultServerCustomizer dialog created in
084: * org.netbeans.modules.php.rt.providers.impl.AbstractServerNode#getCustomizer().
085: */
086: protected ServerCustomizerComponent getCustomizerComponent(
087: DefaultServerCustomizer parentDialog) {
088: return null;
089: }
090:
091: /**
092: * Creates DefaultServerCustomizer dialog window with embedded pannel
093: * retrieved from getCustomizerComponent(ServerCustomizer parentDialog).
094: * Should be overriden to create own component.
095: *
096: * @see getCustomizerComponent(DefaultServerCustomizer);
097: */
098: @Override
099: public Component getCustomizer() {
100: Host host = getLookup().lookup(Host.class);
101: if (host != null) {
102: if (host instanceof HostImpl) {
103: HostImpl impl = (HostImpl) host;
104: String title = NbBundle.getMessage(
105: AbstractInfoNode.class,
106: SERVER_CUSTOMIZER_DIALOG_TITLE, impl
107: .getDisplayName());
108:
109: DefaultServerCustomizer customizer = new DefaultServerCustomizer(
110: impl);
111: ServerCustomizerComponent specificCustomizerPanel = getCustomizerComponent(customizer);
112: if (specificCustomizerPanel != null) {
113: return customizer.createCustomizerDialog(
114: specificCustomizerPanel, title);
115: }
116: }
117: }
118: return null;
119: }
120:
121: /**
122: * override this to return <code>true</code> value if you want to support customizer
123: */
124: @Override
125: public boolean hasCustomizer() {
126: return false;
127: }
128:
129: }
|