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