Author: ffang
Date: Tue Dec 4 04:08:14 2012
New Revision: 1416768
URL: http://svn.apache.org/viewvc?rev=1416768&view=rev
Log:
Merged revisions 1416766 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1416766 | ffang | 2012-12-04 11:54:49 +0800 (二, 04 12 2012) | 1 line
[CXF-4654]cxf:list-buses - Table layout should be aligned if bus name is long
........
Modified:
cxf/branches/2.6.x-fixes/ (props changed)
cxf/branches/2.6.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java
Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Merged /cxf/trunk:r1416766
Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.6.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java?rev=1416768&r1=1416767&r2=1416768&view=diff
==============================================================================
---
cxf/branches/2.6.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java
(original)
+++
cxf/branches/2.6.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java
Tue Dec 4 04:08:14 2012
@@ -31,9 +31,10 @@ import org.apache.karaf.shell.console.Os
*/
@Command(scope = "cxf", name = "list-busses", description = "Lists all CXF
Busses.")
public class ListBussesCommand extends OsgiCommandSupport {
- protected static final String HEADER_FORMAT = "%-40s %-20s";
- protected static final String OUTPUT_FORMAT = "[%-38s] [%-18s]";
-
+ protected static final int DEFAULT_BUSID_LENGTH = 38;
+ protected String headerFormat = "%-40s %-20s";
+ protected String outputFormat = "[%-38s] [%-18s]";
+
private CXFController cxfController;
public void setController(CXFController controller) {
@@ -42,15 +43,29 @@ public class ListBussesCommand extends O
protected Object doExecute() throws Exception {
List<Bus> busses = cxfController.getBusses();
- System.out.println(String.format(HEADER_FORMAT, "Name", "State"));
+ renderFormat(busses);
+ System.out.println(String.format(headerFormat, "Name", "State"));
for (Bus bus : busses) {
String state = "";
if (bus instanceof CXFBusImpl) {
state = ((CXFBusImpl)bus).getState().toString();
}
- System.out.println(String.format(OUTPUT_FORMAT, bus.getId(),
state));
+ System.out.println(String.format(outputFormat, bus.getId(),
state));
}
return null;
}
+
+ private void renderFormat(List<Bus> busses) {
+ int longestBusId = DEFAULT_BUSID_LENGTH;
+ for (Bus bus : busses) {
+ if (bus.getId().length() > longestBusId) {
+ longestBusId = bus.getId().length();
+ }
+ }
+ if (longestBusId > DEFAULT_BUSID_LENGTH) {
+ headerFormat = "%-" + (longestBusId + 2) + "s %-20s";
+ outputFormat = "[%-" + longestBusId + "s] [%-18s]";
+ }
+ }
}