Esempio n. 1
0
  // ask user for script file and name of new profile
  // return false if user cancelled operation
  private boolean getNewWkldInput(
      JFileChooser chooser, Object[] optionDlgMsg, StringBuffer name, StringBuffer scriptFile) {
    // let user select script file with queries
    boolean fileOk = false;
    int retval;
    File file = null;
    FileReader reader = null;
    while (!fileOk) {
      if ((retval = chooser.showDialog(this, "Ok")) != 0) {
        return false;
      }
      file = chooser.getSelectedFile();
      try {
        reader = new FileReader(file.getPath());
        fileOk = true;
        scriptFile.append(file.getPath());
      } catch (FileNotFoundException e) {
        JOptionPane.showMessageDialog(
            this,
            "Selected script file does not exist",
            "Error: New Profile",
            JOptionPane.ERROR_MESSAGE);
      }
    }

    // let user select filename for profile
    int response =
        JOptionPane.showOptionDialog(
            this,
            optionDlgMsg,
            "New Profile",
            JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE,
            null,
            null,
            null);
    if (response != JOptionPane.OK_OPTION) {
      return false;
    }
    JTextField textFld = (JTextField) optionDlgMsg[1];
    name.append(file.getParent() + "/" + textFld.getText());
    return true;
  }
Esempio n. 2
0
  private void createOpsMenu() {
    opsMenu = new JMenu("Ops");
    menuBar.add(opsMenu);

    insertItem = new JMenuItem("Insert...");
    opsMenu.add(insertItem);
    final Object[] insertMsg = new Object[4];
    insertMsg[0] = "Key:";
    final JTextField insertKey = new JTextField("");
    insertMsg[1] = insertKey;
    insertMsg[2] = "Data:";
    final JTextField insertData = new JTextField("");
    insertMsg[3] = insertData;
    insertItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            int response =
                JOptionPane.showOptionDialog(
                    MainWindow.this,
                    insertMsg,
                    "Insert",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    null,
                    null);
            if (response != JOptionPane.OK_OPTION) {
              return;
            }

            // insert new item
            cmd.reset();
            cmd.cmdType = LibgistCommand.INSERT;
            cmd.key.append(insertKey.getText());
            cmd.data.append(insertData.getText());
            opThread.dispatchCmd(cmd);
          }
        });

    deleteItem = new JMenuItem("Delete...");
    opsMenu.add(deleteItem);
    final Object[] deleteMsg = new Object[2];
    deleteMsg[0] = "Query:";
    final JTextField deleteQuery = new JTextField("");
    deleteMsg[1] = deleteQuery;
    deleteItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            int response =
                JOptionPane.showOptionDialog(
                    MainWindow.this,
                    deleteMsg,
                    "Delete",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    null,
                    null);
            if (response != JOptionPane.OK_OPTION) {
              return;
            }

            // delete item(s)
            cmd.reset();
            cmd.cmdType = LibgistCommand.REMOVE;
            cmd.qual.append(deleteQuery.getText());
            opThread.dispatchCmd(cmd);
          }
        });

    searchItem = new JMenuItem("Search...");
    opsMenu.add(searchItem);
    final Object[] searchMsg = new Object[4];
    searchMsg[0] = "Query:";
    final JTextField searchQuery = new JTextField("");
    searchMsg[1] = searchQuery;
    searchMsg[2] = "Retrieval Limit:";
    final JTextField retrLimit = new JTextField("");
    searchMsg[3] = retrLimit;
    searchItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            int response =
                JOptionPane.showOptionDialog(
                    MainWindow.this,
                    searchMsg,
                    "Search",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    null,
                    null);
            if (response != JOptionPane.OK_OPTION) {
              return;
            }
            int limit = 0; // 0 means "get them all"
            // if no limit is specified: we leave it at 0
            if (retrLimit.getText() != null) {
              try {
                limit = Integer.parseInt(retrLimit.getText());
              } catch (NumberFormatException e) {
                // user typed junk
                limit = 0;
                retrLimit.setText("");
              }
            }

            // execute query
            cmd.reset();
            cmd.cmdType = LibgistCommand.FETCH;
            cmd.qual.append(searchQuery.getText());
            cmd.fetchLimit = limit;
            opThread.dispatchCmd(cmd);
          }
        });

    executeItem = new JMenuItem("Execute...");
    final JFileChooser executeChooser = new JFileChooser(".");
    executeChooser.setDialogTitle("Execute Script");
    executeChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    opsMenu.add(executeItem);
    executeItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            // let user choose script file
            int retval = executeChooser.showDialog(MainWindow.this, "Execute");
            if (retval != 0) {
              return;
            }

            // execute script
            cmd.reset();
            cmd.cmdType = LibgistCommand.SCRIPT;
            cmd.scriptFile.append(executeChooser.getSelectedFile().getPath());
            opThread.dispatchCmd(cmd);
          }
        });
  }
Esempio n. 3
0
  private void createFileMenu() {
    fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    newItem = new JMenuItem("New...");
    fileMenu.add(newItem);
    // construct components of option pane to input name and type of new AM
    final Object[] newMsg = new Object[3];
    newMsg[0] = "Name for new AM:";
    final JTextField newName = new JTextField("new-am");
    newMsg[1] = newName;
    final JComboBox cb = new JComboBox();
    for (int i = 0; i < Libgist.extInfo.length; i++) {
      cb.addItem(Libgist.extInfo[i].name);
    }
    newMsg[2] = cb;
    newItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // first close the currently opened index
            int response =
                JOptionPane.showOptionDialog(
                    MainWindow.this,
                    newMsg,
                    "New",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    null,
                    null);
            if (response != JOptionPane.OK_OPTION) {
              return;
            }

            // create new AM
            cmd.reset();
            cmd.cmdType = LibgistCommand.CREATE;
            cmd.indexName.append(newName.getText());
            cmd.extension.append(Libgist.extInfo[cb.getSelectedIndex()]);
            opThread.dispatchCmd(cmd);
          }
        });

    openItem = new JMenuItem("Open...");
    final JFileChooser openChooser = new JFileChooser(".");
    openChooser.setDialogTitle("Open Index");
    openChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileMenu.add(openItem);
    openItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            // first close currently opened index
            // let user choose index file
            int retval = openChooser.showOpenDialog(MainWindow.this);
            if (retval != 0) {
              return;
            }
            String fileName = openChooser.getSelectedFile().getPath();

            // open AM
            cmd.reset();
            cmd.cmdType = LibgistCommand.OPEN;
            cmd.indexName.append(fileName);
            opThread.dispatchCmd(cmd);

            enableIndexOpened();
          }
        });

    closeItem = new JMenuItem("Close");
    fileMenu.add(closeItem);
    closeItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            // close AM
            cmd.reset();
            cmd.cmdType = LibgistCommand.CLOSE;
            opThread.dispatchCmd(cmd);
            // MainWindow.this.setTitle("amdb");
          }
        });

    flushItem = new JMenuItem("Flush");
    fileMenu.add(flushItem);
    flushItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            // open AM
            cmd.reset();
            cmd.cmdType = LibgistCommand.FLUSH;
            opThread.dispatchCmd(cmd);
          }
        });

    fileMenu.addSeparator();

    optionsItem = new JMenuItem("Properties...");
    fileMenu.add(optionsItem);
    optionsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Properties.edit();
          }
        });

    settingsItem = new JMenuItem("Save Settings");
    fileMenu.add(settingsItem);
    settingsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            saveConfig();
          }
        });
    fileMenu.addSeparator();
    exitItem = new JMenuItem("Exit");
    fileMenu.add(exitItem);
    exitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // close AM
            opThread.stopNow();
            Libgist.cleanup();
            System.exit(0);
          }
        });
  }
Esempio n. 4
0
  private void createAnalysisMenu() {
    analysisMenu = new JMenu("Analysis");
    menuBar.add(analysisMenu);

    // analysis-related variables
    analysisInfo = new AnalysisInfo();
    wkldStatsDlg = new WkldStatsDlg(this);
    splitStatsDlg = new SplitStatsDlg(this);
    penaltyStatsDlg = new PenaltyStatsDlg(this);

    newAnalysisItem = new JMenuItem("Create Analysis ...");
    analysisMenu.add(newAnalysisItem);
    newAnalysisItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            JOptionPane.showMessageDialog(
                MainWindow.this,
                "Not implemented yet.\nUse command createanl in gistcmdline instead.");
          }
        });

    openAnalysisItem = new JMenuItem("Open Analysis ...");
    final JFileChooser openAnalysisChooser = new JFileChooser(".");
    openAnalysisChooser.setDialogTitle("Open Analysis");
    openAnalysisChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    analysisMenu.add(openAnalysisItem);
    openAnalysisItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            int retval = openAnalysisChooser.showOpenDialog(MainWindow.this);
            if (retval != 0) {
              return;
            }
            File f = openAnalysisChooser.getSelectedFile();

            cmd.reset();
            cmd.cmdType = LibgistCommand.OPENANL;
            cmd.analysisFile = f;
            opThread.dispatchCmd(cmd);
          }
        });

    completeAnalysisItem = new JMenuItem("Complete Analysis ...");
    analysisMenu.add(completeAnalysisItem);
    completeAnalysisItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            JOptionPane.showMessageDialog(
                MainWindow.this,
                "Not implemented yet.\nUse commands wkldstats, splitstats and penaltystats\nin gistcmdline instead.");
          }
        });

    analysisMenu.addSeparator();

    wkldStatsItem = new JMenuItem("Workload Stats ...");
    analysisMenu.add(wkldStatsItem);
    wkldStatsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            wkldStatsDlg.setVisible(true);
          }
        });

    splitStatsItem = new JMenuItem("Split Stats ...");
    analysisMenu.add(splitStatsItem);
    wkldStatsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            splitStatsDlg.setVisible(true);
          }
        });

    penaltyStatsItem = new JMenuItem("Penalty Stats ...");
    analysisMenu.add(penaltyStatsItem);
    penaltyStatsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            penaltyStatsDlg.setVisible(true);
          }
        });
  }