Commit | Line | Data |
---|---|---|
a2d29ca1 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2014 Ericsson |
a2d29ca1 MK |
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 | * Matthew Khouzam - Initial API and implementation | |
d600c18f | 11 | * Marc-Andre Laperle - Use common method to get opened tmf projects |
a2d29ca1 MK |
12 | *******************************************************************************/ |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace; |
a2d29ca1 MK |
15 | |
16 | import java.util.LinkedHashMap; | |
17 | import java.util.Map; | |
18 | ||
19 | import org.eclipse.core.resources.IFolder; | |
20 | import org.eclipse.core.resources.IProject; | |
a2d29ca1 | 21 | import org.eclipse.jface.viewers.IStructuredSelection; |
a2d29ca1 MK |
22 | import org.eclipse.swt.SWT; |
23 | import org.eclipse.swt.events.SelectionEvent; | |
24 | import org.eclipse.swt.events.SelectionListener; | |
25 | import org.eclipse.swt.layout.GridData; | |
26 | import org.eclipse.swt.layout.GridLayout; | |
27 | import org.eclipse.swt.widgets.Composite; | |
28 | import org.eclipse.swt.widgets.List; | |
2bdf0193 AM |
29 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfTracesFolder; |
30 | import org.eclipse.tracecompass.tmf.ui.project.model.TraceUtils; | |
a2d29ca1 MK |
31 | import org.eclipse.ui.IWorkbench; |
32 | ||
33 | /** | |
34 | * This page selects the project to import to. | |
35 | * | |
36 | * @author Matthew Khouzam | |
a2d29ca1 MK |
37 | */ |
38 | public class ImportTraceWizardPageOptions extends AbstractImportTraceWizardPage { | |
39 | ||
40 | private List fProjects; | |
507b1336 | 41 | private final Map<String, IProject> fProjectsMap = new LinkedHashMap<>(); |
a2d29ca1 MK |
42 | |
43 | /** | |
44 | * Import page that tells where the trace will go | |
45 | * | |
46 | * @param workbench | |
47 | * The workbench reference. | |
48 | * @param selection | |
49 | * The current selection | |
50 | */ | |
51 | public ImportTraceWizardPageOptions(IWorkbench workbench, IStructuredSelection selection) { | |
52 | super(workbench, selection); | |
53 | } | |
54 | ||
55 | @Override | |
56 | public void createControl(Composite parent) { | |
57 | super.createControl(parent); | |
58 | IFolder originalFolder = getBatchWizard().getTargetFolder(); | |
59 | IProject proj = null; | |
60 | if (originalFolder != null) { | |
61 | proj = originalFolder.getProject(); | |
62 | } | |
63 | ||
64 | Composite optionPane = (Composite) this.getControl(); | |
65 | optionPane.setLayout(new GridLayout()); | |
66 | optionPane.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true)); | |
67 | ||
de2501f8 | 68 | fProjects = new List(optionPane, SWT.V_SCROLL); |
a2d29ca1 MK |
69 | fProjects.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
70 | ||
d600c18f MAL |
71 | for (IProject project : TraceUtils.getOpenedTmfProjects()) { |
72 | final String name = project.getName(); | |
73 | fProjectsMap.put(name, project); | |
74 | fProjects.add(name); | |
a2d29ca1 MK |
75 | } |
76 | ||
77 | fProjects.getSelection(); | |
78 | fProjects.addSelectionListener(new SelectionListener() { | |
79 | ||
a2d29ca1 MK |
80 | @Override |
81 | public void widgetSelected(SelectionEvent e) { | |
014d3bab | 82 | updateWithSelection(); |
a2d29ca1 MK |
83 | } |
84 | ||
85 | @Override | |
86 | public void widgetDefaultSelected(SelectionEvent e) { | |
014d3bab | 87 | updateWithSelection(); |
a2d29ca1 MK |
88 | } |
89 | }); | |
90 | if (proj != null) { | |
91 | fProjects.setSelection(fProjects.indexOf(proj.getName())); | |
ae2b897a MAL |
92 | } else if (fProjects.getItemCount() > 0) { |
93 | fProjects.setSelection(0); | |
d80cac0e | 94 | updateWithSelection(); |
a2d29ca1 | 95 | } |
ae2b897a | 96 | setMessage(Messages.SharedSelectProject); |
32a0863e | 97 | this.setTitle(Messages.ImportTraceWizardPageOptionsTitle); |
a2d29ca1 | 98 | } |
014d3bab MAL |
99 | |
100 | private void updateWithSelection() { | |
014d3bab MAL |
101 | String[] selection = fProjects.getSelection(); |
102 | if (selection.length > 0) { | |
103 | final String listItem = selection[0]; | |
d80cac0e | 104 | IFolder folder = fProjectsMap.get(listItem).getFolder(TmfTracesFolder.TRACES_FOLDER_NAME); |
014d3bab MAL |
105 | getBatchWizard().setTraceFolder(folder); |
106 | ImportTraceWizardPageOptions.this.setErrorMessage(null); | |
107 | } else { | |
108 | ImportTraceWizardPageOptions.this.setErrorMessage(Messages.SharedSelectProject); | |
109 | } | |
110 | } | |
a2d29ca1 | 111 | } |