KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > netbeans > module > WSDLDataObject


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.ui.netbeans.module;
21
22 import java.io.IOException JavaDoc;
23
24 import org.netbeans.spi.xml.cookies.CheckXMLSupport;
25 import org.netbeans.spi.xml.cookies.DataObjectAdapters;
26 import org.openide.cookies.SaveCookie;
27 import org.openide.filesystems.FileObject;
28 import org.openide.loaders.DataFolder;
29 import org.openide.loaders.DataObjectExistsException;
30 import org.openide.loaders.MultiDataObject;
31 import org.openide.loaders.MultiFileLoader;
32 import org.openide.nodes.CookieSet;
33 import org.openide.nodes.Node;
34 import org.openide.util.HelpCtx;
35 import org.xml.sax.InputSource JavaDoc;
36
37 /**
38  * Represents a WSDL file.
39  *
40  * @author Jerry Waldorf
41  */

42 public class WSDLDataObject extends MultiDataObject {
43
44     public WSDLDataObject(FileObject fObj, MultiFileLoader loader) throws
45             DataObjectExistsException {
46         super(fObj, loader);
47         CookieSet set = getCookieSet();
48
49         editorSupport = new WSDLEditorSupport(this);
50         // editor support defines MIME type understood by EditorKits registry
51
set.add(editorSupport);
52
53         // Add check and validate cookies
54
InputSource JavaDoc is = DataObjectAdapters.inputSource(this);
55         set.add(new CheckXMLSupport(is));
56         //set.add(new ValidateSchemaSupport(is));
57

58         set.add(new WSDLMultiViewSupport(this));
59         //add validate action here
60
set.add(new WSDLValidateXMLCookie(this));
61     }
62
63     @Override JavaDoc
64     protected Node createNodeDelegate() {
65         return new WSDLNode(this);
66     }
67
68     @Override JavaDoc
69     public HelpCtx getHelpCtx() {
70         return HelpCtx.DEFAULT_HELP;
71     }
72
73     @Override JavaDoc
74     protected void handleDelete() throws IOException JavaDoc {
75         if (isModified()) {
76             setModified(false);
77         }
78         getWSDLEditorSupport().getEnv().unmarkModified();
79         super.handleDelete();
80     }
81
82     protected FileObject handleMove(DataFolder df) throws IOException JavaDoc {
83         //TODO:make sure we save file before moving This is what jave move does.
84
//It also launch move refactoring dialog which we should be doing
85
//as well
86
if(isModified()) {
87             SaveCookie sCookie = (SaveCookie) this.getCookie(SaveCookie.class);
88             if(sCookie != null) {
89                 sCookie.save();
90             }
91         }
92
93         return super.handleMove(df);
94     }
95
96
97     @Override JavaDoc
98     public void setModified(boolean modified) {
99         super.setModified(modified);
100         if (modified) {
101             getCookieSet().add(getSaveCookie());
102         } else {
103             getCookieSet().remove(getSaveCookie());
104         }
105     }
106
107     private SaveCookie getSaveCookie() {
108         return new SaveCookie() {
109             public void save() throws IOException JavaDoc {
110                 getWSDLEditorSupport().saveDocument();
111             }
112
113             @Override JavaDoc
114             public int hashCode() {
115                 return getClass().hashCode();
116             }
117
118             @Override JavaDoc
119             public boolean equals(Object JavaDoc other) {
120                 return other != null && getClass().equals(other.getClass());
121             }
122         };
123     }
124
125     public WSDLEditorSupport getWSDLEditorSupport() {
126         return editorSupport;
127     }
128
129     private static final long serialVersionUID = 6338889116068357651L;
130     private transient WSDLEditorSupport editorSupport;
131
132     public static final String JavaDoc WSDL_ICON_BASE_WITH_EXT = "org/netbeans/modules/xml/wsdl/ui/netbeans/module/resources/wsdl16.png";
133 }
134
Popular Tags