View Javadoc

1   /*
2    * soapUI, copyright (C) 2004-2008 eviware.com
3    *
4    * soapUI is free software; you can redistribute it and/or modify it under the
5    * terms of version 2.1 of the GNU Lesser General Public License as published by
6    * the Free Software Foundation.
7    *
8    * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9    * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   * See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.support;
14  
15  import com.eviware.soapui.impl.wsdl.panels.teststeps.support.GroovyEditor;
16  import com.eviware.soapui.impl.wsdl.panels.teststeps.support.GroovyEditorModel;
17  import com.eviware.soapui.support.components.JUndoableTextArea;
18  
19  import javax.swing.*;
20  import javax.swing.text.Document;
21  
22  public class DefaultEditorFactory implements EditorFactory
23  {
24     public JComponent buildXPathEditor( EditorModel editorModel )
25     {
26        JUndoableTextArea textArea = new JUndoableTextArea( );
27        textArea.setText( editorModel.getEditorText() );
28        textArea.getDocument().addDocumentListener( new EditorModelDocumentListener( editorModel ) );
29        return new JScrollPane( textArea );
30     }
31  
32     public JComponent buildXmlEditor( EditorModel editorModel )
33     {
34        JUndoableTextArea textArea = new JUndoableTextArea( );
35        textArea.setText( editorModel.getEditorText() );
36        textArea.getDocument().addDocumentListener( new EditorModelDocumentListener( editorModel ) );
37        return new JScrollPane( textArea );
38     }
39  
40     public JComponent buildGroovyEditor( GroovyEditorModel editorModel )
41     {
42        return new GroovyEditor( editorModel );
43     }
44  
45     private static class EditorModelDocumentListener extends DocumentListenerAdapter
46     {
47        private EditorModel editorModel;
48  
49        public EditorModelDocumentListener( EditorModel editorModel )
50        {
51           this.editorModel = editorModel;
52        }
53  
54        public void update( Document document )
55        {
56           editorModel.setEditorText( getText( document ));
57        }
58     }
59  }