Pressing control in Hop Web crashes the app
@@ -24,6 +24,7 @@ import org.apache.hop.core.logging.LogChannel;
import org.apache.hop.ui.hopgui.file.IHopFileTypeHandler;
import org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Control;
@@ -42,12 +43,10 @@ public class HopGuiKeyHandler extends KeyAdapter {
private KeyboardShortcut lastShortcut;
private long lastShortcutTime;
-
private HopGuiKeyHandler() {
this.parentObjects = new HashSet<>();
}
-
public static HopGuiKeyHandler getInstance() {
if (singleton == null) {
singleton = new HopGuiKeyHandler();
@@ -63,11 +62,13 @@ public class HopGuiKeyHandler extends KeyAdapter {
parentObjects.remove(parentObject);
}
- @Override public void keyPressed( KeyEvent event ) {
+ @Override
+ public void keyPressed(KeyEvent event) {
// TODO: allow for keyboard shortcut priorities for certain objects.
//
for (Object parentObject : parentObjects) {
- List<KeyboardShortcut> shortcuts = GuiRegistry.getInstance().getKeyboardShortcuts( parentObject.getClass().getName() );
+ List<KeyboardShortcut> shortcuts =
+ GuiRegistry.getInstance().getKeyboardShortcuts(parentObject.getClass().getName());
if (shortcuts != null) {
for (KeyboardShortcut shortcut : shortcuts) {
if (handleKey(parentObject, event, shortcut)) {
@@ -87,9 +88,15 @@ public class HopGuiKeyHandler extends KeyAdapter {
//
if (parentObject instanceof Control) {
Control control = (Control) parentObject;
+ try {
if (!control.isVisible()) {
return false;
}
+ } catch (SWTException e) {
+ // Invalid thread: none of our business, bail out
+ //
+ return false;
+ }
}
if (parentObject instanceof HopGuiPipelineGraph) {
@@ -131,7 +138,9 @@ public class HopGuiKeyHandler extends KeyAdapter {
return true; // Stop looking after 1 execution
}
} catch (Exception ex) {
- LogChannel.UI.logError( "Error calling keyboard shortcut method on parent object " + parentObject.toString(), ex );
+ LogChannel.UI.logError(
+ "Error calling keyboard shortcut method on parent object " + parentObject.toString(),
+ ex);
}
}
return false;
