Exemplo n.º 1
0
  public void updateTheUpdater() {
    final FilesCollection.Filter filter =
        new FilesCollection.Filter() {

          @Override
          public boolean matches(final FileObject file) {
            if (file.filename.equals("jars/ij-updater-core.jar")) {
              file.setAction(files, Action.UPDATE);
              return true;
            }
            return false;
          }
        };
    final FilesCollection justTheUpdater = files.clone(files.filter(filter));
    final Installer installer =
        new Installer(justTheUpdater, getProgress("Installing the updater..."));
    try {
      installer.start();
    } catch (final Canceled e) {
      // TODO: remove "update/" directory
      error("Canceled");
      installer.done();
    } catch (final IOException e) {
      // TODO: remove "update/" directory
      error("Installer failed: " + e);
      installer.done();
    }
  }
Exemplo n.º 2
0
  public void addCustomViewOptions() {
    viewOptions.clearCustomOptions();

    final Collection<String> names = files.getUpdateSiteNames();
    if (names.size() > 1)
      for (final String name : names)
        viewOptions.addCustomOption(
            "View files of the '" + name + "' site", files.forUpdateSite(name));
  }
Exemplo n.º 3
0
  protected void upload() throws InstantiationException {
    final ResolveDependencies resolver = new ResolveDependencies(this, files, true);
    if (!resolver.resolve()) return;

    final String errors = files.checkConsistency();
    if (errors != null) {
      error(errors);
      return;
    }

    final List<String> possibleSites = new ArrayList<String>(files.getSiteNamesToUpload());
    if (possibleSites.size() == 0) {
      error("Huh? No upload site?");
      return;
    }
    String updateSiteName;
    if (possibleSites.size() == 1) updateSiteName = possibleSites.get(0);
    else {
      updateSiteName =
          SwingTools.getChoice(
              this, possibleSites, "Which site do you want to upload to?", "Update site");
      if (updateSiteName == null) return;
    }
    final FilesUploader uploader = new FilesUploader(files, updateSiteName);

    Progress progress = null;
    try {
      if (!uploader.login()) return;
      progress = getProgress("Uploading...");
      uploader.upload(progress);
      for (final FileObject file : files.toUploadOrRemove())
        if (file.getAction() == Action.UPLOAD) {
          file.markUploaded();
          file.setStatus(Status.INSTALLED);
        } else {
          file.markRemoved();
          file.setStatus(Status.OBSOLETE_UNINSTALLED);
        }
      updateFilesTable();
      canUpload = false;
      files.write();
      info("Uploaded successfully.");
      enableUploadOrNot();
      dispose();
    } catch (final Canceled e) {
      // TODO: teach uploader to remove the lock file
      error("Canceled");
      if (progress != null) progress.done();
    } catch (final Throwable e) {
      UpdaterUserInterface.get().handleException(e);
      error("Upload failed: " + e);
      if (progress != null) progress.done();
    }
  }
Exemplo n.º 4
0
 private void quit() {
   if (files.hasChanges()) {
     if (!SwingTools.showQuestion(
         this, "Quit?", "You have specified changes. Are you sure you want to quit?")) return;
   } else
     try {
       files.write();
     } catch (final Exception e) {
       error("There was an error writing the local metadata cache: " + e);
     }
   dispose();
 }
Exemplo n.º 5
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.º 6
0
 // checkWritable() is guaranteed to be called after Checksummer ran
 public void checkWritable() {
   String list = null;
   for (final FileObject object : files) {
     final File file = files.prefix(object);
     if (!file.exists() || file.canWrite()) continue;
     if (list == null) list = object.getFilename();
     else list += ", " + object.getFilename();
   }
   if (list != null)
     UpdaterUserInterface.get()
         .info(
             "WARNING: The following files are set to read-only: '" + list + "'",
             "Read-only files");
 }
Exemplo n.º 7
0
  public void updateFilesTable() {
    Iterable<FileObject> view = viewOptions.getView(table);
    final Set<FileObject> selected = new HashSet<FileObject>();
    for (final FileObject file : table.getSelectedFiles()) selected.add(file);
    table.clearSelection();

    final String search = searchTerm.getText().trim();
    if (!search.equals("")) view = FilesCollection.filter(search, view);

    // Directly update the table for display
    table.setFiles(view);
    for (int i = 0; i < table.getRowCount(); i++)
      if (selected.contains(table.getFile(i))) table.addRowSelectionInterval(i, i);
  }
Exemplo n.º 8
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.º 9
0
 public void install() {
   final Installer installer = new Installer(files, getProgress("Installing..."));
   try {
     installer.start();
     updateFilesTable();
     filesChanged();
     files.write();
     info("Updated successfully.  Please restart ImageJ!");
     dispose();
   } catch (final Canceled e) {
     // TODO: remove "update/" directory
     error("Canceled");
     installer.done();
   } catch (final Exception e) {
     Log.error(e);
     // TODO: remove "update/" directory
     error("Installer failed: " + e);
     installer.done();
   }
 }
Exemplo n.º 10
0
 void enableUploadOrNot() {
   upload.setVisible(!easyMode && files.hasUploadableSites());
   upload.setEnabled(canUpload || files.hasUploadOrRemove());
 }
Exemplo n.º 11
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();
  }