1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 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 * Francois Chouinard - Initial API and implementation
11 * Patrick Tasse - Updated for TMF 2.0
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.gdbtrace
.ui
.views
.project
.dialogs
;
17 import java
.io
.IOException
;
18 import java
.util
.Arrays
;
20 import org
.eclipse
.cdt
.core
.CCorePlugin
;
21 import org
.eclipse
.cdt
.core
.IBinaryParser
;
22 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
23 import org
.eclipse
.core
.runtime
.CoreException
;
24 import org
.eclipse
.core
.runtime
.IPath
;
25 import org
.eclipse
.core
.runtime
.IStatus
;
26 import org
.eclipse
.core
.runtime
.Path
;
27 import org
.eclipse
.core
.runtime
.Status
;
28 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
29 import org
.eclipse
.swt
.SWT
;
30 import org
.eclipse
.swt
.events
.SelectionAdapter
;
31 import org
.eclipse
.swt
.events
.SelectionEvent
;
32 import org
.eclipse
.swt
.graphics
.Font
;
33 import org
.eclipse
.swt
.layout
.GridData
;
34 import org
.eclipse
.swt
.layout
.GridLayout
;
35 import org
.eclipse
.swt
.widgets
.Button
;
36 import org
.eclipse
.swt
.widgets
.Composite
;
37 import org
.eclipse
.swt
.widgets
.Control
;
38 import org
.eclipse
.swt
.widgets
.Event
;
39 import org
.eclipse
.swt
.widgets
.FileDialog
;
40 import org
.eclipse
.swt
.widgets
.Label
;
41 import org
.eclipse
.swt
.widgets
.Listener
;
42 import org
.eclipse
.swt
.widgets
.Shell
;
43 import org
.eclipse
.swt
.widgets
.Text
;
44 import org
.eclipse
.tracecompass
.internal
.gdbtrace
.ui
.GdbTraceUIPlugin
;
45 import org
.eclipse
.tracecompass
.tmf
.ui
.dialog
.TmfFileDialogFactory
;
46 import org
.eclipse
.ui
.dialogs
.SelectionStatusDialog
;
49 * Dialog implementation for the Select Trace Executable command
51 * @author Francois Chouinard
53 public class SelectTraceExecutableDialog
extends SelectionStatusDialog
{
55 private final IStatus OK_STATUS
= new Status(IStatus
.OK
, GdbTraceUIPlugin
.PLUGIN_ID
, ""); //$NON-NLS-1$
56 private final IStatus PATH_ERROR_STATUS
= new Status(IStatus
.ERROR
, GdbTraceUIPlugin
.PLUGIN_ID
, Messages
.SelectTraceExecutableDialog_Message
);
57 private final IStatus BINARY_ERROR_STATUS
= new Status(IStatus
.ERROR
, GdbTraceUIPlugin
.PLUGIN_ID
, Messages
.SelectTraceExecutableDialog_BinaryError
);
59 private Text fExecutableNameEntry
;
60 private IPath fExecutablePath
;
63 * Creates a SelectTraceExecutableDialog
65 * @param parentShell parent of the new dialog
67 public SelectTraceExecutableDialog(Shell parentShell
) {
69 setTitle(Messages
.SelectTraceExecutableDialog_Title
);
70 setStatusLineAboveButtons(true);
71 setHelpAvailable(false);
75 protected void computeResult() {
76 setResult(Arrays
.asList(new IPath
[] { fExecutablePath
}));
80 public void create() {
82 getButton(IDialogConstants
.OK_ID
).setEnabled(false);
86 protected Control
createDialogArea(Composite parent
) {
87 Composite composite
= (Composite
) super.createDialogArea(parent
);
88 composite
.setLayout(new GridLayout());
89 composite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
91 createFolderNameGroup(composite
);
93 setStatusLineAboveButtons(true);
94 updateStatus(PATH_ERROR_STATUS
);
100 * Creates the folder name specification controls.
102 * @param parent the parent composite
104 private void createFolderNameGroup(Composite parent
) {
105 final Shell shell
= parent
.getShell();
106 Font font
= parent
.getFont();
107 Composite composite
= new Composite(parent
, SWT
.NONE
);
108 GridLayout layout
= new GridLayout(3, false);
109 composite
.setLayout(layout
);
110 composite
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
112 // Executable name label
113 Label label
= new Label(composite
, SWT
.NONE
);
115 label
.setText(Messages
.SelectTraceExecutableDialog_ExecutableName
);
117 // Executable name entry field
118 fExecutableNameEntry
= new Text(composite
, SWT
.BORDER
);
119 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
120 data
.widthHint
= IDialogConstants
.ENTRY_FIELD_WIDTH
;
121 fExecutableNameEntry
.setLayoutData(data
);
122 fExecutableNameEntry
.setFont(font
);
123 fExecutableNameEntry
.addListener(SWT
.Modify
, new Listener() {
125 public void handleEvent(Event event
) {
126 fExecutablePath
= Path
.fromOSString(fExecutableNameEntry
.getText());
127 if (! validateExecutableName()) {
128 updateStatus(PATH_ERROR_STATUS
);
129 } else if (! validateExecutableBinary()) {
130 updateStatus(BINARY_ERROR_STATUS
);
132 updateStatus(OK_STATUS
);
138 Button browseExecutableButton
= new Button(composite
, SWT
.NONE
);
139 browseExecutableButton
.setText(Messages
.SelectTraceExecutableDialog_Browse
);
140 browseExecutableButton
.addSelectionListener(new SelectionAdapter() {
142 public void widgetSelected(SelectionEvent event
) {
143 FileDialog dlg
= TmfFileDialogFactory
.create(shell
);
144 String workspacePath
= ResourcesPlugin
.getWorkspace().getRoot().getLocation().toOSString();
145 dlg
.setFilterPath(workspacePath
);
146 dlg
.setText(Messages
.SelectTraceExecutableDialog_ExecutablePrompt
);
147 String path
= dlg
.open();
149 fExecutableNameEntry
.setText(path
);
157 * Checks whether the executable location is valid.
159 private boolean validateExecutableName() {
160 if (fExecutablePath
!= null) {
161 File file
= new File(fExecutablePath
.toOSString());
162 return file
.exists() && file
.isFile();
168 * Checks whether the executable location is a recognized executable.
170 private boolean validateExecutableBinary() {
172 IBinaryParser parser
= CCorePlugin
.getDefault().getDefaultBinaryParser();
173 IBinaryParser
.IBinaryFile binary
= parser
.getBinary(fExecutablePath
);
174 if (binary
instanceof IBinaryParser
.IBinaryObject
) {
177 } catch (CoreException e
) {
178 } catch (IOException e
) {
184 * Returns the selected executable path.
185 * @return the executable path
187 public IPath
getExecutablePath() {
188 return fExecutablePath
;