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