Exemplo n.º 1
0
  private void filesChangedWorker() {
    // TODO: once this is editable, make sure changes are committed
    fileDetails.reset();
    for (final FileObject file : table.getSelectedFiles()) fileDetails.showFileDetails(file);
    if (fileDetails.getDocument().getLength() > 0 && table.areAllSelectedFilesUploadable())
      fileDetails.setEditableForDevelopers();

    for (final FileAction button : fileActions) button.enableIfValid();

    apply.setEnabled(files.hasChanges());
    cancel.setText(files.hasChanges() ? "Cancel" : "Close");

    if (files.hasUploadableSites()) enableUploadOrNot();

    int install = 0, uninstall = 0, upload = 0;
    long bytesToDownload = 0, bytesToUpload = 0;

    for (final FileObject file : files)
      switch (file.getAction()) {
        case INSTALL:
        case UPDATE:
          install++;
          bytesToDownload += file.filesize;
          break;
        case UNINSTALL:
          uninstall++;
          break;
        case UPLOAD:
          upload++;
          bytesToUpload += file.filesize;
          break;
      }
    int implicated = 0;
    final DependencyMap map = files.getDependencies(true);
    for (final FileObject file : map.keySet()) {
      implicated++;
      bytesToUpload += file.filesize;
    }
    String text = "";
    if (install > 0)
      text +=
          " install/update: "
              + install
              + (implicated > 0 ? "+" + implicated : "")
              + " ("
              + sizeToString(bytesToDownload)
              + ")";
    if (uninstall > 0) text += " uninstall: " + uninstall;
    if (files.hasUploadableSites() && upload > 0)
      text += " upload: " + upload + " (" + sizeToString(bytesToUpload) + ")";
    fileSummary.setText(text);
  }
Exemplo n.º 2
0
  protected void showOrHide() {
    for (final FileAction action : fileActions) {
      action.setVisible(!easyMode);
    }
    searchPanel.setVisible(!easyMode);
    viewOptionsPanel.setVisible(!easyMode);
    chooseLabel.setVisible(!easyMode);
    summaryPanel.setVisible(!easyMode);
    rightPanel.setVisible(!easyMode);
    updateSites.setVisible(!easyMode);

    final boolean uploadable = !easyMode && files.hasUploadableSites();
    upload.setVisible(uploadable);
    if (showChanges != null) showChanges.setVisible(uploadable);
    if (rebuildButton != null) rebuildButton.setVisible(uploadable);

    easy.setText(easyMode ? "Advanced mode" : "Easy mode");
  }
Exemplo n.º 3
0
 void enableUploadOrNot() {
   upload.setVisible(!easyMode && files.hasUploadableSites());
   upload.setEnabled(canUpload || files.hasUploadOrRemove());
 }
Exemplo n.º 4
0
  public UpdaterFrame(final FilesCollection files) {
    super("ImageJ Updater");
    setPreferredSize(new Dimension(780, 560));

    this.files = files;

    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(final WindowEvent e) {
            quit();
          }
        });

    // ======== Start: LEFT PANEL ========
    final JPanel leftPanel = new JPanel();
    final GridBagLayout gb = new GridBagLayout();
    leftPanel.setLayout(gb);
    final GridBagConstraints c =
        new GridBagConstraints(
            0,
            0, // x, y
            9,
            1, // rows, cols
            0,
            0, // weightx, weighty
            GridBagConstraints.NORTHWEST, // anchor
            GridBagConstraints.HORIZONTAL, // fill
            new Insets(0, 0, 0, 0),
            0,
            0); // ipadx, ipady

    searchTerm = new JTextField();
    searchTerm
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {

              @Override
              public void changedUpdate(final DocumentEvent e) {
                updateFilesTable();
              }

              @Override
              public void removeUpdate(final DocumentEvent e) {
                updateFilesTable();
              }

              @Override
              public void insertUpdate(final DocumentEvent e) {
                updateFilesTable();
              }
            });
    searchPanel = SwingTools.labelComponentRigid("Search:", searchTerm);
    gb.setConstraints(searchPanel, c);
    leftPanel.add(searchPanel);

    Component box = Box.createRigidArea(new Dimension(0, 10));
    c.gridy = 1;
    gb.setConstraints(box, c);
    leftPanel.add(box);

    viewOptions = new ViewOptions();
    viewOptions.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(final ActionEvent e) {
            updateFilesTable();
          }
        });

    viewOptionsPanel = SwingTools.labelComponentRigid("View Options:", viewOptions);
    c.gridy = 2;
    gb.setConstraints(viewOptionsPanel, c);
    leftPanel.add(viewOptionsPanel);

    box = Box.createRigidArea(new Dimension(0, 10));
    c.gridy = 3;
    gb.setConstraints(box, c);
    leftPanel.add(box);

    // Create labels to annotate table
    chooseLabel = SwingTools.label("Please choose what you want to install/uninstall:", null);
    c.gridy = 4;
    gb.setConstraints(chooseLabel, c);
    leftPanel.add(chooseLabel);

    box = Box.createRigidArea(new Dimension(0, 5));
    c.gridy = 5;
    gb.setConstraints(box, c);
    leftPanel.add(box);

    // Label text for file summaries
    fileSummary = new JLabel();
    summaryPanel = SwingTools.horizontalPanel();
    summaryPanel.add(fileSummary);
    summaryPanel.add(Box.createHorizontalGlue());

    // Create the file table and set up its scrollpane
    table = new FileTable(this);
    table.getSelectionModel().addListSelectionListener(this);
    final JScrollPane fileListScrollpane = new JScrollPane(table);
    fileListScrollpane.getViewport().setBackground(table.getBackground());

    c.gridy = 6;
    c.weightx = 1;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    gb.setConstraints(fileListScrollpane, c);
    leftPanel.add(fileListScrollpane);

    box = Box.createRigidArea(new Dimension(0, 5));
    c.gridy = 7;
    c.weightx = 0;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    gb.setConstraints(box, c);
    leftPanel.add(box);

    // ======== End: LEFT PANEL ========

    // ======== Start: RIGHT PANEL ========
    rightPanel = SwingTools.verticalPanel();

    rightPanel.add(Box.createVerticalGlue());

    fileDetails = new FileDetails(this);
    SwingTools.tab(fileDetails, "Details", "Individual file information", 350, 315, rightPanel);
    // TODO: put this into SwingTools, too
    rightPanel.add(Box.createRigidArea(new Dimension(0, 25)));
    // ======== End: RIGHT PANEL ========

    // ======== Start: TOP PANEL (LEFT + RIGHT) ========
    final JPanel topPanel = SwingTools.horizontalPanel();
    topPanel.add(leftPanel);
    topPanel.add(Box.createRigidArea(new Dimension(15, 0)));
    topPanel.add(rightPanel);
    topPanel.setBorder(BorderFactory.createEmptyBorder(20, 15, 5, 15));
    // ======== End: TOP PANEL (LEFT + RIGHT) ========

    // ======== Start: BOTTOM PANEL ========
    final JPanel bottomPanel2 = SwingTools.horizontalPanel();
    final JPanel bottomPanel = SwingTools.horizontalPanel();
    bottomPanel.setBorder(BorderFactory.createEmptyBorder(5, 15, 15, 15));
    bottomPanel.add(new FileAction("Keep as-is", null));
    bottomPanel.add(Box.createRigidArea(new Dimension(15, 0)));
    bottomPanel.add(new FileAction("Install", Action.INSTALL, "Update", Action.UPDATE));
    bottomPanel.add(Box.createRigidArea(new Dimension(15, 0)));
    bottomPanel.add(new FileAction("Uninstall", Action.UNINSTALL));

    bottomPanel.add(Box.createHorizontalGlue());

    // Button to start actions
    apply =
        SwingTools.button(
            "Apply changes",
            "Start installing/uninstalling files",
            new ActionListener() {

              @Override
              public void actionPerformed(final ActionEvent e) {
                applyChanges();
              }
            },
            bottomPanel);
    apply.setEnabled(files.hasChanges());

    // Manage update sites
    updateSites =
        SwingTools.button(
            "Manage update sites",
            "Manage multiple update sites for updating and uploading",
            new ActionListener() {

              @Override
              public void actionPerformed(final ActionEvent e) {
                new SitesDialog(
                        UpdaterFrame.this,
                        UpdaterFrame.this.files,
                        UpdaterFrame.this.files.hasUploadableSites())
                    .setVisible(true);
              }
            },
            bottomPanel2);

    // TODO: unify upload & apply changes (probably apply changes first, then
    // upload)
    // includes button to upload to server if is a Developer using
    bottomPanel2.add(Box.createRigidArea(new Dimension(15, 0)));
    upload =
        SwingTools.button(
            "Upload to server",
            "Upload selected files to server",
            new ActionListener() {

              @Override
              public void actionPerformed(final ActionEvent e) {
                new Thread() {

                  @Override
                  public void run() {
                    try {
                      upload();
                    } catch (final InstantiationException e) {
                      Log.error(e);
                      error("Could not upload (possibly unknown protocol)");
                    }
                  }
                }.start();
              }
            },
            bottomPanel2);
    upload.setVisible(files.hasUploadableSites());
    enableUploadOrNot();

    final IJ1Plugin fileChanges = IJ1Plugin.discover("fiji.scripting.ShowPluginChanges");
    if (fileChanges != null && files.prefix(".git").isDirectory()) {
      bottomPanel2.add(Box.createRigidArea(new Dimension(15, 0)));
      showChanges =
          SwingTools.button(
              "Show changes",
              "Show the changes in Git since the last upload",
              new ActionListener() {

                @Override
                public void actionPerformed(final ActionEvent e) {
                  new Thread() {

                    @Override
                    public void run() {
                      for (final FileObject file : table.getSelectedFiles())
                        fileChanges.run(file.filename);
                    }
                  }.start();
                }
              },
              bottomPanel2);
    }
    final IJ1Plugin rebuild = IJ1Plugin.discover("fiji.scripting.RunFijiBuild");
    if (rebuild != null && files.prefix(".git").isDirectory()) {
      bottomPanel2.add(Box.createRigidArea(new Dimension(15, 0)));
      rebuildButton =
          SwingTools.button(
              "Rebuild",
              "Rebuild using Fiji Build",
              new ActionListener() {

                @Override
                public void actionPerformed(final ActionEvent e) {
                  new Thread() {

                    @Override
                    public void run() {
                      String list = "";
                      final List<String> names = new ArrayList<String>();
                      for (final FileObject file : table.getSelectedFiles()) {
                        list += ("".equals(list) ? "" : " ") + file.filename + "-rebuild";
                        names.add(file.filename);
                      }
                      if (!"".equals(list)) rebuild.run(list);
                      final Checksummer checksummer =
                          new Checksummer(files, getProgress("Checksumming rebuilt files"));
                      checksummer.updateFromLocal(names);
                      filesChanged();
                      updateFilesTable();
                    }
                  }.start();
                }
              },
              bottomPanel2);
    }

    bottomPanel2.add(Box.createHorizontalGlue());

    bottomPanel.add(Box.createRigidArea(new Dimension(15, 0)));
    easy =
        SwingTools.button(
            "Toggle easy mode",
            "Toggle between easy and verbose mode",
            new ActionListener() {

              @Override
              public void actionPerformed(final ActionEvent e) {
                toggleEasyMode();
              }
            },
            bottomPanel);

    bottomPanel.add(Box.createRigidArea(new Dimension(15, 0)));
    cancel =
        SwingTools.button(
            "Close",
            "Exit Update Manager",
            new ActionListener() {

              @Override
              public void actionPerformed(final ActionEvent e) {
                quit();
              }
            },
            bottomPanel);
    // ======== End: BOTTOM PANEL ========

    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
    getContentPane().add(topPanel);
    getContentPane().add(summaryPanel);
    getContentPane().add(bottomPanel);
    getContentPane().add(bottomPanel2);

    getRootPane().setDefaultButton(apply);

    table.getModel().addTableModelListener(this);

    pack();

    SwingTools.addAccelerator(
        cancel,
        (JComponent) getContentPane(),
        cancel.getActionListeners()[0],
        KeyEvent.VK_ESCAPE,
        0);

    addCustomViewOptions();
  }