control: Add LTTng profile preference page
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / dialogs / LoadDialog.java
CommitLineData
f4da4c59
BH
1/**********************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal, Ericsson
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
8 *
9 * Contributors:
10 * Contributors:
11 * Patrick-Jeffrey Pollo Guilbert, William Enright,
12 * William Tri-Khiem Truong - Initial API and implementation
13 * Bernd Hufmann - Renamed from ProfileHandler and redesign
14 **********************************************************************/
15package org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs;
16
17import java.io.File;
18import java.util.ArrayList;
19import java.util.List;
20
21import org.eclipse.core.filesystem.EFS;
22import org.eclipse.core.filesystem.IFileStore;
23import org.eclipse.jface.dialogs.IDialogConstants;
24import org.eclipse.jface.dialogs.TitleAreaDialog;
fc9ff6c4 25import org.eclipse.jface.preference.PreferenceDialog;
f4da4c59
BH
26import org.eclipse.jface.viewers.CheckStateChangedEvent;
27import org.eclipse.jface.viewers.CheckboxTreeViewer;
28import org.eclipse.jface.viewers.ICheckStateListener;
29import org.eclipse.jface.viewers.ISelectionChangedListener;
f4da4c59 30import org.eclipse.jface.viewers.SelectionChangedEvent;
f4da4c59
BH
31import org.eclipse.remote.core.IRemoteConnection;
32import org.eclipse.remote.ui.widgets.RemoteResourceBrowserWidget;
33import org.eclipse.swt.SWT;
34import org.eclipse.swt.events.SelectionAdapter;
35import org.eclipse.swt.events.SelectionEvent;
f4da4c59
BH
36import org.eclipse.swt.layout.GridData;
37import org.eclipse.swt.layout.GridLayout;
38import org.eclipse.swt.widgets.Button;
39import org.eclipse.swt.widgets.Composite;
40import org.eclipse.swt.widgets.Control;
41import org.eclipse.swt.widgets.Shell;
f4da4c59
BH
42import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator;
43import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
fc9ff6c4
BH
44import org.eclipse.tracecompass.internal.lttng2.control.ui.views.preferences.ControlRemoteProfilesPreferencePage;
45import org.eclipse.tracecompass.internal.lttng2.control.ui.views.preferences.LTTngProfileViewer;
f4da4c59 46import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.LTTngControlServiceConstants;
fc9ff6c4 47import org.eclipse.ui.dialogs.PreferencesUtil;
f4da4c59
BH
48
49/**
50 * Dialog box for collecting parameter for loading a session.
51 *
52 * @author Bernd Hufmann
53 * @author Patrick-Jeffrey Pollo Guilbert
54 * @author William Enright
55 * @author William Tri-Khiem Truong
56 *
57 */
58public class LoadDialog extends TitleAreaDialog implements ILoadDialog {
59 // ------------------------------------------------------------------------
60 // Constants
61 // ------------------------------------------------------------------------
62 /** The icon file for this dialog box. */
63 public static final String IMPORT_ICON_FILE = "icons/elcl16/import_button.png"; //$NON-NLS-1$
64
65 // ------------------------------------------------------------------------
66 // Constants
67 // ------------------------------------------------------------------------
68 /**
69 * The dialog composite.
70 */
71 private Composite fDialogComposite = null;
72 private Button fLocalButton = null;
73 private Button fRemoteButton = null;
74
75 private Composite fLocalComposite = null;
76 private CheckboxTreeViewer fFolderViewer;
77
78 private Button fForceButton = null;
79
80 private RemoteResourceBrowserWidget fFileWidget;
81 private IRemoteConnection fConnection = null;
82
83 private List<IFileStore> fLocalFiles = null;
84 private List<IFileStore> fRemoteFiles = null;
85
86 private boolean fIsForce = true;
87
88 // ------------------------------------------------------------------------
89 // Constructors
90 // ------------------------------------------------------------------------
91 /**
92 * Constructor
93 *
94 * @param shell
95 * - a shell for the display of the dialog
96 */
97 public LoadDialog(Shell shell) {
98 super(shell);
99 setShellStyle(SWT.RESIZE | getShellStyle());
100 }
101
102 @Override
103 public List<IFileStore> getRemoteResources() {
104 return fRemoteFiles;
105 }
106
107 @Override
108 public List<IFileStore> getLocalResources() {
109 return fLocalFiles;
110 }
111
112 @Override
113 public boolean isForce() {
114 return fIsForce;
115 }
116
117 @Override
118 public void initialize (IRemoteConnection connection) {
119 fConnection = connection;
120 fIsForce = true;
121 fRemoteFiles = null;
122 fLocalFiles = null;
123 }
124
125 // ------------------------------------------------------------------------
126 // Operations
127 // ------------------------------------------------------------------------
128 @Override
129 protected void configureShell(Shell newShell) {
130 super.configureShell(newShell);
131 newShell.setText(Messages.TraceControl_LoadDialogTitle);
132 newShell.setImage(Activator.getDefault().loadIcon(IMPORT_ICON_FILE));
133 }
134
135 @Override
136 protected Control createDialogArea(Composite parent) {
137 // Main dialog panel
138 fDialogComposite = new Composite(parent, SWT.NONE);
139 GridLayout layout = new GridLayout(1, true);
140 fDialogComposite.setLayout(layout);
141 GridData data = new GridData(GridData.FILL_BOTH);
142 data.heightHint = 300;
143 fDialogComposite.setLayoutData(data);
144
145 createSelectionGroup();
146 createOptionComposite();
147 fLocalComposite = null;
148 fFileWidget = null;
149 createLocalComposite();
150 setMessage(Messages.TraceControl_SelectProfileText);
151 return fDialogComposite;
152 }
153
154 private void createSelectionGroup() {
155 Composite group = new Composite(fDialogComposite, SWT.BORDER);
156 group.setLayout(new GridLayout(2, true));
157 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
158
159 fLocalButton = new Button(group, SWT.RADIO);
160 fLocalButton.setText(Messages.TraceControl_LocalButtonText);
161 fLocalButton.setLayoutData(new GridData(GridData.FILL_BOTH));
162 fLocalButton.setSelection(true);
163
164 fRemoteButton = new Button(group, SWT.RADIO);
165 fRemoteButton.setText(Messages.TraceControl_RemoteButtonText);
166 fRemoteButton.setLayoutData(new GridData(GridData.FILL_BOTH));
167
168 fLocalButton.addSelectionListener(new SelectionAdapter() {
169 @Override
170 public void widgetSelected(SelectionEvent e) {
171 if (fLocalButton.getSelection()) {
172 disposeRemoteComposite();
173 createLocalComposite();
174 fRemoteFiles = null;
175 fDialogComposite.layout();
176 enableLocalButtons();
177 }
178 }
179 });
180
181 fRemoteButton.addSelectionListener(new SelectionAdapter() {
182 @Override
183 public void widgetSelected(SelectionEvent e) {
184 if (fRemoteButton.getSelection()) {
185 disposeLocalComposite();
186 createRemoteComposite();
187 fLocalFiles = null;
188 fDialogComposite.layout();
189 enableRemoteButtons();
190 }
191 }
192 });
193 }
194
195 private void createLocalComposite() {
196 if (fLocalComposite == null) {
197 fLocalComposite = new Composite(fDialogComposite, SWT.BORDER);
198 fLocalComposite.setLayout(new GridLayout(2, false));
199 fLocalComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
200
fc9ff6c4
BH
201 fFolderViewer = LTTngProfileViewer.createLTTngProfileViewer(fLocalComposite, SWT.NONE);
202 fFolderViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
f4da4c59
BH
203 fFolderViewer.addCheckStateListener(new ICheckStateListener() {
204 @Override
205 public void checkStateChanged(CheckStateChangedEvent event) {
206 enableLocalButtons();
207 }
208 });
209 }
210 }
211
212 /**
213 * Disposes the remote composite (if existing)
214 */
215 private void disposeLocalComposite() {
216 if (fLocalComposite != null) {
217 fLocalComposite.dispose();
218 fLocalComposite = null;
219 }
220 }
221
222 private void createRemoteComposite() {
223 if (fFileWidget == null) {
224 fFileWidget = new RemoteResourceBrowserWidget(fDialogComposite, SWT.BORDER, RemoteResourceBrowserWidget.SHOW_HIDDEN_CHECKBOX);
225 fFileWidget.setLayoutData(new GridData(GridData.FILL_BOTH));
226 fFileWidget.setInitialPath(LTTngControlServiceConstants.DEFAULT_PATH);
227 fFileWidget.setConnection(fConnection);
228 fFileWidget.addSelectionChangedListener(new ISelectionChangedListener() {
229 @Override
230 public void selectionChanged(SelectionChangedEvent event) {
231 enableRemoteButtons();
232 }
233 });
234 getButton(IDialogConstants.OK_ID).setEnabled(true);
235 }
236 }
237
238 /**
239 * Disposes the remote composite (if existing)
240 */
241 private void disposeRemoteComposite() {
242 if (fFileWidget != null) {
243 fFileWidget.dispose();
244 fFileWidget = null;
245 }
246 }
247
248 private void createOptionComposite() {
249 Composite group = new Composite(fDialogComposite, SWT.BORDER);
250 group.setLayout(new GridLayout(1, true));
251 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
252
253 fForceButton = new Button(group, SWT.CHECK);
254 fForceButton.setText(Messages.TraceControl_ForceButtonText);
255 fForceButton.setSelection(true);
256 }
257
258 private void enableLocalButtons() {
259 Object[] checked = fFolderViewer.getCheckedElements();
260 boolean enabled = (checked != null) && (checked.length > 0);
261 Button okButton = getButton(IDialogConstants.OK_ID);
262 if (okButton != null) {
263 okButton.setEnabled(enabled);
264 }
265 }
266
267 private void enableRemoteButtons() {
268 List<IFileStore> resources = fFileWidget.getResources();
269 boolean enabled = (resources != null) && (resources.size() > 0);
270 Button okButton = getButton(IDialogConstants.OK_ID);
271 if (okButton != null) {
272 okButton.setEnabled(enabled);
273 }
274 }
275
276 @Override
fc9ff6c4 277 protected void createButtonsForButtonBar(final Composite parent) {
f4da4c59 278 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
fc9ff6c4
BH
279 Button manageButton = createButton(parent, IDialogConstants.CLIENT_ID + 1, Messages.TraceControl_ManageButtonText, false);
280 manageButton.addSelectionListener(new SelectionAdapter() {
281 @Override
282 public void widgetSelected(SelectionEvent e) {
283 PreferenceDialog dialog =
284 PreferencesUtil.createPreferenceDialogOn(parent.getShell(),
285 ControlRemoteProfilesPreferencePage.ID,
286 new String[] { ControlRemoteProfilesPreferencePage.ID },
287 null);
288 dialog.open();
289 if (fLocalComposite != null) {
290 fFolderViewer.setInput(LTTngProfileViewer.getViewerInput());
291 enableLocalButtons();
292 }
293 }
294 });
f4da4c59
BH
295 Button button = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false);
296 button.setEnabled(false);
297 }
298
299 @Override
300 protected void okPressed() {
301 fIsForce = fForceButton.getSelection();
302 if (fFileWidget != null) {
303 fRemoteFiles = fFileWidget.getResources();
304 if (fRemoteFiles.size() > 0) {
305 super.okPressed();
306 }
307 return;
308 }
309
310 Object[] files = fFolderViewer.getCheckedElements();
311 List<IFileStore> stores = new ArrayList<>();
312 for (Object file : files) {
313 if (file instanceof File) {
314 stores.add(EFS.getLocalFileSystem().fromLocalFile((File) file));
315 }
316 }
317 if (stores.size() != 0) {
318 fLocalFiles = stores;
319 super.okPressed();
320 }
321 }
322
f4da4c59 323}
This page took 0.053273 seconds and 5 git commands to generate.