01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * The Original Software is NetBeans. The Initial Developer of the Original
16: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19: package org.netbeans.modules.xslt.project.nodes;
20:
21: import java.util.ArrayList;
22: import java.util.Collection;
23: import java.util.Collections;
24: import java.util.List;
25: import org.netbeans.modules.xslt.tmap.model.xsltmap.TransformationDesc;
26: import org.netbeans.modules.xslt.tmap.model.xsltmap.TransformationType;
27: import org.netbeans.modules.xslt.tmap.model.xsltmap.TransformationUC;
28: import org.netbeans.modules.xslt.tmap.model.xsltmap.XsltMapPropertyChangeListener;
29: import org.openide.nodes.Children;
30: import org.openide.nodes.Node;
31:
32: /**
33: *
34: * @author Vitaly Bychkov
35: * @version 1.0
36: */
37: public class TransformationUCChildren extends Children.Keys implements
38: XsltMapPropertyChangeListener {
39: private TransformationUC tUseCase;
40:
41: public TransformationUCChildren(TransformationUC tUseCase) {
42: assert tUseCase != null;
43: this .tUseCase = tUseCase;
44: }
45:
46: protected Node[] createNodes(Object key) {
47: List<Node> nodes = new ArrayList<Node>();
48: if (key instanceof TransformationDesc) {
49: nodes.add(new TransformationDescNode(
50: (TransformationDesc) key));
51: }
52: return nodes.toArray(new Node[nodes.size()]);
53: }
54:
55: private Collection getNodeKeys() {
56: // System.out.println("invoked getNodeKeys() !!! ");
57:
58: if (tUseCase == null) {
59: return Collections.EMPTY_SET;
60: }
61: List<TransformationDesc> tUseCaseDescs = new ArrayList<TransformationDesc>();//tUseCase.getTransformationDescs();
62: if (TransformationType.FILTER_REQUEST_REPLY.equals(tUseCase
63: .getTransformationType())) {
64: tUseCaseDescs = tUseCase.getTransformationDescs();
65: } else {
66: tUseCaseDescs.add(tUseCase.getInputTransformationDesc());
67: }
68:
69: return tUseCaseDescs == null ? Collections.EMPTY_SET
70: : tUseCaseDescs;
71: }
72:
73: protected void addNotify() {
74: super .addNotify();
75: tUseCase.getXsltMapModel().addPropertyChangeListener(this );
76: setKeys(getNodeKeys());
77: }
78:
79: protected void removeNotify() {
80: setKeys(Collections.EMPTY_SET);
81: tUseCase.getXsltMapModel().removePropertyChangeListener(this );
82: super .removeNotify();
83: }
84:
85: public void transformationDescChanged(TransformationDesc oldDesc,
86: TransformationDesc newDesc) {
87: setKeys(getNodeKeys());
88: }
89: }
|