tmf/lttng2: support multiple symbol providers
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.ui / src / org / eclipse / tracecompass / internal / lttng2 / ust / ui / analysis / debuginfo / UstDebugInfoSymbolProviderPreferencePage.java
CommitLineData
cb2b5e56
AM
1/*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc. and others
3 *
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
a6a83eae
MF
8 *
9 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
11 * Mikael Ferland - Adjust title of preference pages for multiple symbol providers
cb2b5e56
AM
12 *******************************************************************************/
13
14package org.eclipse.tracecompass.internal.lttng2.ust.ui.analysis.debuginfo;
15
16import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
17import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
18
19import java.nio.file.Files;
20import java.nio.file.Path;
21import java.nio.file.Paths;
22import java.text.MessageFormat;
23
24import org.eclipse.jdt.annotation.Nullable;
25import org.eclipse.swt.SWT;
26import org.eclipse.swt.events.SelectionAdapter;
27import org.eclipse.swt.events.SelectionEvent;
28import org.eclipse.swt.layout.GridData;
29import org.eclipse.swt.layout.GridLayout;
30import org.eclipse.swt.widgets.Button;
31import org.eclipse.swt.widgets.Composite;
32import org.eclipse.swt.widgets.Control;
33import org.eclipse.swt.widgets.DirectoryDialog;
34import org.eclipse.swt.widgets.Label;
35import org.eclipse.swt.widgets.Text;
36import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
37import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace.SymbolProviderConfig;
38import org.eclipse.tracecompass.tmf.ui.symbols.AbstractSymbolProviderPreferencePage;
39
40/**
41 * Preference page to configure a path prefix from which to resolve all the
42 * paths found the binary file's debug information.
43 *
44 * @author Alexandre Montplaisir
45 */
46public class UstDebugInfoSymbolProviderPreferencePage extends AbstractSymbolProviderPreferencePage {
47
48 private @Nullable Button fUseCustomDirectoryCheckbox;
49 private @Nullable Text fCustomDirectoryPath;
50 private @Nullable Button fBrowseButton;
51 private @Nullable Button fClearButton;
52
53 /**
54 * Creates a new object for the given provider
55 *
56 * @param provider
57 * a non-null provider
58 */
59 public UstDebugInfoSymbolProviderPreferencePage(UstDebugInfoSymbolProvider provider) {
60 super(provider);
61 setDescription(MessageFormat.format(Messages.PreferencePage_WindowDescription, provider.getTrace().getName()));
62 setValid(true);
a6a83eae 63 setTitle(MessageFormat.format(Messages.PreferencePage_TabTitle, provider.getTrace().getName()));
cb2b5e56
AM
64 }
65
66 @Override
67 public UstDebugInfoSymbolProvider getSymbolProvider() {
68 /* Type enforced at constructor */
69 return (UstDebugInfoSymbolProvider) super.getSymbolProvider();
70 }
71
72 @Override
73 protected Control createContents(@Nullable Composite parent) {
74 /*
75 * We will use a grid layout with 3 columns :
76 *
77 * [checkbox+label][][]
78 *
79 * [text field][Browse][Clear]
80 */
81 Composite composite = new Composite(parent, SWT.BORDER);
82 composite.setLayoutData(new GridData(GridData.FILL_BOTH));
83 composite.setLayout(new GridLayout(3, false));
84
85 /* The first row: checkbox and itslabel */
86 Button checkBox = new Button(composite, SWT.CHECK);
87 checkBox.setText(Messages.PreferencePage_CheckboxLabel);
88 checkBox.setToolTipText(Messages.PreferencePage_CheckboxTooltip);
89 checkBox.addSelectionListener(new SelectionAdapter() {
90 @Override
91 public void widgetSelected(@Nullable SelectionEvent e) {
92 updateContents();
93 }
94 });
95 fUseCustomDirectoryCheckbox = checkBox;
96
97 /* Nothing in the two following cells */
98 new Label(composite, SWT.NONE);
99 new Label(composite, SWT.NONE);
100
101 /* Second row: The text input box */
102 Text text = new Text(composite, SWT.BORDER);
103 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
104 text.setEditable(false);
105 text.setToolTipText(Messages.PreferencePage_CheckboxTooltip);
106 fCustomDirectoryPath = text;
107
108 /* The "Browse..." button */
109 Button browseButton = new Button(composite, SWT.NONE);
110 browseButton.setText(Messages.PreferencePage_ButtonBrowse);
111 browseButton.addSelectionListener(new SelectionAdapter() {
112 @Override
113 public void widgetSelected(@Nullable SelectionEvent e) {
114 browseDirectory(checkNotNull(fCustomDirectoryPath), Messages.PreferencePage_BrowseDialogTitle);
115 }
116 });
117 fBrowseButton = browseButton;
118
119 /* The "Clear" button */
120 Button clearButton = new Button(composite, SWT.NONE);
121 clearButton.setText(Messages.PreferencePage_ButtonClear);
122 clearButton.addSelectionListener(new SelectionAdapter() {
123 @Override
124 public void widgetSelected(@Nullable SelectionEvent e) {
125 checkNotNull(fCustomDirectoryPath).setText(""); //$NON-NLS-1$
126 updateContents();
127 }
128 });
129 fClearButton = clearButton;
130
131 /* Load existing preferences */
132 loadCurrentSettings();
133
134 return composite;
135 }
136
137 private void browseDirectory(Text textField, @Nullable String dialogTitle) {
138 DirectoryDialog dialog = new DirectoryDialog(getShell());
139 dialog.setText(dialogTitle);
140 String dirPath = dialog.open();
141 if (dirPath != null) {
142 textField.setText(dirPath);
143 updateContents();
144 }
145 }
146
147 private void loadCurrentSettings() {
148 /* The settings are currently stored in the trace object */
149 LttngUstTrace trace = getSymbolProvider().getTrace();
150 SymbolProviderConfig config = trace.getSymbolProviderConfig();
151
152 checkNotNull(fUseCustomDirectoryCheckbox).setSelection(config.useCustomRootDir());
153 checkNotNull(fCustomDirectoryPath).setText(config.getCustomRootDirPath());
154
155 updateContents();
156 }
157
158 @Override
159 public void saveConfiguration() {
160 SymbolProviderConfig config =
161 new SymbolProviderConfig(getCurrentCheckBoxState(), getCurrentPathPrefix());
162
163 LttngUstTrace trace = getSymbolProvider().getTrace();
164 trace.setSymbolProviderConfig(config);
165 }
166
167 private boolean getCurrentCheckBoxState() {
168 return (checkNotNull(fUseCustomDirectoryCheckbox).getSelection());
169 }
170
171 private String getCurrentPathPrefix() {
172 return nullToEmptyString(checkNotNull(fCustomDirectoryPath).getText());
173 }
174
175 /**
176 * Grey out the relevant controls if the checkbox is unchecked, and vice
177 * versa. Also verify if the current settings are valid, and update the
178 * window error message if needed.
179 */
180 private void updateContents() {
181 boolean useCustomDirEnabled = getCurrentCheckBoxState();
182 checkNotNull(fCustomDirectoryPath).setEnabled(useCustomDirEnabled);
183 checkNotNull(fBrowseButton).setEnabled(useCustomDirEnabled);
184 checkNotNull(fClearButton).setEnabled(useCustomDirEnabled);
185
186 String errorMessage = null;
187
188 if (useCustomDirEnabled) {
189 String pathPrefix = getCurrentPathPrefix();
190 Path path = Paths.get(pathPrefix);
191 if (pathPrefix.equals("") || !Files.isDirectory(path)) { //$NON-NLS-1$
192 errorMessage = Messages.PreferencePage_ErrorDirectoryDoesNotExists;
193 }
194 }
195 setErrorMessage(errorMessage);
196 setValid(errorMessage == null);
197 }
198
199}
This page took 0.040327 seconds and 5 git commands to generate.