2
|
1 |
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
|
2 |
// Use of this source code is governed by a BSD-style license that can be
|
|
3 |
// found in the LICENSE file.
|
|
4 |
|
|
5 |
package org.chromium.debug.ui;
|
|
6 |
|
|
7 |
import java.util.List;
|
|
8 |
|
|
9 |
import org.chromium.debug.core.model.Messages;
|
|
10 |
import org.eclipse.jface.dialogs.Dialog;
|
|
11 |
import org.eclipse.jface.dialogs.IDialogConstants;
|
|
12 |
import org.eclipse.swt.SWT;
|
|
13 |
import org.eclipse.swt.events.SelectionEvent;
|
|
14 |
import org.eclipse.swt.events.SelectionListener;
|
|
15 |
import org.eclipse.swt.layout.GridData;
|
|
16 |
import org.eclipse.swt.widgets.Composite;
|
|
17 |
import org.eclipse.swt.widgets.Control;
|
|
18 |
import org.eclipse.swt.widgets.Event;
|
|
19 |
import org.eclipse.swt.widgets.Label;
|
|
20 |
import org.eclipse.swt.widgets.Listener;
|
|
21 |
import org.eclipse.swt.widgets.Shell;
|
|
22 |
import org.eclipse.swt.widgets.Table;
|
|
23 |
import org.eclipse.swt.widgets.TableColumn;
|
|
24 |
import org.eclipse.swt.widgets.TableItem;
|
|
25 |
|
|
26 |
/**
|
|
27 |
* A dialog where users select which Chromium tab to attach to.
|
|
28 |
*/
|
|
29 |
class ChromiumTabSelectionDialog extends Dialog {
|
|
30 |
|
|
31 |
private final List<String> urls;
|
|
32 |
|
|
33 |
private Table table;
|
|
34 |
|
|
35 |
private int selectedLine = -1;
|
|
36 |
|
|
37 |
ChromiumTabSelectionDialog(Shell shell, List<String> urls) {
|
|
38 |
super(shell);
|
|
39 |
this.urls = urls;
|
|
40 |
}
|
|
41 |
|
|
42 |
@Override
|
|
43 |
protected void configureShell(Shell shell) {
|
|
44 |
super.configureShell(shell);
|
|
45 |
shell.setText(Messages.ChromiumTabSelectionDialog_DialogTitle);
|
|
46 |
}
|
|
47 |
|
|
48 |
@Override
|
|
49 |
public int open() {
|
|
50 |
return super.open();
|
|
51 |
}
|
|
52 |
|
|
53 |
@Override
|
|
54 |
public void create() {
|
|
55 |
super.create();
|
|
56 |
updateOkButton();
|
|
57 |
}
|
|
58 |
|
|
59 |
|
|
60 |
@Override
|
|
61 |
protected Control createDialogArea(Composite parent) {
|
|
62 |
Composite composite = (Composite) super.createDialogArea(parent);
|
|
63 |
Label label = new Label(composite, SWT.NONE);
|
|
64 |
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
|
|
65 |
label.setText(Messages.ChromiumTabSelectionDialog_TableTitle);
|
|
66 |
|
|
67 |
table = new Table(composite, SWT.VIRTUAL | SWT.BORDER | SWT.SINGLE);
|
|
68 |
table.setHeaderVisible(true);
|
|
69 |
table.setLinesVisible(true);
|
|
70 |
table.setItemCount(10);
|
|
71 |
final TableColumn urlColumn = new TableColumn(table, SWT.NONE);
|
|
72 |
urlColumn.setText(Messages.ChromiumTabSelectionDialog_UrlColumnName);
|
|
73 |
urlColumn.setWidth(400);
|
|
74 |
|
|
75 |
table.addListener(SWT.SetData, new Listener() {
|
|
76 |
public void handleEvent(Event event) {
|
|
77 |
if (table.isDisposed()) {
|
|
78 |
return;
|
|
79 |
}
|
|
80 |
processData(event);
|
|
81 |
}
|
|
82 |
|
|
83 |
private void processData(Event event) {
|
|
84 |
TableItem item = (TableItem) event.item;
|
|
85 |
int index = table.indexOf(item);
|
|
86 |
if (index < urls.size()) {
|
|
87 |
item.setText(urls.get(index));
|
|
88 |
GridData data = new GridData();
|
|
89 |
data.grabExcessHorizontalSpace = true;
|
|
90 |
item.setData(data);
|
|
91 |
if (index == 0) {
|
|
92 |
table.select(0);
|
|
93 |
}
|
|
94 |
}
|
|
95 |
}
|
|
96 |
});
|
|
97 |
table.addSelectionListener(new SelectionListener() {
|
|
98 |
public void widgetDefaultSelected(SelectionEvent e) {
|
|
99 |
okPressed();
|
|
100 |
}
|
|
101 |
public void widgetSelected(SelectionEvent e) {
|
|
102 |
}
|
|
103 |
});
|
|
104 |
|
|
105 |
table.setItemCount(urls.size());
|
|
106 |
table.clearAll();
|
|
107 |
|
|
108 |
return composite;
|
|
109 |
}
|
|
110 |
|
|
111 |
private void updateOkButton() {
|
|
112 |
this.getButton(IDialogConstants.OK_ID).setEnabled(urls.size() != 0);
|
|
113 |
}
|
|
114 |
|
|
115 |
@Override
|
|
116 |
protected void okPressed() {
|
|
117 |
selectedLine = table.getSelectionIndex();
|
|
118 |
super.okPressed();
|
|
119 |
}
|
|
120 |
|
|
121 |
int getSelectedLine() {
|
|
122 |
return selectedLine;
|
|
123 |
}
|
|
124 |
}
|