1 /*******************************************************************************
2 * Copyright (c) 2015 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
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.wizards
.fetch
.preferences
;
15 import java
.io
.BufferedWriter
;
17 import java
.io
.FileWriter
;
18 import java
.io
.IOException
;
20 import java
.net
.URISyntaxException
;
21 import java
.util
.ArrayList
;
22 import java
.util
.HashSet
;
23 import java
.util
.List
;
25 import java
.util
.regex
.Pattern
;
26 import java
.util
.regex
.PatternSyntaxException
;
28 import javax
.xml
.parsers
.ParserConfigurationException
;
29 import javax
.xml
.transform
.TransformerException
;
31 import org
.eclipse
.core
.resources
.IResource
;
32 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
33 import org
.eclipse
.core
.runtime
.IPath
;
34 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
35 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
36 import org
.eclipse
.core
.runtime
.URIUtil
;
37 import org
.eclipse
.core
.runtime
.preferences
.DefaultScope
;
38 import org
.eclipse
.core
.runtime
.preferences
.IEclipsePreferences
;
39 import org
.eclipse
.jface
.action
.Action
;
40 import org
.eclipse
.jface
.action
.IMenuListener
;
41 import org
.eclipse
.jface
.action
.IMenuManager
;
42 import org
.eclipse
.jface
.action
.MenuManager
;
43 import org
.eclipse
.jface
.action
.Separator
;
44 import org
.eclipse
.jface
.dialogs
.Dialog
;
45 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
46 import org
.eclipse
.jface
.preference
.PreferencePage
;
47 import org
.eclipse
.jface
.util
.LocalSelectionTransfer
;
48 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
49 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
50 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
51 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
52 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
53 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
54 import org
.eclipse
.jface
.viewers
.TreeViewer
;
55 import org
.eclipse
.jface
.viewers
.Viewer
;
56 import org
.eclipse
.remote
.core
.IRemoteServicesManager
;
57 import org
.eclipse
.swt
.SWT
;
58 import org
.eclipse
.swt
.dnd
.Clipboard
;
59 import org
.eclipse
.swt
.dnd
.Transfer
;
60 import org
.eclipse
.swt
.events
.KeyAdapter
;
61 import org
.eclipse
.swt
.events
.KeyEvent
;
62 import org
.eclipse
.swt
.events
.ModifyEvent
;
63 import org
.eclipse
.swt
.events
.ModifyListener
;
64 import org
.eclipse
.swt
.events
.SelectionAdapter
;
65 import org
.eclipse
.swt
.events
.SelectionEvent
;
66 import org
.eclipse
.swt
.graphics
.Image
;
67 import org
.eclipse
.swt
.layout
.GridData
;
68 import org
.eclipse
.swt
.layout
.GridLayout
;
69 import org
.eclipse
.swt
.widgets
.Button
;
70 import org
.eclipse
.swt
.widgets
.Combo
;
71 import org
.eclipse
.swt
.widgets
.Composite
;
72 import org
.eclipse
.swt
.widgets
.Control
;
73 import org
.eclipse
.swt
.widgets
.Display
;
74 import org
.eclipse
.swt
.widgets
.FileDialog
;
75 import org
.eclipse
.swt
.widgets
.Label
;
76 import org
.eclipse
.swt
.widgets
.Menu
;
77 import org
.eclipse
.swt
.widgets
.Text
;
78 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.Activator
;
79 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.messages
.RemoteMessages
;
80 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.wizards
.fetch
.model
.ExtractRemoteProfilesOperation
;
81 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.wizards
.fetch
.model
.RemoteImportConnectionNodeElement
;
82 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.wizards
.fetch
.model
.RemoteImportProfileElement
;
83 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.wizards
.fetch
.model
.RemoteImportProfilesWriter
;
84 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.wizards
.fetch
.model
.RemoteImportTraceGroupElement
;
85 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.Messages
;
86 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.tracepkg
.TracePackageContentProvider
;
87 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.tracepkg
.TracePackageElement
;
88 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.tracepkg
.TracePackageFilesElement
;
89 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.tracepkg
.TracePackageTraceElement
;
90 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TmfTraceType
;
91 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.TmfRemoteConnectionFactory
;
92 import org
.eclipse
.tracecompass
.tmf
.ui
.dialog
.TmfFileDialogFactory
;
93 import org
.eclipse
.ui
.ISharedImages
;
94 import org
.eclipse
.ui
.IWorkbench
;
95 import org
.eclipse
.ui
.IWorkbenchCommandConstants
;
96 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
97 import org
.eclipse
.ui
.PlatformUI
;
98 import org
.eclipse
.ui
.dialogs
.FilteredTree
;
99 import org
.eclipse
.ui
.dialogs
.PatternFilter
;
102 * Preference page for profiles
104 * @author Patrick Tasse
106 public class RemoteProfilesPreferencePage
extends PreferencePage
implements IWorkbenchPreferencePage
{
108 /** The ID of this preference page */
109 public static final String ID
= "org.eclipse.linuxtools.tmf.remote.ui.preferences.remoteprofiles"; //$NON-NLS-1$
111 private static final String REMOTE_PROFILES_XML_FILE_NAME
= "remote_profiles.xml"; //$NON-NLS-1$
112 private static final String REMOTE_PROFILES_XML_FILE_PATH
=
113 Activator
.getDefault().getStateLocation().addTrailingSeparator().append(REMOTE_PROFILES_XML_FILE_NAME
).toOSString();
115 private static final String REMOTE_PROFILES_LOCATION_PREF
= "REMOTE_PROFILES_LOCATION"; //$NON-NLS-1$
116 private static final String REMOTE_PROFILES_LOCATION_DIR_DEF
= ""; //$NON-NLS-1$
118 private static final String DEFAULT_ROOT_IMPORT_PATH
= "/rootpath"; //$NON-NLS-1$
119 private static final String DEFAULT_IMPORT_NAME
= ""; //$NON-NLS-1$
120 private static final String DEFAULT_FILE_PATTERN
= ".*"; //$NON-NLS-1$
121 private static final String TRACE_TYPE_AUTO_DETECT
= Messages
.ImportTraceWizard_AutoDetection
;
122 private static final String SSH_SCHEME
= "ssh"; //$NON-NLS-1$
124 private TreeViewer fTreeViewer
;
125 private List
<RemoteImportProfileElement
> fProfiles
;
126 private String fSelectedProfileName
;
127 private DetailsPanel fDetailsPanel
;
128 private Button fAddButton
;
129 private Button fRemoveButton
;
130 private Button fImportButton
;
131 private Button fExportButton
;
132 private Button fMoveUpButton
;
133 private Button fMoveDownButton
;
134 private Action fDeleteAction
;
135 private Action fCutAction
;
136 private Action fCopyAction
;
137 private Action fPasteAction
;
139 private static final String PROFILE_FILE_PATH
;
142 String profileFilePath
= REMOTE_PROFILES_XML_FILE_PATH
;
144 // Get alternative location under the parent of Activator.getDefault().getStateLocation()
145 IEclipsePreferences prefs
= DefaultScope
.INSTANCE
.getNode(Activator
.PLUGIN_ID
);
146 String plugin
= prefs
.get(REMOTE_PROFILES_LOCATION_PREF
, REMOTE_PROFILES_LOCATION_DIR_DEF
);
148 if (!plugin
.isEmpty()) {
149 // Alternative location
150 IPath profileFolderPath
= Activator
.getDefault().getStateLocation().removeLastSegments(1).append(plugin
);
151 File profileFolder
= profileFolderPath
.toFile();
152 // Create folder if it doesn't exist
153 if (profileFolder
.exists() || profileFolder
.mkdir()) {
154 profileFilePath
= profileFolderPath
.append(REMOTE_PROFILES_XML_FILE_NAME
).toString();
157 PROFILE_FILE_PATH
= profileFilePath
;
163 public RemoteProfilesPreferencePage() {
167 public void init(IWorkbench workbench
) {
168 noDefaultAndApplyButton();
172 protected Control
createContents(Composite parent
) {
173 Composite composite
= new Composite(parent
, SWT
.NONE
);
174 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
175 composite
.setLayoutData(gd
);
177 GridLayout gl
= new GridLayout(2, false);
178 composite
.setLayout(gl
);
180 PatternFilter patternFilter
= new PatternFilter() {
181 // show all children of matching profiles or profiles with matching connection node
183 protected boolean isLeafMatch(Viewer viewer
, Object element
) {
184 TreeViewer treeViewer
= (TreeViewer
) viewer
;
185 TracePackageContentProvider contentProvider
= (TracePackageContentProvider
) treeViewer
.getContentProvider();
186 Object parentElement
= element
;
187 while (!(parentElement
instanceof RemoteImportProfileElement
)) {
188 parentElement
= contentProvider
.getParent(parentElement
);
189 if (parentElement
instanceof TracePackageTraceElement
) {
190 // don't show children of trace element
194 RemoteImportProfileElement profile
= (RemoteImportProfileElement
) parentElement
;
195 if (super.isLeafMatch(viewer
, profile
)) {
198 for (Object child
: contentProvider
.getChildren(profile
)) {
199 if ((child
instanceof RemoteImportConnectionNodeElement
) && (super.isLeafMatch(viewer
, child
))) {
207 final FilteredTree filteredTree
= new FilteredTree(composite
,
208 SWT
.MULTI
| SWT
.FULL_SELECTION
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.BORDER
, patternFilter
, true);
209 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
211 filteredTree
.setLayoutData(gd
);
212 final TreeViewer treeViewer
= filteredTree
.getViewer();
213 fTreeViewer
= treeViewer
;
215 treeViewer
.setContentProvider(new TracePackageContentProvider() {
217 public Object
[] getElements(Object inputElement
) {
218 if (inputElement
instanceof ArrayList
) {
219 return ((ArrayList
<?
>) inputElement
).toArray();
221 return super.getElements(inputElement
);
225 public boolean hasChildren(Object element
) {
226 if (element
instanceof TracePackageTraceElement
) {
229 return super.hasChildren(element
);
233 treeViewer
.setLabelProvider(new ColumnLabelProvider() {
235 public String
getText(Object element
) {
236 if (element
instanceof TracePackageTraceElement
) {
237 for (TracePackageElement files
: ((TracePackageTraceElement
) element
).getChildren()) {
238 if (files
instanceof TracePackageFilesElement
) {
239 return ((TracePackageFilesElement
) files
).getFileName();
242 } else if (element
instanceof TracePackageElement
) {
243 return ((TracePackageElement
) element
).getText();
245 return super.getText(element
);
248 public Image
getImage(Object element
) {
249 if (element
instanceof TracePackageTraceElement
) {
250 for (TracePackageElement files
: ((TracePackageTraceElement
) element
).getChildren()) {
251 return files
.getImage();
253 } else if (element
instanceof TracePackageElement
) {
254 return ((TracePackageElement
) element
).getImage();
256 return super.getImage(element
);
260 treeViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
262 public void selectionChanged(SelectionChangedEvent event
) {
263 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
264 TracePackageElement element
= (TracePackageElement
) (selection
.size() == 1 ? selection
.getFirstElement() : null);
265 fDetailsPanel
.refreshDetailsPanel(element
);
266 enableButtons(selection
);
267 fSelectedProfileName
= null;
268 while (element
!= null) {
269 if (element
instanceof RemoteImportProfileElement
) {
270 fSelectedProfileName
= ((RemoteImportProfileElement
) element
).getProfileName();
272 element
= element
.getParent();
277 createGlobalActions();
280 fProfiles
= readProfiles(PROFILE_FILE_PATH
, new NullProgressMonitor());
282 treeViewer
.setAutoExpandLevel(AbstractTreeViewer
.ALL_LEVELS
);
283 treeViewer
.setInput(fProfiles
);
284 treeViewer
.expandAll();
286 Composite buttonBar
= createVerticalButtonBar(composite
);
287 gd
= new GridData(SWT
.CENTER
, SWT
.BEGINNING
, false, false);
288 gd
.verticalIndent
= filteredTree
.getFilterControl().computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
+ gl
.verticalSpacing
;
289 buttonBar
.setLayoutData(gd
);
290 enableButtons((IStructuredSelection
) treeViewer
.getSelection());
292 Composite details
= new Composite(composite
, SWT
.NONE
);
293 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 2, 1);
294 details
.setLayoutData(gd
);
295 gl
= new GridLayout(2, false);
297 details
.setLayout(gl
);
299 Label label
= new Label(details
, SWT
.NONE
);
300 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_DetailsPanelLabel
);
301 gd
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, false, 2, 1);
302 label
.setLayoutData(gd
);
304 fDetailsPanel
= new DetailsPanel(details
);
308 for (RemoteImportProfileElement profile
: fProfiles
) {
309 if (profile
.getProfileName().equals(fSelectedProfileName
)) {
310 fTreeViewer
.setSelection(new StructuredSelection(profile
));
314 Dialog
.applyDialogFont(composite
);
319 * Get the remote profiles stored in the preferences
324 * @return the list of remote profiles
326 public static List
<RemoteImportProfileElement
> getRemoteProfiles(IProgressMonitor monitor
) {
327 return readProfiles(PROFILE_FILE_PATH
, monitor
);
330 private static List
<RemoteImportProfileElement
> readProfiles(String path
, IProgressMonitor monitor
) {
331 final ExtractRemoteProfilesOperation op
= new ExtractRemoteProfilesOperation(path
);
333 List
<RemoteImportProfileElement
> profiles
= new ArrayList
<>();
334 if (!op
.getStatus().isOK()) {
337 TracePackageElement
[] resultElements
= op
.getResultElements();
338 if (resultElements
!= null) {
339 for (TracePackageElement element
: resultElements
) {
340 if (element
instanceof RemoteImportProfileElement
) {
341 profiles
.add((RemoteImportProfileElement
) element
);
348 private boolean writeProfiles(List
<RemoteImportProfileElement
> profiles
, String path
) {
350 String contents
= RemoteImportProfilesWriter
.writeProfilesToXML(profiles
.toArray(new TracePackageElement
[0]));
351 File file
= new File(path
);
352 try (BufferedWriter writer
= new BufferedWriter(new FileWriter(file
))) {
353 writer
.write(contents
);
356 } catch (IOException
| ParserConfigurationException
| TransformerException e
) {
357 MessageDialog
.openError(getShell(), RemoteMessages
.RemoteProfilesPreferencePage_ErrorWritingProfile
, e
.getMessage());
362 private void createGlobalActions() {
363 fDeleteAction
= new Action(RemoteMessages
.RemoteProfilesPreferencePage_DeleteAction
) {
366 final IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
367 if (selection
.size() == 0) {
370 for (Object item
: selection
.toList()) {
375 fDeleteAction
.setImageDescriptor(PlatformUI
.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages
.IMG_TOOL_DELETE
));
376 fDeleteAction
.setActionDefinitionId(IWorkbenchCommandConstants
.EDIT_DELETE
);
377 fDeleteAction
.setAccelerator(SWT
.DEL
);
379 fCutAction
= new Action(RemoteMessages
.RemoteProfilesPreferencePage_CutAction
) {
382 final IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
383 if (selection
.size() != 1) {
386 setClipboardContents(selection
);
387 Object item
= selection
.getFirstElement();
391 fCutAction
.setImageDescriptor(PlatformUI
.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages
.IMG_TOOL_CUT
));
392 fCutAction
.setActionDefinitionId(IWorkbenchCommandConstants
.EDIT_CUT
);
393 fCutAction
.setAccelerator(SWT
.CTRL
| 'X');
395 fCopyAction
= new Action(RemoteMessages
.RemoteProfilesPreferencePage_CopyAction
) {
398 final IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
399 if (selection
.size() != 1) {
402 setClipboardContents(new StructuredSelection(
403 copyElement(null, (TracePackageElement
) selection
.getFirstElement())));
406 fCopyAction
.setImageDescriptor(PlatformUI
.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages
.IMG_TOOL_COPY
));
407 fCopyAction
.setActionDefinitionId(IWorkbenchCommandConstants
.EDIT_COPY
);
408 fCopyAction
.setAccelerator(SWT
.CTRL
| 'C');
410 fPasteAction
= new Action(RemoteMessages
.RemoteProfilesPreferencePage_PasteAction
) {
413 final IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
414 if (selection
.size() > 1) {
417 if (!validatePaste(selection
.getFirstElement())) {
420 IStructuredSelection data
= getClipboardContents();
421 data
= getClipboardContents();
425 for (Object object
: data
.toArray()) {
426 if (object
instanceof RemoteImportProfileElement
) {
427 TracePackageElement element
= copyElement(null, (TracePackageElement
) object
);
428 TracePackageElement target
= (TracePackageElement
) selection
.getFirstElement();
429 if (target
== null) {
430 fProfiles
.add((RemoteImportProfileElement
) element
);
432 int index
= fProfiles
.indexOf(target
);
433 fProfiles
.add(index
+ 1, (RemoteImportProfileElement
) element
);
435 Object
[] expanded
= fTreeViewer
.getExpandedElements();
436 fTreeViewer
.refresh();
437 fTreeViewer
.setExpandedElements(expanded
);
438 fTreeViewer
.expandToLevel(element
, AbstractTreeViewer
.ALL_LEVELS
);
439 fTreeViewer
.setSelection(new StructuredSelection(element
));
441 } else if (object
instanceof TracePackageElement
&& selection
.getFirstElement() instanceof TracePackageElement
) {
442 TracePackageElement element
= copyElement(null, (TracePackageElement
) object
);
443 TracePackageElement target
= (TracePackageElement
) selection
.getFirstElement();
444 if (target
.getClass().equals(element
.getClass())) {
445 int index
= target
.getParent().indexOf(target
);
446 target
.getParent().addChild(index
+ 1, element
);
447 fTreeViewer
.refresh(target
.getParent());
449 target
.addChild(0, element
);
450 fTreeViewer
.refresh(target
);
452 fTreeViewer
.expandToLevel(element
, AbstractTreeViewer
.ALL_LEVELS
);
453 fTreeViewer
.setSelection(new StructuredSelection(element
));
459 fPasteAction
.setImageDescriptor(PlatformUI
.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages
.IMG_TOOL_PASTE
));
460 fPasteAction
.setActionDefinitionId(IWorkbenchCommandConstants
.EDIT_PASTE
);
461 fPasteAction
.setAccelerator(SWT
.CTRL
| 'V');
463 fTreeViewer
.getTree().addKeyListener(new KeyAdapter() {
465 public void keyPressed(KeyEvent e
) {
466 if (e
.stateMask
== 0 && e
.keyCode
== SWT
.DEL
) {
469 if ((e
.stateMask
& SWT
.CTRL
) == SWT
.CTRL
) {
470 if (e
.keyCode
== 'x') {
472 } else if (e
.keyCode
== 'c') {
474 } else if (e
.keyCode
== 'v') {
482 private void createContextMenu() {
483 MenuManager menuManager
= new MenuManager();
484 menuManager
.setRemoveAllWhenShown(true);
485 menuManager
.addMenuListener(new IMenuListener() {
487 public void menuAboutToShow(IMenuManager manager
) {
488 fillContextMenu(manager
);
492 Menu contextMenu
= menuManager
.createContextMenu(fTreeViewer
.getTree());
493 fTreeViewer
.getTree().setMenu(contextMenu
);
496 private void fillContextMenu(IMenuManager manager
) {
497 final IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
498 final List
<Object
> items
= selection
.toList();
499 if (items
.size() == 1) {
500 Object item
= items
.get(0);
501 if (item
instanceof RemoteImportProfileElement
) {
502 final RemoteImportProfileElement profile
= (RemoteImportProfileElement
) item
;
503 manager
.add(new Action(RemoteMessages
.RemoteProfilesPreferencePage_NewConnectionNode
) {
506 newConnectionNode(profile
, null);
509 } else if (item
instanceof RemoteImportConnectionNodeElement
) {
510 final RemoteImportConnectionNodeElement node
= (RemoteImportConnectionNodeElement
) item
;
511 manager
.add(new Action(RemoteMessages
.RemoteProfilesPreferencePage_NewTraceGroupAction
) {
514 newTraceGroup(node
, null);
517 } else if (item
instanceof RemoteImportTraceGroupElement
) {
518 final RemoteImportTraceGroupElement traceGroup
= (RemoteImportTraceGroupElement
) item
;
519 manager
.add(new Action(RemoteMessages
.RemoteProfilesPreferencePage_NewTraceAction
) {
522 newTrace(traceGroup
, null);
527 manager
.add(new Separator());
528 manager
.add(fDeleteAction
);
529 fDeleteAction
.setEnabled(items
.size() > 0);
530 manager
.add(new Separator());
531 manager
.add(fCutAction
);
532 fCutAction
.setEnabled(items
.size() == 1);
533 manager
.add(fCopyAction
);
534 fCopyAction
.setEnabled(items
.size() == 1);
535 manager
.add(fPasteAction
);
536 fPasteAction
.setEnabled(items
.size() <= 1 && validatePaste(selection
.getFirstElement()));
539 private Composite
createVerticalButtonBar(Composite parent
) {
540 Composite composite
= new Composite(parent
, SWT
.NONE
);
541 composite
.setLayout(new GridLayout());
543 fAddButton
= createVerticalButton(composite
, RemoteMessages
.RemoteProfilesPreferencePage_AddButton
);
544 fAddButton
.addSelectionListener(new SelectionAdapter() {
546 public void widgetSelected(SelectionEvent e
) {
547 IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
548 if (selection
.isEmpty()) {
550 } else if (selection
.getFirstElement() instanceof TracePackageElement
) {
551 TracePackageElement previous
= (TracePackageElement
) selection
.getFirstElement();
552 if (previous
instanceof RemoteImportProfileElement
) {
553 newProfile(previous
);
554 } else if (previous
instanceof RemoteImportConnectionNodeElement
) {
555 newConnectionNode(previous
.getParent(), previous
);
556 } else if (previous
instanceof RemoteImportTraceGroupElement
) {
557 newTraceGroup(previous
.getParent(), previous
);
558 } else if (previous
instanceof TracePackageTraceElement
) {
559 newTrace(previous
.getParent(), previous
);
565 fRemoveButton
= createVerticalButton(composite
, RemoteMessages
.RemoteProfilesPreferencePage_RemoveButton
);
566 fRemoveButton
.addSelectionListener(new SelectionAdapter() {
568 public void widgetSelected(SelectionEvent e
) {
569 IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
570 for (Object item
: selection
.toList()) {
571 if (item
instanceof RemoteImportProfileElement
) {
572 fProfiles
.remove(item
);
573 } else if (item
instanceof TracePackageElement
) {
574 TracePackageElement element
= (TracePackageElement
) item
;
575 element
.getParent().removeChild(element
);
578 fTreeViewer
.refresh();
583 new Label(composite
, SWT
.NONE
);
585 fImportButton
= createVerticalButton(composite
, RemoteMessages
.RemoteProfilesPreferencePage_ImportButton
);
586 fImportButton
.addSelectionListener(new SelectionAdapter() {
588 public void widgetSelected(SelectionEvent e
) {
589 FileDialog dialog
= TmfFileDialogFactory
.create(Display
.getCurrent().getActiveShell(), SWT
.OPEN
);
590 dialog
.setText(RemoteMessages
.RemoteProfilesPreferencePage_ImportFileDialogTitle
);
591 dialog
.setFilterExtensions(new String
[] { "*.xml", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
592 String path
= dialog
.open();
594 List
<RemoteImportProfileElement
> profiles
= readProfiles(path
, new NullProgressMonitor());
595 fProfiles
.addAll(profiles
);
596 fTreeViewer
.refresh();
597 for (RemoteImportProfileElement profile
: profiles
) {
598 fTreeViewer
.expandToLevel(profile
, AbstractTreeViewer
.ALL_LEVELS
);
600 fTreeViewer
.setSelection(new StructuredSelection(profiles
));
606 fExportButton
= createVerticalButton(composite
, RemoteMessages
.RemoteProfilesPreferencePage_ExportButton
);
607 fExportButton
.addSelectionListener(new SelectionAdapter() {
609 public void widgetSelected(SelectionEvent e
) {
610 FileDialog dialog
= TmfFileDialogFactory
.create(Display
.getCurrent().getActiveShell(), SWT
.SAVE
);
611 dialog
.setText(RemoteMessages
.RemoteProfilesPreferencePage_ExportFileDialogTitle
);
612 dialog
.setFilterExtensions(new String
[] { "*.xml", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
613 String path
= dialog
.open();
615 IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
616 List
<RemoteImportProfileElement
> profiles
= new ArrayList
<>();
617 for (Object element
: selection
.toList()) {
618 if (element
instanceof RemoteImportProfileElement
) {
619 profiles
.add((RemoteImportProfileElement
) element
);
622 writeProfiles(profiles
, path
);
627 new Label(composite
, SWT
.NONE
);
629 fMoveUpButton
= createVerticalButton(composite
, RemoteMessages
.RemoteProfilesPreferencePage_MoveUpButton
);
630 fMoveUpButton
.addSelectionListener(new SelectionAdapter() {
632 public void widgetSelected(SelectionEvent e
) {
633 IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
634 Object element
= selection
.getFirstElement();
635 if (element
instanceof RemoteImportProfileElement
) {
636 int index
= fProfiles
.indexOf(element
);
638 RemoteImportProfileElement profile
= fProfiles
.remove(index
);
639 fProfiles
.add(index
- 1, profile
);
640 Object
[] expanded
= fTreeViewer
.getExpandedElements();
641 fTreeViewer
.refresh();
642 fTreeViewer
.setExpandedElements(expanded
);
643 enableButtons(selection
);
645 } else if (element
instanceof TracePackageElement
) {
646 TracePackageElement child
= (TracePackageElement
) element
;
647 TracePackageElement parentElement
= child
.getParent();
648 int index
= parentElement
.indexOf(child
);
650 parentElement
.removeChild(child
);
651 parentElement
.addChild(index
- 1, child
);
652 Object
[] expanded
= fTreeViewer
.getExpandedElements();
653 fTreeViewer
.refresh(parentElement
);
654 fTreeViewer
.setExpandedElements(expanded
);
655 enableButtons(selection
);
661 fMoveDownButton
= createVerticalButton(composite
, RemoteMessages
.RemoteProfilesPreferencePage_MoveDownButton
);
662 fMoveDownButton
.addSelectionListener(new SelectionAdapter() {
664 public void widgetSelected(SelectionEvent e
) {
665 IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
666 Object element
= selection
.getFirstElement();
667 if (element
instanceof RemoteImportProfileElement
) {
668 int index
= fProfiles
.indexOf(selection
.getFirstElement());
669 if (index
>= 0 && index
< fProfiles
.size() - 1) {
670 RemoteImportProfileElement profile
= fProfiles
.remove(index
);
671 fProfiles
.add(index
+ 1, profile
);
672 Object
[] expanded
= fTreeViewer
.getExpandedElements();
673 fTreeViewer
.refresh();
674 fTreeViewer
.setExpandedElements(expanded
);
675 enableButtons(selection
);
677 } else if (element
instanceof TracePackageElement
) {
678 TracePackageElement child
= (TracePackageElement
) element
;
679 TracePackageElement parentElement
= child
.getParent();
680 int index
= parentElement
.indexOf(child
);
681 if (index
>= 0 && index
< parentElement
.getChildren().length
- 1) {
682 parentElement
.removeChild(child
);
683 parentElement
.addChild(index
+ 1, child
);
684 Object
[] expanded
= fTreeViewer
.getExpandedElements();
685 fTreeViewer
.refresh(parentElement
);
686 fTreeViewer
.setExpandedElements(expanded
);
687 enableButtons(selection
);
696 private static Button
createVerticalButton(Composite parent
, String text
) {
697 Button button
= new Button(parent
, SWT
.PUSH
);
698 button
.setLayoutData(new GridData(GridData
.HORIZONTAL_ALIGN_FILL
));
699 button
.setText(text
);
703 private void enableButtons(IStructuredSelection selection
) {
704 boolean allProfiles
= false;
705 for (Object element
: selection
.toList()) {
706 if (element
instanceof RemoteImportProfileElement
) {
713 fAddButton
.setEnabled(selection
.size() <= 1);
714 fRemoveButton
.setEnabled(!selection
.isEmpty());
715 fExportButton
.setEnabled(allProfiles
);
718 if (selection
.size() == 1) {
719 Object item
= selection
.getFirstElement();
720 if (item
instanceof RemoteImportProfileElement
) {
721 index
= fProfiles
.indexOf(item
);
722 length
= fProfiles
.size();
723 } else if (item
instanceof TracePackageElement
) {
724 TracePackageElement element
= (TracePackageElement
) item
;
725 TracePackageElement parent
= element
.getParent();
726 index
= parent
.indexOf(element
);
727 length
= parent
.getChildren().length
;
730 fMoveUpButton
.setEnabled(index
> 0);
731 fMoveDownButton
.setEnabled(index
< length
- 1);
734 private class DetailsPanel
{
736 private Composite fComposite
;
738 public DetailsPanel(Composite parent
) {
739 fComposite
= new Composite(parent
, SWT
.BORDER
);
740 GridLayout gl
= new GridLayout(2, false);
741 fComposite
.setLayout(gl
);
742 GridData gd
= new GridData(SWT
.FILL
, SWT
.BEGINNING
, true, false);
743 Combo combo
= new Combo(fComposite
, SWT
.BORDER
);
744 combo
.setText("*"); //$NON-NLS-1$
745 gd
.heightHint
= 2 * gl
.marginHeight
+ gl
.verticalSpacing
+ 2 * (combo
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
746 fComposite
.setLayoutData(gd
);
750 public void refreshDetailsPanel(final TracePackageElement selection
) {
751 for (Control control
: fComposite
.getChildren()) {
755 if (selection
instanceof RemoteImportProfileElement
) {
756 final RemoteImportProfileElement element
= (RemoteImportProfileElement
) selection
;
758 Label label
= new Label(fComposite
, SWT
.NONE
);
759 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_ProfileNameLabel
);
760 final Text profileNameText
= new Text(fComposite
, SWT
.BORDER
);
761 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
762 profileNameText
.setLayoutData(gd
);
763 profileNameText
.setText(element
.getProfileName());
764 profileNameText
.addModifyListener(new ModifyListener() {
766 public void modifyText(ModifyEvent e
) {
767 element
.setProfileName(profileNameText
.getText().trim());
768 fTreeViewer
.refresh(element
, true);
770 fSelectedProfileName
= element
.getProfileName();
774 } else if (selection
instanceof RemoteImportConnectionNodeElement
) {
775 final RemoteImportConnectionNodeElement element
= (RemoteImportConnectionNodeElement
) selection
;
777 Label label
= new Label(fComposite
, SWT
.NONE
);
778 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_ConnectionNodeNameLabel
);
779 final Text nameText
= new Text(fComposite
, SWT
.BORDER
);
780 nameText
.setText(element
.getName());
781 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
782 nameText
.setLayoutData(gd
);
783 nameText
.addModifyListener(new ModifyListener() {
785 public void modifyText(ModifyEvent e
) {
786 element
.setName(nameText
.getText().trim());
787 fTreeViewer
.refresh(element
, true);
792 label
= new Label(fComposite
, SWT
.NONE
);
793 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_ConnectionNodeURILabel
);
794 final Text uriText
= new Text(fComposite
, SWT
.BORDER
);
795 uriText
.setText(element
.getURI());
796 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
797 uriText
.setLayoutData(gd
);
798 uriText
.addModifyListener(new ModifyListener() {
800 public void modifyText(ModifyEvent e
) {
801 element
.setURI(uriText
.getText().trim());
802 fTreeViewer
.refresh(element
, true);
807 } else if (selection
instanceof RemoteImportTraceGroupElement
) {
808 final RemoteImportTraceGroupElement element
= (RemoteImportTraceGroupElement
) selection
;
810 Label label
= new Label(fComposite
, SWT
.NONE
);
811 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_RootPathLabel
);
812 final Text rootText
= new Text(fComposite
, SWT
.BORDER
);
813 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
814 rootText
.setLayoutData(gd
);
815 rootText
.setText(element
.getRootImportPath());
816 rootText
.addModifyListener(new ModifyListener() {
818 public void modifyText(ModifyEvent e
) {
819 element
.setRootImportPath(rootText
.getText().trim());
820 fTreeViewer
.refresh(element
, true);
825 // create label for alignment
826 new Label(fComposite
, SWT
.NONE
);
827 final Button recursiveButton
= new Button(fComposite
, SWT
.CHECK
);
828 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
829 recursiveButton
.setLayoutData(gd
);
830 recursiveButton
.setText(RemoteMessages
.RemoteProfilesPreferencePage_RecursiveButton
);
831 recursiveButton
.setSelection(element
.isRecursive());
832 recursiveButton
.addSelectionListener(new SelectionAdapter() {
834 public void widgetSelected(SelectionEvent e
) {
835 element
.setRecursive(recursiveButton
.getSelection());
836 fTreeViewer
.refresh(element
, true);
840 } else if (selection
instanceof TracePackageTraceElement
) {
841 final TracePackageTraceElement element
= (TracePackageTraceElement
) selection
;
843 Label label
= new Label(fComposite
, SWT
.NONE
);
844 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_FilePatternLabel
);
845 final Text fileNameText
= new Text(fComposite
, SWT
.BORDER
);
846 for (TracePackageElement child
: element
.getChildren()) {
847 if (child
instanceof TracePackageFilesElement
) {
848 TracePackageFilesElement files
= (TracePackageFilesElement
) child
;
849 fileNameText
.setText(files
.getFileName());
852 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
853 fileNameText
.setLayoutData(gd
);
854 fileNameText
.addModifyListener(new ModifyListener() {
856 public void modifyText(ModifyEvent e
) {
857 for (TracePackageElement child
: element
.getChildren()) {
858 if (child
instanceof TracePackageFilesElement
) {
859 TracePackageFilesElement files
= (TracePackageFilesElement
) child
;
860 files
.setFileName(fileNameText
.getText().trim());
863 fTreeViewer
.refresh(element
, true);
868 label
= new Label(fComposite
, SWT
.NONE
);
869 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_TraceTypeLabel
);
870 final Combo combo
= new Combo(fComposite
, SWT
.BORDER
| SWT
.READ_ONLY
);
871 String
[] availableTraceTypes
= TmfTraceType
.getAvailableTraceTypes();
872 String
[] traceTypeList
= new String
[availableTraceTypes
.length
+ 1];
873 traceTypeList
[0] = TRACE_TYPE_AUTO_DETECT
;
874 System
.arraycopy(availableTraceTypes
, 0, traceTypeList
, 1, availableTraceTypes
.length
);
875 combo
.setItems(traceTypeList
);
877 for (int i
= 1; i
< traceTypeList
.length
; i
++) {
878 String traceType
= traceTypeList
[i
];
879 String traceTypeId
= TmfTraceType
.getTraceTypeId(traceType
);
880 if (traceTypeId
.equals(element
.getTraceType())) {
885 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
886 combo
.setLayoutData(gd
);
887 combo
.addSelectionListener(new SelectionAdapter() {
889 public void widgetSelected(SelectionEvent e
) {
890 if (combo
.getSelectionIndex() == 0) {
891 element
.setTraceType(null);
893 String traceType
= combo
.getText();
894 String traceTypeId
= TmfTraceType
.getTraceTypeId(traceType
);
895 element
.setTraceType(traceTypeId
);
906 private RemoteImportProfileElement
newProfile(TracePackageElement previous
) {
907 RemoteImportProfileElement profile
= new RemoteImportProfileElement(null, RemoteMessages
.RemoteProfilesPreferencePage_DefaultProfileName
);
908 RemoteImportConnectionNodeElement node
= new RemoteImportConnectionNodeElement(profile
, RemoteMessages
.RemoteProfilesPreferencePage_DefaultConnectionNodeName
, RemoteMessages
.RemoteProfilesPreferencePage_DefaultConnectionNodeURI
);
909 RemoteImportTraceGroupElement traceGroup
= new RemoteImportTraceGroupElement(node
, DEFAULT_ROOT_IMPORT_PATH
);
910 TracePackageTraceElement trace
= new TracePackageTraceElement(traceGroup
, DEFAULT_IMPORT_NAME
, null);
911 new TracePackageFilesElement(trace
, DEFAULT_FILE_PATTERN
);
912 int index
= previous
== null ? fProfiles
.size() : fProfiles
.indexOf(previous
) + 1;
913 fProfiles
.add(index
, profile
);
914 newElementAdded(profile
);
918 private RemoteImportConnectionNodeElement
newConnectionNode(TracePackageElement parent
, TracePackageElement previous
) {
919 RemoteImportConnectionNodeElement node
= new RemoteImportConnectionNodeElement(null, RemoteMessages
.RemoteProfilesPreferencePage_DefaultConnectionNodeName
, RemoteMessages
.RemoteProfilesPreferencePage_DefaultConnectionNodeURI
);
920 RemoteImportTraceGroupElement traceGroup
= new RemoteImportTraceGroupElement(node
, DEFAULT_ROOT_IMPORT_PATH
);
921 TracePackageTraceElement trace
= new TracePackageTraceElement(traceGroup
, DEFAULT_IMPORT_NAME
, null);
922 new TracePackageFilesElement(trace
, DEFAULT_FILE_PATTERN
);
923 int index
= previous
== null ? parent
.getChildren().length
: parent
.indexOf(previous
) + 1;
924 parent
.addChild(index
, node
);
925 newElementAdded(node
);
929 private RemoteImportTraceGroupElement
newTraceGroup(TracePackageElement parent
, TracePackageElement previous
) {
930 RemoteImportTraceGroupElement traceGroup
= new RemoteImportTraceGroupElement(null, DEFAULT_ROOT_IMPORT_PATH
);
931 TracePackageTraceElement trace
= new TracePackageTraceElement(traceGroup
, DEFAULT_IMPORT_NAME
, null);
932 new TracePackageFilesElement(trace
, DEFAULT_FILE_PATTERN
);
933 int index
= previous
== null ? parent
.getChildren().length
: parent
.indexOf(previous
) + 1;
934 parent
.addChild(index
, traceGroup
);
935 newElementAdded(traceGroup
);
939 private TracePackageTraceElement
newTrace(TracePackageElement parent
, TracePackageElement previous
) {
940 TracePackageTraceElement trace
= new TracePackageTraceElement(null, DEFAULT_IMPORT_NAME
, null);
941 new TracePackageFilesElement(trace
, DEFAULT_FILE_PATTERN
);
942 int index
= previous
== null ? parent
.getChildren().length
: parent
.indexOf(previous
) + 1;
943 parent
.addChild(index
, trace
);
944 newElementAdded(trace
);
948 private void newElementAdded(TracePackageElement element
) {
949 if (element
.getParent() != null) {
950 fTreeViewer
.refresh(element
.getParent());
952 fTreeViewer
.refresh();
954 fTreeViewer
.expandToLevel(element
, AbstractTreeViewer
.ALL_LEVELS
);
955 fTreeViewer
.setSelection(new StructuredSelection(element
));
959 private void removeElement(Object item
) {
960 if (item
instanceof RemoteImportProfileElement
) {
961 fProfiles
.remove(item
);
962 fTreeViewer
.refresh();
964 } else if (item
instanceof TracePackageElement
) {
965 TracePackageElement element
= (TracePackageElement
) item
;
966 TracePackageElement parent
= element
.getParent();
967 parent
.removeChild(element
);
968 fTreeViewer
.refresh(parent
);
973 private TracePackageElement
copyElement(TracePackageElement parent
, TracePackageElement element
) {
974 TracePackageElement copy
= null;
975 if (element
instanceof RemoteImportProfileElement
) {
976 RemoteImportProfileElement source
= (RemoteImportProfileElement
) element
;
977 copy
= new RemoteImportProfileElement(parent
, source
.getProfileName());
978 } else if (element
instanceof RemoteImportConnectionNodeElement
) {
979 RemoteImportConnectionNodeElement source
= (RemoteImportConnectionNodeElement
) element
;
980 copy
= new RemoteImportConnectionNodeElement(parent
, source
.getName(), source
.getURI());
981 } else if (element
instanceof RemoteImportTraceGroupElement
) {
982 RemoteImportTraceGroupElement source
= (RemoteImportTraceGroupElement
) element
;
983 copy
= new RemoteImportTraceGroupElement(parent
, source
.getRootImportPath());
984 ((RemoteImportTraceGroupElement
) copy
).setRecursive(source
.isRecursive());
985 } else if (element
instanceof TracePackageTraceElement
) {
986 TracePackageTraceElement source
= (TracePackageTraceElement
) element
;
987 copy
= new TracePackageTraceElement(parent
, source
.getImportName(), source
.getTraceType());
988 } else if (element
instanceof TracePackageFilesElement
) {
989 TracePackageFilesElement source
= (TracePackageFilesElement
) element
;
990 copy
= new TracePackageFilesElement(parent
, source
.getFileName());
992 for (TracePackageElement child
: element
.getChildren()) {
993 copyElement(copy
, child
);
998 private static boolean validatePaste(Object target
) {
999 IStructuredSelection data
= getClipboardContents();
1000 if (data
== null || data
.isEmpty()) {
1003 for (Object item
: data
.toArray()) {
1004 if (item
instanceof RemoteImportConnectionNodeElement
) {
1005 if (!(target
instanceof RemoteImportConnectionNodeElement
||
1006 target
instanceof RemoteImportProfileElement
)) {
1009 } else if (item
instanceof RemoteImportTraceGroupElement
) {
1010 if (!(target
instanceof RemoteImportTraceGroupElement
||
1011 target
instanceof RemoteImportConnectionNodeElement
)) {
1014 } else if (item
instanceof TracePackageTraceElement
) {
1015 if (!(target
instanceof TracePackageTraceElement
||
1016 target
instanceof RemoteImportTraceGroupElement
)) {
1019 } else if (item
instanceof RemoteImportProfileElement
) {
1020 if (!(target
instanceof RemoteImportProfileElement
||
1031 private static void setClipboardContents(IStructuredSelection data
) {
1032 LocalSelectionTransfer transfer
= LocalSelectionTransfer
.getTransfer();
1033 transfer
.setSelection(data
);
1034 Clipboard clipboard
= new Clipboard(PlatformUI
.getWorkbench().getDisplay());
1035 clipboard
.setContents(new Object
[] { new Object() }, new Transfer
[] { transfer
});
1036 clipboard
.dispose();
1039 private static IStructuredSelection
getClipboardContents() {
1040 Clipboard clipboard
= new Clipboard(PlatformUI
.getWorkbench().getDisplay());
1041 IStructuredSelection data
= (IStructuredSelection
) clipboard
.getContents(LocalSelectionTransfer
.getTransfer());
1042 clipboard
.dispose();
1046 private void validate() {
1048 Set
<String
> profileNames
= new HashSet
<>();
1049 for (RemoteImportProfileElement profile
: fProfiles
) {
1050 if (profile
.getProfileName().length() == 0) {
1051 setErrorMessage(RemoteMessages
.RemoteProfilesPreferencePage_EmptyProfileNameError
);
1054 String prefix
= profile
.getProfileName() + ": "; //$NON-NLS-1$
1055 if (!profileNames
.add(profile
.getProfileName())) {
1056 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_DuplicateProfileNameError
);
1059 Set
<String
> nodeNames
= new HashSet
<>();
1061 for (TracePackageElement profileChild
: profile
.getChildren()) {
1062 if (profileChild
instanceof RemoteImportConnectionNodeElement
) {
1064 RemoteImportConnectionNodeElement node
= (RemoteImportConnectionNodeElement
) profileChild
;
1065 if (node
.getName().length() == 0) {
1066 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_EmptyNodeNameError
);
1069 // validate node name against the OS since the name will be used as folder name at the destination
1070 if (!ResourcesPlugin
.getWorkspace().validateName(node
.getName(), IResource
.FOLDER
).isOK()) {
1071 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_InvalidNodeName
);
1074 if (!nodeNames
.add(node
.getName())) {
1075 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_DuplicateConnectionNodeNameError
);
1079 if (node
.getURI().length() == 0) {
1080 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_EmptyNodeURIError
);
1084 URI uri
= URIUtil
.fromString(node
.getURI());
1085 IRemoteServicesManager manager
= TmfRemoteConnectionFactory
.getService(IRemoteServicesManager
.class);
1086 if (manager
== null || manager
.getConnectionType(uri
) == null) {
1087 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_UnsupportedURISchemeError
);
1090 if (uri
.getScheme().equals(SSH_SCHEME
)) {
1091 if (uri
.getHost() == null) {
1092 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_InvalidHostOrPortError
);
1095 if (uri
.getUserInfo() == null) {
1096 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_MissingUserInfoError
);
1100 } catch (URISyntaxException e
) {
1101 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_InvalidNodeURIError
);
1104 int traceGroupCount
= 0;
1105 for (TracePackageElement nodeChild
: node
.getChildren()) {
1106 if (nodeChild
instanceof RemoteImportTraceGroupElement
) {
1108 RemoteImportTraceGroupElement traceGroup
= (RemoteImportTraceGroupElement
) nodeChild
;
1109 if (traceGroup
.getRootImportPath().length() == 0) {
1110 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_EmptyRootPathError
);
1114 for (TracePackageElement traceGroupChild
: traceGroup
.getChildren()) {
1115 if (traceGroupChild
instanceof TracePackageTraceElement
) {
1117 TracePackageTraceElement trace
= (TracePackageTraceElement
) traceGroupChild
;
1119 for (TracePackageElement traceChild
: trace
.getChildren()) {
1120 if (traceChild
instanceof TracePackageFilesElement
) {
1121 TracePackageFilesElement files
= (TracePackageFilesElement
) traceChild
;
1122 if (files
.getFileName().length() == 0) {
1123 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_EmptyFilePatternError
);
1127 Pattern
.compile(files
.getFileName());
1128 } catch (PatternSyntaxException e
) {
1129 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_InvalidFilePatternError
);
1136 if (traceCount
== 0) {
1137 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_MissingTraceError
);
1142 if (traceGroupCount
== 0) {
1143 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_MissingTraceGroupError
);
1148 if (nodeCount
== 0) {
1149 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_MissingConnectionNodeError
);
1154 setErrorMessage(null);
1158 public boolean performOk() {
1159 return writeProfiles(fProfiles
, PROFILE_FILE_PATH
);
1163 * Set the selected profile name
1165 * @param profileName the selected profile name
1167 public void setSelectedProfile(String profileName
) {
1168 fSelectedProfileName
= profileName
;
1169 if (fTreeViewer
!= null && !fTreeViewer
.getTree().isDisposed()) {
1170 for (RemoteImportProfileElement profile
: fProfiles
) {
1171 if (profile
.getProfileName().equals(profileName
)) {
1172 fTreeViewer
.setSelection(new StructuredSelection(profile
));
1179 * Return the selected profile name
1181 * @return the selected profile name or null
1183 public String
getSelectedProfile() {
1184 return fSelectedProfileName
;