/**
* Wizard page that lets the user manage his projects and start inserts.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
public class ProjectPage extends TWizardPage implements ListSelectionListener, DocumentListener, ClipboardOwner {
/** The “generate key” action. */
private Action projectGenerateKeyAction;
+ /** The “reset edition” action. */
+ private Action projectResetEditionAction;
+
/** The file chooser. */
private JFileChooser pathChooser;
/**
* Creates a new project page.
- *
+ *
* @param wizard
* The wizard this page belongs to
*/
/**
* Adds the given listener to the list of listeners.
- *
+ *
* @param listener
* The listener to add
*/
/**
* Removes the given listener from the list of listeners.
- *
+ *
* @param listener
* The listener to remove
*/
projectGenerateKeyAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_G);
projectGenerateKeyAction.setEnabled(false);
+ projectResetEditionAction = new AbstractAction(I18n.getMessage("jsite.project.action.reset-edition")) {
+
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ actionResetEdition();
+ }
+ };
+ projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
+ projectResetEditionAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R);
+ projectResetEditionAction.setEnabled(false);
+
I18nContainer.getInstance().registerRunnable(new Runnable() {
@SuppressWarnings("synthetic-access")
projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
projectGenerateKeyAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.generate-new-key"));
projectGenerateKeyAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.generate-new-key.tooltip"));
+ projectResetEditionAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.reset-edition"));
+ projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
pathChooser.setApproveButtonText(I18n.getMessage("jsite.project.action.browse.choose"));
}
});
/**
* Creates the information panel.
- *
+ *
* @return The information panel
*/
private JComponent createInformationPanel() {
final TLabel projectPrivateKeyLabel = new TLabel(I18n.getMessage("jsite.project.project.private-key") + ":", KeyEvent.VK_R, projectPrivateKeyTextField);
informationTable.add(projectPrivateKeyLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
- informationTable.add(projectPrivateKeyTextField, new GridBagConstraints(1, 6, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
+ informationTable.add(projectPrivateKeyTextField, new GridBagConstraints(1, 6, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
+ informationTable.add(new JButton(projectResetEditionAction), new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
projectPathTextField = new JTextField();
projectPathTextField.getDocument().putProperty("name", "project.path");
/**
* Sets the project list.
- *
+ *
* @param projects
* The list of projects
*/
/**
* Returns the list of projects.
- *
+ *
* @return The list of projects
*/
public Project[] getProjects() {
/**
* Sets the freenet interface to use.
- *
+ *
* @param freenetInterface
* The freenetInterface to use
*/
/**
* Returns the currently selected project.
- *
+ *
* @return The currently selected project
*/
public Project getSelectedProject() {
/**
* Updates the currently selected project with changed information from a
* textfield.
- *
+ *
* @param documentEvent
* The document event to process
*/
newProject.setName(I18n.getMessage("jsite.project.new-project.name"));
newProject.setInsertURI(keyPair[0]);
newProject.setRequestURI(keyPair[1]);
- newProject.setEdition(0);
+ newProject.setEdition(-1);
+ newProject.setPath("");
projectListModel.add(newProject);
projectScrollPane.revalidate();
projectScrollPane.repaint();
- projectList.setSelectedIndex(projectListModel.size() - 1);
+ projectList.setSelectedIndex(projectListModel.indexOf(newProject));
}
/**
}
}
+ /**
+ * Resets the edition of the currently selected project.
+ */
+ private void actionResetEdition() {
+ if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.reset-edition"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
+ return;
+ }
+ int selectedIndex = projectList.getSelectedIndex();
+ if (selectedIndex > -1) {
+ Project selectedProject = (Project) projectList.getSelectedValue();
+ selectedProject.setEdition(-1);
+ }
+ }
+
//
// INTERFACE ListSelectionListener
//
projectCloneAction.setEnabled(selectedRow > -1);
projectCopyURIAction.setEnabled(selectedRow > -1);
projectGenerateKeyAction.setEnabled(selectedRow > -1);
+ projectResetEditionAction.setEnabled(selectedRow > -1);
if (selectedRow > -1) {
projectNameTextField.setText(selectedProject.getName());
projectDescriptionTextField.setText(selectedProject.getDescription());