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
.viewers
.CheckStateChangedEvent
;
26 import org
.eclipse
.jface
.viewers
.CheckboxTreeViewer
;
27 import org
.eclipse
.jface
.viewers
.ICheckStateListener
;
28 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
29 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
30 import org
.eclipse
.jface
.viewers
.LabelProvider
;
31 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
32 import org
.eclipse
.jface
.viewers
.Viewer
;
33 import org
.eclipse
.remote
.core
.IRemoteConnection
;
34 import org
.eclipse
.remote
.ui
.widgets
.RemoteResourceBrowserWidget
;
35 import org
.eclipse
.swt
.SWT
;
36 import org
.eclipse
.swt
.events
.SelectionAdapter
;
37 import org
.eclipse
.swt
.events
.SelectionEvent
;
38 import org
.eclipse
.swt
.graphics
.Image
;
39 import org
.eclipse
.swt
.layout
.GridData
;
40 import org
.eclipse
.swt
.layout
.GridLayout
;
41 import org
.eclipse
.swt
.widgets
.Button
;
42 import org
.eclipse
.swt
.widgets
.Composite
;
43 import org
.eclipse
.swt
.widgets
.Control
;
44 import org
.eclipse
.swt
.widgets
.Shell
;
45 import org
.eclipse
.swt
.widgets
.Tree
;
46 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.LttngProfileManager
;
47 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
48 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
49 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.LTTngControlServiceConstants
;
50 import org
.eclipse
.ui
.ISharedImages
;
51 import org
.eclipse
.ui
.PlatformUI
;
54 * Dialog box for collecting parameter for loading a session.
56 * @author Bernd Hufmann
57 * @author Patrick-Jeffrey Pollo Guilbert
58 * @author William Enright
59 * @author William Tri-Khiem Truong
62 public class LoadDialog
extends TitleAreaDialog
implements ILoadDialog
{
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
66 /** The icon file for this dialog box. */
67 public static final String IMPORT_ICON_FILE
= "icons/elcl16/import_button.png"; //$NON-NLS-1$
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
73 * The dialog composite.
75 private Composite fDialogComposite
= null;
76 private Button fLocalButton
= null;
77 private Button fRemoteButton
= null;
79 private Composite fLocalComposite
= null;
80 private CheckboxTreeViewer fFolderViewer
;
82 private Button fForceButton
= null;
84 private RemoteResourceBrowserWidget fFileWidget
;
85 private IRemoteConnection fConnection
= null;
87 private List
<IFileStore
> fLocalFiles
= null;
88 private List
<IFileStore
> fRemoteFiles
= null;
90 private boolean fIsForce
= true;
92 // ------------------------------------------------------------------------
94 // ------------------------------------------------------------------------
99 * - a shell for the display of the dialog
101 public LoadDialog(Shell shell
) {
103 setShellStyle(SWT
.RESIZE
| getShellStyle());
107 public List
<IFileStore
> getRemoteResources() {
112 public List
<IFileStore
> getLocalResources() {
117 public boolean isForce() {
122 public void initialize (IRemoteConnection connection
) {
123 fConnection
= connection
;
129 // ------------------------------------------------------------------------
131 // ------------------------------------------------------------------------
133 protected void configureShell(Shell newShell
) {
134 super.configureShell(newShell
);
135 newShell
.setText(Messages
.TraceControl_LoadDialogTitle
);
136 newShell
.setImage(Activator
.getDefault().loadIcon(IMPORT_ICON_FILE
));
140 protected Control
createDialogArea(Composite parent
) {
142 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
143 GridLayout layout
= new GridLayout(1, true);
144 fDialogComposite
.setLayout(layout
);
145 GridData data
= new GridData(GridData
.FILL_BOTH
);
146 data
.heightHint
= 300;
147 fDialogComposite
.setLayoutData(data
);
149 createSelectionGroup();
150 createOptionComposite();
151 fLocalComposite
= null;
153 createLocalComposite();
154 setMessage(Messages
.TraceControl_SelectProfileText
);
155 return fDialogComposite
;
158 private void createSelectionGroup() {
159 Composite group
= new Composite(fDialogComposite
, SWT
.BORDER
);
160 group
.setLayout(new GridLayout(2, true));
161 group
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
163 fLocalButton
= new Button(group
, SWT
.RADIO
);
164 fLocalButton
.setText(Messages
.TraceControl_LocalButtonText
);
165 fLocalButton
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
166 fLocalButton
.setSelection(true);
168 fRemoteButton
= new Button(group
, SWT
.RADIO
);
169 fRemoteButton
.setText(Messages
.TraceControl_RemoteButtonText
);
170 fRemoteButton
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
172 fLocalButton
.addSelectionListener(new SelectionAdapter() {
174 public void widgetSelected(SelectionEvent e
) {
175 if (fLocalButton
.getSelection()) {
176 disposeRemoteComposite();
177 createLocalComposite();
179 fDialogComposite
.layout();
180 enableLocalButtons();
185 fRemoteButton
.addSelectionListener(new SelectionAdapter() {
187 public void widgetSelected(SelectionEvent e
) {
188 if (fRemoteButton
.getSelection()) {
189 disposeLocalComposite();
190 createRemoteComposite();
192 fDialogComposite
.layout();
193 enableRemoteButtons();
199 private void createLocalComposite() {
200 if (fLocalComposite
== null) {
201 fLocalComposite
= new Composite(fDialogComposite
, SWT
.BORDER
);
202 fLocalComposite
.setLayout(new GridLayout(2, false));
203 fLocalComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
205 Composite viewerComposite
= new Composite(fLocalComposite
, SWT
.NONE
);
206 viewerComposite
.setLayout(new GridLayout(1, false));
207 viewerComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
209 fFolderViewer
= new CheckboxTreeViewer(viewerComposite
);
210 fFolderViewer
.setContentProvider(new ProfileContentProvider());
211 fFolderViewer
.setLabelProvider(new ProfileLabelProvider());
212 fFolderViewer
.setInput(LttngProfileManager
.getProfiles());
214 GridData data
= new GridData(GridData
.FILL_BOTH
);
215 Tree tree
= fFolderViewer
.getTree();
216 tree
.setLayoutData(data
);
218 fFolderViewer
.addCheckStateListener(new ICheckStateListener() {
220 public void checkStateChanged(CheckStateChangedEvent event
) {
221 enableLocalButtons();
228 * Disposes the remote composite (if existing)
230 private void disposeLocalComposite() {
231 if (fLocalComposite
!= null) {
232 fLocalComposite
.dispose();
233 fLocalComposite
= null;
237 private void createRemoteComposite() {
238 if (fFileWidget
== null) {
239 fFileWidget
= new RemoteResourceBrowserWidget(fDialogComposite
, SWT
.BORDER
, RemoteResourceBrowserWidget
.SHOW_HIDDEN_CHECKBOX
);
240 fFileWidget
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
241 fFileWidget
.setInitialPath(LTTngControlServiceConstants
.DEFAULT_PATH
);
242 fFileWidget
.setConnection(fConnection
);
243 fFileWidget
.addSelectionChangedListener(new ISelectionChangedListener() {
245 public void selectionChanged(SelectionChangedEvent event
) {
246 enableRemoteButtons();
249 getButton(IDialogConstants
.OK_ID
).setEnabled(true);
254 * Disposes the remote composite (if existing)
256 private void disposeRemoteComposite() {
257 if (fFileWidget
!= null) {
258 fFileWidget
.dispose();
263 private void createOptionComposite() {
264 Composite group
= new Composite(fDialogComposite
, SWT
.BORDER
);
265 group
.setLayout(new GridLayout(1, true));
266 group
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
268 fForceButton
= new Button(group
, SWT
.CHECK
);
269 fForceButton
.setText(Messages
.TraceControl_ForceButtonText
);
270 fForceButton
.setSelection(true);
273 private void enableLocalButtons() {
274 Object
[] checked
= fFolderViewer
.getCheckedElements();
275 boolean enabled
= (checked
!= null) && (checked
.length
> 0);
276 Button okButton
= getButton(IDialogConstants
.OK_ID
);
277 if (okButton
!= null) {
278 okButton
.setEnabled(enabled
);
282 private void enableRemoteButtons() {
283 List
<IFileStore
> resources
= fFileWidget
.getResources();
284 boolean enabled
= (resources
!= null) && (resources
.size() > 0);
285 Button okButton
= getButton(IDialogConstants
.OK_ID
);
286 if (okButton
!= null) {
287 okButton
.setEnabled(enabled
);
292 protected void createButtonsForButtonBar(Composite parent
) {
293 createButton(parent
, IDialogConstants
.CANCEL_ID
, IDialogConstants
.CANCEL_LABEL
, false);
294 Button button
= createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.OK_LABEL
, false);
295 button
.setEnabled(false);
299 protected void okPressed() {
300 fIsForce
= fForceButton
.getSelection();
301 if (fFileWidget
!= null) {
302 fRemoteFiles
= fFileWidget
.getResources();
303 if (fRemoteFiles
.size() > 0) {
309 Object
[] files
= fFolderViewer
.getCheckedElements();
310 List
<IFileStore
> stores
= new ArrayList
<>();
311 for (Object file
: files
) {
312 if (file
instanceof File
) {
313 stores
.add(EFS
.getLocalFileSystem().fromLocalFile((File
) file
));
316 if (stores
.size() != 0) {
317 fLocalFiles
= stores
;
323 * Helper class for the contents of a folder in a tracing project
325 * @author Bernd Hufmann
327 public static class ProfileContentProvider
implements ITreeContentProvider
{
329 public Object
[] getChildren(Object o
) {
331 if (o
instanceof File
[]) {
334 File store
= (File
) o
;
335 if (store
.isDirectory()) {
336 return store
.listFiles();
338 return new Object
[0];
342 public Object
getParent(Object element
) {
343 return ((File
) element
).getParent();
347 public void dispose() {
351 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
355 public Object
[] getElements(Object inputElement
) {
356 return getChildren(inputElement
);
360 public boolean hasChildren(Object element
) {
361 return ((File
) element
).isDirectory();
365 static class ProfileLabelProvider
extends LabelProvider
{
367 public String
getText(Object element
) {
368 return ((File
) element
).getName();
372 public Image
getImage(Object element
) {
373 if (((File
) element
).isDirectory()) {
374 return PlatformUI
.getWorkbench().getSharedImages().getImage(ISharedImages
.IMG_OBJ_FOLDER
);
376 return PlatformUI
.getWorkbench().getSharedImages().getImage(ISharedImages
.IMG_OBJ_FILE
);