1 11 package org.eclipse.jface.internal.text.link.contentassist; 12 13 14 import org.eclipse.swt.events.FocusEvent; 15 import org.eclipse.swt.events.FocusListener; 16 import org.eclipse.swt.events.SelectionEvent; 17 import org.eclipse.swt.events.SelectionListener; 18 import org.eclipse.swt.events.ShellAdapter; 19 import org.eclipse.swt.events.ShellEvent; 20 import org.eclipse.swt.widgets.Display; 21 import org.eclipse.swt.widgets.ScrollBar; 22 import org.eclipse.swt.widgets.Shell; 23 import org.eclipse.swt.widgets.Table; 24 25 26 32 class PopupCloser2 extends ShellAdapter implements FocusListener, SelectionListener { 33 34 35 private ContentAssistant2 fContentAssistant; 36 37 private Table fTable; 38 39 private ScrollBar fScrollbar; 40 41 private boolean fScrollbarClicked= false; 42 43 private Shell fShell; 44 45 46 52 public void install(ContentAssistant2 contentAssistant, Table table) { 53 fContentAssistant= contentAssistant; 54 fTable= table; 55 if (Helper2.okToUse(fTable)) { 56 Shell shell= fTable.getShell(); 57 if (Helper2.okToUse(shell)) { 58 fShell= shell; 59 fShell.addShellListener(this); 60 } 61 fTable.addFocusListener(this); 62 fScrollbar= fTable.getVerticalBar(); 63 if (fScrollbar != null) 64 fScrollbar.addSelectionListener(this); 65 } 66 } 67 68 71 public void uninstall() { 72 fContentAssistant= null; 73 if (Helper2.okToUse(fShell)) 74 fShell.removeShellListener(this); 75 fShell= null; 76 if (Helper2.okToUse(fScrollbar)) 77 fScrollbar.removeSelectionListener(this); 78 if (Helper2.okToUse(fTable)) 79 fTable.removeFocusListener(this); 80 } 81 82 85 public void widgetSelected(SelectionEvent e) { 86 fScrollbarClicked= true; 87 } 88 89 92 public void widgetDefaultSelected(SelectionEvent e) { 93 fScrollbarClicked= true; 94 } 95 96 99 public void focusGained(FocusEvent e) { 100 } 101 102 105 public void focusLost(final FocusEvent e) { 106 fScrollbarClicked= false; 107 Display d= fTable.getDisplay(); 108 d.asyncExec(new Runnable () { 109 public void run() { 110 if (Helper2.okToUse(fTable) && !fTable.isFocusControl() && !fScrollbarClicked && fContentAssistant != null) 111 fContentAssistant.popupFocusLost(e); 112 } 113 }); 114 } 115 116 120 public void shellDeactivated(ShellEvent e) { 121 if (fContentAssistant != null) 122 fContentAssistant.hide(); 123 } 124 125 126 130 public void shellClosed(ShellEvent e) { 131 if (fContentAssistant != null) 132 fContentAssistant.hide(); 133 } 134 } 135 | Popular Tags |