/**
   * Creates a new dockable.
   *
   * @param manager the manager used to handle all operations concerning dockables.
   */
  public PictureRepositoryDockable(final ViewManager manager) {
    super("PictureListDockable");
    pictures = manager.getPictures();

    setCloseable(true);
    setMinimizable(true);
    setMaximizable(true);
    setExternalizable(true);
    setTitleText("Pictures");
    setTitleIcon(Resources.getIcon("dockable.list"));

    pictureListModel = new DefaultListModel();
    list = new JList(pictureListModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    Container content = getContentPane();
    content.setLayout(new GridBagLayout());
    content.add(
        new JScrollPane(list),
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1.0,
            100.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(1, 1, 1, 1),
            0,
            0));

    pictureNew =
        new CButton() {
          @Override
          protected void action() {
            String name = askForName();
            if (name != null) {
              pictures.add(new Picture(name));
            }
          }
        };
    pictureNew.setText("New picture");
    pictureNew.setTooltip("Creates a new picture");
    pictureNew.setIcon(Resources.getIcon("picture.add"));

    pictureDelete =
        new CButton() {
          @Override
          protected void action() {
            Picture picture = (Picture) list.getSelectedValue();
            if (picture != null) {
              pictures.remove(picture);
            }
          }
        };
    pictureDelete.setText("Delete picture");
    pictureDelete.setTooltip("Delete the selected picture");
    pictureDelete.setIcon(Resources.getIcon("picture.remove"));
    pictureDelete.setEnabled(false);

    pictureShow =
        new CButton() {
          @Override
          protected void action() {
            Picture picture = (Picture) list.getSelectedValue();
            if (picture != null) manager.open(picture);
          }
        };
    pictureShow.setText("Show picture");
    pictureShow.setTooltip("Open a new view displaying the selected picture");
    pictureShow.setIcon(Resources.getIcon("picture.show"));
    pictureShow.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
    pictureShow.setEnabled(false);

    addAction(pictureNew);
    addAction(pictureDelete);
    addAction(pictureShow);
    addSeparator();

    pictures.addListener(
        new PictureRepositoryListener() {
          public void pictureAdded(Picture picture) {
            pictureListModel.addElement(picture);
          }

          public void pictureRemoved(Picture picture) {
            pictureListModel.removeElement(picture);
          }
        });
    list.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            boolean enable = list.getSelectedValue() != null;
            pictureDelete.setEnabled(enable);
            pictureShow.setEnabled(enable);
          }
        });
  }