Search in sources :

Example 1 with ComboParameter

use of net.sf.mzmine.parameters.parametertypes.ComboParameter in project mzmine2 by mzmine.

the class ProjectParametersSetupDialog method copyParameterValuesToRawDataFiles.

private void copyParameterValuesToRawDataFiles() {
    MZmineProject currentProject = MZmineCore.getProjectManager().getCurrentProject();
    // Remove all previous parameters from project
    UserParameter<?, ?>[] parameters = currentProject.getParameters();
    for (UserParameter<?, ?> parameter : parameters) {
        currentProject.removeParameter(parameter);
    }
    // Add new parameters
    parameters = parameterValues.keySet().toArray(new UserParameter[0]);
    for (UserParameter<?, ?> parameter : parameters) {
        currentProject.addParameter(parameter);
    }
    // Set values for new parameters
    for (int columnIndex = 0; columnIndex < parameterValues.keySet().size(); columnIndex++) {
        UserParameter<?, ?> parameter = tablemodelParameterValues.getParameter(columnIndex + 1);
        for (int dataFileIndex = 0; dataFileIndex < dataFiles.length; dataFileIndex++) {
            RawDataFile file = dataFiles[dataFileIndex];
            Object value = tablemodelParameterValues.getValueAt(dataFileIndex, columnIndex + 1);
            if (parameter instanceof DoubleParameter) {
                Double doubleValue = null;
                if (value instanceof Double)
                    doubleValue = (Double) value;
                if (value instanceof String)
                    doubleValue = Double.parseDouble((String) value);
                currentProject.setParameterValue(parameter, file, doubleValue);
            }
            if (parameter instanceof StringParameter) {
                if (value == null)
                    value = "";
                currentProject.setParameterValue(parameter, file, (String) value);
            }
            if (parameter instanceof ComboParameter) {
                if (value == null)
                    value = "";
                currentProject.setParameterValue(parameter, file, (String) value);
            }
        }
    }
}
Also used : UserParameter(net.sf.mzmine.parameters.UserParameter) StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Example 2 with ComboParameter

use of net.sf.mzmine.parameters.parametertypes.ComboParameter in project mzmine2 by mzmine.

the class UserParameterSaveHandler method fillParameterElement.

/**
 * Create the part of the XML document related to the scans
 *
 * @param scan
 * @param element
 */
private void fillParameterElement(UserParameter<?, ?> parameter, TransformerHandler hd) throws SAXException, IOException {
    AttributesImpl atts = new AttributesImpl();
    RawDataFile[] dataFiles = project.getDataFiles();
    if (parameter instanceof ComboParameter) {
        Object[] choices = ((ComboParameter<?>) parameter).getChoices();
        for (Object choice : choices) {
            hd.startElement("", "", UserParameterElementName.OPTION.getElementName(), atts);
            hd.characters(choice.toString().toCharArray(), 0, choice.toString().length());
            hd.endElement("", "", UserParameterElementName.OPTION.getElementName());
        }
    }
    for (RawDataFile dataFile : dataFiles) {
        Object value = project.getParameterValue(parameter, dataFile);
        if (value == null)
            continue;
        String valueString = String.valueOf(value);
        String dataFileID = dataFilesIDMap.get(dataFile);
        atts.addAttribute("", "", UserParameterElementName.DATA_FILE.getElementName(), "CDATA", dataFileID);
        hd.startElement("", "", UserParameterElementName.VALUE.getElementName(), atts);
        atts.clear();
        hd.characters(valueString.toCharArray(), 0, valueString.length());
        hd.endElement("", "", UserParameterElementName.VALUE.getElementName());
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Example 3 with ComboParameter

use of net.sf.mzmine.parameters.parametertypes.ComboParameter in project mzmine2 by mzmine.

the class UserParameterOpenHandler_2_3 method endElement.

/**
 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
 *      java.lang.String)
 */
@SuppressWarnings("unchecked")
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
    if (canceled)
        throw new SAXException("Parsing canceled");
    // <OPTION>
    if (qName.equals(UserParameterElementName_2_3.OPTION.getElementName())) {
        String optionValue = getTextOfElement();
        currentOptions.add(optionValue);
    }
    // <VALUE>
    if (qName.equals(UserParameterElementName_2_3.VALUE.getElementName())) {
        RawDataFile currentDataFile = dataFilesIDMap.get(currentDataFileID);
        String valueString = getTextOfElement();
        Object value;
        if (currentParameter instanceof DoubleParameter) {
            value = new Double(valueString);
        } else
            value = valueString;
        currentValues.put(currentDataFile, value);
    }
    // <PARAMETER>
    if (qName.equals(UserParameterElementName_2_3.PARAMETER.getElementName())) {
        if (currentParameter instanceof ComboParameter) {
            String[] newChoices = currentOptions.toArray(new String[0]);
            ((ComboParameter<String>) currentParameter).setChoices(newChoices);
        }
        newProject.addParameter(currentParameter);
        for (RawDataFile dataFile : currentValues.keySet()) {
            Object value = currentValues.get(dataFile);
            newProject.setParameterValue(currentParameter, dataFile, value);
        }
        parsedParams++;
    }
}
Also used : DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SAXException(org.xml.sax.SAXException) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Example 4 with ComboParameter

use of net.sf.mzmine.parameters.parametertypes.ComboParameter in project mzmine2 by mzmine.

the class UserParameterOpenHandler_2_3 method startElement.

/**
 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String,
 *      java.lang.String, org.xml.sax.Attributes)
 */
public void startElement(String namespaceURI, String lName, String qName, Attributes attrs) throws SAXException {
    if (canceled)
        throw new SAXException("Parsing canceled");
    // <PARAMETERS>
    if (qName.equals(UserParameterElementName_2_3.PARAMETERS.getElementName())) {
        String count = attrs.getValue(UserParameterElementName_2_3.COUNT.getElementName());
        totalParams = Integer.parseInt(count);
    }
    // <PARAMETER>
    if (qName.equals(UserParameterElementName_2_3.PARAMETER.getElementName())) {
        String name = attrs.getValue(UserParameterElementName_2_3.NAME.getElementName());
        String type = attrs.getValue(UserParameterElementName_2_3.TYPE.getElementName());
        if (type.equals(DoubleParameter.class.getSimpleName())) {
            currentParameter = new DoubleParameter(name, null);
        } else if (type.equals(StringParameter.class.getSimpleName())) {
            currentParameter = new StringParameter(name, null);
        } else if (type.equals(ComboParameter.class.getSimpleName())) {
            currentParameter = new ComboParameter<String>(name, null, new String[0]);
        } else {
            throw new SAXException("Unknown parameter type: " + type);
        }
        logger.finest("Loading parameter " + name);
        currentOptions.clear();
        currentValues.clear();
    }
    // <VALUE>
    if (qName.equals(UserParameterElementName_2_3.VALUE.getElementName())) {
        currentDataFileID = attrs.getValue(UserParameterElementName_2_3.DATA_FILE.getElementName());
    }
}
Also used : StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) SAXException(org.xml.sax.SAXException) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Example 5 with ComboParameter

use of net.sf.mzmine.parameters.parametertypes.ComboParameter in project mzmine2 by mzmine.

the class UserParameterOpenHandler_2_5 method endElement.

/**
 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
 *      java.lang.String)
 */
@SuppressWarnings("unchecked")
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
    if (canceled)
        throw new SAXException("Parsing canceled");
    // <OPTION>
    if (qName.equals(UserParameterElementName_2_5.OPTION.getElementName())) {
        String optionValue = getTextOfElement();
        currentOptions.add(optionValue);
    }
    // <VALUE>
    if (qName.equals(UserParameterElementName_2_5.VALUE.getElementName())) {
        RawDataFile currentDataFile = dataFilesIDMap.get(currentDataFileID);
        String valueString = getTextOfElement();
        Object value;
        if (currentParameter instanceof DoubleParameter) {
            value = new Double(valueString);
        } else
            value = valueString;
        currentValues.put(currentDataFile, value);
    }
    // <PARAMETER>
    if (qName.equals(UserParameterElementName_2_5.PARAMETER.getElementName())) {
        if (currentParameter instanceof ComboParameter) {
            String[] newChoices = currentOptions.toArray(new String[0]);
            ((ComboParameter<String>) currentParameter).setChoices(newChoices);
        }
        newProject.addParameter(currentParameter);
        for (RawDataFile dataFile : currentValues.keySet()) {
            Object value = currentValues.get(dataFile);
            newProject.setParameterValue(currentParameter, dataFile, value);
        }
        parsedParams++;
    }
}
Also used : DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SAXException(org.xml.sax.SAXException) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Aggregations

ComboParameter (net.sf.mzmine.parameters.parametertypes.ComboParameter)11 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)6 DoubleParameter (net.sf.mzmine.parameters.parametertypes.DoubleParameter)6 StringParameter (net.sf.mzmine.parameters.parametertypes.StringParameter)4 SAXException (org.xml.sax.SAXException)4 Parameter (net.sf.mzmine.parameters.Parameter)2 SimpleParameterSet (net.sf.mzmine.parameters.impl.SimpleParameterSet)2 ExitCode (net.sf.mzmine.util.ExitCode)2 Color (java.awt.Color)1 Window (java.awt.Window)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 URL (java.net.URL)1 Vector (java.util.Vector)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 JComboBox (javax.swing.JComboBox)1 Feature (net.sf.mzmine.datamodel.Feature)1 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)1 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)1