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.project.nodes;
020:
021: import java.io.IOException;
022: import java.util.ArrayList;
023: import java.util.Collection;
024: import java.util.Collections;
025: import java.util.List;
026: import org.netbeans.api.project.Project;
027: import org.netbeans.modules.xslt.tmap.model.xsltmap.TransformationDesc;
028: import org.netbeans.modules.xslt.tmap.model.xsltmap.TransformationUC;
029: import org.netbeans.modules.xslt.tmap.model.xsltmap.XsltMapModel;
030: import org.openide.ErrorManager;
031: import org.openide.filesystems.FileAttributeEvent;
032: import org.openide.filesystems.FileChangeListener;
033: import org.openide.filesystems.FileEvent;
034: import org.openide.filesystems.FileObject;
035: import org.openide.filesystems.FileRenameEvent;
036: import org.openide.nodes.Children;
037: import org.openide.nodes.Node;
038:
039: /**
040: *
041: * @author Vitaly Bychkov
042: * @version 1.0
043: */
044: public class TransformationsChildren extends Children.Keys implements
045: FileChangeListener {
046: private FileObject projectDir;
047: private Project project;
048:
049: public TransformationsChildren(Project project) {
050: super ();
051: this .project = project;
052: this .projectDir = project.getProjectDirectory();
053: }
054:
055: protected Node[] createNodes(Object key) {
056: List<Node> nodes = new ArrayList<Node>();
057: if (key instanceof TransformationUC) {
058: nodes
059: .add(new TransformationUCNode(
060: (TransformationUC) key,
061: new TransformationUCChildren(
062: (TransformationUC) key)));
063:
064: // List<TransformationDesc> descs = ((TransformationUC)key).getTransformationDescs();
065: // if (descs != null) {
066: // for (TransformationDesc elem : descs) {
067: // nodes.add(new TransformationDescNode(elem));
068: // }
069: // }
070: } else if (key instanceof TransformationDesc) {
071: nodes.add(new TransformationDescNode(
072: (TransformationDesc) key));
073: }
074: return nodes.toArray(new Node[nodes.size()]);
075: }
076:
077: private Collection getNodeKeys() {
078: // System.out.println("invoked getNodeKeys() !!! ");
079:
080: if (projectDir == null) {
081: return Collections.EMPTY_SET;
082: }
083: XsltMapModel xsltMapModel;
084: try {
085: xsltMapModel = XsltMapModel.getDefault(project);
086: if (xsltMapModel != null) {
087: return xsltMapModel.getTransformationUCs();
088: // TODO a | r return xsltMapModel.getTransformationDescs();
089: }
090: } catch (IOException ex) {
091: ex.printStackTrace();
092: ErrorManager.getDefault().notify(ex);
093: }
094: return Collections.EMPTY_SET;
095: }
096:
097: protected void addNotify() {
098: super .addNotify();
099: projectDir.getFileObject("src").addFileChangeListener(this );
100: setKeys(getNodeKeys());
101: }
102:
103: protected void removeNotify() {
104: setKeys(Collections.EMPTY_SET);
105: projectDir.getFileObject("src").removeFileChangeListener(this );
106: super .removeNotify();
107: }
108:
109: public void fileFolderCreated(FileEvent fe) {
110: setKeys(getNodeKeys());
111: }
112:
113: public void fileDataCreated(FileEvent fe) {
114: }
115:
116: public void fileChanged(FileEvent fe) {
117: setKeys(getNodeKeys());
118: }
119:
120: public void fileDeleted(FileEvent fe) {
121: setKeys(getNodeKeys());
122: }
123:
124: public void fileRenamed(FileRenameEvent fe) {
125: setKeys(getNodeKeys());
126: }
127:
128: public void fileAttributeChanged(FileAttributeEvent fe) {
129: }
130:
131: }
|