public void saveLog() {
   File file = new File("." + File.separator);
   String logFile = null;
   try {
     logFile =
         RapidMinerGUI.getMainFrame()
             .getProcess()
             .getRootOperator()
             .getParameterAsString(ProcessRootOperator.PARAMETER_LOGFILE);
   } catch (UndefinedParameterError ex) {
     // tries to use process file name for initialization
   }
   if (logFile != null) {
     file = RapidMinerGUI.getMainFrame().getProcess().resolveFileName(logFile);
   }
   file = SwingTools.chooseFile(RapidMinerGUI.getMainFrame(), file, false, "log", "log file");
   if (file != null) {
     PrintWriter out = null;
     try {
       out = new PrintWriter(new FileWriter(file));
       out.println(textArea.getText());
     } catch (IOException ex) {
       SwingTools.showSimpleErrorMessage("cannot_write_log_file", ex);
     } finally {
       if (out != null) {
         out.close();
       }
     }
   }
 }
 /**
  * If the thread is currently active, calls {@link #executionCancelled()} to notify children. If
  * not active, removes the thread from the queue so it won't become active.
  */
 public final void cancel() {
   boolean dependentThreads = false;
   synchronized (LOCK) {
     dependentThreads = checkQueuedThreadDependOnCurrentThread();
   }
   if (dependentThreads) {
     if (ConfirmDialog.OK_OPTION
         != SwingTools.showConfirmDialog(
             "cancel_pg_with_dependencies", ConfirmDialog.OK_CANCEL_OPTION)) {
       return;
     } else {
       synchronized (LOCK) {
         removeQueuedThreadsWithDependency(getID());
       }
     }
   }
   synchronized (LOCK) {
     cancelled = true;
     if (started) {
       executionCancelled();
       currentThreads.remove(this);
     } else {
       // cancel and not started? Can only be in queue
       queuedThreads.remove(this);
     }
   }
   taskCancelled(this);
 }
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();
 }
  public void addTabI18N(String key, Component component, String... i18nArgs) {
    String name;
    if (i18nArgs != null && i18nArgs.length > 0) {
      name = formatMessage(key, "label", i18nArgs);
    } else {
      name = getMessage(key, "label");
    }
    Icon icon = null;
    String iconName = getMessageOrNull(key, "icon");
    if (iconName != null) {
      icon = SwingTools.createIcon((isLargeIcons() ? "24/" : "16/") + iconName);
    }
    addTab(name, icon, component);
    int index = getTabCount() - 1;

    String tip;
    if (i18nArgs != null && i18nArgs.length > 0) {
      tip = formatMessage(key, "tip", i18nArgs);
    } else {
      tip = getMessageOrNull(key, "tip");
    }
    if (tip != null) {
      setToolTipTextAt(index, tip);
    }

    // try to look up and set mnemonic
    String mne = getMessageOrNull(key, "mne");
    if (mne != null) {
      mne = mne.toUpperCase();
      if (name.indexOf(mne.charAt(0)) == -1) {
        if (name.indexOf(mne.toUpperCase().charAt(0)) != -1) {
          mne = mne.toUpperCase();
          LogService.getRoot()
              .warning(
                  "Mnemonic key "
                      + mne
                      + " not found for tab "
                      + i18KeyPrefix
                      + "."
                      + key
                      + " ("
                      + name
                      + "), converting to upper case.");
        }
      }
      setMnemonicAt(index, mne.charAt(0));
    }
  }
  private synchronized void append(LogRecord record) {
    Document doc = textArea.getStyledDocument();
    String formatted = formatter.format(record);

    if (record.getLevel().intValue() >= Level.SEVERE.intValue()) {
      StyleConstants.setForeground(attributeSet, COLOR_ERROR);
      StyleConstants.setBold(attributeSet, true);
    } else if (record.getLevel().intValue() >= Level.WARNING.intValue()) {
      StyleConstants.setForeground(attributeSet, COLOR_WARNING);
      StyleConstants.setBold(attributeSet, true);
    } else if (record.getLevel().intValue() >= Level.INFO.intValue()) {
      StyleConstants.setForeground(attributeSet, COLOR_INFO);
      StyleConstants.setBold(attributeSet, false);
    } else {
      StyleConstants.setForeground(attributeSet, COLOR_DEFAULT);
      StyleConstants.setBold(attributeSet, false);
    }

    try {
      doc.insertString(doc.getLength(), formatted, attributeSet);
    } catch (BadLocationException e) {
      // cannot happen
      // rather dump to stderr than logging and having this method called back
      e.printStackTrace();
    }

    if (maxRows >= 0) {
      int removeLength = 0;
      while (lineLengths.size() > maxRows) {
        removeLength += lineLengths.removeFirst();
      }
      try {
        doc.remove(0, removeLength);
      } catch (BadLocationException e) {
        SwingTools.showSimpleErrorMessage("error_during_logging", e);
      }
    }
    textArea.setCaretPosition(textArea.getDocument().getLength());
  }
Exemplo n.º 7
0
 public void info(final String message) {
   SwingTools.showMessageBox(this, message, JOptionPane.INFORMATION_MESSAGE);
 }
Exemplo n.º 8
0
 public void warn(final String message) {
   SwingTools.showMessageBox(this, message, JOptionPane.WARNING_MESSAGE);
 }
Exemplo n.º 9
0
 public void error(final String message) {
   SwingTools.showMessageBox(this, message, JOptionPane.ERROR_MESSAGE);
 }
Exemplo n.º 10
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();
  }