Esempio n. 1
0
  private TrialDialog(final WizardUI parent) {
    super(parent, UIMessages.getMessage(UIMessages.UI_TRIAL_TITLE), true);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    String strMsg = null;
    try {
      strMsg =
          Util.readStream(
              UIMessages.class.getResourceAsStream(UIMessages.getMessage(UIMessages.RSRC_TRIAL)));
    } catch (IOException e) {
      strMsg = UIMessages.getMessage(UIMessages.ERR_TRIAL_LOAD);
    }

    // Label for trial info
    // The HTML must constrain the width, or the label lays it out too wide
    // XXX http://developer.java.sun.com/developer/bugParade/bugs/4348815.html
    JLabel lblMsg = new JLabel(strMsg);

    // Link to purchase
    HyperLabel lblPurchase =
        new HyperLabel(
            UIMessages.getMessage(UIMessages.UI_LABEL_PURCHASE),
            UIMessages.getMessage(UIMessages.URL_PURCHASE));

    // Link to register
    HyperLabel lblRegister =
        new HyperLabel(
            UIMessages.getMessage(UIMessages.UI_LABEL_REGISTER), parent.getRegistrationURL());

    // Button to enter license
    JButton btnLicense = new JButton(UIMessages.getMessage(UIMessages.UI_BUTTON_TRIAL_LICENSE));
    btnLicense.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            parent.showLicenseDialog(TrialDialog.this);
          }
        });

    // OK button
    JButton btnOK = new JButton(UIMessages.getMessage(UIMessages.UI_BUTTON_OK));
    btnOK.addActionListener(new DisposeHandler(this));

    // Lay it all out
    Container panel = getContentPane();
    panel.setLayout(new GridBagLayout());
    WizardGBC gbc = new WizardGBC();

    gbc.reset();
    gbc.fill = gbc.BOTH;
    gbc.weightx = 1;
    gbc.weighty = 1;
    gbc.gridwidth = 2;
    gbc.insets.top = gbc.insets.left = gbc.insets.right = 5;
    panel.add(lblMsg, gbc);

    gbc.reset();
    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.anchor = gbc.WEST;
    gbc.weightx = 1;
    gbc.insets.top = gbc.insets.left = 5;
    panel.add(lblRegister, gbc);

    gbc.reset();
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.insets.top = gbc.insets.right = 5;
    panel.add(lblPurchase, gbc);

    gbc.reset();
    gbc.gridx = 1;
    gbc.gridy = 2;
    gbc.insets.top = gbc.insets.right = 5;
    panel.add(btnLicense, gbc);

    gbc.reset();
    gbc.gridy = 3;
    gbc.fill = gbc.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridwidth = 2;
    gbc.insets.top = 10;
    panel.add(new JSeparator(), gbc);

    gbc.reset();
    gbc.gridy = 4;
    gbc.anchor = gbc.CENTER;
    gbc.gridwidth = 2;
    gbc.insets.top = gbc.insets.bottom = 10;
    panel.add(btnOK, gbc);

    pack();
  }
  /**
   * Checks conditions and starts the algorithm.
   *
   * @param evt
   */
  private void runButtonActionPerformed(java.awt.event.ActionEvent evt) {
    if (this.projectComboBox.getSelectedItem().equals("")) {
      UIMessages.showErrorMessage("Please select a project", "Error");
      return;
    }

    if (this.traitSetComboBox.getSelectedIndex() < 0) {
      UIMessages.showErrorMessage("Please select a trait option", "Error");
      return;
    }

    String projectName = projectComboBox.getSelectedItem().toString();
    String traitName = traitSetComboBox.getSelectedItem().toString();
    String markerName = markerSetComboBox.getSelectedItem().toString();
    Project ap = Model.getInstance().getProject(projectName);
    TraitSet ts = ap.getTrait(traitName);
    MarkerSet ms = ap.getMarker(markerName);
    if (this.algorithmComboBox.getSelectedIndex() < 0
        && !this.loadAssociationRadioButton.isSelected()) {
      UIMessages.showErrorMessage("Please select an algorithm", "Error");
      return;
    }

    if (this.algorithmComboBox.getSelectedItem().equals("Adaptive Multi-Task Lasso")) {
      ArrayList<String> where = new ArrayList<String>();
      where.add("markersetid = " + ms.getId());
      if (Integer.parseInt(
              DataManager.runSelectQuery("count(*)", "feature", true, where, null).get(0))
          < 1) {
        UIMessages.showErrorMessage("Selected marker set does not have features", "Error");
        return;
      }
    }

    if (this.markerSetComboBox.getSelectedIndex() < 0) {
      UIMessages.showErrorMessage("Please select a marker", "Error");
      return;
    }

    if (this.networkComboBox.getSelectedIndex() < 0 && this.networkComboBox.isEnabled()) {
      UIMessages.showErrorMessage(
          "Please select a valid network option for selected algorithm", "Error");
      return;
    }

    if (this.networkComboBox.getSelectedIndex() < 0 && this.networkComboBox.isEnabled()) {
      UIMessages.showErrorMessage(
          "Please select a valid Population option for selected algorithm", "Error");
      return;
    }

    if (this.numberComboBox.isEnabled() && this.numberComboBox.getSelectedIndex() < 0) {
      UIMessages.showErrorMessage(
          "Please select a valid Population option for this algorithm", "Error");
      return;
    }
    if (this.nameTextField.getText().equals("")) {
      UIMessages.showErrorMessage("Please specify a valid name", "Error");
      return;
    }

    if (Model.getInstance()
        .getProject(projectComboBox.getSelectedItem().toString())
        .isAssocNamePresentInProject(this.nameTextField.getText())) {
      UIMessages.showErrorMessage("Specified name already exists for this project", "Error");
      return;
    }

    String networkName = this.networkComboBox.getSelectedItem().toString();
    String algoName = this.algorithmComboBox.getSelectedItem().toString();

    String popno = this.numberComboBox.getSelectedItem().toString();
    if (!this.numberComboBox.isEnabled()) {
      popno = "1";
    }
    algoName = (algoName.equals("")) ? null : algoName;
    Network net = (Network) ts.getTraitStructure(networkName);

    if (ts.getNetworks().size() == 0) // without a network, we will be unable
    // to view this visualization, so we add it here.
    {
      try {
        view.addAlgorithm(
            Algorithms.NetworkAlgorithms.algonames().get(0),
            Algorithms.NetworkAlgorithms.jobTypeID().get(0),
            ap.getId(),
            ts.getId(),
            ms.getId());
      } catch (Exception e) {
      }
    }

    if (this.createAssociationRadioButton.isSelected()) {
      int structtype =
          algorithmComboBox.getSelectedIndex() < 0
              ? -1
              : Algorithms.AssociationAlgorithms.inputStructure()
                  .get(algorithmComboBox.getSelectedIndex());
      IOFilesForIOLasso ioffio = null;
      if (structtype == 3) {
        ioffio = new IOFilesForIOLasso(currentComponentReference);

        ioffio.setVisible(true);

        if (ioffio.getInputFilePath() == null
            || ioffio.getInputFilePath().length() < 5
            || ioffio.getOutputFilePath() == null
            || ioffio.getOutputFilePath().length() < 5) {
          UIMessages.showErrorMessage("I/O Lasso needs valid group files", "Error");
          return;
        }
      }

      AssociationParameterObject apo =
          new AssociationParameterObject(
              (Network) ts.getTraitStructure(networkName),
              this.nameTextField.getText(),
              ms.getPopulation(networkName),
              popno,
              ioffio);
      int idx = this.algorithmComboBox.getSelectedIndex() - 1;

      view.addAlgorithm(
          Algorithms.AssociationAlgorithms.algonames().get(idx),
          Algorithms.AssociationAlgorithms.jobTypeID().get(idx),
          ap.getId(),
          ts.getId(),
          ms.getId(),
          apo);
    } else {
      DataAddRemoveHandler.getInstance()
          .addAssociation(
              ap.getId(),
              ts,
              ms,
              this.nameTextField.getText(),
              this.associationFilePathTextField.getText(),
              null);
    }
    this.dispose();
  }