1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 * Marc-Andre Laperle - Use common method to get opened tmf projects
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.wizards
.importtrace
;
16 import java
.util
.LinkedHashMap
;
19 import org
.eclipse
.core
.resources
.IFolder
;
20 import org
.eclipse
.core
.resources
.IProject
;
21 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TraceUtils
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.events
.SelectionEvent
;
25 import org
.eclipse
.swt
.events
.SelectionListener
;
26 import org
.eclipse
.swt
.layout
.GridData
;
27 import org
.eclipse
.swt
.layout
.GridLayout
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.List
;
30 import org
.eclipse
.ui
.IWorkbench
;
33 * This page selects the project to import to.
35 * @author Matthew Khouzam
38 public class ImportTraceWizardPageOptions
extends AbstractImportTraceWizardPage
{
40 private List fProjects
;
41 private final Map
<String
, IProject
> fProjectsMap
= new LinkedHashMap
<String
, IProject
>();
44 * Import page that tells where the trace will go
47 * The workbench reference.
49 * The current selection
51 public ImportTraceWizardPageOptions(IWorkbench workbench
, IStructuredSelection selection
) {
52 super(workbench
, selection
);
56 public void createControl(Composite parent
) {
57 super.createControl(parent
);
58 IFolder originalFolder
= getBatchWizard().getTargetFolder();
60 if (originalFolder
!= null) {
61 proj
= originalFolder
.getProject();
64 Composite optionPane
= (Composite
) this.getControl();
65 optionPane
.setLayout(new GridLayout());
66 optionPane
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.TOP
, true, true));
68 fProjects
= new List(optionPane
, SWT
.NONE
);
69 fProjects
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
71 for (IProject project
: TraceUtils
.getOpenedTmfProjects()) {
72 final String name
= project
.getName();
73 fProjectsMap
.put(name
, project
);
77 fProjects
.getSelection();
78 fProjects
.addSelectionListener(new SelectionListener() {
80 private static final String TRACE
= "Traces"; //$NON-NLS-1$
83 public void widgetSelected(SelectionEvent e
) {
84 final String listItem
= fProjects
.getSelection()[0];
85 IFolder folder
= fProjectsMap
.get(listItem
).getFolder(TRACE
);
86 getBatchWizard().setTraceFolder(folder
);
87 ImportTraceWizardPageOptions
.this.setErrorMessage(null);
91 public void widgetDefaultSelected(SelectionEvent e
) {
92 final String listItem
= fProjects
.getSelection()[0];
93 IFolder folder
= fProjectsMap
.get(listItem
).getFolder(TRACE
);
94 getBatchWizard().setTraceFolder(folder
);
95 ImportTraceWizardPageOptions
.this.setErrorMessage(null);
99 fProjects
.setSelection(fProjects
.indexOf(proj
.getName()));
100 this.setErrorMessage(null);
102 this.setErrorMessage(Messages
.SharedSelectProject
);
104 this.setTitle(Messages
.ImportTraceWizardPageOptionsTitle
);