Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / tracecontrol / dialogs / ImportTraceDialog.java
CommitLineData
e8d771d5
BH
1/*******************************************************************************
2 * Copyright (c) 2011 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 * Patrick Tasse - Initial API and implementation
11 *
12 *******************************************************************************/
13package org.eclipse.linuxtools.lttng.ui.tracecontrol.dialogs;
14
15import org.eclipse.core.resources.IProject;
16import org.eclipse.core.resources.ResourcesPlugin;
17import org.eclipse.core.runtime.CoreException;
18import org.eclipse.jface.dialogs.Dialog;
19import org.eclipse.jface.dialogs.IDialogConstants;
6c13869b
FC
20import org.eclipse.linuxtools.lttng.core.LTTngProjectNature;
21import org.eclipse.linuxtools.lttng.core.tracecontrol.model.TraceResource;
22import org.eclipse.linuxtools.lttng.core.tracecontrol.model.TraceResource.TraceState;
e8d771d5
BH
23import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin;
24import org.eclipse.linuxtools.lttng.ui.tracecontrol.Messages;
25import org.eclipse.rse.ui.SystemBasePlugin;
26import org.eclipse.swt.SWT;
27import org.eclipse.swt.layout.GridData;
28import org.eclipse.swt.layout.GridLayout;
29import org.eclipse.swt.widgets.Button;
30import org.eclipse.swt.widgets.Composite;
31import org.eclipse.swt.widgets.Control;
32import org.eclipse.swt.widgets.Label;
33import org.eclipse.swt.widgets.Shell;
34import org.eclipse.swt.widgets.Table;
35import org.eclipse.swt.widgets.TableColumn;
36import org.eclipse.swt.widgets.TableItem;
37import org.eclipse.swt.widgets.Text;
38
39/**
40 * <b><u>ImportTraceDialog</u></b>
41 * <p>
42 * Dialog box to import a trace a LTTng project.
43 * </p>
44 */
45public class ImportTraceDialog extends Dialog {
46
e8d771d5
BH
47 // ------------------------------------------------------------------------
48 // Attributes
49 // ------------------------------------------------------------------------
50 private TraceResource fTrace;
51 private Table fTable;
52 private Text fNameText;
53 private Button fLinkOnlyButton;
54 private IProject fProject;
55 private String fTraceName;
56 private boolean fLinkOnly = false;
57
58 // ------------------------------------------------------------------------
59 // Constructors
60 // ------------------------------------------------------------------------
61
62 /**
63 * Constructor
64 *
65 * @param parentShell The parent shell
66 * @param trace The trace to import
67 */
68 public ImportTraceDialog(Shell parentShell, TraceResource trace) {
69 super(parentShell);
70 fTrace = trace;
71 }
72
73 // ------------------------------------------------------------------------
74 // Operations
75 // ------------------------------------------------------------------------
76 /*
77 * (non-Javadoc)
78 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
79 */
80 @Override
81 protected Control createDialogArea(Composite parent) {
82 getShell().setText(Messages.ImportTraceDialog_Title);
83 getShell().setImage(LTTngUiPlugin.getDefault().getImage(LTTngUiPlugin.ICON_ID_IMPORT_TRACE));
84
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));
88
89 Label tableLabel = new Label(composite, SWT.NONE);
90 tableLabel.setText(Messages.ImportTraceDialog_TableLabel);
91
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);
96
97 TableColumn column = new TableColumn(fTable, SWT.CENTER);
98 column.setText(Messages.ImportTraceDialog_ProjectColumn);
99
100 for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
101 try {
a79913eb 102 if (project.isOpen() && project.hasNature(LTTngProjectNature.ID)) {
e8d771d5
BH
103 TableItem item = new TableItem(fTable, SWT.LEFT);
104 item.setText(0, project.getName());
105 item.setData(project);
106 }
107 } catch (CoreException e) {
108 SystemBasePlugin.logError("ImportTraceDialog", e); //$NON-NLS-1$
109 }
110 }
111
112 for (int i = 0; i < fTable.getColumnCount(); i++) {
113 fTable.getColumn(i).pack();
114 }
115
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);
119 gl.marginWidth = 0;
120 gl.marginHeight = 0;
121 nameComposite.setLayout(gl);
122
123 Label nameLabel = new Label(nameComposite, SWT.NONE);
124 nameLabel.setText(Messages.ImportTraceDialog_NameLabel);
125
126 fNameText = new Text(nameComposite, SWT.BORDER);
127 fNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
128 fNameText.setText(fTrace.getName());
129
130 if (fTrace.getTraceConfig().isNetworkTrace()) {
131 fLinkOnlyButton = new Button(composite, SWT.CHECK);
132 fLinkOnlyButton.setText(Messages.ImportTraceDialog_LinkOnly);
a79913eb
FC
133 fLinkOnlyButton.setSelection(true);
134 fLinkOnly = true;
135 if (fTrace.getTraceState() != TraceState.STOPPED) {
136 // if the trace is not stopped, link is the only allowed option
137 fLinkOnlyButton.setEnabled(false);
138 }
e8d771d5
BH
139 }
140
141 return composite;
142 }
143
144 /*
145 * (non-Javadoc)
146 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
147 */
148 @Override
149 protected void createButtonsForButtonBar(Composite parent) {
150 super.createButtonsForButtonBar(parent);
151 getButton(IDialogConstants.OK_ID).setText(Messages.ImportTraceDialog_ImportButton);
152 }
153
154 /*
155 * (non-Javadoc)
156 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
157 */
158 @Override
159 protected void okPressed() {
160 TableItem[] selection = fTable.getSelection();
161 if (selection.length > 0) {
162 fProject = (IProject) selection[0].getData();
163 }
164 fTraceName = fNameText.getText();
165 if (fLinkOnlyButton != null) {
166 fLinkOnly = fLinkOnlyButton.getSelection();
167 }
168 super.okPressed();
169 }
170
171 /**
172 * Returns the project to import to.
173 *
174 * @return project to import to.
175 */
176 public IProject getProject() {
177 return fProject;
178 }
179
180 /**
181 * Gets the name of the trace in the LTTng project.
182 *
183 * @return
184 */
185 public String getTraceName() {
186 return fTraceName;
187 }
188
189 /**
190 * Returns if trace should be linked or copied to the project.
191 * Only applicable for traces residing on local host.
192 *
193 * @return true if trace should be linked to the project,
194 * false if it should be copied
195 */
196 public boolean getLinkOnly() {
197 return fLinkOnly;
198 }
199}
This page took 0.032416 seconds and 5 git commands to generate.