|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * Check list selection dialog |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracebuilder.view; |
|
20 |
|
21 import org.eclipse.jface.dialogs.TitleAreaDialog; |
|
22 import org.eclipse.jface.viewers.CheckboxTreeViewer; |
|
23 import org.eclipse.jface.viewers.IContentProvider; |
|
24 import org.eclipse.jface.viewers.ILabelProvider; |
|
25 import org.eclipse.swt.SWT; |
|
26 import org.eclipse.swt.events.SelectionAdapter; |
|
27 import org.eclipse.swt.events.SelectionEvent; |
|
28 import org.eclipse.swt.layout.GridData; |
|
29 import org.eclipse.swt.widgets.Combo; |
|
30 import org.eclipse.swt.widgets.Composite; |
|
31 import org.eclipse.swt.widgets.Control; |
|
32 import org.eclipse.swt.widgets.Shell; |
|
33 import org.eclipse.ui.PlatformUI; |
|
34 |
|
35 import com.nokia.tracebuilder.engine.CheckListDialogEntry; |
|
36 import com.nokia.tracebuilder.engine.TraceBuilderDialogs.CheckListDialogParameters; |
|
37 |
|
38 /** |
|
39 * Check list selection dialog |
|
40 * |
|
41 */ |
|
42 class CheckListSelectionDialog extends TitleAreaDialog { |
|
43 |
|
44 /** |
|
45 * Table width |
|
46 */ |
|
47 private static final int TREE_WIDTH = 400; // CodForChk_Dis_Magic |
|
48 |
|
49 /** |
|
50 * Table height |
|
51 */ |
|
52 private static final int TREE_HEIGHT = 300; // CodForChk_Dis_Magic |
|
53 |
|
54 /** |
|
55 * Content provider |
|
56 */ |
|
57 private IContentProvider contentProvider; |
|
58 |
|
59 /** |
|
60 * Label provider |
|
61 */ |
|
62 private ILabelProvider labelProvider; |
|
63 |
|
64 /** |
|
65 * Tree viewer |
|
66 */ |
|
67 private CheckboxTreeViewer viewer; |
|
68 |
|
69 /** |
|
70 * Dialog parameters |
|
71 */ |
|
72 private CheckListDialogParameters parameters; |
|
73 |
|
74 /** |
|
75 * Root selector combo box |
|
76 */ |
|
77 private Combo rootSelector; |
|
78 |
|
79 /** |
|
80 * Constructor |
|
81 * |
|
82 * @param shell |
|
83 * the dialog shell |
|
84 * @param parameters |
|
85 * dialog parameters |
|
86 */ |
|
87 CheckListSelectionDialog(Shell shell, CheckListDialogParameters parameters) { |
|
88 super(shell); |
|
89 contentProvider = new CheckListSelectionDialogContentProvider(); |
|
90 labelProvider = new CheckListSelectionDialogLabelProvider(); |
|
91 this.parameters = parameters; |
|
92 } |
|
93 |
|
94 /* |
|
95 * (non-Javadoc) |
|
96 * |
|
97 * @see org.eclipse.jface.dialogs.TitleAreaDialog# |
|
98 * createContents(org.eclipse.swt.widgets.Composite) |
|
99 */ |
|
100 @Override |
|
101 protected Control createContents(Composite parent) { |
|
102 Control control = super.createContents(parent); |
|
103 // Registers the help context to the root control |
|
104 PlatformUI.getWorkbench().getHelpSystem().setHelp(control, |
|
105 TraceViewHelp.getCheckListDialogContext(parameters.dialogType)); |
|
106 return control; |
|
107 } |
|
108 |
|
109 /* |
|
110 * (non-Javadoc) |
|
111 * |
|
112 * @see org.eclipse.jface.dialogs.TitleAreaDialog# |
|
113 * createDialogArea(org.eclipse.swt.widgets.Composite) |
|
114 */ |
|
115 @Override |
|
116 protected Control createDialogArea(Composite parent) { |
|
117 setTitle(TraceViewMessages.getCheckListTitle(parameters.dialogType)); |
|
118 setMessage(TraceViewMessages.getCheckListText(parameters.dialogType)); |
|
119 getShell().setText( |
|
120 TraceViewMessages.getCheckListTitle(parameters.dialogType)); |
|
121 Composite composite = (Composite) super.createDialogArea(parent); |
|
122 if (parameters.showRoot) { |
|
123 createRootSelector(composite); |
|
124 } |
|
125 viewer = new CheckboxTreeViewer(composite, SWT.BORDER); |
|
126 GridData data = new GridData(GridData.FILL_BOTH); |
|
127 data.heightHint = TREE_HEIGHT; |
|
128 data.widthHint = TREE_WIDTH; |
|
129 viewer.getTree().setLayoutData(data); |
|
130 viewer.setContentProvider(contentProvider); |
|
131 viewer.setLabelProvider(labelProvider); |
|
132 viewer.setInput(parameters.rootItems.get(0)); |
|
133 ((CheckListSelectionDialogContentProvider) contentProvider) |
|
134 .initializeCheckStates(parameters.expandLevel); |
|
135 return composite; |
|
136 } |
|
137 |
|
138 /** |
|
139 * Creates the root selector combo box |
|
140 * |
|
141 * @param composite |
|
142 * the parent composite |
|
143 */ |
|
144 private void createRootSelector(Composite composite) { |
|
145 rootSelector = new Combo(composite, SWT.BORDER | SWT.READ_ONLY); |
|
146 GridData gridData = new GridData(); |
|
147 gridData.horizontalAlignment = GridData.FILL; |
|
148 rootSelector.setLayoutData(gridData); |
|
149 for (int i = 0; i < parameters.rootItems.size(); i++) { |
|
150 rootSelector |
|
151 .add(parameters.rootItems.get(i).getObject().toString()); |
|
152 } |
|
153 rootSelector.select(0); |
|
154 rootSelector.addSelectionListener(new SelectionAdapter() { |
|
155 |
|
156 /* |
|
157 * (non-Javadoc) |
|
158 * |
|
159 * @see org.eclipse.swt.events.SelectionAdapter# |
|
160 * widgetSelected(org.eclipse.swt.events.SelectionEvent) |
|
161 */ |
|
162 @Override |
|
163 public void widgetSelected(SelectionEvent e) { |
|
164 CheckListDialogEntry entry = parameters.rootItems |
|
165 .get(rootSelector.getSelectionIndex()); |
|
166 viewer.setInput(entry); |
|
167 } |
|
168 |
|
169 }); |
|
170 } |
|
171 |
|
172 } |