Commit | Line | Data |
---|---|---|
abfad0aa FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 Ericsson | |
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 | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.views.project.dialogs; | |
14 | ||
15 | import org.eclipse.core.resources.IFile; | |
16 | import org.eclipse.core.resources.IFolder; | |
17 | import org.eclipse.core.resources.IResource; | |
18 | import org.eclipse.core.resources.IWorkspace; | |
19 | import org.eclipse.core.resources.ResourcesPlugin; | |
20 | import org.eclipse.core.runtime.CoreException; | |
21 | import org.eclipse.core.runtime.IPath; | |
22 | import org.eclipse.jface.viewers.IStructuredSelection; | |
23 | import org.eclipse.jface.wizard.Wizard; | |
7995b722 | 24 | import org.eclipse.linuxtools.tmf.ui.internal.Messages; |
abfad0aa FC |
25 | import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfExperimentNode; |
26 | import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfProjectNode; | |
27 | import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfTraceNode; | |
28 | import org.eclipse.ui.IImportWizard; | |
29 | import org.eclipse.ui.IWorkbench; | |
30 | ||
31 | /** | |
32 | * <b><u>AddTraceWizard</u></b> | |
33 | * <p> | |
34 | * TODO: Implement me. Please. | |
35 | */ | |
36 | public class AddTraceWizard extends Wizard implements IImportWizard { | |
37 | ||
38 | private TmfProjectNode fProject; | |
39 | private TmfExperimentNode fExperiment; | |
40 | private AddTraceWizardPage fMainPage; | |
41 | ||
42 | /** | |
43 | * @param project | |
44 | */ | |
45 | public AddTraceWizard(TmfProjectNode project, TmfExperimentNode experiment) { | |
46 | fProject = project; | |
47 | fExperiment = experiment; | |
48 | } | |
49 | ||
50 | /* (non-Javadoc) | |
51 | * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) | |
52 | */ | |
d4011df2 | 53 | @Override |
abfad0aa | 54 | public void init(IWorkbench workbench, IStructuredSelection selection) { |
b9763f53 | 55 | setWindowTitle(Messages.AddTraceWizard_WindowTitle); |
abfad0aa FC |
56 | } |
57 | ||
58 | /* (non-Javadoc) | |
59 | * @see org.eclipse.jface.wizard.Wizard#addPages() | |
60 | */ | |
61 | @Override | |
62 | public void addPages() { | |
63 | super.addPages(); | |
3b38ea61 | 64 | fMainPage = new AddTraceWizardPage(fProject, "Some string"); //$NON-NLS-1$ |
abfad0aa FC |
65 | addPage(fMainPage); |
66 | } | |
67 | ||
68 | /* (non-Javadoc) | |
69 | * @see org.eclipse.jface.wizard.Wizard#performFinish() | |
70 | */ | |
71 | @Override | |
72 | public boolean performFinish() { | |
73 | ||
74 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | |
75 | IFolder experimentFolder = fExperiment.getFolder(); | |
76 | ||
77 | TmfTraceNode[] traces = fMainPage.getSelection(); | |
78 | for (TmfTraceNode trace : traces) { | |
79 | try { | |
80 | IResource resource = trace.getResource(); | |
81 | IPath location = resource.getLocation(); | |
82 | if (resource instanceof IFolder) { | |
83 | IFolder folder = experimentFolder.getFolder(trace.getName()); | |
84 | if (workspace.validateLinkLocation(folder, location).isOK()) { | |
85 | folder.createLink(location, IResource.REPLACE, null); | |
86 | } | |
87 | else { | |
b9763f53 | 88 | System.out.println("Invalid Trace Location"); //$NON-NLS-1$ |
abfad0aa FC |
89 | } |
90 | } else { | |
91 | IFile file = experimentFolder.getFile(trace.getName()); | |
92 | if (workspace.validateLinkLocation(file, location).isOK()) { | |
93 | file.createLink(location, IResource.REPLACE, null); | |
94 | } | |
95 | else { | |
b9763f53 | 96 | System.out.println("Invalid Trace Location"); //$NON-NLS-1$ |
abfad0aa FC |
97 | } |
98 | } | |
99 | } catch (CoreException e) { | |
100 | e.printStackTrace(); | |
101 | } | |
102 | } | |
103 | ||
104 | return true; | |
105 | } | |
106 | ||
107 | } |