1 package com.opensymphony.workflow.designer.dialogs; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import java.io.File ; 6 import java.net.MalformedURLException ; 7 import javax.swing.*; 8 9 import com.jgoodies.forms.layout.FormLayout; 10 import com.jgoodies.forms.builder.DefaultFormBuilder; 11 import com.opensymphony.workflow.designer.swing.FileField; 12 import com.opensymphony.workflow.designer.*; 13 import com.opensymphony.workflow.loader.Workspace; 14 15 20 public class NewWorkspaceDialog extends BaseDialog 21 { 22 private JRadioButton create = new JRadioButton(ResourceManager.getString("workspace.create")); 23 private JRadioButton load = new JRadioButton(ResourceManager.getString("workspace.load")); 24 private FileField loadField = new FileField(JFileChooser.FILES_AND_DIRECTORIES, false, WorkflowDesigner.WORKSPACE_SUFFIX, ResourceManager.getString("workspace.files")); 25 private FileField createField = new FileField(JFileChooser.FILES_AND_DIRECTORIES, true, WorkflowDesigner.WORKSPACE_SUFFIX, ResourceManager.getString("workspace.files")); 26 27 public NewWorkspaceDialog(Frame owner, String title, boolean modal) throws HeadlessException 28 { 29 super(owner, title, modal); 30 FormLayout layout = new FormLayout("2dlu, left:max(40dlu;pref), 3dlu, 110dlu:grow, 7dlu"); 32 DefaultFormBuilder builder = new DefaultFormBuilder(layout, ResourceManager.getBundle()); 33 builder.setLeadingColumnOffset(1); 34 35 builder.appendI15dSeparator("workspace.createload"); 36 builder.append(load, loadField); 37 loadField.addFocusListener(new FocusAdapter() 38 { 39 public void focusGained(FocusEvent e) 40 { 41 load.setSelected(true); 42 } 43 }); 44 loadField.addActionListener(new ActionListener() 45 { 46 public void actionPerformed(ActionEvent e) 47 { 48 load.setSelected(true); 49 } 50 }); 51 builder.nextLine(); 52 ButtonGroup group = new ButtonGroup(); 53 group.add(create); 54 group.add(load); 55 builder.append(create, createField); 56 builder.nextLine(); 57 createField.getTextField().addFocusListener(new FocusAdapter() 58 { 59 public void focusGained(FocusEvent e) 60 { 61 create.setSelected(true); 62 } 63 }); 64 createField.addActionListener(new ActionListener() 65 { 66 public void actionPerformed(ActionEvent e) 67 { 68 create.setSelected(true); 69 } 70 }); 71 72 getContentPane().add(builder.getPanel()); 73 } 74 75 public void ok() 76 { 77 if(load.isSelected()) 78 { 79 File file = loadField.getFile(); 80 if(file==null || file.isDirectory()) 81 { 82 JOptionPane.showMessageDialog(this, ResourceManager.getString("error.file.invalid"), ResourceManager.getString("error"), JOptionPane.ERROR_MESSAGE); 83 return; 84 } 85 try 86 { 87 WorkflowDesigner.INSTANCE.openWorkspace(loadField.getFile().toURL()); 88 } 89 catch(MalformedURLException e) 90 { 91 e.printStackTrace(); 92 } 93 } 94 else 95 { 96 File file = createField.getFile(); 97 if(file == null || file.isDirectory()) 98 { 99 JOptionPane.showMessageDialog(this, ResourceManager.getString("error.file.invalid"), ResourceManager.getString("error"), JOptionPane.ERROR_MESSAGE); 100 return; 101 } 102 Workspace space = WorkflowDesigner.INSTANCE.newWorkspace(); 103 space.setLocation(file); 104 Prefs.INSTANCE.put(Prefs.LAST_WORKSPACE, file.toString()); 105 WorkflowDesigner.INSTANCE.navigator().setWorkspace(space); 106 } 107 super.ok(); 108 } 109 } 110 | Popular Tags |