8080import org .eclipse .core .commands .ExecutionException ;
8181import org .eclipse .core .commands .operations .IOperationHistory ;
8282import org .eclipse .core .commands .operations .OperationHistoryFactory ;
83+ import org .eclipse .jface .bindings .TriggerSequence ;
84+ import org .eclipse .jface .bindings .keys .KeySequence ;
85+ import org .eclipse .jface .bindings .keys .KeyStroke ;
86+ import org .eclipse .jface .bindings .keys .SWTKeySupport ;
8387import org .eclipse .jface .viewers .IStructuredSelection ;
8488import org .eclipse .jface .viewers .StructuredSelection ;
8589import org .eclipse .jface .window .Window ;
99103import org .eclipse .swt .widgets .TableItem ;
100104import org .eclipse .swtchart .extensions .core .IKeyboardSupport ;
101105import org .eclipse .ui .PlatformUI ;
106+ import org .eclipse .ui .contexts .IContextService ;
107+ import org .eclipse .ui .keys .IBindingService ;
102108
103109public class ExtendedPeakScanListUI extends Composite implements IExtendedPartUI , ConfigurableUI <PeakScanListUIConfig > {
104110
@@ -108,6 +114,11 @@ public class ExtendedPeakScanListUI extends Composite implements IExtendedPartUI
108114 private static final String DESCRIPTION_PEAKS = "Number Peaks:" ;
109115 private static final String DESCRIPTION_SCANS = "Scans:" ;
110116
117+ private static final String KEY_CLASS_PREFIX = "org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList." ;
118+
119+ private IContextService contextService = (IContextService )PlatformUI .getWorkbench ().getService (IContextService .class );
120+ private IBindingService bindingService = PlatformUI .getWorkbench ().getService (IBindingService .class );
121+
111122 private AtomicReference <Composite > toolbarMain = new AtomicReference <>();
112123 private AtomicReference <Button > buttonToolbarInfo = new AtomicReference <>();
113124 private AtomicReference <InformationUI > toolbarInfoTop = new AtomicReference <>();
@@ -138,6 +149,7 @@ public class ExtendedPeakScanListUI extends Composite implements IExtendedPartUI
138149 public ExtendedPeakScanListUI (Composite parent , int style ) {
139150
140151 super (parent , style );
152+ contextService .activateContext ("org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList" );
141153 createControl ();
142154 }
143155
@@ -454,30 +466,28 @@ private void addKeyEventProcessors(Display display, ITableSettings tableSettings
454466 @ Override
455467 public void handleEvent (ExtendedTableViewer extendedTableViewer , KeyEvent e ) {
456468
457- if (e .keyCode == SWT .DEL ) {
469+ if (matchesKeyPress ("InternalStandard" , e )) {
470+ modifyInternalStandards (display );
471+ } else if (matchesKeyPress ("Classifier" , e )) {
472+ modifyClassifier (display );
473+ } else if (matchesKeyPress ("DeleteTargets" , e )) {
474+ deleteTargetsAll (e .display );
475+ } else if (matchesKeyPress ("Unknown" , e )) {
476+ addTargetsUnknown (e .display );
477+ } else if (matchesKeyPress ("Query" , e )) {
478+ scanIdentifierControl .get ().runIdentification (e .display );
479+ tableViewer .get ().refresh ();
480+ UpdateNotifierUI .update (display , chromatogramSelection );
481+ } else if (matchesKeyPress ("ActiveAnalysis" , e )) {
482+ setPeaksActiveForAnalysis (true );
483+ } else if (matchesKeyPress ("InactiveAnalysis" , e )) {
484+ setPeaksActiveForAnalysis (false );
485+ } else if (e .keyCode == SWT .DEL ) {
458486 deletePeaksOrIdentifications (display );
459487 } else if ((e .stateMask & SWT .MOD1 ) == SWT .MOD1 ) {
460- if (e .keyCode == IKeyboardSupport .KEY_CODE_LC_I ) {
461- if ((e .stateMask & SWT .MOD3 ) == SWT .MOD3 ) {
462- setPeaksActiveForAnalysis (false ); // CTRL + ALT + i
463- } else {
464- setPeaksActiveForAnalysis (true ); // CTRL + i
465- }
466- } else if (e .keyCode == IKeyboardSupport .KEY_CODE_LC_S ) {
467- modifyInternalStandards (display ); // CTRL + s
468- } else if (e .keyCode == IKeyboardSupport .KEY_CODE_LC_G ) {
469- modifyClassifier (display ); // CTRL + g
470- } else if (e .keyCode == IKeyboardSupport .KEY_CODE_LC_D ) {
471- deleteTargetsAll (e .display ); // CTRL + d
472- } else if (e .keyCode == IKeyboardSupport .KEY_CODE_LC_U ) {
473- addTargetsUnknown (e .display ); // CTRL + u
474- } else if (e .keyCode == IKeyboardSupport .KEY_CODE_LC_Q ) {
475- scanIdentifierControl .get ().runIdentification (e .display ); // CTRL + q
476- tableViewer .get ().refresh ();
477- UpdateNotifierUI .update (display , chromatogramSelection );
478- } else if (e .keyCode == IKeyboardSupport .KEY_CODE_LC_A ) {
488+ if (e .keyCode == IKeyboardSupport .KEY_CODE_LC_A ) {
479489 if (showPeakProfilesSelectionAll ) {
480- propagateSelection (display );
490+ propagateSelection (display ); // CTRL + A
481491 }
482492 }
483493 } else {
@@ -487,6 +497,18 @@ public void handleEvent(ExtendedTableViewer extendedTableViewer, KeyEvent e) {
487497 });
488498 }
489499
500+ private boolean matchesKeyPress (String commandSuffix , KeyEvent e ) {
501+
502+ TriggerSequence triggerSequence = bindingService .getBestActiveBindingFor (KEY_CLASS_PREFIX + commandSuffix );
503+ if (triggerSequence instanceof KeySequence keySequence ) {
504+ KeyStroke [] bindingStrokes = keySequence .getKeyStrokes ();
505+ int accelerator = SWTKeySupport .convertEventToUnmodifiedAccelerator (e );
506+ KeyStroke eventStroke = SWTKeySupport .convertAcceleratorToKeyStroke (accelerator );
507+ return bindingStrokes .length > 0 && bindingStrokes [0 ].equals (eventStroke );
508+ }
509+ return false ;
510+ }
511+
490512 private IOperationHistory getOperationHistory () {
491513
492514 return OperationHistoryFactory .getOperationHistory ();
0 commit comments