KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > dialogs > ImportWorkflowDialog


1 package com.opensymphony.workflow.designer.dialogs;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import java.net.URL JavaDoc;
6 import java.net.MalformedURLException JavaDoc;
7 import java.io.File JavaDoc;
8 import javax.swing.*;
9
10 import com.opensymphony.workflow.designer.ResourceManager;
11 import com.opensymphony.workflow.designer.UIFactory;
12 import com.opensymphony.workflow.designer.swing.FileField;
13 import com.jgoodies.forms.builder.DefaultFormBuilder;
14
15 /**
16  * @author Hani Suleiman (hani@formicary.net)
17  * Date: Dec 25, 2003
18  * Time: 1:25:28 AM
19  */

20 public class ImportWorkflowDialog extends BaseDialog
21 {
22   private JRadioButton web = new JRadioButton(ResourceManager.getString("import.web.long"));
23   private JRadioButton file = new JRadioButton(ResourceManager.getString("import.file.long"));
24   private FileField fileField = new FileField(JFileChooser.FILES_AND_DIRECTORIES, false, ".xml", ResourceManager.getString("descriptor.files"));
25   private JTextField webField = new JTextField();
26   private URL JavaDoc url;
27
28   public ImportWorkflowDialog(Frame owner, String JavaDoc title, boolean modal) throws HeadlessException
29   {
30     super(owner, title, modal);
31     DefaultFormBuilder builder = UIFactory.getDialogBuilder(null, getContentPane());
32     builder.append(web, webField);
33       webField.addFocusListener(new FocusAdapter()
34       {
35           public void focusGained(FocusEvent e)
36           {
37               web.setSelected(true);
38           }
39       });
40     builder.nextLine();
41     ButtonGroup group = new ButtonGroup();
42     group.add(web);
43     group.add(file);
44     builder.append(file, fileField);
45       fileField.getTextField().addFocusListener(new FocusAdapter()
46       {
47           public void focusGained(FocusEvent e)
48           {
49               file.setSelected(true);
50           }
51       });
52     fileField.addActionListener(new ActionListener()
53     {
54       public void actionPerformed(ActionEvent e)
55       {
56         file.setSelected(true);
57       }
58     });
59   }
60
61     public void ok()
62     {
63         if(web.isSelected())
64         {
65           try
66           {
67             url = new URL JavaDoc(webField.getText());
68             super.ok();
69               return;
70           }
71           catch(MalformedURLException JavaDoc e1)
72           {
73             JOptionPane.showMessageDialog(this, ResourceManager.getString("import.url.invalid", new Object JavaDoc[]{e1.getMessage()}));
74           }
75         }
76         else if(file.isSelected())
77         {
78           try
79           {
80             File JavaDoc f = new File JavaDoc(fileField.getText());
81             if(!f.exists() || f.isDirectory())
82             {
83               JOptionPane.showMessageDialog(this, ResourceManager.getString("import.url.file.invalid"));
84               return;
85             }
86             url = f.toURL();
87               super.ok();
88                 return;
89           }
90           catch(MalformedURLException JavaDoc e1)
91           {
92             JOptionPane.showMessageDialog(this, ResourceManager.getString("import.url.invalid", new Object JavaDoc[]{e1.getMessage()}),
93               ResourceManager.getString("error"), JOptionPane.ERROR_MESSAGE);
94           }
95         }
96     }
97
98   public URL JavaDoc getImportURL()
99   {
100     return url;
101   }
102 }
103
Popular Tags