001: package com.opensymphony.workflow.designer.dialogs;
002:
003: import java.awt.*;
004: import java.awt.event.*;
005: import java.io.File;
006: import java.net.MalformedURLException;
007: import javax.swing.*;
008:
009: import com.jgoodies.forms.layout.FormLayout;
010: import com.jgoodies.forms.builder.DefaultFormBuilder;
011: import com.opensymphony.workflow.designer.swing.FileField;
012: import com.opensymphony.workflow.designer.*;
013: import com.opensymphony.workflow.loader.Workspace;
014:
015: /**
016: * @author Hani Suleiman (hani@formicary.net)
017: * Date: Dec 28, 2003
018: * Time: 4:39:11 PM
019: */
020: public class NewWorkspaceDialog extends BaseDialog {
021: private JRadioButton create = new JRadioButton(ResourceManager
022: .getString("workspace.create"));
023: private JRadioButton load = new JRadioButton(ResourceManager
024: .getString("workspace.load"));
025: private FileField loadField = new FileField(
026: JFileChooser.FILES_AND_DIRECTORIES, false,
027: WorkflowDesigner.WORKSPACE_SUFFIX, ResourceManager
028: .getString("workspace.files"));
029: private FileField createField = new FileField(
030: JFileChooser.FILES_AND_DIRECTORIES, true,
031: WorkflowDesigner.WORKSPACE_SUFFIX, ResourceManager
032: .getString("workspace.files"));
033:
034: public NewWorkspaceDialog(Frame owner, String title, boolean modal)
035: throws HeadlessException {
036: super (owner, title, modal);
037: //getContentPane().setLayout(new BorderLayout());
038: FormLayout layout = new FormLayout(
039: "2dlu, left:max(40dlu;pref), 3dlu, 110dlu:grow, 7dlu");
040: DefaultFormBuilder builder = new DefaultFormBuilder(layout,
041: ResourceManager.getBundle());
042: builder.setLeadingColumnOffset(1);
043:
044: builder.appendI15dSeparator("workspace.createload");
045: builder.append(load, loadField);
046: loadField.addFocusListener(new FocusAdapter() {
047: public void focusGained(FocusEvent e) {
048: load.setSelected(true);
049: }
050: });
051: loadField.addActionListener(new ActionListener() {
052: public void actionPerformed(ActionEvent e) {
053: load.setSelected(true);
054: }
055: });
056: builder.nextLine();
057: ButtonGroup group = new ButtonGroup();
058: group.add(create);
059: group.add(load);
060: builder.append(create, createField);
061: builder.nextLine();
062: createField.getTextField().addFocusListener(new FocusAdapter() {
063: public void focusGained(FocusEvent e) {
064: create.setSelected(true);
065: }
066: });
067: createField.addActionListener(new ActionListener() {
068: public void actionPerformed(ActionEvent e) {
069: create.setSelected(true);
070: }
071: });
072:
073: getContentPane().add(builder.getPanel());
074: }
075:
076: public void ok() {
077: if (load.isSelected()) {
078: File file = loadField.getFile();
079: if (file == null || file.isDirectory()) {
080: JOptionPane.showMessageDialog(this , ResourceManager
081: .getString("error.file.invalid"),
082: ResourceManager.getString("error"),
083: JOptionPane.ERROR_MESSAGE);
084: return;
085: }
086: try {
087: WorkflowDesigner.INSTANCE.openWorkspace(loadField
088: .getFile().toURL());
089: } catch (MalformedURLException e) {
090: e.printStackTrace();
091: }
092: } else {
093: File file = createField.getFile();
094: if (file == null || file.isDirectory()) {
095: JOptionPane.showMessageDialog(this , ResourceManager
096: .getString("error.file.invalid"),
097: ResourceManager.getString("error"),
098: JOptionPane.ERROR_MESSAGE);
099: return;
100: }
101: Workspace space = WorkflowDesigner.INSTANCE
102: .newLocalWorkspace();
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: }
|