|
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 * Dialog interface implementation |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracebuilder.view; |
|
20 |
|
21 import java.io.File; |
|
22 |
|
23 import org.eclipse.jface.dialogs.IDialogConstants; |
|
24 import org.eclipse.jface.dialogs.MessageDialog; |
|
25 import org.eclipse.swt.SWT; |
|
26 import org.eclipse.swt.widgets.DirectoryDialog; |
|
27 import org.eclipse.swt.widgets.FileDialog; |
|
28 import org.eclipse.swt.widgets.Shell; |
|
29 |
|
30 import com.nokia.tracebuilder.engine.TraceBuilderDialogs; |
|
31 |
|
32 /** |
|
33 * Dialog interface implementation |
|
34 * |
|
35 */ |
|
36 final class TraceViewDialogs implements TraceBuilderDialogs { |
|
37 |
|
38 /** |
|
39 * Trace view |
|
40 */ |
|
41 private TraceView view; |
|
42 |
|
43 /** |
|
44 * Constructor |
|
45 * |
|
46 * @param view |
|
47 * trace view |
|
48 */ |
|
49 TraceViewDialogs(TraceView view) { |
|
50 this.view = view; |
|
51 } |
|
52 |
|
53 /* |
|
54 * (non-Javadoc) |
|
55 * |
|
56 * @see com.nokia.tracebuilder.engine.TraceBuilderDialogs# |
|
57 * showConfirmationQuery(com.nokia.tracebuilder.engine.TraceBuilderDialogs.QueryDialogParameters) |
|
58 */ |
|
59 public int showConfirmationQuery(QueryDialogParameters parameters) { |
|
60 Shell shell = view.getShell(); |
|
61 int ret = CANCEL; |
|
62 if (shell != null) { |
|
63 if (parameters instanceof DirectoryDialogQueryParameters) { |
|
64 ret = showDirectoryQuery((DirectoryDialogQueryParameters) parameters); |
|
65 } else if (parameters instanceof FileDialogQueryParameters) { |
|
66 ret = showFileQuery((FileDialogQueryParameters) parameters); |
|
67 } else if (parameters instanceof ExtendedQueryParameters) { |
|
68 ret = showExtendedQueryDialog(parameters, shell); |
|
69 } else { |
|
70 if (MessageDialog.openQuestion(shell, Messages |
|
71 .getString("TraceView.TraceBuilder"), //$NON-NLS-1$ |
|
72 TraceViewMessages.getConfirmationQueryText(parameters))) { |
|
73 ret = OK; |
|
74 } |
|
75 } |
|
76 } |
|
77 return ret; |
|
78 } |
|
79 |
|
80 /* |
|
81 * (non-Javadoc) |
|
82 * |
|
83 * @see com.nokia.tracebuilder.engine.TraceBuilderDialogs# |
|
84 * showErrorMessage(java.lang.String) |
|
85 */ |
|
86 public void showErrorMessage(String message) { |
|
87 Shell shell = view.getShell(); |
|
88 if (shell != null) { |
|
89 shell.getDisplay().asyncExec( |
|
90 new MessageDialogRunnable(shell, message)); |
|
91 } |
|
92 } |
|
93 |
|
94 /* |
|
95 * (non-Javadoc) |
|
96 * |
|
97 * @see com.nokia.tracebuilder.engine.TraceBuilderDialogs# |
|
98 * showCheckList(com.nokia.tracebuilder.engine.TraceBuilderDialogs.CheckListDialogType, |
|
99 * java.util.List, java.util.List) |
|
100 */ |
|
101 public int showCheckList(CheckListDialogParameters parameters) { |
|
102 Shell shell = view.getShell(); |
|
103 int ret = CANCEL; |
|
104 if (shell != null) { |
|
105 CheckListSelectionDialog dlg = new CheckListSelectionDialog(shell, |
|
106 parameters); |
|
107 int result = dlg.open(); |
|
108 if (result == IDialogConstants.OK_ID |
|
109 || result == IDialogConstants.YES_ID) { |
|
110 ret = OK; |
|
111 } |
|
112 } |
|
113 return ret; |
|
114 } |
|
115 |
|
116 /** |
|
117 * Shows a directory query |
|
118 * |
|
119 * @param parameters |
|
120 * the query parameters |
|
121 * @return OK / CANCEL |
|
122 */ |
|
123 private int showDirectoryQuery(DirectoryDialogQueryParameters parameters) { |
|
124 Shell shell = view.getShell(); |
|
125 int ret = CANCEL; |
|
126 if (shell != null) { |
|
127 DirectoryDialog dd = new DirectoryDialog(shell); |
|
128 dd.setMessage(TraceViewMessages |
|
129 .getConfirmationQueryText(parameters)); |
|
130 String res = dd.open(); |
|
131 if (res != null) { |
|
132 parameters.path = res; |
|
133 ret = OK; |
|
134 } |
|
135 } |
|
136 return ret; |
|
137 } |
|
138 |
|
139 /** |
|
140 * Shows file selection dialog |
|
141 * |
|
142 * @param parameters |
|
143 * the parameters |
|
144 * @return OK / CANCEL |
|
145 */ |
|
146 private int showFileQuery(FileDialogQueryParameters parameters) { |
|
147 Shell shell = view.getShell(); |
|
148 int ret = CANCEL; |
|
149 if (shell != null) { |
|
150 FileDialog fd = new FileDialog(shell, SWT.SINGLE | SWT.OPEN); |
|
151 File f = new File(parameters.path); |
|
152 if (f.isDirectory()) { |
|
153 fd.setFilterPath(f.getPath()); |
|
154 } else { |
|
155 fd.setFilterPath(f.getParent()); |
|
156 } |
|
157 if (parameters.filters != null) { |
|
158 fd.setFilterNames(parameters.filterTitles); |
|
159 fd.setFilterExtensions(parameters.filters); |
|
160 } |
|
161 fd.setText(TraceViewMessages.getConfirmationQueryText(parameters)); |
|
162 String res = fd.open(); |
|
163 if (res != null) { |
|
164 parameters.path = res; |
|
165 ret = OK; |
|
166 } |
|
167 } |
|
168 return ret; |
|
169 } |
|
170 |
|
171 /** |
|
172 * Shows a query dialog, where the buttons have been defined by client |
|
173 * |
|
174 * @param parameters |
|
175 * the dialog parameters |
|
176 * @param shell |
|
177 * the parent shell |
|
178 * @return the index of the selected button |
|
179 */ |
|
180 private int showExtendedQueryDialog(QueryDialogParameters parameters, |
|
181 Shell shell) { |
|
182 MessageDialog md = new MessageDialog( |
|
183 shell, |
|
184 Messages.getString("TraceView.TraceBuilder"), //$NON-NLS-1$ |
|
185 null, ((ExtendedQueryParameters) parameters).message, |
|
186 MessageDialog.QUESTION, |
|
187 ((ExtendedQueryParameters) parameters).buttonTitles, 0); |
|
188 // Returns the index of the button defined in extended query parameters |
|
189 return md.open(); |
|
190 } |
|
191 |
|
192 } |