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