1 19 20 package org.netbeans.modules.xml.validation; 21 22 import java.awt.event.ActionEvent ; 23 import java.io.IOException ; 24 import java.util.List ; 25 import javax.swing.AbstractAction ; 26 import javax.swing.Icon ; 27 import javax.swing.ImageIcon ; 28 import javax.swing.KeyStroke ; 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 45 public class ValidateAction extends AbstractAction { 46 47 private static final long serialVersionUID = 1L; 48 49 public static final String ACCELERATOR = "alt shift F9"; private static final Icon icon = new ImageIcon (Utilities.loadImage( 51 "org/netbeans/modules/xml/validation/resources/validation.png")); 52 private static final String 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 event) { 67 RequestProcessor.getDefault().post(new RunAction()); 68 } 69 70 71 public class RunAction implements Runnable { 72 73 private List <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 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 <ResultItem> getValidationResults() { 98 return validationResults; 99 } 100 } 101 } 102 | Popular Tags |