KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > validation > ValidateAction


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.validation;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.swing.AbstractAction JavaDoc;
26 import javax.swing.Icon JavaDoc;
27 import javax.swing.ImageIcon JavaDoc;
28 import javax.swing.KeyStroke JavaDoc;
29 import org.netbeans.modules.xml.validation.ui.ValidationOutputWindow;
30 import org.netbeans.modules.xml.xam.Model;
31 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
32 import org.openide.ErrorManager;
33 import org.openide.util.NbBundle;
34 import org.openide.util.RequestProcessor;
35 import org.openide.util.Utilities;
36 import org.openide.windows.IOProvider;
37 import org.openide.windows.InputOutput;
38
39
40
41 /**
42  * Validates XML file sending results to output window.
43  *
44  */

45 public class ValidateAction extends AbstractAction JavaDoc {
46     
47     private static final long serialVersionUID = 1L;
48     
49     public static final String JavaDoc ACCELERATOR = "alt shift F9"; // NOI18N
50
private static final Icon JavaDoc icon = new ImageIcon JavaDoc(Utilities.loadImage(
51             "org/netbeans/modules/xml/validation/resources/validation.png"));
52     private static final String JavaDoc label = NbBundle.getMessage(
53             ValidateAction.class,"NAME_Validate_XML");
54     private Model model;
55     
56     
57     public ValidateAction(Model model) {
58         super(label, icon);
59     putValue(NAME, label);
60         putValue(SHORT_DESCRIPTION, label);
61         putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(ACCELERATOR));
62         this.model = model;
63     }
64     
65     
66     public void actionPerformed(ActionEvent JavaDoc event) {
67         RequestProcessor.getDefault().post(new RunAction());
68     }
69     
70     
71     public class RunAction implements Runnable JavaDoc{
72         
73         private List JavaDoc<ResultItem> validationResults;
74         
75         public void run() {
76             InputOutput io = IOProvider.getDefault().getIO(NbBundle.
77                     getMessage(ValidationOutputWindow.class,
78                     "TITLE_XML_check_window"), false);
79             try {
80                 io.getOut().reset();
81             } catch(IOException JavaDoc ex) {
82                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
83             }
84             io.getOut().println(NbBundle.getMessage(
85                     ValidateAction.class,"MSG_XML_valid_start"));
86             io.select();
87             
88             ValidationOutputWindowController validationController =
89                     new ValidationOutputWindowController();
90             validationResults = validationController.validate(model);
91             
92             io.getOut().print(NbBundle.getMessage(
93                     ValidateAction.class,"MSG_XML_valid_end"));
94             io.select();
95         }
96         
97         public List JavaDoc<ResultItem> getValidationResults() {
98             return validationResults;
99         }
100     }
101 }
102
Popular Tags