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