129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2005 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.internal.text.link.contentassist.PopupCloser2;
|
|
14
|
131
|
15 import dwtx.jface.internal.text.link.contentassist.IProposalListener; // packageimport
|
|
16 import dwtx.jface.internal.text.link.contentassist.LineBreakingReader; // packageimport
|
|
17 import dwtx.jface.internal.text.link.contentassist.CompletionProposalPopup2; // packageimport
|
|
18 import dwtx.jface.internal.text.link.contentassist.ContextInformationPopup2; // packageimport
|
|
19 import dwtx.jface.internal.text.link.contentassist.ContentAssistMessages; // packageimport
|
|
20 import dwtx.jface.internal.text.link.contentassist.Helper2; // packageimport
|
|
21 import dwtx.jface.internal.text.link.contentassist.IContentAssistListener2; // packageimport
|
|
22 import dwtx.jface.internal.text.link.contentassist.ContentAssistant2; // packageimport
|
|
23 import dwtx.jface.internal.text.link.contentassist.AdditionalInfoController2; // packageimport
|
|
24
|
|
25
|
129
|
26 import dwt.dwthelper.utils;
|
|
27
|
|
28
|
|
29 import dwt.events.FocusEvent;
|
|
30 import dwt.events.FocusListener;
|
|
31 import dwt.events.SelectionEvent;
|
|
32 import dwt.events.SelectionListener;
|
|
33 import dwt.events.ShellAdapter;
|
|
34 import dwt.events.ShellEvent;
|
|
35 import dwt.widgets.Display;
|
|
36 import dwt.widgets.ScrollBar;
|
|
37 import dwt.widgets.Shell;
|
|
38 import dwt.widgets.Table;
|
|
39
|
|
40
|
|
41 /**
|
|
42 * A generic closer class used to monitor various
|
|
43 * interface events in order to determine whether
|
|
44 * a content assistant should be terminated and all
|
|
45 * associated windows be closed.
|
|
46 */
|
|
47 class PopupCloser2 : ShellAdapter , FocusListener, SelectionListener {
|
|
48
|
|
49 /** The content assistant to be monitored */
|
|
50 private ContentAssistant2 fContentAssistant;
|
|
51 /** The table of a selector popup opened by the content assistant */
|
|
52 private Table fTable;
|
|
53 /** The scrollbar of the table for the selector popup */
|
|
54 private ScrollBar fScrollbar;
|
|
55 /** Indicates whether the scrollbar thumb has been grabbed. */
|
|
56 private bool fScrollbarClicked= false;
|
|
57 /** The shell on which some listeners are registered. */
|
|
58 private Shell fShell;
|
|
59
|
|
60
|
|
61 /**
|
|
62 * Installs this closer on the given table opened by the given content assistant.
|
|
63 *
|
|
64 * @param contentAssistant the content assistant
|
|
65 * @param table the table to be tracked
|
|
66 */
|
|
67 public void install(ContentAssistant2 contentAssistant, Table table) {
|
|
68 fContentAssistant= contentAssistant;
|
|
69 fTable= table;
|
|
70 if (Helper2.okToUse(fTable)) {
|
|
71 Shell shell= fTable.getShell();
|
|
72 if (Helper2.okToUse(shell)) {
|
|
73 fShell= shell;
|
|
74 fShell.addShellListener(this);
|
|
75 }
|
|
76 fTable.addFocusListener(this);
|
|
77 fScrollbar= fTable.getVerticalBar();
|
|
78 if (fScrollbar !is null)
|
|
79 fScrollbar.addSelectionListener(this);
|
|
80 }
|
|
81 }
|
|
82
|
|
83 /**
|
|
84 * Uninstalls this closer if previously installed.
|
|
85 */
|
|
86 public void uninstall() {
|
|
87 fContentAssistant= null;
|
|
88 if (Helper2.okToUse(fShell))
|
|
89 fShell.removeShellListener(this);
|
|
90 fShell= null;
|
|
91 if (Helper2.okToUse(fScrollbar))
|
|
92 fScrollbar.removeSelectionListener(this);
|
|
93 if (Helper2.okToUse(fTable))
|
|
94 fTable.removeFocusListener(this);
|
|
95 }
|
|
96
|
|
97 /*
|
|
98 * @see dwt.events.SelectionListener#widgetSelected(dwt.events.SelectionEvent)
|
|
99 */
|
|
100 public void widgetSelected(SelectionEvent e) {
|
|
101 fScrollbarClicked= true;
|
|
102 }
|
|
103
|
|
104 /*
|
|
105 * @see dwt.events.SelectionListener#widgetDefaultSelected(dwt.events.SelectionEvent)
|
|
106 */
|
|
107 public void widgetDefaultSelected(SelectionEvent e) {
|
|
108 fScrollbarClicked= true;
|
|
109 }
|
|
110
|
|
111 /*
|
|
112 * @see dwt.events.FocusListener#focusGained(dwt.events.FocusEvent)
|
|
113 */
|
|
114 public void focusGained(FocusEvent e) {
|
|
115 }
|
|
116
|
|
117 /*
|
|
118 * @see dwt.events.FocusListener#focusLost(dwt.events.FocusEvent)
|
|
119 */
|
158
|
120 public void focusLost(FocusEvent e) {
|
129
|
121 fScrollbarClicked= false;
|
|
122 Display d= fTable.getDisplay();
|
158
|
123 d.asyncExec(dgRunnable((FocusEvent e_) {
|
|
124 if (Helper2.okToUse(fTable) && !fTable.isFocusControl() && !fScrollbarClicked && fContentAssistant !is null)
|
|
125 fContentAssistant.popupFocusLost(e_);
|
|
126 }, e ));
|
129
|
127 }
|
|
128
|
|
129 /*
|
|
130 * @see dwt.events.ShellAdapter#shellDeactivated(dwt.events.ShellEvent)
|
|
131 * @since 3.1
|
|
132 */
|
|
133 public void shellDeactivated(ShellEvent e) {
|
|
134 if (fContentAssistant !is null)
|
|
135 fContentAssistant.hide();
|
|
136 }
|
|
137
|
|
138
|
|
139 /*
|
|
140 * @see dwt.events.ShellAdapter#shellClosed(dwt.events.ShellEvent)
|
|
141 * @since 3.1
|
|
142 */
|
|
143 public void shellClosed(ShellEvent e) {
|
|
144 if (fContentAssistant !is null)
|
|
145 fContentAssistant.hide();
|
|
146 }
|
|
147 }
|