tmf.ui: Introduce TmfFileDialogFactory
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.remote.ui / src / org / eclipse / tracecompass / internal / tmf / remote / ui / wizards / fetch / RemoteFetchLogWizardPage.java
CommitLineData
417a4110
BH
1/*******************************************************************************
2 * Copyright (c) 2015 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 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12package org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch;
13
14import java.util.ArrayList;
15import java.util.List;
16
17import org.eclipse.core.runtime.NullProgressMonitor;
18import org.eclipse.jface.preference.PreferenceDialog;
19import org.eclipse.jface.viewers.IStructuredSelection;
20import org.eclipse.jface.window.Window;
21import org.eclipse.jface.wizard.IWizardPage;
22import org.eclipse.swt.SWT;
23import org.eclipse.swt.events.ControlAdapter;
24import org.eclipse.swt.events.ControlEvent;
25import org.eclipse.swt.events.SelectionAdapter;
26import org.eclipse.swt.events.SelectionEvent;
27import org.eclipse.swt.layout.GridData;
28import org.eclipse.swt.layout.GridLayout;
29import org.eclipse.swt.widgets.Button;
30import org.eclipse.swt.widgets.Combo;
31import org.eclipse.swt.widgets.Composite;
32import org.eclipse.swt.widgets.Group;
33import org.eclipse.swt.widgets.Label;
34import org.eclipse.swt.widgets.Text;
35import org.eclipse.tracecompass.internal.tmf.remote.ui.Activator;
36import org.eclipse.tracecompass.internal.tmf.remote.ui.messages.RemoteMessages;
37import org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement;
38import org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement;
39import org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.preferences.RemoteProfilesPreferencePage;
40import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizardPage;
41import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.Messages;
42import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement;
43import org.eclipse.ui.dialogs.PreferencesUtil;
44import org.eclipse.ui.plugin.AbstractUIPlugin;
45
46
47/**
48 * Wizard page for selection and managing remote profiles.
49 */
50public class RemoteFetchLogWizardPage extends ImportTraceWizardPage {
51
52 // ------------------------------------------------------------------------
53 // Constant(s)
54 // ------------------------------------------------------------------------
55 private static final String PAGE_NAME = "org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.RemoteFetchLogWizardPage"; //$NON-NLS-1$
56 private static final String ICON_PATH = "icons/elcl16/fetch_log_wiz.gif"; //$NON-NLS-1$
57
58 // ------------------------------------------------------------------------
59 // Attributes
60 // ------------------------------------------------------------------------
61 private Combo fProfileNameCombo;
62 private Text fNodesText;
63
64 // Button to overwrite existing resources or not
65 private Button fOverwriteExistingResourcesCheckbox;
66
67 private List<RemoteImportProfileElement> fProfiles = new ArrayList<>();
68 private RemoteImportProfileElement fProfile;
69
70 // ------------------------------------------------------------------------
71 // Constructor(s)
72 // ------------------------------------------------------------------------
73 /**
74 * Constructor
75 *
76 * @param title
77 * Name of page
78 * @param selection
79 * Current selection
80 */
81 public RemoteFetchLogWizardPage(String title, IStructuredSelection selection) {
82 super(PAGE_NAME, selection);
83 setTitle(title);
84 setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, ICON_PATH));
85 setDescription(RemoteMessages.RemoteFetchLogWizardPage_Description);
86 }
87
88 // ------------------------------------------------------------------------
89 // Operations
90 // ------------------------------------------------------------------------
91
92 @Override
93 public boolean finish() {
94 // Nothing to do for this page
95 return true;
96 }
97
98 @Override
99 public boolean canFlipToNextPage() {
100 return fProfile != null;
101 }
102
103 // ------------------------------------------------------------------------
104 // Source Group
105 // ------------------------------------------------------------------------
106
107 @Override
108 protected void createSourceGroup(final Composite parent) {
109 Composite directoryContainerGroup = new Composite(parent, SWT.NONE);
110 GridLayout layout = new GridLayout();
111 layout.numColumns = 3;
112 directoryContainerGroup.setLayout(layout);
113 directoryContainerGroup.setFont(parent.getFont());
114 directoryContainerGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
115
116 Label profileLabel = new Label(directoryContainerGroup, SWT.NONE);
117 profileLabel.setText(RemoteMessages.RemoteProfilesPreferencePage_ProfileNameLabel);
118 profileLabel.setFont(parent.getFont());
119
120 fProfileNameCombo = new Combo(directoryContainerGroup, SWT.BORDER | SWT.READ_ONLY);
121 GridData pdata = new GridData(SWT.FILL, SWT.FILL, true, false);
122 pdata.widthHint = SIZING_TEXT_FIELD_WIDTH;
123 fProfileNameCombo.setLayoutData(pdata);
124 fProfileNameCombo.setFont(parent.getFont());
125
126 Button manageProfilesButton = new Button(directoryContainerGroup, SWT.NONE);
127 manageProfilesButton.addSelectionListener(new SelectionAdapter() {
128 @Override
129 public void widgetSelected(SelectionEvent e) {
130 PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(parent.getShell(),
131 RemoteProfilesPreferencePage.ID,
132 new String[] { RemoteProfilesPreferencePage.ID },
133 null);
134 RemoteProfilesPreferencePage page = (RemoteProfilesPreferencePage) dialog.getSelectedPage();
135 page.setSelectedProfile(fProfileNameCombo.getText());
136 if (dialog.open() == Window.OK) {
137 fProfiles.clear();
138 fProfile = null;
139 updateProfileData();
140 if (page.getSelectedProfile() != null) {
141 int index = fProfileNameCombo.indexOf(page.getSelectedProfile());
142 fProfileNameCombo.select(index);
143 }
144 updateFromSourceField();
145 }
146 }
147 });
148
149 manageProfilesButton.setText(RemoteMessages.RemoteFetchLogWizardPage_ManageProfileLabel);
150
151 Label nodesLabel = new Label(directoryContainerGroup, SWT.NONE);
152 nodesLabel.setText(RemoteMessages.RemoteFetchLogWizardPage_NodesLabel);
153 nodesLabel.setFont(parent.getFont());
154
155 fNodesText = new Text(directoryContainerGroup, SWT.NONE);
156 GridData gd_nodeText = new GridData(SWT.FILL, SWT.FILL, true, false);
157 gd_nodeText.horizontalSpan = 2;
158 gd_nodeText.widthHint = 0;
159 fNodesText.setLayoutData(gd_nodeText);
160 fNodesText.setEditable(false);
161 fNodesText.addControlListener(new ControlAdapter() {
162 @Override
163 public void controlResized(ControlEvent e) {
164 updateNodesText();
165 }
166 });
167
168 updateProfileData();
169 updateFromSourceField();
170
171 fProfileNameCombo.addSelectionListener(new SelectionAdapter() {
172 @Override
173 public void widgetSelected(SelectionEvent e) {
174 updateFromSourceField();
175 }
176 });
177
178 setErrorMessage(null);
179 setPageComplete(true);
180 }
181
182 @Override
183 public boolean validateSourceGroup() {
184 return true;
185 }
186
187 // ------------------------------------------------------------------------
188 // Options
189 // ------------------------------------------------------------------------
190 @Override
191 protected void createOptionsGroupButtons(Group optionsGroup) {
192 // Overwrite checkbox
193 fOverwriteExistingResourcesCheckbox = new Button(optionsGroup, SWT.CHECK);
194 fOverwriteExistingResourcesCheckbox.setFont(optionsGroup.getFont());
195 fOverwriteExistingResourcesCheckbox.setText(Messages.ImportTraceWizard_OverwriteExistingTrace);
196 fOverwriteExistingResourcesCheckbox.setSelection(false);
197 fOverwriteExistingResourcesCheckbox.addSelectionListener(new SelectionAdapter() {
198 @Override
199 public void widgetSelected(SelectionEvent e) {
200 updateNextPage();
201 setPageComplete(fProfile != null);
202 }
203 });
204
205 updateWidgetEnablements();
206 }
207
208 // ------------------------------------------------------------------------
209 // Helper methods
210 // ------------------------------------------------------------------------
211 private void updateProfileData() {
212 fProfileNameCombo.removeAll();
213 fProfiles = RemoteProfilesPreferencePage.getRemoteProfiles(new NullProgressMonitor());
214 int i = 0;
215 for (RemoteImportProfileElement profile : fProfiles) {
216 fProfileNameCombo.add(profile.getProfileName(), i++);
217 }
218 if (i > 0) {
219 fProfileNameCombo.select(0);
220 }
221 }
222
223 private void updateFromSourceField() {
224 int index = fProfileNameCombo.getSelectionIndex();
225 if (index < 0) {
226 updateNodesText();
227 updateNextPage();
228 setPageComplete(false);
229 return;
230 }
231 fProfile = fProfiles.get(index);
232
233 updateNodesText();
234 updateNextPage();
235
236 setPageComplete(true);
237 }
238
239 private void updateNodesText() {
240 if (fProfile == null) {
241 fNodesText.setText(""); //$NON-NLS-1$
242 fNodesText.setToolTipText(null);
243 return;
244 }
245
246 StringBuilder text = new StringBuilder();
247 StringBuilder tooltip = new StringBuilder();
248 for (TracePackageElement element : fProfile.getChildren()) {
249 if (element instanceof RemoteImportConnectionNodeElement) {
250 RemoteImportConnectionNodeElement node = (RemoteImportConnectionNodeElement) element;
251 if (text.length() != 0) {
252 text.append(", "); //$NON-NLS-1$
253 tooltip.append('\n');
254 }
255 String nodeInfo = node.getName() + " (" + //$NON-NLS-1$
256 node.getURI().toString()+ ')';
257 text.append(nodeInfo);
258 tooltip.append(nodeInfo);
259 }
260 }
261 fNodesText.setText(text.toString());
262 fNodesText.setToolTipText(null);
263 while (fNodesText.computeSize(SWT.DEFAULT, SWT.DEFAULT).x > fNodesText.getSize().x && text.length() > 0) {
264 text.deleteCharAt(text.length() - 1);
265 fNodesText.setText(text.toString() + "..."); //$NON-NLS-1$
266 fNodesText.setToolTipText(tooltip.toString());
267 }
268 }
269
270 private void updateNextPage() {
271 IWizardPage nextPage = getNextPage();
272 if (nextPage instanceof RemoteFetchLogWizardRemotePage) {
273 ((RemoteFetchLogWizardRemotePage) nextPage).setPageData(
274 fProfile,
275 fOverwriteExistingResourcesCheckbox != null ?
276 fOverwriteExistingResourcesCheckbox.getSelection() : false);
277 }
278 }
279}
This page took 0.059732 seconds and 5 git commands to generate.