1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.x.impl.swing;
14
15 import java.awt.event.ActionEvent;
16
17 import javax.swing.AbstractAction;
18 import javax.swing.Action;
19 import javax.swing.ImageIcon;
20 import javax.swing.KeyStroke;
21
22 import com.eviware.soapui.support.HelpActionMarker;
23 import com.eviware.soapui.support.Tools;
24 import com.eviware.soapui.support.UISupport;
25 import com.eviware.soapui.support.action.swing.ActionList;
26 import com.eviware.soapui.support.action.swing.DefaultActionList;
27 import com.eviware.x.form.XForm;
28 import com.eviware.x.form.XFormDialog;
29 import com.eviware.x.form.XFormDialogBuilder;
30
31 public class SwingXFormDialogBuilder extends XFormDialogBuilder
32 {
33 private String name;
34 private SwingXFormDialog dialog;
35
36 public SwingXFormDialogBuilder( String name )
37 {
38 this.name = name;
39 }
40
41 @Override
42 public XForm createForm( String name )
43 {
44 XForm form = new SwingXFormImpl( name );
45 ((SwingXFormImpl)form).addSpace( 5 );
46 addForm( form );
47 return form;
48 }
49
50 @Override
51 public XFormDialog buildDialog( ActionList actions, String description, ImageIcon icon )
52 {
53 XForm[] forms = getForms();
54 dialog = forms.length > 1 ? new JTabbedFormDialog( name, forms, actions, description, icon ) : new JFormDialog(
55 name, ( SwingXFormImpl )forms[0], actions, description, icon );
56
57 return dialog;
58 }
59
60 @Override
61 public XFormDialog buildWizard( String description, ImageIcon icon, String helpURL )
62 {
63 Action helpAction = ( helpURL.length() > 0 ? new HelpAction( helpURL ) : null );
64 XForm[] forms = getForms();
65 dialog = new JWizardDialog( name, forms, helpAction, description, icon );
66
67 return dialog;
68 }
69
70 @Override
71 public ActionList buildOkCancelActions()
72 {
73 DefaultActionList actions = new DefaultActionList( "Actions" );
74 actions.addAction( new OKAction() );
75 actions.addAction( new CancelAction() );
76 return actions;
77 }
78
79 @Override
80 public ActionList buildOkCancelHelpActions( String url )
81 {
82 DefaultActionList actions = new DefaultActionList( "Actions" );
83 actions.addAction( new HelpAction( url ) );
84 OKAction okAction = new OKAction();
85 actions.addAction( okAction );
86 actions.addAction( new CancelAction() );
87 actions.setDefaultAction( okAction );
88 return actions;
89 }
90
91 protected final class OKAction extends AbstractAction
92 {
93 public OKAction()
94 {
95 super( "OK" );
96 }
97
98 public void actionPerformed( ActionEvent e )
99 {
100 if( dialog != null && dialog.validate() )
101 {
102 dialog.setReturnValue( XFormDialog.OK_OPTION );
103 dialog.setVisible( false );
104 }
105 }
106 }
107
108 protected final class CancelAction extends AbstractAction
109 {
110 public CancelAction()
111 {
112 super( "Cancel" );
113 }
114
115 public void actionPerformed( ActionEvent e )
116 {
117 if( dialog != null )
118 {
119 dialog.setReturnValue( XFormDialog.CANCEL_OPTION );
120 dialog.setVisible( false );
121 }
122 }
123 }
124
125 public final class HelpAction extends AbstractAction implements HelpActionMarker
126 {
127 private final String url;
128
129 public HelpAction( String url )
130 {
131 this( "Online Help", url, UISupport.getKeyStroke( "F1" ) );
132 }
133
134 public HelpAction( String title, String url )
135 {
136 this( title, url, null );
137 }
138
139 public HelpAction( String title, String url, KeyStroke accelerator )
140 {
141 super( title );
142 this.url = url;
143 putValue( Action.SHORT_DESCRIPTION, "Show online help" );
144 if( accelerator != null )
145 putValue( Action.ACCELERATOR_KEY, accelerator );
146
147 putValue( Action.SMALL_ICON, UISupport.HELP_ICON );
148 }
149
150 public void actionPerformed( ActionEvent e )
151 {
152 Tools.openURL( url );
153 }
154 }
155 }