1 11 package org.eclipse.jface.text.contentassist; 12 13 import org.eclipse.swt.events.FocusEvent; 14 import org.eclipse.swt.events.FocusListener; 15 import org.eclipse.swt.events.SelectionEvent; 16 import org.eclipse.swt.events.SelectionListener; 17 import org.eclipse.swt.events.ShellAdapter; 18 import org.eclipse.swt.events.ShellEvent; 19 import org.eclipse.swt.widgets.Display; 20 import org.eclipse.swt.widgets.ScrollBar; 21 import org.eclipse.swt.widgets.Shell; 22 import org.eclipse.swt.widgets.Table; 23 24 25 31 class PopupCloser extends ShellAdapter implements FocusListener, SelectionListener { 32 33 34 private ContentAssistant fContentAssistant; 35 36 private Table fTable; 37 38 private ScrollBar fScrollbar; 39 40 private boolean fScrollbarClicked= false; 41 45 private Shell fShell; 46 47 53 public void install(ContentAssistant contentAssistant, Table table) { 54 fContentAssistant= contentAssistant; 55 fTable= table; 56 if (Helper.okToUse(fTable)) { 57 Shell shell= fTable.getShell(); 58 if (Helper.okToUse(shell)) { 59 fShell= shell; 60 fShell.addShellListener(this); 61 } 62 63 fTable.addFocusListener(this); 64 fScrollbar= fTable.getVerticalBar(); 65 if (fScrollbar != null) 66 fScrollbar.addSelectionListener(this); 67 } 68 } 69 70 73 public void uninstall() { 74 fContentAssistant= null; 75 if (Helper.okToUse(fShell)) 76 fShell.removeShellListener(this); 77 fShell= null; 78 if (Helper.okToUse(fScrollbar)) 79 fScrollbar.removeSelectionListener(this); 80 if (Helper.okToUse(fTable)) 81 fTable.removeFocusListener(this); 82 } 83 84 87 public void widgetSelected(SelectionEvent e) { 88 fScrollbarClicked= true; 89 } 90 91 94 public void widgetDefaultSelected(SelectionEvent e) { 95 fScrollbarClicked= true; 96 } 97 98 101 public void focusGained(FocusEvent e) { 102 } 103 104 107 public void focusLost(final FocusEvent e) { 108 fScrollbarClicked= false; 109 Display d= fTable.getDisplay(); 110 d.asyncExec(new Runnable () { 111 public void run() { 112 if (Helper.okToUse(fTable) && !fTable.isFocusControl() && !fScrollbarClicked && fContentAssistant != null) 113 fContentAssistant.popupFocusLost(e); 114 } 115 }); 116 } 117 118 122 public void shellDeactivated(ShellEvent e) { 123 if (fContentAssistant != null) 124 fContentAssistant.hide(); 125 } 126 127 128 132 public void shellClosed(ShellEvent e) { 133 if (fContentAssistant != null) 134 fContentAssistant.hide(); 135 } 136 } 137 | Popular Tags |