18 package com.nokia.cdt.internal.debug.launch.newwizard; |
18 package com.nokia.cdt.internal.debug.launch.newwizard; |
19 |
19 |
20 import java.io.File; |
20 import java.io.File; |
21 import java.text.MessageFormat; |
21 import java.text.MessageFormat; |
22 import java.util.ArrayList; |
22 import java.util.ArrayList; |
23 import java.util.Iterator; |
|
24 import java.util.LinkedHashSet; |
23 import java.util.LinkedHashSet; |
25 import java.util.List; |
24 import java.util.List; |
26 import java.util.Set; |
25 import java.util.Set; |
27 |
26 |
28 import org.eclipse.cdt.core.model.CoreModel; |
27 import org.eclipse.cdt.core.model.CoreModel; |
92 private Text sisEdit; |
91 private Text sisEdit; |
93 private Button sisBrowse; |
92 private Button sisBrowse; |
94 private Composite installPackageUI; |
93 private Composite installPackageUI; |
95 |
94 |
96 private List<IPath> remotePathEntries = new ArrayList<IPath>(); |
95 private List<IPath> remotePathEntries = new ArrayList<IPath>(); |
|
96 private ArrayList<IPath> projectGeneratedRemotePaths; |
97 |
97 |
98 protected DebugRunProcessDialog(Shell shell, LaunchWizardData data) { |
98 protected DebugRunProcessDialog(Shell shell, LaunchWizardData data) { |
99 super(shell, data); |
99 super(shell, data); |
100 } |
100 } |
101 |
101 |
144 if(remoteProgramViewer != null) { |
144 if(remoteProgramViewer != null) { |
145 IPath currentPath = PathUtils.createPath(remoteProgramViewer.getCombo().getText().trim()); |
145 IPath currentPath = PathUtils.createPath(remoteProgramViewer.getCombo().getText().trim()); |
146 remotePathEntries.remove(currentPath); |
146 remotePathEntries.remove(currentPath); |
147 remotePathEntries.add(0, currentPath); // MRU |
147 remotePathEntries.add(0, currentPath); // MRU |
148 } |
148 } |
149 |
149 |
|
150 // make a set, removing user dupes, and also removing the entries we added |
150 Set<IPath> uniqueRemotePathEntries = new LinkedHashSet<IPath>(remotePathEntries); |
151 Set<IPath> uniqueRemotePathEntries = new LinkedHashSet<IPath>(remotePathEntries); |
151 |
152 if (projectGeneratedRemotePaths != null) |
152 for (Iterator<IPath> iter = uniqueRemotePathEntries.iterator(); iter.hasNext(); ) { |
153 uniqueRemotePathEntries.removeAll(projectGeneratedRemotePaths); |
153 IPath path = iter.next(); |
|
154 if (path.isEmpty() || getHostFileForRemoteLocation(path) != null) |
|
155 iter.remove(); |
|
156 } |
|
157 |
154 |
158 // truncate size, removing from end |
155 // truncate size, removing from end |
159 List<IPath> mruPathEntries = new ArrayList<IPath>(uniqueRemotePathEntries); |
156 List<IPath> mruPathEntries = new ArrayList<IPath>(uniqueRemotePathEntries); |
160 while (mruPathEntries.size() > 10) { |
157 while (mruPathEntries.size() > 10) { |
161 mruPathEntries.remove(mruPathEntries.size() - 1); |
158 mruPathEntries.remove(mruPathEntries.size() - 1); |
443 // selection is already a remote path; map back to project if possible |
440 // selection is already a remote path; map back to project if possible |
444 IPath projPath = getHostFileForRemoteLocation(exeSelectionPath); |
441 IPath projPath = getHostFileForRemoteLocation(exeSelectionPath); |
445 if (projPath != null) { |
442 if (projPath != null) { |
446 exeSelectionPath = projPath; |
443 exeSelectionPath = projPath; |
447 } |
444 } |
|
445 else { |
|
446 // remote path does not correspond to anything; select some project exe so |
|
447 // the combo isn't empty |
|
448 exeSelectionPath = exes.get(0); |
|
449 } |
448 } |
450 } |
449 projectExecutableViewer.setSelection(new StructuredSelection(exeSelectionPath)); |
451 projectExecutableViewer.setSelection(new StructuredSelection(exeSelectionPath)); |
450 |
452 |
451 if (remoteProgramViewer != null) { |
453 if (remoteProgramViewer != null) { |
452 if (!remotePathEntries.contains(remotePath)) { |
454 if (!remotePathEntries.contains(remotePath)) { |
487 * @param path |
489 * @param path |
488 * @return host path or <code>null</code> |
490 * @return host path or <code>null</code> |
489 */ |
491 */ |
490 private IPath getHostFileForRemoteLocation(IPath path) { |
492 private IPath getHostFileForRemoteLocation(IPath path) { |
491 for (IPath exe : data.getExes()) { |
493 for (IPath exe : data.getExes()) { |
492 IPath remoteSuggested = createSuggestedRemotePath(exe); |
494 // no... we don't have any knowledge (yet) of the actual install path, |
493 if (remoteSuggested.equals(path)) { |
495 // so comparing the exact path will fail if the user edited it. |
|
496 // IPath remoteSuggested = createSuggestedRemotePath(exe); |
|
497 |
|
498 // be pretty loose in the matching for now |
|
499 if (exe.lastSegment().equalsIgnoreCase(path.lastSegment())) { |
494 return exe; |
500 return exe; |
495 } |
501 } |
496 } |
502 } |
497 return null; |
503 return null; |
498 } |
504 } |
535 projectExecutableViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
541 projectExecutableViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
536 |
542 |
537 public void selectionChanged(SelectionChangedEvent event) { |
543 public void selectionChanged(SelectionChangedEvent event) { |
538 Object sel = ((IStructuredSelection) event.getSelection()).getFirstElement(); |
544 Object sel = ((IStructuredSelection) event.getSelection()).getFirstElement(); |
539 if (sel instanceof IPath) { |
545 if (sel instanceof IPath) { |
540 data.setExeSelectionPath((IPath) sel); |
546 if (projectExecutableRadioButton.getSelection()) { |
|
547 data.setExeSelectionPath((IPath) sel); |
|
548 } |
541 |
549 |
542 // track the default remote program from the executable, for easy editing |
550 // track the default remote program from the executable, for easy editing |
543 if (remoteProgramViewer != null) { |
551 if (remoteProgramViewer != null && !remoteExecutableRadioButton.getSelection()) { |
544 IPath exeSelectionPath = createSuggestedRemotePath(data.getExeSelectionPath()); |
552 IPath exeSelectionPath = createSuggestedRemotePath(data.getExeSelectionPath()); |
545 // path should already be in model |
553 // path should already be in model |
546 remoteProgramViewer.setSelection(new StructuredSelection(exeSelectionPath)); |
554 remoteProgramViewer.setSelection(new StructuredSelection(exeSelectionPath)); |
547 } |
555 } |
548 |
556 |
580 remoteExecutableRadioButton.setToolTipText(Messages.getString("DebugRunProcessDialog.LaunchRemoteProgramRadioTooltip")); //$NON-NLS-1$ |
588 remoteExecutableRadioButton.setToolTipText(Messages.getString("DebugRunProcessDialog.LaunchRemoteProgramRadioTooltip")); //$NON-NLS-1$ |
581 |
589 |
582 remoteProgramViewer = new ComboViewer(radioGroup, SWT.BORDER); |
590 remoteProgramViewer = new ComboViewer(radioGroup, SWT.BORDER); |
583 GridDataFactory.fillDefaults().grab(true, false).applyTo(remoteProgramViewer.getControl()); |
591 GridDataFactory.fillDefaults().grab(true, false).applyTo(remoteProgramViewer.getControl()); |
584 |
592 |
|
593 projectGeneratedRemotePaths = new ArrayList<IPath>(); |
|
594 for (IPath launchable : data.getLaunchableExes()) { |
|
595 projectGeneratedRemotePaths.add(createSuggestedRemotePath(launchable)); |
|
596 } |
|
597 |
585 // add the entries before the user MRU entries |
598 // add the entries before the user MRU entries |
586 int addIdx = 0; |
599 remotePathEntries.addAll(0, projectGeneratedRemotePaths); |
587 for (IPath launchable : data.getLaunchableExes()) { |
|
588 remotePathEntries.add(addIdx++, createSuggestedRemotePath(launchable)); |
|
589 } |
|
590 |
600 |
591 remoteProgramViewer.setContentProvider(new ArrayContentProvider()); |
601 remoteProgramViewer.setContentProvider(new ArrayContentProvider()); |
592 remoteProgramViewer.setLabelProvider(new LabelProvider() { |
602 remoteProgramViewer.setLabelProvider(new LabelProvider() { |
593 @Override |
603 @Override |
594 public String getText(Object element) { |
604 public String getText(Object element) { |
613 }); |
623 }); |
614 |
624 |
615 remoteProgramViewer.getCombo().addModifyListener(new ModifyListener() { |
625 remoteProgramViewer.getCombo().addModifyListener(new ModifyListener() { |
616 public void modifyText(ModifyEvent e) { |
626 public void modifyText(ModifyEvent e) { |
617 IPath path = PathUtils.createPath(remoteProgramViewer.getCombo().getText().trim()); |
627 IPath path = PathUtils.createPath(remoteProgramViewer.getCombo().getText().trim()); |
618 data.setExeSelectionPath(path); |
628 if (remoteExecutableRadioButton.getSelection()) { |
|
629 data.setExeSelectionPath(path); |
|
630 } |
|
631 |
|
632 if (!projectExecutableRadioButton.getSelection()) { |
|
633 IPath projPath = getHostFileForRemoteLocation(path); |
|
634 if (projPath != null) { |
|
635 projectExecutableViewer.setSelection(new StructuredSelection(projPath)); |
|
636 } |
|
637 } |
|
638 |
619 validate(); |
639 validate(); |
620 } |
640 } |
621 }); |
641 }); |
622 |
642 |
623 remoteProgramViewer.getCombo().addFocusListener(new FocusAdapter() { |
643 remoteProgramViewer.getCombo().addFocusListener(new FocusAdapter() { |