001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.bpel.nodes.refactoring;
020:
021: import org.netbeans.modules.bpel.editors.api.nodes.NodeType;
022: import org.netbeans.modules.bpel.editors.api.utils.RefactorUtil;
023: import org.netbeans.modules.bpel.model.api.BpelEntity;
024: import org.netbeans.modules.bpel.model.api.Sequence;
025: import org.netbeans.modules.bpel.nodes.BpelNode;
026: import org.netbeans.modules.soa.ui.SoaUiUtil;
027: import org.openide.nodes.Node;
028:
029: /**
030: *
031: * @author Vitaly Bychkov
032: * @version 1.0
033: *
034: */
035: public class UsageContextNode extends UsageFilterNode {
036: private Node originalNode;
037:
038: public UsageContextNode(Node originalNode) {
039: super (originalNode, Children.LEAF);
040: this .originalNode = originalNode;
041: disableDelegation(DELEGATE_GET_DISPLAY_NAME
042: | DELEGATE_SET_DISPLAY_NAME | DELEGATE_GET_NAME
043: | DELEGATE_SET_NAME);
044: }
045:
046: public String getHtmlDisplayName() {
047: return getGraedContextName(getName());
048: }
049:
050: // public String getName() {
051: // Object ref = originalNode.getReference();
052: // if (ref == null || !(ref instanceof BpelEntity)) {
053: // return originalNode.getHtmlDisplayName();
054: // }
055: // return Util.getUsageContextPath((BpelEntity)ref, Sequence.class);
056: // }
057:
058: public String getDisplayName() {
059: return originalNode.getDisplayName();
060: }
061:
062: // TODO r|m
063: public String getName() {
064: // public String getHtmlDisplayName() {
065: // String contextName = getName();
066: if (!(originalNode instanceof BpelNode)) {
067: return originalNode.getHtmlDisplayName();
068: }
069:
070: Object ref = ((BpelNode) originalNode).getReference();
071: if (ref == null || !(ref instanceof BpelEntity)) {
072: return originalNode.getHtmlDisplayName();
073: }
074:
075: String contextName = null;
076: NodeType nodeType = ((BpelNode) originalNode).getNodeType();
077: switch (nodeType) {
078: case VARIABLE_CONTAINER:
079: case CORRELATION_SET_CONTAINER:
080: case MESSAGE_EXCHANGE_CONTAINER:
081: contextName = RefactorUtil.getUsageContextPath(
082: ((BpelNode) originalNode).getHtmlDisplayName(),
083: (BpelEntity) ref, Sequence.class);
084: break;
085: default:
086: contextName = RefactorUtil.getUsageContextPath(
087: (BpelEntity) ref, Sequence.class);
088: }
089:
090: if (contextName == null) {
091: return originalNode.getHtmlDisplayName();
092: }
093: // TODO r | a
094: // contextName = getGraedContextName(contextName);
095: return contextName;
096: }
097:
098: public boolean canRename() {
099: return false;
100: }
101:
102: private String getGraedContextName(String contextPathName) {
103: if (contextPathName == null) {
104: return contextPathName;
105: }
106:
107: int lastSepPosition = contextPathName
108: .lastIndexOf(RefactorUtil.ENTITY_SEPARATOR);
109: if (lastSepPosition > 0) {
110: lastSepPosition++;
111: contextPathName = SoaUiUtil
112: .getGrayString("", contextPathName.substring(0,
113: lastSepPosition)// NOI18N
114: , contextPathName
115: .substring(lastSepPosition), false);
116: }
117: return contextPathName;
118: }
119: }
|