KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.swing.Action JavaDoc;
24 import javax.swing.undo.UndoManager JavaDoc;
25 import org.netbeans.modules.xml.refactoring.CannotRefactorException;
26 import org.netbeans.modules.xml.refactoring.FileRenameRequest;
27 import org.netbeans.modules.xml.refactoring.RefactoringManager;
28 import org.netbeans.modules.xml.refactoring.ui.ModelProvider;
29 import org.netbeans.modules.xml.refactoring.ui.util.AnalysisUtilities;
30 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
31 import org.netbeans.modules.xml.wsdl.ui.actions.WSDLViewOpenAction;
32 import org.openide.DialogDisplayer;
33 import org.openide.NotifyDescriptor;
34 import org.openide.loaders.DataNode;
35 import org.openide.loaders.DataObject;
36 import org.openide.nodes.Children;
37 import org.openide.util.NbBundle;
38 import org.openide.util.actions.SystemAction;
39
40 /**
41  * A node to represent the WSDLDataObject.
42  */

43 public class WSDLNode extends DataNode implements ModelProvider {
44
45     public WSDLNode(WSDLDataObject obj) {
46         this (obj, Children.LEAF);
47     }
48
49     private WSDLNode(DataObject obj, Children ch) {
50         super (obj, ch);
51         setIconBaseWithExtension("org/netbeans/modules/xml/wsdl/ui/netbeans/module/resources/wsdl16.png");
52     }
53
54     public Action JavaDoc getPreferredAction() {
55         return SystemAction.get(WSDLViewOpenAction.class);
56     }
57
58     public void setName(String JavaDoc name, boolean rename) {
59         WSDLDataObject dobj = (WSDLDataObject) getDataObject();
60         if (!rename || name != null && name.equals(dobj.getName())) {
61             return;
62         }
63
64         try {
65             WSDLEditorSupport editor = dobj.getWSDLEditorSupport();
66             WSDLModel model = editor.getModel();
67             UndoManager JavaDoc undo = editor.getUndoManager();
68             // Modifying definitions component leaves an edit on the queue.
69
model.removeUndoableEditListener(undo);
70             FileRenameRequest request = new FileRenameRequest(model, name);
71             try {
72                 RefactoringManager.getInstance().execute(request, true);
73                 // Rename the definitions element in the model to follow
74
// the name of the file.
75
if (model.startTransaction()) {
76                     model.getDefinitions().setName(name);
77                 }
78             } catch (CannotRefactorException cre) {
79                 AnalysisUtilities.showRefactoringUI(request);
80             } finally {
81                 model.endTransaction();
82             }
83             model.addUndoableEditListener(undo);
84             // Save the document after modifying the definitions component,
85
// so the file is not left modified because of the file rename.
86
editor.saveDocument();
87         } catch (IOException JavaDoc ioe) {
88             String JavaDoc msg = NbBundle.getMessage(WSDLDataObject.class,
89                     "MSG_UnableToRename", ioe.getMessage());
90             NotifyDescriptor nd = new NotifyDescriptor.Message(
91                     msg, NotifyDescriptor.ERROR_MESSAGE);
92             DialogDisplayer.getDefault().notify(nd);
93         }
94     }
95
96     public WSDLModel getModel() {
97         try {
98             WSDLDataObject dobj = (WSDLDataObject) getDataObject();
99             return dobj.getWSDLEditorSupport().getModel();
100         } catch(IOException JavaDoc ex) {
101             String JavaDoc msg = NbBundle.getMessage(WSDLDataObject.class, "MSG_UnableToLoadWsdl", ex.getMessage());
102             NotifyDescriptor nd = new NotifyDescriptor.Message(
103                 msg, NotifyDescriptor.ERROR_MESSAGE);
104             DialogDisplayer.getDefault().notify(nd);
105         }
106         return null;
107     }
108 }
109
Popular Tags