-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add undo/redo for peak/scan deletion.
- Loading branch information
1 parent
a33485b
commit eeae90e
Showing
7 changed files
with
403 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...rc/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/handlers/RedoOperationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2008, 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 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/eplv10.html | ||
* | ||
* Contributors: | ||
* Dr. Philip Wenig - initial API and implementation | ||
* Matthias Mailänder - reimplemented using Eclipse API | ||
*******************************************************************************/ | ||
package org.eclipse.chemclipse.ux.extension.xxd.ui.internal.handlers; | ||
|
||
import javax.inject.Named; | ||
|
||
import org.eclipse.chemclipse.logging.core.Logger; | ||
import org.eclipse.chemclipse.progress.core.InfoType; | ||
import org.eclipse.chemclipse.progress.core.StatusLineLogger; | ||
import org.eclipse.chemclipse.support.ui.workbench.DisplayUtils; | ||
import org.eclipse.core.commands.ExecutionException; | ||
import org.eclipse.core.commands.operations.IOperationHistory; | ||
import org.eclipse.core.commands.operations.IUndoContext; | ||
import org.eclipse.e4.core.di.annotations.CanExecute; | ||
import org.eclipse.e4.core.di.annotations.Execute; | ||
import org.eclipse.e4.ui.di.UISynchronize; | ||
import org.eclipse.e4.ui.model.application.ui.basic.MPart; | ||
import org.eclipse.e4.ui.services.IServiceConstants; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.graphics.Cursor; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.ui.operations.IWorkbenchOperationSupport; | ||
|
||
public class RedoOperationHandler { | ||
|
||
private static final Logger logger = Logger.getLogger(RedoOperationHandler.class); | ||
|
||
@CanExecute | ||
boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart part) { | ||
|
||
IWorkbenchOperationSupport operationSupport = PlatformUI.getWorkbench().getOperationSupport(); | ||
return operationSupport.getOperationHistory().canRedo(operationSupport.getUndoContext()); | ||
} | ||
|
||
@Execute | ||
public void execute(UISynchronize uiSynchronize, final @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, @Named(IServiceConstants.ACTIVE_PART) MPart part) { | ||
|
||
StatusLineLogger.setInfo(InfoType.MESSAGE, "Start Redo Operation"); | ||
uiSynchronize.syncExec(new Runnable() { | ||
|
||
@Override | ||
public void run() { | ||
|
||
Cursor cursor = shell.getCursor(); | ||
try { | ||
Cursor cursorNew = DisplayUtils.getDisplay().getSystemCursor(SWT.CURSOR_WAIT); | ||
shell.setCursor(cursorNew); | ||
/* | ||
* Undo the operation. | ||
*/ | ||
IWorkbenchOperationSupport operationSupport = PlatformUI.getWorkbench().getOperationSupport(); | ||
IOperationHistory operationHistory = operationSupport.getOperationHistory(); | ||
IUndoContext undoContext = operationSupport.getUndoContext(); | ||
operationHistory.redo(undoContext, null, null); | ||
} catch(ExecutionException e) { | ||
logger.warn(e); | ||
} finally { | ||
shell.setCursor(cursor); | ||
} | ||
} | ||
}); | ||
StatusLineLogger.setInfo(InfoType.MESSAGE, "Redo Operation finished"); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...rc/org/eclipse/chemclipse/ux/extension/xxd/ui/internal/handlers/UndoOperationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2008, 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 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/eplv10.html | ||
* | ||
* Contributors: | ||
* Dr. Philip Wenig - initial API and implementation | ||
* Matthias Mailänder - reimplemented using Eclipse API | ||
*******************************************************************************/ | ||
package org.eclipse.chemclipse.ux.extension.xxd.ui.internal.handlers; | ||
|
||
import javax.inject.Named; | ||
|
||
import org.eclipse.chemclipse.logging.core.Logger; | ||
import org.eclipse.chemclipse.progress.core.InfoType; | ||
import org.eclipse.chemclipse.progress.core.StatusLineLogger; | ||
import org.eclipse.chemclipse.support.ui.workbench.DisplayUtils; | ||
import org.eclipse.core.commands.ExecutionException; | ||
import org.eclipse.core.commands.operations.IOperationHistory; | ||
import org.eclipse.core.commands.operations.IUndoContext; | ||
import org.eclipse.e4.core.di.annotations.CanExecute; | ||
import org.eclipse.e4.core.di.annotations.Execute; | ||
import org.eclipse.e4.ui.di.UISynchronize; | ||
import org.eclipse.e4.ui.model.application.ui.basic.MPart; | ||
import org.eclipse.e4.ui.services.IServiceConstants; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.graphics.Cursor; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.ui.operations.IWorkbenchOperationSupport; | ||
|
||
public class UndoOperationHandler { | ||
|
||
private static final Logger logger = Logger.getLogger(UndoOperationHandler.class); | ||
|
||
@CanExecute | ||
boolean canExecute() { | ||
|
||
IWorkbenchOperationSupport operationSupport = PlatformUI.getWorkbench().getOperationSupport(); | ||
return operationSupport.getOperationHistory().canUndo(operationSupport.getUndoContext()); | ||
} | ||
|
||
@Execute | ||
public void execute(UISynchronize uiSynchronize, final @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, @Named(IServiceConstants.ACTIVE_PART) MPart part) { | ||
|
||
StatusLineLogger.setInfo(InfoType.MESSAGE, "Start Undo Operation"); | ||
uiSynchronize.syncExec(new Runnable() { | ||
|
||
@Override | ||
public void run() { | ||
|
||
Cursor cursor = shell.getCursor(); | ||
try { | ||
Cursor cursorNew = DisplayUtils.getDisplay().getSystemCursor(SWT.CURSOR_WAIT); | ||
shell.setCursor(cursorNew); | ||
/* | ||
* Undo the operation. | ||
*/ | ||
IWorkbenchOperationSupport operationSupport = PlatformUI.getWorkbench().getOperationSupport(); | ||
IOperationHistory operationHistory = operationSupport.getOperationHistory(); | ||
IUndoContext undoContext = operationSupport.getUndoContext(); | ||
operationHistory.undo(undoContext, null, null); | ||
} catch(ExecutionException e) { | ||
logger.warn(e); | ||
} finally { | ||
shell.setCursor(cursor); | ||
} | ||
} | ||
}); | ||
StatusLineLogger.setInfo(InfoType.MESSAGE, "Undo Operation finished"); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
...xd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/operations/DeletePeaksOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021, 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 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Matthias Mailänder - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.chemclipse.ux.extension.xxd.ui.operations; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.chemclipse.model.core.IChromatogram; | ||
import org.eclipse.chemclipse.model.core.IPeak; | ||
import org.eclipse.chemclipse.model.selection.IChromatogramSelection; | ||
import org.eclipse.chemclipse.support.events.IChemClipseEvents; | ||
import org.eclipse.chemclipse.swt.ui.notifier.UpdateNotifierUI; | ||
import org.eclipse.core.commands.ExecutionException; | ||
import org.eclipse.core.commands.operations.AbstractOperation; | ||
import org.eclipse.core.runtime.IAdaptable; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.swt.widgets.Display; | ||
|
||
@SuppressWarnings("rawtypes") | ||
public class DeletePeaksOperation extends AbstractOperation { | ||
|
||
private IChromatogramSelection<?, ?> chromatogramSelection; | ||
private Display display; | ||
private List<IPeak> peaksToDelete; | ||
|
||
public DeletePeaksOperation(Display display, IChromatogramSelection chromatogramSelection, List<IPeak> peaksToDelete) { | ||
|
||
super("Delete Peaks"); | ||
this.display = display; | ||
this.chromatogramSelection = chromatogramSelection; | ||
this.peaksToDelete = peaksToDelete; | ||
} | ||
|
||
@Override | ||
public boolean canExecute() { | ||
|
||
return !peaksToDelete.isEmpty() && chromatogramSelection != null; | ||
} | ||
|
||
@Override | ||
public boolean canRedo() { | ||
|
||
return !peaksToDelete.isEmpty(); | ||
} | ||
|
||
@Override | ||
public boolean canUndo() { | ||
|
||
return !peaksToDelete.isEmpty(); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { | ||
|
||
IChromatogram chromatogram = chromatogramSelection.getChromatogram(); | ||
chromatogram.removePeaks(peaksToDelete); | ||
update("Peaks were deleted."); | ||
return Status.OK_STATUS; | ||
} | ||
|
||
private void update(String message) { | ||
|
||
chromatogramSelection.setSelectedPeak(null); | ||
// chromatogramSelection.update(true); | ||
// | ||
UpdateNotifierUI.update(display, chromatogramSelection); | ||
UpdateNotifierUI.update(display, IChemClipseEvents.TOPIC_IDENTIFICATION_TARGETS_UPDATE_SELECTION, message); | ||
} | ||
|
||
@Override | ||
public String getLabel() { | ||
|
||
return "Delete Peaks"; | ||
} | ||
|
||
@Override | ||
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { | ||
|
||
return execute(monitor, info); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { | ||
|
||
IChromatogram chromatogram = chromatogramSelection.getChromatogram(); | ||
for(IPeak peak : peaksToDelete) { | ||
chromatogram.addPeak(peak); | ||
} | ||
update("Peaks were added back again."); | ||
return Status.OK_STATUS; | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
...xd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/operations/DeleteScansOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Matthias Mailänder - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.chemclipse.ux.extension.xxd.ui.operations; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.commons.lang3.SerializationUtils; | ||
import org.eclipse.chemclipse.model.core.IScan; | ||
import org.eclipse.chemclipse.model.selection.IChromatogramSelection; | ||
import org.eclipse.chemclipse.support.events.IChemClipseEvents; | ||
import org.eclipse.chemclipse.swt.ui.notifier.UpdateNotifierUI; | ||
import org.eclipse.core.commands.ExecutionException; | ||
import org.eclipse.core.commands.operations.AbstractOperation; | ||
import org.eclipse.core.runtime.IAdaptable; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.swt.widgets.Display; | ||
|
||
@SuppressWarnings("rawtypes") | ||
public class DeleteScansOperation extends AbstractOperation { | ||
|
||
private IChromatogramSelection<?, ?> chromatogramSelection; | ||
private Display display; | ||
private List<IScan> scansToClear; | ||
private List<IScan> backupScans; | ||
|
||
public DeleteScansOperation(Display display, IChromatogramSelection chromatogramSelection, List<IScan> scansToClear) { | ||
|
||
super("Delete Scans"); | ||
this.display = display; | ||
this.chromatogramSelection = chromatogramSelection; | ||
this.scansToClear = scansToClear; | ||
backupScans = new ArrayList<IScan>(); | ||
} | ||
|
||
@Override | ||
public boolean canExecute() { | ||
|
||
return !scansToClear.isEmpty() && chromatogramSelection != null; | ||
} | ||
|
||
@Override | ||
public boolean canRedo() { | ||
|
||
return !scansToClear.isEmpty() && chromatogramSelection != null; | ||
} | ||
|
||
@Override | ||
public boolean canUndo() { | ||
|
||
return !scansToClear.isEmpty(); | ||
} | ||
|
||
@Override | ||
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { | ||
|
||
for(IScan scan : scansToClear) { | ||
IScan deepCopy = SerializationUtils.clone(scan); | ||
backupScans.add(deepCopy); | ||
scan.getTargets().clear(); | ||
} | ||
chromatogramSelection.setSelectedIdentifiedScan(null); | ||
update(); | ||
return Status.OK_STATUS; | ||
} | ||
|
||
private void update() { | ||
|
||
if(chromatogramSelection != null) { | ||
chromatogramSelection.setSelectedPeak(null); | ||
chromatogramSelection.update(true); | ||
// | ||
UpdateNotifierUI.update(display, chromatogramSelection); | ||
} | ||
UpdateNotifierUI.update(display, IChemClipseEvents.TOPIC_IDENTIFICATION_TARGETS_UPDATE_SELECTION, "Peaks were deleted."); | ||
} | ||
|
||
@Override | ||
public String getLabel() { | ||
|
||
return "Delete Scans"; | ||
} | ||
|
||
@Override | ||
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { | ||
|
||
return execute(monitor, info); | ||
} | ||
|
||
@Override | ||
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { | ||
|
||
for(IScan scan : backupScans) { | ||
chromatogramSelection.getChromatogram().getScan(scan.getScanNumber()).getTargets().addAll(scan.getTargets()); | ||
} | ||
update(); | ||
return Status.OK_STATUS; | ||
} | ||
} |
Oops, something went wrong.