/** Save the archetypes list to the datafile. */ public void saveList() { ArchetypesManager.setArchtypesList(listData); try { ArchetypesManager.writeArchetypes(); } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getMessage(), "IO Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } }
/** 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()); }
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(); } }); }