Package org.woped.core.config

Examples of org.woped.core.config.IMetricsConfiguration


  /**
   * @param variableName
   * @return True if the Variable exists
   */
  public static boolean isVariableValid(String variableName){
    IMetricsConfiguration metricsConfig = ConfigurationManager.getMetricsConfiguration();
   
    if (metricsConfig.hasAlgorithmFormula(variableName)){
      return true;
    }
   
    if (metricsConfig.hasAlgorithmMethod(variableName)){
      return true;
    }
   
    if(metricsConfig.hasVariableFormula(variableName)){
      return true;
    }
   
    if(metricsConfig.hasVariableMethod(variableName)){
      return true;
    }
   
    return false;
  }
View Full Code Here


  }

  public void actionPerformed(ActionEvent evt) {
    String btnName = ((JButton) evt.getSource()).getName();
    String textAddition = "";
    IMetricsConfiguration metricsConfig = ConfigurationManager
        .getMetricsConfiguration();

    if (btnName != null) {
      if (btnName.equals(MetricsBuilderPanel.NEW_BTN)) {

        String newMetricID = (String) JOptionPane.showInputDialog(null,
            Messages.getString("Metrics.Builder.New.EnterNewID"),
            Messages.getString("Metrics.Builder.New.EnterNewID"),
            JOptionPane.PLAIN_MESSAGE);
        // User canceled
        if(newMetricID == null)
          return;
        else {
          clearFields();
          currentMetricID = "";
        }
       
        if (metricsConfig.isMetricIDInUse(newMetricID))
          JOptionPane
              .showMessageDialog(
                  null,
                  Messages.getString("Metrics.Builder.New.IDAlreadyInUse")
                      + "!",
                  Messages.getString("Metrics.Builder.New.IDAlreadyInUse"),
                  JOptionPane.ERROR_MESSAGE);
        else {
          JFileChooser fileChooser = new JFileChooser();
          fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
          FileFilter filter = new LabeledFileFilter() {
            public boolean accept(File file) {
              if (file.getAbsolutePath().endsWith(".xml"))
                return true;
              return false;
            }

            public String getDescription() {
              return "Metrics XML file (*.xml)";
            }

            public String getExtension() {
              return ".xml";
            }
          };

          fileChooser.addChoosableFileFilter(filter);
          fileChooser.setCurrentDirectory(new File(metricsConfig
              .getCustomMetricsDir() + File.separatorChar));
          File file = null;
          int returnVal = fileChooser.showSaveDialog(null);

          if (returnVal == JFileChooser.APPROVE_OPTION) {
            String path = fileChooser.getSelectedFile()
                .getAbsolutePath();

            if (!path.substring(path.length() - 4, path.length())
                .equals(".xml"))
              path += ".xml";

            file = new File(path);

            // User selected a new file for the new algorithm, so
            // add it
            if (metricsConfig.findFileIDToFileName(file
                .getAbsolutePath()) == -1)
              metricsConfig.addNewMetricFile(file
                  .getAbsolutePath());

            metricsConfig.addNewAlgorithm(newMetricID,
                metricsConfig.findFileIDToFileName(file
                    .getAbsolutePath()));
            update();
            currentMetricID = newMetricID;
            MetricsBuilderPanel.displayMetric(newMetricID);
          }
          updateMetricWithGUIData();
        }
      } else if (btnName.equals(MetricsBuilderPanel.SAVE_BTN)) {
        updateMetricWithGUIData();
        metricsConfig.endEditSession(true);
        dirty = false;
        metricsConfig.startEditSession();
      } else if (btnName.equals(MetricsBuilderPanel.IMPORT_BTN))
        importMetricsFile();
      else if (btnName.equals(MetricsBuilderPanel.EXPORT_BTN))
        exportMetricsFile();
      else if (btnName.equals(MetricsBuilderPanel.EXIT_BTN)) {
        if (dirty) {
          int option = JOptionPane
              .showConfirmDialog(
                  null,
                  Messages.getString("Metrics.Builder.Exit.SaveChanges"),
                  Messages.getString("Metrics.Builder.Exit.SaveChanges.Title"),
                  JOptionPane.YES_NO_CANCEL_OPTION,
                  JOptionPane.WARNING_MESSAGE);

          if (option == JOptionPane.YES_OPTION) {
            metricsConfig.endEditSession(true);
            dirty = false;
            currentMetricID = "";
            closeFrame();
          } else if (option == JOptionPane.NO_OPTION) {
            metricsConfig.endEditSession(false);
            dirty = false;
            currentMetricID = "";
            closeFrame();
          } else
            return;

        } else {
          currentMetricID = "";
          closeFrame();
        }
      } else if (btnName.equals(MetricsBuilderPanel.CHECK_BTN)) {
        try {
          MetricsCalculator
              .checkFormula(MetricsBuilderPanel.jMetricsFormulaTextField
                  .getText());
          JOptionPane
              .showMessageDialog(
                  null,
                  Messages.getString("Metrics.Builder.ConsistencyCheck.NoIssuesFound"), //$NON-NLS-1$
                  Messages.getString("Metrics.Builder.ConsistencyCheck.ConsistencyChecker"), //$NON-NLS-1$
                  JOptionPane.INFORMATION_MESSAGE);
        } catch (CalculateFormulaException cfe) {
          boolean showErrorFrame = true;

          // This logic should check if there is an enhancement
          // available
          if (cfe instanceof NestedCalculateFormulaException) {
            NestedCalculateFormulaException ncfe = (NestedCalculateFormulaException) cfe;

            if (ncfe.hasEnhancementExceptions()) {
              String newLine = System
                  .getProperty("line.separator"); //$NON-NLS-1$

              int answer = JOptionPane
                  .showConfirmDialog(
                      null,
                      Messages.getString("Metrics.Builder.ConsistencyCheck.ErrorsCanBeReducedByUsingTheFormula") + newLine + //$NON-NLS-1$
                          "\""
                          + ncfe.getEnhancementExceptions()
                              .get(0)
                              .getEnhancedFormula()
                          + "\""
                          + newLine
                          + Messages
                              .getString("Metrics.Builder.ConsistencyCheck.DoYouWantToUseThisFormula"), //$NON-NLS-1$

                      Messages.getString("Metrics.Builder.ConsistencyCheck.EnhancementAvailable"), //$NON-NLS-1$
                      JOptionPane.YES_NO_OPTION,
                      JOptionPane.QUESTION_MESSAGE);

              // Check if Yes is clicked
              if (answer == JOptionPane.YES_OPTION) {
                // Writing the new Formula into the Text-Field
                MetricsBuilderPanel.jMetricsFormulaTextField
                    .setText(ncfe
                        .getEnhancementExceptions()
                        .get(0).getEnhancedFormula());

                // Disable that the original error-screen
                showErrorFrame = false;

                // Run the check process a second time for
                // getting the errors for the new formula
                try {
                  // Run the checker
                  MetricsCalculator.checkFormula(ncfe
                      .getEnhancementExceptions().get(0)
                      .getEnhancedFormula());

                  // Show the successful Dialog if no errors
                  // appear
                  JOptionPane
                      .showMessageDialog(
                          null,
                          Messages.getString("Metrics.Builder.ConsistencyCheck.NoIssuesFound"), //$NON-NLS-1$
                          Messages.getString("Metrics.Builder.ConsistencyCheck.ConsistencyChecker"), //$NON-NLS-1$
                          JOptionPane.INFORMATION_MESSAGE);
                } catch (CalculateFormulaException e) {
                  // Show the Error-Frame
                  new MetricsBuilderErrorFrame(e);
                }
              }
            }
          }

          // If had not been any enhancement available or the
          // enhancements had not been accepted
          // --> the formula has not been changed
          if (showErrorFrame) {
            new MetricsBuilderErrorFrame(cfe);
          }
        }
      } else if (btnName.equals(MetricsBuilderPanel.DELETE_TAB2_BTN)) {
         
          int row =  MetricsBuilderPanel.jTableValues.getSelectedRow();
         
          MetricsBuilderPanel.jTableValues.editingCanceled(new ChangeEvent(MetricsBuilderPanel.jTableValues));
          MetricsBuilderPanel.model.removeRow(row);
          MetricsBuilderPanel.model.fireTableDataChanged();
         
      } else if (btnName.equals(MetricsBuilderPanel.ADD_TAB2_BTN)) { 
       
          MetricsBuilderPanel.model.addRow(MetricsBuilderPanel.DEFAULT_CELL_VALUES);
          MetricsBuilderPanel.model.fireTableDataChanged();

         
      } else if (btnName.equals(MetricsBuilderPanel.CLEAR_GROUP_BTN)) {
      } else if (btnName.equals(MetricsBuilderPanel.EXIT_GROUP_BTN)) {
        closeFrame();
      } else if (btnName.equals(MetricsBuilderPanel.SAVE_TAB2_BTN)) {
        updateMetricWithGUIData();
        metricsConfig.endEditSession(true);
        dirty = false;
        metricsConfig.startEditSession();
      } else if (btnName.equals(MetricsBuilderPanel.EXIT_TAB2_BTN)) {
        closeFrame();
      } else if (btnName.equals(MetricsBuilderPanel.FUNC_BTN))
        textAddition = ((JButton) evt.getSource()).getText()
            .toLowerCase() + "(";
View Full Code Here

    int returnVal = fileChooser.showSaveDialog(null);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
      importFromFile = new File(fileChooser.getSelectedFile()
          .getAbsolutePath());
      IMetricsConfiguration metricsConfig = ConfigurationManager
          .getMetricsConfiguration();
      File importToFile = new File(metricsConfig.getCustomMetricsDir()
          + File.separatorChar
          + fileChooser.getSelectedFile().getName());
      if (importToFile.exists())
        JOptionPane
            .showMessageDialog(
                null,
                "A custom metrics file with the same name already exists. Please rename the file.",
                "Error", JOptionPane.ERROR_MESSAGE);
      else {
        // Copy file to usermetrics folder
        try {
          FileReader in = new FileReader(importFromFile);
          FileWriter out = new FileWriter(importToFile);
          int c;
          while ((c = in.read()) != -1)
            out.write(c);

          in.close();
          out.close();
        } catch (FileNotFoundException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }

        // Load content of the file
        metricsConfig.readConfig(importToFile);
        update();
        JOptionPane.showMessageDialog(null,
            "Import finished succesfully.");
      }
    }
View Full Code Here

    for (int i : MetricsBuilderPanel.jVariableListTab3.getSelectedIndices())
      list.add((String) MetricsBuilderPanel.jVariableListTab3.getModel()
          .getElementAt(i));

    IMetricsConfiguration metricsConfig = ConfigurationManager
        .getMetricsConfiguration();
    if (metricsConfig.save(list, exportFile))
      JOptionPane.showMessageDialog(null, "Export finished succesfully.");
    else
      JOptionPane.showMessageDialog(null, "Error while exporting.");
  }
View Full Code Here

          }

          whileMetricFilling = true;
          updateMetricWithGUIData();
          MetricsBuilderPanel.displayMetric(metricsID);
          IMetricsConfiguration metricsConfig = ConfigurationManager
              .getMetricsConfiguration();
          MetricsBuilderPanel.setElementsEditable(metricsConfig
              .isCustomMetric(metricsID));
          whileMetricFilling = false;

          currentMetricID = metricsID;
        } else if (oldTabIndex == 1) {
          if (listName != null) {
            if (listName.equals(MetricsBuilderPanel.ALGORITHM_LIST)) {
              NameIDListEntry listEntry = (NameIDListEntry) MetricsBuilderPanel.jAlgorithmListTab1
                  .getModel().getElementAt(index);
              metricsID = listEntry.getMetricID();
              MetricsBuilderPanel.clear();
              MetricsBuilderPanel.fillTable(metricsID);

            } else if (listName
                .equals(MetricsBuilderPanel.VARIABLE_LIST)) {
              NameIDListEntry listEntry = (NameIDListEntry) MetricsBuilderPanel.jVariableListTab1
                  .getModel().getElementAt(index);
              metricsID = listEntry.getMetricID();
              MetricsBuilderPanel.clear();
              MetricsBuilderPanel.fillTable(metricsID);
            } else if (listName
                .equals(MetricsBuilderPanel.ALGORITHM_LIST_TAB2)) {
              NameIDListEntry listEntry = (NameIDListEntry) MetricsBuilderPanel.jAlgorithmListTab2
                  .getModel().getElementAt(index);
              metricsID = listEntry.getMetricID();
              MetricsBuilderPanel.clear();
              MetricsBuilderPanel.fillTable(metricsID);
            } else if (listName
                .equals(MetricsBuilderPanel.VARIABLE_LIST_TAB2)) {
              NameIDListEntry listEntry = (NameIDListEntry) MetricsBuilderPanel.jVariableListTab2
                  .getModel().getElementAt(index);
              MetricsBuilderPanel.clear();
              metricsID = listEntry.getMetricID();
              MetricsBuilderPanel.fillTable(metricsID);
            }

          }

          whileMetricFilling = true;
          updateMetricWithGUIData();
          MetricsBuilderPanel.displayMetric(metricsID);
          IMetricsConfiguration metricsConfig = ConfigurationManager
              .getMetricsConfiguration();
          MetricsBuilderPanel.setElementsEditable(metricsConfig
              .isCustomMetric(metricsID));
          whileMetricFilling = false;
          currentMetricID = metricsID;
        }
      }
View Full Code Here

   */
  private boolean updateMetricWithGUIData() {
    if (currentMetricID.isEmpty())
      return false;

    IMetricsConfiguration metricsConfig = ConfigurationManager
        .getMetricsConfiguration();

    // Check on which tab we are to process the correct data
    switch (oldTabIndex) {
    case 0:
      // If this field is not enabled we currently display an internal
      // metric,
      // so there cannot have been any changes -> return
      if (!MetricsBuilderPanel.jMetricsNameTextField.isEnabled())
        return true;

      if (MetricsBuilderPanel.jMetricsFormulaTextField.getText()
          .isEmpty()) {
        JOptionPane
            .showMessageDialog(
                null,
                Messages.getString("Metrics.Builder.General.FormulaNeeded"),
                Messages.getString("Metrics.Builder.General.FormulaNeeded"),
                JOptionPane.WARNING_MESSAGE);
        return false;
      }

      // Since the user can only create new algorithms, we do not need to
      // check for the metric type
      metricsConfig.setAlgorithmName(currentMetricID,
          MetricsBuilderPanel.jMetricsNameTextField.getText());
      metricsConfig.setAlgorithmFormula(currentMetricID,
          MetricsBuilderPanel.jMetricsFormulaTextField.getText());
      metricsConfig.setAlgorithmDescription(currentMetricID,
          MetricsBuilderPanel.jMetricsDescriptionTextField.getText());
      break;

    case 1:
     
View Full Code Here

    add(createMainPanel(metricsID), BorderLayout.CENTER);
  }
 
  private JPanel createMainPanel(String metricsID) {   
    mbp = new MetricsBuilderPanel();
    IMetricsConfiguration metricsConfig = ConfigurationManager.getMetricsConfiguration();
    MetricsBuilderPanel.setElementsEditable(metricsConfig.isCustomMetric(metricsID));
    metricsConfig.startEditSession();
    return mbp;
  }
View Full Code Here

    //Sorting the FormulaIDs alphabetically
    java.util.Arrays.sort( keylist );
   
    //Getting access to the Formula Configuration
    //needed to get the old Formula
    IMetricsConfiguration metricsConfig = ConfigurationManager.getMetricsConfiguration();
   
    for(int i = 0; i < keylist.length; i++){
      //FormulaID
      array[i][0] = keylist[i];
      //Old-Formula
      if(metricsConfig.hasAlgorithmFormula(keylist[i])){
        //This Formula is a Algorithm
        array[i][1] = metricsConfig.getAlgorithmFormula(keylist[i]);
      }else if(metricsConfig.hasVariableFormula(keylist[i])){
        //This Formula is a Variable
        array[i][1] = metricsConfig.getVariableFormula(keylist[i]);
      }else{
        array[i][1] = " ";
      }
      
      //EnhancedFormula
View Full Code Here

  
  /**
   * Fills the GUI with matching values.
   */
  private void setValues() {
    IMetricsConfiguration metricsConfig = ConfigurationManager
        .getMetricsConfiguration();

    // Add algorithms to list
    DefaultListModel algorithmListModel = new DefaultListModel();
    ArrayList<NameIDListEntry> algorithmList = new ArrayList<NameIDListEntry>();
    for (String s : metricsConfig.getAlgorithmIDs())
      algorithmList.add(new NameIDListEntry(s, metricsConfig.getAlgorithmName(s)));
    Collections.sort(algorithmList);
    for (NameIDListEntry entry : algorithmList
      algorithmListModel.addElement(entry);
    jAlgorithmListTab1.setModel(algorithmListModel);
    jAlgorithmListTab2.setModel(algorithmListModel);
    jAlgorithmListTab3.setModel(algorithmListModel);
   
    // Add variables to list
    DefaultListModel variableListModel = new DefaultListModel();
    ArrayList<NameIDListEntry> variableList = new ArrayList<NameIDListEntry>();
    for (String s : metricsConfig.getVariableIDs())
      variableList.add(new NameIDListEntry(s, metricsConfig.getVariableName(s)));
    Collections.sort(variableList);
    for (NameIDListEntry entry : variableList)
      variableListModel.addElement(entry);
    jVariableListTab1.setModel(variableListModel);
    jVariableListTab2.setModel(variableListModel);
View Full Code Here

   * @param topGroupName  Name of the top group, containing further groups
   * @return  Content of the top group and all its subgroups (Calculation results)
   */
  public List<UIMetricsGroup> calculateMetrics(String topGroupName){
    if(topGroupName == null) return new ArrayList<UIMetricsGroup>();
    IMetricsConfiguration metricsConfig = ConfigurationManager.getMetricsConfiguration();
    mc = new MetricsCalculator(editor);
    valueStates = new HashMap<String, IMetricsConfiguration.MetricThresholdState>();
   
    List<String> groupnames = metricsConfig.getGroupIDsFromGroup(algorithmGroupNameToID(topGroupName));
    List<UIMetricsGroup> answerList = new ArrayList<UIMetricsGroup>();
    for(String algorithmGroupName:groupnames){
      List<StringPair> resultList = new ArrayList<StringPair>();
     
      for(String id : metricsConfig.getAlgorithmIDsFromGroup(algorithmGroupName))
        {
          StringPair result = calculateSingle(metricsConfig, id);
          if(result == null) continue;
          resultList.add(result);
        }
      if(resultList.size()>0)
        answerList.add(new UIMetricsGroup(metricsConfig.getAlgorithmGroupName(algorithmGroupName),resultList));
    }
    return answerList;
  }
View Full Code Here

TOP

Related Classes of org.woped.core.config.IMetricsConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.