Search in sources :

Example 1 with PeakListTreeModel

use of net.sf.mzmine.desktop.impl.projecttree.PeakListTreeModel in project mzmine2 by mzmine.

the class SimplePeakList method removeRow.

/**
 * @see net.sf.mzmine.datamodel.PeakList#removeRow(net.sf.mzmine.datamodel.PeakListRow)
 */
@Override
public void removeRow(PeakListRow row) {
    peakListRows.remove(row);
    // We have to update the project tree model
    MZmineProjectImpl project = (MZmineProjectImpl) MZmineCore.getProjectManager().getCurrentProject();
    PeakListTreeModel treeModel = project.getPeakListTreeModel();
    treeModel.removeObject(row);
    updateMaxIntensity();
}
Also used : PeakListTreeModel(net.sf.mzmine.desktop.impl.projecttree.PeakListTreeModel) MZmineProjectImpl(net.sf.mzmine.project.impl.MZmineProjectImpl)

Example 2 with PeakListTreeModel

use of net.sf.mzmine.desktop.impl.projecttree.PeakListTreeModel in project mzmine2 by mzmine.

the class SortPeakListsModule method runModule.

@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
    List<PeakList> peakLists = Arrays.asList(parameters.getParameter(SortPeakListsParameters.peakLists).getValue().getMatchingPeakLists());
    PeakListTreeModel model = null;
    if (project instanceof MZmineProjectImpl) {
        model = ((MZmineProjectImpl) project).getPeakListTreeModel();
    } else if (MZmineCore.getDesktop() instanceof MainWindow) {
        ProjectTree tree = ((MainWindow) MZmineCore.getDesktop()).getMainPanel().getPeakListTree();
        model = (PeakListTreeModel) tree.getModel();
    }
    if (model == null)
        throw new MSDKRuntimeException("Cannot find feature list tree model for sorting. Different MZmine project impl?");
    final DefaultMutableTreeNode rootNode = model.getRoot();
    // Get all tree nodes that represent selected feature lists, and remove
    // them from
    final ArrayList<DefaultMutableTreeNode> selectedNodes = new ArrayList<DefaultMutableTreeNode>();
    for (int row = 0; row < rootNode.getChildCount(); row++) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) rootNode.getChildAt(row);
        Object selectedObject = selectedNode.getUserObject();
        if (peakLists.contains(selectedObject)) {
            selectedNodes.add(selectedNode);
        }
    }
    // Get the index of the first selected item
    final ArrayList<Integer> positions = new ArrayList<Integer>();
    for (DefaultMutableTreeNode node : selectedNodes) {
        int nodeIndex = rootNode.getIndex(node);
        if (nodeIndex != -1)
            positions.add(nodeIndex);
    }
    if (positions.isEmpty())
        return ExitCode.ERROR;
    int insertPosition = Collections.min(positions);
    // Sort the feature lists by name
    Collections.sort(selectedNodes, new Comparator<DefaultMutableTreeNode>() {

        @Override
        public int compare(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) {
            return o1.getUserObject().toString().compareTo(o2.getUserObject().toString());
        }
    });
    // Reorder the nodes in the tree model
    for (DefaultMutableTreeNode node : selectedNodes) {
        model.removeNodeFromParent(node);
        model.insertNodeInto(node, rootNode, insertPosition);
        insertPosition++;
    }
    return ExitCode.OK;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) ProjectTree(net.sf.mzmine.desktop.impl.projecttree.ProjectTree) PeakListTreeModel(net.sf.mzmine.desktop.impl.projecttree.PeakListTreeModel) MainWindow(net.sf.mzmine.desktop.impl.MainWindow) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) PeakList(net.sf.mzmine.datamodel.PeakList) MZmineProjectImpl(net.sf.mzmine.project.impl.MZmineProjectImpl) Nonnull(javax.annotation.Nonnull)

Aggregations

PeakListTreeModel (net.sf.mzmine.desktop.impl.projecttree.PeakListTreeModel)2 MZmineProjectImpl (net.sf.mzmine.project.impl.MZmineProjectImpl)2 MSDKRuntimeException (io.github.msdk.MSDKRuntimeException)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 PeakList (net.sf.mzmine.datamodel.PeakList)1 MainWindow (net.sf.mzmine.desktop.impl.MainWindow)1 ProjectTree (net.sf.mzmine.desktop.impl.projecttree.ProjectTree)1