1 /**********************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal, 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
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 **********************************************************************/
15 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import org
.eclipse
.core
.filesystem
.EFS
;
22 import org
.eclipse
.core
.filesystem
.IFileStore
;
23 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
24 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
25 import org
.eclipse
.jface
.preference
.PreferenceDialog
;
26 import org
.eclipse
.jface
.viewers
.CheckStateChangedEvent
;
27 import org
.eclipse
.jface
.viewers
.CheckboxTreeViewer
;
28 import org
.eclipse
.jface
.viewers
.ICheckStateListener
;
29 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
30 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
31 import org
.eclipse
.remote
.core
.IRemoteConnection
;
32 import org
.eclipse
.remote
.ui
.widgets
.RemoteResourceBrowserWidget
;
33 import org
.eclipse
.swt
.SWT
;
34 import org
.eclipse
.swt
.events
.SelectionAdapter
;
35 import org
.eclipse
.swt
.events
.SelectionEvent
;
36 import org
.eclipse
.swt
.layout
.GridData
;
37 import org
.eclipse
.swt
.layout
.GridLayout
;
38 import org
.eclipse
.swt
.widgets
.Button
;
39 import org
.eclipse
.swt
.widgets
.Composite
;
40 import org
.eclipse
.swt
.widgets
.Control
;
41 import org
.eclipse
.swt
.widgets
.Shell
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
43 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
44 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.preferences
.ControlRemoteProfilesPreferencePage
;
45 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.preferences
.LTTngProfileViewer
;
46 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.LTTngControlServiceConstants
;
47 import org
.eclipse
.ui
.dialogs
.PreferencesUtil
;
50 * Dialog box for collecting parameter for loading a session.
52 * @author Bernd Hufmann
53 * @author Patrick-Jeffrey Pollo Guilbert
54 * @author William Enright
55 * @author William Tri-Khiem Truong
58 public class LoadDialog
extends TitleAreaDialog
implements ILoadDialog
{
59 // ------------------------------------------------------------------------
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$
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
69 * The dialog composite.
71 private Composite fDialogComposite
= null;
72 private Button fLocalButton
= null;
73 private Button fRemoteButton
= null;
75 private Composite fLocalComposite
= null;
76 private CheckboxTreeViewer fFolderViewer
;
78 private Button fForceButton
= null;
80 private RemoteResourceBrowserWidget fFileWidget
;
81 private IRemoteConnection fConnection
= null;
83 private List
<IFileStore
> fLocalFiles
= null;
84 private List
<IFileStore
> fRemoteFiles
= null;
86 private boolean fIsForce
= true;
88 // ------------------------------------------------------------------------
90 // ------------------------------------------------------------------------
95 * - a shell for the display of the dialog
97 public LoadDialog(Shell shell
) {
99 setShellStyle(SWT
.RESIZE
| getShellStyle());
103 public List
<IFileStore
> getRemoteResources() {
108 public List
<IFileStore
> getLocalResources() {
113 public boolean isForce() {
118 public void initialize (IRemoteConnection connection
) {
119 fConnection
= connection
;
125 // ------------------------------------------------------------------------
127 // ------------------------------------------------------------------------
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
));
136 protected Control
createDialogArea(Composite parent
) {
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
);
145 createSelectionGroup();
146 createOptionComposite();
147 fLocalComposite
= null;
149 createLocalComposite();
150 setMessage(Messages
.TraceControl_SelectProfileText
);
151 return fDialogComposite
;
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
));
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);
164 fRemoteButton
= new Button(group
, SWT
.RADIO
);
165 fRemoteButton
.setText(Messages
.TraceControl_RemoteButtonText
);
166 fRemoteButton
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
168 fLocalButton
.addSelectionListener(new SelectionAdapter() {
170 public void widgetSelected(SelectionEvent e
) {
171 if (fLocalButton
.getSelection()) {
172 disposeRemoteComposite();
173 createLocalComposite();
175 fDialogComposite
.layout();
176 enableLocalButtons();
181 fRemoteButton
.addSelectionListener(new SelectionAdapter() {
183 public void widgetSelected(SelectionEvent e
) {
184 if (fRemoteButton
.getSelection()) {
185 disposeLocalComposite();
186 createRemoteComposite();
188 fDialogComposite
.layout();
189 enableRemoteButtons();
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
));
201 fFolderViewer
= LTTngProfileViewer
.createLTTngProfileViewer(fLocalComposite
, SWT
.NONE
);
202 fFolderViewer
.getTree().setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
203 fFolderViewer
.addCheckStateListener(new ICheckStateListener() {
205 public void checkStateChanged(CheckStateChangedEvent event
) {
206 enableLocalButtons();
213 * Disposes the remote composite (if existing)
215 private void disposeLocalComposite() {
216 if (fLocalComposite
!= null) {
217 fLocalComposite
.dispose();
218 fLocalComposite
= null;
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() {
230 public void selectionChanged(SelectionChangedEvent event
) {
231 enableRemoteButtons();
234 getButton(IDialogConstants
.OK_ID
).setEnabled(true);
239 * Disposes the remote composite (if existing)
241 private void disposeRemoteComposite() {
242 if (fFileWidget
!= null) {
243 fFileWidget
.dispose();
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
));
253 fForceButton
= new Button(group
, SWT
.CHECK
);
254 fForceButton
.setText(Messages
.TraceControl_ForceButtonText
);
255 fForceButton
.setSelection(true);
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
);
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
);
277 protected void createButtonsForButtonBar(final Composite parent
) {
278 createButton(parent
, IDialogConstants
.CANCEL_ID
, IDialogConstants
.CANCEL_LABEL
, false);
279 Button manageButton
= createButton(parent
, IDialogConstants
.CLIENT_ID
+ 1, Messages
.TraceControl_ManageButtonText
, false);
280 manageButton
.addSelectionListener(new SelectionAdapter() {
282 public void widgetSelected(SelectionEvent e
) {
283 PreferenceDialog dialog
=
284 PreferencesUtil
.createPreferenceDialogOn(parent
.getShell(),
285 ControlRemoteProfilesPreferencePage
.ID
,
286 new String
[] { ControlRemoteProfilesPreferencePage
.ID
},
289 if (fLocalComposite
!= null) {
290 fFolderViewer
.setInput(LTTngProfileViewer
.getViewerInput());
291 enableLocalButtons();
295 Button button
= createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.OK_LABEL
, false);
296 button
.setEnabled(false);
300 protected void okPressed() {
301 fIsForce
= fForceButton
.getSelection();
302 if (fFileWidget
!= null) {
303 fRemoteFiles
= fFileWidget
.getResources();
304 if (fRemoteFiles
.size() > 0) {
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
));
317 if (stores
.size() != 0) {
318 fLocalFiles
= stores
;