Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Tarassov2013-03-09 19:23:06 +0000
committerEugene Tarassov2013-03-09 19:23:06 +0000
commit560b6c1f33f035667c21940903ef17806c126173 (patch)
tree73a7aff5379fabf93d7daff4523fcd2b0ab7347f /plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse
parentd7b4a384b0a241fc473f7e58e12fcc2920b4bc33 (diff)
downloadorg.eclipse.tcf-560b6c1f33f035667c21940903ef17806c126173.tar.gz
org.eclipse.tcf-560b6c1f33f035667c21940903ef17806c126173.tar.xz
org.eclipse.tcf-560b6c1f33f035667c21940903ef17806c126173.zip
TCF Debugger: re-designed TCF launch configuration dialog:
1. The Target page is now first page in the dialog - target should be selected before other configuration steps. 2. New page added: Download. The page allows to download ELF files to the target during launch. 3. The Main page renamed to Application. 4. Implementation of context, process and remote file selection dialogs and controls is moved from o.e.tcf.cdt.ui to o.e.tcf.debug.ui, because it has no CDT dependencies.
Diffstat (limited to 'plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse')
-rw-r--r--plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/launch/ContextSelection.java25
-rw-r--r--plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/launch/TCFCDTLaunchDelegate.java3
-rw-r--r--plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/disassembly/TCFDisassemblyBackend.java2
-rw-r--r--plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/FileSystemBrowserControl.java515
-rw-r--r--plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/PeerListControl.java639
-rw-r--r--plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/ProcessListControl.java505
-rw-r--r--plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/ProcessPrompter.java16
-rw-r--r--plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/ProcessSelectionDialog.java120
-rw-r--r--plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/RemoteCMainTab.java18
-rw-r--r--plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/RemoteFileSelectionDialog.java170
10 files changed, 18 insertions, 1995 deletions
diff --git a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/launch/ContextSelection.java b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/launch/ContextSelection.java
deleted file mode 100644
index 0cc2b0644..000000000
--- a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/launch/ContextSelection.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Wind River Systems, Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.internal.cdt.launch;
-
-public class ContextSelection {
- public String fPeerId;
- public String fContextId;
- public boolean fIsAttached;
- public ContextSelection(String peerId, String contextId) {
- this(peerId, contextId, true);
- }
- public ContextSelection(String peerId, String contextId, boolean isAttached) {
- fPeerId = peerId;
- fContextId = contextId;
- fIsAttached = isAttached;
- }
-}
diff --git a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/launch/TCFCDTLaunchDelegate.java b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/launch/TCFCDTLaunchDelegate.java
index f15b68f35..4c254cf5b 100644
--- a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/launch/TCFCDTLaunchDelegate.java
+++ b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/launch/TCFCDTLaunchDelegate.java
@@ -22,6 +22,7 @@ import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.IStatusHandler;
import org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate;
import org.eclipse.tcf.internal.debug.model.TCFLaunch;
+import org.eclipse.tcf.internal.debug.ui.launch.ContextSelection;
import org.eclipse.tcf.util.TCFTask;
/**
@@ -90,7 +91,7 @@ public class TCFCDTLaunchDelegate extends TCFLaunchDelegate {
if (prompter != null) {
Object result = prompter.handleStatus(contextPrompt, config);
if (result instanceof ContextSelection) {
- return (ContextSelection) result;
+ return (ContextSelection)result;
}
}
return null;
diff --git a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/disassembly/TCFDisassemblyBackend.java b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/disassembly/TCFDisassemblyBackend.java
index 51068758a..37df306f7 100644
--- a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/disassembly/TCFDisassemblyBackend.java
+++ b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/disassembly/TCFDisassemblyBackend.java
@@ -266,7 +266,7 @@ public class TCFDisassemblyBackend extends AbstractDisassemblyBackend {
done = true;
/* Don't call setUpdatePending() if pending state was reset by the view */
if (context_cnt != fContextCount) return;
- assert fCallback.getUpdatePending();
+ if (!fCallback.getUpdatePending()) return;
fCallback.setUpdatePending(false);
}
}
diff --git a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/FileSystemBrowserControl.java b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/FileSystemBrowserControl.java
deleted file mode 100644
index e6ee9453a..000000000
--- a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/FileSystemBrowserControl.java
+++ /dev/null
@@ -1,515 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Wind River Systems, Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.internal.cdt.ui.launch;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.core.runtime.Path;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.tcf.protocol.IChannel;
-import org.eclipse.tcf.protocol.IChannel.IChannelListener;
-import org.eclipse.tcf.protocol.IPeer;
-import org.eclipse.tcf.protocol.IToken;
-import org.eclipse.tcf.protocol.Protocol;
-import org.eclipse.tcf.services.IFileSystem;
-import org.eclipse.tcf.services.IFileSystem.DirEntry;
-import org.eclipse.tcf.services.IFileSystem.FileSystemException;
-import org.eclipse.tcf.services.IFileSystem.IFileHandle;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.PlatformUI;
-
-public class FileSystemBrowserControl {
-
- static class FileInfo {
- String name;
- String fullname;
- boolean isDir;
- FileInfo[] children;
- Throwable children_error;
- int index;
- boolean children_pending;
- FileInfo parent;
- }
-
- private Tree fileTree;
- private Display fDisplay;
- private IPeer fPeer;
- private final FileInfo fRootInfo = new FileInfo();
- private IChannel fChannel;
- private IFileSystem fFileSystem;
- private String fFileToSelect;
- private LinkedList<String> fPathToSelect;
- private FileInfo fLastSelectedFileInfo;
- private final boolean fDirectoriesOnly;
-
- public FileSystemBrowserControl(Composite parent, boolean directoriesOnly) {
- fDirectoriesOnly = directoriesOnly;
- fDisplay = parent.getDisplay();
- parent.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- handleDispose();
- }
- });
- createFileListArea(parent);
- }
-
- public void setInput(IPeer peer) {
- if (peer == fPeer) {
- return;
- }
- if (fPeer != null) {
- Protocol.invokeAndWait(new Runnable() {
- public void run() {
- disconnectPeer();
- }
- });
- }
- fileTree.setItemCount(0);
- fRootInfo.children = null;
- fPeer = peer;
- if (fPeer != null) {
- Protocol.invokeAndWait(new Runnable() {
- public void run() {
- connectPeer();
- }
- });
- }
- }
-
- public Tree getTree() {
- return fileTree;
- }
-
- private void createFileListArea(Composite parent) {
- Font font = parent.getFont();
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setFont(font);
- GridLayout layout = new GridLayout(1, false);
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- composite.setLayout(layout);
- composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
-
- fileTree = new Tree(composite, SWT.VIRTUAL | SWT.BORDER | SWT.SINGLE);
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.minimumHeight = 300;
- gd.minimumWidth = 350;
- fileTree.setLayoutData(gd);
- fileTree.setFont(font);
- fileTree.addListener(SWT.SetData, new Listener() {
- public void handleEvent(Event event) {
- TreeItem item = (TreeItem)event.item;
- FileInfo info = findFileInfo(item);
- if (info == null) {
- updateItems(item.getParentItem(), false);
- }
- else {
- fillItem(item, info);
- }
- }
- });
- }
-
- private void handleDispose() {
- Protocol.invokeAndWait(new Runnable() {
- public void run() {
- disconnectPeer();
- fFileSystem = null;
- fDisplay = null;
- }
- });
- }
-
- protected void disconnectPeer() {
- if (fChannel != null && fChannel.getState() != IChannel.STATE_CLOSED) {
- fChannel.close();
- }
- }
-
- protected void connectPeer() {
- final IChannel channel = fPeer.openChannel();
- fChannel = channel;
- fFileSystem = null;
- channel.addChannelListener(new IChannelListener() {
- public void congestionLevel(int level) {
- }
- public void onChannelClosed(final Throwable error) {
- if (fChannel != channel) return;
- fChannel = null;
- if (fDisplay != null) {
- fDisplay.asyncExec(new Runnable() {
- public void run() {
- if (fRootInfo.children_pending) return;
- fRootInfo.children = null;
- fRootInfo.children_error = error;
- updateItems(fRootInfo);
- }
- });
- }
- }
- public void onChannelOpened() {
- if (fChannel != channel) return;
- fFileSystem = fChannel.getRemoteService(IFileSystem.class);
- if (fFileSystem != null) {
- if (fFileToSelect != null && fFileToSelect.length() > 0) {
- final LinkedList<String> filePath = new LinkedList<String>();
- filePath.addAll(Arrays.asList(fFileToSelect.split("[/\\\\]", -1)));
- if (fFileToSelect.charAt(0) == '/') {
- filePath.set(0, "/");
- }
- fPathToSelect = filePath;
- fLastSelectedFileInfo = fRootInfo;
- }
- }
- if (fDisplay != null) {
- fDisplay.asyncExec(new Runnable() {
- public void run() {
- if (fRootInfo.children_pending) return;
- fRootInfo.children = null;
- fRootInfo.children_error = null;
- updateItems(fRootInfo);
- }
- });
- }
- }
- });
- }
-
- private void updateItems(TreeItem parent_item, boolean reload) {
- final FileInfo parent_info = findFileInfo(parent_item);
- if (parent_info == null) {
- parent_item.setText("Invalid");
- }
- else {
- if (reload && parent_info.children_error != null) {
- loadChildren(parent_info);
- }
- fDisplay.asyncExec(new Runnable() {
- public void run() {
- updateItems(parent_info);
- }
- });
- }
- }
-
- private void updateItems(final FileInfo parent) {
- if (fDisplay == null) return;
- assert Thread.currentThread() == fDisplay.getThread();
- TreeItem[] items = null;
- boolean expanded = true;
- if (parent.children == null || parent.children_error != null) {
- if (parent == fRootInfo) {
- fileTree.setItemCount(1);
- items = fileTree.getItems();
- }
- else {
- TreeItem item = findItem(parent);
- if (item == null) return;
- expanded = item.getExpanded();
- item.setItemCount(1);
- items = item.getItems();
- }
- assert items.length == 1;
- items[0].removeAll();
- if (parent.children_pending) {
- items[0].setForeground(fDisplay.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
- items[0].setText("Pending...");
- }
- else if (parent.children_error != null) {
- String msg = parent.children_error.getMessage();
- if (msg == null) msg = parent.children_error.getClass().getName();
- else msg = msg.replace('\n', ' ');
- items[0].setForeground(fDisplay.getSystemColor(SWT.COLOR_RED));
- items[0].setText(msg);
- items[0].setImage((Image) null);
- }
- else if (expanded) {
- loadChildren(parent);
- items[0].setForeground(fDisplay.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
- items[0].setText("Pending...");
- }
- else {
- items[0].setText("");
- }
- }
- else {
- FileInfo[] arr = parent.children;
- if (parent == fRootInfo) {
- fileTree.setItemCount(arr.length);
- items = fileTree.getItems();
- }
- else {
- TreeItem item = findItem(parent);
- if (item == null) return;
- expanded = item.getExpanded();
- item.setItemCount(expanded ? arr.length : 1);
- items = item.getItems();
- }
- if (expanded) {
- assert items.length == arr.length;
- for (int i = 0; i < items.length; i++) fillItem(items[i], arr[i]);
- expandSelect();
- }
- else {
- items[0].setText("");
- }
- }
- }
-
- private void expandSelect() {
- if (fPathToSelect == null) return;
- if (fPathToSelect.isEmpty()) {
- fPathToSelect = null;
- fFileToSelect = null;
- return;
- }
- do {
- String name = fPathToSelect.getFirst();
- if (name.length() == 0) {
- fPathToSelect.removeFirst();
- continue;
- }
- FileInfo info = findFileInfo(fLastSelectedFileInfo, name);
- if (info == null) break;
- TreeItem item = findItem(info);
- if (item == null) break;
- fPathToSelect.removeFirst();
- if (fPathToSelect.isEmpty()) {
- fileTree.setSelection(item);
- fileTree.showItem(item);
- } else {
- item.setExpanded(true);
- fileTree.showItem(item);
- }
- fLastSelectedFileInfo = info;
- } while (!fPathToSelect.isEmpty());
- }
-
- private void loadChildren(final FileInfo parent) {
- assert Thread.currentThread() == fDisplay.getThread();
- if (parent.children_pending) return;
- assert parent.children == null;
- parent.children_pending = true;
- parent.children_error = null;
- Protocol.invokeLater(new Runnable() {
- public void run() {
- final IFileSystem fs = fFileSystem;
- if (fs == null || !canHaveChildren(parent)) {
- doneLoadChildren(parent, null, new FileInfo[0]);
- return;
- }
- if (parent.fullname == null) {
- fs.roots(new IFileSystem.DoneRoots() {
- public void doneRoots(IToken token, FileSystemException error, DirEntry[] entries) {
- if (error != null) {
- doneLoadChildren(parent, error, null);
- } else {
- final List<FileInfo> fileInfos = new ArrayList<FileInfo>(entries.length);
- for (DirEntry entry : entries) {
- FileInfo info = new FileInfo();
- info.parent = parent;
- String name = entry.filename;
- int length = name.length();
- if (length > 1 && (name.endsWith("\\") || name.endsWith("/"))) {
- name = name.substring(0, length - 1);
- }
- info.name = name;
- info.fullname = entry.longname != null ? entry.longname : entry.filename;
- info.isDir = entry.attrs != null ? entry.attrs.isDirectory() : false;
- if (!fDirectoriesOnly || info.isDir) {
- fileInfos.add(info);
- }
- }
- doneLoadChildren(parent, null, fileInfos.toArray(new FileInfo[fileInfos.size()]));
- }
- }
- });
- return;
- }
- fs.opendir(parent.fullname, new IFileSystem.DoneOpen() {
- final List<FileInfo> fileInfos = new ArrayList<FileInfo>();
- public void doneOpen(IToken token, FileSystemException error, final IFileHandle handle) {
- if (error != null) {
- doneLoadChildren(parent, error, null);
- return;
- }
- fs.readdir(handle, new IFileSystem.DoneReadDir() {
- public void doneReadDir(IToken token, FileSystemException error, DirEntry[] entries, boolean eof) {
- if (entries != null) {
- for (DirEntry entry : entries) {
- FileInfo info = new FileInfo();
- info.parent = parent;
- info.name = entry.filename;
- info.fullname = entry.longname != null ? entry.longname : (new Path(parent.fullname).append(info.name).toString());
- info.isDir = entry.attrs != null ? entry.attrs.isDirectory() : false;
- if (!fDirectoriesOnly || info.isDir) {
- fileInfos.add(info);
- }
- }
- }
- if (error != null || eof) {
- fs.close(handle, new IFileSystem.DoneClose() {
- public void doneClose(IToken token, FileSystemException error) {
- // ignore error
- }
- });
- int size = fileInfos.size();
- if (size == 0 && error != null) {
- doneLoadChildren(parent, error, null);
- } else {
- doneLoadChildren(parent, null, fileInfos.toArray(new FileInfo[size]));
- }
- } else {
- fs.readdir(handle, this);
- }
- }
- });
- }
- });
- }
- });
- }
-
- private void doneLoadChildren(final FileInfo parent, final Throwable error, final FileInfo[] children) {
- assert Protocol.isDispatchThread();
- assert error == null || children == null;
- if (fDisplay == null) return;
- Arrays.sort(children, new Comparator<FileInfo>() {
- public int compare(FileInfo o1, FileInfo o2) {
- if (o1.isDir == o2.isDir)
- return o1.name.compareTo(o2.name);
- if (o1.isDir) return 1;
- return -1;
- }});
- int i = 0;
- for (FileInfo fileInfo : children) {
- fileInfo.index = i++;
- }
- fDisplay.asyncExec(new Runnable() {
- public void run() {
- assert parent.children_pending;
- assert parent.children == null;
- parent.children_pending = false;
- parent.children = children;
- parent.children_error = error;
- updateItems(parent);
- }
- });
- }
-
- public FileInfo findFileInfo(TreeItem item) {
- assert Thread.currentThread() == fDisplay.getThread();
- if (item == null) return fRootInfo ;
- TreeItem parent = item.getParentItem();
- FileInfo info = findFileInfo(parent);
- if (info == null) return null;
- if (info.children == null) return null;
- if (info.children_error != null) return null;
- int i = parent == null ? fileTree.indexOf(item) : parent.indexOf(item);
- if (i < 0 || i >= info.children.length) return null;
- assert info.children[i].index == i;
- return info.children[i];
- }
-
- private FileInfo findFileInfo(FileInfo parent, String name) {
- assert Thread.currentThread() == fDisplay.getThread();
- if (name == null) return fRootInfo;
- if (name.equals(parent.name)) return parent;
- FileInfo[] childInfos = parent.children;
- if (childInfos != null) {
- for (FileInfo fileInfo : childInfos) {
- FileInfo found = findFileInfo(fileInfo, name);
- if (found != null) {
- return found;
- }
- }
- }
- return null;
- }
-
- private TreeItem findItem(FileInfo info) {
- if (info == null) return null;
- assert info.parent != null;
- if (info.parent == fRootInfo) {
- int n = fileTree.getItemCount();
- if (info.index >= n) return null;
- return fileTree.getItem(info.index);
- }
- TreeItem i = findItem(info.parent);
- if (i == null) return null;
- int n = i.getItemCount();
- if (info.index >= n) return null;
- return i.getItem(info.index);
- }
-
- private void fillItem(TreeItem item, FileInfo info) {
- assert Thread.currentThread() == fDisplay.getThread();
- Object data = item.getData("TCFContextInfo");
- if (data != null && data != info) item.removeAll();
- item.setData("TCFContextInfo", info);
- String text = info.name != null ? info.name : info.fullname;
- item.setText(text);
- item.setForeground(fDisplay.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
- item.setImage(getImage(info));
- if (!canHaveChildren(info)) item.setItemCount(0);
- else if (info.children == null || info.children_error != null) item.setItemCount(1);
- else item.setItemCount(info.children.length);
- }
-
- private boolean canHaveChildren(FileInfo info) {
- return info.isDir || info == fRootInfo;
- }
-
- private Image getImage(FileInfo info) {
- if (info.isDir) {
- return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
- } else {
- return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
- }
- }
-
- public void setInitialSelection(final String filename) {
- fPathToSelect = null;
- Protocol.invokeLater(new Runnable() {
- public void run() {
- fFileToSelect = filename;
- }
- });
- }
-
- public FileInfo getSelection() {
- if (fileTree != null) {
- TreeItem[] items = fileTree.getSelection();
- if (items.length > 0) {
- FileInfo info = findFileInfo(items[0]);
- return info;
- }
- }
- return null;
- }
-
-}
diff --git a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/PeerListControl.java b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/PeerListControl.java
deleted file mode 100644
index 69174d524..000000000
--- a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/PeerListControl.java
+++ /dev/null
@@ -1,639 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Wind River Systems, Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.internal.cdt.ui.launch;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.runtime.ListenerList;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.TreeEvent;
-import org.eclipse.swt.events.TreeListener;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeColumn;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.tcf.internal.cdt.ui.Activator;
-import org.eclipse.tcf.internal.cdt.ui.ImageCache;
-import org.eclipse.tcf.protocol.IChannel;
-import org.eclipse.tcf.protocol.IChannel.IChannelListener;
-import org.eclipse.tcf.protocol.IPeer;
-import org.eclipse.tcf.protocol.Protocol;
-import org.eclipse.tcf.services.ILocator;
-
-// Cloned from TCFTargetTab
-public class PeerListControl implements ISelectionProvider {
-
- private Tree peer_tree;
- private final PeerInfo peer_info = new PeerInfo();
- private Display display;
- private final ListenerList fSelectionListeners = new ListenerList(ListenerList.IDENTITY);
- private String fInitialPeerId = "*";
-
- static class PeerInfo {
- PeerInfo parent;
- int index;
- String id;
- Map<String,String> attrs;
- PeerInfo[] children;
- boolean children_pending;
- Throwable children_error;
- IPeer peer;
- IChannel channel;
- ILocator locator;
- LocatorListener listener;
- }
-
- private class LocatorListener implements ILocator.LocatorListener {
-
- private final PeerInfo parent;
-
- LocatorListener(PeerInfo parent) {
- this.parent = parent;
- }
-
- public void peerAdded(final IPeer peer) {
- if (display == null) return;
- final String id = peer.getID();
- final HashMap<String,String> attrs = new HashMap<String,String>(peer.getAttributes());
- display.asyncExec(new Runnable() {
- public void run() {
- if (parent.children_error != null) return;
- PeerInfo[] arr = parent.children;
- String agentId = attrs.get(IPeer.ATTR_AGENT_ID);
- for (PeerInfo p : arr) {
- assert !p.id.equals(id);
- if (agentId != null && agentId.equals(p.attrs.get(IPeer.ATTR_AGENT_ID)))
- return;
- }
- PeerInfo[] buf = new PeerInfo[arr.length + 1];
- System.arraycopy(arr, 0, buf, 0, arr.length);
- PeerInfo info = new PeerInfo();
- info.parent = parent;
- info.index = arr.length;
- info.id = id;
- info.attrs = attrs;
- info.peer = peer;
- buf[arr.length] = info;
- parent.children = buf;
- updateItems(parent);
- }
- });
- }
-
- public void peerChanged(final IPeer peer) {
- if (display == null) return;
- final String id = peer.getID();
- final HashMap<String,String> attrs = new HashMap<String,String>(peer.getAttributes());
- display.asyncExec(new Runnable() {
- public void run() {
- if (parent.children_error != null) return;
- PeerInfo[] arr = parent.children;
- for (int i = 0; i < arr.length; i++) {
- if (arr[i].id.equals(id)) {
- arr[i].attrs = attrs;
- arr[i].peer = peer;
- updateItems(parent);
- }
- }
- }
- });
- }
-
- public void peerRemoved(final String id) {
- if (display == null) return;
- display.asyncExec(new Runnable() {
- public void run() {
- if (parent.children_error != null) return;
- PeerInfo[] arr = parent.children;
- PeerInfo[] buf = new PeerInfo[arr.length - 1];
- int j = 0;
- for (int i = 0; i < arr.length; i++) {
- if (arr[i].id.equals(id)) {
- final PeerInfo info = arr[i];
- Protocol.invokeLater(new Runnable() {
- public void run() {
- disconnectPeer(info);
- }
- });
- }
- else {
- arr[i].index = j;
- buf[j++] = arr[i];
- }
- }
- parent.children = buf;
- updateItems(parent);
- }
- });
- }
-
- public void peerHeartBeat(final String id) {
- if (display == null) return;
- display.asyncExec(new Runnable() {
- public void run() {
- if (parent.children_error != null) return;
- PeerInfo[] arr = parent.children;
- for (int i = 0; i < arr.length; i++) {
- if (arr[i].id.equals(id)) {
- if (arr[i].children_error != null) {
- TreeItem item = findItem(arr[i]);
- boolean visible = item != null;
- while (visible && item != null) {
- if (!item.getExpanded()) visible = false;
- item = item.getParentItem();
- }
- if (visible) loadChildren(arr[i]);
- }
- break;
- }
- }
- }
- });
- }
- }
-
- public PeerListControl(Composite parent) {
- display = parent.getDisplay();
- parent.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- handleDispose();
- }
- });
- loadChildren(peer_info);
- createPeerListArea(parent);
- }
-
- public void setInitialSelectedPeerId(String peerId) {
- fInitialPeerId = peerId;
- }
-
- public Tree getTree() {
- return peer_tree;
- }
-
- private void createPeerListArea(Composite parent) {
- Font font = parent.getFont();
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setFont(font);
- GridLayout layout = new GridLayout(1, false);
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- composite.setLayout(layout);
- composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
-
- peer_tree = new Tree(composite, SWT.VIRTUAL | SWT.BORDER | SWT.SINGLE);
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.heightHint = 80;
- gd.minimumWidth = 400;
- peer_tree.setLayoutData(gd);
-
- for (int i = 0; i < 5; i++) {
- TreeColumn column = new TreeColumn(peer_tree, SWT.LEAD, i);
- column.setMoveable(true);
- switch (i) {
- case 0:
- column.setText("Name");
- column.setWidth(160);
- break;
- case 1:
- column.setText("OS");
- column.setWidth(100);
- break;
- case 2:
- column.setText("Transport");
- column.setWidth(60);
- break;
- case 3:
- column.setText("Host");
- column.setWidth(100);
- break;
- case 4:
- column.setText("Port");
- column.setWidth(40);
- break;
- }
- }
-
- peer_tree.setHeaderVisible(true);
- peer_tree.setFont(font);
- peer_tree.addListener(SWT.SetData, new Listener() {
- public void handleEvent(Event event) {
- TreeItem item = (TreeItem)event.item;
- PeerInfo info = findPeerInfo(item);
- if (info == null) {
- updateItems(item.getParentItem(), false);
- }
- else {
- fillItem(item, info);
- }
- }
- });
- peer_tree.addTreeListener(new TreeListener() {
- public void treeCollapsed(TreeEvent e) {
- updateItems((TreeItem)e.item, false);
- }
- public void treeExpanded(TreeEvent e) {
- updateItems((TreeItem)e.item, true);
- }
- });
- peer_tree.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- fireSelectionChangedEvent();
- }
- });
- }
-
- private void handleDispose() {
- Protocol.invokeAndWait(new Runnable() {
- public void run() {
- disconnectPeer(peer_info);
- display = null;
- }
- });
- }
-
- private void disconnectPeer(final PeerInfo info) {
- assert Protocol.isDispatchThread();
- if (info.children != null) {
- for (PeerInfo p : info.children) disconnectPeer(p);
- }
- if (info.listener != null) {
- info.locator.removeListener(info.listener);
- info.listener = null;
- info.locator = null;
- }
- if (info.channel != null) {
- info.channel.close();
- }
- }
-
- private boolean canHaveChildren(PeerInfo parent) {
- return parent == peer_info || parent.attrs.get(IPeer.ATTR_PROXY) != null;
- }
-
- private void loadChildren(final PeerInfo parent) {
- assert Thread.currentThread() == display.getThread();
- if (parent.children_pending) return;
- assert parent.children == null;
- parent.children_pending = true;
- parent.children_error = null;
- Protocol.invokeAndWait(new Runnable() {
- public void run() {
- assert parent.listener == null;
- assert parent.channel == null;
- if (!canHaveChildren(parent)) {
- doneLoadChildren(parent, null, new PeerInfo[0]);
- }
- else if (parent == peer_info) {
- peer_info.locator = Protocol.getLocator();
- doneLoadChildren(parent, null, createLocatorListener(peer_info));
- }
- else {
- final IChannel channel = parent.peer.openChannel();
- parent.channel = channel;
- parent.channel.addChannelListener(new IChannelListener() {
- boolean opened = false;
- boolean closed = false;
- public void congestionLevel(int level) {
- }
- public void onChannelClosed(final Throwable error) {
- assert !closed;
- if (parent.channel != channel) return;
- if (!opened) {
- doneLoadChildren(parent, error, null);
- }
- else {
- if (display != null) {
- display.asyncExec(new Runnable() {
- public void run() {
- if (parent.children_pending) return;
- parent.children = null;
- parent.children_error = error;
- updateItems(parent);
- }
- });
- }
- }
- closed = true;
- parent.channel = null;
- parent.locator = null;
- parent.listener = null;
- }
- public void onChannelOpened() {
- assert !opened;
- assert !closed;
- if (parent.channel != channel) return;
- opened = true;
- parent.locator = parent.channel.getRemoteService(ILocator.class);
- if (parent.locator == null) {
- doneLoadChildren(parent, new Exception("Service not supported: " + ILocator.NAME), null);
- parent.channel.close();
- }
- else {
- doneLoadChildren(parent, null, createLocatorListener(parent));
- }
- }
- });
- }
- }
- });
- }
-
- private PeerInfo[] createLocatorListener(PeerInfo peer) {
- assert Protocol.isDispatchThread();
- Map<String,IPeer> map = peer.locator.getPeers();
- List<PeerInfo> filteredPeers = new ArrayList<PeerInfo>();
- Set<String> agentIds = new HashSet<String>();
- for (IPeer p : map.values()) {
- String agentID = p.getAgentID();
- if (agentID != null && agentIds.add(agentID)) {
- PeerInfo info = new PeerInfo();
- info.parent = peer;
- info.index = filteredPeers.size();
- info.id = p.getID();
- info.attrs = new HashMap<String,String>(p.getAttributes());
- info.peer = p;
- filteredPeers.add(info);
- }
- }
- PeerInfo[] buf = filteredPeers.toArray(new PeerInfo[filteredPeers.size()]);
- peer.listener = new LocatorListener(peer);
- peer.locator.addListener(peer.listener);
- return buf;
- }
-
- private void doneLoadChildren(final PeerInfo parent, final Throwable error, final PeerInfo[] children) {
- assert Protocol.isDispatchThread();
- assert error == null || children == null;
- if (display == null) return;
- display.asyncExec(new Runnable() {
- public void run() {
- assert parent.children_pending;
- assert parent.children == null;
- parent.children_pending = false;
- parent.children = children;
- parent.children_error = error;
- updateItems(parent);
- }
- });
- }
-
- private void updateItems(TreeItem parent_item, boolean reload) {
- final PeerInfo parent_info = findPeerInfo(parent_item);
- if (parent_info == null) {
- parent_item.setText("Invalid");
- }
- else {
- if (reload && parent_info.children_error != null) {
- loadChildren(parent_info);
- }
- display.asyncExec(new Runnable() {
- public void run() {
- updateItems(parent_info);
- }
- });
- }
- }
-
- private void updateItems(final PeerInfo parent) {
- if (display == null) return;
- assert Thread.currentThread() == display.getThread();
- TreeItem[] items = null;
- boolean expanded = true;
- if (parent.children == null || parent.children_error != null) {
- if (parent == peer_info) {
- peer_tree.setItemCount(1);
- items = peer_tree.getItems();
- }
- else {
- TreeItem item = findItem(parent);
- if (item == null) return;
- expanded = item.getExpanded();
- item.setItemCount(1);
- items = item.getItems();
- }
- assert items.length == 1;
- items[0].removeAll();
- if (parent.children_pending) {
- items[0].setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
- items[0].setText("Connecting...");
- }
- else if (parent.children_error != null) {
- String msg = parent.children_error.getMessage();
- if (msg == null) msg = parent.children_error.getClass().getName();
- else msg = msg.replace('\n', ' ');
- items[0].setForeground(display.getSystemColor(SWT.COLOR_RED));
- items[0].setText(msg);
- }
- else if (expanded) {
- loadChildren(parent);
- items[0].setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
- items[0].setText("Connecting...");
- }
- else {
- Protocol.invokeAndWait(new Runnable() {
- public void run() {
- disconnectPeer(parent);
- }
- });
- items[0].setText("");
- }
- int n = peer_tree.getColumnCount();
- for (int i = 1; i < n; i++) items[0].setText(i, "");
- items[0].setImage((Image)null);
- }
- else {
- PeerInfo[] arr = parent.children;
- if (parent == peer_info) {
- peer_tree.setItemCount(arr.length);
- items = peer_tree.getItems();
- }
- else {
- TreeItem item = findItem(parent);
- if (item == null) return;
- expanded = item.getExpanded();
- item.setItemCount(expanded ? arr.length : 1);
- items = item.getItems();
- }
- if (expanded) {
- assert items.length == arr.length;
- for (int i = 0; i < items.length; i++) fillItem(items[i], arr[i]);
- if (fInitialPeerId != null && items.length > 0) {
- if ("*".equals(fInitialPeerId)) {
- fInitialPeerId = null;
- peer_tree.setSelection(items[0]);
- fireSelectionChangedEvent();
- } else {
- int i = 0;
- for (PeerInfo peerInfo : arr) {
- if (fInitialPeerId.equals(peerInfo.id)) {
- fInitialPeerId = null;
- peer_tree.setSelection(items[i]);
- fireSelectionChangedEvent();
- break;
- }
- i++;
- }
- }
- }
- }
- else {
- Protocol.invokeAndWait(new Runnable() {
- public void run() {
- disconnectPeer(parent);
- }
- });
- items[0].setText("");
- int n = peer_tree.getColumnCount();
- for (int i = 1; i < n; i++) items[0].setText(i, "");
- }
- }
- }
-
- public PeerInfo findPeerInfo(String peerId) {
- return findPeerInfo(peer_info, peerId);
- }
-
- private PeerInfo findPeerInfo(PeerInfo parent, String peerId) {
- if (peerId.equals(parent.id)) return parent;
- PeerInfo[] children = parent.children;
- if (children == null) return null;
- for (PeerInfo child : children) {
- PeerInfo info = findPeerInfo(child, peerId);
- if (info != null) return info;
- }
- return null;
- }
-
- public PeerInfo findPeerInfo(TreeItem item) {
- assert Thread.currentThread() == display.getThread();
- if (item == null) return peer_info;
- TreeItem parent = item.getParentItem();
- PeerInfo info = findPeerInfo(parent);
- if (info == null) return null;
- if (info.children == null) return null;
- if (info.children_error != null) return null;
- int i = parent == null ? peer_tree.indexOf(item) : parent.indexOf(item);
- if (i < 0 || i >= info.children.length) return null;
- assert info.children[i].index == i;
- return info.children[i];
- }
-
- private TreeItem findItem(PeerInfo info) {
- if (info == null) return null;
- assert info.parent != null;
- if (info.parent == peer_info) {
- int n = peer_tree.getItemCount();
- if (info.index >= n) return null;
- return peer_tree.getItem(info.index);
- }
- TreeItem i = findItem(info.parent);
- if (i == null) return null;
- int n = i.getItemCount();
- if (info.index >= n) return null;
- return i.getItem(info.index);
- }
-
- private void fillItem(TreeItem item, PeerInfo info) {
- assert Thread.currentThread() == display.getThread();
- Object data = item.getData("TCFPeerInfo");
- if (data != null && data != info) item.removeAll();
- item.setData("TCFPeerInfo", info);
- String text[] = new String[5];
- text[0] = info.attrs.get(IPeer.ATTR_NAME);
- text[1] = info.attrs.get(IPeer.ATTR_OS_NAME);
- text[2] = info.attrs.get(IPeer.ATTR_TRANSPORT_NAME);
- text[3] = info.attrs.get(IPeer.ATTR_IP_HOST);
- text[4] = info.attrs.get(IPeer.ATTR_IP_PORT);
- for (int i = 0; i < text.length; i++) {
- if (text[i] == null) text[i] = "";
- }
- item.setText(text);
- item.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
- item.setImage(ImageCache.getImage(getImageName(info)));
- if (!canHaveChildren(info)) item.setItemCount(0);
- else if (info.children == null || info.children_error != null) item.setItemCount(1);
- else item.setItemCount(info.children.length);
- }
-
- private String getImageName(PeerInfo info) {
- return ImageCache.IMG_TARGET_TAB;
- }
-
- public void addSelectionChangedListener(ISelectionChangedListener listener) {
- fSelectionListeners .add(listener);
- }
-
- public ISelection getSelection() {
- TreeItem[] items = peer_tree.getSelection();
- PeerInfo[] peers = new PeerInfo[items.length];
- int i = 0;
- for (TreeItem item : items) {
- peers[i++] = findPeerInfo(item);
- }
- return new StructuredSelection(peers);
- }
-
- public void removeSelectionChangedListener(ISelectionChangedListener listener) {
- fSelectionListeners.remove(listener);
- }
-
- public void setSelection(ISelection selection) {
- peer_tree.deselectAll();
- if (selection instanceof IStructuredSelection) {
- Object[] elements = ((IStructuredSelection) selection).toArray();
- for (Object object : elements) {
- if (object instanceof PeerInfo) {
- TreeItem item = findItem((PeerInfo) object);
- if (item != null) {
- peer_tree.select(item);
- }
- }
- }
- }
- }
-
- private void fireSelectionChangedEvent() {
- SelectionChangedEvent event = new SelectionChangedEvent(this, getSelection());
- Object[] listeners = fSelectionListeners.getListeners();
- for (Object listener : listeners) {
- try {
- ((ISelectionChangedListener) listener).selectionChanged(event);
- } catch (Exception e) {
- Activator.log(e);
- }
- }
- }
-
-}
diff --git a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/ProcessListControl.java b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/ProcessListControl.java
deleted file mode 100644
index 616329d6c..000000000
--- a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/ProcessListControl.java
+++ /dev/null
@@ -1,505 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Wind River Systems, Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.internal.cdt.ui.launch;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.debug.ui.DebugUITools;
-import org.eclipse.debug.ui.IDebugUIConstants;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.tcf.protocol.IChannel;
-import org.eclipse.tcf.protocol.IChannel.IChannelListener;
-import org.eclipse.tcf.protocol.IPeer;
-import org.eclipse.tcf.protocol.IToken;
-import org.eclipse.tcf.protocol.Protocol;
-import org.eclipse.tcf.services.IProcesses;
-import org.eclipse.tcf.services.IProcesses.ProcessContext;
-
-public class ProcessListControl {
-
- private final class ProcessListener implements IProcesses.ProcessesListener {
- public void exited(final String process_id, int exit_code) {
- if (display != null) {
- display.asyncExec(new Runnable() {
- public void run() {
- ProcessInfo info = findProcessInfo(root_info, process_id);
- if (info != null && info.parent != null && info.parent.children != null) {
- info.parent.children = null;
- loadChildren(info.parent);
- }
- }
- });
- }
- }
- }
-
- static class ProcessInfo {
- String name;
- String id;
- boolean isContainer;
- ProcessInfo[] children;
- Throwable children_error;
- int index;
- boolean children_pending;
- ProcessInfo parent;
- protected boolean isAttached;
- }
-
- private Tree fProcessTree;
- private Display display;
- private IPeer fPeer;
- private final ProcessInfo root_info = new ProcessInfo();
- private IChannel fChannel;
- private IProcesses fProcesses;
- protected final ProcessListener fProcessListener = new ProcessListener();
- private String fContextToSelect;
- private LinkedList<String> fPathToSelect;
- private Composite fComposite;
-
- public ProcessListControl(Composite parent) {
- display = parent.getDisplay();
- parent.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- handleDispose();
- }
- });
- createProcessListArea(parent);
- }
-
- public void setInput(IPeer peer) {
- if (peer == fPeer) {
- return;
- }
- if (fPeer != null) {
- Protocol.invokeAndWait(new Runnable() {
- public void run() {
- disconnectPeer();
- }
- });
- }
- fProcessTree.setItemCount(0);
- root_info.children = null;
- fPeer = peer;
- if (fPeer != null) {
- Protocol.invokeAndWait(new Runnable() {
- public void run() {
- connectPeer();
- }
- });
- }
- }
-
- public Control getControl() {
- return fComposite;
- }
-
- public Tree getTree() {
- return fProcessTree;
- }
-
- public ProcessInfo getSelection() {
- if (fProcessTree != null) {
- TreeItem[] items = fProcessTree.getSelection();
- if (items.length > 0) {
- ProcessInfo info = findProcessInfo(items[0]);
- return info;
- }
- }
- return null;
- }
-
- private void createProcessListArea(Composite parent) {
- Font font = parent.getFont();
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setFont(font);
- GridLayout layout = new GridLayout(1, false);
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- composite.setLayout(layout);
- composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
- fComposite = composite;
-
- fProcessTree = new Tree(composite, SWT.VIRTUAL | SWT.BORDER | SWT.SINGLE);
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.minimumHeight = 150;
- gd.minimumWidth = 470;
- fProcessTree.setLayoutData(gd);
- fProcessTree.setFont(font);
- fProcessTree.addListener(SWT.SetData, new Listener() {
- public void handleEvent(Event event) {
- TreeItem item = (TreeItem)event.item;
- ProcessInfo info = findProcessInfo(item);
- if (info == null) {
- updateItems(item.getParentItem(), false);
- }
- else {
- fillItem(item, info);
- }
- }
- });
- }
-
- private void handleDispose() {
- Protocol.invokeAndWait(new Runnable() {
- public void run() {
- disconnectPeer();
- if (fProcesses != null) {
- fProcesses.removeListener(fProcessListener);
- fProcesses = null;
- }
- display = null;
- }
- });
- }
-
- protected void disconnectPeer() {
- if (fChannel != null && fChannel.getState() != IChannel.STATE_CLOSED) {
- fChannel.close();
- }
- }
-
- protected void connectPeer() {
- final IChannel channel = fPeer.openChannel();
- fChannel = channel;
- fProcesses = null;
- channel.addChannelListener(new IChannelListener() {
- public void congestionLevel(int level) {
- }
- public void onChannelClosed(final Throwable error) {
- if (fChannel != channel) return;
- fChannel = null;
- if (display != null) {
- display.asyncExec(new Runnable() {
- public void run() {
- if (root_info.children_pending) return;
- root_info.children = null;
- root_info.children_error = error;
- updateItems(root_info);
- }
- });
- }
- }
- public void onChannelOpened() {
- if (fChannel != channel) return;
- fProcesses = fChannel.getRemoteService(IProcesses.class);
- if (fProcesses != null) {
- fProcesses.addListener(fProcessListener);
- if (fContextToSelect != null) {
- final LinkedList<String> contextPath = new LinkedList<String>();
- contextPath.addFirst(fContextToSelect);
- fProcesses.getContext(fContextToSelect, new IProcesses.DoneGetContext() {
- public void doneGetContext(IToken token, Exception error, ProcessContext context) {
- if (error == null) {
- String parentId = context.getParentID();
- if (parentId != null) {
- contextPath.addFirst(parentId);
- fProcesses.getContext(parentId, this);
- return;
- }
- if (display != null) {
- display.asyncExec(new Runnable() {
- public void run() {
- fPathToSelect = contextPath;
- expandSelect();
- }
- });
- }
- }
- }
- });
- }
- }
- if (display != null) {
- display.asyncExec(new Runnable() {
- public void run() {
- if (root_info.children_pending) return;
- root_info.children = null;
- root_info.children_error = null;
- updateItems(root_info);
- }
- });
- }
- }
- });
- }
-
- private void updateItems(TreeItem parent_item, boolean reload) {
- final ProcessInfo parent_info = findProcessInfo(parent_item);
- if (parent_info == null) {
- parent_item.setText("Invalid");
- }
- else {
- if (reload && parent_info.children_error != null) {
- loadChildren(parent_info);
- }
- display.asyncExec(new Runnable() {
- public void run() {
- updateItems(parent_info);
- }
- });
- }
- }
-
- private void updateItems(final ProcessInfo parent) {
- if (display == null) return;
- assert Thread.currentThread() == display.getThread();
- TreeItem[] items = null;
- boolean expanded = true;
- if (parent.children == null || parent.children_error != null) {
- if (parent == root_info) {
- fProcessTree.setItemCount(1);
- items = fProcessTree.getItems();
- }
- else {
- TreeItem item = findItem(parent);
- if (item == null) return;
- expanded = item.getExpanded();
- item.setItemCount(1);
- items = item.getItems();
- }
- assert items.length == 1;
- items[0].removeAll();
- if (parent.children_pending) {
- items[0].setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
- items[0].setText("Pending...");
- }
- else if (parent.children_error != null) {
- String msg = parent.children_error.getMessage();
- if (msg == null) msg = parent.children_error.getClass().getName();
- else msg = msg.replace('\n', ' ');
- items[0].setForeground(display.getSystemColor(SWT.COLOR_RED));
- items[0].setText(msg);
- items[0].setImage((Image) null);
- }
- else if (expanded) {
- loadChildren(parent);
- items[0].setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
- items[0].setText("Pending...");
- }
- else {
- items[0].setText("");
- }
- }
- else {
- ProcessInfo[] arr = parent.children;
- if (parent == root_info) {
- fProcessTree.setItemCount(arr.length);
- items = fProcessTree.getItems();
- }
- else {
- TreeItem item = findItem(parent);
- if (item == null) return;
- expanded = item.getExpanded();
- item.setItemCount(expanded ? arr.length : 1);
- items = item.getItems();
- }
- if (expanded) {
- assert items.length == arr.length;
- for (int i = 0; i < items.length; i++) fillItem(items[i], arr[i]);
- // auto-expand single children
- if (items.length == 1 && !items[0].getExpanded()) {
- items[0].setExpanded(true);
- }
- expandSelect();
- }
- else {
- items[0].setText("");
- }
- }
- }
-
- private void expandSelect() {
- if (fPathToSelect == null) return;
- if (fPathToSelect.isEmpty()) {
- fPathToSelect = null;
- fContextToSelect = null;
- return;
- }
- do {
- String id = fPathToSelect.get(0);
- ProcessInfo info = findProcessInfo(root_info, id);
- if (info == null) break;
- TreeItem item = findItem(info);
- if (item == null) break;
- fPathToSelect.removeFirst();
- if (fPathToSelect.isEmpty()) {
- fProcessTree.setSelection(item);
- } else {
- item.setExpanded(true);
- }
- } while (!fPathToSelect.isEmpty());
- }
-
- private void loadChildren(final ProcessInfo parent) {
- assert Thread.currentThread() == display.getThread();
- if (parent.children_pending) return;
- assert parent.children == null;
- parent.children_pending = true;
- parent.children_error = null;
- Protocol.invokeLater(new Runnable() {
- public void run() {
- final IProcesses proc = fProcesses;
- if (proc == null || !canHaveChildren(parent)) {
- doneLoadChildren(parent, null, new ProcessInfo[0]);
- }
- else {
- proc.getChildren(parent.id, false, new IProcesses.DoneGetChildren() {
- public void doneGetChildren(IToken token, Exception error, String[] context_ids) {
- if (error != null) {
- doneLoadChildren(parent, error, null);
- } else if (context_ids.length > 0){
- final List<ProcessInfo> contextInfos = new ArrayList<ProcessInfo>(context_ids.length);
- final Set<IToken> pending = new HashSet<IToken>();
- for (String id : context_ids) {
- pending.add(proc.getContext(id, new IProcesses.DoneGetContext() {
- public void doneGetContext(IToken token, Exception error, ProcessContext context) {
- if (context != null) {
- ProcessInfo info = new ProcessInfo();
- info.parent = parent;
- info.id = context.getID();
- info.name = context.getName();
- if (info.name == null || info.name.length() == 0) {
- info.name = info.id;
- } else {
- info.name += " [" + info.id + ']';
- }
- info.isContainer = false;
- info.isAttached = context.isAttached();
- info.index = contextInfos.size();
- contextInfos.add(info);
- }
- pending.remove(token);
- if (pending.isEmpty()) {
- doneLoadChildren(parent, null, contextInfos.toArray(new ProcessInfo[contextInfos.size()]));
- }
- }
- }));
- }
- } else {
- doneLoadChildren(parent, null, new ProcessInfo[0]);
- }
- }
- });
- }
- }
- });
- }
-
- private void doneLoadChildren(final ProcessInfo parent, final Throwable error, final ProcessInfo[] children) {
- assert Protocol.isDispatchThread();
- assert error == null || children == null;
- if (display == null) return;
- display.asyncExec(new Runnable() {
- public void run() {
- assert parent.children_pending;
- assert parent.children == null;
- parent.children_pending = false;
- parent.children = children;
- parent.children_error = error;
- updateItems(parent);
- }
- });
- }
-
- public ProcessInfo findProcessInfo(TreeItem item) {
- assert Thread.currentThread() == display.getThread();
- if (item == null) return root_info ;
- TreeItem parent = item.getParentItem();
- ProcessInfo info = findProcessInfo(parent);
- if (info == null) return null;
- if (info.children == null) return null;
- if (info.children_error != null) return null;
- int i = parent == null ? fProcessTree.indexOf(item) : parent.indexOf(item);
- if (i < 0 || i >= info.children.length) return null;
- assert info.children[i].index == i;
- return info.children[i];
- }
-
- public ProcessInfo findProcessInfo(ProcessInfo parent, String id) {
- assert Thread.currentThread() == display.getThread();
- if (id == null) return root_info;
- if (id.equals(parent.id)) return parent;
- ProcessInfo[] childInfos = parent.children;
- if (childInfos != null) {
- for (ProcessInfo contextInfo : childInfos) {
- ProcessInfo found = findProcessInfo(contextInfo, id);
- if (found != null) {
- return found;
- }
- }
- }
- return null;
- }
-
- private TreeItem findItem(ProcessInfo info) {
- if (info == null) return null;
- assert info.parent != null;
- if (info.parent == root_info) {
- int n = fProcessTree.getItemCount();
- if (info.index >= n) return null;
- return fProcessTree.getItem(info.index);
- }
- TreeItem i = findItem(info.parent);
- if (i == null) return null;
- int n = i.getItemCount();
- if (info.index >= n) return null;
- return i.getItem(info.index);
- }
-
- private void fillItem(TreeItem item, ProcessInfo info) {
- assert Thread.currentThread() == display.getThread();
- Object data = item.getData("TCFContextInfo");
- if (data != null && data != info) item.removeAll();
- item.setData("TCFContextInfo", info);
- String text = info.name != null ? info.name : info.id;
- item.setText(text);
- item.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
- item.setImage(getImage(info));
- if (!canHaveChildren(info)) item.setItemCount(0);
- else if (info.children == null || info.children_error != null) item.setItemCount(1);
- else item.setItemCount(info.children.length);
- }
-
- private boolean canHaveChildren(ProcessInfo info) {
- return info.isContainer || info == root_info;
- }
-
- private Image getImage(ProcessInfo info) {
- return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_OS_PROCESS);
- }
-
- public void selectContext(final String contextId) {
- fPathToSelect = null;
- Protocol.invokeLater(new Runnable() {
- public void run() {
- fContextToSelect = contextId;
- }
- });
- }
-
-}
diff --git a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/ProcessPrompter.java b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/ProcessPrompter.java
index 4a0fa0294..a87c88c8a 100644
--- a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/ProcessPrompter.java
+++ b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/ProcessPrompter.java
@@ -15,19 +15,22 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.IStatusHandler;
import org.eclipse.jface.window.Window;
-import org.eclipse.tcf.internal.cdt.launch.ContextSelection;
import org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate;
+import org.eclipse.tcf.internal.debug.ui.launch.ContextSelection;
+import org.eclipse.tcf.internal.debug.ui.launch.ContextSelectionDialog;
import org.eclipse.ui.PlatformUI;
public class ProcessPrompter implements IStatusHandler {
public Object handleStatus(IStatus status, Object source) throws CoreException {
ILaunchConfiguration config = (ILaunchConfiguration) source;
- String peerId = config.getAttribute(TCFLaunchDelegate.ATTR_PEER_ID, (String) null);
- String contextId = config.getAttribute("attach_to_process", (String) null);
- if (peerId == null || contextId == null) {
- ContextSelection selection = new ContextSelection(peerId, contextId);
- ProcessSelectionDialog diag = new ProcessSelectionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
+ String peerId = config.getAttribute(TCFLaunchDelegate.ATTR_PEER_ID, (String)null);
+ String contextPath = config.getAttribute(TCFLaunchDelegate.ATTR_ATTACH_PATH, (String)null);
+ if (peerId == null || contextPath == null) {
+ ContextSelection selection = new ContextSelection();
+ selection.fPeerId = peerId;
+ selection.fContextFullName = contextPath;
+ ContextSelectionDialog diag = new ContextSelectionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), true);
diag.setSelection(selection);
if (diag.open() == Window.OK) {
return diag.getSelection();
@@ -35,5 +38,4 @@ public class ProcessPrompter implements IStatusHandler {
}
return null;
}
-
}
diff --git a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/ProcessSelectionDialog.java b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/ProcessSelectionDialog.java
deleted file mode 100644
index 15fa82bad..000000000
--- a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/ProcessSelectionDialog.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Wind River Systems, Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.internal.cdt.ui.launch;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.window.IShellProvider;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.tcf.internal.cdt.launch.ContextSelection;
-import org.eclipse.tcf.internal.cdt.ui.launch.PeerListControl.PeerInfo;
-import org.eclipse.tcf.internal.cdt.ui.launch.ProcessListControl.ProcessInfo;
-
-/**
- * Dialog to select a peer and context.
- */
-public class ProcessSelectionDialog extends Dialog {
-
- private ContextSelection fSelection;
- private ProcessListControl fContextList;
-
- protected ProcessSelectionDialog(IShellProvider parentShell) {
- super(parentShell);
- }
-
- public void setSelection(ContextSelection selection) {
- fSelection = selection;
- }
-
- public ContextSelection getSelection() {
- return fSelection;
- }
-
- @Override
- protected void configureShell(Shell newShell) {
- newShell.setText("Select Peer and Context");
- super.configureShell(newShell);
- }
-
- @Override
- protected Control createContents(Composite parent) {
- Control control = super.createContents(parent);
- updateButtonState();
- return control;
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite composite = (Composite) super.createDialogArea(parent);
- new Label(composite, SWT.NONE).setText("TCF Peers:");
- final PeerListControl peerList = new PeerListControl(composite);
- new Label(composite, SWT.NONE).setText("Contexts:");
- fContextList = new ProcessListControl(composite);
- peerList.addSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- ISelection selection = event.getSelection();
- if (selection instanceof IStructuredSelection) {
- IStructuredSelection ss = (IStructuredSelection) selection;
- Object element = ss.getFirstElement();
- if (element instanceof PeerInfo) {
- handlePeerSelected((PeerInfo) element);
- }
- }
- }
- });
- fContextList.getTree().addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- ProcessInfo contextInfo = fContextList.findProcessInfo((TreeItem) e.item);
- if (contextInfo != null) {
- handleContextSelected(contextInfo);
- }
- }
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- if (getButton(IDialogConstants.OK_ID).isEnabled()) {
- buttonPressed(IDialogConstants.OK_ID);
- }
- }
- });
- if (fSelection.fContextId != null) {
- fContextList.selectContext(fSelection.fContextId);
- }
- return composite;
- }
-
- private void updateButtonState() {
- getButton(IDialogConstants.OK_ID).setEnabled(fSelection.fContextId != null);
- }
-
- protected void handleContextSelected(ProcessInfo contextInfo) {
- fSelection.fContextId = contextInfo.id;
- updateButtonState();
- }
-
- protected void handlePeerSelected(PeerInfo peerInfo) {
- fSelection.fPeerId = peerInfo.id;
- fContextList.setInput(peerInfo.peer);
- }
-
-}
diff --git a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/RemoteCMainTab.java b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/RemoteCMainTab.java
index 64f0cbda0..79ece2719 100644
--- a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/RemoteCMainTab.java
+++ b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/RemoteCMainTab.java
@@ -22,7 +22,6 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
@@ -37,8 +36,10 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.tcf.internal.cdt.ui.launch.PeerListControl.PeerInfo;
import org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate;
+import org.eclipse.tcf.internal.debug.ui.launch.PeerListControl;
+import org.eclipse.tcf.internal.debug.ui.launch.PeerListControl.PeerInfo;
+import org.eclipse.tcf.internal.debug.ui.launch.RemoteFileSelectionDialog;
import org.eclipse.tcf.protocol.IChannel;
import org.eclipse.tcf.protocol.IChannel.IChannelListener;
import org.eclipse.tcf.services.IFileSystem;
@@ -122,7 +123,8 @@ public class RemoteCMainTab extends CMainTab implements IShellProvider {
if (fSelectedPeer == null) {
setErrorMessage("No target selected.");
valid = false;
- } else if (!fPeerHasProcessesService) {
+ }
+ else if (!fPeerHasProcessesService) {
setErrorMessage("Selected target does not support 'Processes' service");
valid = false;
}
@@ -242,15 +244,7 @@ public class RemoteCMainTab extends CMainTab implements IShellProvider {
protected void updatePeerFromConfig(ILaunchConfiguration config) {
try {
String peerId = config.getAttribute(TCFLaunchDelegate.ATTR_PEER_ID, (String) null);
- if (peerId != null) {
- PeerInfo info = fPeerList.findPeerInfo(peerId);
- if (info != null) {
- fPeerList.setSelection(new StructuredSelection(info));
- handlePeerSelectionChanged();
- } else {
- fPeerList.setInitialSelectedPeerId(peerId);
- }
- }
+ fPeerList.setInitialSelection(peerId);
}
catch (CoreException e) {
// Ignore
diff --git a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/RemoteFileSelectionDialog.java b/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/RemoteFileSelectionDialog.java
deleted file mode 100644
index 23af441d2..000000000
--- a/plugins/org.eclipse.tcf.cdt.ui/src/org/eclipse/tcf/internal/cdt/ui/launch/RemoteFileSelectionDialog.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Wind River Systems, Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.internal.cdt.ui.launch;
-
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.window.IShellProvider;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.FocusAdapter;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.tcf.internal.cdt.ui.launch.FileSystemBrowserControl.FileInfo;
-import org.eclipse.tcf.protocol.IPeer;
-
-/**
- * Dialog to select a remote file.
- */
-public class RemoteFileSelectionDialog extends Dialog {
-
- private String fSelection;
- private FileSystemBrowserControl fFileList;
- private IPeer fPeer;
- private boolean fForSave;
- private Text fFileNameText;
-
- protected RemoteFileSelectionDialog(IShellProvider parentShell, int style) {
- super(parentShell);
- setShellStyle(getShellStyle() | SWT.RESIZE);
- fForSave = (style & SWT.SAVE) != 0;
- }
-
- public void setPeer(IPeer peer) {
- fPeer = peer;
- if (fFileList != null) {
- fFileList.setInput(peer);
- }
- }
-
- public void setSelection(String fileSelection) {
- fSelection = fileSelection;
- }
-
- public String getSelection() {
- return fSelection;
- }
-
- @Override
- protected void configureShell(Shell newShell) {
- newShell.setText("Select File");
- super.configureShell(newShell);
- }
-
- @Override
- protected Control createContents(Composite parent) {
- Control control = super.createContents(parent);
- updateButtonState();
- return control;
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite composite = (Composite) super.createDialogArea(parent);
- fFileList = new FileSystemBrowserControl(composite, false);
- fFileList.getTree().addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- FileInfo contextInfo = fFileList.findFileInfo((TreeItem) e.item);
- if (contextInfo != null) {
- handleFileSelected(contextInfo);
- }
- }
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- if (getButton(IDialogConstants.OK_ID).isEnabled()) {
- buttonPressed(IDialogConstants.OK_ID);
- }
- }
- });
-
- if (fForSave) {
- Composite fileNameComp = new Composite(composite, SWT.NONE);
- fileNameComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- GridLayout layout = new GridLayout(2, false);
- layout.marginWidth = 0;
- fileNameComp.setLayout(layout);
- new Label(fileNameComp, SWT.NONE).setText("File Name:");
- fFileNameText = new Text(fileNameComp, SWT.BORDER);
- fFileNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- fFileNameText.addFocusListener(new FocusAdapter() {
- @Override
- public void focusLost(FocusEvent e) {
- handleFileNameChanged();
- }
- });
- }
-
- if (fSelection != null) {
- fFileList.setInitialSelection(fSelection);
- if (fFileNameText != null) {
- String basename = new Path(fSelection).lastSegment();
- if (basename != null) {
- fFileNameText.setText(basename);
- }
- }
- }
- if (fPeer != null) {
- fFileList.setInput(fPeer);
- }
- return composite;
- }
-
- private void updateButtonState() {
- boolean enabled = fSelection != null;
- if (enabled && fForSave) {
- enabled = fFileNameText.getText().trim().length() > 0;
- }
- getButton(IDialogConstants.OK_ID).setEnabled(enabled);
- }
-
- protected void handleFileNameChanged() {
- if (fSelection != null) {
- fSelection = new Path(fSelection).removeLastSegments(1).append(fFileNameText.getText().trim()).toString();
- updateButtonState();
- }
- }
-
- protected void handleFileSelected(FileInfo fileInfo) {
- if (fileInfo.isDir) {
- if (fForSave) {
- String basename = fFileNameText.getText().trim();
- if (basename.length() > 0) {
- fSelection = new Path(fileInfo.fullname).append(basename).toString();
- } else {
- fSelection = fileInfo.fullname;
- }
- } else {
- fSelection = null;
- }
- } else {
- fSelection = fileInfo.fullname;
- if (fFileNameText != null) {
- String basename = new Path(fSelection).lastSegment();
- if (basename != null) {
- fFileNameText.setText(basename);
- }
- }
- }
- updateButtonState();
- }
-
-}

Back to the top