Esempio n. 1
0
  /**
   * Show the saved results on the server.
   *
   * @param mysettings jemboss settings
   * @param frameName title name for frame
   */
  public ShowSavedResults(final JembossParams mysettings, final JFrame f) {

    this("Saved results list" + (Jemboss.withSoap ? " on server" : ""));

    try {
      final ResultList reslist = new ResultList(mysettings);
      JMenu resFileMenu = new JMenu("File");
      resMenu.add(resFileMenu);

      final JCheckBoxMenuItem listByProgram = new JCheckBoxMenuItem("List by program");
      listByProgram.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              listByProgramName();
            }
          });
      resFileMenu.add(listByProgram);

      JCheckBoxMenuItem listByDate = new JCheckBoxMenuItem("List by date", true);
      listByDate.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              listByDateRun(reslist, false);
            }
          });
      resFileMenu.add(listByDate);

      ButtonGroup group = new ButtonGroup();
      group.add(listByProgram);
      group.add(listByDate);

      JButton refresh = new JButton(rfii);
      refresh.setMargin(new Insets(0, 1, 0, 1));
      refresh.setToolTipText("Refresh");
      resMenu.add(refresh);

      refresh.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              try {
                setCursor(cbusy);
                ResultList newlist = new ResultList(mysettings);
                setCursor(cdone);
                if (newlist.getStatus().equals("0")) {
                  reslist.updateRes(newlist.hash());
                  datasets.removeAllElements();

                  StringTokenizer tok = new StringTokenizer((String) reslist.get("list"), "\n");
                  while (tok.hasMoreTokens()) datasets.addElement(convertToPretty(tok.nextToken()));

                  if (listByProgram.isSelected()) listByProgramName();
                  else listByDateRun(reslist, false);
                } else {
                  JOptionPane.showMessageDialog(
                      null, newlist.getStatusMsg(), "Soap Error", JOptionPane.ERROR_MESSAGE);
                }
              } catch (JembossSoapException eae) {
                AuthPopup ap = new AuthPopup(mysettings, f);
                ap.setBottomPanel();
                ap.setSize(380, 170);
                ap.pack();
                ap.setVisible(true);
              }
            }
          });

      resFileMenu.addSeparator();
      JMenuItem resFileMenuExit = new JMenuItem("Close");
      resFileMenuExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));

      resFileMenuExit.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              dispose();
            }
          });
      resFileMenu.add(resFileMenuExit);
      setJMenuBar(resMenu);

      // this is the list of saved results
      listByDateRun(reslist, true);

      final JList st = new JList(datasets);
      st.setCellRenderer(new TabListCellRenderer());

      st.addListSelectionListener(
          new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
              if (e.getValueIsAdjusting()) return;

              JList theList = (JList) e.getSource();
              if (theList.isSelectionEmpty()) {
                System.out.println("Empty selection");
              } else {
                int index = theList.getSelectedIndex();
                String thisdata = convertToOriginal(datasets.elementAt(index));
                aboutRes.setText((String) reslist.get(thisdata));
                aboutRes.setCaretPosition(0);
              }
            }
          });

      st.addMouseListener(
          new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
              if (e.getClickCount() == 2) {
                try {
                  setCursor(cbusy);
                  String project = convertToOriginal(st.getSelectedValue());
                  ResultList thisres = new ResultList(mysettings, project, "show_saved_results");
                  new ShowResultSet(thisres.hash(), project, mysettings);
                  setCursor(cdone);
                } catch (JembossSoapException eae) {
                  AuthPopup ap = new AuthPopup(mysettings, f);
                  ap.setBottomPanel();
                  ap.setSize(380, 170);
                  ap.pack();
                  ap.setVisible(true);
                }
              }
            }
          });
      sp.add(st);

      // display retrieves all files and shows them in a window
      JPanel resButtonPanel = new JPanel();
      JButton showResButton = new JButton("Display");
      showResButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              String sel = convertToOriginal(st.getSelectedValue());
              if (sel != null) {
                try {
                  setCursor(cbusy);
                  ResultList thisres = new ResultList(mysettings, sel, "show_saved_results");
                  if (thisres.hash().size() == 0)
                    JOptionPane.showMessageDialog(
                        sp,
                        "This application launch '" + sel + "' didn't produce any result files.");
                  else new ShowResultSet(thisres.hash(), sel, mysettings);
                  setCursor(cdone);
                } catch (JembossSoapException eae) {
                  AuthPopup ap = new AuthPopup(mysettings, f);
                  ap.setBottomPanel();
                  ap.setSize(380, 170);
                  ap.pack();
                  ap.setVisible(true);
                }
              } else {
                statusField.setText("Nothing selected to be displayed.");
              }
            }
          });

      // add a users note for that project
      JButton addNoteButton = new JButton("Edit Notes");
      addNoteButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              String sel = convertToOriginal(st.getSelectedValue());
              if (sel != null) {
                try {
                  setCursor(cbusy);
                  ResultList thisres =
                      new ResultList(mysettings, sel, "Notes", "show_saved_results");
                  new ShowResultSet(thisres.hash(), sel, mysettings);
                  setCursor(cdone);
                } catch (JembossSoapException eae) {
                  AuthPopup ap = new AuthPopup(mysettings, f);
                  ap.setBottomPanel();
                  ap.setSize(380, 170);
                  ap.pack();
                  ap.setVisible(true);
                }
              } else {
                statusField.setText("Selected a project!");
              }
            }
          });

      // delete removes the file on the server & edits the list
      JButton delResButton = new JButton("Delete");
      delResButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              Object sel[] = st.getSelectedValues();
              if (sel != null) {
                String selList = new String("");
                JTextPane delList = new JTextPane();
                FontMetrics fm = delList.getFontMetrics(delList.getFont());
                int maxWidth = 0;
                for (int i = 0; i < sel.length; i++) {
                  if (i == sel.length - 1) selList = selList.concat((String) sel[i]);
                  else selList = selList.concat(sel[i] + "\n");

                  int width = fm.stringWidth((String) sel[i]);
                  if (width > maxWidth) maxWidth = width;
                }
                int ok = JOptionPane.OK_OPTION;
                if (sel.length > 1) {
                  JScrollPane scrollDel = new JScrollPane(delList);
                  delList.setText(selList);
                  delList.setEditable(false);
                  delList.setCaretPosition(0);

                  Dimension d1 = delList.getPreferredSize();
                  int maxHeight = (int) d1.getHeight() + 5;
                  if (maxHeight > 350) maxHeight = 350;
                  else if (maxHeight < 50) maxHeight = 50;

                  scrollDel.setPreferredSize(new Dimension(maxWidth + 30, maxHeight));

                  ok =
                      JOptionPane.showConfirmDialog(
                          null, scrollDel, "Confirm Deletion", JOptionPane.YES_NO_OPTION);
                }
                if (ok == JOptionPane.OK_OPTION) {
                  try // ask the server to delete these results
                  {
                    setCursor(cbusy);
                    selList = convertToOriginal(selList);
                    new ResultList(mysettings, selList, "delete_saved_results");
                    setCursor(cdone);

                    // amend the list
                    for (int i = 0; i < sel.length; i++) datasets.removeElement(sel[i]);

                    statusField.setText("Deleted " + sel.length + "  result(s)");

                    aboutRes.setText("");
                    st.setSelectedIndex(-1);
                  } catch (JembossSoapException eae) {
                    AuthPopup ap = new AuthPopup(mysettings, f);
                    ap.setBottomPanel();
                    ap.setSize(380, 170);
                    ap.pack();
                    ap.setVisible(true);
                  }
                }
              } else {
                statusField.setText("Nothing selected for deletion.");
              }
            }
          });
      resButtonPanel.add(delResButton);
      resButtonPanel.add(addNoteButton);
      resButtonPanel.add(showResButton);
      resButtonStatus.add(resButtonPanel, BorderLayout.CENTER);
      resButtonStatus.add(statusField, BorderLayout.SOUTH);

      Container c = getContentPane();
      c.add(ss, BorderLayout.WEST);
      c.add(aboutScroll, BorderLayout.CENTER);
      c.add(resButtonStatus, BorderLayout.SOUTH);
      pack();

      setVisible(true);
    } catch (JembossSoapException eae) {
      AuthPopup ap = new AuthPopup(mysettings, f);
      ap.setBottomPanel();
      ap.setSize(380, 170);
      ap.pack();
      ap.setVisible(true);
    }
  }
Esempio n. 2
0
  /**
   * Show the results sent to a batch queue.
   *
   * @param mysettings jemboss settings
   * @param epr pending results
   * @throws JembossSoapException when server connection fails
   */
  public ShowSavedResults(final JembossParams mysettings, final PendingResults epr)
      throws JembossSoapException {
    this("Current Sessions Results");

    Dimension d = new Dimension(270, 100);
    ss.setPreferredSize(d);
    //  ss.setMaximumSize(d);

    JMenu resFileMenu = new JMenu("File");
    resMenu.add(resFileMenu);

    JButton refresh = new JButton(rfii);
    refresh.setMargin(new Insets(0, 1, 0, 1));
    refresh.setToolTipText("Refresh");
    resMenu.add(refresh);
    refresh.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setCursor(cbusy);
            epr.updateStatus();
            setCursor(cdone);
            datasets.removeAllElements();
            Enumeration enumer = epr.descriptionHash().keys();
            while (enumer.hasMoreElements()) {
              String image = convertToPretty((String) enumer.nextElement());
              datasets.addElement(image);
            }
          }
        });

    JMenuItem resFileMenuExit = new JMenuItem("Close");
    resFileMenuExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));

    resFileMenuExit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });
    resFileMenu.add(resFileMenuExit);
    setJMenuBar(resMenu);

    // set up the results list in the gui
    Enumeration enumer = epr.descriptionHash().keys();
    while (enumer.hasMoreElements())
      datasets.addElement(convertToPretty((String) enumer.nextElement()));

    final JList st = new JList(datasets);
    st.setCellRenderer(new TabListCellRenderer());
    st.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) return;

            JList theList = (JList) e.getSource();
            if (!theList.isSelectionEmpty()) {
              int index = theList.getSelectedIndex();
              String thisdata = convertToOriginal(datasets.elementAt(index));
              aboutRes.setText((String) epr.descriptionHash().get(thisdata));
              aboutRes.setCaretPosition(0);
              aboutRes.setEditable(false);
            }
          }
        });

    st.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
              try {
                setCursor(cbusy);
                String project = convertToOriginal(st.getSelectedValue());
                ResultList thisres = new ResultList(mysettings, project, "show_saved_results");
                setCursor(cdone);
                if (thisres.getStatus().equals("0"))
                  new ShowResultSet(thisres.hash(), project, mysettings);
                else
                  JOptionPane.showMessageDialog(
                      null, thisres.getStatusMsg(), "Soap Error", JOptionPane.ERROR_MESSAGE);

              } catch (JembossSoapException eae) {
                AuthPopup ap = new AuthPopup(mysettings, null);
                ap.setBottomPanel();
                ap.setSize(380, 170);
                ap.pack();
                ap.setVisible(true);
              }
            }
          }
        });
    sp.add(st);

    // display retrieves all the files and shows them in a window

    JPanel resButtonPanel = new JPanel();
    JButton showResButton = new JButton("Display");
    showResButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (st.getSelectedValue() != null) {
              try {
                setCursor(cbusy);
                String project = convertToOriginal(st.getSelectedValue());
                ResultList thisres = new ResultList(mysettings, project, "show_saved_results");
                setCursor(cdone);
                if (thisres.getStatus().equals("0"))
                  new ShowResultSet(thisres.hash(), project, mysettings);
                else
                  JOptionPane.showMessageDialog(
                      null, thisres.getStatusMsg(), "Soap Error", JOptionPane.ERROR_MESSAGE);
              } catch (JembossSoapException eae) {
                setCursor(cdone);
                AuthPopup ap = new AuthPopup(mysettings, null);
                ap.setBottomPanel();
                ap.setSize(380, 170);
                ap.pack();
                ap.setVisible(true);
              }
            }
          }
        });

    // delete removes the file on the server and edits the list
    JButton delResButton = new JButton("Delete");
    delResButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Object sel[] = st.getSelectedValues();
            if (sel != null) {
              String selList = new String("");
              for (int i = 0; i < sel.length; i++) selList = selList.concat(sel[i] + "\n");

              int ok = JOptionPane.OK_OPTION;
              if (sel.length > 1)
                ok =
                    JOptionPane.showConfirmDialog(
                        null,
                        "Delete the following results:\n" + selList,
                        "Confirm Deletion",
                        JOptionPane.YES_NO_OPTION);

              if (ok == JOptionPane.OK_OPTION) {

                try {
                  setCursor(cbusy);
                  selList = convertToOriginal(selList);
                  new ResultList(mysettings, selList, "delete_saved_results");
                  setCursor(cdone);

                  for (int i = 0; i < sel.length; i++) {
                    JembossProcess jp = epr.getResult(convertToOriginal(sel[i]));
                    epr.removeResult(jp);
                    datasets.removeElement(sel[i]); // amend the list
                  }
                  statusField.setText("Deleted " + sel.length + "  result(s)");
                  aboutRes.setText("");
                  st.setSelectedIndex(-1);
                } catch (JembossSoapException eae) {
                  // shouldn't happen
                  AuthPopup ap = new AuthPopup(mysettings, null);
                  ap.setBottomPanel();
                  ap.setSize(380, 170);
                  ap.pack();
                  ap.setVisible(true);
                }
              }
            }
          }
        });
    resButtonPanel.add(delResButton);
    resButtonPanel.add(showResButton);
    resButtonStatus.add(resButtonPanel, BorderLayout.CENTER);
    resButtonStatus.add(statusField, BorderLayout.SOUTH);

    Container c = getContentPane();
    c.add(ss, BorderLayout.WEST);
    c.add(aboutScroll, BorderLayout.CENTER);
    c.add(resButtonStatus, BorderLayout.SOUTH);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    pack();
    setVisible(true);

    // add in automatic updates
    String freq = (String) AdvancedOptions.jobMgr.getSelectedItem();
    int ind = freq.indexOf(" ");
    new ResultsUpdateTimer(Integer.parseInt(freq.substring(0, ind)), datasets, this);
    statusField.setText("Window refresh rate " + freq);
  }