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
.ui
.dialogs
.SelectionStatusDialog
;
48 * Dialog implementation for the Select Trace Executable command
50 * @author Francois Chouinard
52 public class SelectTraceExecutableDialog
extends SelectionStatusDialog
{
54 private final IStatus OK_STATUS
= new Status(IStatus
.OK
, GdbTraceUIPlugin
.PLUGIN_ID
, ""); //$NON-NLS-1$
55 private final IStatus PATH_ERROR_STATUS
= new Status(IStatus
.ERROR
, GdbTraceUIPlugin
.PLUGIN_ID
, Messages
.SelectTraceExecutableDialog_Message
);
56 private final IStatus BINARY_ERROR_STATUS
= new Status(IStatus
.ERROR
, GdbTraceUIPlugin
.PLUGIN_ID
, Messages
.SelectTraceExecutableDialog_BinaryError
);
58 private Text fExecutableNameEntry
;
59 private IPath fExecutablePath
;
62 * Creates a SelectTraceExecutableDialog
64 * @param parentShell parent of the new dialog
66 public SelectTraceExecutableDialog(Shell parentShell
) {
68 setTitle(Messages
.SelectTraceExecutableDialog_Title
);
69 setStatusLineAboveButtons(true);
70 setHelpAvailable(false);
74 protected void computeResult() {
75 setResult(Arrays
.asList(new IPath
[] { fExecutablePath
}));
79 public void create() {
81 getButton(IDialogConstants
.OK_ID
).setEnabled(false);
85 protected Control
createDialogArea(Composite parent
) {
86 Composite composite
= (Composite
) super.createDialogArea(parent
);
87 composite
.setLayout(new GridLayout());
88 composite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
90 createFolderNameGroup(composite
);
92 setStatusLineAboveButtons(true);
93 updateStatus(PATH_ERROR_STATUS
);
99 * Creates the folder name specification controls.
101 * @param parent the parent composite
103 private void createFolderNameGroup(Composite parent
) {
104 final Shell shell
= parent
.getShell();
105 Font font
= parent
.getFont();
106 Composite composite
= new Composite(parent
, SWT
.NONE
);
107 GridLayout layout
= new GridLayout(3, false);
108 composite
.setLayout(layout
);
109 composite
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
111 // Executable name label
112 Label label
= new Label(composite
, SWT
.NONE
);
114 label
.setText(Messages
.SelectTraceExecutableDialog_ExecutableName
);
116 // Executable name entry field
117 fExecutableNameEntry
= new Text(composite
, SWT
.BORDER
);
118 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
119 data
.widthHint
= IDialogConstants
.ENTRY_FIELD_WIDTH
;
120 fExecutableNameEntry
.setLayoutData(data
);
121 fExecutableNameEntry
.setFont(font
);
122 fExecutableNameEntry
.addListener(SWT
.Modify
, new Listener() {
124 public void handleEvent(Event event
) {
125 fExecutablePath
= Path
.fromOSString(fExecutableNameEntry
.getText());
126 if (! validateExecutableName()) {
127 updateStatus(PATH_ERROR_STATUS
);
128 } else if (! validateExecutableBinary()) {
129 updateStatus(BINARY_ERROR_STATUS
);
131 updateStatus(OK_STATUS
);
137 Button browseExecutableButton
= new Button(composite
, SWT
.NONE
);
138 browseExecutableButton
.setText(Messages
.SelectTraceExecutableDialog_Browse
);
139 browseExecutableButton
.addSelectionListener(new SelectionAdapter() {
141 public void widgetSelected(SelectionEvent event
) {
142 FileDialog dlg
= new FileDialog(shell
);
143 String workspacePath
= ResourcesPlugin
.getWorkspace().getRoot().getLocation().toOSString();
144 dlg
.setFilterPath(workspacePath
);
145 dlg
.setText(Messages
.SelectTraceExecutableDialog_ExecutablePrompt
);
146 String path
= dlg
.open();
148 fExecutableNameEntry
.setText(path
);
156 * Checks whether the executable location is valid.
158 private boolean validateExecutableName() {
159 if (fExecutablePath
!= null) {
160 File file
= new File(fExecutablePath
.toOSString());
161 return file
.exists() && file
.isFile();
167 * Checks whether the executable location is a recognized executable.
169 private boolean validateExecutableBinary() {
171 IBinaryParser parser
= CCorePlugin
.getDefault().getDefaultBinaryParser();
172 IBinaryParser
.IBinaryFile binary
= parser
.getBinary(fExecutablePath
);
173 if (binary
instanceof IBinaryParser
.IBinaryObject
) {
176 } catch (CoreException e
) {
177 } catch (IOException e
) {
183 * Returns the selected executable path.
184 * @return the executable path
186 public IPath
getExecutablePath() {
187 return fExecutablePath
;