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
.ui
.ISharedImages
;
93 import org
.eclipse
.ui
.IWorkbench
;
94 import org
.eclipse
.ui
.IWorkbenchCommandConstants
;
95 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
96 import org
.eclipse
.ui
.PlatformUI
;
97 import org
.eclipse
.ui
.dialogs
.FilteredTree
;
98 import org
.eclipse
.ui
.dialogs
.PatternFilter
;
101 * Preference page for profiles
103 * @author Patrick Tasse
105 public class RemoteProfilesPreferencePage
extends PreferencePage
implements IWorkbenchPreferencePage
{
107 /** The ID of this preference page */
108 public static final String ID
= "org.eclipse.linuxtools.tmf.remote.ui.preferences.remoteprofiles"; //$NON-NLS-1$
110 private static final String REMOTE_PROFILES_XML_FILE_NAME
= "remote_profiles.xml"; //$NON-NLS-1$
111 private static final String REMOTE_PROFILES_XML_FILE_PATH
=
112 Activator
.getDefault().getStateLocation().addTrailingSeparator().append(REMOTE_PROFILES_XML_FILE_NAME
).toOSString();
114 private static final String REMOTE_PROFILES_LOCATION_PREF
= "REMOTE_PROFILES_LOCATION"; //$NON-NLS-1$
115 private static final String REMOTE_PROFILES_LOCATION_DIR_DEF
= ""; //$NON-NLS-1$
117 private static final String DEFAULT_ROOT_IMPORT_PATH
= "/rootpath"; //$NON-NLS-1$
118 private static final String DEFAULT_IMPORT_NAME
= ""; //$NON-NLS-1$
119 private static final String DEFAULT_FILE_PATTERN
= ".*"; //$NON-NLS-1$
120 private static final String TRACE_TYPE_AUTO_DETECT
= Messages
.ImportTraceWizard_AutoDetection
;
121 private static final String SSH_SCHEME
= "ssh"; //$NON-NLS-1$
123 private TreeViewer fTreeViewer
;
124 private List
<RemoteImportProfileElement
> fProfiles
;
125 private String fSelectedProfileName
;
126 private DetailsPanel fDetailsPanel
;
127 private Button fAddButton
;
128 private Button fRemoveButton
;
129 private Button fImportButton
;
130 private Button fExportButton
;
131 private Button fMoveUpButton
;
132 private Button fMoveDownButton
;
133 private Action fDeleteAction
;
134 private Action fCutAction
;
135 private Action fCopyAction
;
136 private Action fPasteAction
;
138 private static final String PROFILE_FILE_PATH
;
141 String profileFilePath
= REMOTE_PROFILES_XML_FILE_PATH
;
143 // Get alternative location under the parent of Activator.getDefault().getStateLocation()
144 IEclipsePreferences prefs
= DefaultScope
.INSTANCE
.getNode(Activator
.PLUGIN_ID
);
145 String plugin
= prefs
.get(REMOTE_PROFILES_LOCATION_PREF
, REMOTE_PROFILES_LOCATION_DIR_DEF
);
147 if (!plugin
.isEmpty()) {
148 // Alternative location
149 IPath profileFolderPath
= Activator
.getDefault().getStateLocation().removeLastSegments(1).append(plugin
);
150 File profileFolder
= profileFolderPath
.toFile();
151 // Create folder if it doesn't exist
152 if (profileFolder
.exists() || profileFolder
.mkdir()) {
153 profileFilePath
= profileFolderPath
.append(REMOTE_PROFILES_XML_FILE_NAME
).toString();
156 PROFILE_FILE_PATH
= profileFilePath
;
162 public RemoteProfilesPreferencePage() {
166 public void init(IWorkbench workbench
) {
167 noDefaultAndApplyButton();
171 protected Control
createContents(Composite parent
) {
172 Composite composite
= new Composite(parent
, SWT
.NONE
);
173 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
174 composite
.setLayoutData(gd
);
176 GridLayout gl
= new GridLayout(2, false);
177 composite
.setLayout(gl
);
179 PatternFilter patternFilter
= new PatternFilter() {
180 // show all children of matching profiles or profiles with matching connection node
182 protected boolean isLeafMatch(Viewer viewer
, Object element
) {
183 TreeViewer treeViewer
= (TreeViewer
) viewer
;
184 TracePackageContentProvider contentProvider
= (TracePackageContentProvider
) treeViewer
.getContentProvider();
185 Object parentElement
= element
;
186 while (!(parentElement
instanceof RemoteImportProfileElement
)) {
187 parentElement
= contentProvider
.getParent(parentElement
);
188 if (parentElement
instanceof TracePackageTraceElement
) {
189 // don't show children of trace element
193 RemoteImportProfileElement profile
= (RemoteImportProfileElement
) parentElement
;
194 if (super.isLeafMatch(viewer
, profile
)) {
197 for (Object child
: contentProvider
.getChildren(profile
)) {
198 if ((child
instanceof RemoteImportConnectionNodeElement
) && (super.isLeafMatch(viewer
, child
))) {
206 final FilteredTree filteredTree
= new FilteredTree(composite
,
207 SWT
.MULTI
| SWT
.FULL_SELECTION
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.BORDER
, patternFilter
, true);
208 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
210 filteredTree
.setLayoutData(gd
);
211 final TreeViewer treeViewer
= filteredTree
.getViewer();
212 fTreeViewer
= treeViewer
;
214 treeViewer
.setContentProvider(new TracePackageContentProvider() {
216 public Object
[] getElements(Object inputElement
) {
217 if (inputElement
instanceof ArrayList
) {
218 return ((ArrayList
<?
>) inputElement
).toArray();
220 return super.getElements(inputElement
);
224 public boolean hasChildren(Object element
) {
225 if (element
instanceof TracePackageTraceElement
) {
228 return super.hasChildren(element
);
232 treeViewer
.setLabelProvider(new ColumnLabelProvider() {
234 public String
getText(Object element
) {
235 if (element
instanceof TracePackageTraceElement
) {
236 for (TracePackageElement files
: ((TracePackageTraceElement
) element
).getChildren()) {
237 if (files
instanceof TracePackageFilesElement
) {
238 return ((TracePackageFilesElement
) files
).getFileName();
241 } else if (element
instanceof TracePackageElement
) {
242 return ((TracePackageElement
) element
).getText();
244 return super.getText(element
);
247 public Image
getImage(Object element
) {
248 if (element
instanceof TracePackageTraceElement
) {
249 for (TracePackageElement files
: ((TracePackageTraceElement
) element
).getChildren()) {
250 return files
.getImage();
252 } else if (element
instanceof TracePackageElement
) {
253 return ((TracePackageElement
) element
).getImage();
255 return super.getImage(element
);
259 treeViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
261 public void selectionChanged(SelectionChangedEvent event
) {
262 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
263 TracePackageElement element
= (TracePackageElement
) (selection
.size() == 1 ? selection
.getFirstElement() : null);
264 fDetailsPanel
.refreshDetailsPanel(element
);
265 enableButtons(selection
);
266 fSelectedProfileName
= null;
267 while (element
!= null) {
268 if (element
instanceof RemoteImportProfileElement
) {
269 fSelectedProfileName
= ((RemoteImportProfileElement
) element
).getProfileName();
271 element
= element
.getParent();
276 createGlobalActions();
279 fProfiles
= readProfiles(PROFILE_FILE_PATH
, new NullProgressMonitor());
281 treeViewer
.setAutoExpandLevel(AbstractTreeViewer
.ALL_LEVELS
);
282 treeViewer
.setInput(fProfiles
);
283 treeViewer
.expandAll();
285 Composite buttonBar
= createVerticalButtonBar(composite
);
286 gd
= new GridData(SWT
.CENTER
, SWT
.BEGINNING
, false, false);
287 gd
.verticalIndent
= filteredTree
.getFilterControl().computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
+ gl
.verticalSpacing
;
288 buttonBar
.setLayoutData(gd
);
289 enableButtons((IStructuredSelection
) treeViewer
.getSelection());
291 Composite details
= new Composite(composite
, SWT
.NONE
);
292 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 2, 1);
293 details
.setLayoutData(gd
);
294 gl
= new GridLayout(2, false);
296 details
.setLayout(gl
);
298 Label label
= new Label(details
, SWT
.NONE
);
299 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_DetailsPanelLabel
);
300 gd
= new GridData(SWT
.BEGINNING
, SWT
.CENTER
, false, false, 2, 1);
301 label
.setLayoutData(gd
);
303 fDetailsPanel
= new DetailsPanel(details
);
307 for (RemoteImportProfileElement profile
: fProfiles
) {
308 if (profile
.getProfileName().equals(fSelectedProfileName
)) {
309 fTreeViewer
.setSelection(new StructuredSelection(profile
));
313 Dialog
.applyDialogFont(composite
);
318 * Get the remote profiles stored in the preferences
323 * @return the list of remote profiles
325 public static List
<RemoteImportProfileElement
> getRemoteProfiles(IProgressMonitor monitor
) {
326 return readProfiles(PROFILE_FILE_PATH
, monitor
);
329 private static List
<RemoteImportProfileElement
> readProfiles(String path
, IProgressMonitor monitor
) {
330 final ExtractRemoteProfilesOperation op
= new ExtractRemoteProfilesOperation(path
);
332 List
<RemoteImportProfileElement
> profiles
= new ArrayList
<>();
333 if (!op
.getStatus().isOK()) {
336 TracePackageElement
[] resultElements
= op
.getResultElements();
337 if (resultElements
!= null) {
338 for (TracePackageElement element
: resultElements
) {
339 if (element
instanceof RemoteImportProfileElement
) {
340 profiles
.add((RemoteImportProfileElement
) element
);
347 private boolean writeProfiles(List
<RemoteImportProfileElement
> profiles
, String path
) {
349 String contents
= RemoteImportProfilesWriter
.writeProfilesToXML(profiles
.toArray(new TracePackageElement
[0]));
350 File file
= new File(path
);
351 try (BufferedWriter writer
= new BufferedWriter(new FileWriter(file
))) {
352 writer
.write(contents
);
355 } catch (IOException
| ParserConfigurationException
| TransformerException e
) {
356 MessageDialog
.openError(getShell(), RemoteMessages
.RemoteProfilesPreferencePage_ErrorWritingProfile
, e
.getMessage());
361 private void createGlobalActions() {
362 fDeleteAction
= new Action(RemoteMessages
.RemoteProfilesPreferencePage_DeleteAction
) {
365 final IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
366 if (selection
.size() == 0) {
369 for (Object item
: selection
.toList()) {
374 fDeleteAction
.setImageDescriptor(PlatformUI
.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages
.IMG_TOOL_DELETE
));
375 fDeleteAction
.setActionDefinitionId(IWorkbenchCommandConstants
.EDIT_DELETE
);
376 fDeleteAction
.setAccelerator(SWT
.DEL
);
378 fCutAction
= new Action(RemoteMessages
.RemoteProfilesPreferencePage_CutAction
) {
381 final IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
382 if (selection
.size() != 1) {
385 setClipboardContents(selection
);
386 Object item
= selection
.getFirstElement();
390 fCutAction
.setImageDescriptor(PlatformUI
.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages
.IMG_TOOL_CUT
));
391 fCutAction
.setActionDefinitionId(IWorkbenchCommandConstants
.EDIT_CUT
);
392 fCutAction
.setAccelerator(SWT
.CTRL
| 'X');
394 fCopyAction
= new Action(RemoteMessages
.RemoteProfilesPreferencePage_CopyAction
) {
397 final IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
398 if (selection
.size() != 1) {
401 setClipboardContents(new StructuredSelection(
402 copyElement(null, (TracePackageElement
) selection
.getFirstElement())));
405 fCopyAction
.setImageDescriptor(PlatformUI
.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages
.IMG_TOOL_COPY
));
406 fCopyAction
.setActionDefinitionId(IWorkbenchCommandConstants
.EDIT_COPY
);
407 fCopyAction
.setAccelerator(SWT
.CTRL
| 'C');
409 fPasteAction
= new Action(RemoteMessages
.RemoteProfilesPreferencePage_PasteAction
) {
412 final IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
413 if (selection
.size() > 1) {
416 if (!validatePaste(selection
.getFirstElement())) {
419 IStructuredSelection data
= getClipboardContents();
420 data
= getClipboardContents();
424 for (Object object
: data
.toArray()) {
425 if (object
instanceof RemoteImportProfileElement
) {
426 TracePackageElement element
= copyElement(null, (TracePackageElement
) object
);
427 TracePackageElement target
= (TracePackageElement
) selection
.getFirstElement();
428 if (target
== null) {
429 fProfiles
.add((RemoteImportProfileElement
) element
);
431 int index
= fProfiles
.indexOf(target
);
432 fProfiles
.add(index
+ 1, (RemoteImportProfileElement
) element
);
434 Object
[] expanded
= fTreeViewer
.getExpandedElements();
435 fTreeViewer
.refresh();
436 fTreeViewer
.setExpandedElements(expanded
);
437 fTreeViewer
.expandToLevel(element
, AbstractTreeViewer
.ALL_LEVELS
);
438 fTreeViewer
.setSelection(new StructuredSelection(element
));
440 } else if (object
instanceof TracePackageElement
&& selection
.getFirstElement() instanceof TracePackageElement
) {
441 TracePackageElement element
= copyElement(null, (TracePackageElement
) object
);
442 TracePackageElement target
= (TracePackageElement
) selection
.getFirstElement();
443 if (target
.getClass().equals(element
.getClass())) {
444 int index
= target
.getParent().indexOf(target
);
445 target
.getParent().addChild(index
+ 1, element
);
446 fTreeViewer
.refresh(target
.getParent());
448 target
.addChild(0, element
);
449 fTreeViewer
.refresh(target
);
451 fTreeViewer
.expandToLevel(element
, AbstractTreeViewer
.ALL_LEVELS
);
452 fTreeViewer
.setSelection(new StructuredSelection(element
));
458 fPasteAction
.setImageDescriptor(PlatformUI
.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages
.IMG_TOOL_PASTE
));
459 fPasteAction
.setActionDefinitionId(IWorkbenchCommandConstants
.EDIT_PASTE
);
460 fPasteAction
.setAccelerator(SWT
.CTRL
| 'V');
462 fTreeViewer
.getTree().addKeyListener(new KeyAdapter() {
464 public void keyPressed(KeyEvent e
) {
465 if (e
.stateMask
== 0 && e
.keyCode
== SWT
.DEL
) {
468 if ((e
.stateMask
& SWT
.CTRL
) == SWT
.CTRL
) {
469 if (e
.keyCode
== 'x') {
471 } else if (e
.keyCode
== 'c') {
473 } else if (e
.keyCode
== 'v') {
481 private void createContextMenu() {
482 MenuManager menuManager
= new MenuManager();
483 menuManager
.setRemoveAllWhenShown(true);
484 menuManager
.addMenuListener(new IMenuListener() {
486 public void menuAboutToShow(IMenuManager manager
) {
487 fillContextMenu(manager
);
491 Menu contextMenu
= menuManager
.createContextMenu(fTreeViewer
.getTree());
492 fTreeViewer
.getTree().setMenu(contextMenu
);
495 private void fillContextMenu(IMenuManager manager
) {
496 final IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
497 final List
<Object
> items
= selection
.toList();
498 if (items
.size() == 1) {
499 Object item
= items
.get(0);
500 if (item
instanceof RemoteImportProfileElement
) {
501 final RemoteImportProfileElement profile
= (RemoteImportProfileElement
) item
;
502 manager
.add(new Action(RemoteMessages
.RemoteProfilesPreferencePage_NewConnectionNode
) {
505 newConnectionNode(profile
, null);
508 } else if (item
instanceof RemoteImportConnectionNodeElement
) {
509 final RemoteImportConnectionNodeElement node
= (RemoteImportConnectionNodeElement
) item
;
510 manager
.add(new Action(RemoteMessages
.RemoteProfilesPreferencePage_NewTraceGroupAction
) {
513 newTraceGroup(node
, null);
516 } else if (item
instanceof RemoteImportTraceGroupElement
) {
517 final RemoteImportTraceGroupElement traceGroup
= (RemoteImportTraceGroupElement
) item
;
518 manager
.add(new Action(RemoteMessages
.RemoteProfilesPreferencePage_NewTraceAction
) {
521 newTrace(traceGroup
, null);
526 manager
.add(new Separator());
527 manager
.add(fDeleteAction
);
528 fDeleteAction
.setEnabled(items
.size() > 0);
529 manager
.add(new Separator());
530 manager
.add(fCutAction
);
531 fCutAction
.setEnabled(items
.size() == 1);
532 manager
.add(fCopyAction
);
533 fCopyAction
.setEnabled(items
.size() == 1);
534 manager
.add(fPasteAction
);
535 fPasteAction
.setEnabled(items
.size() <= 1 && validatePaste(selection
.getFirstElement()));
538 private Composite
createVerticalButtonBar(Composite parent
) {
539 Composite composite
= new Composite(parent
, SWT
.NONE
);
540 composite
.setLayout(new GridLayout());
542 fAddButton
= createVerticalButton(composite
, RemoteMessages
.RemoteProfilesPreferencePage_AddButton
);
543 fAddButton
.addSelectionListener(new SelectionAdapter() {
545 public void widgetSelected(SelectionEvent e
) {
546 IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
547 if (selection
.isEmpty()) {
549 } else if (selection
.getFirstElement() instanceof TracePackageElement
) {
550 TracePackageElement previous
= (TracePackageElement
) selection
.getFirstElement();
551 if (previous
instanceof RemoteImportProfileElement
) {
552 newProfile(previous
);
553 } else if (previous
instanceof RemoteImportConnectionNodeElement
) {
554 newConnectionNode(previous
.getParent(), previous
);
555 } else if (previous
instanceof RemoteImportTraceGroupElement
) {
556 newTraceGroup(previous
.getParent(), previous
);
557 } else if (previous
instanceof TracePackageTraceElement
) {
558 newTrace(previous
.getParent(), previous
);
564 fRemoveButton
= createVerticalButton(composite
, RemoteMessages
.RemoteProfilesPreferencePage_RemoveButton
);
565 fRemoveButton
.addSelectionListener(new SelectionAdapter() {
567 public void widgetSelected(SelectionEvent e
) {
568 IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
569 for (Object item
: selection
.toList()) {
570 if (item
instanceof RemoteImportProfileElement
) {
571 fProfiles
.remove(item
);
572 } else if (item
instanceof TracePackageElement
) {
573 TracePackageElement element
= (TracePackageElement
) item
;
574 element
.getParent().removeChild(element
);
577 fTreeViewer
.refresh();
582 new Label(composite
, SWT
.NONE
);
584 fImportButton
= createVerticalButton(composite
, RemoteMessages
.RemoteProfilesPreferencePage_ImportButton
);
585 fImportButton
.addSelectionListener(new SelectionAdapter() {
587 public void widgetSelected(SelectionEvent e
) {
588 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.OPEN
);
589 dialog
.setText(RemoteMessages
.RemoteProfilesPreferencePage_ImportFileDialogTitle
);
590 dialog
.setFilterExtensions(new String
[] { "*.xml", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
591 String path
= dialog
.open();
593 List
<RemoteImportProfileElement
> profiles
= readProfiles(path
, new NullProgressMonitor());
594 fProfiles
.addAll(profiles
);
595 fTreeViewer
.refresh();
596 for (RemoteImportProfileElement profile
: profiles
) {
597 fTreeViewer
.expandToLevel(profile
, AbstractTreeViewer
.ALL_LEVELS
);
599 fTreeViewer
.setSelection(new StructuredSelection(profiles
));
605 fExportButton
= createVerticalButton(composite
, RemoteMessages
.RemoteProfilesPreferencePage_ExportButton
);
606 fExportButton
.addSelectionListener(new SelectionAdapter() {
608 public void widgetSelected(SelectionEvent e
) {
609 FileDialog dialog
= new FileDialog(Display
.getCurrent().getActiveShell(), SWT
.SAVE
);
610 dialog
.setText(RemoteMessages
.RemoteProfilesPreferencePage_ExportFileDialogTitle
);
611 dialog
.setFilterExtensions(new String
[] { "*.xml", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
612 String path
= dialog
.open();
614 IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
615 List
<RemoteImportProfileElement
> profiles
= new ArrayList
<>();
616 for (Object element
: selection
.toList()) {
617 if (element
instanceof RemoteImportProfileElement
) {
618 profiles
.add((RemoteImportProfileElement
) element
);
621 writeProfiles(profiles
, path
);
626 new Label(composite
, SWT
.NONE
);
628 fMoveUpButton
= createVerticalButton(composite
, RemoteMessages
.RemoteProfilesPreferencePage_MoveUpButton
);
629 fMoveUpButton
.addSelectionListener(new SelectionAdapter() {
631 public void widgetSelected(SelectionEvent e
) {
632 IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
633 Object element
= selection
.getFirstElement();
634 if (element
instanceof RemoteImportProfileElement
) {
635 int index
= fProfiles
.indexOf(element
);
637 RemoteImportProfileElement profile
= fProfiles
.remove(index
);
638 fProfiles
.add(index
- 1, profile
);
639 Object
[] expanded
= fTreeViewer
.getExpandedElements();
640 fTreeViewer
.refresh();
641 fTreeViewer
.setExpandedElements(expanded
);
642 enableButtons(selection
);
644 } else if (element
instanceof TracePackageElement
) {
645 TracePackageElement child
= (TracePackageElement
) element
;
646 TracePackageElement parentElement
= child
.getParent();
647 int index
= parentElement
.indexOf(child
);
649 parentElement
.removeChild(child
);
650 parentElement
.addChild(index
- 1, child
);
651 Object
[] expanded
= fTreeViewer
.getExpandedElements();
652 fTreeViewer
.refresh(parentElement
);
653 fTreeViewer
.setExpandedElements(expanded
);
654 enableButtons(selection
);
660 fMoveDownButton
= createVerticalButton(composite
, RemoteMessages
.RemoteProfilesPreferencePage_MoveDownButton
);
661 fMoveDownButton
.addSelectionListener(new SelectionAdapter() {
663 public void widgetSelected(SelectionEvent e
) {
664 IStructuredSelection selection
= (IStructuredSelection
) fTreeViewer
.getSelection();
665 Object element
= selection
.getFirstElement();
666 if (element
instanceof RemoteImportProfileElement
) {
667 int index
= fProfiles
.indexOf(selection
.getFirstElement());
668 if (index
>= 0 && index
< fProfiles
.size() - 1) {
669 RemoteImportProfileElement profile
= fProfiles
.remove(index
);
670 fProfiles
.add(index
+ 1, profile
);
671 Object
[] expanded
= fTreeViewer
.getExpandedElements();
672 fTreeViewer
.refresh();
673 fTreeViewer
.setExpandedElements(expanded
);
674 enableButtons(selection
);
676 } else if (element
instanceof TracePackageElement
) {
677 TracePackageElement child
= (TracePackageElement
) element
;
678 TracePackageElement parentElement
= child
.getParent();
679 int index
= parentElement
.indexOf(child
);
680 if (index
>= 0 && index
< parentElement
.getChildren().length
- 1) {
681 parentElement
.removeChild(child
);
682 parentElement
.addChild(index
+ 1, child
);
683 Object
[] expanded
= fTreeViewer
.getExpandedElements();
684 fTreeViewer
.refresh(parentElement
);
685 fTreeViewer
.setExpandedElements(expanded
);
686 enableButtons(selection
);
695 private static Button
createVerticalButton(Composite parent
, String text
) {
696 Button button
= new Button(parent
, SWT
.PUSH
);
697 button
.setLayoutData(new GridData(GridData
.HORIZONTAL_ALIGN_FILL
));
698 button
.setText(text
);
702 private void enableButtons(IStructuredSelection selection
) {
703 boolean allProfiles
= false;
704 for (Object element
: selection
.toList()) {
705 if (element
instanceof RemoteImportProfileElement
) {
712 fAddButton
.setEnabled(selection
.size() <= 1);
713 fRemoveButton
.setEnabled(!selection
.isEmpty());
714 fExportButton
.setEnabled(allProfiles
);
717 if (selection
.size() == 1) {
718 Object item
= selection
.getFirstElement();
719 if (item
instanceof RemoteImportProfileElement
) {
720 index
= fProfiles
.indexOf(item
);
721 length
= fProfiles
.size();
722 } else if (item
instanceof TracePackageElement
) {
723 TracePackageElement element
= (TracePackageElement
) item
;
724 TracePackageElement parent
= element
.getParent();
725 index
= parent
.indexOf(element
);
726 length
= parent
.getChildren().length
;
729 fMoveUpButton
.setEnabled(index
> 0);
730 fMoveDownButton
.setEnabled(index
< length
- 1);
733 private class DetailsPanel
{
735 private Composite fComposite
;
737 public DetailsPanel(Composite parent
) {
738 fComposite
= new Composite(parent
, SWT
.BORDER
);
739 GridLayout gl
= new GridLayout(2, false);
740 fComposite
.setLayout(gl
);
741 GridData gd
= new GridData(SWT
.FILL
, SWT
.BEGINNING
, true, false);
742 Combo combo
= new Combo(fComposite
, SWT
.BORDER
);
743 combo
.setText("*"); //$NON-NLS-1$
744 gd
.heightHint
= 2 * gl
.marginHeight
+ gl
.verticalSpacing
+ 2 * (combo
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
745 fComposite
.setLayoutData(gd
);
749 public void refreshDetailsPanel(final TracePackageElement selection
) {
750 for (Control control
: fComposite
.getChildren()) {
754 if (selection
instanceof RemoteImportProfileElement
) {
755 final RemoteImportProfileElement element
= (RemoteImportProfileElement
) selection
;
757 Label label
= new Label(fComposite
, SWT
.NONE
);
758 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_ProfileNameLabel
);
759 final Text profileNameText
= new Text(fComposite
, SWT
.BORDER
);
760 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
761 profileNameText
.setLayoutData(gd
);
762 profileNameText
.setText(element
.getProfileName());
763 profileNameText
.addModifyListener(new ModifyListener() {
765 public void modifyText(ModifyEvent e
) {
766 element
.setProfileName(profileNameText
.getText().trim());
767 fTreeViewer
.refresh(element
, true);
769 fSelectedProfileName
= element
.getProfileName();
773 } else if (selection
instanceof RemoteImportConnectionNodeElement
) {
774 final RemoteImportConnectionNodeElement element
= (RemoteImportConnectionNodeElement
) selection
;
776 Label label
= new Label(fComposite
, SWT
.NONE
);
777 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_ConnectionNodeNameLabel
);
778 final Text nameText
= new Text(fComposite
, SWT
.BORDER
);
779 nameText
.setText(element
.getName());
780 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
781 nameText
.setLayoutData(gd
);
782 nameText
.addModifyListener(new ModifyListener() {
784 public void modifyText(ModifyEvent e
) {
785 element
.setName(nameText
.getText().trim());
786 fTreeViewer
.refresh(element
, true);
791 label
= new Label(fComposite
, SWT
.NONE
);
792 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_ConnectionNodeURILabel
);
793 final Text uriText
= new Text(fComposite
, SWT
.BORDER
);
794 uriText
.setText(element
.getURI());
795 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
796 uriText
.setLayoutData(gd
);
797 uriText
.addModifyListener(new ModifyListener() {
799 public void modifyText(ModifyEvent e
) {
800 element
.setURI(uriText
.getText().trim());
801 fTreeViewer
.refresh(element
, true);
806 } else if (selection
instanceof RemoteImportTraceGroupElement
) {
807 final RemoteImportTraceGroupElement element
= (RemoteImportTraceGroupElement
) selection
;
809 Label label
= new Label(fComposite
, SWT
.NONE
);
810 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_RootPathLabel
);
811 final Text rootText
= new Text(fComposite
, SWT
.BORDER
);
812 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
813 rootText
.setLayoutData(gd
);
814 rootText
.setText(element
.getRootImportPath());
815 rootText
.addModifyListener(new ModifyListener() {
817 public void modifyText(ModifyEvent e
) {
818 element
.setRootImportPath(rootText
.getText().trim());
819 fTreeViewer
.refresh(element
, true);
824 // create label for alignment
825 new Label(fComposite
, SWT
.NONE
);
826 final Button recursiveButton
= new Button(fComposite
, SWT
.CHECK
);
827 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
828 recursiveButton
.setLayoutData(gd
);
829 recursiveButton
.setText(RemoteMessages
.RemoteProfilesPreferencePage_RecursiveButton
);
830 recursiveButton
.setSelection(element
.isRecursive());
831 recursiveButton
.addSelectionListener(new SelectionAdapter() {
833 public void widgetSelected(SelectionEvent e
) {
834 element
.setRecursive(recursiveButton
.getSelection());
835 fTreeViewer
.refresh(element
, true);
839 } else if (selection
instanceof TracePackageTraceElement
) {
840 final TracePackageTraceElement element
= (TracePackageTraceElement
) selection
;
842 Label label
= new Label(fComposite
, SWT
.NONE
);
843 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_FilePatternLabel
);
844 final Text fileNameText
= new Text(fComposite
, SWT
.BORDER
);
845 for (TracePackageElement child
: element
.getChildren()) {
846 if (child
instanceof TracePackageFilesElement
) {
847 TracePackageFilesElement files
= (TracePackageFilesElement
) child
;
848 fileNameText
.setText(files
.getFileName());
851 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
852 fileNameText
.setLayoutData(gd
);
853 fileNameText
.addModifyListener(new ModifyListener() {
855 public void modifyText(ModifyEvent e
) {
856 for (TracePackageElement child
: element
.getChildren()) {
857 if (child
instanceof TracePackageFilesElement
) {
858 TracePackageFilesElement files
= (TracePackageFilesElement
) child
;
859 files
.setFileName(fileNameText
.getText().trim());
862 fTreeViewer
.refresh(element
, true);
867 label
= new Label(fComposite
, SWT
.NONE
);
868 label
.setText(RemoteMessages
.RemoteProfilesPreferencePage_TraceTypeLabel
);
869 final Combo combo
= new Combo(fComposite
, SWT
.BORDER
| SWT
.READ_ONLY
);
870 String
[] availableTraceTypes
= TmfTraceType
.getAvailableTraceTypes();
871 String
[] traceTypeList
= new String
[availableTraceTypes
.length
+ 1];
872 traceTypeList
[0] = TRACE_TYPE_AUTO_DETECT
;
873 System
.arraycopy(availableTraceTypes
, 0, traceTypeList
, 1, availableTraceTypes
.length
);
874 combo
.setItems(traceTypeList
);
876 for (int i
= 1; i
< traceTypeList
.length
; i
++) {
877 String traceType
= traceTypeList
[i
];
878 String traceTypeId
= TmfTraceType
.getTraceTypeId(traceType
);
879 if (traceTypeId
.equals(element
.getTraceType())) {
884 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
885 combo
.setLayoutData(gd
);
886 combo
.addSelectionListener(new SelectionAdapter() {
888 public void widgetSelected(SelectionEvent e
) {
889 if (combo
.getSelectionIndex() == 0) {
890 element
.setTraceType(null);
892 String traceType
= combo
.getText();
893 String traceTypeId
= TmfTraceType
.getTraceTypeId(traceType
);
894 element
.setTraceType(traceTypeId
);
905 private RemoteImportProfileElement
newProfile(TracePackageElement previous
) {
906 RemoteImportProfileElement profile
= new RemoteImportProfileElement(null, RemoteMessages
.RemoteProfilesPreferencePage_DefaultProfileName
);
907 RemoteImportConnectionNodeElement node
= new RemoteImportConnectionNodeElement(profile
, RemoteMessages
.RemoteProfilesPreferencePage_DefaultConnectionNodeName
, RemoteMessages
.RemoteProfilesPreferencePage_DefaultConnectionNodeURI
);
908 RemoteImportTraceGroupElement traceGroup
= new RemoteImportTraceGroupElement(node
, DEFAULT_ROOT_IMPORT_PATH
);
909 TracePackageTraceElement trace
= new TracePackageTraceElement(traceGroup
, DEFAULT_IMPORT_NAME
, null);
910 new TracePackageFilesElement(trace
, DEFAULT_FILE_PATTERN
);
911 int index
= previous
== null ? fProfiles
.size() : fProfiles
.indexOf(previous
) + 1;
912 fProfiles
.add(index
, profile
);
913 newElementAdded(profile
);
917 private RemoteImportConnectionNodeElement
newConnectionNode(TracePackageElement parent
, TracePackageElement previous
) {
918 RemoteImportConnectionNodeElement node
= new RemoteImportConnectionNodeElement(null, RemoteMessages
.RemoteProfilesPreferencePage_DefaultConnectionNodeName
, RemoteMessages
.RemoteProfilesPreferencePage_DefaultConnectionNodeURI
);
919 RemoteImportTraceGroupElement traceGroup
= new RemoteImportTraceGroupElement(node
, DEFAULT_ROOT_IMPORT_PATH
);
920 TracePackageTraceElement trace
= new TracePackageTraceElement(traceGroup
, DEFAULT_IMPORT_NAME
, null);
921 new TracePackageFilesElement(trace
, DEFAULT_FILE_PATTERN
);
922 int index
= previous
== null ? parent
.getChildren().length
: parent
.indexOf(previous
) + 1;
923 parent
.addChild(index
, node
);
924 newElementAdded(node
);
928 private RemoteImportTraceGroupElement
newTraceGroup(TracePackageElement parent
, TracePackageElement previous
) {
929 RemoteImportTraceGroupElement traceGroup
= new RemoteImportTraceGroupElement(null, DEFAULT_ROOT_IMPORT_PATH
);
930 TracePackageTraceElement trace
= new TracePackageTraceElement(traceGroup
, DEFAULT_IMPORT_NAME
, null);
931 new TracePackageFilesElement(trace
, DEFAULT_FILE_PATTERN
);
932 int index
= previous
== null ? parent
.getChildren().length
: parent
.indexOf(previous
) + 1;
933 parent
.addChild(index
, traceGroup
);
934 newElementAdded(traceGroup
);
938 private TracePackageTraceElement
newTrace(TracePackageElement parent
, TracePackageElement previous
) {
939 TracePackageTraceElement trace
= new TracePackageTraceElement(null, DEFAULT_IMPORT_NAME
, null);
940 new TracePackageFilesElement(trace
, DEFAULT_FILE_PATTERN
);
941 int index
= previous
== null ? parent
.getChildren().length
: parent
.indexOf(previous
) + 1;
942 parent
.addChild(index
, trace
);
943 newElementAdded(trace
);
947 private void newElementAdded(TracePackageElement element
) {
948 if (element
.getParent() != null) {
949 fTreeViewer
.refresh(element
.getParent());
951 fTreeViewer
.refresh();
953 fTreeViewer
.expandToLevel(element
, AbstractTreeViewer
.ALL_LEVELS
);
954 fTreeViewer
.setSelection(new StructuredSelection(element
));
958 private void removeElement(Object item
) {
959 if (item
instanceof RemoteImportProfileElement
) {
960 fProfiles
.remove(item
);
961 fTreeViewer
.refresh();
963 } else if (item
instanceof TracePackageElement
) {
964 TracePackageElement element
= (TracePackageElement
) item
;
965 TracePackageElement parent
= element
.getParent();
966 parent
.removeChild(element
);
967 fTreeViewer
.refresh(parent
);
972 private TracePackageElement
copyElement(TracePackageElement parent
, TracePackageElement element
) {
973 TracePackageElement copy
= null;
974 if (element
instanceof RemoteImportProfileElement
) {
975 RemoteImportProfileElement source
= (RemoteImportProfileElement
) element
;
976 copy
= new RemoteImportProfileElement(parent
, source
.getProfileName());
977 } else if (element
instanceof RemoteImportConnectionNodeElement
) {
978 RemoteImportConnectionNodeElement source
= (RemoteImportConnectionNodeElement
) element
;
979 copy
= new RemoteImportConnectionNodeElement(parent
, source
.getName(), source
.getURI());
980 } else if (element
instanceof RemoteImportTraceGroupElement
) {
981 RemoteImportTraceGroupElement source
= (RemoteImportTraceGroupElement
) element
;
982 copy
= new RemoteImportTraceGroupElement(parent
, source
.getRootImportPath());
983 ((RemoteImportTraceGroupElement
) copy
).setRecursive(source
.isRecursive());
984 } else if (element
instanceof TracePackageTraceElement
) {
985 TracePackageTraceElement source
= (TracePackageTraceElement
) element
;
986 copy
= new TracePackageTraceElement(parent
, source
.getImportName(), source
.getTraceType());
987 } else if (element
instanceof TracePackageFilesElement
) {
988 TracePackageFilesElement source
= (TracePackageFilesElement
) element
;
989 copy
= new TracePackageFilesElement(parent
, source
.getFileName());
991 for (TracePackageElement child
: element
.getChildren()) {
992 copyElement(copy
, child
);
997 private static boolean validatePaste(Object target
) {
998 IStructuredSelection data
= getClipboardContents();
999 if (data
== null || data
.isEmpty()) {
1002 for (Object item
: data
.toArray()) {
1003 if (item
instanceof RemoteImportConnectionNodeElement
) {
1004 if (!(target
instanceof RemoteImportConnectionNodeElement
||
1005 target
instanceof RemoteImportProfileElement
)) {
1008 } else if (item
instanceof RemoteImportTraceGroupElement
) {
1009 if (!(target
instanceof RemoteImportTraceGroupElement
||
1010 target
instanceof RemoteImportConnectionNodeElement
)) {
1013 } else if (item
instanceof TracePackageTraceElement
) {
1014 if (!(target
instanceof TracePackageTraceElement
||
1015 target
instanceof RemoteImportTraceGroupElement
)) {
1018 } else if (item
instanceof RemoteImportProfileElement
) {
1019 if (!(target
instanceof RemoteImportProfileElement
||
1030 private static void setClipboardContents(IStructuredSelection data
) {
1031 LocalSelectionTransfer transfer
= LocalSelectionTransfer
.getTransfer();
1032 transfer
.setSelection(data
);
1033 Clipboard clipboard
= new Clipboard(PlatformUI
.getWorkbench().getDisplay());
1034 clipboard
.setContents(new Object
[] { new Object() }, new Transfer
[] { transfer
});
1035 clipboard
.dispose();
1038 private static IStructuredSelection
getClipboardContents() {
1039 Clipboard clipboard
= new Clipboard(PlatformUI
.getWorkbench().getDisplay());
1040 IStructuredSelection data
= (IStructuredSelection
) clipboard
.getContents(LocalSelectionTransfer
.getTransfer());
1041 clipboard
.dispose();
1045 private void validate() {
1047 Set
<String
> profileNames
= new HashSet
<>();
1048 for (RemoteImportProfileElement profile
: fProfiles
) {
1049 if (profile
.getProfileName().length() == 0) {
1050 setErrorMessage(RemoteMessages
.RemoteProfilesPreferencePage_EmptyProfileNameError
);
1053 String prefix
= profile
.getProfileName() + ": "; //$NON-NLS-1$
1054 if (!profileNames
.add(profile
.getProfileName())) {
1055 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_DuplicateProfileNameError
);
1058 Set
<String
> nodeNames
= new HashSet
<>();
1060 for (TracePackageElement profileChild
: profile
.getChildren()) {
1061 if (profileChild
instanceof RemoteImportConnectionNodeElement
) {
1063 RemoteImportConnectionNodeElement node
= (RemoteImportConnectionNodeElement
) profileChild
;
1064 if (node
.getName().length() == 0) {
1065 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_EmptyNodeNameError
);
1068 // validate node name against the OS since the name will be used as folder name at the destination
1069 if (!ResourcesPlugin
.getWorkspace().validateName(node
.getName(), IResource
.FOLDER
).isOK()) {
1070 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_InvalidNodeName
);
1073 if (!nodeNames
.add(node
.getName())) {
1074 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_DuplicateConnectionNodeNameError
);
1078 if (node
.getURI().length() == 0) {
1079 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_EmptyNodeURIError
);
1083 URI uri
= URIUtil
.fromString(node
.getURI());
1084 IRemoteServicesManager manager
= TmfRemoteConnectionFactory
.getService(IRemoteServicesManager
.class);
1085 if (manager
== null || manager
.getConnectionType(uri
) == null) {
1086 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_UnsupportedURISchemeError
);
1089 if (uri
.getScheme().equals(SSH_SCHEME
)) {
1090 if (uri
.getHost() == null) {
1091 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_InvalidHostOrPortError
);
1094 if (uri
.getUserInfo() == null) {
1095 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_MissingUserInfoError
);
1099 } catch (URISyntaxException e
) {
1100 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_InvalidNodeURIError
);
1103 int traceGroupCount
= 0;
1104 for (TracePackageElement nodeChild
: node
.getChildren()) {
1105 if (nodeChild
instanceof RemoteImportTraceGroupElement
) {
1107 RemoteImportTraceGroupElement traceGroup
= (RemoteImportTraceGroupElement
) nodeChild
;
1108 if (traceGroup
.getRootImportPath().length() == 0) {
1109 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_EmptyRootPathError
);
1113 for (TracePackageElement traceGroupChild
: traceGroup
.getChildren()) {
1114 if (traceGroupChild
instanceof TracePackageTraceElement
) {
1116 TracePackageTraceElement trace
= (TracePackageTraceElement
) traceGroupChild
;
1118 for (TracePackageElement traceChild
: trace
.getChildren()) {
1119 if (traceChild
instanceof TracePackageFilesElement
) {
1120 TracePackageFilesElement files
= (TracePackageFilesElement
) traceChild
;
1121 if (files
.getFileName().length() == 0) {
1122 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_EmptyFilePatternError
);
1126 Pattern
.compile(files
.getFileName());
1127 } catch (PatternSyntaxException e
) {
1128 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_InvalidFilePatternError
);
1135 if (traceCount
== 0) {
1136 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_MissingTraceError
);
1141 if (traceGroupCount
== 0) {
1142 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_MissingTraceGroupError
);
1147 if (nodeCount
== 0) {
1148 setErrorMessage(prefix
+ RemoteMessages
.RemoteProfilesPreferencePage_MissingConnectionNodeError
);
1153 setErrorMessage(null);
1157 public boolean performOk() {
1158 return writeProfiles(fProfiles
, PROFILE_FILE_PATH
);
1162 * Set the selected profile name
1164 * @param profileName the selected profile name
1166 public void setSelectedProfile(String profileName
) {
1167 fSelectedProfileName
= profileName
;
1168 if (fTreeViewer
!= null && !fTreeViewer
.getTree().isDisposed()) {
1169 for (RemoteImportProfileElement profile
: fProfiles
) {
1170 if (profile
.getProfileName().equals(profileName
)) {
1171 fTreeViewer
.setSelection(new StructuredSelection(profile
));
1178 * Return the selected profile name
1180 * @return the selected profile name or null
1182 public String
getSelectedProfile() {
1183 return fSelectedProfileName
;