/** Create a new archetype. */
 private void makeNewAchetype() {
   Archetype archetype = new Archetype();
   archetype.setName("New Archetype");
   listData.add(archetype);
   archetypeList.setSelectedIndex(listData.size() - 1);
   saveListAction.setEnabled(true);
 }
 /**
  * Respond to selections within the left list.
  *
  * @throws InvocationTargetException
  * @throws InterruptedException
  */
 private void respondToListClick() {
   this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
   enableOrDisableActions();
   int idx = archetypeList.getSelectedIndex();
   if (idx == -1 || idx >= listData.size()) {
     // no selection
     if (archetypeControl == null) {
       return;
     }
     archetypeControl.removeNameChangeListener(this);
     rightPanel.removeAll();
     archetypeControl = null;
     rightPanel.add(selectLeftLabel);
     rightPanel.repaint();
     return;
   }
   if (archetypeControl == null) {
     archetypeControl = new ArchetypeControl(listData.get(idx));
     setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
     rightPanel.removeAll();
     rightPanel.add(archetypeControl, BorderLayout.CENTER);
     rightPanel.repaint();
     rightPanel.revalidate();
     setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
     archetypeControl.addNameChangeListener(this);
   } else {
     archetypeControl.setArchetype(listData.get(idx));
     archetypeControl.repaint();
   }
   this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
 }
 /** Revert the list back to its saved state. */
 protected void revertList() {
   int ret =
       JOptionPane.showConfirmDialog(
           this, "Revert list losing unsaved changes?", "Confirm", JOptionPane.OK_CANCEL_OPTION);
   if (ret == JOptionPane.CANCEL_OPTION) {
     return;
   }
   archetypeControl.removeNameChangeListener(this);
   rightPanel.removeAll();
   archetypeControl = null;
   rightPanel.add(selectLeftLabel);
   rightPanel.repaint();
   listData.clear();
   listData.addAll(ArchetypesManager.getArchetypes());
 }
  protected void doExportSelected() {
    Archetype selected = listData.get(archetypeList.getSelectedIndex());
    if (selected == null) {
      return;
    }
    // Set up the dialog
    JMemoryFileChooser chooser = new JMemoryFileChooser();
    chooser.setFileFilter(characterFileFilter);
    chooser.setSelectedFile(new File(selected.getName() + ".xml"));
    chooser.setDialogTitle("Export Archetype");
    chooser.setApproveButtonText("Export");

    // Call dialog
    if (chooser.showSaveDialog(FILEDIALOG_NAME, this) != JFileChooser.APPROVE_OPTION) {
      return;
    }
    File targetFile = chooser.getSelectedFile();
    // Save it
    try {
      performSave(selected, targetFile);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          this, "An error occured during export.", "Error", JOptionPane.ERROR_MESSAGE);
    }
  }
 /**
  * @param importFile
  * @throws IOException
  * @throws JDOMException
  */
 private void performImport(File importFile) throws JDOMException, IOException {
   SAXBuilder builder = new SAXBuilder();
   Document doc = builder.build(importFile);
   Element root = doc.getRootElement();
   Archetype imported = new Archetype();
   imported.setXML(root);
   listData.add(imported);
 }
 /** Delete selected archetype */
 private void deleteSelectedAchetype() {
   int idx = archetypeList.getSelectedIndex();
   if (idx == -1) {
     return;
   }
   StringBuilder msg = new StringBuilder(256);
   msg.append("Delete archetype \"");
   msg.append(listData.get(idx).getName());
   msg.append("\" ?");
   int ret =
       JOptionPane.showConfirmDialog(
           this, msg.toString(), "Confirm", JOptionPane.OK_CANCEL_OPTION);
   if (ret == JOptionPane.CANCEL_OPTION) {
     return;
   }
   listData.remove(idx);
   saveListAction.setEnabled(true);
 }
 private void enableOrDisableActions() {
   int idx = archetypeList.getSelectedIndex();
   if (archetypeList.getSelectedIndex() == -1) {
     deleteArchetypeAction.setEnabled(false);
     return;
   }
   if (StringUtils.equalsIgnoreCase("generic", listData.get(idx).getName())) {
     deleteArchetypeAction.setEnabled(false);
     return;
   }
   exportArchetypeAction.setEnabled(true);
   deleteArchetypeAction.setEnabled(true);
 }
  private void buildLeftPanel() {
    leftPanel = new JPanel();
    leftPanel.setLayout(new GridBagLayout());
    listData = new MutableList<Archetype>();
    listData.addAll(ArchetypesManager.getInstance().getArchetypes());
    archetypeList = new JList(listData);
    archetypeList.setCellRenderer(new ArchetypesCellRenderer());
    archetypeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    scroller = new JScrollPane(archetypeList);
    Insets buttonInsets = new Insets(0, 2, 5, 2);
    leftPanel.add(
        scroller,
        new GridBagConstraints(
            0,
            2,
            2,
            1,
            0.25,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 2, 0, 2),
            0,
            0));

    addButton = new JButton(newArchetypeAction);
    deleteButton = new JButton(deleteArchetypeAction);
    saveButton = new JButton(saveListAction);
    revertButton = new JButton(revertListAction);

    leftPanel.add(
        addButton,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0,
            0,
            GridBagConstraints.NORTH,
            GridBagConstraints.HORIZONTAL,
            buttonInsets,
            0,
            0));
    leftPanel.add(
        deleteButton,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0,
            0,
            GridBagConstraints.NORTH,
            GridBagConstraints.HORIZONTAL,
            buttonInsets,
            0,
            0));

    addButton.setMargin(new Insets(0, 2, 0, 2));
    deleteButton.setMargin(new Insets(0, 2, 0, 2));
    saveButton.setMargin(new Insets(0, 2, 0, 2));
    revertButton.setMargin(new Insets(0, 2, 0, 2));
    deleteArchetypeAction.setEnabled(false);
    // leftPanel.setBorder( BorderFactory.createTitledBorder("Archetypes") );
    exportArchetypeAction.setEnabled(false);
    archetypeList.addListSelectionListener(
        new ListSelectionListener() {

          public void valueChanged(ListSelectionEvent e) {
            respondToListClick();
          }
        });
  }