KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > tools > actions > CheckAction


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 package org.netbeans.modules.xml.tools.actions;
20
21 import java.util.*;
22
23 import org.openide.*;
24 import org.openide.nodes.*;
25 import org.openide.util.HelpCtx;
26 import org.openide.util.actions.CookieAction;
27 import org.openide.loaders.*;
28
29 import org.netbeans.tax.*;
30 import org.netbeans.modules.xml.core.*;
31 import org.netbeans.modules.xml.core.actions.*;
32
33 import org.netbeans.api.xml.cookies.*;
34 import org.openide.util.RequestProcessor;
35
36 /**
37  * Checks well-formess of XML file sending results to output window.
38  *
39  * @author Petr Kuzel
40  * @version 1.0
41  */

42 public class CheckAction extends CookieAction implements CollectXMLAction.XMLAction {
43
44     /** Serial Version UID */
45     private static final long serialVersionUID = -4617456591768900199L;
46
47     /** Be hooked on XMLDataObjectLook narking XML nodes. */
48     protected Class JavaDoc[] cookieClasses () {
49         return new Class JavaDoc[] { CheckXMLCookie.class };
50     }
51
52     /** All selected nodes must be XML one to allow this action */
53     protected int mode () {
54         return MODE_ALL;
55     }
56
57     /** Check all selected nodes. */
58     protected void performAction (Node[] nodes) {
59
60         if (nodes == null) return;
61         
62         RequestProcessor.postRequest(
63                new CheckAction.RunAction (nodes));
64     }
65
66     /** Human presentable name. */
67     public String JavaDoc getName() {
68         return Util.THIS.getString("NAME_Check_XML");
69     }
70
71     /** Do not slow by any icon. */
72     protected String JavaDoc iconResource () {
73         return "org/netbeans/modules/xml/tools/resources/check_xml.png"; // NOI18N
74
}
75
76     /** Provide accurate help. */
77     public HelpCtx getHelpCtx () {
78         return new HelpCtx (CheckAction.class);
79     }
80     
81     protected boolean asynchronous() {
82         return false;
83     }
84
85     private class RunAction implements Runnable JavaDoc{
86         private Node[] nodes;
87
88         RunAction (Node[] nodes){
89             this.nodes = nodes;
90         }
91
92         public void run() {
93             InputOutputReporter console = new InputOutputReporter();
94             console.message(Util.THIS.getString("MSG_XML_check_start"));
95             console.moveToFront();
96             for (int i = 0; i<nodes.length; i++) {
97                 Node node = nodes[i];
98                 CheckXMLCookie cake = (CheckXMLCookie) node.getCookie(CheckXMLCookie.class);
99                 if (cake == null) continue;
100                 console.setNode(node); //??? how can console determine which editor to highlight
101
cake.checkXML(console);
102             }
103
104             console.message(Util.THIS.getString("MSG_XML_check_end"));
105             console.moveToFront(true);
106        }
107     }
108 }
109
Popular Tags