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 java.util.ArrayList;
023: import java.util.List;
024: import javax.swing.Action;
025: import javax.swing.JMenu;
026: import javax.swing.JPopupMenu;
027: import javax.swing.JSeparator;
028: import org.netbeans.modules.soa.ui.SoaUiUtil;
029: import org.netbeans.modules.xml.axi.AXIComponent;
030: import org.netbeans.modules.xslt.mapper.model.nodes.NodeFactory;
031: import org.netbeans.modules.xslt.mapper.model.nodes.TreeNode;
032: import org.netbeans.modules.xslt.mapper.model.nodes.actions.ActionConst;
033: import org.netbeans.modules.xslt.mapper.model.nodes.actions.ActionGroupConstructor;
034: import org.netbeans.modules.xslt.mapper.model.nodes.actions.AddNestedAxiGroup;
035: import org.netbeans.modules.xslt.mapper.model.nodes.actions.AddNestedRulesGroup;
036: import org.netbeans.modules.xslt.mapper.model.nodes.actions.DeleteAction;
037: import org.netbeans.modules.xslt.mapper.model.nodes.actions.SupportedRuleTypes;
038: import org.netbeans.modules.xslt.mapper.model.nodes.visitor.NodeVisitor;
039: import org.netbeans.modules.xslt.mapper.view.XsltMapper;
040: import org.netbeans.modules.xslt.model.XslComponent;
041: import org.openide.util.NbBundle;
042:
043: /**
044: *
045: * @author Alexey
046: */
047: public class RuleNode extends StylesheetNode {
048:
049: public RuleNode(XslComponent component, XsltMapper mapper) {
050: super (component, mapper);
051: }
052:
053: protected List<TreeNode> loadChildren() {
054: XslComponent myself = (XslComponent) getDataObject();
055: List<XslComponent> children = myself.getChildren();
056:
057: List<TreeNode> result = new ArrayList<TreeNode>(children.size());
058:
059: for (XslComponent c : children) {
060: TreeNode newNode = (TreeNode) NodeFactory.createNode(c,
061: getMapper());
062:
063: if (newNode != null) {
064: newNode.setParent(this );
065: result.add(newNode);
066: }
067: }
068:
069: return result;
070: }
071:
072: public AXIComponent getType() {
073: return (getParent() != null) ? getParent().getType() : null;
074: }
075:
076: public boolean isMappable() {
077: return false;
078: }
079:
080: public void accept(NodeVisitor visitor) {
081: visitor.visit(this );
082: }
083:
084: public String toString() {
085: return getComponent().getComponentType().getSimpleName();
086: }
087:
088: public Image getIcon() {
089: return SupportedRuleTypes.getCommonImage();
090: }
091:
092: public String getName() {
093: if (getType() == null) {
094: return SoaUiUtil.getFormattedHtmlString(true,
095: new SoaUiUtil.TextChunk(toString(),
096: SoaUiUtil.MISTAKE_RED));
097: } else {
098: return toString();
099: }
100: }
101:
102: public JPopupMenu constructPopupMenu() {
103: JPopupMenu rootMenu = new JPopupMenu();
104: Action newAction;
105: //
106: String localizedName = NbBundle.getMessage(ActionConst.class,
107: ActionConst.ADD_MENU);
108: JMenu addMenu = new JMenu(localizedName);
109: //
110: ActionGroupConstructor nestedAxi = new AddNestedAxiGroup(
111: getMapper(), this );
112: Action[] addNestedAxiArr = nestedAxi.getActions();
113: //
114: AddNestedRulesGroup nestedRules = new AddNestedRulesGroup(
115: getMapper(), this );
116: Action[] addNestedRuleArr = nestedRules.getActions();
117: //
118: if (addNestedAxiArr != null) {
119: for (Action action : addNestedAxiArr) {
120: addMenu.add(action);
121: }
122: }
123: //
124: if (addNestedAxiArr != null && addNestedAxiArr.length > 0
125: && addNestedRuleArr != null
126: && addNestedRuleArr.length > 0) {
127: addMenu.add(new JSeparator());
128: }
129: //
130: if (addNestedRuleArr != null) {
131: for (Action action : addNestedRuleArr) {
132: addMenu.add(action);
133: }
134: }
135: // Add menu is added only if it's not empty
136: if (addMenu.getMenuComponentCount() != 0) {
137: rootMenu.add(addMenu);
138: }
139: //
140: newAction = new DeleteAction(getMapper(), this );
141: rootMenu.add(newAction);
142: //
143: return rootMenu;
144: }
145:
146: }
|