KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > module > loader > AntProjectDataObject


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * 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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.apache.tools.ant.module.loader;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.io.IOException JavaDoc;
25 import org.apache.tools.ant.module.api.AntProjectCookie;
26 import org.apache.tools.ant.module.nodes.AntProjectNode;
27 import org.apache.tools.ant.module.xml.AntProjectSupport;
28 import org.netbeans.spi.xml.cookies.CheckXMLSupport;
29 import org.netbeans.spi.xml.cookies.DataObjectAdapters;
30 import org.openide.cookies.SaveCookie;
31 import org.openide.filesystems.FileObject;
32 import org.openide.loaders.DataObject;
33 import org.openide.loaders.DataObjectExistsException;
34 import org.openide.loaders.MultiDataObject;
35 import org.openide.nodes.CookieSet;
36 import org.openide.nodes.Node;
37
38 public class AntProjectDataObject extends MultiDataObject implements PropertyChangeListener JavaDoc {
39
40     public AntProjectDataObject(FileObject pf, AntProjectDataLoader loader) throws DataObjectExistsException, IOException JavaDoc {
41         super(pf, loader);
42         CookieSet cookies = getCookieSet();
43         cookies.add (new AntProjectDataEditor (this));
44         FileObject prim = getPrimaryFile ();
45         AntProjectCookie proj = new AntProjectSupport (prim);
46         cookies.add (proj);
47         if (proj.getFile () != null) {
48             cookies.add (new AntActionInstance (proj));
49         }
50         cookies.add(new CheckXMLSupport(DataObjectAdapters.inputSource(this)));
51         addPropertyChangeListener (this);
52     }
53     
54     @Override JavaDoc
55     protected Node createNodeDelegate () {
56         return new AntProjectNode (this);
57     }
58
59     void addSaveCookie (final SaveCookie save) {
60         if (getCookie (SaveCookie.class) == null) {
61             getCookieSet ().add (save);
62             setModified (true);
63         }
64     }
65
66     void removeSaveCookie (final SaveCookie save) {
67         if (getCookie (SaveCookie.class) == save) {
68             getCookieSet ().remove (save);
69             setModified (false);
70         }
71     }
72
73     public void propertyChange (PropertyChangeEvent JavaDoc ev) {
74         String JavaDoc prop = ev.getPropertyName ();
75         if (prop == null || prop.equals (DataObject.PROP_PRIMARY_FILE)) { // #11979
76
// XXX this might be better handled by overriding FileEntry.rename/move:
77
((AntProjectSupport) getCookie (AntProjectSupport.class)).setFileObject (getPrimaryFile ());
78         }
79     }
80
81 }
82
Popular Tags