use of net.sf.mzmine.datamodel.MZmineProject 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.datamodel.MZmineProject in project mzmine2 by mzmine.
the class ProjectParametersSetupDialog method copyParameterValuesFromRawDataFiles.
private void copyParameterValuesFromRawDataFiles() {
MZmineProject currentProject = MZmineCore.getProjectManager().getCurrentProject();
for (int dataFileIndex = 0; dataFileIndex < dataFiles.length; dataFileIndex++) {
RawDataFile file = dataFiles[dataFileIndex];
UserParameter<?, ?>[] parameters = currentProject.getParameters();
// Loop through all parameters defined for this file
for (UserParameter<?, ?> p : parameters) {
// Check if this parameter has been seen before?
Object[] values;
if (!(parameterValues.containsKey(p))) {
// No, initialize a new array of values for this parameter
values = new Object[dataFiles.length];
for (int i = 0; i < values.length; i++) values[i] = p.getValue();
parameterValues.put(p, values);
} else {
values = parameterValues.get(p);
}
// Set value of this parameter for the current raw data file
values[dataFileIndex] = currentProject.getParameterValue(p, file);
}
}
}
use of net.sf.mzmine.datamodel.MZmineProject in project mzmine2 by mzmine.
the class ProjectCloseModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
int selectedValue = JOptionPane.showInternalConfirmDialog(MZmineCore.getDesktop().getMainWindow().getContentPane(), "Are you sure you want to close the current project?", "Close project", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (selectedValue != JOptionPane.YES_OPTION)
return ExitCode.CANCEL;
// Close all windows related to previous project
GUIUtils.closeAllWindows();
// Create a new, empty project
MZmineProject newProject = new MZmineProjectImpl();
// Replace the current project with the new one
ProjectManager projectManager = MZmineCore.getProjectManager();
projectManager.setCurrentProject(newProject);
// Ask the garbage collector to free the previously used memory
System.gc();
logger.info("Project closed.");
return ExitCode.OK;
}
use of net.sf.mzmine.datamodel.MZmineProject in project mzmine2 by mzmine.
the class HeatMapParameters method showSetupDialog.
@Override
public ExitCode showSetupDialog(Window parent, boolean valueCheckRequired) {
// Update the parameter choices
MZmineProject project = MZmineCore.getProjectManager().getCurrentProject();
UserParameter<?, ?>[] newChoices = project.getParameters();
getParameter(HeatMapParameters.selectionData).setChoices(newChoices);
if (newChoices.length > 0) {
ArrayList<Object> values = new ArrayList<Object>();
for (RawDataFile dataFile : project.getDataFiles()) {
Object paramValue = project.getParameterValue(newChoices[0], dataFile);
if (paramValue == null) {
continue;
}
if (!values.contains(paramValue)) {
values.add(paramValue);
}
}
Object[] newValues = values.toArray();
getParameter(HeatMapParameters.referenceGroup).setChoices(newValues);
}
HeatmapSetupDialog dialog = new HeatmapSetupDialog(parent, valueCheckRequired, this);
dialog.setVisible(true);
return dialog.getExitCode();
}
use of net.sf.mzmine.datamodel.MZmineProject in project mzmine2 by mzmine.
the class ProjectTreeDnDHandler method importData.
public boolean importData(TransferSupport info) {
if (!info.isDrop()) {
return false;
}
ProjectTree projectTree = (ProjectTree) info.getComponent();
DefaultTreeModel treeModel = (DefaultTreeModel) projectTree.getModel();
MZmineProject project = MZmineCore.getProjectManager().getCurrentProject();
JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();
TreePath dropPath = dl.getPath();
DefaultMutableTreeNode droppedLocationNode = (DefaultMutableTreeNode) dropPath.getLastPathComponent();
Object droppedLocationObject = droppedLocationNode.getUserObject();
int childIndex = dl.getChildIndex();
TreePath[] transferedPaths = projectTree.getSelectionPaths();
// Check if the drop target is among the project data files
if (droppedLocationObject == RawDataTreeModel.dataFilesNodeName) {
for (TreePath path : transferedPaths) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
int currentIndex = node.getParent().getIndex(node);
Object transferObject = node.getUserObject();
if (transferObject instanceof RawDataFile) {
treeModel.removeNodeFromParent(node);
if (childIndex > currentIndex)
childIndex--;
treeModel.insertNodeInto(node, droppedLocationNode, childIndex);
childIndex++;
}
}
}
// Check if the drop target is AFTER the data files (last position)
if ((droppedLocationObject == project) && (childIndex == 1)) {
int numOfFiles = project.getDataFiles().length;
DefaultMutableTreeNode filesNode = (DefaultMutableTreeNode) droppedLocationNode.getChildAt(0);
for (TreePath path : transferedPaths) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
Object transferObject = node.getUserObject();
if (transferObject instanceof RawDataFile) {
treeModel.removeNodeFromParent(node);
treeModel.insertNodeInto(node, filesNode, numOfFiles - 1);
}
}
}
// Check if the drop target is among the project feature lists
if (droppedLocationObject == PeakListTreeModel.peakListsNodeName) {
for (TreePath path : transferedPaths) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
int currentIndex = node.getParent().getIndex(node);
Object transferObject = node.getUserObject();
if (childIndex > currentIndex)
childIndex--;
if (transferObject instanceof PeakList) {
treeModel.removeNodeFromParent(node);
treeModel.insertNodeInto(node, droppedLocationNode, childIndex);
childIndex++;
}
}
}
// Check if the drop target is AFTER the feature lists (last position)
if ((droppedLocationObject == project) && (childIndex == 2)) {
DefaultMutableTreeNode peakListsNode = (DefaultMutableTreeNode) droppedLocationNode.getChildAt(1);
int numOfPeakLists = project.getPeakLists().length;
for (TreePath path : transferedPaths) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
Object transferObject = node.getUserObject();
if (transferObject instanceof PeakList) {
treeModel.removeNodeFromParent(node);
treeModel.insertNodeInto(node, peakListsNode, numOfPeakLists - 1);
}
}
}
return true;
}
Aggregations