Commit | Line | Data |
---|---|---|
6e512b93 | 1 | /******************************************************************************* |
a3767fd9 | 2 | * Copyright (c) 2009, 2011 Ericsson, MontaVista Software |
6e512b93 ASL |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
a3767fd9 | 11 | * Yufen Kuo (ykuo@mvista.com) - add support to allow user specify trace library path |
6e512b93 ASL |
12 | *******************************************************************************/ |
13 | ||
14 | package org.eclipse.linuxtools.lttng.ui.views.project.dialogs; | |
15 | ||
42f18e57 | 16 | import org.eclipse.core.resources.IFolder; |
a3767fd9 | 17 | import org.eclipse.core.resources.IProject; |
42f18e57 | 18 | import org.eclipse.jface.dialogs.MessageDialog; |
6e512b93 | 19 | import org.eclipse.jface.viewers.IStructuredSelection; |
6c13869b FC |
20 | import org.eclipse.linuxtools.lttng.core.TraceHelper; |
21 | import org.eclipse.linuxtools.lttng.core.exceptions.LttngException; | |
22 | import org.eclipse.linuxtools.lttng.core.trace.LTTngTraceVersion; | |
8e30d685 | 23 | import org.eclipse.linuxtools.lttng.ui.views.project.handlers.TraceErrorHandler; |
2fbfb67b | 24 | import org.eclipse.linuxtools.lttng.ui.views.project.model.LTTngProjectNode; |
6e512b93 ASL |
25 | import org.eclipse.ui.IWorkbench; |
26 | import org.eclipse.ui.internal.wizards.datatransfer.WizardFileSystemResourceImportPage1; | |
27 | ||
28 | /** | |
29 | * <b><u>ImportTraceWizardPage</u></b> | |
30 | * <p> | |
31 | * TODO: Implement me. Please. | |
32 | */ | |
12c155f5 | 33 | @Deprecated |
6e512b93 ASL |
34 | @SuppressWarnings("restriction") |
35 | public class ImportTraceWizardPage extends WizardFileSystemResourceImportPage1 { | |
a2e53983 FC |
36 | |
37 | private boolean isContainerSet = false; | |
38 | private String initialContainerString = ""; //$NON-NLS-1$ | |
39 | private String selectedSourceDirectory = ""; //$NON-NLS-1$ | |
a3767fd9 | 40 | private IProject project; |
a2e53983 FC |
41 | |
42 | public ImportTraceWizardPage(IWorkbench workbench, IStructuredSelection selection) { | |
43 | super(workbench, selection); | |
44 | ||
42f18e57 FC |
45 | project = (IProject) selection.getFirstElement(); |
46 | IFolder folder = project.getFolder(LTTngProjectNode.TRACE_FOLDER_NAME); | |
47 | if (folder == null) { | |
48 | MessageDialog.openError(getShell(), Messages.ImportTrace_ErrorTitle, Messages.ImportTrace_InvalidProject); | |
49 | } | |
50 | String path = folder.getFullPath().toOSString(); | |
a2e53983 FC |
51 | |
52 | initialContainerString = path; | |
53 | setContainerFieldValue(path); | |
54 | } | |
55 | ||
56 | public String getTraceDirectory() { | |
57 | String tmpPath = ""; //$NON-NLS-1$ | |
58 | if ((getSourceDirectory() != null) && (getSourceDirectory().getName() != null)) { | |
59 | tmpPath = this.getSourceDirectory().getName().toString(); | |
8e30d685 | 60 | } |
a2e53983 FC |
61 | |
62 | return tmpPath; | |
63 | } | |
64 | ||
65 | public String getInitialContainerString() { | |
66 | return initialContainerString; | |
67 | } | |
68 | ||
69 | public String getTracepath() { | |
70 | String tmpPath = ""; //$NON-NLS-1$ | |
71 | if ((getSourceDirectory() != null) && (getSourceDirectory().getPath() != null)) { | |
72 | tmpPath = this.getSourceDirectory().getPath().toString(); | |
8e30d685 | 73 | } |
a2e53983 FC |
74 | |
75 | return tmpPath; | |
76 | } | |
77 | ||
78 | public String getDestination() { | |
79 | String returnPath = null; | |
80 | ||
81 | if (getContainerFullPath() != null) { | |
82 | returnPath = getContainerFullPath().toString(); | |
8e30d685 | 83 | } |
a2e53983 FC |
84 | return returnPath; |
85 | } | |
86 | ||
87 | public boolean isSelectedElementsValidLttngTraces() { | |
88 | boolean returnedValue = true; | |
89 | ||
90 | // We don't want to test until something is selected | |
91 | if (selectionGroup.getCheckedElementCount() > 0) { | |
92 | ||
93 | // We don't want to revalidate each time, only want a new directory | |
94 | // is selected | |
95 | if (!selectedSourceDirectory.equals(getSourceDirectory().getAbsolutePath().toString())) { | |
96 | try { | |
97 | if (isPathLttngTrace(getSourceDirectory().getAbsolutePath()) == false) { | |
98 | returnedValue = false; | |
99 | selectedSourceDirectory = ""; //$NON-NLS-1$ | |
100 | ||
101 | String errMessage[] = { Messages.ImportTraceWizardPage_BadTraceVersion + getSourceDirectory().getAbsolutePath() }; | |
102 | errMessage = extendErrorMessage(errMessage, ""); //$NON-NLS-1$ | |
103 | errMessage = extendErrorMessage(errMessage, Messages.ImportTraceWizardPage_BadTraceVersionMsg1); | |
104 | errMessage = extendErrorMessage(errMessage, Messages.ImportTraceWizardPage_BadTraceVersionMsg2); | |
105 | showVersionErrorPopup(errMessage); | |
106 | selectionGroup.setAllSelections(false); | |
107 | } else { | |
108 | selectedSourceDirectory = getSourceDirectory().getAbsolutePath(); | |
109 | ||
110 | if (isContainerSet == false) { | |
111 | isContainerSet = true; | |
112 | ||
113 | if (!getDestination().toString().equals(getInitialContainerString() + "/" + getTraceDirectory())) { //$NON-NLS-1$ | |
114 | // *** HACK *** | |
115 | // Force a sane destination to avoid imported | |
116 | // files to end up in the root of the "Traces/" | |
117 | // directory | |
118 | setContainerFieldValue(getInitialContainerString() + "/" + getTraceDirectory()); //$NON-NLS-1$ | |
119 | } | |
8e30d685 | 120 | } |
a2e53983 FC |
121 | } |
122 | } catch (LttngException e) { | |
123 | String[] errorMessages = e.toString().split("\n"); //$NON-NLS-1$ | |
124 | String exceptionMessage[] = { "Version check failed for the path : ", this.getTracepath(), "", "Returned error was :" }; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ | |
125 | ||
126 | for (int pos = 0; pos < errorMessages.length; pos++) { | |
127 | exceptionMessage = extendErrorMessage(exceptionMessage, errorMessages[pos]); | |
128 | } | |
129 | ||
130 | showVersionErrorPopup(exceptionMessage); | |
131 | selectionGroup.setAllSelections(false); | |
132 | returnedValue = false; | |
8e30d685 | 133 | } |
a2e53983 | 134 | } |
8e30d685 | 135 | } |
a2e53983 FC |
136 | isContainerSet = false; |
137 | ||
138 | return returnedValue; | |
139 | } | |
140 | ||
141 | public boolean isPathLttngTrace(String path) throws LttngException { | |
142 | ||
143 | boolean returnedValue = true; | |
a3767fd9 | 144 | String traceLibPath = TraceHelper.getTraceLibDirFromProject(project); |
a2e53983 | 145 | // Ask for a LttngTraceVersion for the given path |
a3767fd9 | 146 | LTTngTraceVersion traceVersion = new LTTngTraceVersion(path, traceLibPath); |
a2e53983 FC |
147 | |
148 | // If this is not a valid LTTng trace | |
149 | if (traceVersion.isValidLttngTrace() == false) { | |
150 | returnedValue = false; | |
8e30d685 | 151 | } |
a2e53983 FC |
152 | |
153 | return returnedValue; | |
154 | } | |
155 | ||
156 | public String[] extendErrorMessage(String[] oldErrorMessage, String lineToAdd) { | |
157 | String tmSwapMessage[] = new String[oldErrorMessage.length + 1]; | |
158 | for (int pos = 0; pos < oldErrorMessage.length; pos++) { | |
159 | tmSwapMessage[pos] = oldErrorMessage[pos]; | |
8e30d685 | 160 | } |
a2e53983 FC |
161 | tmSwapMessage[oldErrorMessage.length] = lineToAdd; |
162 | ||
163 | return tmSwapMessage; | |
164 | } | |
165 | ||
8e30d685 | 166 | /** |
a2e53983 FC |
167 | * This function will show a version error popup that contain the given |
168 | * message. | |
8e30d685 WB |
169 | * |
170 | */ | |
171 | public void showVersionErrorPopup(String[] errMessages) { | |
a2e53983 FC |
172 | TraceErrorHandler errorDialog = new TraceErrorHandler(errMessages); |
173 | try { | |
174 | errorDialog.execute(null); | |
175 | } catch (Exception e) { | |
176 | e.printStackTrace(); | |
177 | } | |
8e30d685 | 178 | } |
a2e53983 FC |
179 | |
180 | // // *** HACK HACK AND HACK *** | |
181 | // // Everything below is a proof of concept on how we could tweak the | |
182 | // import wizard to act according to our plan | |
183 | // // Uncomment everything below if you want to test it, but please, does | |
184 | // not put any of this into production | |
185 | // @SuppressWarnings({ "unchecked", "rawtypes" }) | |
186 | // @Override | |
187 | // public boolean finish() { | |
188 | // if (!ensureSourceIsValid()) { | |
189 | // return false; | |
190 | // } | |
191 | // saveWidgetValues(); | |
192 | // | |
193 | // Iterator resourcesEnum = getSelectedResources().iterator(); | |
194 | // List listRealFiles = new ArrayList(); | |
195 | // | |
196 | // // **** | |
197 | // // HACK #1 : | |
198 | // // We need to convert everything into java.io.File because | |
199 | // ImportOperation does NOT support FileSystemElement | |
200 | // while (resourcesEnum.hasNext()) { | |
201 | // FileSystemElement tmpFileElement = | |
202 | // ((FileSystemElement)resourcesEnum.next()); | |
203 | // java.io.File tmpRealFile = new | |
204 | // java.io.File(tmpFileElement.getFileSystemObject().toString()); | |
205 | // | |
206 | // listRealFiles.add(tmpRealFile); | |
207 | // } | |
208 | // | |
209 | // if (listRealFiles.size() > 0) { | |
210 | // // Call import ressources (code is below) | |
211 | // return importResources(listRealFiles); | |
212 | // } | |
213 | // | |
214 | // MessageDialog.openInformation(getContainer().getShell(), | |
215 | // DataTransferMessages.DataTransfer_information, | |
216 | // DataTransferMessages.FileImport_noneSelected); | |
217 | // return false; | |
218 | // } | |
219 | // | |
220 | // @Override | |
221 | // protected boolean importResources(List fileSystemObjects) { | |
222 | // // *** Explanation of the hackssss | |
223 | // // We want the import wizard to import everything in the form of : | |
224 | // // trace1/ -> tracefiles* | |
225 | // // | |
226 | // // However, the wizard is too dumb to do the following and will recreate | |
227 | // the full architecture the user selected. | |
228 | // // So, depending what the user select, we could end up with something | |
229 | // like : | |
230 | // // home/user/somewhere/trace1/ -> tracefiles* | |
231 | // // | |
232 | // // Since there is nothing to do with that, we need to change the "source" | |
233 | // and the "to-import files" to reflect this. | |
234 | // // Basically, from the case above, the "source" should be changed to | |
235 | // "trace1/" and "to-import files" | |
236 | // // should have the correct parent so the wizard can still find them | |
237 | // // | |
238 | // // Let's see how fun it is to do with mr. import wizard. | |
239 | // | |
240 | // | |
241 | // List listRealFilesShortPath = new ArrayList(); | |
242 | // java.io.File newFullSource = getSourceDirectory(); | |
243 | // | |
244 | // // We will loop for every "to-import full path files" we have and | |
245 | // recreate "short path" files | |
246 | // // Mean, the current path of the file is currently something like : | |
247 | // // Path : /home/billybob/mytraces/trace1/metadata_0 Parent : null | |
248 | // // And we want something less dumb like : | |
249 | // // Path : metadata_0 Parent : /home/billybob/mytraces/trace1/ | |
250 | // for (int pos=0; pos<fileSystemObjects.size(); pos++) { | |
251 | // java.io.File oldFile = (java.io.File)fileSystemObjects.get(pos); | |
252 | // java.io.File newShortPathFile = oldFile; | |
253 | // | |
254 | // // *** | |
255 | // // HACK #2 : We need to ajust the source of the files! | |
256 | // // Our current source is probably like : | |
257 | // // (Source) Path : / (or null?) | |
258 | // // (Files) Path : /home/billybob/mytraces/trace1/metadata_0 Parent : null | |
259 | // // We want something like : | |
260 | // // (Source) Path : /home/billybob/mytraces/trace1/ | |
261 | // // (Files) Path : metadata_0 Parent : /home/billybob/mytraces/trace1/ | |
262 | // // | |
263 | // // *BUG : However, we might need MULTIPLE sources since we could have | |
264 | // MULTIPLE traces selected... | |
265 | // // THIS IS NOT HANDLED YET. | |
266 | // | |
267 | // // Make a new path like -> /home/billybob/mytraces/trace1/ | |
268 | // String newParent = oldFile.getAbsolutePath().substring(0, | |
269 | // oldFile.getAbsolutePath().lastIndexOf("/") ); | |
270 | // | |
271 | // // Create a "short path file" with the good parent from it. This give : | |
272 | // // (Files) Path : metadata_0 Parent : /home/billybob/mytraces/trace1/ | |
273 | // newShortPathFile = new java.io.File(newParent, oldFile.getName() ); | |
274 | // | |
275 | // // Create a new "full source" directory -> | |
276 | // /home/billybob/mytraces/trace1/ | |
277 | // newFullSource = new java.io.File( newParent ); | |
278 | // | |
279 | // // Add our pretty file to the new List | |
280 | // listRealFilesShortPath.add(newShortPathFile); | |
281 | // } | |
282 | // | |
283 | // // *** | |
284 | // // HACK #3 | |
285 | // // Now that we have everything, we need to AJUST THE DESTINATION | |
286 | // // To do so, we ajust the "ContainerValue" text field. | |
287 | // // | |
288 | // // Right now we have something like : | |
289 | // // Path -> /where/to/import/ | |
290 | // // (Files) Path : metadata_0 Parent : /home/billybob/mytraces/trace1/ | |
291 | // // We want something like : | |
292 | // // Path -> /where/to/import/trace1/ | |
293 | // // (Files) Path : metadata_0 Parent : /home/billybob/mytraces/trace1/ | |
294 | // // | |
295 | // | |
296 | // // We take the current text field and we add the "full source" name | |
297 | // // Note : the "name" is the last directory name so "trace1" is returned | |
298 | // for a path like "/home/billybob/mytraces/trace1/" | |
299 | // setContainerFieldValue(getContainerFullPath() + "/" + | |
300 | // newFullSource.getName()); | |
301 | // | |
302 | // /* | |
303 | // System.out.println("\n\n" + getContainerFullPath()); | |
304 | // System.out.println(newFullSource); | |
305 | // System.out.println(FileSystemStructureProvider.INSTANCE); | |
306 | // System.out.println(this.getContainer()); | |
307 | // System.out.println(fileSystemObjects); | |
308 | // */ | |
309 | // | |
310 | // // Finally import !! | |
311 | // ImportOperation operation = new ImportOperation(getContainerFullPath(), | |
312 | // newFullSource, FileSystemStructureProvider.INSTANCE, this, | |
313 | // listRealFilesShortPath); | |
314 | // | |
315 | // operation.setContext(getShell()); | |
316 | // return executeImportOperation(operation); | |
317 | // } | |
318 | // | |
319 | // // This function test if the selected directory are LTTng traces | |
320 | // // This one is made to work with the madness above. | |
321 | // public boolean isSelectedElementsValidLttngTraces() { | |
322 | // boolean returnedValue = true; | |
323 | // | |
324 | // String errMessage[] = { | |
325 | // "Couldn't get LTTng version number for the path : " }; | |
326 | // | |
327 | // // We don't want to test until something is selected | |
328 | // if ( selectionGroup.getCheckedElementCount() > 0 ) { | |
329 | // try { | |
330 | // List<MinimizedFileSystemElement> selectionList = | |
331 | // selectionGroup.getAllWhiteCheckedItems(); | |
332 | // MinimizedFileSystemElement tmpSelectedElement = null; | |
333 | // | |
334 | // for ( int x=0; x<selectionList.size(); x++) { | |
335 | // tmpSelectedElement = selectionList.get(x); | |
336 | // | |
337 | // // *** VERIFY *** | |
338 | // // Not sure ALL directory are checked. | |
339 | // if ( tmpSelectedElement.isDirectory() ) { | |
340 | // String tmpPath = tmpSelectedElement.getFileSystemObject().toString(); | |
341 | // if ( isPathLttngTrace( tmpPath ) == false ) { | |
342 | // returnedValue = false; | |
343 | // errMessage = extendErrorMessage(errMessage, tmpPath); | |
344 | // } | |
345 | // } | |
346 | // } | |
347 | // | |
348 | // if ( returnedValue == false ) { | |
349 | // errMessage = extendErrorMessage(errMessage, ""); | |
350 | // errMessage = extendErrorMessage(errMessage, | |
351 | // "Verify that the directory is a valid LTTng trace directory."); | |
352 | // showVersionErrorPopup(errMessage); | |
353 | // selectionGroup.setAllSelections(false); | |
354 | // } | |
355 | // } | |
356 | // catch (LttngException e) { | |
357 | // String exceptionMessage[] = { "Version check failed for the path : ", | |
358 | // this.getTracepath(), "", "Returned error was :", e.toString() }; | |
359 | // showVersionErrorPopup(exceptionMessage); | |
360 | // selectionGroup.setAllSelections(false); | |
361 | // returnedValue = false; | |
362 | // } | |
363 | // } | |
364 | // | |
365 | // return returnedValue; | |
366 | // } | |
367 | ||
6e512b93 | 368 | } |