KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > forte > actions > XMLCAction


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Lisa Reese
21  *
22  */

23 package org.enhydra.kelp.forte.actions;
24
25 import org.openide.nodes.Node;
26 import org.openide.TopManager;
27 import org.openide.util.HelpCtx;
28 import org.openide.util.NbBundle;
29 import org.openide.util.actions.CallableSystemAction;
30 import org.openide.util.actions.SystemAction;
31 import org.openide.loaders.DataFolder;
32 import org.openide.loaders.DataObject;
33 import org.openide.src.ClassElement;
34 import org.openide.DialogDescriptor;
35 import org.openide.filesystems.FileSystem;
36 import org.openide.filesystems.FileObject;
37
38 // ToolBox
39
import org.enhydra.tool.common.SwingUtil;
40 import org.enhydra.tool.common.event.HelpEvent;
41 import org.enhydra.tool.common.event.HelpListener;
42
43 // AddinCore
44
import org.enhydra.kelp.KelpInfo;
45 import org.enhydra.kelp.common.xmlc.XMLCButtonListener;
46 import org.enhydra.kelp.common.xmlc.XMLCButtonPanel;
47 import org.enhydra.kelp.common.xmlc.CoreXMLCTool;
48 import org.enhydra.kelp.common.node.OtterDocumentNode;
49
50 // AddinForte
51
import org.enhydra.kelp.forte.node.ForteProject;
52 import org.enhydra.kelp.forte.XMLCSettings;
53
54 import java.awt.Dialog JavaDoc;
55 import java.awt.Frame JavaDoc;
56 import java.awt.event.ActionListener JavaDoc;
57 import java.awt.event.ActionEvent JavaDoc;
58 import java.net.URL JavaDoc;
59 import java.net.MalformedURLException JavaDoc;
60 import java.io.File JavaDoc;
61 import java.util.Enumeration JavaDoc;
62
63 //dr
64
import org.enhydra.kelp.common.node.OtterProject;
65
66 /**
67  * Action sensitive to some cookie that does something useful.
68  *
69  * @author rees0234
70  */

71 public class XMLCAction extends CallableSystemAction implements HelpListener {
72     private static String JavaDoc anchor = "xmlcwizard";
73
74     // implements HelpListener
75
public void onHelp(HelpEvent event) {
76         URL JavaDoc url = null;
77         String JavaDoc[] home = new String JavaDoc[2];
78         home[0] = System.getProperty("netbeans.home");
79         home[1] = System.getProperty("netbeans.user");
80         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
81         buf.append(KelpInfo.getAddinHelpURL(home));
82         buf.append('#').append(anchor);
83         try {
84           url = new URL JavaDoc(buf.toString());
85           TopManager.getDefault().showUrl(url);
86         } catch (MalformedURLException JavaDoc e) {
87           e.printStackTrace(System.err);
88         }
89     }
90
91
92     public void performAction() {
93         String JavaDoc[] options = XMLCButtonPanel.getOptions();
94         CoreXMLCTool tool = new CoreXMLCTool();
95         XMLCButtonListener listener = new XMLCButtonListener(tool);
96         DialogDescriptor dscr = new DialogDescriptor(tool.getInnerPanel(),
97                 tool.getTitle(), true, options, options[0],
98                 DialogDescriptor.BOTTOM_ALIGN, HelpCtx.DEFAULT_HELP,
99                 listener);
100         Dialog JavaDoc dlg = TopManager.getDefault().createDialog(dscr);
101         tool.setProject(new ForteProject());
102         tool.addHelpListener(this);
103         dlg.show();
104
105         //gotta refresh the directories so build will work right away on generated files:
106
ForteProject project = new ForteProject();
107         String JavaDoc src = XMLCSettings.getDefault().getSource();
108         if ((src != null) && (src.length() > 0))
109         {
110             FileObject source = project.getRootFolder().getFileObject(src);
111             source.refresh();
112             Enumeration JavaDoc kids = source.getChildren(true);
113             while (kids.hasMoreElements())
114                 ((FileObject)kids.nextElement()).refresh(); //blech
115
}
116
117
118     }
119
120     public boolean isEnabled()
121     {
122         ForteProject project = new ForteProject();
123         if (project.getRootFolder() == null)
124 // firePropertyChange(PROP_ENABLED, (Boolean)getProperty(PROP_ENABLED), new Boolean(false);
125
return false;
126         OtterDocumentNode[] nodes = project.getAllDocuments();
127         return ((nodes != null) && (nodes.length > 0));
128     }
129
130     public String JavaDoc getName() {
131         return CoreXMLCTool.getDefaultTitle();
132     }
133
134     protected String JavaDoc iconResource() {
135         return "smallicon.gif";
136     }
137
138     public HelpCtx getHelpCtx() {
139         return HelpCtx.DEFAULT_HELP;
140         // If you will provide context help then use:
141
// return new HelpCtx (XMLCAction.class);
142
}
143
144     /**
145      * Perform extra initialization of this action's singleton.
146      * PLEASE do not use constructors for this purpose!
147      */

148     protected void initialize() {
149         // mn 08.06.2002
150
super.initialize();
151         putProperty(javax.swing.Action.SHORT_DESCRIPTION,
152                     NbBundle.getMessage(XMLCAction.class,
153                                         "HINT_XMLC_Action"));
154     }
155
156 }
157
Popular Tags