Format
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
d7ecd75678
commit
d49a2474e0
@ -137,7 +137,8 @@ public final class HistoryTextKeyListener extends KeyAdapter {
|
|||||||
}
|
}
|
||||||
currentIndex = -1;
|
currentIndex = -1;
|
||||||
} else {
|
} else {
|
||||||
final String cmd = commands.get(commands.size() - (--currentIndex) - 1);
|
currentIndex--;
|
||||||
|
final String cmd = commands.get(commands.size() - currentIndex - 1);
|
||||||
console.setInput(cmd);
|
console.setInput(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ import net.bigeon.gclc.tools.StringProvider;
|
|||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public final class SWTConsole extends Composite
|
public final class SWTConsole extends Composite
|
||||||
implements ConsoleDelayIO, ConsoleInput, ConsoleOutput {
|
implements ConsoleDelayIO, ConsoleInput, ConsoleOutput {
|
||||||
|
private static final int TWO = 2;
|
||||||
private static final String ERROR_SYNCHRO_PROMPT = "Error in synchronization of prompting";
|
private static final String ERROR_SYNCHRO_PROMPT = "Error in synchronization of prompting";
|
||||||
/** The number of columns of the layout. */
|
/** The number of columns of the layout. */
|
||||||
private static final int LAYOUT_NB_COLUMNS = 2;
|
private static final int LAYOUT_NB_COLUMNS = 2;
|
||||||
@ -102,6 +103,7 @@ public final class SWTConsole extends Composite
|
|||||||
.getLogger(SWTConsole.class.getName());
|
.getLogger(SWTConsole.class.getName());
|
||||||
/** The empty string constant. */
|
/** The empty string constant. */
|
||||||
private static final String EMPTY = ""; //$NON-NLS-1$
|
private static final String EMPTY = ""; //$NON-NLS-1$
|
||||||
|
|
||||||
/** The console output text field. */
|
/** The console output text field. */
|
||||||
private final Text consoleOutput;
|
private final Text consoleOutput;
|
||||||
/** The console input text field. */
|
/** The console input text field. */
|
||||||
@ -141,6 +143,8 @@ public final class SWTConsole extends Composite
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.swt.widgets.Composite#checkSubclass() */
|
||||||
@Override
|
@Override
|
||||||
protected void checkSubclass() {
|
protected void checkSubclass() {
|
||||||
// Disable the check that prevents subclassing of SWT components
|
// Disable the check that prevents subclassing of SWT components
|
||||||
@ -258,7 +262,7 @@ public final class SWTConsole extends Composite
|
|||||||
promptLock.wait();
|
promptLock.wait();
|
||||||
}
|
}
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e); //$NON-NLS-1$
|
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e);
|
||||||
command = null;
|
command = null;
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
@ -302,21 +306,13 @@ public final class SWTConsole extends Composite
|
|||||||
initPrompt(prompt.apply());
|
initPrompt(prompt.apply());
|
||||||
promptLock.notifyAll();
|
promptLock.notifyAll();
|
||||||
try {
|
try {
|
||||||
final long start = System.currentTimeMillis();
|
waitPromptResolution(timeout);
|
||||||
long cur = start;
|
|
||||||
while (prompting && start + timeout > cur) {
|
|
||||||
promptLock.wait((cur - start - timeout) / 2);
|
|
||||||
cur = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e); //$NON-NLS-1$
|
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e);
|
||||||
command = null;
|
command = null;
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isDisposed()) {
|
|
||||||
throw new IOException("Input closed"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,7 +331,7 @@ public final class SWTConsole extends Composite
|
|||||||
throw new IOException();
|
throw new IOException();
|
||||||
}
|
}
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e); //$NON-NLS-1$
|
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e);
|
||||||
command = null;
|
command = null;
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
} finally {
|
} finally {
|
||||||
@ -353,17 +349,9 @@ public final class SWTConsole extends Composite
|
|||||||
initPrompt(message);
|
initPrompt(message);
|
||||||
promptLock.notifyAll();
|
promptLock.notifyAll();
|
||||||
try {
|
try {
|
||||||
final long start = System.currentTimeMillis();
|
waitPromptResolution(timeout);
|
||||||
long cur = start;
|
|
||||||
while (prompting && start + timeout > cur) {
|
|
||||||
promptLock.wait((cur - start - timeout) / 2);
|
|
||||||
cur = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
if (isDisposed()) {
|
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e); //$NON-NLS-1$
|
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e);
|
||||||
command = null;
|
command = null;
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
} finally {
|
} finally {
|
||||||
@ -373,6 +361,24 @@ public final class SWTConsole extends Composite
|
|||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Wait the prompt resolution by user.
|
||||||
|
*
|
||||||
|
* @param timeout the timeout for the wait
|
||||||
|
* @throws InterruptedException if the thread is interrupted
|
||||||
|
* @throws IOException if the console is disposed. */
|
||||||
|
private void waitPromptResolution(final long timeout)
|
||||||
|
throws InterruptedException, IOException {
|
||||||
|
final long start = System.currentTimeMillis();
|
||||||
|
long cur = start;
|
||||||
|
while (prompting && start + timeout > cur) {
|
||||||
|
promptLock.wait((cur - start - timeout) / TWO);
|
||||||
|
cur = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
if (isDisposed()) {
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Reset the prompt message. */
|
/** Reset the prompt message. */
|
||||||
private void resetPrompt() {
|
private void resetPrompt() {
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
Display.getDefault().syncExec(new Runnable() {
|
||||||
@ -403,8 +409,10 @@ public final class SWTConsole extends Composite
|
|||||||
consoleInput.setSelection(input.length());
|
consoleInput.setSelection(input.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
|
||||||
@Override
|
@Override
|
||||||
public void setPrompt(String prompt) {
|
public void setPrompt(final String prompt) {
|
||||||
setPrompt(new ConstantString(prompt));
|
setPrompt(new ConstantString(prompt));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,21 +434,15 @@ public final class SWTConsole extends Composite
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param string the text */
|
/** Set the input text.
|
||||||
|
*
|
||||||
|
* @param string the text */
|
||||||
public void setText(final String string) {
|
public void setText(final String string) {
|
||||||
consoleInput.setText(string);
|
consoleInput.setText(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* (non-Javadoc)
|
||||||
*
|
* @see net.bigeon.gclc.swt.ConsoleDelayIO#validateInput() */
|
||||||
*/
|
|
||||||
public void validateCommand() {
|
|
||||||
validateInput();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void validateInput() {
|
public void validateInput() {
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
Display.getDefault().syncExec(new Runnable() {
|
||||||
|
Loading…
Reference in New Issue
Block a user