Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 276942
Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/discovery/ui/wizards/ConnectorDiscoveryWizardMainPage.java (+11 lines)
Lines 57-62 Link Here
57
import org.eclipse.mylyn.internal.discovery.ui.DiscoveryImages;
57
import org.eclipse.mylyn.internal.discovery.ui.DiscoveryImages;
58
import org.eclipse.mylyn.internal.discovery.ui.DiscoveryUi;
58
import org.eclipse.mylyn.internal.discovery.ui.DiscoveryUi;
59
import org.eclipse.mylyn.internal.discovery.ui.util.DiscoveryUiUtil;
59
import org.eclipse.mylyn.internal.discovery.ui.util.DiscoveryUiUtil;
60
import org.eclipse.mylyn.internal.discovery.ui.util.TraverseManager;
60
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
61
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
61
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonThemes;
62
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonThemes;
62
import org.eclipse.mylyn.internal.provisional.commons.ui.GradientCanvas;
63
import org.eclipse.mylyn.internal.provisional.commons.ui.GradientCanvas;
Lines 167-172 Link Here
167
168
168
	private ScrolledComposite bodyScrolledComposite;
169
	private ScrolledComposite bodyScrolledComposite;
169
170
171
	private TraverseManager traverseManager;
172
170
	public ConnectorDiscoveryWizardMainPage() {
173
	public ConnectorDiscoveryWizardMainPage() {
171
		super(ConnectorDiscoveryWizardMainPage.class.getSimpleName());
174
		super(ConnectorDiscoveryWizardMainPage.class.getSimpleName());
172
		setTitle(org.eclipse.mylyn.internal.discovery.ui.wizards.Messages.ConnectorDiscoveryWizardMainPage_connectorDiscovery);
175
		setTitle(org.eclipse.mylyn.internal.discovery.ui.wizards.Messages.ConnectorDiscoveryWizardMainPage_connectorDiscovery);
Lines 271-276 Link Here
271
			}
274
			}
272
275
273
		}
276
		}
277
		traverseManager = new TraverseManager(container);
274
		{ // container
278
		{ // container
275
			body = new Composite(container, SWT.NULL);
279
			body = new Composite(container, SWT.NULL);
276
			GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 480).applyTo(body);
280
			GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 480).applyTo(body);
Lines 519-524 Link Here
519
523
520
		bodyScrolledComposite.setContent(scrolledContents);
524
		bodyScrolledComposite.setContent(scrolledContents);
521
525
526
		body.getDisplay().asyncExec(new Runnable() {
527
			public void run() {
528
				traverseManager.manage(body);
529
			}
530
		});
531
522
		Dialog.applyDialogFont(body);
532
		Dialog.applyDialogFont(body);
523
		// we've changed it so it needs to know
533
		// we've changed it so it needs to know
524
		body.layout(true);
534
		body.layout(true);
Lines 671-676 Link Here
671
					connector.getProvider(), connector.getLicense()));
681
					connector.getProvider(), connector.getLicense()));
672
682
673
			infoLabel = new Label(connectorContainer, SWT.NULL);
683
			infoLabel = new Label(connectorContainer, SWT.NULL);
684
			infoLabel.setData(TraverseManager.KEY_ACCEPT_FOCUS, true);
674
			configureLook(infoLabel, background);
685
			configureLook(infoLabel, background);
675
			if (hasTooltip(connector)) {
686
			if (hasTooltip(connector)) {
676
				infoLabel.setImage(infoImage);
687
				infoLabel.setImage(infoImage);
(-)src/org/eclipse/mylyn/internal/discovery/ui/util/TraverseManager.java (+156 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies 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
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.discovery.ui.util;
13
14
import java.util.ArrayList;
15
import java.util.HashSet;
16
import java.util.List;
17
import java.util.Set;
18
import java.util.Stack;
19
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.custom.ScrolledComposite;
22
import org.eclipse.swt.events.DisposeEvent;
23
import org.eclipse.swt.events.DisposeListener;
24
import org.eclipse.swt.events.TraverseEvent;
25
import org.eclipse.swt.events.TraverseListener;
26
import org.eclipse.swt.widgets.Button;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Control;
29
import org.eclipse.swt.widgets.Display;
30
import org.eclipse.swt.widgets.Link;
31
import org.eclipse.swt.widgets.Shell;
32
import org.eclipse.swt.widgets.Text;
33
34
/**
35
 * @author David Green
36
 */
37
public class TraverseManager implements TraverseListener, DisposeListener {
38
39
	public static final String KEY_ACCEPT_FOCUS = TraverseManager.class.getName() + "#acceptFocus"; //$NON-NLS-1$
40
41
	private boolean handleEvent = true;
42
43
	private final Composite control;
44
45
	private final Set<Control> managedControls = new HashSet<Control>();
46
47
	public TraverseManager(Composite control) {
48
		this.control = control;
49
	}
50
51
	public void widgetDisposed(DisposeEvent e) {
52
		managedControls.remove(e.widget);
53
	}
54
55
	public void manage(Control control) {
56
		if (managedControls.add(control)) {
57
			control.addTraverseListener(this);
58
			control.addDisposeListener(this);
59
		}
60
		List<Control> focusCandidates = getFocusCandidates(null);
61
		for (Control c : focusCandidates) {
62
			if (managedControls.add(c)) {
63
				c.addTraverseListener(this);
64
				c.addDisposeListener(this);
65
			}
66
		}
67
	}
68
69
	public void keyTraversed(TraverseEvent event) {
70
		if (!handleEvent) {
71
			return;
72
		}
73
		Control focusControl = Display.getCurrent().getFocusControl();
74
		switch (event.detail) {
75
		case SWT.TRAVERSE_TAB_PREVIOUS:
76
		case SWT.TRAVERSE_ARROW_PREVIOUS: {
77
			List<Control> focusCandidates = getFocusCandidates(focusControl);
78
			if (focusCandidates.size() > 0) {
79
				Control nextFocus = focusCandidates.get(focusCandidates.size() - 1);
80
				if (!nextFocus.forceFocus()) {
81
					nextFocus.setFocus();
82
				}
83
			}
84
			break;
85
		}
86
		case SWT.TRAVERSE_TAB_NEXT:
87
		case SWT.TRAVERSE_ARROW_NEXT: {
88
			List<Control> focusCandidates = getFocusCandidates(null);
89
			int i = focusControl == null ? -1 : focusCandidates.indexOf(focusControl);
90
			if (i >= 0 && (i < (focusCandidates.size() - 1))) {
91
				Control nextFocus = focusCandidates.get(i + 1);
92
				if (!nextFocus.forceFocus()) {
93
					nextFocus.setFocus();
94
				}
95
			}
96
			break;
97
		}
98
		default:
99
			handleEvent = false;
100
			event.doit = true;
101
			Control c = control;
102
			Shell shell = c.getShell();
103
			while (c != null) {
104
				if (c.traverse(event.detail)) {
105
					break;
106
				}
107
				if (!event.doit || control == shell) {
108
					break;
109
				}
110
				c = c.getParent();
111
			}
112
			handleEvent = true;
113
			break;
114
		}
115
	}
116
117
	private List<Control> getFocusCandidates(Control stop) {
118
		List<Control> candidates = new ArrayList<Control>(20);
119
		// document order traversal (depth-first)
120
		Stack<Control> controls = new Stack<Control>();
121
		controls.push(control);
122
		while (!controls.isEmpty()) {
123
			Control c = controls.pop();
124
			if (c == stop) {
125
				break;
126
			}
127
			if (accept(c)) {
128
				if (c.isEnabled()) {
129
					candidates.add(c);
130
				}
131
			} else {
132
				if (c instanceof ScrolledComposite) {
133
					controls.push(((ScrolledComposite) c).getContent());
134
				} else if (c instanceof Composite) {
135
					Control[] children = ((Composite) c).getChildren();
136
					for (int x = children.length - 1; x >= 0; --x) {
137
						controls.push(children[x]);
138
					}
139
				}
140
			}
141
		}
142
		return candidates;
143
	}
144
145
	protected boolean accept(Control c) {
146
		Class<? extends Control> classOfControl = c.getClass();
147
		if (classOfControl == Button.class || classOfControl == Link.class || classOfControl == Text.class) {
148
			return true;
149
		}
150
		if (c.getData(KEY_ACCEPT_FOCUS) != null) {
151
			return true;
152
		}
153
		return false;
154
	}
155
156
}

Return to bug 276942