Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed database editor not being marked as dirty properly #877

Merged
merged 3 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2018 Lablicate GmbH.
* Copyright (c) 2008, 2022 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -27,17 +27,20 @@ public abstract class AbstractMassSpectra implements IMassSpectra {
private final List<IScanMSD> massSpectra;
private String converterId = "";
private String name = "";
private boolean dirty;
private final List<IUpdateListener> updateListeners;

public AbstractMassSpectra(List<IScanMSD> massSpectra) {

this.massSpectra = massSpectra;
updateListeners = new ArrayList<IUpdateListener>();
updateListeners = new ArrayList<>();
}

/**
* Initialize mass spectra and create a new internal mass spectra list.
*/
public AbstractMassSpectra() {

this(new ArrayList<>());
}

Expand Down Expand Up @@ -130,4 +133,16 @@ public void removeUpdateListener(IUpdateListener updateListener) {

updateListeners.remove(updateListener);
}

@Override
public boolean isDirty() {

return dirty;
}

@Override
public void setDirty(boolean dirty) {

this.dirty = dirty;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2018 Lablicate GmbH.
* Copyright (c) 2008, 2022 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
Expand All @@ -9,6 +9,7 @@
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Alexander Kerner - implementation
* Matthias Mailänder - add dirty handling
*******************************************************************************/
package org.eclipse.chemclipse.msd.model.core;

Expand Down Expand Up @@ -106,4 +107,16 @@ public interface IMassSpectra extends IUpdateListener {
* @param updateListener
*/
void removeUpdateListener(IUpdateListener updateListener);

/**
* This flag marks if a this list of mass spectra has been edited.
*/
boolean isDirty();

/**
* This flag marks if this list of mass spectra has been edited.<br/>
* It will only be saved if it is dirty. It should save a little bit of
* process time.
*/
void setDirty(boolean isDirty);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2021 Lablicate GmbH.
* Copyright (c) 2017, 2022 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -25,14 +25,17 @@
import org.eclipse.chemclipse.msd.model.core.IScanMSD;
import org.eclipse.chemclipse.msd.model.implementation.Ion;
import org.eclipse.chemclipse.msd.model.implementation.RegularLibraryMassSpectrum;
import org.eclipse.chemclipse.msd.swt.ui.Activator;
import org.eclipse.chemclipse.msd.swt.ui.components.massspectrum.MassSpectrumListUI;
import org.eclipse.chemclipse.msd.swt.ui.internal.runnables.LibraryImportRunnable;
import org.eclipse.chemclipse.msd.swt.ui.preferences.PreferenceSupplier;
import org.eclipse.chemclipse.rcp.ui.icons.core.ApplicationImageFactory;
import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImage;
import org.eclipse.chemclipse.support.events.IChemClipseEvents;
import org.eclipse.chemclipse.support.text.ValueFormat;
import org.eclipse.chemclipse.swt.ui.components.SearchSupportUI;
import org.eclipse.chemclipse.swt.ui.support.Colors;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
Expand Down Expand Up @@ -83,11 +86,20 @@ public LibraryModifySupportUI(Composite parent, int style) {
public void update(IMassSpectra massSpectra) {

this.massSpectra = massSpectra;
notify(massSpectra);
if(massSpectrumListUI != null) {
massSpectrumListUI.setInput(massSpectra);
}
}

private void notify(IMassSpectra massSpectra) {

IEventBroker eventBroker = Activator.getDefault().getEventBroker();
if(eventBroker != null) {
eventBroker.send(IChemClipseEvents.TOPIC_LIBRARY_MSD_UPDATE, massSpectra);
}
}

public void setReferencedComposites(MassSpectrumListUI massSpectrumListUI, SearchSupportUI searchSupportUI) {

this.searchSupportUI = searchSupportUI;
Expand Down Expand Up @@ -226,6 +238,7 @@ public void widgetSelected(SelectionEvent e) {
if(massSpectraImport != null) {
textLibraryPath.setText("");
massSpectra.addMassSpectra(massSpectraImport.getList());
massSpectra.setDirty(true);
update(massSpectra);
resetSearch();
}
Expand Down Expand Up @@ -278,6 +291,7 @@ public void widgetSelected(SelectionEvent e) {
if(object instanceof IScanMSD) {
IScanMSD massSpectrum = (IScanMSD)object;
massSpectra.removeMassSpectrum(massSpectrum);
massSpectra.setDirty(true);
}
}
update(massSpectra);
Expand Down Expand Up @@ -324,12 +338,14 @@ public void widgetSelected(SelectionEvent e) {
* Add to library and update the list.
*/
massSpectra.addMassSpectrum(libraryMassSpectrum);
massSpectra.setDirty(true);
update(massSpectra);
if(searchSupportUI != null) {
searchSupportUI.setSearchText(name);
}
//
} catch(Exception e1) {
logger.warn(e1);
} catch(Exception exception) {
logger.warn(exception);
}
}
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2021 Lablicate GmbH.
* Copyright (c) 2012, 2022 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -80,6 +80,7 @@ public interface IChemClipseEvents {
String TOPIC_SCAN_TARGET_UPDATE_COMPARISON = "target/update/comparison"; // Object[]{scan, identificationTarget}
String TOPIC_SCAN_REFERENCE_UPDATE_COMPARISON = "scan/update/comparison"; // Object[]{scan1, scan2}
//
String TOPIC_LIBRARY_MSD_UPDATE = "library/msd/update";
String TOPIC_LIBRARY_MSD_UPDATE_SELECTION = "library/msd/update/selection";
//
String TOPIC_PROCESSING_INFO_UPDATE = "processinginfo/update";
Expand Down
Loading