Commits

hani  committed 9204b73

If no current workspace on startup, prompt user to load/create

  • Participants
  • Parent commits 4c7fad6

Comments (0)

Files changed (4)

File src/designer/com/opensymphony/workflow/designer/ResourceManager.properties

 title.warn=Warning
 
 descriptor.files=XML Workflow Files
-workspaces.files=Workspace Files
+workspace.files=Workspace Files
 png.files=PNG Files
 
 workspace=Workspace
+workspace.new=Select Workspace
+workspace.load=Load existing workspace
+workspace.create=Create new workspace
+workspace.createload=Please create or load a new workspace
 error=Error
 error.save.workflow=Invalid Workflow: {0}
 error.save.workflow.long=Error saving workflow {0}
 error.save.unsavedspace=Please save this workspace before importing workflows into it
+error.file.invalid=Invalid file selected
 
 import.web=URL
 import.web.long=Import from a URL

File src/designer/com/opensymphony/workflow/designer/UIFactory.java

 	  return ButtonBarFactory.buildCenteredBar(buttons);
   }
 
+  public static JPanel getButtonBar(ActionListener[] listener, String prefix, String[] names)
+  {
+    if(prefix == null) prefix = "";
+    if(listener.length!=names.length) throw new IllegalArgumentException("listener.length=" + listener.length + " but names.length=" + names.length);
+    JButton[] buttons = new JButton[names.length];
+    for(int i = 0; i < buttons.length; i++)
+    {
+      buttons[i] = new JButton(ResourceManager.getString(names[i]));
+      buttons[i].setActionCommand(prefix + names[i]);
+      buttons[i].addActionListener(listener[i]);
+    }
+    return ButtonBarFactory.buildCenteredBar(buttons);
+  }
+
   public static JComponent createTablePanel(JTable table)
   {
     Color background = UIManager.getColor("window");

File src/designer/com/opensymphony/workflow/designer/WorkflowDesigner.java

 import com.opensymphony.workflow.designer.editor.*;
 import com.opensymphony.workflow.designer.swing.*;
 import com.opensymphony.workflow.designer.swing.status.StatusBar;
+import com.opensymphony.workflow.designer.dialogs.NewWorkspaceDialog;
 import com.opensymphony.workflow.loader.PaletteDescriptor;
 import com.opensymphony.workflow.loader.WorkflowDescriptor;
 import com.opensymphony.workflow.loader.Workspace;
     }
   }
 
+  public void checkWorkspaceExists()
+  {
+    if(manager.getCurrentWorkspace()==null)
+    {
+      NewWorkspaceDialog newSpace = new NewWorkspaceDialog(this, ResourceManager.getString("workspace.new"), true);
+      Utils.centerComponent(this, newSpace);
+      newSpace.show();
+    }
+  }
+
   public void save(int index)
   {
     Layout layout = (Layout)mlayout.get(index);
     manager.saveWorkspace();
   }
 
-  public void newWorkspace()
+  public Workspace newWorkspace()
   {
     closeWorkspace();
     Workspace workspace = new Workspace();
     manager.setCurrentWorkspace(workspace);
     navigator.setWorkspace(workspace);
+    return workspace;
   }
 
   public void closeWorkspace()
     splash.setProgress(100);
     splash.closeSplash();
     splash = null;
+    d.checkWorkspaceExists();
   }
 }

File src/designer/com/opensymphony/workflow/designer/dialogs/NewWorkspaceDialog.java

+package com.opensymphony.workflow.designer.dialogs;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.io.File;
+import javax.swing.*;
+
+import com.jgoodies.forms.layout.FormLayout;
+import com.opensymphony.workflow.designer.swing.DefaultFormBuilder;
+import com.opensymphony.workflow.designer.swing.FileField;
+import com.opensymphony.workflow.designer.*;
+import com.opensymphony.workflow.loader.Workspace;
+
+/**
+ * @author Hani Suleiman (hani@formicary.net)
+ *         Date: Dec 28, 2003
+ *         Time: 4:39:11 PM
+ */
+public class NewWorkspaceDialog extends JDialog implements ActionListener
+{
+  private JRadioButton create = new JRadioButton(ResourceManager.getString("workspace.create"));
+  private JRadioButton load = new JRadioButton(ResourceManager.getString("workspace.load"));
+  private FileField loadField = new FileField(JFileChooser.FILES_AND_DIRECTORIES, false, WorkflowDesigner.WORKSPACE_SUFFIX, ResourceManager.getString("workspace.files"));
+  private FileField createField = new FileField(JFileChooser.FILES_AND_DIRECTORIES, true, WorkflowDesigner.WORKSPACE_SUFFIX, ResourceManager.getString("workspace.files"));
+
+  public NewWorkspaceDialog(Frame owner, String title, boolean modal) throws HeadlessException
+  {
+    super(owner, title, modal);
+    getContentPane().setLayout(new BorderLayout());
+    FormLayout layout = new FormLayout("2dlu, left:max(40dlu;pref), 3dlu, 110dlu:grow, 7dlu");
+    DefaultFormBuilder builder = new DefaultFormBuilder(layout, ResourceManager.getBundle());
+    builder.setLeadingColumnOffset(1);
+
+    builder.appendI15dSeparator("workspace.createload");
+    builder.append(load, loadField);
+    loadField.addFocusListener(new FocusAdapter()
+    {
+      public void focusGained(FocusEvent e)
+      {
+        load.setSelected(true);
+      }
+    });
+    loadField.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        load.setSelected(true);
+      }
+    });
+    builder.nextLine();
+    ButtonGroup group = new ButtonGroup();
+    group.add(create);
+    group.add(load);
+    builder.append(create, createField);
+    builder.nextLine();
+    createField.getTextField().addFocusListener(new FocusAdapter()
+    {
+      public void focusGained(FocusEvent e)
+      {
+        create.setSelected(true);
+      }
+    });
+    createField.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        create.setSelected(true);
+      }
+    });
+
+    getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
+    getContentPane().add(UIFactory.getButtonBar(this, "", new String[]{"ok", "cancel"}), BorderLayout.SOUTH);
+    pack();
+  }
+
+  public void actionPerformed(ActionEvent e)
+  {
+    String command = e.getActionCommand();
+    if("ok".equals(command))
+    {
+      if(load.isSelected())
+      {
+        File file = loadField.getFile();
+        if(file==null || file.isDirectory())
+        {
+          JOptionPane.showMessageDialog((Component)e.getSource(), ResourceManager.getString("error.file.invalid"), ResourceManager.getString("error"), JOptionPane.ERROR_MESSAGE);
+          return;
+        }
+        WorkflowDesigner.INSTANCE.openWorkspace(loadField.getFile());
+        dispose();
+      }
+      else
+      {
+        File file = createField.getFile();
+        if(file == null || file.isDirectory())
+        {
+          JOptionPane.showMessageDialog((Component)e.getSource(), ResourceManager.getString("error.file.invalid"), ResourceManager.getString("error"), JOptionPane.ERROR_MESSAGE);
+          return;
+        }
+        Workspace space = WorkflowDesigner.INSTANCE.newWorkspace();
+        space.setLocation(file);
+        Prefs.INSTANCE.put(Prefs.LAST_WORKSPACE, file.toString());
+        WorkflowDesigner.INSTANCE.navigator().setWorkspace(space);
+      }
+      dispose();
+    }
+    else
+    {
+      dispose();
+    }
+  }
+}