001: package salomeTMF_plug.beanshell;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Dimension;
005: import java.awt.FlowLayout;
006: import java.awt.Frame;
007: import java.awt.event.ActionEvent;
008: import java.awt.event.ActionListener;
009: import java.io.File;
010:
011: import javax.swing.BorderFactory;
012: import javax.swing.BoxLayout;
013: import javax.swing.ButtonGroup;
014: import javax.swing.JButton;
015: import javax.swing.JDialog;
016: import javax.swing.JLabel;
017: import javax.swing.JOptionPane;
018: import javax.swing.JPanel;
019: import javax.swing.JRadioButton;
020: import javax.swing.JTextField;
021: import javax.swing.border.TitledBorder;
022:
023: import org.objectweb.salome_tmf.ihm.languages.Language;
024:
025: public class GuiScriptChoice extends JDialog {
026:
027: private JPanel jContentPane = null;
028: private JPanel jpChoice = null;
029: private ButtonGroup jbgGroup = null;
030: private JRadioButton jrbExistingTestPlan = null;
031: private JRadioButton jrbNewTestPlan = null;
032: private JPanel jpExistingTestPlan = null;
033: private JPanel jpNewTestPlan = null;
034: private JTextField jtfExistingTestPlanName = null;
035: private JButton jbBrowse = null;
036: private JTextField jtfNewTestPlanName = null;
037: private JPanel jpButtons = null;
038: private JButton jbCancel = null;
039: private JButton jbOk = null;
040: private JPanel jpNameTestPlan = null;
041: private JPanel jpBrowse = null;
042: private JLabel jlTitleNewTesPlan = null;
043:
044: public GuiScriptChoice(Frame parent) {
045: super (parent, true);
046: initialize();
047: this .pack();
048: this .setVisible(true);
049: }
050:
051: private void initialize() {
052: this .setModal(true);
053: this .setResizable(false);
054: this .setDefaultCloseOperation(DISPOSE_ON_CLOSE);
055: this .setTitle("Beanshell Script");
056: this .setContentPane(getJContentPane());
057: // window center
058: this .setLocationRelativeTo(this .getParent());
059: }
060:
061: public File getSelectedFile() {
062: File file = null;
063: if (jrbExistingTestPlan.isSelected()) {
064: if (!jtfExistingTestPlanName.getText().trim().equals("")) {
065: file = new File(jtfExistingTestPlanName.getText());
066: }
067: } else if (jrbNewTestPlan.isSelected()) {
068: if (!jtfNewTestPlanName.getText().trim().equals("")) {
069: String fileName = jtfNewTestPlanName.getText();
070: if (!jtfNewTestPlanName.getText().toUpperCase()
071: .contains(".BSH")) {
072: fileName = fileName + ".bsh";
073: }
074: file = new File(fileName);
075: }
076: }
077: return (file);
078: }
079:
080: private void selectedAction() {
081: if (jrbExistingTestPlan.isSelected()) {
082: jtfExistingTestPlanName.setEnabled(true);
083: jbBrowse.setEnabled(true);
084: jtfNewTestPlanName.setEnabled(false);
085: jlTitleNewTesPlan.setEnabled(false);
086: } else if (jrbNewTestPlan.isSelected()) {
087: jtfExistingTestPlanName.setEnabled(false);
088: jbBrowse.setEnabled(false);
089: jtfNewTestPlanName.setEnabled(true);
090: jlTitleNewTesPlan.setEnabled(true);
091: }
092: }
093:
094: private void displayFileChooser() {
095: javax.swing.JFileChooser fileChooser = new javax.swing.JFileChooser();
096: fileChooser.setApproveButtonText(Language.getInstance()
097: .getText("Valider"));
098: fileChooser.addChoosableFileFilter(new BeanShellFileFilter(
099: "BeanShell", ".bsh"));
100:
101: int returnVal = fileChooser.showOpenDialog(this );
102: if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
103: jtfExistingTestPlanName.setText(fileChooser
104: .getSelectedFile().getPath());
105: }
106: }
107:
108: /**
109: * This method initializes jContentPane
110: *
111: * @return javax.swing.JPanel
112: */
113: private JPanel getJContentPane() {
114: if (jContentPane == null) {
115: jbgGroup = new ButtonGroup();
116: jContentPane = new JPanel();
117: jContentPane.setLayout(new BorderLayout());
118: jContentPane.add(getJpChoice(), BorderLayout.CENTER);
119: jContentPane.add(getJpButtons(), BorderLayout.SOUTH);
120: }
121: return jContentPane;
122: }
123:
124: /**
125: * This method initializes jpChoice
126: *
127: * @return javax.swing.JPanel
128: */
129: private JPanel getJpChoice() {
130: if (jpChoice == null) {
131: try {
132: jpChoice = new JPanel();
133: jpChoice.setLayout(new BoxLayout(getJpChoice(),
134: BoxLayout.Y_AXIS));
135: jpChoice.add(getJpExistingTestPlan(), null);
136: jpChoice.add(getJpNewTestPlan(), null);
137: } catch (java.lang.Throwable e) {
138: // TODO: Something
139: }
140: }
141: return jpChoice;
142: }
143:
144: /**
145: * This method initializes jrbExistingTestPlan
146: *
147: * @return javax.swing.JRadioButton
148: */
149: private JRadioButton getJrbExistingTestPlan() {
150: if (jrbExistingTestPlan == null) {
151: try {
152: jrbExistingTestPlan = new JRadioButton();
153: jrbExistingTestPlan.setText(Language.getInstance()
154: .getText("Existing_script"));
155: jrbExistingTestPlan.setSelected(true);
156: jbgGroup.add(jrbExistingTestPlan);
157: jrbExistingTestPlan
158: .addChangeListener(new javax.swing.event.ChangeListener() {
159: public void stateChanged(
160: javax.swing.event.ChangeEvent evt) {
161: selectedAction();
162: }
163: });
164: } catch (java.lang.Throwable e) {
165: // TODO: Something
166: }
167: }
168: return jrbExistingTestPlan;
169: }
170:
171: /**
172: * This method initializes jrbNewTestPlan
173: *
174: * @return javax.swing.JRadioButton
175: */
176: private JRadioButton getJrbNewTestPlan() {
177: if (jrbNewTestPlan == null) {
178: try {
179: jrbNewTestPlan = new JRadioButton();
180: jrbNewTestPlan.setText(Language.getInstance().getText(
181: "New_script"));
182: jbgGroup.add(jrbNewTestPlan);
183: jrbNewTestPlan
184: .addChangeListener(new javax.swing.event.ChangeListener() {
185: public void stateChanged(
186: javax.swing.event.ChangeEvent evt) {
187: selectedAction();
188: }
189: });
190: } catch (java.lang.Throwable e) {
191: // TODO: Something
192: }
193: }
194: return jrbNewTestPlan;
195: }
196:
197: /**
198: * This method initializes jpExistingTestPlan
199: *
200: * @return javax.swing.JPanel
201: */
202: private JPanel getJpExistingTestPlan() {
203: if (jpExistingTestPlan == null) {
204: try {
205: jpExistingTestPlan = new JPanel();
206: jpExistingTestPlan.setLayout(new BorderLayout());
207: jpExistingTestPlan.add(getJrbExistingTestPlan(),
208: BorderLayout.NORTH);
209: jpExistingTestPlan.add(getJpBrowse(),
210: BorderLayout.CENTER);
211: } catch (java.lang.Throwable e) {
212: // TODO: Something
213: }
214: }
215: return jpExistingTestPlan;
216: }
217:
218: /**
219: * This method initializes jpNewTestPlan
220: *
221: * @return javax.swing.JPanel
222: */
223: private JPanel getJpNewTestPlan() {
224: if (jpNewTestPlan == null) {
225: try {
226: jpNewTestPlan = new JPanel();
227: jpNewTestPlan.setLayout(new BorderLayout());
228: jpNewTestPlan.add(getJrbNewTestPlan(),
229: BorderLayout.NORTH);
230: jpNewTestPlan.add(getJpNameTestPlan(),
231: BorderLayout.CENTER);
232: } catch (java.lang.Throwable e) {
233: // TODO: Something
234: }
235: }
236: return jpNewTestPlan;
237: }
238:
239: /**
240: * This method initializes jtfExistingTestPlanName
241: *
242: * @return javax.swing.JTextField
243: */
244: private JTextField getJtfExistingTestPlanName() {
245: if (jtfExistingTestPlanName == null) {
246: try {
247: jtfExistingTestPlanName = new JTextField();
248: jtfExistingTestPlanName.setText("");
249: jtfExistingTestPlanName.setPreferredSize(new Dimension(
250: 250, 19));
251: } catch (java.lang.Throwable e) {
252: // TODO: Something
253: }
254: }
255: return jtfExistingTestPlanName;
256: }
257:
258: /**
259: * This method initializes jbBrowse
260: *
261: * @return javax.swing.JButton
262: */
263: private JButton getJbBrowse() {
264: if (jbBrowse == null) {
265: try {
266: jbBrowse = new JButton();
267: jbBrowse.setText(Language.getInstance().getText(
268: "Browse"));
269: jbBrowse.addActionListener(new ActionListener() {
270: public void actionPerformed(ActionEvent e) {
271: displayFileChooser();
272: }
273: });
274: } catch (java.lang.Throwable e) {
275: // TODO: Something
276: }
277: }
278: return jbBrowse;
279: }
280:
281: /**
282: * This method initializes jtfNewTestPlanName
283: *
284: * @return javax.swing.JTextField
285: */
286: private JTextField getJtfNewTestPlanName() {
287: if (jtfNewTestPlanName == null) {
288: try {
289: jtfNewTestPlanName = new JTextField();
290: jtfNewTestPlanName.setText("");
291: jtfNewTestPlanName.setEnabled(false);
292: jtfNewTestPlanName.setPreferredSize(new Dimension(170,
293: 19));
294: } catch (java.lang.Throwable e) {
295: // TODO: Something
296: }
297: }
298: return jtfNewTestPlanName;
299: }
300:
301: /**
302: * This method initializes jpButtons
303: *
304: * @return javax.swing.JPanel
305: */
306: private JPanel getJpButtons() {
307: if (jpButtons == null) {
308: try {
309: jpButtons = new JPanel();
310: jpButtons.setLayout(new FlowLayout());
311: jpButtons.add(getJbOk(), null);
312: jpButtons.add(getJbCancel(), null);
313: } catch (java.lang.Throwable e) {
314: // TODO: Something
315: }
316: }
317: return jpButtons;
318: }
319:
320: /**
321: * This method initializes jbCancel
322: *
323: * @return javax.swing.JButton
324: */
325: private JButton getJbCancel() {
326: if (jbCancel == null) {
327: try {
328: jbCancel = new JButton();
329: jbCancel.setText(Language.getInstance().getText(
330: "Annuler"));
331: jbCancel.addActionListener(new ActionListener() {
332: public void actionPerformed(ActionEvent e) {
333: jbCancelActionPerformed();
334: }
335: });
336: } catch (java.lang.Throwable e) {
337: // TODO: Something
338: }
339: }
340: return jbCancel;
341: }
342:
343: private void jbCancelActionPerformed() {
344: this .dispose();
345: }
346:
347: /**
348: * This method initializes jbOk
349: *
350: * @return javax.swing.JButton
351: */
352: private JButton getJbOk() {
353: if (jbOk == null) {
354: try {
355: jbOk = new JButton();
356: jbOk.setText(Language.getInstance().getText("Valider"));
357: jbOk.addActionListener(new ActionListener() {
358: public void actionPerformed(ActionEvent e) {
359: jbOkActionPerformed();
360: }
361: });
362: } catch (java.lang.Throwable e) {
363: // TODO: Something
364: }
365: }
366: return jbOk;
367: }
368:
369: private void jbOkActionPerformed() {
370: if (jrbExistingTestPlan.isSelected()) {
371: if (jtfExistingTestPlanName.getText().trim().equals("")) {
372: JOptionPane.showMessageDialog(this ,
373: "Please select a script.", "Warning",
374: JOptionPane.INFORMATION_MESSAGE);
375: } else {
376: this .dispose();
377: }
378: } else if (jrbNewTestPlan.isSelected()) {
379: if (jtfNewTestPlanName.getText().trim().equals("")) {
380: JOptionPane.showMessageDialog(this ,
381: "Please fill the new script name.", "Warning",
382: JOptionPane.INFORMATION_MESSAGE);
383: } else {
384: this .dispose();
385: }
386: }
387: }
388:
389: /**
390: * This method initializes jpNameTestPlan
391: *
392: * @return javax.swing.JPanel
393: */
394: private JPanel getJpNameTestPlan() {
395: if (jpNameTestPlan == null) {
396: try {
397: jpNameTestPlan = new JPanel();
398: jpNameTestPlan
399: .setLayout(new FlowLayout(FlowLayout.LEFT));
400: jpNameTestPlan.setBorder(BorderFactory
401: .createTitledBorder(null, "",
402: TitledBorder.DEFAULT_JUSTIFICATION,
403: TitledBorder.DEFAULT_POSITION, null,
404: null));
405: jlTitleNewTesPlan = new JLabel(Language.getInstance()
406: .getText("Nom_du_script_:_"));
407: jpNameTestPlan.add(jlTitleNewTesPlan, null);
408: jpNameTestPlan.add(getJtfNewTestPlanName(), null);
409: } catch (java.lang.Throwable e) {
410: // TODO: Something
411: }
412: }
413: return jpNameTestPlan;
414: }
415:
416: /**
417: * This method initializes jpBrowse
418: *
419: * @return javax.swing.JPanel
420: */
421: private JPanel getJpBrowse() {
422: if (jpBrowse == null) {
423: try {
424: jpBrowse = new JPanel();
425: jpBrowse.setLayout(new FlowLayout(FlowLayout.LEFT));
426: jpBrowse.setBorder(BorderFactory.createTitledBorder(
427: null, "", TitledBorder.DEFAULT_JUSTIFICATION,
428: TitledBorder.DEFAULT_POSITION, null, null));
429: jpBrowse.add(getJtfExistingTestPlanName(), null);
430: jpBrowse.add(getJbBrowse(), null);
431: } catch (java.lang.Throwable e) {
432: // TODO: Something
433: }
434: }
435: return jpBrowse;
436: }
437:
438: }
|