Exemplo n.º 1
0
 public void valueChanged(ListSelectionEvent e) {
   if (!e.getValueIsAdjusting()) {
     if (userInputListener.isModified()) {
       // the user has modified the config, but not stored it
       int decision =
           JOptionPane.showConfirmDialog(
               this,
               "The configuration for project '"
                   + selectedProjectName
                   + "' has unsaved changes. Do you wish to save them?",
               "Save Changes?",
               JOptionPane.YES_NO_CANCEL_OPTION);
       if (decision == JOptionPane.YES_OPTION) { // store
         try {
           storeConfig(false);
         } catch (Exception ex) {
           Main.fatalError(ex);
         }
       }
       if (decision == JOptionPane.CANCEL_OPTION) {
         selection.removeListSelectionListener(this);
         selection.setSelectedValue(selectedProjectName, true);
         selection.addListSelectionListener(this);
         return;
       }
     }
     selectedProjectName = (String) selection.getSelectedValue();
     generateGUIGonfiguration(selectedProjectName);
     generateGUIDescription(selectedProjectName);
   }
 }
Exemplo n.º 2
0
  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {
    if (e.getSource().equals(saveConfig)
        || e.getSource()
            .equals(
                saveConfig2)) { // --------------------------------------------------------------------
      if (selection.getSelectedValue() == null) {
        JOptionPane.showMessageDialog(
            this,
            "Please select a project from the selection.",
            "No project selected.",
            JOptionPane.ERROR_MESSAGE);
      } else
        try {
          storeConfig(false);
        } catch (Exception ex) {
          Main.fatalError(ex);
        }
    } else if (e.getSource()
        .equals(ok)) { // --------------------------------------------------------------------
      if (selection.getSelectedValue() == null) {
        JOptionPane.showMessageDialog(
            this,
            "Please select a project from the selection.",
            "No project selected.",
            JOptionPane.ERROR_MESSAGE);
      } else {
        if (userInputListener.isModified()) {
          // the user has modified the config, but not stored it
          int decision =
              JOptionPane.showConfirmDialog(
                  this,
                  "The modifications to this configuration have not yet been saved.\n\nDo you want to store this configuration, such that it is also available for subsequent runs?",
                  "Unsaved modifications",
                  JOptionPane.YES_NO_CANCEL_OPTION);
          if (decision == JOptionPane.YES_OPTION) { // store
            try {
              storeConfig(false);
            } catch (Exception ex) {
              Main.fatalError(ex);
            }
          }
          if (decision == JOptionPane.CANCEL_OPTION) {
            return; // don't do anything
          }
        }

        Document customDoc = validateCustomFields();
        if (customDoc == null) { // there is invalid xml in the custom entry
          return;
        }

        if (!selectedProjectName.equals("defaultProject")) {
          Global.projectName = selectedProjectName;
          Global.useProject = true;
          appConfig.lastChosenProject = Global.projectName;
        }

        Element customEle = customDoc.getRootElement().getChild("Custom");
        XMLParser.parseCustom(customEle, "");

        setFrameworkConfig();

        // Block the overwriting of the now set values.
        XMLParser.blockParse = true;

        this.setVisible(false);

        // reset the tooltip dismiss delay to the default value
        ToolTipManager.sharedInstance().setDismissDelay(defaultTooltipDismissDelay);

        appConfig.projectSelectorSelectedTab = 1 + right.getSelectedIndex();
        appConfig
            .writeConfig(); // write the config, s.t. when the main application crashes, at least
                            // the project selector config is preserved
        storeConfig(true); // store the config to a file s.t. the simulation process can read it

        // wake up the waiting object.
        synchronized (main) {
          main.notify();
        }
      }
    } else if (e.getSource()
        .equals(cancel)) { // --------------------------------------------------------------------
      if (userInputListener.isModified()) {
        // the user has modified the config, but not stored it
        int decision =
            JOptionPane.showConfirmDialog(
                this,
                "The configuration for project '"
                    + selectedProjectName
                    + "' has unsaved changes. Do you wish to save them?",
                "Save Changes?",
                JOptionPane.YES_NO_CANCEL_OPTION);
        if (decision == JOptionPane.YES_OPTION) { // store
          try {
            storeConfig(false);
          } catch (Exception ex) {
            Main.fatalError(ex);
          }
        }
        if (decision == JOptionPane.CANCEL_OPTION) {
          return;
        }
      }
      appConfig.projectSelectorSelectedTab = 1 + right.getSelectedIndex();
      appConfig.writeConfig();
      System.exit(1);
    } else if (e.getSource()
        .equals(collapse)) { // --------------------------------------------------------------------
      showOptionalFields = false;
      insertProjectEntries();
      this.repaint();
    } else if (e.getSource()
        .equals(expand)) { // --------------------------------------------------------------------
      showOptionalFields = true;
      insertProjectEntries();
      this.repaint();
    }
  }