1 /*******************************************************************************
2 * Copyright (c) 2011 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 * Patrick Tasse - Initial API and implementation
12 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng
.ui
.tracecontrol
.dialogs
;
15 import org
.eclipse
.core
.resources
.IProject
;
16 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
17 import org
.eclipse
.core
.runtime
.CoreException
;
18 import org
.eclipse
.jface
.dialogs
.Dialog
;
19 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
20 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.LTTngProjectNature
;
21 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.tracecontrol
.model
.TraceResource
;
22 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.tracecontrol
.model
.TraceResource
.TraceState
;
23 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.Activator
;
24 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.tracecontrol
.Messages
;
25 import org
.eclipse
.rse
.ui
.SystemBasePlugin
;
26 import org
.eclipse
.swt
.SWT
;
27 import org
.eclipse
.swt
.layout
.GridData
;
28 import org
.eclipse
.swt
.layout
.GridLayout
;
29 import org
.eclipse
.swt
.widgets
.Button
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
31 import org
.eclipse
.swt
.widgets
.Control
;
32 import org
.eclipse
.swt
.widgets
.Label
;
33 import org
.eclipse
.swt
.widgets
.Shell
;
34 import org
.eclipse
.swt
.widgets
.Table
;
35 import org
.eclipse
.swt
.widgets
.TableColumn
;
36 import org
.eclipse
.swt
.widgets
.TableItem
;
37 import org
.eclipse
.swt
.widgets
.Text
;
40 * <b><u>ImportTraceDialog</u></b>
42 * Dialog box to import a trace a LTTng project.
45 public class ImportTraceDialog
extends Dialog
{
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
50 private TraceResource fTrace
;
52 private Text fNameText
;
53 private Button fLinkOnlyButton
;
54 private IProject fProject
;
55 private String fTraceName
;
56 private boolean fLinkOnly
= false;
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
65 * @param parentShell The parent shell
66 * @param trace The trace to import
68 public ImportTraceDialog(Shell parentShell
, TraceResource trace
) {
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
78 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
81 protected Control
createDialogArea(Composite parent
) {
82 getShell().setText(Messages
.ImportTraceDialog_Title
);
83 getShell().setImage(Activator
.getDefault().getImage(Activator
.ICON_ID_IMPORT_TRACE
));
85 Composite composite
= new Composite(parent
, SWT
.NONE
);
86 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
87 composite
.setLayout(new GridLayout(1, false));
89 Label tableLabel
= new Label(composite
, SWT
.NONE
);
90 tableLabel
.setText(Messages
.ImportTraceDialog_TableLabel
);
92 fTable
= new Table(composite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.FULL_SELECTION
);
93 fTable
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
94 fTable
.setHeaderVisible(true);
95 fTable
.setLinesVisible(true);
97 TableColumn column
= new TableColumn(fTable
, SWT
.CENTER
);
98 column
.setText(Messages
.ImportTraceDialog_ProjectColumn
);
100 for (IProject project
: ResourcesPlugin
.getWorkspace().getRoot().getProjects()) {
102 if (project
.isOpen() && project
.hasNature(LTTngProjectNature
.ID
)) {
103 TableItem item
= new TableItem(fTable
, SWT
.LEFT
);
104 item
.setText(0, project
.getName());
105 item
.setData(project
);
107 } catch (CoreException e
) {
108 SystemBasePlugin
.logError("ImportTraceDialog", e
); //$NON-NLS-1$
112 for (int i
= 0; i
< fTable
.getColumnCount(); i
++) {
113 fTable
.getColumn(i
).pack();
116 Composite nameComposite
= new Composite(composite
, SWT
.NONE
);
117 nameComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
118 GridLayout gl
= new GridLayout(2, false);
121 nameComposite
.setLayout(gl
);
123 Label nameLabel
= new Label(nameComposite
, SWT
.NONE
);
124 nameLabel
.setText(Messages
.ImportTraceDialog_NameLabel
);
126 fNameText
= new Text(nameComposite
, SWT
.BORDER
);
127 fNameText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
128 fNameText
.setText(fTrace
.getName());
130 if (fTrace
.getTraceConfig().isNetworkTrace()) {
131 fLinkOnlyButton
= new Button(composite
, SWT
.CHECK
);
132 fLinkOnlyButton
.setText(Messages
.ImportTraceDialog_LinkOnly
);
133 fLinkOnlyButton
.setSelection(true);
135 if (fTrace
.getTraceState() != TraceState
.STOPPED
) {
136 // if the trace is not stopped, link is the only allowed option
137 fLinkOnlyButton
.setEnabled(false);
146 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
149 protected void createButtonsForButtonBar(Composite parent
) {
150 super.createButtonsForButtonBar(parent
);
151 getButton(IDialogConstants
.OK_ID
).setText(Messages
.ImportTraceDialog_ImportButton
);
156 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
159 protected void okPressed() {
160 TableItem
[] selection
= fTable
.getSelection();
161 if (selection
.length
> 0) {
162 fProject
= (IProject
) selection
[0].getData();
164 fTraceName
= fNameText
.getText();
165 if (fLinkOnlyButton
!= null) {
166 fLinkOnly
= fLinkOnlyButton
.getSelection();
172 * Returns the project to import to.
174 * @return project to import to.
176 public IProject
getProject() {
181 * Gets the name of the trace in the LTTng project.
185 public String
getTraceName() {
190 * Returns if trace should be linked or copied to the project.
191 * Only applicable for traces residing on local host.
193 * @return true if trace should be linked to the project,
194 * false if it should be copied
196 public boolean getLinkOnly() {