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

Drag and Drop for RI and MS Databases #1793

Merged
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
Expand Up @@ -148,7 +148,7 @@ public void init(IEditorSite site, IEditorInput input) throws PartInitException
Thread.currentThread().interrupt();
}
} else {
throw new PartInitException("The file could't be loaded.");
throw new PartInitException("Unimplemented editor input " + input.getClass());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IURIEditorInput;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.osgi.service.event.Event;
Expand Down Expand Up @@ -84,8 +85,10 @@ public void init(IEditorSite site, IEditorInput input) throws PartInitException
setPartName(fileName);
if(input instanceof IFileEditorInput fileEditorInput) {
this.file = fileEditorInput.getFile().getLocation().toFile();
} else if(input instanceof IURIEditorInput uriEditorInput) {
this.file = new File(uriEditorInput.getURI());
} else {
throw new PartInitException("The file could't be loaded.");
throw new PartInitException("Unimplemented editor input " + input.getClass());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ public void init(IEditorSite site, IEditorInput input) throws PartInitException
monitor.run(false, false, runnable);
batchProcessJob = runnable.getBatchProcessJob();
} catch(InvocationTargetException e) {
throw new PartInitException("The file could't be loaded.", e.getTargetException());
throw new PartInitException("The file couldn't be loaded.", e.getTargetException());
} catch(InterruptedException e) {
Thread.currentThread().interrupt();
}
} else {
throw new PartInitException("The file could't be loaded.");
throw new PartInitException("The file couldn't be loaded.");
}
}

Expand All @@ -156,7 +156,7 @@ protected void updateDirtyStatus(boolean dirty) {
@Override
public boolean isSaveAsAllowed() {

return false; // enable once the Date Explorer can open .obj
return false; // enable once the Data Explorer can open .obj
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void init(IEditorSite site, IEditorInput input) throws PartInitException
if(input instanceof IFileEditorInput fileEditorInput) {
file = fileEditorInput.getFile().getLocation().toFile();
} else {
throw new PartInitException("The file could't be loaded.");
throw new PartInitException("Unimplemented editor input " + input.getClass());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.chemclipse.msd.model;bundle-version="0.9.0",
org.eclipse.chemclipse.msd.converter;bundle-version="0.9.0",
org.eclipse.chemclipse.converter;bundle-version="0.9.0",
org.eclipse.chemclipse.model;bundle-version="0.9.0"
org.eclipse.chemclipse.model;bundle-version="0.9.0",
org.eclipse.chemclipse.ux.extension.msd.ui;bundle-version="0.9.0"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,24 @@
name="Database Collector (*.msl)">
</wizard>
</extension>
<extension
point="org.eclipse.ui.editors">
<editor
class="org.eclipse.chemclipse.ux.extension.msd.ui.editors.DatabaseEditor"
extensions="msl"
icon="platform:/plugin/org.eclipse.chemclipse.rcp.ui.icons/icons/16x16/database.gif"
id="org.eclipse.chemclipse.ux.extension.msd.ui.editors.DatabaseEditor.msl"
name="Mass Spectra Database">
</editor>
</extension>
<extension
point="org.eclipse.ui.editors">
<editor
class="org.eclipse.chemclipse.ux.extension.msd.ui.editors.DatabaseEditor"
extensions="msp"
icon="platform:/plugin/org.eclipse.chemclipse.rcp.ui.icons/icons/16x16/database.gif"
id="org.eclipse.chemclipse.ux.extension.msd.ui.editors.DatabaseEditor.msp"
name="Mass Spectra Database">
</editor>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
isImportable="true">
</DatabaseSupplier>
<DatabaseSupplier
description="Reads and writes NIST Text (MSP) mass spectra."
description="Reads and writes NIST Text (MSP) mass spectra."
exportConverter="org.eclipse.chemclipse.msd.converter.supplier.amdis.converter.msp.MSPDatabaseExportConverter"
fileExtension=".msp"
filterName="NIST Text (*.msp)"
Expand Down Expand Up @@ -50,7 +50,7 @@
isImportable="false">
</PeakSupplier>
<PeakSupplier
description="Writes NIST Text (MSP) mass spectra."
description="Writes NIST Text (MSP) mass spectra."
exportConverter="org.eclipse.chemclipse.msd.converter.supplier.amdis.converter.msp.MSPPeakExportConverter"
fileExtension=".msp"
filterName="NIST Text (*.msp)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ public static void saveMassSpectra(List<IPeakMSD> peaks) throws NoConverterAvail
/**
* Opens a file dialog and tries to save the mass spectra
*
* @param chromatogram
* @param shell
* @param peaks
* @param fileName
* @throws NoConverterAvailableException
*/
public static void saveMassSpectra(Shell shell, List<IPeakMSD> peaks, String fileName) throws NoConverterAvailableException {
Expand Down Expand Up @@ -179,7 +181,9 @@ public static boolean saveMassSpectra(IMassSpectra massSpectra) throws NoConvert
/**
* Opens a file dialog and tries to save the mass spectra
*
* @param shell
* @param massSpectra
* @param fileName
* @throws NoConverterAvailableException
*/
public static void saveMassSpectra(Shell shell, IMassSpectra massSpectra, String fileName) throws NoConverterAvailableException {
Expand Down Expand Up @@ -246,6 +250,7 @@ public static void writeFile(Shell shell, final File file, final IMassSpectra ma
logger.warn(e.getCause());
} catch(InterruptedException e) {
logger.warn(e);
Thread.currentThread().interrupt();
}
File data = runnable.getData();
if(data == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.swtchart;bundle-version="0.8.0",
org.eclipse.swtchart.extensions;bundle-version="0.8.0",
org.eclipse.chemclipse.xxd.process;bundle-version="0.8.0",
org.eclipse.swt
org.eclipse.ui.ide;bundle-version="3.22.100"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-Vendor: ChemClipse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.eclipse.chemclipse.converter.exceptions.NoConverterAvailableException;
import org.eclipse.chemclipse.logging.core.Logger;
import org.eclipse.chemclipse.model.exceptions.ChromatogramIsNullException;
import org.eclipse.chemclipse.model.notifier.UpdateNotifier;
import org.eclipse.chemclipse.msd.converter.database.DatabaseConverter;
import org.eclipse.chemclipse.msd.converter.exceptions.NoMassSpectrumConverterAvailableException;
Expand All @@ -40,13 +39,11 @@
import org.eclipse.chemclipse.swt.ui.notifier.UpdateNotifierUI;
import org.eclipse.chemclipse.ux.extension.msd.ui.internal.support.DatabaseImportRunnable;
import org.eclipse.chemclipse.ux.extension.msd.ui.swt.MassSpectrumLibraryUI;
import org.eclipse.chemclipse.ux.extension.ui.editors.IChemClipseEditor;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.di.Persist;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
Expand All @@ -60,29 +57,35 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IURIEditorInput;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.inject.Inject;

public class DatabaseEditor implements IChemClipseEditor {
public class DatabaseEditor extends EditorPart {

public static final String ID = "org.eclipse.chemclipse.ux.extension.msd.ui.part.massSpectrumLibraryEditor";
public static final String CONTRIBUTION_URI = "bundleclass://org.eclipse.chemclipse.ux.extension.msd.ui/org.eclipse.chemclipse.ux.extension.msd.ui.editors.DatabaseEditor";
public static final String ICON_URI = ApplicationImageFactory.getInstance().getURI(IApplicationImage.IMAGE_MASS_SPECTRUM_DATABASE, IApplicationImageProvider.SIZE_16x16);
public static final String TOOLTIP = "Mass Spectrum Library - Detector Type: MSD";
//
private static final Logger logger = Logger.getLogger(DatabaseEditor.class);
//
private boolean isDirty = false;
/*
* Injected member in constructor
*/
@Inject
private MPart part;
@Inject
private MDirtyable dirtyable;
@Inject
private MApplication application;
@Inject
private EModelService modelService;
Expand All @@ -96,10 +99,6 @@ public class DatabaseEditor implements IChemClipseEditor {
private IMassSpectra massSpectra = null;
private ArrayList<EventHandler> registeredEventHandler;
private List<Object> objects = new ArrayList<>();
/*
* Showing additional info in tabs.
*/
private TabFolder tabFolder;

public void registerEvent(String topic, String property) {

Expand Down Expand Up @@ -146,28 +145,14 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte
try {
dialog.run(true, false, runnable);
} catch(InvocationTargetException e) {
saveAs();
doSaveAs();
} catch(InterruptedException e) {
logger.warn(e);
Thread.currentThread().interrupt();
}
}

@Override
public boolean saveAs() {

boolean saveSuccessful = false;
if(massSpectra != null) {
try {
saveSuccessful = DatabaseFileSupport.saveMassSpectra(massSpectra);
dirtyable.setDirty(!saveSuccessful);
} catch(NoConverterAvailableException e) {
logger.warn(e);
}
}
return saveSuccessful;
}

@Focus
public void setFocus() {

Expand All @@ -182,7 +167,7 @@ public void updateObjects(List<Object> objects, String topic) {
Object object = objects.get(0);
if(object instanceof IMassSpectra newMassSpectra) {
if(object == massSpectra) {
dirtyable.setDirty(newMassSpectra.isDirty());
isDirty = newMassSpectra.isDirty();
}
}
}
Expand All @@ -197,17 +182,6 @@ private void createControl(Composite parent) {
registerEvents();
}

private void createEditorPage() {

TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
tabItem.setText("Library");
//
massSpectrumLibraryUI = new MassSpectrumLibraryUI(tabFolder, SWT.NONE);
updateMassSpectrumListUI();
//
tabItem.setControl(massSpectrumLibraryUI);
}

private void createErrorMessagePage(Composite parent) {

Composite composite = new Composite(parent, SWT.NONE);
Expand All @@ -221,14 +195,12 @@ private void createPages(Composite parent) {
if(massSpectra != null && massSpectra.getMassSpectrum(1) != null) {
String label = ("".equals(massSpectra.getName())) ? massSpectrumFile.getName() : massSpectra.getName();
part.setLabel(label);
tabFolder = new TabFolder(parent, SWT.BOTTOM);
createEditorPage();
} else {
createErrorMessagePage(parent);
}
}

private void importMassSpectra(File file, boolean batch) throws ChromatogramIsNullException {
private void importMassSpectra(File file, boolean batch) {

ProgressMonitorDialog dialog = new ProgressMonitorDialog(DisplayUtils.getShell());
DatabaseImportRunnable runnable = new DatabaseImportRunnable(file);
Expand Down Expand Up @@ -336,12 +308,7 @@ private void saveMassSpectra(IProgressMonitor monitor, Shell shell) throws NoMas
monitor.subTask("Save Mass Spectra");
IProcessingInfo<File> processingInfo = DatabaseConverter.convert(massSpectrumFile, massSpectra, false, converterId, monitor);
try {
/*
* If no failures have occurred, set the dirty status to
* false.
*/
processingInfo.getProcessingResult();
dirtyable.setDirty(false);
isDirty = !processingInfo.hasErrorMessages();
} catch(TypeCastException e) {
logger.warn(e);
}
Expand All @@ -362,4 +329,74 @@ private void updateMassSpectrumListUI() {

massSpectrumLibraryUI.update(massSpectrumFile, massSpectra);
}

@Override
public void doSave(IProgressMonitor monitor) {

if(massSpectra != null) {
try {
boolean saveSuccessful = DatabaseFileSupport.saveMassSpectra(massSpectra);
isDirty = !saveSuccessful;
} catch(NoConverterAvailableException e) {
logger.warn(e);
}
}
}

@Override
public void doSaveAs() {

try {
DatabaseFileSupport.saveMassSpectra(Display.getCurrent().getActiveShell(), massSpectra, "Mass Spectra");
} catch(NoConverterAvailableException e) {
logger.warn(e);
}
}

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {

setSite(site);
setInput(input);
//
String fileName = input.getName();
fileName = fileName.substring(0, fileName.length() - 4);
setPartName(fileName);
//
if(input instanceof IFileEditorInput fileEditorInput) {
File file = fileEditorInput.getFile().getLocation().toFile();
importMassSpectra(file, true);
} else if(input instanceof IURIEditorInput uriEditorInput) {
File file = new File(uriEditorInput.getURI());
importMassSpectra(file, true);
} else {
throw new PartInitException("Unimplemented editor input " + input.getClass());
}
}

@Override
public boolean isDirty() {

return isDirty;
}

@Override
public boolean isSaveAsAllowed() {

return true;
}

@Override
public void createPartControl(Composite parent) {

TabFolder tabFolder = new TabFolder(parent, SWT.BOTTOM);
//
TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
tabItem.setText("Library");
//
massSpectrumLibraryUI = new MassSpectrumLibraryUI(tabFolder, SWT.NONE);
updateMassSpectrumListUI();
//
tabItem.setControl(massSpectrumLibraryUI);
}
}
Loading
Loading