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.xslt.mapper.model.targettree;
020:
021: import java.awt.Image;
022: import javax.swing.Action;
023: import javax.swing.JPopupMenu;
024: import org.netbeans.modules.xml.axi.AXIComponent;
025: import org.netbeans.modules.xml.axi.Element;
026: import org.netbeans.modules.xml.xpath.XPathPredicateExpression;
027: import org.netbeans.modules.xslt.mapper.model.PredicatedAxiComponent;
028: import org.netbeans.modules.xslt.mapper.model.nodes.actions.DeletePredicateAction;
029: import org.netbeans.modules.xslt.mapper.model.nodes.actions.EditPredicateAction;
030: import org.netbeans.modules.xslt.mapper.model.nodes.visitor.NodeVisitor;
031: import org.netbeans.modules.xslt.mapper.view.PredicateManager;
032: import org.netbeans.modules.xslt.mapper.view.XsltMapper;
033:
034: /**
035: * A schema node with predicates
036: *
037: * @author nk160297
038: */
039: public class PredicatedSchemaNode extends SchemaNode {
040:
041: /** Creates a new instance of PlaceholderNode */
042: public PredicatedSchemaNode(PredicatedAxiComponent component,
043: XsltMapper mapper) {
044: super (component, mapper);
045: }
046:
047: public PredicatedAxiComponent getPredicatedAxiComp() {
048: return (PredicatedAxiComponent) getDataObject();
049: }
050:
051: public void accept(NodeVisitor visitor) {
052: visitor.visit(this );
053: }
054:
055: public AXIComponent getType() {
056: return ((PredicatedAxiComponent) getDataObject()).getType();
057: }
058:
059: public String toString() {
060: XPathPredicateExpression[] predArr = getPredicatedAxiComp()
061: .getPredicates();
062: String predicatesText = PredicateManager.toString(predArr);
063: if (predicatesText.length() == 0) {
064: return super .toString();
065: } else {
066: return super .toString() + " " + predicatesText;
067: }
068: }
069:
070: // TODO rewrite. The icon should be a bit different.
071: public Image getIcon() {
072: return super .getIcon();
073: }
074:
075: public String getName() {
076: XPathPredicateExpression[] predArr = getPredicatedAxiComp()
077: .getPredicates();
078: String predicatesText = PredicateManager.toString(predArr);
079: if (predicatesText.length() == 0) {
080: return super .getName();
081: } else {
082: return super .getName() + " " + predicatesText;
083: }
084: }
085:
086: public String getTooltipText() {
087: XPathPredicateExpression[] predArr = getPredicatedAxiComp()
088: .getPredicates();
089: String predicatesText = PredicateManager.toString(predArr);
090: if (predicatesText.length() == 0) {
091: return super .getTooltipText();
092: } else {
093: return super .getTooltipText() + " " + predicatesText;
094: }
095: }
096:
097: // TODO rewrite. It should have specific popup menu
098: public JPopupMenu constructPopupMenu() {
099: JPopupMenu rootMenu = new JPopupMenu();
100: //
101: Action newAction;
102: //
103: if (isSourceViewNode()) {
104: AXIComponent sc = getType();
105: if (sc instanceof Element) {
106: newAction = new EditPredicateAction(getMapper(), this );
107: rootMenu.add(newAction);
108: newAction = new DeletePredicateAction(getMapper(), this );
109: rootMenu.add(newAction);
110: }
111: }
112: //
113: return rootMenu;
114: }
115:
116: }
|