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
;
17 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.events
.SelectionEvent
;
20 import org
.eclipse
.swt
.events
.SelectionListener
;
21 import org
.eclipse
.swt
.layout
.GridData
;
22 import org
.eclipse
.swt
.layout
.GridLayout
;
23 import org
.eclipse
.swt
.widgets
.Button
;
24 import org
.eclipse
.swt
.widgets
.Composite
;
25 import org
.eclipse
.swt
.widgets
.DirectoryDialog
;
26 import org
.eclipse
.swt
.widgets
.Display
;
27 import org
.eclipse
.swt
.widgets
.FileDialog
;
28 import org
.eclipse
.swt
.widgets
.Table
;
29 import org
.eclipse
.swt
.widgets
.TableItem
;
30 import org
.eclipse
.ui
.IWorkbench
;
33 * <b>Select the directories to scan for traces</b> this page is the second of
34 * three pages shown. This one selects the files to be scanned.
36 * @author Matthew Khouzam
39 public class ImportTraceWizardSelectDirectoriesPage
extends AbstractImportTraceWizardPage
{
44 public static String ID
= "org.eclipse.linuxtools.tmf.ui.project.wizards.importtrace.ImportTraceWizardPagePopulate"; //$NON-NLS-1$
47 * Constructor. Creates the trace wizard page.
50 * The name of the page.
52 * The current selection
54 protected ImportTraceWizardSelectDirectoriesPage(String name
, IStructuredSelection selection
) {
55 super(name
, selection
);
62 * The workbench reference.
64 * The current selection
66 public ImportTraceWizardSelectDirectoriesPage(IWorkbench workbench
, IStructuredSelection selection
) {
67 super(workbench
, selection
);
71 public void createControl(Composite parent
) {
72 super.createControl(parent
);
73 final Composite control
= (Composite
) this.getControl();
74 control
.setLayout(new GridLayout(2, false));
75 control
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
77 final Table selectedFiles
= new Table(control
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
78 selectedFiles
.clearAll();
79 selectedFiles
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
80 selectedFiles
.setLinesVisible(true);
82 Composite buttonArea
= new Composite(control
, SWT
.None
);
83 buttonArea
.setLayout(new GridLayout());
84 buttonArea
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.TOP
, false, false));
86 Button addFile
= new Button(buttonArea
, SWT
.PUSH
);
87 addFile
.setText(Messages
.ImportTraceWizardAddFile
);
88 addFile
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
89 addFile
.addSelectionListener(new AddFileHandler());
90 addFile
.setAlignment(SWT
.CENTER
);
92 Button addDirectory
= new Button(buttonArea
, SWT
.PUSH
);
93 addDirectory
.setText(Messages
.ImportTraceWizardAddDirectory
);
94 addDirectory
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
95 addDirectory
.addSelectionListener(new AddDirectoryHandler());
96 addDirectory
.setAlignment(SWT
.CENTER
);
98 Button removeFile
= new Button(buttonArea
, SWT
.PUSH
);
99 removeFile
.setText(Messages
.ImportTraceWizardRemove
);
100 removeFile
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
101 removeFile
.addSelectionListener(new RemoveFileHandler(selectedFiles
));
102 removeFile
.setAlignment(SWT
.CENTER
);
104 // int maxSize = Math.max(addFile.getSize().x, Math.max(addDirectory.getSize().x, removeFile.getSize().x));
105 // int maxHeight = Math.max(addFile.getSize().y, Math.max(addDirectory.getSize().y, removeFile.getSize().y));
106 // addFile.setSize(maxSize, maxHeight);
107 // addDirectory.setSize(maxSize, maxHeight);
108 // removeFile.setSize(maxSize, maxHeight);
110 this.setTitle(Messages
.ImportTraceWizardDirectoryCaption
);
113 private void updateButtons() {
114 BatchImportTraceWizard wiz
= getBatchWizard();
116 wiz
.getContainer().updateButtons();
119 private void updateTable() {
120 final Table selectedFiles
= (Table
) ((Composite
) getControl()).getChildren()[0];
121 selectedFiles
.clearAll();
122 selectedFiles
.setItemCount(0);
123 for (String s
: ((BatchImportTraceWizard
) getWizard()).getFileNames()) {
124 TableItem ti
= new TableItem(selectedFiles
, SWT
.None
);
130 public boolean canFlipToNextPage() {
131 final Table selectedFiles
= (Table
) ((Composite
) getControl()).getChildren()[0];
132 boolean canLoad
= selectedFiles
.getItemCount() > 0;
134 setErrorMessage(null);
136 setErrorMessage(Messages
.ImportTraceWizardDirectoryHint
);
141 private final class AddFileHandler
implements SelectionListener
{
143 public void widgetSelected(SelectionEvent e
) {
145 FileDialog dialog
= new
146 FileDialog(Display
.getCurrent().getActiveShell(), SWT
.NONE
);
147 String fn
= dialog
.open();
149 File f
= new File(fn
);
151 getBatchWizard().addFileToScan(fn
);
159 public void widgetDefaultSelected(SelectionEvent e
) {
163 private final class AddDirectoryHandler
implements SelectionListener
{
165 public void widgetSelected(SelectionEvent e
) {
167 // BUG BUG BUG BUG BUG IN SWT. Cannot read multiple files in a
170 // FileDialog dialog = new
171 // FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN |
173 // dialog.setFilterPath(".");
174 // if (null != dialog.open()) {
175 // for (String fn : dialog.getFileNames()) {
176 // final String pathname = dialog.getFilterPath() +
177 // File.separator + fn;
178 // File f = new File(pathname);
180 // ((BatchImportTraceWizard) getWizard()).addFile(fn, f);
185 DirectoryDialog dialog
= new
186 DirectoryDialog(Display
.getCurrent().getActiveShell(), SWT
.NONE
);
187 String fn
= dialog
.open();
189 File f
= new File(fn
);
191 getBatchWizard().addFileToScan(fn
);
199 public void widgetDefaultSelected(SelectionEvent e
) {
203 private final class RemoveFileHandler
implements SelectionListener
{
204 private final Table selectedFiles
;
206 private RemoveFileHandler(Table selectedFiles
) {
207 this.selectedFiles
= selectedFiles
;
211 public void widgetSelected(SelectionEvent e
) {
212 TableItem selectedToRemove
[] = selectedFiles
.getSelection();
213 for (TableItem victim
: selectedToRemove
) {
214 String victimName
= victim
.getText();
215 ((BatchImportTraceWizard
) getWizard()).removeFile(victimName
);
221 public void widgetDefaultSelected(SelectionEvent e
) {