|
1 /* |
|
2 * Copyright (c) 2010 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 the License "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 */ |
|
17 |
|
18 package com.nokia.carbide.cpp.internal.pi.wizards.ui; |
|
19 |
|
20 import java.util.List; |
|
21 |
|
22 import org.eclipse.core.runtime.IPath; |
|
23 import org.eclipse.core.runtime.IStatus; |
|
24 import org.eclipse.core.runtime.Path; |
|
25 import org.eclipse.core.runtime.Status; |
|
26 import org.eclipse.jface.dialogs.ErrorDialog; |
|
27 import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
28 import org.eclipse.jface.viewers.IStructuredContentProvider; |
|
29 import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
30 import org.eclipse.jface.viewers.TableViewer; |
|
31 import org.eclipse.jface.viewers.Viewer; |
|
32 import org.eclipse.swt.SWT; |
|
33 import org.eclipse.swt.events.SelectionAdapter; |
|
34 import org.eclipse.swt.events.SelectionEvent; |
|
35 import org.eclipse.swt.layout.GridData; |
|
36 import org.eclipse.swt.layout.GridLayout; |
|
37 import org.eclipse.swt.widgets.Button; |
|
38 import org.eclipse.swt.widgets.Composite; |
|
39 import org.eclipse.swt.widgets.DirectoryDialog; |
|
40 import org.eclipse.swt.widgets.FileDialog; |
|
41 import org.eclipse.swt.widgets.Table; |
|
42 import org.eclipse.swt.widgets.TableColumn; |
|
43 |
|
44 import com.nokia.carbide.cpp.pi.PiPlugin; |
|
45 |
|
46 /** |
|
47 * Provides content of the profile data file selection from file system group |
|
48 */ |
|
49 public class FileSelectionGroup extends AbstractBaseGroup { |
|
50 |
|
51 private TableViewer profileDataTable; |
|
52 |
|
53 /** |
|
54 * Constructor |
|
55 * |
|
56 * @param parent instance of the parent composite |
|
57 * @param wizardSettings instance of the INewPIWizardSettings |
|
58 */ |
|
59 public FileSelectionGroup(Composite parent, |
|
60 INewPIWizardSettings wizardSettings) { |
|
61 super(parent, wizardSettings); |
|
62 } |
|
63 |
|
64 /* |
|
65 * (non-Javadoc) |
|
66 * @see com.nokia.carbide.cpp.internal.pi.wizards.ui.AbstractBaseGroup#createContent() |
|
67 */ |
|
68 protected void createContent() { |
|
69 GridLayout gridLayout = new GridLayout(); |
|
70 gridLayout.numColumns = 2; |
|
71 this.setLayout(gridLayout); |
|
72 this.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
73 this.setText(Messages.getString("FileSelectionGroup.title")); //$NON-NLS-1$ |
|
74 |
|
75 |
|
76 profileDataTable = new TableViewer(this, SWT.BORDER| SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL |
|
77 | SWT.FULL_SELECTION); |
|
78 |
|
79 TableColumn column = new TableColumn(profileDataTable.getTable(), SWT.NONE); |
|
80 column.setText(Messages.getString("FileSelectionGroup.profilerDataFileName")); //$NON-NLS-1$ |
|
81 column.setWidth(200); |
|
82 column.setResizable(true); |
|
83 column.setMoveable(true); |
|
84 column.addSelectionListener(new SelectionAdapter(){ |
|
85 public void widgetSelected(SelectionEvent e) |
|
86 { |
|
87 if (!(e.widget instanceof TableColumn)) |
|
88 return; |
|
89 ((AbstractBaseSorter)profileDataTable.getSorter()).doSort(0); |
|
90 profileDataTable.refresh(); |
|
91 |
|
92 } |
|
93 }); |
|
94 |
|
95 column = new TableColumn(profileDataTable.getTable(), SWT.NONE); |
|
96 column.setText(Messages.getString("FileSelectionGroup.profilerDataFilePath")); //$NON-NLS-1$ |
|
97 column.setWidth(300); |
|
98 column.setResizable(true); |
|
99 column.setMoveable(true); |
|
100 column.addSelectionListener(new SelectionAdapter(){ |
|
101 public void widgetSelected(SelectionEvent e) |
|
102 { |
|
103 if (!(e.widget instanceof TableColumn)) |
|
104 return; |
|
105 ((AbstractBaseSorter)profileDataTable.getSorter()).doSort(1); |
|
106 profileDataTable.refresh(); |
|
107 |
|
108 } |
|
109 }); |
|
110 |
|
111 GridData fileLogsTableGridData = new GridData(GridData.FILL_BOTH); |
|
112 profileDataTable.getTable().setLayoutData(fileLogsTableGridData); |
|
113 profileDataTable.getTable().setHeaderVisible(true); |
|
114 profileDataTable.getTable().setLinesVisible(true); |
|
115 profileDataTable.setContentProvider(new IStructuredContentProvider(){ |
|
116 public Object[] getElements(Object inputElement) { |
|
117 if (inputElement instanceof List<?>){ |
|
118 return ((List<?>)inputElement).toArray(); |
|
119 } |
|
120 return new Object[0]; |
|
121 } |
|
122 public void dispose() { |
|
123 } |
|
124 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|
125 } |
|
126 |
|
127 }); |
|
128 |
|
129 profileDataTable.addSelectionChangedListener(new ISelectionChangedListener() { |
|
130 public void selectionChanged(SelectionChangedEvent event) { |
|
131 if(profileDataTable.getTable().getSelectionCount() == 1){ |
|
132 wizardSettings.validatePage(); |
|
133 |
|
134 } |
|
135 } |
|
136 }); |
|
137 |
|
138 |
|
139 profileDataTable.setSorter( new AbstractBaseSorter(profileDataTable.getTable(), 0){ |
|
140 @Override |
|
141 public int compare(Viewer viewer, Object e1, Object e2) { |
|
142 IPath path1 = (IPath)e1; |
|
143 IPath path2 = (IPath)e2; |
|
144 int returnCode = 0; |
|
145 switch (column) { |
|
146 case 0: |
|
147 returnCode = path1.lastSegment().compareTo(path2.lastSegment()); |
|
148 break; |
|
149 case 1: |
|
150 returnCode = path1.removeLastSegments(1).toOSString().compareTo(path2.removeLastSegments(1).toOSString()); |
|
151 break; |
|
152 |
|
153 default: |
|
154 break; |
|
155 } |
|
156 if (!sortAscending) |
|
157 returnCode = -returnCode; |
|
158 return returnCode; |
|
159 } |
|
160 }); |
|
161 |
|
162 profileDataTable.setLabelProvider(new AbstractLabelProvider() { |
|
163 public String getColumnText(Object element, int columnIndex) { |
|
164 IPath path = (IPath)element; |
|
165 switch (columnIndex) { |
|
166 case 0: |
|
167 return path.lastSegment(); |
|
168 case 1: |
|
169 return path.removeLastSegments(1).toOSString(); |
|
170 default: |
|
171 break; |
|
172 } |
|
173 return ""; //$NON-NLS-1$ |
|
174 } |
|
175 }); |
|
176 |
|
177 |
|
178 Composite fileSelectionButtonComposite = new Composite(this, SWT.NONE); |
|
179 GridLayout threadButtonLayout = new GridLayout(); |
|
180 GridData fileSelectionButtonGridData = new GridData( |
|
181 GridData.HORIZONTAL_ALIGN_FILL); |
|
182 fileSelectionButtonComposite.setLayoutData(fileSelectionButtonGridData); |
|
183 fileSelectionButtonComposite.setLayout(threadButtonLayout); |
|
184 threadButtonLayout.numColumns = 1; |
|
185 |
|
186 // Add file button |
|
187 Button addFileButton = new Button(fileSelectionButtonComposite, |
|
188 SWT.PUSH); |
|
189 addFileButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
190 addFileButton.setText(Messages.getString("FileSelectionGroup.actionAddFile")); //$NON-NLS-1$ |
|
191 addFileButton.addSelectionListener(new SelectionAdapter() { |
|
192 public void widgetSelected(SelectionEvent e) { |
|
193 // open file dialog for selecting a crash file |
|
194 FileDialog dialog = new FileDialog(getShell(), SWT.MULTI); |
|
195 dialog.setText(Messages.getString("FileSelectionGroup.dialogFileTitle")); //$NON-NLS-1$ |
|
196 String[] filterExt = { "*.dat", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$ |
|
197 dialog.setFilterExtensions(filterExt); |
|
198 String path = dialog.open(); |
|
199 if(path != null){ |
|
200 IPath folder = new Path(path).removeLastSegments(1); |
|
201 for(String fileName: dialog.getFileNames()){ |
|
202 try { |
|
203 addProfileDataFile(folder.append(fileName)); |
|
204 } catch (IllegalArgumentException iae) { |
|
205 IStatus status = new Status(Status.ERROR, |
|
206 PiPlugin.PLUGIN_ID, iae.getMessage()); |
|
207 ErrorDialog.openError(getShell(), |
|
208 Messages.getString("FileSelectionGroup.performanceInvestigator"), null, status); //$NON-NLS-1$ |
|
209 } |
|
210 } |
|
211 refreshTable(profileDataTable); |
|
212 } |
|
213 } |
|
214 }); |
|
215 |
|
216 // Add folder button |
|
217 Button addDirectoryButton = new Button(fileSelectionButtonComposite, |
|
218 SWT.PUSH); |
|
219 addDirectoryButton |
|
220 .setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
221 addDirectoryButton.setText(Messages.getString("FileSelectionGroup.actionAddDirectory")); //$NON-NLS-1$ |
|
222 addDirectoryButton.addSelectionListener(new SelectionAdapter() { |
|
223 |
|
224 public void widgetSelected(SelectionEvent e) { |
|
225 // open file dialog for selecting a crash file |
|
226 DirectoryDialog dialog = new DirectoryDialog(getShell()); |
|
227 dialog |
|
228 .setText(Messages.getString("FileSelectionGroup.dialogDirectoryTitle")); //$NON-NLS-1$ |
|
229 String result = dialog.open(); |
|
230 if (result != null) { |
|
231 try { |
|
232 addDirectory(new Path(result)); |
|
233 refreshTable(profileDataTable); |
|
234 |
|
235 } catch (IllegalArgumentException iae) { |
|
236 IStatus status = new Status(Status.ERROR, |
|
237 PiPlugin.PLUGIN_ID, iae.getMessage()); |
|
238 ErrorDialog.openError(getShell(), |
|
239 Messages.getString("FileSelectionGroup.performanceInvestigator"), null, status); //$NON-NLS-1$ |
|
240 } |
|
241 } |
|
242 } |
|
243 }); |
|
244 |
|
245 // Remove one file button |
|
246 Button removeOneButton = new Button(fileSelectionButtonComposite, |
|
247 SWT.PUSH); |
|
248 removeOneButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
249 removeOneButton.setText(Messages.getString("FileSelectionGroup.actionRemove")); //$NON-NLS-1$ |
|
250 removeOneButton.addSelectionListener(new SelectionAdapter() { |
|
251 public void widgetSelected(SelectionEvent e) { |
|
252 removeSelectedItem(profileDataTable); |
|
253 refreshTable(profileDataTable); |
|
254 } |
|
255 |
|
256 }); |
|
257 |
|
258 // Remove all files and folders button |
|
259 Button removeAllButton = new Button(fileSelectionButtonComposite, |
|
260 SWT.PUSH); |
|
261 removeAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
262 removeAllButton.setText(Messages.getString("FileSelectionGroup.actionRemoveAll")); //$NON-NLS-1$ |
|
263 removeAllButton.addSelectionListener(new SelectionAdapter() { |
|
264 public void widgetSelected(SelectionEvent e) { |
|
265 removeAll(); |
|
266 refreshTable(profileDataTable); |
|
267 } |
|
268 |
|
269 }); |
|
270 } |
|
271 |
|
272 /* |
|
273 * (non-Javadoc) |
|
274 * @see com.nokia.carbide.cpp.internal.pi.wizards.ui.AbstractBaseGroup#getTable() |
|
275 */ |
|
276 @Override |
|
277 public Table getTable() { |
|
278 return profileDataTable.getTable(); |
|
279 } |
|
280 } |