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