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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.wizards
.importtrace
;
15 import java
.util
.LinkedHashMap
;
18 import org
.eclipse
.core
.resources
.IFolder
;
19 import org
.eclipse
.core
.resources
.IProject
;
20 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
21 import org
.eclipse
.core
.runtime
.CoreException
;
22 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.TmfProjectNature
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.events
.SelectionEvent
;
26 import org
.eclipse
.swt
.events
.SelectionListener
;
27 import org
.eclipse
.swt
.layout
.GridData
;
28 import org
.eclipse
.swt
.layout
.GridLayout
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.swt
.widgets
.List
;
31 import org
.eclipse
.ui
.IWorkbench
;
34 * This page selects the project to import to.
36 * @author Matthew Khouzam
39 public class ImportTraceWizardPageOptions
extends AbstractImportTraceWizardPage
{
41 private List fProjects
;
42 private final Map
<String
, IProject
> fProjectsMap
= new LinkedHashMap
<String
, IProject
>();
45 * Import page that tells where the trace will go
48 * The workbench reference.
50 * The current selection
52 public ImportTraceWizardPageOptions(IWorkbench workbench
, IStructuredSelection selection
) {
53 super(workbench
, selection
);
57 public void createControl(Composite parent
) {
58 super.createControl(parent
);
59 IFolder originalFolder
= getBatchWizard().getTargetFolder();
61 if (originalFolder
!= null) {
62 proj
= originalFolder
.getProject();
65 Composite optionPane
= (Composite
) this.getControl();
66 optionPane
.setLayout(new GridLayout());
67 optionPane
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.TOP
, true, true));
69 IProject
[] projects
= ResourcesPlugin
.getWorkspace().getRoot().getProjects();
71 fProjects
= new List(optionPane
, SWT
.NONE
);
72 fProjects
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
74 for (IProject project
: projects
) {
76 if (project
.getNature(TmfProjectNature
.ID
) != null) {
77 final String name
= project
.getName();
78 fProjectsMap
.put(name
, project
);
81 } catch (CoreException e
) {
82 // TODO: add a logger to activator and then log it
86 fProjects
.getSelection();
87 fProjects
.addSelectionListener(new SelectionListener() {
89 private static final String TRACE
= "Traces"; //$NON-NLS-1$
92 public void widgetSelected(SelectionEvent e
) {
93 final String listItem
= fProjects
.getSelection()[0];
94 IFolder folder
= fProjectsMap
.get(listItem
).getFolder(TRACE
);
95 getBatchWizard().setTraceFolder(folder
);
96 ImportTraceWizardPageOptions
.this.setErrorMessage(null);
100 public void widgetDefaultSelected(SelectionEvent e
) {
101 final String listItem
= fProjects
.getSelection()[0];
102 IFolder folder
= fProjectsMap
.get(listItem
).getFolder(TRACE
);
103 getBatchWizard().setTraceFolder(folder
);
104 ImportTraceWizardPageOptions
.this.setErrorMessage(null);
108 fProjects
.setSelection(fProjects
.indexOf(proj
.getName()));
109 this.setErrorMessage(null);
111 this.setErrorMessage(Messages
.SharedSelectProject
);
113 this.setTitle(Messages
.ImportTraceWizardPageOptionsTitle
);