comparison dwtx/jface/internal/text/link/contentassist/PopupCloser2.d @ 129:eb30df5ca28b

Added JFace Text sources
author Frank Benoit <benoit@tionex.de>
date Sat, 23 Aug 2008 19:10:48 +0200
parents
children c4fb132a086c
comparison
equal deleted inserted replaced
128:8df1d4193877 129:eb30df5ca28b
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
15 import dwt.dwthelper.utils;
16
17
18 import dwt.events.FocusEvent;
19 import dwt.events.FocusListener;
20 import dwt.events.SelectionEvent;
21 import dwt.events.SelectionListener;
22 import dwt.events.ShellAdapter;
23 import dwt.events.ShellEvent;
24 import dwt.widgets.Display;
25 import dwt.widgets.ScrollBar;
26 import dwt.widgets.Shell;
27 import dwt.widgets.Table;
28
29
30 /**
31 * A generic closer class used to monitor various
32 * interface events in order to determine whether
33 * a content assistant should be terminated and all
34 * associated windows be closed.
35 */
36 class PopupCloser2 : ShellAdapter , FocusListener, SelectionListener {
37
38 /** The content assistant to be monitored */
39 private ContentAssistant2 fContentAssistant;
40 /** The table of a selector popup opened by the content assistant */
41 private Table fTable;
42 /** The scrollbar of the table for the selector popup */
43 private ScrollBar fScrollbar;
44 /** Indicates whether the scrollbar thumb has been grabbed. */
45 private bool fScrollbarClicked= false;
46 /** The shell on which some listeners are registered. */
47 private Shell fShell;
48
49
50 /**
51 * Installs this closer on the given table opened by the given content assistant.
52 *
53 * @param contentAssistant the content assistant
54 * @param table the table to be tracked
55 */
56 public void install(ContentAssistant2 contentAssistant, Table table) {
57 fContentAssistant= contentAssistant;
58 fTable= table;
59 if (Helper2.okToUse(fTable)) {
60 Shell shell= fTable.getShell();
61 if (Helper2.okToUse(shell)) {
62 fShell= shell;
63 fShell.addShellListener(this);
64 }
65 fTable.addFocusListener(this);
66 fScrollbar= fTable.getVerticalBar();
67 if (fScrollbar !is null)
68 fScrollbar.addSelectionListener(this);
69 }
70 }
71
72 /**
73 * Uninstalls this closer if previously installed.
74 */
75 public void uninstall() {
76 fContentAssistant= null;
77 if (Helper2.okToUse(fShell))
78 fShell.removeShellListener(this);
79 fShell= null;
80 if (Helper2.okToUse(fScrollbar))
81 fScrollbar.removeSelectionListener(this);
82 if (Helper2.okToUse(fTable))
83 fTable.removeFocusListener(this);
84 }
85
86 /*
87 * @see dwt.events.SelectionListener#widgetSelected(dwt.events.SelectionEvent)
88 */
89 public void widgetSelected(SelectionEvent e) {
90 fScrollbarClicked= true;
91 }
92
93 /*
94 * @see dwt.events.SelectionListener#widgetDefaultSelected(dwt.events.SelectionEvent)
95 */
96 public void widgetDefaultSelected(SelectionEvent e) {
97 fScrollbarClicked= true;
98 }
99
100 /*
101 * @see dwt.events.FocusListener#focusGained(dwt.events.FocusEvent)
102 */
103 public void focusGained(FocusEvent e) {
104 }
105
106 /*
107 * @see dwt.events.FocusListener#focusLost(dwt.events.FocusEvent)
108 */
109 public void focusLost(final FocusEvent e) {
110 fScrollbarClicked= false;
111 Display d= fTable.getDisplay();
112 d.asyncExec(new Runnable() {
113 public void run() {
114 if (Helper2.okToUse(fTable) && !fTable.isFocusControl() && !fScrollbarClicked && fContentAssistant !is null)
115 fContentAssistant.popupFocusLost(e);
116 }
117 });
118 }
119
120 /*
121 * @see dwt.events.ShellAdapter#shellDeactivated(dwt.events.ShellEvent)
122 * @since 3.1
123 */
124 public void shellDeactivated(ShellEvent e) {
125 if (fContentAssistant !is null)
126 fContentAssistant.hide();
127 }
128
129
130 /*
131 * @see dwt.events.ShellAdapter#shellClosed(dwt.events.ShellEvent)
132 * @since 3.1
133 */
134 public void shellClosed(ShellEvent e) {
135 if (fContentAssistant !is null)
136 fContentAssistant.hide();
137 }
138 }