Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.ote.ui.host.cmd')
-rw-r--r--plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/ConsoleNode.java7
-rw-r--r--plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/EnvironmentViewer.java500
-rw-r--r--plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/TestServerConsoleServiceRenderer.java315
3 files changed, 421 insertions, 401 deletions
diff --git a/plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/ConsoleNode.java b/plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/ConsoleNode.java
index 359d18fdd4..b43f5b69fc 100644
--- a/plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/ConsoleNode.java
+++ b/plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/ConsoleNode.java
@@ -14,7 +14,6 @@ import org.eclipse.osee.framework.jdk.core.type.TreeObject;
import org.eclipse.osee.ote.core.OSEEPerson1_4;
import org.eclipse.osee.ote.core.environment.interfaces.IRemoteCommandConsole;
-
/**
* @author Ken J. Aguilar
*/
@@ -22,7 +21,7 @@ public class ConsoleNode extends TreeObject {
private final IRemoteCommandConsole console;
private String users;
-
+
public ConsoleNode(IRemoteCommandConsole console, OSEEPerson1_4[] users) {
super("Console");
this.console = console;
@@ -34,13 +33,13 @@ public class ConsoleNode extends TreeObject {
sb.append(users[i].getName());
sb.append(", ");
}
- sb.append(users[users.length -1]);
+ sb.append(users[users.length - 1]);
this.users = sb.toString();
} else {
this.users = users.length == 0 ? "<none>" : users[0].getName();
}
}
-
+
public IRemoteCommandConsole getConsole() {
return console;
}
diff --git a/plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/EnvironmentViewer.java b/plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/EnvironmentViewer.java
index ac09778a05..0fb2511fe0 100644
--- a/plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/EnvironmentViewer.java
+++ b/plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/EnvironmentViewer.java
@@ -41,246 +41,262 @@ import org.eclipse.ui.PlatformUI;
*/
public class EnvironmentViewer extends Composite {
- private static final Image ENVIRONMENT_IMAGE = PlatformUI.getWorkbench().getSharedImages().getImage(
- ISharedImages.IMG_OBJ_FOLDER);
-
- private static final Image USER_IMAGE = ImageManager.getImage(OteUiHostCmdImage.USER);
-
- private static final Image CONSOLE_IMAGE = ImageManager.getImage(OteUiHostCmdImage.CONSOLE);
-
- protected enum ColumnEnum {
- Service(SWT.LEFT),
- Users;
-
- private int alignment;
-
- private ColumnEnum() {
- this.alignment = SWT.CENTER;
- }
-
- private ColumnEnum(int alignment) {
- this.alignment = alignment;
- }
-
- public int getAlignment() {
- return alignment;
- }
-
- public static String[] toArray() {
- ColumnEnum[] enumArray = ColumnEnum.values();
- String[] toReturn = new String[enumArray.length];
- for (int index = 0; index < enumArray.length; index++) {
- toReturn[index] = enumArray[index].toString();
- }
- return toReturn;
- }
- }
-
- private TreeViewer viewer;
-
- public EnvironmentViewer(Composite parent, int style) {
- super(parent, style);
- createControl();
- }
-
- public void createControl() {
- this.setLayout(new GridLayout());
- this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- createTreeArea(this);
- createColumns();
- attachListeners();
- packColumnData();
- }
-
- private void createTreeArea(Composite parent) {
- viewer = new TreeViewer(parent, SWT.SINGLE | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
- viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- (viewer).getTree().setHeaderVisible(true);
- (viewer).getTree().setLinesVisible(true);
- viewer.setUseHashlookup(true);
- viewer.setColumnProperties(ColumnEnum.toArray());
- viewer.setContentProvider(new TreeContentProvider());
- viewer.setLabelProvider(new TreeLabelProvider());
- viewer.setSorter(new ViewerSorter());
- viewer.setInput(new ArrayList<String>());
- viewer.getControl().setBackground(Displays.getSystemColor(SWT.COLOR_WHITE));
- }
-
- private void createColumns() {
- for (ColumnEnum columnEnum : ColumnEnum.values()) {
- TreeColumn column = new TreeColumn(viewer.getTree(), SWT.CENTER, columnEnum.ordinal());
- column.setText(columnEnum.toString());
- column.setWidth(columnEnum.toString().length());
- column.setAlignment(columnEnum.getAlignment());
- }
- }
-
- public void packColumnData() {
- TreeColumn[] columns = viewer.getTree().getColumns();
- for (TreeColumn column : columns) {
- column.pack();
- }
- }
-
- private void attachListeners() {
- viewer.addTreeListener(new ITreeViewerListener() {
-
- public void treeCollapsed(TreeExpansionEvent event) {
- packColumnData();
- }
-
- public void treeExpanded(TreeExpansionEvent event) {
- packColumnData();
- }
-
- });
- }
-
- private class TreeLabelProvider implements ITableLabelProvider, ILabelProvider {
-
- public Image getImage(Object obj) {
- Image toReturn = null;
- if (obj instanceof UserNode) {
- toReturn = USER_IMAGE;
- } else if (obj instanceof ConsoleNode) {
- toReturn = CONSOLE_IMAGE;
- } else if (obj instanceof TreeParent) {
- toReturn = ENVIRONMENT_IMAGE;
- }
- return toReturn;
- }
-
- public String getText(Object obj) {
- if (obj instanceof ConsoleNode) {
- ((ConsoleNode) obj).getName();
- }
- return obj.toString();
- }
-
- public Image getColumnImage(Object element, int columnIndex) {
- Image toReturn = null;
- ColumnEnum column = ColumnEnum.values()[columnIndex];
- switch (column) {
- case Service:
- if (element instanceof UserNode) {
- toReturn = USER_IMAGE;
- } else if (element instanceof ConsoleNode) {
- toReturn = CONSOLE_IMAGE;
- } else if (element instanceof TreeParent) {
- toReturn = ENVIRONMENT_IMAGE;
- }
- break;
- default:
- break;
- }
- return toReturn;
- }
-
- public String getColumnText(Object element, int columnIndex) {
- String toReturn = null;
- ColumnEnum column = ColumnEnum.values()[columnIndex];
- switch (column) {
- case Service:
- if (element instanceof ConsoleNode) {
- toReturn = ((ConsoleNode) element).getName();
- } else if (element instanceof TreeParent) {
- toReturn = element.toString();
- }
- break;
- case Users:
- if (element instanceof ConsoleNode) {
- toReturn = ((ConsoleNode) element).getUsers();
- }
- break;
- default:
- break;
- }
- return toReturn;
- }
-
- public void addListener(ILabelProviderListener listener) {
- }
-
- public void dispose() {
- }
-
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- public void removeListener(ILabelProviderListener listener) {
- }
- }
-
- private class TreeContentProvider implements ITreeContentProvider {
-
- public void dispose() {
- }
-
- public Object[] getChildren(Object parentElement) {
- if (parentElement != null && parentElement instanceof TreeParent) {
- TreeParent parent = (TreeParent) parentElement;
- if (parent.hasChildren()) {
- return parent.getChildren();
- }
- }
- return new Object[0];
- }
-
- public Object[] getElements(Object inputElement) {
- if (inputElement != null && inputElement instanceof Collection) {
- Collection<?> elementArray = (Collection<?>) inputElement;
- return elementArray.toArray();
- }
- return new Object[0];
- }
-
- public Object getParent(Object element) {
- if (element != null && element instanceof TreeObject) {
- TreeObject child = (TreeObject) element;
- return child.getParent();
- }
- return new Object();
- }
-
- public boolean hasChildren(Object element) {
- if (element instanceof TreeParent) {
- TreeParent parent = (TreeParent) element;
- return parent.hasChildren();
- }
- return false;
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
- }
-
- @Override
- public boolean setFocus() {
- return this.viewer.getControl().setFocus();
- }
-
- public StructuredViewer getViewer() {
- return viewer;
- }
-
- public void setInput(List<TreeParent> input) {
- viewer.setInput(input);
- }
-
- public void refresh() {
- Displays.ensureInDisplayThread(new Runnable() {
- @Override
- public void run() {
- packColumnData();
- viewer.refresh();
- }
- });
- }
-
- @Override
- public void dispose() {
- viewer.getControl().dispose();
- super.dispose();
- }
+ private static final Image ENVIRONMENT_IMAGE = PlatformUI.getWorkbench().getSharedImages().getImage(
+ ISharedImages.IMG_OBJ_FOLDER);
+
+ private static final Image USER_IMAGE = ImageManager.getImage(OteUiHostCmdImage.USER);
+
+ private static final Image CONSOLE_IMAGE = ImageManager.getImage(OteUiHostCmdImage.CONSOLE);
+
+ protected enum ColumnEnum {
+ Service(SWT.LEFT),
+ Users;
+
+ private int alignment;
+
+ private ColumnEnum() {
+ this.alignment = SWT.CENTER;
+ }
+
+ private ColumnEnum(int alignment) {
+ this.alignment = alignment;
+ }
+
+ public int getAlignment() {
+ return alignment;
+ }
+
+ public static String[] toArray() {
+ ColumnEnum[] enumArray = ColumnEnum.values();
+ String[] toReturn = new String[enumArray.length];
+ for (int index = 0; index < enumArray.length; index++) {
+ toReturn[index] = enumArray[index].toString();
+ }
+ return toReturn;
+ }
+ }
+
+ private TreeViewer viewer;
+
+ public EnvironmentViewer(Composite parent, int style) {
+ super(parent, style);
+ createControl();
+ }
+
+ public void createControl() {
+ this.setLayout(new GridLayout());
+ this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ createTreeArea(this);
+ createColumns();
+ attachListeners();
+ packColumnData();
+ }
+
+ private void createTreeArea(Composite parent) {
+ viewer = new TreeViewer(parent, SWT.SINGLE | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+ viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ viewer.getTree().setHeaderVisible(true);
+ viewer.getTree().setLinesVisible(true);
+ viewer.setUseHashlookup(true);
+ viewer.setColumnProperties(ColumnEnum.toArray());
+ viewer.setContentProvider(new TreeContentProvider());
+ viewer.setLabelProvider(new TreeLabelProvider());
+ viewer.setSorter(new ViewerSorter());
+ viewer.setInput(new ArrayList<String>());
+ viewer.getControl().setBackground(Displays.getSystemColor(SWT.COLOR_WHITE));
+ }
+
+ private void createColumns() {
+ for (ColumnEnum columnEnum : ColumnEnum.values()) {
+ TreeColumn column = new TreeColumn(viewer.getTree(), SWT.CENTER, columnEnum.ordinal());
+ column.setText(columnEnum.toString());
+ column.setWidth(columnEnum.toString().length());
+ column.setAlignment(columnEnum.getAlignment());
+ }
+ }
+
+ public void packColumnData() {
+ TreeColumn[] columns = viewer.getTree().getColumns();
+ for (TreeColumn column : columns) {
+ column.pack();
+ }
+ }
+
+ private void attachListeners() {
+ viewer.addTreeListener(new ITreeViewerListener() {
+
+ @Override
+ public void treeCollapsed(TreeExpansionEvent event) {
+ packColumnData();
+ }
+
+ @Override
+ public void treeExpanded(TreeExpansionEvent event) {
+ packColumnData();
+ }
+
+ });
+ }
+
+ private class TreeLabelProvider implements ITableLabelProvider, ILabelProvider {
+
+ @Override
+ public Image getImage(Object obj) {
+ Image toReturn = null;
+ if (obj instanceof UserNode) {
+ toReturn = USER_IMAGE;
+ } else if (obj instanceof ConsoleNode) {
+ toReturn = CONSOLE_IMAGE;
+ } else if (obj instanceof TreeParent) {
+ toReturn = ENVIRONMENT_IMAGE;
+ }
+ return toReturn;
+ }
+
+ @Override
+ public String getText(Object obj) {
+ if (obj instanceof ConsoleNode) {
+ ((ConsoleNode) obj).getName();
+ }
+ return obj.toString();
+ }
+
+ @Override
+ public Image getColumnImage(Object element, int columnIndex) {
+ Image toReturn = null;
+ ColumnEnum column = ColumnEnum.values()[columnIndex];
+ switch (column) {
+ case Service:
+ if (element instanceof UserNode) {
+ toReturn = USER_IMAGE;
+ } else if (element instanceof ConsoleNode) {
+ toReturn = CONSOLE_IMAGE;
+ } else if (element instanceof TreeParent) {
+ toReturn = ENVIRONMENT_IMAGE;
+ }
+ break;
+ default:
+ break;
+ }
+ return toReturn;
+ }
+
+ @Override
+ public String getColumnText(Object element, int columnIndex) {
+ String toReturn = null;
+ ColumnEnum column = ColumnEnum.values()[columnIndex];
+ switch (column) {
+ case Service:
+ if (element instanceof ConsoleNode) {
+ toReturn = ((ConsoleNode) element).getName();
+ } else if (element instanceof TreeParent) {
+ toReturn = element.toString();
+ }
+ break;
+ case Users:
+ if (element instanceof ConsoleNode) {
+ toReturn = ((ConsoleNode) element).getUsers();
+ }
+ break;
+ default:
+ break;
+ }
+ return toReturn;
+ }
+
+ @Override
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ @Override
+ public void removeListener(ILabelProviderListener listener) {
+ }
+ }
+
+ private class TreeContentProvider implements ITreeContentProvider {
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement != null && parentElement instanceof TreeParent) {
+ TreeParent parent = (TreeParent) parentElement;
+ if (parent.hasChildren()) {
+ return parent.getChildren();
+ }
+ }
+ return new Object[0];
+ }
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ if (inputElement != null && inputElement instanceof Collection) {
+ Collection<?> elementArray = (Collection<?>) inputElement;
+ return elementArray.toArray();
+ }
+ return new Object[0];
+ }
+
+ @Override
+ public Object getParent(Object element) {
+ if (element != null && element instanceof TreeObject) {
+ TreeObject child = (TreeObject) element;
+ return child.getParent();
+ }
+ return new Object();
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ if (element instanceof TreeParent) {
+ TreeParent parent = (TreeParent) element;
+ return parent.hasChildren();
+ }
+ return false;
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ }
+
+ @Override
+ public boolean setFocus() {
+ return this.viewer.getControl().setFocus();
+ }
+
+ public StructuredViewer getViewer() {
+ return viewer;
+ }
+
+ public void setInput(List<TreeParent> input) {
+ viewer.setInput(input);
+ }
+
+ public void refresh() {
+ Displays.ensureInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ packColumnData();
+ viewer.refresh();
+ }
+ });
+ }
+
+ @Override
+ public void dispose() {
+ viewer.getControl().dispose();
+ super.dispose();
+ }
}
diff --git a/plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/TestServerConsoleServiceRenderer.java b/plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/TestServerConsoleServiceRenderer.java
index 738eaec8c9..cf0aba3bf6 100644
--- a/plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/TestServerConsoleServiceRenderer.java
+++ b/plugins/org.eclipse.osee.ote.ui.host.cmd/src/org/eclipse/osee/ote/ui/host/cmd/TestServerConsoleServiceRenderer.java
@@ -45,159 +45,164 @@ import org.eclipse.swt.widgets.Text;
* Created on Oct 9, 2006
*/
public class TestServerConsoleServiceRenderer implements IServiceRenderer {
- private IHostTestEnvironment testService;
- private Group composite;
- private final Hashtable<ITestEnvironment, IRemoteCommandConsole> consoles;
- private volatile IRemoteCommandConsole selectedConsole;
- private Text outputTxt;
- private Text inputTxt;
- private Button sendCmdBtn;
- private EnvironmentViewer envViewer;
- private final InputManager<TreeParent> inputManager;
-
- public TestServerConsoleServiceRenderer() {
- this.consoles = new Hashtable<ITestEnvironment, IRemoteCommandConsole>(24);
- this.selectedConsole = null;
- this.inputManager = new InputManager<TreeParent>();
- }
-
- @Override
- public void refresh() {
- Displays.ensureInDisplayThread(new Runnable() {
- @Override
- public void run() {
- if (composite != null && !composite.isDisposed() && testService != null) {
- cleanupService();
- try {
- ITestEnvironment[] envs = testService.getRemoteEnvironments();
- consoles.clear();
- if (envs.length > 0) {
- for (ITestEnvironment env : envs) {
- consoles.put(env, env.getCommandConsole());
- }
- selectedConsole = consoles.get(envs[0]);
- } else {
- selectedConsole = null;
- }
-
- envViewer.setInput(inputManager.getInputList());
- TreeBuilder.buildTree(inputManager, testService, consoles);
- envViewer.refresh();
-
- } catch (Throwable t) {
- OseeLog.log(UiPlugin.class, Level.SEVERE, "exception getting hosts", t);
- }
- }
- }
- });
- }
-
- public void setService(ServiceItem serviceItem) {
- OseeLog.log(UiPlugin.class, Level.INFO, "setting test environment service");
- testService = (IHostTestEnvironment) serviceItem.service;
- if (outputTxt != null && !outputTxt.isDisposed()) {
- outputTxt.setText("");
- }
- }
-
- public void disconnect() {
- consoles.clear();
- }
-
- public void dispose() {
- cleanupService();
- Widgets.disposeWidgets(composite, outputTxt, inputTxt, sendCmdBtn);
- }
-
- public Control renderInComposite(Composite parent) {
- composite = new Group(parent, SWT.NONE);
- composite.setLayout(new GridLayout());
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- composite.setText("Test Server Console");
-
- SashForm sashForm = new SashForm(composite, SWT.NONE);
- sashForm.setLayout(new GridLayout());
- sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- sashForm.setOrientation(SWT.VERTICAL);
- sashForm.SASH_WIDTH = 3;
-
- envViewer = new EnvironmentViewer(sashForm, SWT.NONE);
- envViewer.getViewer().addDoubleClickListener(new IDoubleClickListener() {
-
- public void doubleClick(DoubleClickEvent event) {
- Object element = ((IStructuredSelection) event.getSelection()).getFirstElement();
- if (element != null && element instanceof ConsoleNode) {
- selectedConsole = ((ConsoleNode) element).getConsole();
- outputTxt.setText("");
- }
- }
-
- });
- createConsoleArea(sashForm);
-
- sashForm.setWeights(new int[] {3, 7});
- return composite;
- }
-
- private void createConsoleArea(Composite parent) {
- Group composite = new Group(parent, SWT.NONE);
- Widgets.setFormLayout(composite, 5, 5);
- composite.setText("Interact");
-
- outputTxt =
- Widgets.createTxt(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY | SWT.BORDER, "");
- outputTxt.setTabs(4);
- outputTxt.setBackground(Displays.getSystemColor(SWT.COLOR_BLACK));
- outputTxt.setForeground(Displays.getSystemColor(SWT.COLOR_GREEN));
- outputTxt.setFont(new Font(Display.getDefault(), "Courier", 10, SWT.NORMAL));
- Widgets.attachToParent(outputTxt, SWT.TOP, 0, 5);
- Widgets.attachToParent(outputTxt, SWT.BOTTOM, 75, 0);
- Widgets.attachToParent(outputTxt, SWT.LEFT, 0, 5);
- Widgets.attachToParent(outputTxt, SWT.RIGHT, 100, -5);
-
- inputTxt = Widgets.createTxt(composite, SWT.SINGLE | SWT.BORDER, "");
- inputTxt.addTraverseListener(new TraverseListener() {
- @Override
- public void keyTraversed(TraverseEvent event) {
- if (event.detail == SWT.TRAVERSE_RETURN) {
- sendCmd(inputTxt.getText());
- }
- }
-
- });
- Widgets.attachToControl(inputTxt, outputTxt, SWT.LEFT, SWT.LEFT, 0);
- sendCmdBtn = Widgets.createBtn(composite, SWT.PUSH, "Execute");
- sendCmdBtn.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent arg0) {
- sendCmd(inputTxt.getText());
- }
-
- });
- Widgets.attachToControl(sendCmdBtn, outputTxt, SWT.TOP, SWT.BOTTOM, 5);
- Widgets.attachToControl(sendCmdBtn, outputTxt, SWT.RIGHT, SWT.RIGHT, 0);
- Widgets.attachToControl(inputTxt, sendCmdBtn, SWT.RIGHT, SWT.LEFT, -5);
- Widgets.attachToControl(inputTxt, sendCmdBtn, SWT.TOP, SWT.CENTER, 0);
- }
-
- private void sendCmd(String cmd) {
- try {
- if (selectedConsole != null) {
- outputTxt.append(selectedConsole.doCommand(cmd));
- inputTxt.setText("");
- } else {
- outputTxt.append("No Consoles Available\n");
- }
- } catch (Throwable t) {
- OseeLog.log(UiPlugin.class, Level.SEVERE, "Exception trying to execute test service console command " + cmd, t);
- outputTxt.append("Exception ocurred when executing command\n");
-
- }
- }
-
- private void cleanupService() {
- consoles.clear();
- inputManager.removeAll();
- }
+ private IHostTestEnvironment testService;
+ private Group composite;
+ private final Hashtable<ITestEnvironment, IRemoteCommandConsole> consoles;
+ private volatile IRemoteCommandConsole selectedConsole;
+ private Text outputTxt;
+ private Text inputTxt;
+ private Button sendCmdBtn;
+ private EnvironmentViewer envViewer;
+ private final InputManager<TreeParent> inputManager;
+
+ public TestServerConsoleServiceRenderer() {
+ this.consoles = new Hashtable<ITestEnvironment, IRemoteCommandConsole>(24);
+ this.selectedConsole = null;
+ this.inputManager = new InputManager<TreeParent>();
+ }
+
+ @Override
+ public void refresh() {
+ Displays.ensureInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ if (composite != null && !composite.isDisposed() && testService != null) {
+ cleanupService();
+ try {
+ ITestEnvironment[] envs = testService.getRemoteEnvironments();
+ consoles.clear();
+ if (envs.length > 0) {
+ for (ITestEnvironment env : envs) {
+ consoles.put(env, env.getCommandConsole());
+ }
+ selectedConsole = consoles.get(envs[0]);
+ } else {
+ selectedConsole = null;
+ }
+
+ envViewer.setInput(inputManager.getInputList());
+ TreeBuilder.buildTree(inputManager, testService, consoles);
+ envViewer.refresh();
+
+ } catch (Throwable t) {
+ OseeLog.log(UiPlugin.class, Level.SEVERE, "exception getting hosts", t);
+ }
+ }
+ }
+ });
+ }
+
+ @Override
+ public void setService(ServiceItem serviceItem) {
+ OseeLog.log(UiPlugin.class, Level.INFO, "setting test environment service");
+ testService = (IHostTestEnvironment) serviceItem.service;
+ if (outputTxt != null && !outputTxt.isDisposed()) {
+ outputTxt.setText("");
+ }
+ }
+
+ @Override
+ public void disconnect() {
+ consoles.clear();
+ }
+
+ @Override
+ public void dispose() {
+ cleanupService();
+ Widgets.disposeWidgets(composite, outputTxt, inputTxt, sendCmdBtn);
+ }
+
+ @Override
+ public Control renderInComposite(Composite parent) {
+ composite = new Group(parent, SWT.NONE);
+ composite.setLayout(new GridLayout());
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ composite.setText("Test Server Console");
+
+ SashForm sashForm = new SashForm(composite, SWT.NONE);
+ sashForm.setLayout(new GridLayout());
+ sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ sashForm.setOrientation(SWT.VERTICAL);
+ sashForm.SASH_WIDTH = 3;
+
+ envViewer = new EnvironmentViewer(sashForm, SWT.NONE);
+ envViewer.getViewer().addDoubleClickListener(new IDoubleClickListener() {
+
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ Object element = ((IStructuredSelection) event.getSelection()).getFirstElement();
+ if (element != null && element instanceof ConsoleNode) {
+ selectedConsole = ((ConsoleNode) element).getConsole();
+ outputTxt.setText("");
+ }
+ }
+
+ });
+ createConsoleArea(sashForm);
+
+ sashForm.setWeights(new int[] {3, 7});
+ return composite;
+ }
+
+ private void createConsoleArea(Composite parent) {
+ Group composite = new Group(parent, SWT.NONE);
+ Widgets.setFormLayout(composite, 5, 5);
+ composite.setText("Interact");
+
+ outputTxt =
+ Widgets.createTxt(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY | SWT.BORDER, "");
+ outputTxt.setTabs(4);
+ outputTxt.setBackground(Displays.getSystemColor(SWT.COLOR_BLACK));
+ outputTxt.setForeground(Displays.getSystemColor(SWT.COLOR_GREEN));
+ outputTxt.setFont(new Font(Display.getDefault(), "Courier", 10, SWT.NORMAL));
+ Widgets.attachToParent(outputTxt, SWT.TOP, 0, 5);
+ Widgets.attachToParent(outputTxt, SWT.BOTTOM, 75, 0);
+ Widgets.attachToParent(outputTxt, SWT.LEFT, 0, 5);
+ Widgets.attachToParent(outputTxt, SWT.RIGHT, 100, -5);
+
+ inputTxt = Widgets.createTxt(composite, SWT.SINGLE | SWT.BORDER, "");
+ inputTxt.addTraverseListener(new TraverseListener() {
+ @Override
+ public void keyTraversed(TraverseEvent event) {
+ if (event.detail == SWT.TRAVERSE_RETURN) {
+ sendCmd(inputTxt.getText());
+ }
+ }
+
+ });
+ Widgets.attachToControl(inputTxt, outputTxt, SWT.LEFT, SWT.LEFT, 0);
+ sendCmdBtn = Widgets.createBtn(composite, SWT.PUSH, "Execute");
+ sendCmdBtn.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ sendCmd(inputTxt.getText());
+ }
+
+ });
+ Widgets.attachToControl(sendCmdBtn, outputTxt, SWT.TOP, SWT.BOTTOM, 5);
+ Widgets.attachToControl(sendCmdBtn, outputTxt, SWT.RIGHT, SWT.RIGHT, 0);
+ Widgets.attachToControl(inputTxt, sendCmdBtn, SWT.RIGHT, SWT.LEFT, -5);
+ Widgets.attachToControl(inputTxt, sendCmdBtn, SWT.TOP, SWT.CENTER, 0);
+ }
+
+ private void sendCmd(String cmd) {
+ try {
+ if (selectedConsole != null) {
+ outputTxt.append(selectedConsole.doCommand(cmd));
+ inputTxt.setText("");
+ } else {
+ outputTxt.append("No Consoles Available\n");
+ }
+ } catch (Throwable t) {
+ OseeLog.log(UiPlugin.class, Level.SEVERE, "Exception trying to execute test service console command " + cmd, t);
+ outputTxt.append("Exception ocurred when executing command\n");
+
+ }
+ }
+
+ private void cleanupService() {
+ consoles.clear();
+ inputManager.removeAll();
+ }
}

Back to the top