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-2007 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:
042: package org.netbeans.modules.uml.palette.ui;
043:
044: import java.awt.Image;
045: import org.openide.nodes.Node;
046: import org.openide.ErrorManager;
047: import org.openide.cookies.InstanceCookie;
048: import org.openide.nodes.FilterNode;
049: import org.netbeans.modules.uml.core.support.umlsupport.Log;
050: import org.netbeans.modules.uml.palette.model.ModelingPaletteNodeDescriptor;
051:
052: /**
053: *
054: * @author Thuy
055: */
056:
057: class PaletteElementNode extends FilterNode {
058: Node node;
059: InstanceCookie ic;
060: ModelingPaletteNodeDescriptor nodeDescriptor;
061:
062: private static final int DELEGATE = DELEGATE_SET_NAME
063: | DELEGATE_GET_NAME | DELEGATE_SET_DISPLAY_NAME
064: | DELEGATE_GET_DISPLAY_NAME
065: | DELEGATE_SET_SHORT_DESCRIPTION
066: | DELEGATE_GET_SHORT_DESCRIPTION | DELEGATE_DESTROY
067: | DELEGATE_GET_ACTIONS | DELEGATE_GET_CONTEXT_ACTIONS
068: | DELEGATE_SET_VALUE | DELEGATE_GET_VALUE;
069:
070: public PaletteElementNode(InstanceCookie ic, Node node) {
071: super (node);
072: this .node = node;
073: this .ic = ic;
074: enableDelegation(DELEGATE);
075: nodeDescriptor = getModelingPaletteNodeDescriptorInstance();
076:
077: }
078:
079: public String getDisplayName() {
080: if (nodeDescriptor != null)
081: return nodeDescriptor.getDisplayName();
082: return "Default"; // Should not happen.
083: }
084:
085: public String getShortDescription() {
086: if (nodeDescriptor != null)
087: return nodeDescriptor.getTooltip();
088: return "Default"; // Should not happen.
089: }
090:
091: public Image getIcon(int type) {
092: if (nodeDescriptor != null)
093: return nodeDescriptor.getIcon(type);
094: return null;
095: }
096:
097: public Image getOpenedIcon(int type) {
098: return getIcon(type);
099: }
100:
101: public ModelingPaletteNodeDescriptor getModelingPaletteNodeDescriptorInstance() {
102: if (ic != null) {
103: try {
104: Object o = ic.instanceCreate();
105: if (o instanceof ModelingPaletteNodeDescriptor)
106: return (ModelingPaletteNodeDescriptor) o;
107: } catch (Exception e) {
108: ErrorManager.getDefault().notify(
109: ErrorManager.INFORMATIONAL, e);
110: Log
111: .out("ModelingPaletteNodeDescriptor():getModelingPaletteNodeDescriptorInstance(): Error "
112: + e); // NOI18N
113: }
114: }
115: return null;
116: }
117: }
|