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 *.cal editor not being marked as dirty when changes were made #897

Merged
merged 3 commits into from
Feb 7, 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) 2014, 2020 Lablicate GmbH.
* Copyright (c) 2014, 2022 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -39,6 +39,7 @@ public class Activator extends AbstractActivatorUI {
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {

super.start(context);
Expand All @@ -51,6 +52,7 @@ public void start(BundleContext context) throws Exception {
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {

IEventBroker eventBroker = getEventBroker(context);
Expand Down Expand Up @@ -86,6 +88,7 @@ private EventHandler registerEventHandler(IEventBroker eventBroker, String prope

EventHandler eventHandler = new EventHandler() {

@Override
public void handleEvent(Event event) {

try {
Expand Down Expand Up @@ -125,4 +128,4 @@ private IEventBroker getEventBroker(BundleContext bundleContext) {
eclipseContext.set(Logger.class, null);
return eclipseContext.get(IEventBroker.class);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2018 Lablicate GmbH.
* Copyright (c) 2016, 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 @@ -12,11 +12,19 @@
package org.eclipse.chemclipse.chromatogram.xxd.calculator.supplier.amdiscalri.ui.editors;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PreDestroy;

import org.eclipse.chemclipse.chromatogram.xxd.calculator.supplier.amdiscalri.io.CalibrationFileReader;
import org.eclipse.chemclipse.chromatogram.xxd.calculator.supplier.amdiscalri.io.CalibrationFileWriter;
import org.eclipse.chemclipse.chromatogram.xxd.calculator.supplier.amdiscalri.ui.Activator;
import org.eclipse.chemclipse.logging.core.Logger;
import org.eclipse.chemclipse.model.columns.ISeparationColumnIndices;
import org.eclipse.chemclipse.support.events.IChemClipseEvents;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
Expand All @@ -26,24 +34,22 @@
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;

public class EditorCalibration extends MultiPageEditorPart {

private static final Logger logger = Logger.getLogger(EditorCalibration.class);
//
private PageCalibration pageCalibration;
private File file;
private boolean isDirty = false;
private boolean initialize = true;
//
private ISeparationColumnIndices separationColumnIndices;

@Override
protected void createPages() {

pageCalibration = new PageCalibration(getContainer());
int pageIndex = addPage(pageCalibration.getControl());
setPageText(pageIndex, "Retention Index Calibration (*.cal)");
setDirty(true);
}
//
private ArrayList<EventHandler> registeredEventHandler;
private List<Object> objects = new ArrayList<>();

@Override
public void doSave(IProgressMonitor monitor) {
Expand All @@ -69,23 +75,6 @@ public void doSaveAs() {
}
}

@Override
public boolean isSaveAsAllowed() {

return true;
}

@Override
public void setFocus() {

if(initialize) {
initialize = false;
CalibrationFileReader calibrationFileReader = new CalibrationFileReader();
separationColumnIndices = calibrationFileReader.parse(file);
pageCalibration.showData(file, separationColumnIndices);
}
}

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

Expand All @@ -94,7 +83,6 @@ public void init(IEditorSite site, IEditorInput input) throws PartInitException
fileName = fileName.substring(0, fileName.length() - 4);
setPartName(fileName);
if(input instanceof IFileEditorInput) {
//
IFileEditorInput fileEditorInput = (IFileEditorInput)input;
this.file = fileEditorInput.getFile().getLocation().toFile();
} else {
Expand All @@ -103,20 +91,117 @@ public void init(IEditorSite site, IEditorInput input) throws PartInitException
}

@Override
public void dispose() {
public boolean isDirty() {

super.dispose();
return isDirty;
}

@Override
public boolean isDirty() {
public boolean isSaveAsAllowed() {

return isDirty;
return true;
}

public void registerEvent(String topic, String property) {

registerEvent(topic, new String[]{property});
}

public void registerEvent(String topic, String[] properties) {

IEventBroker eventBroker = Activator.getDefault().getEventBroker();
if(eventBroker != null) {
registeredEventHandler.add(registerEventHandler(eventBroker, topic, properties));
}
}

public void registerEvents() {

registerEvent(IChemClipseEvents.TOPIC_RI_LIBRARY_UPDATE, IChemClipseEvents.EVENT_BROKER_DATA);
}

public void setDirty(boolean isDirty) {

this.isDirty = isDirty;
firePropertyChange(IEditorPart.PROP_DIRTY);
}

@Override
public void setFocus() {

if(initialize) {
initialize = false;
CalibrationFileReader calibrationFileReader = new CalibrationFileReader();
separationColumnIndices = calibrationFileReader.parse(file);
pageCalibration.showData(file, separationColumnIndices);
}
}

public void updateObjects(List<Object> objects) {

if(objects.size() == 1) {
Object object = objects.get(0);
if(object instanceof Object[]) {
Object[] array = (Object[])object;
if(array.length == 2) {
Object content = array[1];
if(content instanceof ISeparationColumnIndices) {
ISeparationColumnIndices separationColumnIndices = (ISeparationColumnIndices)content;
if(this.separationColumnIndices == separationColumnIndices) {
setDirty(separationColumnIndices.isDirty());
}
}
}
}
}
}

@PreDestroy
private void preDestroy() {

IEventBroker eventBroker = Activator.getDefault().getEventBroker();
if(eventBroker != null) {
for(EventHandler eventHandler : registeredEventHandler) {
eventBroker.unsubscribe(eventHandler);
}
}
}

private EventHandler registerEventHandler(IEventBroker eventBroker, String topic, String[] properties) {

EventHandler eventHandler = new EventHandler() {

@Override
public void handleEvent(Event event) {

try {
objects.clear();
for(String property : properties) {
Object object = event.getProperty(property);
objects.add(object);
}
update(topic);
} catch(Exception e) {
logger.warn(e + "\t" + event);
}
}
};
eventBroker.subscribe(topic, eventHandler);
return eventHandler;
}

private void update(String topic) {

updateObjects(objects);
}

@Override
protected void createPages() {

pageCalibration = new PageCalibration(getContainer());
int pageIndex = addPage(pageCalibration.getControl());
setPageText(pageIndex, "Retention Index Calibration (*.cal)");
registeredEventHandler = new ArrayList<>();
registerEvents();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2021 Lablicate GmbH.
* Copyright (c) 2018, 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 @@ -19,6 +19,7 @@ public abstract class AbstractSeparationColumn implements ISeparationColumn {
private String diameter = "";
private String phase = "";

@Override
public void copyFrom(ISeparationColumn separationColumn) {

if(separationColumn != null) {
Expand Down Expand Up @@ -105,33 +106,44 @@ public int hashCode() {
@Override
public boolean equals(Object obj) {

if(this == obj)
if(this == obj) {
return true;
if(obj == null)
}
if(obj == null) {
return false;
if(getClass() != obj.getClass())
}
if(getClass() != obj.getClass()) {
return false;
}
AbstractSeparationColumn other = (AbstractSeparationColumn)obj;
if(diameter == null) {
if(other.diameter != null)
if(other.diameter != null) {
return false;
} else if(!diameter.equals(other.diameter))
}
} else if(!diameter.equals(other.diameter)) {
return false;
}
if(length == null) {
if(other.length != null)
if(other.length != null) {
return false;
} else if(!length.equals(other.length))
}
} else if(!length.equals(other.length)) {
return false;
}
if(name == null) {
if(other.name != null)
if(other.name != null) {
return false;
} else if(!name.equals(other.name))
}
} else if(!name.equals(other.name)) {
return false;
}
if(phase == null) {
if(other.phase != null)
if(other.phase != null) {
return false;
} else if(!phase.equals(other.phase))
}
} else if(!phase.equals(other.phase)) {
return false;
}
return true;
}

Expand All @@ -140,4 +152,4 @@ public String toString() {

return "AbstractSeparationColumn [name=" + name + ", length=" + length + ", diameter=" + diameter + ", phase=" + phase + "]";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Lablicate GmbH.
* Copyright (c) 2018, 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 @@ -8,6 +8,7 @@
*
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Matthias Mailänder - dirty flagging
*******************************************************************************/
package org.eclipse.chemclipse.model.columns;

Expand All @@ -20,4 +21,8 @@ public interface ISeparationColumnIndices extends NavigableMap<Integer, IRetenti
void setSeparationColumn(ISeparationColumn separationColumn);

void put(IRetentionIndexEntry retentionIndexEntry);

boolean isDirty();

void setDirty(boolean isDirty);
}
Loading