mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 11:25:35 +02:00
Merge "Bug 467350 - Public API to open consoles"
This commit is contained in:
commit
ce6a031731
3 changed files with 121 additions and 37 deletions
|
@ -0,0 +1,49 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2015 Red Hat 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:
|
||||||
|
* Red Hat Inc. - Initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.remote.console;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.remote.core.IRemoteConnection;
|
||||||
|
import org.eclipse.remote.internal.console.TerminalConsoleFactory;
|
||||||
|
import org.eclipse.ui.console.IConsole;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A collection of public API utility methods to open
|
||||||
|
* consoles to IRemoteConnection objects
|
||||||
|
*/
|
||||||
|
public class TerminalConsoleUtility {
|
||||||
|
/**
|
||||||
|
* Opens a dialog to allow selection of an IRemoteConnection,
|
||||||
|
* encoding, etc. and then open a console to it.
|
||||||
|
*/
|
||||||
|
public void openConsole() {
|
||||||
|
new TerminalConsoleFactory().openConsole();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open a specific IRemoteConnection and encoding combination.
|
||||||
|
* @param connection
|
||||||
|
* @param encoding
|
||||||
|
*/
|
||||||
|
public static void openConsole(final IRemoteConnection connection, final String encoding) {
|
||||||
|
new TerminalConsoleFactory().openConsole(connection, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find an existing console for the given IRemoteConnection
|
||||||
|
* @param connection
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<IConsole> findConsole(IRemoteConnection connection) {
|
||||||
|
return new TerminalConsoleFactory().findConsole(connection);
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,6 +10,9 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.remote.internal.console;
|
package org.eclipse.remote.internal.console;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
@ -36,48 +39,80 @@ public class TerminalConsoleFactory implements IConsoleFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openConsole(final IRemoteConnection connection, final String encoding) {
|
public static void openConsole(final IRemoteConnection connection, final String encoding) {
|
||||||
new Job(ConsoleMessages.OPENNING_TERMINAL) {
|
Job j = new Job(ConsoleMessages.OPENNING_TERMINAL) {
|
||||||
@Override
|
@Override
|
||||||
public IStatus run(IProgressMonitor monitor) {
|
public IStatus run(IProgressMonitor monitor) {
|
||||||
IRemoteCommandShellService commandShellService = connection.getService(IRemoteCommandShellService.class);
|
return openConsoleImplementation(connection, encoding, monitor);
|
||||||
if (commandShellService == null) {
|
}
|
||||||
return Status.CANCEL_STATUS;
|
};
|
||||||
}
|
j.schedule();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IStatus openConsoleImplementation( final IRemoteConnection connection,
|
||||||
|
final String encoding, IProgressMonitor monitor) {
|
||||||
|
IRemoteCommandShellService commandShellService = connection.getService(IRemoteCommandShellService.class);
|
||||||
|
if (commandShellService == null) {
|
||||||
|
return Status.CANCEL_STATUS;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
IConsole ret = createConsole(connection, encoding, commandShellService, monitor);
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
} catch(RemoteConnectionException rce) {
|
||||||
|
return rce.getStatus();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
}
|
||||||
if (!connection.isOpen()) {
|
|
||||||
connection.open(monitor);
|
private static IConsole createConsole( final IRemoteConnection connection,
|
||||||
}
|
final String encoding, IRemoteCommandShellService service,
|
||||||
|
IProgressMonitor monitor) throws RemoteConnectionException {
|
||||||
|
if (!connection.isOpen()) {
|
||||||
|
connection.open(monitor);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO, how to handle command shells that are singletons, like serial ports
|
// TODO, how to handle command shells that are singletons, like serial ports
|
||||||
|
|
||||||
// Find the index;
|
IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
|
||||||
IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
|
// Find the next index;
|
||||||
IConsole[] consoles = consoleManager.getConsoles();
|
int index = findNextIndex(consoleManager, connection);
|
||||||
boolean[] indices = new boolean[consoles.length];
|
|
||||||
for (IConsole console : consoles) {
|
|
||||||
if (console instanceof TerminalConsole) {
|
|
||||||
TerminalConsole terminalConsole = (TerminalConsole) console;
|
|
||||||
if (terminalConsole.getConnection().equals(connection)) {
|
|
||||||
indices[terminalConsole.getIndex()] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int index = 0;
|
|
||||||
while (index < indices.length && indices[index]) {
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
TerminalConsole terminalConsole = new TerminalConsole(connection, index, encoding);
|
TerminalConsole terminalConsole = new TerminalConsole(connection, index, encoding);
|
||||||
consoleManager.addConsoles(new IConsole[] { terminalConsole });
|
consoleManager.addConsoles(new IConsole[] { terminalConsole });
|
||||||
consoleManager.showConsoleView(terminalConsole);
|
consoleManager.showConsoleView(terminalConsole);
|
||||||
|
return terminalConsole;
|
||||||
return Status.OK_STATUS;
|
}
|
||||||
} catch (RemoteConnectionException e) {
|
|
||||||
return e.getStatus();
|
private static int findNextIndex(IConsoleManager consoleManager, IRemoteConnection connection) {
|
||||||
|
IConsole[] consoles = consoleManager.getConsoles();
|
||||||
|
boolean[] indices = new boolean[consoles.length];
|
||||||
|
for (IConsole console : consoles) {
|
||||||
|
if (console instanceof TerminalConsole) {
|
||||||
|
TerminalConsole terminalConsole = (TerminalConsole) console;
|
||||||
|
if (terminalConsole.getConnection().equals(connection)) {
|
||||||
|
indices[terminalConsole.getIndex()] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.schedule();
|
}
|
||||||
|
int index = 0;
|
||||||
|
while (index < indices.length && indices[index]) {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public static List<IConsole> findConsole(IRemoteConnection connection) {
|
||||||
|
ArrayList<IConsole> ret = new ArrayList<IConsole>();
|
||||||
|
IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
|
||||||
|
IConsole[] consoles = consoleManager.getConsoles();
|
||||||
|
for (IConsole console : consoles) {
|
||||||
|
if (console instanceof TerminalConsole) {
|
||||||
|
TerminalConsole terminalConsole = (TerminalConsole) console;
|
||||||
|
if (terminalConsole.getConnection().equals(connection)) {
|
||||||
|
ret.add(terminalConsole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -148,7 +148,7 @@ public class TerminalConsolePage extends Page {
|
||||||
|
|
||||||
public void disconnectTerminal() {
|
public void disconnectTerminal() {
|
||||||
if (tViewCtrl.getState() != TerminalState.CLOSED) {
|
if (tViewCtrl.getState() != TerminalState.CLOSED) {
|
||||||
tViewCtrl.getTerminalConnector().disconnect();
|
tViewCtrl.disconnectTerminal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue