Commit | Line | Data |
---|---|---|
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 | *******************************************************************************/ | |
13 | package org.eclipse.linuxtools.lttng.ui.tracecontrol.dialogs; | |
14 | ||
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.lttng.tracecontrol.model.TraceResource; | |
21 | import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; | |
22 | import org.eclipse.linuxtools.lttng.ui.tracecontrol.Messages; | |
23 | import org.eclipse.rse.ui.SystemBasePlugin; | |
24 | import org.eclipse.swt.SWT; | |
25 | import org.eclipse.swt.layout.GridData; | |
26 | import org.eclipse.swt.layout.GridLayout; | |
27 | import org.eclipse.swt.widgets.Button; | |
28 | import org.eclipse.swt.widgets.Composite; | |
29 | import org.eclipse.swt.widgets.Control; | |
30 | import org.eclipse.swt.widgets.Label; | |
31 | import org.eclipse.swt.widgets.Shell; | |
32 | import org.eclipse.swt.widgets.Table; | |
33 | import org.eclipse.swt.widgets.TableColumn; | |
34 | import org.eclipse.swt.widgets.TableItem; | |
35 | import org.eclipse.swt.widgets.Text; | |
36 | ||
37 | /** | |
38 | * <b><u>ImportTraceDialog</u></b> | |
39 | * <p> | |
40 | * Dialog box to import a trace a LTTng project. | |
41 | * </p> | |
42 | */ | |
43 | public class ImportTraceDialog extends Dialog { | |
44 | ||
45 | public static final String LTTngProjectNatureID = "org.eclipse.linuxtools.lttng.ui.views.project.LTTngProjectNature"; //$NON-NLS-1$ | |
46 | ||
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 { | |
102 | if (project.hasNature(LTTngProjectNatureID)) { | |
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); | |
133 | } | |
134 | ||
135 | return composite; | |
136 | } | |
137 | ||
138 | /* | |
139 | * (non-Javadoc) | |
140 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) | |
141 | */ | |
142 | @Override | |
143 | protected void createButtonsForButtonBar(Composite parent) { | |
144 | super.createButtonsForButtonBar(parent); | |
145 | getButton(IDialogConstants.OK_ID).setText(Messages.ImportTraceDialog_ImportButton); | |
146 | } | |
147 | ||
148 | /* | |
149 | * (non-Javadoc) | |
150 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | |
151 | */ | |
152 | @Override | |
153 | protected void okPressed() { | |
154 | TableItem[] selection = fTable.getSelection(); | |
155 | if (selection.length > 0) { | |
156 | fProject = (IProject) selection[0].getData(); | |
157 | } | |
158 | fTraceName = fNameText.getText(); | |
159 | if (fLinkOnlyButton != null) { | |
160 | fLinkOnly = fLinkOnlyButton.getSelection(); | |
161 | } | |
162 | super.okPressed(); | |
163 | } | |
164 | ||
165 | /** | |
166 | * Returns the project to import to. | |
167 | * | |
168 | * @return project to import to. | |
169 | */ | |
170 | public IProject getProject() { | |
171 | return fProject; | |
172 | } | |
173 | ||
174 | /** | |
175 | * Gets the name of the trace in the LTTng project. | |
176 | * | |
177 | * @return | |
178 | */ | |
179 | public String getTraceName() { | |
180 | return fTraceName; | |
181 | } | |
182 | ||
183 | /** | |
184 | * Returns if trace should be linked or copied to the project. | |
185 | * Only applicable for traces residing on local host. | |
186 | * | |
187 | * @return true if trace should be linked to the project, | |
188 | * false if it should be copied | |
189 | */ | |
190 | public boolean getLinkOnly() { | |
191 | return fLinkOnly; | |
192 | } | |
193 | } |