Update prompt for dynamic value
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
@@ -82,7 +82,7 @@
|
||||
<dependency>
|
||||
<groupId>fr.bigeon</groupId>
|
||||
<artifactId>gclc</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.0.4-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.bigeon</groupId>
|
||||
|
||||
@@ -50,6 +50,8 @@ import org.eclipse.swt.widgets.Text;
|
||||
import fr.bigeon.gclc.ConsoleApplication;
|
||||
import fr.bigeon.gclc.manager.ConsoleInput;
|
||||
import fr.bigeon.gclc.manager.ConsoleOutput;
|
||||
import fr.bigeon.gclc.tools.ConstantString;
|
||||
import fr.bigeon.gclc.tools.StringProvider;
|
||||
|
||||
/** A SWT component to connect to gclc {@link ConsoleApplication}.
|
||||
* <p>
|
||||
@@ -73,7 +75,7 @@ public final class SWTConsole extends Composite
|
||||
/** The prompt label. */
|
||||
private final Label lblPromptlabel;
|
||||
/** The prompt text. */
|
||||
private String prompt = ">"; //$NON-NLS-1$
|
||||
private StringProvider prompt = new ConstantString("> "); //$NON-NLS-1$
|
||||
/** The command entered by the user. */
|
||||
private String command = null;
|
||||
/** If the prompt should be active. */
|
||||
@@ -97,7 +99,7 @@ public final class SWTConsole extends Composite
|
||||
consoleOutput.setRedraw(true);
|
||||
|
||||
lblPromptlabel = new Label(this, SWT.NONE);
|
||||
lblPromptlabel.setText(prompt);
|
||||
lblPromptlabel.setText(prompt.apply());
|
||||
|
||||
consoleInput = new Text(this, SWT.BORDER);
|
||||
consoleInput.setLayoutData(
|
||||
@@ -135,7 +137,7 @@ public final class SWTConsole extends Composite
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.ConsoleManager#getPrompt() */
|
||||
@Override
|
||||
public String getPrompt() {
|
||||
public StringProvider getPrompt() {
|
||||
return prompt;
|
||||
}
|
||||
|
||||
@@ -216,6 +218,7 @@ public final class SWTConsole extends Composite
|
||||
public void run() {
|
||||
if (!consoleInput.isDisposed()) {
|
||||
consoleInput.setEnabled(true);
|
||||
lblPromptlabel.setText(prompt.apply());
|
||||
consoleInput.setFocus();
|
||||
}
|
||||
}
|
||||
@@ -284,7 +287,7 @@ public final class SWTConsole extends Composite
|
||||
@Override
|
||||
public void run() {
|
||||
if (!consoleOutput.isDisposed()) {
|
||||
lblPromptlabel.setText(prompt);
|
||||
lblPromptlabel.setText(prompt.apply());
|
||||
// relayout
|
||||
SWTConsole.this.layout();
|
||||
}
|
||||
@@ -323,20 +326,25 @@ public final class SWTConsole extends Composite
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.ConsoleManager#setPrompt(java.lang.String) */
|
||||
@Override
|
||||
public void setPrompt(final String prompt) {
|
||||
public void setPrompt(final StringProvider prompt) {
|
||||
this.prompt = prompt;
|
||||
Display.getDefault().syncExec(new Runnable() {
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
if (!consoleOutput.isDisposed()) {
|
||||
lblPromptlabel.setText(prompt);
|
||||
lblPromptlabel.setText(prompt.apply());
|
||||
// relayout
|
||||
SWTConsole.this.layout();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrompt(String prompt) {
|
||||
setPrompt(new ConstantString(prompt));
|
||||
}
|
||||
|
||||
/** @param string the text */
|
||||
public void setText(final String string) {
|
||||
|
||||
Reference in New Issue
Block a user