tmf remote: Bug 460847: Add profile preference for remote fetching
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.remote.ui / src / org / eclipse / tracecompass / internal / tmf / remote / ui / wizards / fetch / preferences / RemoteProfilesPreferencePage.java
CommitLineData
9ba2101a
PT
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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.preferences;
14
15import java.io.BufferedWriter;
16import java.io.File;
17import java.io.FileWriter;
18import java.io.IOException;
19import java.net.URI;
20import java.net.URISyntaxException;
21import java.util.ArrayList;
22import java.util.HashSet;
23import java.util.List;
24import java.util.Set;
25import java.util.regex.Pattern;
26import java.util.regex.PatternSyntaxException;
27
28import javax.xml.parsers.ParserConfigurationException;
29import javax.xml.transform.TransformerException;
30
31import org.eclipse.core.resources.IResource;
32import org.eclipse.core.resources.ResourcesPlugin;
33import org.eclipse.core.runtime.IProgressMonitor;
34import org.eclipse.core.runtime.NullProgressMonitor;
35import org.eclipse.core.runtime.URIUtil;
36import org.eclipse.jface.action.Action;
37import org.eclipse.jface.action.IMenuListener;
38import org.eclipse.jface.action.IMenuManager;
39import org.eclipse.jface.action.MenuManager;
40import org.eclipse.jface.action.Separator;
41import org.eclipse.jface.dialogs.Dialog;
42import org.eclipse.jface.dialogs.MessageDialog;
43import org.eclipse.jface.preference.PreferencePage;
44import org.eclipse.jface.util.LocalSelectionTransfer;
45import org.eclipse.jface.viewers.AbstractTreeViewer;
46import org.eclipse.jface.viewers.ColumnLabelProvider;
47import org.eclipse.jface.viewers.ISelectionChangedListener;
48import org.eclipse.jface.viewers.IStructuredSelection;
49import org.eclipse.jface.viewers.SelectionChangedEvent;
50import org.eclipse.jface.viewers.StructuredSelection;
51import org.eclipse.jface.viewers.TreeViewer;
52import org.eclipse.jface.viewers.Viewer;
53import org.eclipse.remote.core.IRemoteServicesManager;
54import org.eclipse.swt.SWT;
55import org.eclipse.swt.dnd.Clipboard;
56import org.eclipse.swt.dnd.Transfer;
57import org.eclipse.swt.events.KeyAdapter;
58import org.eclipse.swt.events.KeyEvent;
59import org.eclipse.swt.events.ModifyEvent;
60import org.eclipse.swt.events.ModifyListener;
61import org.eclipse.swt.events.SelectionAdapter;
62import org.eclipse.swt.events.SelectionEvent;
63import org.eclipse.swt.graphics.Image;
64import org.eclipse.swt.layout.GridData;
65import org.eclipse.swt.layout.GridLayout;
66import org.eclipse.swt.widgets.Button;
67import org.eclipse.swt.widgets.Combo;
68import org.eclipse.swt.widgets.Composite;
69import org.eclipse.swt.widgets.Control;
70import org.eclipse.swt.widgets.Display;
71import org.eclipse.swt.widgets.FileDialog;
72import org.eclipse.swt.widgets.Label;
73import org.eclipse.swt.widgets.Menu;
74import org.eclipse.swt.widgets.Text;
75import org.eclipse.tracecompass.internal.tmf.remote.ui.Activator;
76import org.eclipse.tracecompass.internal.tmf.remote.ui.messages.RemoteMessages;
77import org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.ExtractRemoteProfilesOperation;
78import org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement;
79import org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement;
80import org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfilesWriter;
81import org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement;
82import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.Messages;
83import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageContentProvider;
84import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement;
85import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement;
86import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement;
87import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
88import org.eclipse.tracecompass.tmf.remote.core.proxy.RemoteSystemProxy;
89import org.eclipse.ui.ISharedImages;
90import org.eclipse.ui.IWorkbench;
91import org.eclipse.ui.IWorkbenchCommandConstants;
92import org.eclipse.ui.IWorkbenchPreferencePage;
93import org.eclipse.ui.PlatformUI;
94import org.eclipse.ui.dialogs.FilteredTree;
95import org.eclipse.ui.dialogs.PatternFilter;
96
97/**
98 * Preference page for profiles
99 *
100 * @author Patrick Tasse
101 */
102public class RemoteProfilesPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
103
104 /** The ID of this preference page */
105 public static final String ID = "org.eclipse.linuxtools.tmf.remote.ui.preferences.remoteprofiles"; //$NON-NLS-1$
106
107 private static final String REMOTE_PROFILES_XML_FILE_NAME = "remote_profiles.xml"; //$NON-NLS-1$
108 private static final String REMOTE_PROFILES_XML_FILE_PATH =
109 Activator.getDefault().getStateLocation().addTrailingSeparator().append(REMOTE_PROFILES_XML_FILE_NAME).toOSString();
110
111 private static final String DEFAULT_ROOT_IMPORT_PATH = "/rootpath"; //$NON-NLS-1$
112 private static final String DEFAULT_IMPORT_NAME = ""; //$NON-NLS-1$
113 private static final String DEFAULT_FILE_PATTERN = ".*"; //$NON-NLS-1$
114 private static final String TRACE_TYPE_AUTO_DETECT = Messages.ImportTraceWizard_AutoDetection;
115 private static final String SSH_SCHEME = "ssh"; //$NON-NLS-1$
116
117 private TreeViewer fTreeViewer;
118 private List<RemoteImportProfileElement> fProfiles;
119 private String fSelectedProfileName;
120 private DetailsPanel fDetailsPanel;
121 private Button fAddButton;
122 private Button fRemoveButton;
123 private Button fImportButton;
124 private Button fExportButton;
125 private Button fMoveUpButton;
126 private Button fMoveDownButton;
127 private Action fDeleteAction;
128 private Action fCutAction;
129 private Action fCopyAction;
130 private Action fPasteAction;
131
132 /**
133 * Constructor
134 */
135 public RemoteProfilesPreferencePage() {
136 }
137
138 @Override
139 public void init(IWorkbench workbench) {
140 noDefaultAndApplyButton();
141 }
142
143 @Override
144 protected Control createContents(Composite parent) {
145 Composite composite = new Composite(parent, SWT.NONE);
146 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
147 composite.setLayoutData(gd);
148
149 GridLayout gl = new GridLayout(2, false);
150 composite.setLayout(gl);
151
152 PatternFilter patternFilter = new PatternFilter() {
153 // show all children of matching profiles or profiles with matching connection node
154 @Override
155 protected boolean isLeafMatch(Viewer viewer, Object element) {
156 TreeViewer treeViewer = (TreeViewer) viewer;
157 TracePackageContentProvider contentProvider = (TracePackageContentProvider) treeViewer.getContentProvider();
158 Object parentElement = element;
159 while (!(parentElement instanceof RemoteImportProfileElement)) {
160 parentElement = contentProvider.getParent(parentElement);
161 if (parentElement instanceof TracePackageTraceElement) {
162 // don't show children of trace element
163 return false;
164 }
165 }
166 RemoteImportProfileElement profile = (RemoteImportProfileElement) parentElement;
167 if (super.isLeafMatch(viewer, profile)) {
168 return true;
169 }
170 for (Object child : contentProvider.getChildren(profile)) {
171 if (child instanceof RemoteImportConnectionNodeElement) {
172 if (super.isLeafMatch(viewer, child)) {
173 return true;
174 }
175 }
176 }
177 return false;
178 }
179 };
180
181 final FilteredTree filteredTree = new FilteredTree(composite,
182 SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
183 gd = new GridData(SWT.FILL, SWT.FILL, true, true);
184 gd.heightHint = 0;
185 filteredTree.setLayoutData(gd);
186 final TreeViewer treeViewer = filteredTree.getViewer();
187 fTreeViewer = treeViewer;
188
189 treeViewer.setContentProvider(new TracePackageContentProvider() {
190 @Override
191 public Object[] getElements(Object inputElement) {
192 if (inputElement instanceof ArrayList) {
193 return ((ArrayList<?>) inputElement).toArray();
194 }
195 return super.getElements(inputElement);
196 }
197
198 @Override
199 public boolean hasChildren(Object element) {
200 if (element instanceof TracePackageTraceElement) {
201 return false;
202 }
203 return super.hasChildren(element);
204 }
205 });
206
207 treeViewer.setLabelProvider(new ColumnLabelProvider() {
208 @Override
209 public String getText(Object element) {
210 if (element instanceof TracePackageTraceElement) {
211 for (TracePackageElement files : ((TracePackageTraceElement) element).getChildren()) {
212 if (files instanceof TracePackageFilesElement) {
213 return ((TracePackageFilesElement) files).getFileName();
214 }
215 }
216 } else if (element instanceof TracePackageElement) {
217 return ((TracePackageElement) element).getText();
218 }
219 return super.getText(element);
220 }
221 @Override
222 public Image getImage(Object element) {
223 if (element instanceof TracePackageTraceElement) {
224 for (TracePackageElement files : ((TracePackageTraceElement) element).getChildren()) {
225 return files.getImage();
226 }
227 } else if (element instanceof TracePackageElement) {
228 return ((TracePackageElement) element).getImage();
229 }
230 return super.getImage(element);
231 }
232 });
233
234 treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
235 @Override
236 public void selectionChanged(SelectionChangedEvent event) {
237 IStructuredSelection selection = (IStructuredSelection) event.getSelection();
238 TracePackageElement element = (TracePackageElement) (selection.size() == 1 ? selection.getFirstElement() : null);
239 fDetailsPanel.refreshDetailsPanel(element);
240 enableButtons(selection);
241 fSelectedProfileName = null;
242 while (element != null) {
243 if (element instanceof RemoteImportProfileElement) {
244 fSelectedProfileName = ((RemoteImportProfileElement) element).getProfileName();
245 }
246 element = element.getParent();
247 }
248 }
249 });
250
251 createGlobalActions();
252 createContextMenu();
253
254 fProfiles = readProfiles(REMOTE_PROFILES_XML_FILE_PATH, new NullProgressMonitor());
255
256 treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
257 treeViewer.setInput(fProfiles);
258 treeViewer.expandAll();
259
260 Composite buttonBar = createVerticalButtonBar(composite);
261 gd = new GridData(SWT.CENTER, SWT.BEGINNING, false, false);
262 gd.verticalIndent = filteredTree.getFilterControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y + gl.verticalSpacing;
263 buttonBar.setLayoutData(gd);
264 enableButtons((IStructuredSelection) treeViewer.getSelection());
265
266 Composite details = new Composite(composite, SWT.NONE);
267 gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
268 details.setLayoutData(gd);
269 gl = new GridLayout(2, false);
270 gl.marginWidth = 0;
271 details.setLayout(gl);
272
273 Label label = new Label(details, SWT.NONE);
274 label.setText(RemoteMessages.RemoteProfilesPreferencePage_DetailsPanelLabel);
275 gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1);
276 label.setLayoutData(gd);
277
278 fDetailsPanel = new DetailsPanel(details);
279
280 validate();
281
282 for (RemoteImportProfileElement profile : fProfiles) {
283 if (profile.getProfileName().equals(fSelectedProfileName)) {
284 fTreeViewer.setSelection(new StructuredSelection(profile));
285 }
286 }
287
288 Dialog.applyDialogFont(composite);
289 return composite;
290 }
291
292 /**
293 * Get the remote profiles stored in the preferences
294 *
295 * @param monitor
296 * a progress monitor
297 *
298 * @return the list of remote profiles
299 */
300 public static List<RemoteImportProfileElement> getRemoteProfiles(IProgressMonitor monitor) {
301 return readProfiles(REMOTE_PROFILES_XML_FILE_PATH, monitor);
302 }
303
304 private static List<RemoteImportProfileElement> readProfiles(String path, IProgressMonitor monitor) {
305 final ExtractRemoteProfilesOperation op = new ExtractRemoteProfilesOperation(path);
306 op.run(monitor);
307 List<RemoteImportProfileElement> profiles = new ArrayList<>();
308 if (!op.getStatus().isOK()) {
309 return profiles;
310 }
311 TracePackageElement[] resultElements = op.getResultElements();
312 if (resultElements != null) {
313 for (TracePackageElement element : resultElements) {
314 if (element instanceof RemoteImportProfileElement) {
315 profiles.add((RemoteImportProfileElement) element);
316 }
317 }
318 }
319 return profiles;
320 }
321
322 private boolean writeProfiles(List<RemoteImportProfileElement> profiles, String path) {
323 try {
324 String contents = RemoteImportProfilesWriter.writeProfilesToXML(profiles.toArray(new TracePackageElement[0]));
325 File file = new File(path);
326 try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
327 writer.write(contents);
328 return true;
329 }
330 } catch (IOException | ParserConfigurationException | TransformerException e) {
331 MessageDialog.openError(getShell(), RemoteMessages.RemoteProfilesPreferencePage_ErrorWritingProfile, e.getMessage());
332 }
333 return false;
334 }
335
336 private void createGlobalActions() {
337 fDeleteAction = new Action(RemoteMessages.RemoteProfilesPreferencePage_DeleteAction) {
338 @Override
339 public void run() {
340 final IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
341 if (selection.size() == 0) {
342 return;
343 }
344 for (Object item : selection.toList()) {
345 if (item instanceof RemoteImportProfileElement) {
346 fProfiles.remove(item);
347 fTreeViewer.refresh();
348 validate();
349 } else if (item instanceof TracePackageElement) {
350 TracePackageElement element = (TracePackageElement) item;
351 TracePackageElement parent = element.getParent();
352 parent.removeChild(element);
353 fTreeViewer.refresh(parent);
354 validate();
355 }
356 }
357 }
358 };
359 fDeleteAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
360 fDeleteAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_DELETE);
361 fDeleteAction.setAccelerator(SWT.DEL);
362
363 fCutAction = new Action(RemoteMessages.RemoteProfilesPreferencePage_CutAction) {
364 @Override
365 public void run() {
366 final IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
367 if (selection.size() != 1) {
368 return;
369 }
370 setClipboardContents(selection);
371 Object item = selection.getFirstElement();
372 if (item instanceof RemoteImportProfileElement) {
373 fProfiles.remove(item);
374 fTreeViewer.refresh();
375 validate();
376 } else if (item instanceof TracePackageElement) {
377 TracePackageElement element = (TracePackageElement) item;
378 TracePackageElement parent = element.getParent();
379 parent.removeChild(element);
380 fTreeViewer.refresh(parent);
381 validate();
382 }
383 }
384 };
385 fCutAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
386 fCutAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_CUT);
387 fCutAction.setAccelerator(SWT.CTRL | 'X');
388
389 fCopyAction = new Action(RemoteMessages.RemoteProfilesPreferencePage_CopyAction) {
390 @Override
391 public void run() {
392 final IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
393 if (selection.size() != 1) {
394 return;
395 }
396 setClipboardContents(new StructuredSelection(
397 copyElement(null, (TracePackageElement) selection.getFirstElement())));
398 }
399 };
400 fCopyAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
401 fCopyAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_COPY);
402 fCopyAction.setAccelerator(SWT.CTRL | 'C');
403
404 fPasteAction = new Action(RemoteMessages.RemoteProfilesPreferencePage_PasteAction) {
405 @Override
406 public void run() {
407 final IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
408 if (selection.size() > 1) {
409 return;
410 }
411 if (!validatePaste(selection.getFirstElement())) {
412 return;
413 }
414 IStructuredSelection data = getClipboardContents();
415 data = getClipboardContents();
416 if (data == null) {
417 return;
418 }
419 for (Object object : data.toArray()) {
420 if (object instanceof RemoteImportProfileElement) {
421 TracePackageElement element = copyElement(null, (TracePackageElement) object);
422 TracePackageElement target = (TracePackageElement) selection.getFirstElement();
423 if (target == null) {
424 fProfiles.add((RemoteImportProfileElement) element);
425 } else {
426 int index = fProfiles.indexOf(target);
427 fProfiles.add(index + 1, (RemoteImportProfileElement) element);
428 }
429 Object[] expanded = fTreeViewer.getExpandedElements();
430 fTreeViewer.refresh();
431 fTreeViewer.setExpandedElements(expanded);
432 fTreeViewer.expandToLevel(element, AbstractTreeViewer.ALL_LEVELS);
433 fTreeViewer.setSelection(new StructuredSelection(element));
434 validate();
435 } else if (object instanceof TracePackageElement && selection.getFirstElement() instanceof TracePackageElement) {
436 TracePackageElement element = copyElement(null, (TracePackageElement) object);
437 TracePackageElement target = (TracePackageElement) selection.getFirstElement();
438 if (target.getClass().equals(element.getClass())) {
439 int index = target.getParent().indexOf(target);
440 target.getParent().addChild(index + 1, element);
441 fTreeViewer.refresh(target.getParent());
442 } else {
443 target.addChild(0, element);
444 fTreeViewer.refresh(target);
445 }
446 fTreeViewer.expandToLevel(element, AbstractTreeViewer.ALL_LEVELS);
447 fTreeViewer.setSelection(new StructuredSelection(element));
448 validate();
449 }
450 }
451 }
452 };
453 fPasteAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
454 fPasteAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_PASTE);
455 fPasteAction.setAccelerator(SWT.CTRL | 'V');
456
457 fTreeViewer.getTree().addKeyListener(new KeyAdapter() {
458 @Override
459 public void keyPressed(KeyEvent e) {
460 if (e.stateMask == 0 && e.keyCode == SWT.DEL) {
461 fDeleteAction.run();
462 }
463 if ((e.stateMask & SWT.CTRL) == SWT.CTRL) {
464 if (e.keyCode == 'x') {
465 fCutAction.run();
466 } else if (e.keyCode == 'c') {
467 fCopyAction.run();
468 } else if (e.keyCode == 'v') {
469 fPasteAction.run();
470 }
471 }
472 }
473 });
474 }
475
476 private void createContextMenu() {
477 MenuManager menuManager = new MenuManager();
478 menuManager.setRemoveAllWhenShown(true);
479 menuManager.addMenuListener(new IMenuListener() {
480 @Override
481 public void menuAboutToShow(IMenuManager manager) {
482 fillContextMenu(manager);
483 }
484 });
485
486 Menu contextMenu = menuManager.createContextMenu(fTreeViewer.getTree());
487 fTreeViewer.getTree().setMenu(contextMenu);
488 }
489
490 private void fillContextMenu(IMenuManager manager) {
491 final IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
492 final List<Object> items = selection.toList();
493 if (items.size() == 1) {
494 Object item = items.get(0);
495 if (item instanceof RemoteImportProfileElement) {
496 final RemoteImportProfileElement profile = (RemoteImportProfileElement) item;
497 manager.add(new Action(RemoteMessages.RemoteProfilesPreferencePage_NewConnectionNode) {
498 @Override
499 public void run() {
500 newConnectionNode(profile, null);
501 }
502 });
503 } else if (item instanceof RemoteImportConnectionNodeElement) {
504 final RemoteImportConnectionNodeElement node = (RemoteImportConnectionNodeElement) item;
505 manager.add(new Action(RemoteMessages.RemoteProfilesPreferencePage_NewTraceGroupAction) {
506 @Override
507 public void run() {
508 newTraceGroup(node, null);
509 }
510 });
511 } else if (item instanceof RemoteImportTraceGroupElement) {
512 final RemoteImportTraceGroupElement traceGroup = (RemoteImportTraceGroupElement) item;
513 manager.add(new Action(RemoteMessages.RemoteProfilesPreferencePage_NewTraceAction) {
514 @Override
515 public void run() {
516 newTrace(traceGroup, null);
517 }
518 });
519 }
520 }
521 manager.add(new Separator());
522 manager.add(fDeleteAction);
523 fDeleteAction.setEnabled(items.size() > 0);
524 manager.add(new Separator());
525 manager.add(fCutAction);
526 fCutAction.setEnabled(items.size() == 1);
527 manager.add(fCopyAction);
528 fCopyAction.setEnabled(items.size() == 1);
529 manager.add(fPasteAction);
530 fPasteAction.setEnabled(items.size() <= 1 && validatePaste(selection.getFirstElement()));
531 }
532
533 private Composite createVerticalButtonBar(Composite parent) {
534 Composite composite = new Composite(parent, SWT.NONE);
535 composite.setLayout(new GridLayout());
536
537 fAddButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_AddButton);
538 fAddButton.addSelectionListener(new SelectionAdapter() {
539 @Override
540 public void widgetSelected(SelectionEvent e) {
541 IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
542 if (selection.isEmpty()) {
543 newProfile(null);
544 } else if (selection.getFirstElement() instanceof TracePackageElement) {
545 TracePackageElement previous = (TracePackageElement) selection.getFirstElement();
546 if (previous instanceof RemoteImportProfileElement) {
547 newProfile(previous);
548 } else if (previous instanceof RemoteImportConnectionNodeElement) {
549 newConnectionNode(previous.getParent(), previous);
550 } else if (previous instanceof RemoteImportTraceGroupElement) {
551 newTraceGroup(previous.getParent(), previous);
552 } else if (previous instanceof TracePackageTraceElement) {
553 newTrace(previous.getParent(), previous);
554 }
555 }
556 }
557 });
558
559 fRemoveButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_RemoveButton);
560 fRemoveButton.addSelectionListener(new SelectionAdapter() {
561 @Override
562 public void widgetSelected(SelectionEvent e) {
563 IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
564 for (Object item : selection.toList()) {
565 if (item instanceof RemoteImportProfileElement) {
566 fProfiles.remove(item);
567 } else if (item instanceof TracePackageElement) {
568 TracePackageElement element = (TracePackageElement) item;
569 element.getParent().removeChild(element);
570 }
571 }
572 fTreeViewer.refresh();
573 validate();
574 }
575 });
576
577 new Label(composite, SWT.NONE);
578
579 fImportButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_ImportButton);
580 fImportButton.addSelectionListener(new SelectionAdapter() {
581 @Override
582 public void widgetSelected(SelectionEvent e) {
583 FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN);
584 dialog.setText(RemoteMessages.RemoteProfilesPreferencePage_ImportFileDialogTitle);
585 dialog.setFilterExtensions(new String[] { "*.xml", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
586 String path = dialog.open();
587 if (path != null) {
588 List<RemoteImportProfileElement> profiles = readProfiles(path, new NullProgressMonitor());
589 fProfiles.addAll(profiles);
590 fTreeViewer.refresh();
591 for (RemoteImportProfileElement profile : profiles) {
592 fTreeViewer.expandToLevel(profile, AbstractTreeViewer.ALL_LEVELS);
593 }
594 fTreeViewer.setSelection(new StructuredSelection(profiles));
595 validate();
596 }
597 }
598 });
599
600 fExportButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_ExportButton);
601 fExportButton.addSelectionListener(new SelectionAdapter() {
602 @Override
603 public void widgetSelected(SelectionEvent e) {
604 FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
605 dialog.setText(RemoteMessages.RemoteProfilesPreferencePage_ExportFileDialogTitle);
606 dialog.setFilterExtensions(new String[] { "*.xml", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
607 String path = dialog.open();
608 if (path != null) {
609 IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
610 List<RemoteImportProfileElement> profiles = new ArrayList<>();
611 for (Object element : selection.toList()) {
612 if (element instanceof RemoteImportProfileElement) {
613 profiles.add((RemoteImportProfileElement) element);
614 }
615 }
616 writeProfiles(profiles, path);
617 }
618 }
619 });
620
621 new Label(composite, SWT.NONE);
622
623 fMoveUpButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_MoveUpButton);
624 fMoveUpButton.addSelectionListener(new SelectionAdapter() {
625 @Override
626 public void widgetSelected(SelectionEvent e) {
627 IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
628 Object element = selection.getFirstElement();
629 if (element instanceof RemoteImportProfileElement) {
630 int index = fProfiles.indexOf(element);
631 if (index > 0) {
632 RemoteImportProfileElement profile = fProfiles.remove(index);
633 fProfiles.add(index - 1, profile);
634 Object[] expanded = fTreeViewer.getExpandedElements();
635 fTreeViewer.refresh();
636 fTreeViewer.setExpandedElements(expanded);
637 enableButtons(selection);
638 }
639 } else if (element instanceof TracePackageElement) {
640 TracePackageElement child = (TracePackageElement) element;
641 TracePackageElement parentElement = child.getParent();
642 int index = parentElement.indexOf(child);
643 if (index > 0) {
644 parentElement.removeChild(child);
645 parentElement.addChild(index - 1, child);
646 Object[] expanded = fTreeViewer.getExpandedElements();
647 fTreeViewer.refresh(parentElement);
648 fTreeViewer.setExpandedElements(expanded);
649 enableButtons(selection);
650 }
651 }
652 }
653 });
654
655 fMoveDownButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_MoveDownButton);
656 fMoveDownButton.addSelectionListener(new SelectionAdapter() {
657 @Override
658 public void widgetSelected(SelectionEvent e) {
659 IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
660 Object element = selection.getFirstElement();
661 if (element instanceof RemoteImportProfileElement) {
662 int index = fProfiles.indexOf(selection.getFirstElement());
663 if (index >= 0 && index < fProfiles.size() - 1) {
664 RemoteImportProfileElement profile = fProfiles.remove(index);
665 fProfiles.add(index + 1, profile);
666 Object[] expanded = fTreeViewer.getExpandedElements();
667 fTreeViewer.refresh();
668 fTreeViewer.setExpandedElements(expanded);
669 enableButtons(selection);
670 }
671 } else if (element instanceof TracePackageElement) {
672 TracePackageElement child = (TracePackageElement) element;
673 TracePackageElement parentElement = child.getParent();
674 int index = parentElement.indexOf(child);
675 if (index >= 0 && index < parentElement.getChildren().length - 1) {
676 parentElement.removeChild(child);
677 parentElement.addChild(index + 1, child);
678 Object[] expanded = fTreeViewer.getExpandedElements();
679 fTreeViewer.refresh(parentElement);
680 fTreeViewer.setExpandedElements(expanded);
681 enableButtons(selection);
682 }
683 }
684 }
685 });
686
687 return composite;
688 }
689
690 private static Button createVerticalButton(Composite parent, String text) {
691 Button button = new Button(parent, SWT.PUSH);
692 button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
693 button.setText(text);
694 return button;
695 }
696
697 private void enableButtons(IStructuredSelection selection) {
698 boolean allProfiles = false;
699 for (Object element : selection.toList()) {
700 if (element instanceof RemoteImportProfileElement) {
701 allProfiles = true;
702 } else {
703 allProfiles = false;
704 break;
705 }
706 }
707 fAddButton.setEnabled(selection.size() <= 1);
708 fRemoveButton.setEnabled(!selection.isEmpty());
709 fExportButton.setEnabled(allProfiles);
710 int index = 0;
711 int length = 0;
712 if (selection.size() == 1) {
713 Object item = selection.getFirstElement();
714 if (item instanceof RemoteImportProfileElement) {
715 index = fProfiles.indexOf(item);
716 length = fProfiles.size();
717 } else if (item instanceof TracePackageElement) {
718 TracePackageElement element = (TracePackageElement) item;
719 TracePackageElement parent = element.getParent();
720 index = parent.indexOf(element);
721 length = parent.getChildren().length;
722 }
723 }
724 fMoveUpButton.setEnabled(index > 0);
725 fMoveDownButton.setEnabled(index < length - 1);
726 }
727
728 private class DetailsPanel {
729
730 private Composite fComposite;
731
732 public DetailsPanel(Composite parent) {
733 fComposite = new Composite(parent, SWT.BORDER);
734 GridLayout gl = new GridLayout(2, false);
735 fComposite.setLayout(gl);
736 GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
737 Combo combo = new Combo(fComposite, SWT.BORDER);
738 combo.setText("*"); //$NON-NLS-1$
739 gd.heightHint = 2 * gl.marginHeight + gl.verticalSpacing + 2 * (combo.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
740 fComposite.setLayoutData(gd);
741 combo.dispose();
742 }
743
744 public void refreshDetailsPanel(final TracePackageElement selection) {
745 for (Control control : fComposite.getChildren()) {
746 control.dispose();
747 }
748
749 if (selection instanceof RemoteImportProfileElement) {
750 final RemoteImportProfileElement element = (RemoteImportProfileElement) selection;
751
752 Label label = new Label(fComposite, SWT.NONE);
753 label.setText(RemoteMessages.RemoteProfilesPreferencePage_ProfileNameLabel);
754 final Text profileNameText = new Text(fComposite, SWT.BORDER);
755 GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
756 profileNameText.setLayoutData(gd);
757 profileNameText.setText(element.getProfileName());
758 profileNameText.addModifyListener(new ModifyListener() {
759 @Override
760 public void modifyText(ModifyEvent e) {
761 element.setProfileName(profileNameText.getText().trim());
762 fTreeViewer.refresh(element, true);
763 validate();
764 fSelectedProfileName = element.getProfileName();
765 }
766 });
767
768 } else if (selection instanceof RemoteImportConnectionNodeElement) {
769 final RemoteImportConnectionNodeElement element = (RemoteImportConnectionNodeElement) selection;
770
771 Label label = new Label(fComposite, SWT.NONE);
772 label.setText(RemoteMessages.RemoteProfilesPreferencePage_ConnectionNodeNameLabel);
773 final Text nameText = new Text(fComposite, SWT.BORDER);
774 nameText.setText(element.getName());
775 GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
776 nameText.setLayoutData(gd);
777 nameText.addModifyListener(new ModifyListener() {
778 @Override
779 public void modifyText(ModifyEvent e) {
780 element.setName(nameText.getText().trim());
781 fTreeViewer.refresh(element, true);
782 validate();
783 }
784 });
785
786 label = new Label(fComposite, SWT.NONE);
787 label.setText(RemoteMessages.RemoteProfilesPreferencePage_ConnectionNodeURILabel);
788 final Text uriText = new Text(fComposite, SWT.BORDER);
789 uriText.setText(element.getURI());
790 gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
791 uriText.setLayoutData(gd);
792 uriText.addModifyListener(new ModifyListener() {
793 @Override
794 public void modifyText(ModifyEvent e) {
795 element.setURI(uriText.getText().trim());
796 fTreeViewer.refresh(element, true);
797 validate();
798 }
799 });
800
801 } else if (selection instanceof RemoteImportTraceGroupElement) {
802 final RemoteImportTraceGroupElement element = (RemoteImportTraceGroupElement) selection;
803
804 Label label = new Label(fComposite, SWT.NONE);
805 label.setText(RemoteMessages.RemoteProfilesPreferencePage_RootPathLabel);
806 final Text rootText = new Text(fComposite, SWT.BORDER);
807 GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
808 rootText.setLayoutData(gd);
809 rootText.setText(element.getRootImportPath());
810 rootText.addModifyListener(new ModifyListener() {
811 @Override
812 public void modifyText(ModifyEvent e) {
813 element.setRootImportPath(rootText.getText().trim());
814 fTreeViewer.refresh(element, true);
815 validate();
816 }
817 });
818
819 label = new Label(fComposite, SWT.NONE);
820 final Button recursiveButton = new Button(fComposite, SWT.CHECK);
821 gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
822 recursiveButton.setLayoutData(gd);
823 recursiveButton.setText(RemoteMessages.RemoteProfilesPreferencePage_RecursiveButton);
824 recursiveButton.setSelection(element.isRecursive());
825 recursiveButton.addSelectionListener(new SelectionAdapter() {
826 @Override
827 public void widgetSelected(SelectionEvent e) {
828 element.setRecursive(recursiveButton.getSelection());
829 fTreeViewer.refresh(element, true);
830 }
831 });
832
833 } else if (selection instanceof TracePackageTraceElement) {
834 final TracePackageTraceElement element = (TracePackageTraceElement) selection;
835
836 Label label = new Label(fComposite, SWT.NONE);
837 label.setText(RemoteMessages.RemoteProfilesPreferencePage_FilePatternLabel);
838 final Text fileNameText = new Text(fComposite, SWT.BORDER);
839 for (TracePackageElement child : element.getChildren()) {
840 if (child instanceof TracePackageFilesElement) {
841 TracePackageFilesElement files = (TracePackageFilesElement) child;
842 fileNameText.setText(files.getFileName());
843 }
844 }
845 GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
846 fileNameText.setLayoutData(gd);
847 fileNameText.addModifyListener(new ModifyListener() {
848 @Override
849 public void modifyText(ModifyEvent e) {
850 for (TracePackageElement child : element.getChildren()) {
851 if (child instanceof TracePackageFilesElement) {
852 TracePackageFilesElement files = (TracePackageFilesElement) child;
853 files.setFileName(fileNameText.getText().trim());
854 }
855 }
856 fTreeViewer.refresh(element, true);
857 validate();
858 }
859 });
860
861 label = new Label(fComposite, SWT.NONE);
862 label.setText(RemoteMessages.RemoteProfilesPreferencePage_TraceTypeLabel);
863 final Combo combo = new Combo(fComposite, SWT.BORDER | SWT.READ_ONLY);
864 String[] availableTraceTypes = TmfTraceType.getAvailableTraceTypes();
865 String[] traceTypeList = new String[availableTraceTypes.length + 1];
866 traceTypeList[0] = TRACE_TYPE_AUTO_DETECT;
867 for (int i = 0; i < availableTraceTypes.length; i++) {
868 traceTypeList[i + 1] = availableTraceTypes[i];
869 }
870 combo.setItems(traceTypeList);
871 combo.select(0);
872 for (int i = 1; i < traceTypeList.length; i++) {
873 String traceType = traceTypeList[i];
874 String traceTypeId = TmfTraceType.getTraceTypeId(traceType);
875 if (traceTypeId.equals(element.getTraceType())) {
876 combo.select(i);
877 break;
878 }
879 }
880 gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
881 combo.setLayoutData(gd);
882 combo.addSelectionListener(new SelectionAdapter() {
883 @Override
884 public void widgetSelected(SelectionEvent e) {
885 if (combo.getSelectionIndex() == 0) {
886 element.setTraceType(null);
887 } else {
888 String traceType = combo.getText();
889 String traceTypeId = TmfTraceType.getTraceTypeId(traceType);
890 element.setTraceType(traceTypeId);
891 }
892 }
893 });
894
895 }
896
897 fComposite.layout();
898 }
899 }
900
901 private RemoteImportProfileElement newProfile(TracePackageElement previous) {
902 RemoteImportProfileElement profile = new RemoteImportProfileElement(null, RemoteMessages.RemoteProfilesPreferencePage_DefaultProfileName);
903 RemoteImportConnectionNodeElement node = new RemoteImportConnectionNodeElement(profile, RemoteMessages.RemoteProfilesPreferencePage_DefaultConnectionNodeName, RemoteMessages.RemoteProfilesPreferencePage_DefaultConnectionNodeURI);
904 RemoteImportTraceGroupElement traceGroup = new RemoteImportTraceGroupElement(node, DEFAULT_ROOT_IMPORT_PATH);
905 TracePackageTraceElement trace = new TracePackageTraceElement(traceGroup, DEFAULT_IMPORT_NAME, null);
906 new TracePackageFilesElement(trace, DEFAULT_FILE_PATTERN);
907 int index = previous == null ? fProfiles.size() : fProfiles.indexOf(previous) + 1;
908 fProfiles.add(index, profile);
909 newElementAdded(profile);
910 return profile;
911 }
912
913 private RemoteImportConnectionNodeElement newConnectionNode(TracePackageElement parent, TracePackageElement previous) {
914 RemoteImportConnectionNodeElement node = new RemoteImportConnectionNodeElement(null, RemoteMessages.RemoteProfilesPreferencePage_DefaultConnectionNodeName, RemoteMessages.RemoteProfilesPreferencePage_DefaultConnectionNodeURI);
915 RemoteImportTraceGroupElement traceGroup = new RemoteImportTraceGroupElement(node, DEFAULT_ROOT_IMPORT_PATH);
916 TracePackageTraceElement trace = new TracePackageTraceElement(traceGroup, DEFAULT_IMPORT_NAME, null);
917 new TracePackageFilesElement(trace, DEFAULT_FILE_PATTERN);
918 int index = previous == null ? parent.getChildren().length : parent.indexOf(previous) + 1;
919 parent.addChild(index, node);
920 newElementAdded(node);
921 return node;
922 }
923
924 private RemoteImportTraceGroupElement newTraceGroup(TracePackageElement parent, TracePackageElement previous) {
925 RemoteImportTraceGroupElement traceGroup = new RemoteImportTraceGroupElement(null, DEFAULT_ROOT_IMPORT_PATH);
926 TracePackageTraceElement trace = new TracePackageTraceElement(traceGroup, DEFAULT_IMPORT_NAME, null);
927 new TracePackageFilesElement(trace, DEFAULT_FILE_PATTERN);
928 int index = previous == null ? parent.getChildren().length : parent.indexOf(previous) + 1;
929 parent.addChild(index, traceGroup);
930 newElementAdded(traceGroup);
931 return traceGroup;
932 }
933
934 private TracePackageTraceElement newTrace(TracePackageElement parent, TracePackageElement previous) {
935 TracePackageTraceElement trace = new TracePackageTraceElement(null, DEFAULT_IMPORT_NAME, null);
936 new TracePackageFilesElement(trace, DEFAULT_FILE_PATTERN);
937 int index = previous == null ? parent.getChildren().length : parent.indexOf(previous) + 1;
938 parent.addChild(index, trace);
939 newElementAdded(trace);
940 return trace;
941 }
942
943 private void newElementAdded(TracePackageElement element) {
944 if (element.getParent() != null) {
945 fTreeViewer.refresh(element.getParent());
946 } else {
947 fTreeViewer.refresh();
948 }
949 fTreeViewer.expandToLevel(element, AbstractTreeViewer.ALL_LEVELS);
950 fTreeViewer.setSelection(new StructuredSelection(element));
951 validate();
952 }
953
954 private TracePackageElement copyElement(TracePackageElement parent, TracePackageElement element) {
955 TracePackageElement copy = null;
956 if (element instanceof RemoteImportProfileElement) {
957 RemoteImportProfileElement source = (RemoteImportProfileElement) element;
958 copy = new RemoteImportProfileElement(parent, source.getProfileName());
959 } else if (element instanceof RemoteImportConnectionNodeElement) {
960 RemoteImportConnectionNodeElement source = (RemoteImportConnectionNodeElement) element;
961 copy = new RemoteImportConnectionNodeElement(parent, source.getName(), source.getURI());
962 } else if (element instanceof RemoteImportTraceGroupElement) {
963 RemoteImportTraceGroupElement source = (RemoteImportTraceGroupElement) element;
964 copy = new RemoteImportTraceGroupElement(parent, source.getRootImportPath());
965 ((RemoteImportTraceGroupElement) copy).setRecursive(source.isRecursive());
966 } else if (element instanceof TracePackageTraceElement) {
967 TracePackageTraceElement source = (TracePackageTraceElement) element;
968 copy = new TracePackageTraceElement(parent, source.getImportName(), source.getTraceType());
969 } else if (element instanceof TracePackageFilesElement) {
970 TracePackageFilesElement source = (TracePackageFilesElement) element;
971 copy = new TracePackageFilesElement(parent, source.getFileName());
972 }
973 for (TracePackageElement child : element.getChildren()) {
974 copyElement(copy, child);
975 }
976 return copy;
977 }
978
979 private static boolean validatePaste(Object target) {
980 IStructuredSelection data = getClipboardContents();
981 if (data == null || data.isEmpty()) {
982 return false;
983 }
984 for (Object item : data.toArray()) {
985 if (item instanceof RemoteImportConnectionNodeElement) {
986 if (!(target instanceof RemoteImportConnectionNodeElement ||
987 target instanceof RemoteImportProfileElement)) {
988 return false;
989 }
990 } else if (item instanceof RemoteImportTraceGroupElement) {
991 if (!(target instanceof RemoteImportTraceGroupElement ||
992 target instanceof RemoteImportConnectionNodeElement)) {
993 return false;
994 }
995 } else if (item instanceof TracePackageTraceElement) {
996 if (!(target instanceof TracePackageTraceElement ||
997 target instanceof RemoteImportTraceGroupElement)) {
998 return false;
999 }
1000 } else if (item instanceof RemoteImportProfileElement) {
1001 if (!(target instanceof RemoteImportProfileElement ||
1002 target == null)) {
1003 return false;
1004 }
1005 } else {
1006 return false;
1007 }
1008 }
1009 return true;
1010 }
1011
1012 private static void setClipboardContents(IStructuredSelection data) {
1013 LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
1014 transfer.setSelection(data);
1015 Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
1016 clipboard.setContents(new Object[] { new Object() }, new Transfer[] { transfer });
1017 clipboard.dispose();
1018 }
1019
1020 private static IStructuredSelection getClipboardContents() {
1021 Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
1022 IStructuredSelection data = (IStructuredSelection) clipboard.getContents(LocalSelectionTransfer.getTransfer());
1023 clipboard.dispose();
1024 return data;
1025 }
1026
1027 private void validate() {
1028 setValid(false);
1029 Set<String> profileNames = new HashSet<>();
1030 for (RemoteImportProfileElement profile : fProfiles) {
1031 if (profile.getProfileName().length() == 0) {
1032 setErrorMessage(RemoteMessages.RemoteProfilesPreferencePage_EmptyProfileNameError);
1033 return;
1034 }
1035 String prefix = profile.getProfileName() + ": "; //$NON-NLS-1$
1036 if (!profileNames.add(profile.getProfileName())) {
1037 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_DuplicateProfileNameError);
1038 return;
1039 }
1040 Set<String> nodeNames = new HashSet<>();
1041 int nodeCount = 0;
1042 for (TracePackageElement profileChild : profile.getChildren()) {
1043 if (profileChild instanceof RemoteImportConnectionNodeElement) {
1044 nodeCount++;
1045 RemoteImportConnectionNodeElement node = (RemoteImportConnectionNodeElement) profileChild;
1046 if (node.getName().length() == 0) {
1047 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_EmptyNodeNameError);
1048 return;
1049 }
1050 // validate node name against the OS since the name will be used as folder name at the destination
1051 if (!ResourcesPlugin.getWorkspace().validateName(node.getName(), IResource.FOLDER).isOK()) {
1052 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_InvalidNodeName);
1053 return;
1054 }
1055 if (!nodeNames.add(node.getName())) {
1056 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_DuplicateConnectionNodeNameError);
1057 return;
1058 }
1059
1060 if (node.getURI().length() == 0) {
1061 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_EmptyNodeURIError);
1062 return;
1063 }
1064 try {
1065 URI uri = URIUtil.fromString(node.getURI());
1066 IRemoteServicesManager manager = RemoteSystemProxy.getService(IRemoteServicesManager.class);
1067 if (manager == null || manager.getConnectionType(uri) == null) {
1068 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_UnsupportedURISchemeError);
1069 return;
1070 }
1071 if (uri.getScheme().equals(SSH_SCHEME)) {
1072 if (uri.getHost() == null) {
1073 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_InvalidHostOrPortError);
1074 return;
1075 }
1076 if (uri.getUserInfo() == null) {
1077 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_MissingUserInfoError);
1078 return;
1079 }
1080 }
1081 } catch (URISyntaxException e) {
1082 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_InvalidNodeURIError);
1083 return;
1084 }
1085 int traceGroupCount = 0;
1086 for (TracePackageElement nodeChild : node.getChildren()) {
1087 if (nodeChild instanceof RemoteImportTraceGroupElement) {
1088 traceGroupCount++;
1089 RemoteImportTraceGroupElement traceGroup = (RemoteImportTraceGroupElement) nodeChild;
1090 if (traceGroup.getRootImportPath().length() == 0) {
1091 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_EmptyRootPathError);
1092 return;
1093 }
1094 int traceCount = 0;
1095 for (TracePackageElement traceGroupChild : traceGroup.getChildren()) {
1096 if (traceGroupChild instanceof TracePackageTraceElement) {
1097 traceCount++;
1098 TracePackageTraceElement trace = (TracePackageTraceElement) traceGroupChild;
1099
1100 for (TracePackageElement traceChild : trace.getChildren()) {
1101 if (traceChild instanceof TracePackageFilesElement) {
1102 TracePackageFilesElement files = (TracePackageFilesElement) traceChild;
1103 if (files.getFileName().length() == 0) {
1104 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_EmptyFilePatternError);
1105 return;
1106 }
1107 try {
1108 Pattern.compile(files.getFileName());
1109 } catch (PatternSyntaxException e) {
1110 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_InvalidFilePatternError);
1111 return;
1112 }
1113 }
1114 }
1115 }
1116 }
1117 if (traceCount == 0) {
1118 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_MissingTraceError);
1119 return;
1120 }
1121 }
1122 }
1123 if (traceGroupCount == 0) {
1124 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_MissingTraceGroupError);
1125 return;
1126 }
1127 }
1128 }
1129 if (nodeCount == 0) {
1130 setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_MissingConnectionNodeError);
1131 return;
1132 }
1133 }
1134 setValid(true);
1135 setErrorMessage(null);
1136 }
1137
1138 @Override
1139 public boolean performOk() {
1140 return writeProfiles(fProfiles, REMOTE_PROFILES_XML_FILE_PATH);
1141 }
1142
1143 /**
1144 * Set the selected profile name
1145 *
1146 * @param profileName the selected profile name
1147 */
1148 public void setSelectedProfile(String profileName) {
1149 fSelectedProfileName = profileName;
1150 if (fTreeViewer != null && !fTreeViewer.getTree().isDisposed()) {
1151 for (RemoteImportProfileElement profile : fProfiles) {
1152 if (profile.getProfileName().equals(profileName)) {
1153 fTreeViewer.setSelection(new StructuredSelection(profile));
1154 }
1155 }
1156 }
1157 }
1158
1159 /**
1160 * Return the selected profile name
1161 *
1162 * @return the selected profile name or null
1163 */
1164 public String getSelectedProfile() {
1165 return fSelectedProfileName;
1166 }
1167}
This page took 0.070917 seconds and 5 git commands to generate.