Search in sources :

Example 1 with MZmineModule

use of net.sf.mzmine.modules.MZmineModule in project mzmine2 by mzmine.

the class ProcessingComponent method setupTreeViews.

private void setupTreeViews() {
    tiProcessingRoot = new DefaultMutableTreeNode("Processing queues");
    msLevelNodes = new DPPMSLevelTreeNode[MSLevel.cropValues().length];
    for (MSLevel mslevel : MSLevel.cropValues()) {
        msLevelNodes[mslevel.ordinal()] = new DPPMSLevelTreeNode(mslevel);
        tiProcessingRoot.add(msLevelNodes[mslevel.ordinal()]);
    }
    tiAllModulesRoot = new DefaultMutableTreeNode("Modules");
    // create category items dynamically, if a new category is added later on.
    DPPModuleCategoryTreeNode[] moduleCategories = new DPPModuleCategoryTreeNode[ModuleSubCategory.values().length];
    for (int i = 0; i < moduleCategories.length; i++) {
        moduleCategories[i] = new DPPModuleCategoryTreeNode(ModuleSubCategory.values()[i]);
        tiAllModulesRoot.add(moduleCategories[i]);
    }
    // add modules to their module category items
    Collection<MZmineModule> moduleList = MZmineCore.getAllModules();
    for (MZmineModule module : moduleList) {
        if (module instanceof DataPointProcessingModule) {
            DataPointProcessingModule dppm = (DataPointProcessingModule) module;
            // add each module as a child of the module category items
            for (DPPModuleCategoryTreeNode catItem : moduleCategories) {
                if (dppm.getModuleSubCategory().equals(catItem.getCategory())) {
                    catItem.add(new DPPModuleTreeNode(dppm));
                }
            }
        }
    }
    // add the categories to the root item
    tvProcessing = new JTree(tiProcessingRoot);
    tvAllModules = new JTree(tiAllModulesRoot);
    tvProcessing.setCellRenderer(new DisableableTreeCellRenderer());
    tvAllModules.setRootVisible(true);
    tvProcessing.setRootVisible(true);
    expandAllNodes(tvAllModules);
}
Also used : DisableableTreeCellRenderer(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.customguicomponents.DisableableTreeCellRenderer) DPPMSLevelTreeNode(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.customguicomponents.DPPMSLevelTreeNode) JTree(javax.swing.JTree) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DPPModuleCategoryTreeNode(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.customguicomponents.DPPModuleCategoryTreeNode) DPPModuleTreeNode(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.customguicomponents.DPPModuleTreeNode) DataPointProcessingModule(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.DataPointProcessingModule) MSLevel(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.MSLevel) MZmineModule(net.sf.mzmine.modules.MZmineModule)

Example 2 with MZmineModule

use of net.sf.mzmine.modules.MZmineModule in project mzmine2 by mzmine.

the class BatchQueue method loadFromXml.

/**
 * De-serialize from XML.
 *
 * @param xmlElement the element that holds the XML.
 * @return the de-serialized value.
 */
public static BatchQueue loadFromXml(final Element xmlElement) {
    // Set the parameter choice for the RowsFilterModule
    String[] choices;
    choices = new String[1];
    choices[0] = "No parameters defined";
    MZmineCore.getConfiguration().getModuleParameters(RowsFilterModule.class).getParameter(RowsFilterParameters.GROUPSPARAMETER).setChoices(choices);
    // Create an empty queue.
    final BatchQueue queue = new BatchQueue();
    // Get the loaded modules.
    final Collection<MZmineModule> allModules = MZmineCore.getAllModules();
    // Process the batch step elements.
    final NodeList nodes = xmlElement.getElementsByTagName(BATCH_STEP_ELEMENT);
    final int nodesLength = nodes.getLength();
    for (int i = 0; i < nodesLength; i++) {
        final Element stepElement = (Element) nodes.item(i);
        final String methodName = stepElement.getAttribute(METHOD_ELEMENT);
        // Find a matching module.
        for (final MZmineModule module : allModules) {
            if (module instanceof MZmineProcessingModule && module.getClass().getName().equals(methodName)) {
                // Get parameters and add step to queue.
                final ParameterSet parameterSet = MZmineCore.getConfiguration().getModuleParameters(module.getClass());
                final ParameterSet methodParams = parameterSet.cloneParameterSet();
                methodParams.loadValuesFromXML(stepElement);
                queue.add(new MZmineProcessingStepImpl<MZmineProcessingModule>((MZmineProcessingModule) module, methodParams));
                break;
            }
        }
    }
    return queue;
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) MZmineProcessingModule(net.sf.mzmine.modules.MZmineProcessingModule) MZmineModule(net.sf.mzmine.modules.MZmineModule)

Example 3 with MZmineModule

use of net.sf.mzmine.modules.MZmineModule in project mzmine2 by mzmine.

the class MZmineConfigurationImpl method loadConfiguration.

@Override
public void loadConfiguration(File file) throws IOException {
    try {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document configuration = dBuilder.parse(file);
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        logger.finest("Loading desktop configuration");
        XPathExpression expr = xpath.compile("//configuration/preferences");
        NodeList nodes = (NodeList) expr.evaluate(configuration, XPathConstants.NODESET);
        if (nodes.getLength() == 1) {
            Element preferencesElement = (Element) nodes.item(0);
            // that needs this key for encryption
            if (file.equals(MZmineConfiguration.CONFIG_FILE))
                new SimpleParameterSet(new Parameter[] { globalEncrypter }).loadValuesFromXML(preferencesElement);
            preferences.loadValuesFromXML(preferencesElement);
        }
        logger.finest("Loading last projects");
        expr = xpath.compile("//configuration/lastprojects");
        nodes = (NodeList) expr.evaluate(configuration, XPathConstants.NODESET);
        if (nodes.getLength() == 1) {
            Element lastProjectsElement = (Element) nodes.item(0);
            lastProjects.loadValueFromXML(lastProjectsElement);
        }
        logger.finest("Loading modules configuration");
        for (MZmineModule module : MZmineCore.getAllModules()) {
            String className = module.getClass().getName();
            expr = xpath.compile("//configuration/modules/module[@class='" + className + "']/parameters");
            nodes = (NodeList) expr.evaluate(configuration, XPathConstants.NODESET);
            if (nodes.getLength() != 1)
                continue;
            Element moduleElement = (Element) nodes.item(0);
            ParameterSet moduleParameters = getModuleParameters(module.getClass());
            moduleParameters.loadValuesFromXML(moduleElement);
        }
        logger.info("Loaded configuration from file " + file);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) ParameterSet(net.sf.mzmine.parameters.ParameterSet) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) IOException(java.io.IOException) XPathFactory(javax.xml.xpath.XPathFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) MZmineModule(net.sf.mzmine.modules.MZmineModule)

Example 4 with MZmineModule

use of net.sf.mzmine.modules.MZmineModule in project mzmine2 by mzmine.

the class MZmineConfigurationImpl method setModuleParameters.

@Override
public void setModuleParameters(Class<? extends MZmineModule> moduleClass, ParameterSet parameters) {
    assert moduleClass != null;
    assert parameters != null;
    MZmineModule moduleInstance = MZmineCore.getModuleInstance(moduleClass);
    Class<? extends ParameterSet> parametersClass = moduleInstance.getParameterSetClass();
    if (!parametersClass.isInstance(parameters)) {
        throw new IllegalArgumentException("Given parameter set is an instance of " + parameters.getClass() + " instead of " + parametersClass);
    }
    moduleParameters.put(moduleClass, parameters);
}
Also used : MZmineModule(net.sf.mzmine.modules.MZmineModule)

Example 5 with MZmineModule

use of net.sf.mzmine.modules.MZmineModule in project mzmine2 by mzmine.

the class DataPointProcessingQueue method loadfromXML.

@Nonnull
public static DataPointProcessingQueue loadfromXML(@Nonnull final Element xmlElement) {
    DataPointProcessingQueue queue = new DataPointProcessingQueue();
    // Get the loaded modules.
    final Collection<MZmineModule> allModules = MZmineCore.getAllModules();
    // Process the processing step elements.
    final NodeList nodes = xmlElement.getElementsByTagName(DATA_POINT_PROCESSING_STEP_ELEMENT);
    final int nodesLength = nodes.getLength();
    for (int i = 0; i < nodesLength; i++) {
        final Element stepElement = (Element) nodes.item(i);
        final String methodName = stepElement.getAttribute(METHOD_ELEMENT);
        logger.finest("loading method " + methodName);
        for (MZmineModule module : allModules) {
            if (module instanceof DataPointProcessingModule && module.getClass().getName().equals(methodName)) {
                // since the same module can be used in different ms levels, we need to clone the
                // parameter set, so we can have different values for every ms level
                ParameterSet parameterSet = MZmineCore.getConfiguration().getModuleParameters(module.getClass()).cloneParameterSet();
                parameterSet.loadValuesFromXML(stepElement);
                queue.add(new MZmineProcessingStepImpl<DataPointProcessingModule>((DataPointProcessingModule) module, parameterSet));
                // add to treeView
                break;
            }
        }
    }
    return queue;
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) MZmineModule(net.sf.mzmine.modules.MZmineModule) Nonnull(javax.annotation.Nonnull)

Aggregations

MZmineModule (net.sf.mzmine.modules.MZmineModule)7 ParameterSet (net.sf.mzmine.parameters.ParameterSet)5 Element (org.w3c.dom.Element)4 IOException (java.io.IOException)3 NodeList (org.w3c.dom.NodeList)3 File (java.io.File)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 SimpleParameterSet (net.sf.mzmine.parameters.impl.SimpleParameterSet)2 Document (org.w3c.dom.Document)2 FileOutputStream (java.io.FileOutputStream)1 Locale (java.util.Locale)1 Nonnull (javax.annotation.Nonnull)1 JTree (javax.swing.JTree)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 XPath (javax.xml.xpath.XPath)1