Move inner classes into tool package
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
acf4484eb3
commit
79ee5394d4
@ -46,7 +46,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>2.0.12</version>
|
<version>2.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
|
@ -46,7 +46,7 @@ import java.io.IOException;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.exception.CommandRunException;
|
import net.bigeon.gclc.exception.CommandRunException;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -38,103 +38,14 @@ package net.bigeon.gclc.swt;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
import org.eclipse.swt.widgets.Widget;
|
|
||||||
|
|
||||||
import net.bigeon.gclc.utils.AOutputForwardRunnable;
|
import net.bigeon.gclc.swt.tools.ToSWTConsoleForwardRunnable;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
||||||
|
|
||||||
/** The manager for console output to insert in a text.
|
/** The manager for console output to insert in a text.
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public final class ConsoleOutputManager implements ConsoleOutputDisplay {
|
public final class ConsoleOutputManager implements ConsoleOutputDisplay {
|
||||||
/** A runnable appending text to the content of a {@link Text} component.
|
|
||||||
*
|
|
||||||
* @author Emmanuel Bigeon */
|
|
||||||
private static class TextAppendingRunnable implements Runnable {
|
|
||||||
/** The text to append on a line (possibly new). */
|
|
||||||
private final String next;
|
|
||||||
/** The {@link Text} component. */
|
|
||||||
private final Text text;
|
|
||||||
|
|
||||||
/** Create the appending runnable.
|
|
||||||
*
|
|
||||||
* @param text the component to update
|
|
||||||
* @param next the text to append */
|
|
||||||
public TextAppendingRunnable(final Text text, final String next) {
|
|
||||||
this.text = text;
|
|
||||||
this.next = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see java.lang.Runnable#run() */
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
final String initialText = text.getText();
|
|
||||||
if (initialText != null && !initialText.isEmpty()) {
|
|
||||||
text.append(System.lineSeparator());
|
|
||||||
}
|
|
||||||
text.append(next);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The local implementation of the forwarding runnable.
|
|
||||||
*
|
|
||||||
* @author Emmanuel Bigeon */
|
|
||||||
private static final class ToSWTConsoleForwardRunnable
|
|
||||||
extends AOutputForwardRunnable {
|
|
||||||
/** The running status. */
|
|
||||||
private boolean running = true;
|
|
||||||
/** The console output. */
|
|
||||||
private final PipedConsoleOutput out;
|
|
||||||
/** The console output display. */
|
|
||||||
private final ConsoleOutputDisplay display;
|
|
||||||
/** The actual SWT component. */
|
|
||||||
private final Widget element;
|
|
||||||
|
|
||||||
/** Create the forwarding runnable.
|
|
||||||
*
|
|
||||||
* @param manager the manager
|
|
||||||
* @param display the display
|
|
||||||
* @param element the composite */
|
|
||||||
public ToSWTConsoleForwardRunnable(final PipedConsoleOutput manager,
|
|
||||||
final ConsoleOutputDisplay display,
|
|
||||||
final Widget element) {
|
|
||||||
super(manager);
|
|
||||||
out = manager;
|
|
||||||
this.display = display;
|
|
||||||
this.element = element;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see
|
|
||||||
* net.bigeon.gclc.utils.AOutputForwardRunnable#forwardLine(java.lang.String) */
|
|
||||||
@Override
|
|
||||||
protected void forwardLine(final String m) {
|
|
||||||
display.appendLine(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see net.bigeon.gclc.utils.AOutputForwardRunnable#isRunning() */
|
|
||||||
@Override
|
|
||||||
protected boolean isRunning() {
|
|
||||||
return running && !element.isDisposed();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Set the running status.
|
|
||||||
*
|
|
||||||
* @param running the running to set */
|
|
||||||
public void setRunning(final boolean running) {
|
|
||||||
this.running = running;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get the output.
|
|
||||||
*
|
|
||||||
* @return the currently forwarded output */
|
|
||||||
public PipedConsoleOutput getOuput() {
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The SWT component displaying the output content. */
|
/** The SWT component displaying the output content. */
|
||||||
private final Text text;
|
private final Text text;
|
||||||
/** The forwarding runnable. */
|
/** The forwarding runnable. */
|
||||||
|
@ -41,6 +41,8 @@ import java.io.BufferedReader;
|
|||||||
|
|
||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Label;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.swt.tools.PromptReadingRunnable;
|
||||||
|
|
||||||
/** The manager for the console prompt updates.
|
/** The manager for the console prompt updates.
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
|
/** A runnable appending text to the content of a {@link Text} component.
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
public class TextAppendingRunnable implements Runnable {
|
||||||
|
/** The text to append on a line (possibly new). */
|
||||||
|
private final String next;
|
||||||
|
/** The {@link Text} component. */
|
||||||
|
private final Text text;
|
||||||
|
|
||||||
|
/** Create the appending runnable.
|
||||||
|
*
|
||||||
|
* @param text the component to update
|
||||||
|
* @param next the text to append */
|
||||||
|
public TextAppendingRunnable(final Text text, final String next) {
|
||||||
|
this.text = text;
|
||||||
|
this.next = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Runnable#run() */
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
final String initialText = text.getText();
|
||||||
|
if (initialText != null && !initialText.isEmpty()) {
|
||||||
|
text.append(System.lineSeparator());
|
||||||
|
}
|
||||||
|
text.append(next);
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt.tools;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
@ -0,0 +1,68 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt.tools;
|
||||||
|
|
||||||
|
import org.eclipse.swt.widgets.Widget;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.swt.ConsoleOutputDisplay;
|
||||||
|
import net.bigeon.gclc.utils.AOutputForwardRunnable;
|
||||||
|
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
||||||
|
|
||||||
|
/** The local implementation of the forwarding runnable.
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
public final class ToSWTConsoleForwardRunnable
|
||||||
|
extends AOutputForwardRunnable {
|
||||||
|
/** The running status. */
|
||||||
|
private boolean running = true;
|
||||||
|
/** The console output. */
|
||||||
|
private final PipedConsoleOutput out;
|
||||||
|
/** The console output display. */
|
||||||
|
private final ConsoleOutputDisplay display;
|
||||||
|
/** The actual SWT component. */
|
||||||
|
private final Widget element;
|
||||||
|
|
||||||
|
/** Create the forwarding runnable.
|
||||||
|
*
|
||||||
|
* @param manager the manager
|
||||||
|
* @param display the display
|
||||||
|
* @param element the composite */
|
||||||
|
public ToSWTConsoleForwardRunnable(final PipedConsoleOutput manager,
|
||||||
|
final ConsoleOutputDisplay display,
|
||||||
|
final Widget element) {
|
||||||
|
super(manager);
|
||||||
|
out = manager;
|
||||||
|
this.display = display;
|
||||||
|
this.element = element;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see
|
||||||
|
* net.bigeon.gclc.utils.AOutputForwardRunnable#forwardLine(java.lang.String) */
|
||||||
|
@Override
|
||||||
|
protected void forwardLine(final String m) {
|
||||||
|
display.appendLine(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.bigeon.gclc.utils.AOutputForwardRunnable#isRunning() */
|
||||||
|
@Override
|
||||||
|
protected boolean isRunning() {
|
||||||
|
return running && !element.isDisposed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set the running status.
|
||||||
|
*
|
||||||
|
* @param running the running to set */
|
||||||
|
public void setRunning(final boolean running) {
|
||||||
|
this.running = running;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the output.
|
||||||
|
*
|
||||||
|
* @return the currently forwarded output */
|
||||||
|
public PipedConsoleOutput getOuput() {
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/** Tool classes for the library. External code should not rely on classes in
|
||||||
|
* there as they can be removed without notice.
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
package net.bigeon.gclc.swt.tools;
|
||||||
|
|
@ -53,6 +53,8 @@ import org.junit.Test;
|
|||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.swt.tools.PromptReadingRunnable;
|
||||||
|
|
||||||
/** @author Emmanuel Bigeon */
|
/** @author Emmanuel Bigeon */
|
||||||
public class PromptReadingRunnableTest {
|
public class PromptReadingRunnableTest {
|
||||||
private final Label view = mock(Label.class);
|
private final Label view = mock(Label.class);
|
||||||
@ -72,7 +74,7 @@ public class PromptReadingRunnableTest {
|
|||||||
}).when(display).syncExec(any(Runnable.class));
|
}).when(display).syncExec(any(Runnable.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for {@link net.bigeon.gclc.swt.PromptReadingRunnable#run()}.
|
/** Test method for {@link net.bigeon.gclc.swt.tools.PromptReadingRunnable#run()}.
|
||||||
*
|
*
|
||||||
* @throws IOException if an error occurred */
|
* @throws IOException if an error occurred */
|
||||||
@Test
|
@Test
|
||||||
@ -85,7 +87,7 @@ public class PromptReadingRunnableTest {
|
|||||||
runnable.run();
|
runnable.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for {@link net.bigeon.gclc.swt.PromptReadingRunnable#run()}.
|
/** Test method for {@link net.bigeon.gclc.swt.tools.PromptReadingRunnable#run()}.
|
||||||
*
|
*
|
||||||
* @throws IOException if an error occurred */
|
* @throws IOException if an error occurred */
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user