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);
}
}
}
}
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());
}
}
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++;
}
}
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());
}
}
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++;
}
}
Aggregations