Explorar o código

1.重构了程序。
2.添加了java控制台。

YangZhiJie %!s(int64=7) %!d(string=hai) anos
pai
achega
f723bd4012
Modificáronse 36 ficheiros con 1798 adicións e 677 borrados
  1. 5 0
      .classpath
  2. 1 0
      .settings/org.eclipse.core.resources.prefs
  3. 1 0
      autoStart.bat
  4. 64 36
      config/applicationContext.xml
  5. 63 45
      pom.xml
  6. 8 8
      src/main/java/com/leanwo/management/App.java
  7. 390 0
      src/main/java/com/leanwo/management/MainFrame.java
  8. 247 0
      src/main/java/com/leanwo/management/ServerFrame.java
  9. 108 0
      src/main/java/com/leanwo/management/ServerLogFrame.java
  10. 0 485
      src/main/java/com/leanwo/management/ServerManagmentJFrame.java
  11. 6 6
      src/main/java/com/leanwo/management/SettingEditFrame.java
  12. 145 0
      src/main/java/com/leanwo/management/console/LogConsole.java
  13. 1 1
      src/main/java/com/leanwo/management/exception/BeanNotInjectException.java
  14. 1 1
      src/main/java/com/leanwo/management/exception/ConfigFileException.java
  15. 101 87
      src/main/java/com/leanwo/management/model/ApplicationSetting.java
  16. 3 1
      src/main/java/com/leanwo/management/service/AutoUpdateService.java
  17. 95 0
      src/main/java/com/leanwo/management/service/FileService.java
  18. 54 0
      src/main/java/com/leanwo/management/service/HttpService.java
  19. 188 0
      src/main/java/com/leanwo/management/service/ProcessService.java
  20. 50 0
      src/main/java/com/leanwo/management/service/ProgramRunResult.java
  21. 18 0
      src/main/java/com/leanwo/management/service/StatusService.java
  22. 51 0
      src/main/java/com/leanwo/management/util/CloseableUtil.java
  23. 1 1
      src/main/java/com/leanwo/management/util/ProgramAutoStartUtil.java
  24. 1 1
      src/main/java/com/leanwo/management/util/ProgramStartUtil.java
  25. 1 1
      src/main/java/com/leanwo/management/util/ProgramStopUtil.java
  26. 3 2
      src/main/java/com/leanwo/management/util/SpringUtil.java
  27. 2 2
      src/main/java/com/leanwo/management/util/XmlConfigPathService.java
  28. 43 0
      src/main/java/com/leanwo/management/widget/ColorCellRenderer.java
  29. 30 0
      src/main/java/com/leanwo/management/widget/DefaultMenuListener.java
  30. 12 0
      src/main/java/com/leanwo/management/widget/SelectEventListener.java
  31. 20 0
      src/main/java/com/leanwo/management/widget/SelectObject.java
  32. 78 0
      src/main/java/com/leanwo/management/widget/TableButtonCell.java
  33. 7 0
      src/main/java/com/leanwo/management/widget/TableButtonListener.java
  34. 0 0
      src/main/resources/com/leanwo/management/prodog_16.png
  35. 0 0
      src/main/resources/commons-logging.properties
  36. 0 0
      src/main/resources/log4j.properties

+ 5 - 0
.classpath

@@ -22,5 +22,10 @@
 			<attribute name="maven.pomderived" value="true"/>
 		</attributes>
 	</classpathentry>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
 	<classpathentry kind="output" path="target/classes"/>
 </classpath>

+ 1 - 0
.settings/org.eclipse.core.resources.prefs

@@ -1,4 +1,5 @@
 eclipse.preferences.version=1
 encoding//src/main/java=UTF-8
+encoding//src/main/resources=UTF-8
 encoding//src/test/java=UTF-8
 encoding/<project>=UTF-8

+ 1 - 0
autoStart.bat

@@ -1,2 +1,3 @@
+title Server Management
 CD D:\LeanwoProgram_2018\OtherServer\ServerManagement
 D:

+ 64 - 36
config/applicationContext.xml

@@ -10,11 +10,17 @@
 
 	<!-- 自动扫描 -->
 	<context:component-scan base-package="com.leanwo" />
-
-	<bean id="autoUpdateService" class="org.leanwo.management.util.AutoUpdateService">
-		<property name="updateSite" value="http://192.168.1.200:8888/AutoUpdate"></property>
-	</bean>	
 	
+	<bean id="springUtil" class="com.leanwo.management.util.SpringUtil" />
+	
+	<bean id="processService" class="com.leanwo.management.service.ProcessService"></bean>
+	<bean id="httpService" class="com.leanwo.management.service.HttpService"></bean>
+	<bean id="fileService" class="com.leanwo.management.service.FileService"></bean>
+	<bean id="xmlConfigPathService" class="com.leanwo.management.util.XmlConfigPathService"/>
+	
+	<bean id="autoUpdateService" class="com.leanwo.management.service.AutoUpdateService">
+		<property name="updateSite" value="http://192.168.1.200:8888/AutoUpdate"></property>
+	</bean>
 	
 	<bean id="applicationSettingCache" class="com.leanwo.management.model.ApplicationSettingCache">
 		<property name="settings">
@@ -32,8 +38,9 @@
 	</bean>
 
 	<bean id="applicationSetting1" class="com.leanwo.management.model.ApplicationSetting">
-		<property name="name" value="Prodog服务程序"></property>
-		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
+		<property name="name" value="Prodog应用服务程序"></property>
+		<property name="installPath" value="D:\ProdogServers\ProdogServer"></property>
+		<property name="startCommand" value="javaw -jar D:\ProdogServers\ProdogServer\ProdogBoot-0.0.1.jar"></property>
 		<property name="startBatFile" value="start.bat"></property>
 		<property name="stopBatFile" value="stop.bat"></property>
 		<property name="autoUpdateFileNames">
@@ -55,8 +62,37 @@
 	</bean>
 	
 	<bean id="applicationSetting2" class="com.leanwo.management.model.ApplicationSetting">
+		<property name="name" value="文件服务程序"></property>
+		<property name="installPath" value="D:\ProdogServers\FileServer"></property>
+		<property name="startCommand" value="javaw -jar D:\ProdogServers\FileServer\FileServer-0.0.1-SNAPSHOT.jar"></property>
+		<property name="stopBatFile" value="stop.bat"></property>
+		<property name="monitorUrl" value="http://127.0.0.1:85/api/monitor"></property>
+		<property name="token" value="123456"></property>
+	</bean>
+	
+	<bean id="applicationSetting3" class="com.leanwo.management.model.ApplicationSetting">
+		<property name="name" value="反向代理服务"></property>
+		<property name="installPath" value="D:\ProdogServers\nginx-1.13.8"></property>
+		<property name="startCommand" value="D:\ProdogServers\nginx-1.13.8\nginx.exe"></property>
+		<property name="stopBatFile" value="stop.bat"></property>
+		<property name="monitorUrl" value="http://127.0.0.1:85/api/monitor"></property>
+		<property name="token" value="123456"></property>
+	</bean>
+	
+	<bean id="applicationSetting4" class="com.leanwo.management.model.ApplicationSetting">
+		<property name="name" value="工作流服务程序"></property>
+		<property name="installPath" value="D:\ProdogServers\WorkflowServer"></property>
+		<property name="startCommand" value="javaw -jar D:\ProdogServers\WorkflowServer\ActivitiServer-0.0.1-SNAPSHOT.jar"></property>
+		<property name="startBatFile" value="start.bat"></property>
+		<property name="stopBatFile" value="stop.bat"></property>
+		<property name="monitorUrl" value="http://127.0.0.1:82/activiti/explorer/monitor"></property>
+		<property name="token" value="123456"></property>
+	</bean>
+	
+	<bean id="applicationSetting5" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="报表服务程序"></property>
-		<property name="installPath" value="C:\Users\TianGuangHui\Service\Report_Server_20171218"></property>
+		<property name="installPath" value="D:\ProdogServers\ReportServer"></property>
+		<property name="startCommand" value="javaw -jar D:\ProdogServers\ReportServer\report-server-0.0.1-SNAPSHOT.jar"></property>
 		<property name="startBatFile" value="start.bat"></property>
 		<property name="stopBatFile" value="stop.bat"></property>
 		<property name="monitorUrl" value="http://127.0.0.1:81/monitor"></property>
@@ -81,57 +117,49 @@
 		</property>		
 	</bean>
 	
-	<bean id="applicationSetting3" class="com.leanwo.management.model.ApplicationSetting">
-		<property name="name" value="工作流服务程序"></property>
-		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
-		<property name="startBatFile" value="start.bat"></property>
-		<property name="stopBatFile" value="stop.bat"></property>
-		<property name="monitorUrl" value="http://127.0.0.1:82/activiti/explorer/monitor"></property>
-		<property name="token" value="123456"></property>
-	</bean>
 	
-	<bean id="applicationSetting4" class="com.leanwo.management.model.ApplicationSetting">
+	<bean id="applicationSetting6" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="钉钉服务程序"></property>
-		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
+		<property name="installPath" value="D:\ProdogServers\DingTalkServer"></property>
+		<property name="startCommand" value="javaw -jar D:\ProdogServers\DingTalkServer\DingDingServer-0.0.1-SNAPSHOT.jar"></property>
 		<property name="startBatFile" value="start.bat"></property>
 		<property name="stopBatFile" value="stop.bat"></property>
 		<property name="monitorUrl" value="http://127.0.0.1:83/monitor"></property>
 		<property name="token" value="123456"></property>
 	</bean>
 	
-	<bean id="applicationSetting5" class="com.leanwo.management.model.ApplicationSetting">
+	<bean id="applicationSetting7" class="com.leanwo.management.model.ApplicationSetting">
 		<property name="name" value="微信服务程序"></property>
-		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
+		<property name="installPath" value="D:\ProdogServers\WeChatServer"></property>
+		<property name="startCommand" value="javaw -jar D:\ProdogServers\WeChatServer\WeChatServer-0.0.1.jar"></property>
 		<property name="startBatFile" value="start.bat"></property>
 		<property name="stopBatFile" value="stop.bat"></property>
 		<property name="monitorUrl" value="http://127.0.0.1:80/monitor"></property>
 		<property name="token" value="123456"></property>
 	</bean>
 	
-	<bean id="applicationSetting6" class="com.leanwo.management.model.ApplicationSetting">
-		<property name="name" value="中间件程序"></property>
-		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
-		<property name="startBatFile" value="start.bat"></property>
+	<bean id="applicationSetting8" class="com.leanwo.management.model.ApplicationSetting">
+		<property name="name" value="排产程序"></property>
+		<property name="installPath" value="D:\ProdogServers\ApsServer"></property>
+		<property name="startCommand" value="javaw -jar D:\ProdogServers\ApsServer\ProdogAssign-0.0.1.jar"></property>
 		<property name="stopBatFile" value="stop.bat"></property>
+		<property name="monitorUrl" value="http://127.0.0.1:85/api/monitor"></property>
+		<property name="token" value="123456"></property>
 	</bean>
 	
-	<bean id="applicationSetting7" class="com.leanwo.management.model.ApplicationSetting">
-		<property name="name" value="抓拍程序"></property>
-		<property name="installPath" value="C:\Users\YangZhiJie\Desktop\Servers\DingTalk_Server_20171218"></property>
+	<bean id="applicationSetting9" class="com.leanwo.management.model.ApplicationSetting">
+		<property name="name" value="中间件程序"></property>
+		<property name="installPath" value=""></property>
+		<property name="startCommand" value="javaw -jar"></property>
 		<property name="startBatFile" value="start.bat"></property>
 		<property name="stopBatFile" value="stop.bat"></property>
 	</bean>
 	
-	<bean id="applicationSetting8" class="com.leanwo.management.model.ApplicationSetting">
-		<property name="name" value="文件服务程序"></property>
+	<bean id="applicationSetting10" class="com.leanwo.management.model.ApplicationSetting">
+		<property name="name" value="抓拍程序"></property>
 		<property name="installPath" value=""></property>
-		<property name="startBatFile" value=""></property>
-		<property name="stopBatFile" value=""></property>
-		<property name="monitorUrl" value="http://127.0.0.1:85/api/monitor"></property>
-		<property name="token" value="123456"></property>
+		<property name="startCommand" value="javaw -jar"></property>
+		<property name="startBatFile" value="start.bat"></property>
+		<property name="stopBatFile" value="stop.bat"></property>
 	</bean>
-	
-	<bean id="springUtil" class="org.leanwo.management.util.SpringUtil" />
-	<bean id="xmlConfigPathService" class="org.leanwo.management.util.XmlConfigPathService"/>
-	
 </beans>

+ 63 - 45
pom.xml

@@ -88,6 +88,18 @@
 	
 	
 	<build>
+		<resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+                <includes>
+                    <include>**/*.png</include>
+                    <include>**/*.properties</include>
+                    <include>**/*.xml</include>
+                </includes>
+            </resource>
+        </resources>
+        
 		<plugins>
 	  		<plugin>
 	    		<groupId>org.apache.maven.plugins</groupId>
@@ -98,49 +110,39 @@
 	    		</configuration>
 	  		</plugin>
 	  		
-	  		
-	  		<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-shade-plugin</artifactId>
-				<version>3.1.0</version>
-				<executions>
-					<execution>
-						<phase>package</phase>
-						<goals>
-							<goal>shade</goal>
-						</goals>
-						<configuration>
-							<filters>  
-                            	<filter>  
-	                                <artifact>*:*</artifact>  
-	                                <excludes>  
-	                                    <exclude>META-INF/*.SF</exclude>  
-	                                    <exclude>META-INF/*.DSA</exclude>  
-	                                    <exclude>META-INF/*.RSA</exclude>  
-	                                </excludes>  
-	                            </filter>  
-	                        </filters>
-							<transformers>
-								<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
-									<resource>META-INF/spring.schemas</resource>
-								</transformer> 
-			                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">  
-			                        <resource>META-INF/spring.handlers</resource>  
-			                    </transformer>  
-								<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
-									<manifestEntries>
-										<Main-Class>org.leanwo.management.ServerManagementApp</Main-Class>
-									</manifestEntries>
-								</transformer>
-							</transformers>
-							<createDependencyReducedPom>false</createDependencyReducedPom>
-						</configuration>
-					</execution>
-				</executions>
-			</plugin>
-			
-			
-			
+			<plugin>
+	            <groupId>org.apache.maven.plugins</groupId>
+	            <artifactId>maven-jar-plugin</artifactId>
+	            <version>3.0.2</version>
+	            <configuration>
+	                <archive>
+	                    <manifest>
+	                        <addClasspath>true</addClasspath>
+	                        <classpathPrefix>lib/</classpathPrefix>
+	                        <mainClass>com.leanwo.management.App</mainClass>
+	                    </manifest>
+	                </archive>
+	            </configuration>
+	        </plugin>
+	        
+	        <plugin>
+	            <groupId>org.apache.maven.plugins</groupId>
+	            <artifactId>maven-dependency-plugin</artifactId>
+	            <version>2.10</version>
+	            <executions>
+	                <execution>
+	                    <id>copy-dependencies</id>
+	                    <phase>package</phase>
+	                    <goals>
+	                        <goal>copy-dependencies</goal>
+	                    </goals>
+	                    <configuration>
+	                        <outputDirectory>${project.build.directory}/lib</outputDirectory>
+	                    </configuration>
+	                </execution>
+	            </executions>
+	        </plugin>
+
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-resources-plugin</artifactId>
@@ -165,6 +167,23 @@
 								</resource>
 							</resources>
 						</configuration>
+					</execution>					
+					<execution>
+						<id>copy-resources-lib</id>
+						<phase>package</phase>
+						<goals>
+							<goal>copy-resources</goal>
+						</goals>
+						<configuration>
+							<encoding>UTF-8</encoding>
+							<outputDirectory>${project.build.directory}/ServerManagement/lib
+							</outputDirectory>
+							<resources>
+								<resource>
+									<directory>${project.build.directory}/lib/</directory>
+								</resource>
+							</resources>
+						</configuration>
 					</execution>
 					
 					<execution>
@@ -192,8 +211,7 @@
 								</resource>
 							</resources>
 						</configuration>
-					</execution>
-					
+					</execution>					
 				</executions>
 			</plugin>			
 		</plugins>

+ 8 - 8
src/main/java/org/leanwo/management/ServerManagementApp.java → src/main/java/com/leanwo/management/App.java

@@ -1,24 +1,24 @@
-package org.leanwo.management;
+package com.leanwo.management;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.leanwo.management.util.ProgramAutoStartUtil;
-import org.leanwo.management.util.ProgramStopUtil;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.FileSystemXmlApplicationContext;
 
-import com.leanwo.management.ServerManagmentJFrame;
+import com.leanwo.management.util.ProgramAutoStartUtil;
+import com.leanwo.management.util.ProgramStartUtil;
+import com.leanwo.management.util.ProgramStopUtil;
 
 /**
  * Hello world!
  *
  */
-public class ServerManagementApp {
+public class App {
 	
-	private static Log logger = LogFactory.getLog(ServerManagmentJFrame.class);
+	private static Log logger = LogFactory.getLog(App.class);
 
 	public static void main(String[] args) {
-		//ProgramStartUtil.generateStartBat();
+		ProgramStartUtil.generateStartBat();
 		ProgramAutoStartUtil.generateStartBat();
 		ProgramStopUtil.generateStopBat();
 		
@@ -37,6 +37,6 @@ public class ServerManagementApp {
 		}
 		
 		ApplicationContext factory = new FileSystemXmlApplicationContext("config/applicationContext.xml");
-		ServerManagmentJFrame serverManagmentJFrame = new ServerManagmentJFrame(isAutoRun);
+		MainFrame serverManagmentJFrame = new MainFrame(isAutoRun);
 	}
 }

+ 390 - 0
src/main/java/com/leanwo/management/MainFrame.java

@@ -0,0 +1,390 @@
+package com.leanwo.management;
+
+import java.awt.AWTEvent;
+import java.awt.AWTException;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Image;
+import java.awt.SystemTray;
+import java.awt.Toolkit;
+import java.awt.TrayIcon;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.imageio.ImageIO;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenu;
+import javax.swing.JOptionPane;
+import javax.swing.JToolBar;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
+
+import org.apache.commons.exec.ExecuteWatchdog;
+import org.apache.log4j.Logger;
+
+import com.leanwo.management.model.ApplicationSetting;
+import com.leanwo.management.model.ApplicationSettingCache;
+import com.leanwo.management.service.AutoUpdateService;
+import com.leanwo.management.service.ProcessService;
+import com.leanwo.management.service.ProgramRunResult;
+import com.leanwo.management.util.SpringUtil;
+import com.leanwo.management.widget.DefaultMenuListener;
+import com.leanwo.management.widget.SelectEventListener;
+import com.leanwo.management.widget.SelectObject;
+
+public class MainFrame extends JFrame{
+	private static Logger logger = Logger.getLogger(MainFrame.class);
+	
+	private JButton startMenu = null;
+	private JButton stopMenu = null;
+	private JButton upgradeMenu = null;
+	private JButton editConfigMenu = null;
+	private JButton startAllMenu = null;
+	
+	private ServerFrame serverFrame = null;
+	private ServerLogFrame serverLogFrame =  null;
+
+	private TrayIcon trayIcon;				// 托盘图标
+	private SystemTray systemTray;	// 系统托盘
+
+	// 得到显示器屏幕的宽高
+	private int width = Toolkit.getDefaultToolkit().getScreenSize().width;
+	private int height = Toolkit.getDefaultToolkit().getScreenSize().height;
+
+	// 定义窗体的宽高
+	private int windowsWidth = 800;
+	private int windowsHeight = 400;
+
+	private ApplicationSettingCache applicationSettingCache = null;
+	private List<ApplicationSetting> settings = null;
+	
+	/** 流程服务 */
+	private ProcessService processService = null;
+
+	/** 升级服务 */
+	private AutoUpdateService autoUpdateService = null;
+
+	/** 自动启动 */
+	private boolean isAutoStart;
+	
+	public MainFrame(boolean isAutoStart) {
+		this.isAutoStart = isAutoStart;
+		initData();
+		initView();
+		initMenuItem();
+	}
+	
+	private void initData() {
+		applicationSettingCache = (ApplicationSettingCache) SpringUtil.getSingleBean(ApplicationSettingCache.class);
+		settings = applicationSettingCache.getSettings();
+		processService = (ProcessService) SpringUtil.getSingleBean(ProcessService.class);
+		autoUpdateService = (AutoUpdateService) SpringUtil.getSingleBean(AutoUpdateService.class);
+	}
+	
+	private void initView() {
+		this.setLayout(new BorderLayout(5,5));
+
+        JToolBar toolbar = new JToolBar();
+        toolbar.setFloatable(false);
+        toolbar.setBorderPainted(false);
+        
+        add(toolbar, BorderLayout.NORTH);
+                
+        startMenu = new JButton("启动");
+        toolbar.add(startMenu);
+
+        stopMenu = new JButton("停止");
+        toolbar.add(stopMenu);
+        
+        upgradeMenu = new JButton("更新");
+        toolbar.add(upgradeMenu);
+
+        editConfigMenu = new JButton("设置");
+        toolbar.add(editConfigMenu);
+        
+        startAllMenu = new JButton("全部启动");
+        toolbar.add(startAllMenu);
+        
+		serverFrame = new ServerFrame(settings);
+		serverFrame.setPreferredSize(new Dimension(300, 0));
+        add(serverFrame, BorderLayout.WEST);
+        serverFrame.addStateChangeListener(new SelectEventListener() {
+			@Override
+			public void onSelect(SelectObject event) {
+				int index = event.getIndex();
+				refreshMenuStatus(index);
+				serverLogFrame.setSelectedIndex(index);
+			}
+		});
+        
+		serverLogFrame = new ServerLogFrame(settings);
+        add(serverLogFrame, BorderLayout.CENTER);
+        
+
+		this.setTitle("Prodog程序管理器");
+		// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设定按关闭时的操作,这里是关闭窗口,如果不设定,就什么也不会发生
+		
+		// 设置图标
+		URL path = MainFrame.class.getResource("prodog_16.png");
+		Image image;
+		try {
+			image = ImageIO.read(path);
+			this.setIconImage(image);
+		} catch (IOException e) {
+			logger.error("读取图片异常。", e);
+		}   
+		
+        // 激活窗口事件
+        this.enableEvents(AWTEvent.WINDOW_EVENT_MASK);
+        
+		// 设置窗体位置和大小
+		this.setBounds((width - windowsWidth) / 2, (height - windowsHeight) / 2, windowsWidth, windowsHeight);
+		
+        this.setVisible(true);
+        
+        if(isAutoStart) {
+        	processService.autoStart(settings, serverLogFrame);
+        }
+	}
+	
+	/**
+	 * 初始化菜单事件
+	 */
+	private void initMenuItem() {
+		startMenu.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				int selectedRow = serverFrame.getSelectedRow();
+				if(selectedRow >= 0 && selectedRow < settings.size()) {
+					ApplicationSetting setting = settings.get(selectedRow);
+					if(setting.getProgramRunResult() != null) {
+						JOptionPane.showMessageDialog(null, "程序已经运行", "程序已经运行", JOptionPane.ERROR_MESSAGE);
+						return;
+					}
+					
+					try {
+						ProgramRunResult programRunResult = processService.startProgram(setting);
+						if(programRunResult == null || programRunResult.getWatchDog() == null) {
+							JOptionPane.showMessageDialog(null, "未配置启动文件或启动命令", "配置异常", JOptionPane.ERROR_MESSAGE);
+						}else {
+							setting.setProgramRunResult(programRunResult);
+							serverLogFrame.updateProgramRunResult(selectedRow, programRunResult);
+						}
+					} catch (IOException e1) {
+						JOptionPane.showMessageDialog(null, e1.getMessage(), "程序启动异常", JOptionPane.ERROR_MESSAGE);
+						logger.error("启动异常", e1);
+					}
+				}else {
+					JOptionPane.showMessageDialog(null, "请先选择服务器", "请先选择服务器", JOptionPane.ERROR_MESSAGE);
+				}
+			}
+		});
+		
+		stopMenu.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				int selectedRow = serverFrame.getSelectedRow();
+				if(selectedRow >= 0 && selectedRow < settings.size()) {
+					ApplicationSetting setting = settings.get(selectedRow);
+					try {
+						ProgramRunResult programRunResult = setting.getProgramRunResult();
+						if(programRunResult != null && programRunResult.getWatchDog() != null) {
+							programRunResult.getWatchDog().destroyProcess();
+						}
+						
+						programRunResult = processService.stopProgram(setting);
+						if(programRunResult == null || programRunResult.getWatchDog() == null) {
+							JOptionPane.showMessageDialog(null, "未配置停止文件", "配置异常", JOptionPane.ERROR_MESSAGE);
+						}else {
+							setting.setProgramRunResult(null);
+						}				
+					} catch (IOException e1) {
+						JOptionPane.showMessageDialog(null, e1.getMessage(), "程序关闭失败", JOptionPane.ERROR_MESSAGE);
+						logger.error("程序关闭失败", e1);
+					}
+				}else {
+					JOptionPane.showMessageDialog(null, "请先选择服务器", "请先选择服务器", JOptionPane.ERROR_MESSAGE);
+				}
+			}
+		});
+		
+		upgradeMenu.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				int selectedRow = serverFrame.getSelectedRow();
+				if(selectedRow >= 0 && selectedRow < settings.size()) {
+					ApplicationSetting setting = settings.get(selectedRow);
+					if(autoUpdateService.canUpdate(setting)) {
+						Object[] options = {"确定","取消"};
+						int response = JOptionPane.showOptionDialog(null, "如果您确定要升级,请点击\'确定\'按钮,否则点击\'取消\'按钮", "确定是否升级", JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
+						if(response==0)
+						{
+							autoUpdateService.autoUpdate(setting);
+						}
+					}else {
+						JOptionPane.showMessageDialog(null, "在服务器上未找到可更新的程序", "没有可更新的程序", JOptionPane.ERROR_MESSAGE);
+					}
+				}else {
+					JOptionPane.showMessageDialog(null, "请先选择服务器", "请先选择服务器", JOptionPane.ERROR_MESSAGE);
+				}
+			}
+		});
+		
+		editConfigMenu.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				int selectedRow = serverFrame.getSelectedRow();
+				if(selectedRow >= 0 && selectedRow < settings.size()) {
+					ApplicationSetting setting = settings.get(selectedRow);
+					SettingEditFrame serverSettingJFrame = new SettingEditFrame(setting);
+					serverSettingJFrame.setVisible(true);
+				}else {
+					JOptionPane.showMessageDialog(null, "请先选择服务器", "请先选择服务器", JOptionPane.ERROR_MESSAGE);
+				}
+			}
+		});
+		
+		startAllMenu.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				boolean canAllStart = true;
+				if (settings != null && settings.size() > 0) {
+					for(int i = 0; i < settings.size(); i ++) {
+						final ApplicationSetting setting = settings.get(i);
+						if(setting.getProgramRunResult() != null) {
+							canAllStart = false;
+							break;
+						}
+					}
+				}
+				
+				if(canAllStart) {
+					processService.autoStart(settings, serverLogFrame);
+				}else {
+					JOptionPane.showMessageDialog(null, "已经有程序启动了,不能全部启动,请手工启动。", "执行失败", JOptionPane.ERROR_MESSAGE);
+				}
+			}
+		});
+	}
+	
+	/**
+	 * 刷新菜单的状态
+	 */
+	private void refreshMenuStatus(int selectedRow) {
+		if(selectedRow >= 0 && selectedRow < settings.size()) {
+			ApplicationSetting setting = settings.get(selectedRow);
+			if(setting.isOnline()) {
+				startMenu.setEnabled(false);
+				stopMenu.setEnabled(true);
+				upgradeMenu.setEnabled(false);
+				editConfigMenu.setEnabled(true);
+			}else {
+				startMenu.setEnabled(true);
+				stopMenu.setEnabled(true);
+				upgradeMenu.setEnabled(true);
+				editConfigMenu.setEnabled(true);
+			}
+		}
+	}
+	
+
+	//重写这个方法  
+    @Override  
+    protected void processWindowEvent(WindowEvent e) {  
+        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
+        	//setVisible(false);
+        	boolean result = false;
+        	// 关闭其他子线程
+        	for(int i = 0; i < settings.size(); i ++) {
+        		ApplicationSetting setting = settings.get(i);
+        		ProgramRunResult programRunResult = setting.getProgramRunResult();
+    			if(programRunResult != null && programRunResult.getWatchDog() != null) {
+    				result = programRunResult.getWatchDog().killedProcess();
+    			}
+    			
+    			if(result == false) {
+    				try {
+						programRunResult = processService.stopProgram(setting);
+						if(programRunResult == null || programRunResult.getWatchDog() == null) {
+	    					logger.error("关闭程序失败" + setting.getName() +"未配置停止文件。");
+	    					JOptionPane.showMessageDialog(null, "未配置停止文件", "配置异常", JOptionPane.ERROR_MESSAGE);
+	    				}else {
+	    					setting.setProgramRunResult(null);
+	    				}
+					} catch (IOException e1) {
+    					logger.error("关闭程序失败" + setting.getName(), e1);
+					}
+    			}else {
+    				setting.setProgramRunResult(null);
+    			}	
+        	}
+        	
+        	Timer timer = new Timer();
+        	this.setEnabled(false);
+        	timer.schedule(new TimerTask() {
+				@Override
+				public void run() {
+					timer.cancel();
+		        	System.exit(0);
+				}
+        	}, 2000, 2000);
+        	return;
+        }
+        super.processWindowEvent(e); //该语句会执行窗口事件的默认动作(如:隐藏)  
+    }  
+    
+	/**
+	 * 初始化系统托盘
+	 */
+	private void initSystemTray() {
+		// 判断当前平台是否支持系统托盘
+		if(SystemTray.isSupported()) {
+			// 获得系统托盘的实例
+			systemTray = SystemTray.getSystemTray();
+			try {
+				URL path = MainFrame.class.getResource("prodog_16.png");
+				Image image = ImageIO.read(path);   
+				trayIcon = new TrayIcon(image);
+				trayIcon.displayMessage("通知:", "程序最小化到系统托盘", TrayIcon.MessageType.INFO);
+				// 设置托盘的图标
+				systemTray.add(trayIcon);
+
+				trayIcon.addMouseListener(new MouseAdapter() {
+					public void mouseClicked(MouseEvent e) {
+						// 双击托盘窗口再现
+						if (e.getClickCount() == 2) {
+							boolean visible = isVisible();
+							// setExtendedState(Frame.NORMAL);
+							setVisible(!visible);
+						}							
+					}
+				});
+
+				this.addWindowListener(new WindowAdapter() {
+					public void windowIconified(WindowEvent e) {
+						// 窗口最小化时
+						setVisible(false);
+					}
+				});
+				
+			} catch (IOException e1) {
+				logger.error("初始化托盘失败", e1);
+			} catch (AWTException e2) {
+				logger.error("初始化托盘失败", e2);
+			}
+		}
+	}
+}

+ 247 - 0
src/main/java/com/leanwo/management/ServerFrame.java

@@ -0,0 +1,247 @@
+package com.leanwo.management;
+
+import java.awt.AWTEvent;
+import java.awt.AWTException;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Image;
+import java.awt.Insets;
+import java.awt.Label;
+import java.awt.SystemTray;
+import java.awt.Toolkit;
+import java.awt.TrayIcon;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Date;
+import java.util.EventListener;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.imageio.ImageIO;
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingUtilities;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.table.DefaultTableModel;
+import javax.swing.table.TableModel;
+
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.DefaultExecuteResultHandler;
+import org.apache.commons.exec.DefaultExecutor;
+import org.apache.commons.exec.ExecuteWatchdog;
+import org.apache.commons.exec.PumpStreamHandler;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.web.client.RestTemplate;
+
+import com.leanwo.management.model.ApplicationSetting;
+import com.leanwo.management.model.ApplicationSettingCache;
+import com.leanwo.management.service.AutoUpdateService;
+import com.leanwo.management.service.ProcessService;
+import com.leanwo.management.util.SpringUtil;
+import com.leanwo.management.util.Variable;
+import com.leanwo.management.widget.ColorCellRenderer;
+import com.leanwo.management.widget.SelectEventListener;
+import com.leanwo.management.widget.SelectObject;
+
+/**
+ * 服务器管理界面
+ * 
+ * @author YangZhiJie
+ *
+ */
+public class ServerFrame extends JPanel {
+	private static Log logger = LogFactory.getLog(ServerFrame.class);
+
+	private JTable table = null;
+
+	private List<ApplicationSetting> settings = null;
+
+	private DefaultTableModel tableModel = null;
+
+	private Set<SelectEventListener> listeners = null;
+
+	private boolean isRunning = false;
+
+	private ProcessService processService = null;
+
+	private Timer timer = null;
+
+	public ServerFrame(List<ApplicationSetting> settings) {
+		this.settings = settings;
+		initData();
+		initView();
+	}
+
+	/**
+	 * 初始化
+	 */
+	private void initData() {
+		processService = (ProcessService) SpringUtil.getSingleBean(ProcessService.class);
+
+		listeners = new HashSet<SelectEventListener>();
+
+		tableModel = new DefaultTableModel();
+
+		Object[][] dataVector = null;
+		if (settings != null && settings.size() > 0) {
+			dataVector = new Object[settings.size()][6];
+			for (int i = 0; i < settings.size(); i++) {
+				ApplicationSetting setting = settings.get(i);
+				dataVector[i] = new Object[3];
+				dataVector[i][0] = String.valueOf(i + 1);
+				dataVector[i][1] = setting.getName();
+				dataVector[i][2] = Variable.LOADING;
+			}
+		}
+
+		Object[] columnIdentifiers = new Object[] { "序号", "程序", "状态" };
+		tableModel.setDataVector(dataVector, columnIdentifiers);
+	}
+
+	private void initView() {
+		this.setLayout(new BorderLayout());
+
+		table = new JTable(tableModel);
+		table.getColumn("序号").setPreferredWidth(50);
+		table.getColumn("程序").setPreferredWidth(150);
+		table.getColumn("状态").setPreferredWidth(96);
+
+		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
+		table.setRowSelectionAllowed(false);
+
+		ListSelectionModel cellSelectionModel = table.getSelectionModel();
+		cellSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+
+		cellSelectionModel.addListSelectionListener(new ListSelectionListener() {
+			public void valueChanged(ListSelectionEvent e) {
+				int[] selectedRows = table.getSelectedRows();
+				if (selectedRows.length > 0) {
+					int selectedRow = selectedRows[0];
+					fireSelectEvent(selectedRow);
+				}
+			}
+		});
+
+		//设置渲染器
+		ColorCellRenderer rcr = new ColorCellRenderer();
+		table.setDefaultRenderer(Object.class, rcr);
+		
+		
+		JScrollPane scroll = new JScrollPane(table);
+		add(scroll);
+
+		timer = new Timer();
+		timer.schedule(timerTask, 2000L, 2000L);
+	}
+
+	/**
+	 * 添加选择事件
+	 * 
+	 * @param listener
+	 */
+	public void addStateChangeListener(SelectEventListener listener) {
+		listeners.add(listener);
+	}
+
+	/**
+	 * 触发选择事件
+	 * 
+	 * @param selectedRow
+	 */
+	public void fireSelectEvent(int selectedRow) {
+		SelectObject event = new SelectObject(table, selectedRow);
+		if (listeners != null) {
+			for (SelectEventListener selectEventListener : listeners) {
+				selectEventListener.onSelect(event);
+			}
+		}
+	}
+
+	/**
+	 * 获取选中的行
+	 * 
+	 * @return
+	 */
+	public int getSelectedRow() {
+		return table.getSelectedRow();
+	}
+
+	/**
+	 * 更新表格
+	 */
+	private void updateTable() {
+		SwingUtilities.invokeLater(new Runnable() {
+			public void run() {
+				table.validate();
+				table.updateUI();
+			}
+		});
+	}
+
+	private TimerTask timerTask = new TimerTask() {
+		@Override
+		public void run() {
+			if (isRunning) {
+				logger.debug("上个定时程序还未运行完成,本次运行跳过");
+				return;
+			}
+			isRunning = true;
+			int selectedRow = getSelectedRow();
+			if (settings != null && settings.size() > 0) {
+				for (int i = 0; i < settings.size(); i++) {
+					ApplicationSetting setting = settings.get(i);
+					boolean oldStatus = setting.isOnline();
+					boolean online = false;
+					try {
+						online = processService.getStatus(setting);
+					}catch(Exception ex) {
+						logger.error(setting.getName() + "状态获取异常");
+					}
+
+					setting.setOnline(online);
+					String status = online ? Variable.RUNNING : Variable.NOT_RUNNING;
+					table.setValueAt(status, i, 2);
+
+					if (selectedRow == i) {
+						if(oldStatus != online) {
+							fireSelectEvent(selectedRow);
+						}
+					}
+				}
+			}
+			isRunning = false;
+			updateTable();
+		}
+	};
+}

+ 108 - 0
src/main/java/com/leanwo/management/ServerLogFrame.java

@@ -0,0 +1,108 @@
+package com.leanwo.management;
+
+import java.awt.GridLayout;
+import java.io.PipedInputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+import javax.swing.JTextArea;
+
+import org.apache.log4j.Logger;
+
+import com.leanwo.management.console.LogConsole;
+import com.leanwo.management.model.ApplicationSetting;
+import com.leanwo.management.model.ApplicationSettingCache;
+import com.leanwo.management.service.ProgramRunResult;
+import com.leanwo.management.util.SpringUtil;
+
+/**
+ * 服务器日志视图
+ * @author YangZhiJie1
+ *
+ */
+public class ServerLogFrame extends JPanel{
+	private static Logger logger = Logger.getLogger(ServerLogFrame.class);
+	
+	private JTabbedPane tabbedpane = null;
+	private String[] tabNames = null;
+
+	private List<ApplicationSetting> settings = null;
+	
+	private Map<Integer, LogConsole> logConsoleMap = null;
+
+	private Timer timer = null;
+	
+	public ServerLogFrame(List<ApplicationSetting> settings) {
+		this.settings = settings;
+		initData();
+		initView();
+	}
+	
+	private void initData() {		
+		if (settings != null && settings.size() > 0) {
+			tabNames = new String[settings.size()];
+			for(int i = 0; i < settings.size(); i ++) {
+				ApplicationSetting setting = settings.get(i);
+				tabNames[i] = setting.getName();
+			}
+		}
+		
+		logConsoleMap = new HashMap<Integer, LogConsole>();
+	}
+	
+	private void initView() {
+		tabbedpane = new JTabbedPane();
+		
+		for(int i = 0; i < tabNames.length; i ++) {
+			JPanel panel = new JPanel();
+			tabbedpane.addTab(tabNames[i],  panel);
+			
+			PipedInputStream outPipedInputStream=new PipedInputStream(); 
+			PipedInputStream errorPipedInputStream=new PipedInputStream(); 
+			
+			LogConsole logConsole = new LogConsole(outPipedInputStream, errorPipedInputStream);
+			panel.setLayout(new GridLayout(1, 1));
+			panel.add(logConsole);
+			logConsoleMap.put(i, logConsole);
+		}
+		
+		setLayout(new GridLayout(1, 1));
+		add(tabbedpane);
+		
+		timer = new Timer();
+		timer.schedule(timerTask, 10000L, 10000L);
+	}
+	
+	public void setSelectedIndex(int index) {
+		if(tabNames != null && index < tabNames.length && index >= 0) {
+			tabbedpane.setSelectedIndex(index);
+		}
+	}
+	
+	/**
+	 * 更新程序运行结果
+	 */
+	public void updateProgramRunResult(int index, ProgramRunResult programRunResult) {
+		if(logConsoleMap.containsKey(index)) {
+			LogConsole logConsole = logConsoleMap.get(index);
+			logConsole.setPipedInputStream(programRunResult.getOutPipedInputStream(), programRunResult.getErrorPipedInputStream());
+		}else {
+			logger.error("找不到序号" + index + "对应的视图。");
+		}
+	}
+	
+
+	private TimerTask timerTask = new TimerTask() {
+		@Override
+		public void run() {
+			for(LogConsole logConsole : logConsoleMap.values()) {
+				logConsole.reserveMaxCharacter();
+			}
+		}
+	};
+}

+ 0 - 485
src/main/java/com/leanwo/management/ServerManagmentJFrame.java

@@ -1,485 +0,0 @@
-package com.leanwo.management;
-
-import java.awt.AWTEvent;
-import java.awt.AWTException;
-import java.awt.BorderLayout;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Image;
-import java.awt.Insets;
-import java.awt.Label;
-import java.awt.SystemTray;
-import java.awt.Toolkit;
-import java.awt.TrayIcon;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
-
-import javax.imageio.ImageIO;
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.SwingUtilities;
-
-import org.apache.commons.exec.CommandLine;
-import org.apache.commons.exec.DefaultExecuteResultHandler;
-import org.apache.commons.exec.DefaultExecutor;
-import org.apache.commons.exec.ExecuteWatchdog;
-import org.apache.commons.exec.PumpStreamHandler;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.leanwo.management.util.AutoUpdateService;
-import org.leanwo.management.util.SpringUtil;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.http.client.SimpleClientHttpRequestFactory;
-import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
-import org.springframework.web.client.RestTemplate;
-
-import com.leanwo.management.model.ApplicationSetting;
-import com.leanwo.management.model.ApplicationSettingCache;
-
-/**
- * 服务器管理界面
- * 
- * @author YangZhiJie
- *
- */
-public class ServerManagmentJFrame extends JFrame {
-	private static Log logger = LogFactory.getLog(ServerManagmentJFrame.class);
-	
-	// 得到显示器屏幕的宽高
-	private int width = Toolkit.getDefaultToolkit().getScreenSize().width;
-	private int height = Toolkit.getDefaultToolkit().getScreenSize().height;
-
-	// 定义窗体的宽高
-	private int windowsWidth = 800;
-	private int windowsHeight = 400;
-
-	private JPanel jPanel = null;
-	private Timer timer;
-
-	private TrayIcon trayIcon;				// 托盘图标
-	private SystemTray systemTray;	// 系统托盘
-	
-	private Map<ApplicationSetting, JLabel> statusLabels = null;
-	private ApplicationSettingCache applicationSettingCache;
-	private boolean isRunning = false;
-	
-	public ServerManagmentJFrame(boolean isAutoRun) {
-		this.setLayout(new BorderLayout());
-		
-		jPanel = new JPanel(new GridBagLayout());
-		this.add(jPanel, BorderLayout.NORTH);
-        
-		this.setTitle("Prodog程序管理器");
-		// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设定按关闭时的操作,这里是关闭窗口,如果不设定,就什么也不会发生
-
-        //激活窗口事件  
-        this.enableEvents(AWTEvent.WINDOW_EVENT_MASK);  
-        
-		// 设置窗体位置和大小
-		this.setBounds((width - windowsWidth) / 2, (height - windowsHeight) / 2, windowsWidth, windowsHeight);
-		
-		statusLabels = new HashMap<ApplicationSetting, JLabel>();
-		
-		generateViewFromJson();
-		
-		this.setVisible(true); // 显示,如果不设置就什么都看不到
-		
-		timer = new Timer();
-		timer.schedule(timerTimerTask, 2000L, 2000L);
-		
-		// 判断当前平台是否支持系统托盘
-		if(SystemTray.isSupported()) {
-			// 获得系统托盘的实例
-			systemTray = SystemTray.getSystemTray();
-			try {
-				URL path = ServerManagmentJFrame.class.getResource("prodog_16.png");
-				Image imgae = ImageIO.read(path);   
-				trayIcon = new TrayIcon(imgae);
-				trayIcon.displayMessage("通知:", "程序最小化到系统托盘", TrayIcon.MessageType.INFO);
-				// 设置托盘的图标
-				systemTray.add(trayIcon);
-
-				trayIcon.addMouseListener(new MouseAdapter() {
-					public void mouseClicked(MouseEvent e) {
-						// 双击托盘窗口再现
-						if (e.getClickCount() == 2) {
-							boolean visible = isVisible();
-							// setExtendedState(Frame.NORMAL);
-							setVisible(!visible);
-						}							
-					}
-				});
-
-				this.addWindowListener(new WindowAdapter() {
-					public void windowIconified(WindowEvent e) {
-						// 窗口最小化时
-						setVisible(false);
-					}
-				});
-				
-			} catch (IOException e1) {
-				e1.printStackTrace();
-			} catch (AWTException e2) {
-				e2.printStackTrace();
-			}
-		}
-		
-		// 程序自动运行
-		if(isAutoRun) {
-			autoStart();
-		}
-	}
-
-	//重写这个方法  
-    @Override  
-    protected void processWindowEvent(WindowEvent e) {  
-        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
-        	setVisible(false);
-        	return;
-        }
-        super.processWindowEvent(e); //该语句会执行窗口事件的默认动作(如:隐藏)  
-    }  
-    
-	public void generateViewFromJson() {
-		GridBagConstraints constrains = null;
-        
-		JLabel label = new JLabel("程序");
-        label.setBorder(BorderFactory.createEtchedBorder());
-		constrains = new GridBagConstraints();
-		constrains.insets = new Insets(0, 0, 0, 0);
-        constrains.fill = GridBagConstraints.BOTH;
-        constrains.gridx = 0;
-        constrains.gridy = 0;
-        constrains.weightx = 25;        
-        constrains.anchor = GridBagConstraints.NORTH;
-        jPanel.add(label, constrains);
-		
-		label = new JLabel("状态");
-        label.setBorder(BorderFactory.createEtchedBorder());
-		constrains = new GridBagConstraints();
-		constrains.insets = new Insets(0, 0, 0, 0);
-        constrains.fill = GridBagConstraints.BOTH;
-        constrains.gridx = 1;
-        constrains.gridy = 0;
-        constrains.weightx = 25;
-        constrains.anchor = GridBagConstraints.NORTH;
-        jPanel.add(label, constrains);
-		
-		label = new JLabel("启动");
-        label.setBorder(BorderFactory.createEtchedBorder());
-		constrains = new GridBagConstraints();
-		constrains.insets = new Insets(0, 0, 0, 0);
-        constrains.fill = GridBagConstraints.BOTH;
-        constrains.gridx = 2;
-        constrains.gridy = 0;
-        constrains.weightx = 10;        
-        constrains.anchor = GridBagConstraints.NORTH;
-        jPanel.add(label, constrains);
-		
-		label = new JLabel("关闭");
-        label.setBorder(BorderFactory.createEtchedBorder());
-		constrains = new GridBagConstraints();
-		constrains.insets = new Insets(0, 0, 0, 0);
-        constrains.fill = GridBagConstraints.BOTH;
-        constrains.gridx = 3;
-        constrains.gridy = 0;
-        constrains.weightx = 10;        
-        constrains.anchor = GridBagConstraints.NORTH;
-        jPanel.add(label, constrains);
-
-		label = new JLabel("检查更新");
-        label.setBorder(BorderFactory.createEtchedBorder());
-		constrains = new GridBagConstraints();
-		constrains.insets = new Insets(0, 0, 0, 0);
-        constrains.fill = GridBagConstraints.BOTH;
-        constrains.gridx = 4;
-        constrains.gridy = 0;
-        constrains.weightx = 10;        
-        constrains.anchor = GridBagConstraints.NORTH;
-        jPanel.add(label, constrains);
-
-		label = new JLabel("修改配置");
-        label.setBorder(BorderFactory.createEtchedBorder());
-		constrains = new GridBagConstraints();
-		constrains.insets = new Insets(0, 0, 0, 0);
-        constrains.fill = GridBagConstraints.BOTH;
-        constrains.gridx = 5;
-        constrains.gridy = 0;
-        constrains.weightx = 10;
-        constrains.anchor = GridBagConstraints.NORTH;
-        jPanel.add(label, constrains);
-        
-		applicationSettingCache = (ApplicationSettingCache) SpringUtil.getSingleBean(ApplicationSettingCache.class);
-		List<ApplicationSetting> settings = applicationSettingCache.getSettings();
-		if (settings != null && settings.size() > 0) {
-			for(int i = 0; i < settings.size(); i ++) {
-				int rowIndex = (i + 1);
-				final ApplicationSetting setting = settings.get(i);
-				
-				label = new JLabel(setting.getName());
-				constrains = new GridBagConstraints();
-				constrains.insets = new Insets(5, 5, 5, 5);
-		        constrains.fill = GridBagConstraints.BOTH;
-		        constrains.gridx = 0;
-		        constrains.gridy = rowIndex;
-		        constrains.weightx = 25;		        
-		        jPanel.add(label, constrains);
-				
-				
-				label = new JLabel(setting.getStatus());
-				constrains = new GridBagConstraints();
-				constrains.insets = new Insets(5, 5, 5, 5);
-		        constrains.fill = GridBagConstraints.BOTH;
-		        constrains.gridx = 1;
-		        constrains.gridy = rowIndex;
-		        constrains.weightx = 25;		        
-		        jPanel.add(label, constrains);
-		        
-		        statusLabels.put(setting, label);
-				
-				JButton startButton = new JButton("启动");
-				constrains = new GridBagConstraints();
-				constrains.insets = new Insets(5, 5, 5, 5);
-		        constrains.fill = GridBagConstraints.BOTH;
-		        constrains.gridx = 2;
-		        constrains.gridy = rowIndex;
-		        constrains.weightx = 10;		        
-		        jPanel.add(startButton, constrains);
-		        startButton.addActionListener(new ActionListener() {
-					@Override
-					public void actionPerformed(ActionEvent e) {
-						try {
-							String path = setting.getInstallPath() + File.separator + setting.getStartBatFile();
-							ExecuteWatchdog executeWatchdog = runProcess(path);
-							setting.setExecuteWatchdog(executeWatchdog);
-						} catch (IOException e1) {
-							e1.printStackTrace();
-						}
-					}
-				});
-				
-				JButton stopButton = new JButton("停止");
-				constrains = new GridBagConstraints();
-				constrains.insets = new Insets(5, 5, 5, 5);
-		        constrains.fill = GridBagConstraints.BOTH;
-		        constrains.gridx = 3;
-		        constrains.gridy = rowIndex;
-		        constrains.weightx = 10;		        
-		        jPanel.add(stopButton, constrains);
-		        stopButton.addActionListener(new ActionListener() {
-					@Override
-					public void actionPerformed(ActionEvent e) {
-						try {
-							String path = setting.getInstallPath() + File.separator + setting.getStopBatFile();
-							ExecuteWatchdog executeWatchdog = runProcess(path);
-							setting.setExecuteWatchdog(null);
-						} catch (IOException e1) {
-							logger.error("程序启动失败", e1);
-						}
-					}
-				});
-		        
-
-				JButton checkUpdate = new JButton("检查更新");
-				constrains = new GridBagConstraints();
-				constrains.insets = new Insets(5, 5, 5, 5);
-		        constrains.fill = GridBagConstraints.BOTH;
-		        constrains.gridx = 4;
-		        constrains.gridy = rowIndex;
-		        constrains.weightx = 10;
-		        jPanel.add(checkUpdate, constrains);
-		        checkUpdate.addActionListener(new ActionListener() {
-					@Override
-					public void actionPerformed(ActionEvent e) {
-						AutoUpdateService autoUpdateService = (AutoUpdateService) SpringUtil.getSingleBean(AutoUpdateService.class);
-						if(autoUpdateService.canUpdate(setting)) {
-							Object[] options = {"确定","取消"};
-							int response = JOptionPane.showOptionDialog(null, "如果您确定要升级,请点击\'确定\'按钮,否则点击\'取消\'按钮", "确定是否升级", JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
-							if(response==0)
-							{
-								autoUpdateService.autoUpdate(setting);
-							}
-						}else {
-							JOptionPane.showMessageDialog(null, "在服务器上未找到可更新的程序", "没有可更新的程序", JOptionPane.ERROR_MESSAGE);
-						}
-					}
-				});
-		        
-
-				JButton config = new JButton("配置");
-				constrains = new GridBagConstraints();
-				constrains.insets = new Insets(5, 5, 5, 5);
-		        constrains.fill = GridBagConstraints.BOTH;
-		        constrains.gridx = 5;
-		        constrains.gridy = rowIndex;
-		        constrains.weightx = 10;
-		        jPanel.add(config, constrains);
-		        config.addActionListener(new ActionListener() {
-					@Override
-					public void actionPerformed(ActionEvent e) {
-						ServerSettingJFrame serverSettingJFrame = new ServerSettingJFrame(setting);
-						serverSettingJFrame.setVisible(true);
-					}
-				});
-			}
-		}
-	}
-	
-	/**
-	 * 运行流程
-	 * @param command "cmd.exe /c start c://example.exe"
-	 * @return
-	 * @throws IOException
-	 */
-	private ExecuteWatchdog runProcess(String command) throws IOException {
-		if(command == null || command.length() == 0) {
-			return null;
-		}
-		logger.info("即将运行命令:" + command);
-		
-		final CommandLine cmdLine = CommandLine.parse(command);
-		
-		final ExecuteWatchdog watchDog = new ExecuteWatchdog(Long.MAX_VALUE);
-		
-		final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
-		DefaultExecutor executor = new DefaultExecutor();
-		executor.setWatchdog(watchDog);
-
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		executor.setStreamHandler(new PumpStreamHandler(baos, baos));
-
-		executor.execute(cmdLine, resultHandler);
-		
-		//等待5秒。
-		try {
-			resultHandler.waitFor(2000);
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-
-		//这里开始的代码会被立即执行下去,因为上面的语句不会被阻塞。
-		final String result = baos.toString().trim();
-		logger.debug(result);//这个result就是ping输出的结果。如果是JAVA程序,抛出了异常,也被它获取。
-		return watchDog;
-	}
-
-	
-	/**
-	 * 程序自动运行
-	 */
-	private void autoStart() {
-		List<ApplicationSetting> settings = applicationSettingCache.getSettings();
-		if (settings != null && settings.size() > 0) {
-			for(int i = 0; i < settings.size(); i ++) {
-				final ApplicationSetting setting = settings.get(i);
-				ExecuteWatchdog executeWatchdog;
-				try {
-					String path = setting.getInstallPath() + File.separator + setting.getStartBatFile();
-					executeWatchdog = runProcess(path);
-					if(executeWatchdog != null) {
-						boolean isWatch = executeWatchdog.isWatching();
-						if(! isWatch) {
-							logger.error("程序" + setting.getName() + "启动失败");
-						}
-						setting.setExecuteWatchdog(executeWatchdog);
-					}
-				} catch (IOException e) {
-					logger.error("程序" + setting.getName() + "启动失败", e);
-				}
-			}
-		}
-	}
-	
-	private TimerTask timerTimerTask = new TimerTask() {
-		@Override
-		public void run() {
-			if(isRunning) {
-				logger.debug("上个定时程序还未运行完成,本次运行跳过");
-				return;
-			}
-			isRunning = true;
-			List<ApplicationSetting> settings = applicationSettingCache.getSettings();
-			if (settings != null && settings.size() > 0) {
-				for(int i = 0; i < settings.size(); i ++) {
-					final ApplicationSetting setting = settings.get(i);
-					JLabel statusLabel = statusLabels.get(setting);
-					if(statusLabel != null) {
-						/*
-						ExecuteWatchdog executeWatchdog = setting.getExecuteWatchdog();
-						if(executeWatchdog == null) {
-							statusLabel.setText("未运行");
-						}else{
-							if(executeWatchdog.isWatching()) {
-								statusLabel.setText("运行中");					
-							}else {
-								statusLabel.setText("已停止");		
-							}
-						}*/
-						
-						// 监控各个服务程序是否正在运行
-						String status = null;
-						String url = setting.getMonitorUrl();
-						String token = setting.getToken();
-						if(url == null || "".equals(url) || token == null || "".equals(token)){
-							continue;
-						}
-						RestTemplate restTemplate = new RestTemplate();		
-						restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
-						HttpHeaders headers = new HttpHeaders();
-						headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
-						headers.add("account", "2");
-						headers.add("token", token);
-						HttpEntity entity = new HttpEntity(headers);
-						try{			
-							ResponseEntity<Long> response = restTemplate.exchange(url, HttpMethod.GET, entity, Long.class);
-							((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setReadTimeout(1000*30);
-							((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setConnectTimeout(1000*30);
-							Long result = response.getBody();
-							long mills = new Date().getTime() - result;
-							status = "运行中(" + mills + "ms)";
-						}catch(Exception ex){
-							status = "已停止";
-						}
-						updateStatus(statusLabel, status);
-					}
-				}
-			}
-			isRunning = false;
-		}
-	};
-	
-	/**
-	 * 在其他线程更新状态Label的文本
-	 * @param statusLabel
-	 * @param status
-	 */
-	private void updateStatus(JLabel statusLabel, String status) {
-		SwingUtilities.invokeLater(new Runnable() {
-		    public void run() {
-		    	statusLabel.setText(status);
-		    }
-		});
-	}
-}

+ 6 - 6
src/main/java/com/leanwo/management/ServerSettingJFrame.java → src/main/java/com/leanwo/management/SettingEditFrame.java

@@ -37,20 +37,20 @@ import javax.swing.Timer;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.leanwo.management.exception.ConfigFileException;
-import org.leanwo.management.util.SpringUtil;
-import org.leanwo.management.util.XmlConfigPathService;
 
+import com.leanwo.management.exception.ConfigFileException;
 import com.leanwo.management.model.ApplicationSetting;
 import com.leanwo.management.model.XmlConfigPath;
+import com.leanwo.management.util.SpringUtil;
+import com.leanwo.management.util.XmlConfigPathService;
 
 /**
  * 服务器配置
  * @author YangZhiJie
  *
  */
-public class ServerSettingJFrame  extends JFrame{
-	private static Log logger = LogFactory.getLog(ServerSettingJFrame.class);
+public class SettingEditFrame  extends JFrame{
+	private static Log logger = LogFactory.getLog(SettingEditFrame.class);
 	private ApplicationSetting applicationSetting;
 	private XmlConfigPath xmlConfigPath;
 	private XmlConfigPathService xmlConfigPathService;
@@ -61,7 +61,7 @@ public class ServerSettingJFrame  extends JFrame{
 	private Map<String, JTextArea> textAreas = new HashMap<String, JTextArea>();
 	private JButton saveButton;
 	
-	public ServerSettingJFrame(ApplicationSetting applicationSetting) {
+	public SettingEditFrame(ApplicationSetting applicationSetting) {
 		this.jPanel = this.getContentPane();  
 
 		this.setSize(800, 600);

+ 145 - 0
src/main/java/com/leanwo/management/console/LogConsole.java

@@ -0,0 +1,145 @@
+package com.leanwo.management.console;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PipedInputStream;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+
+public class LogConsole extends JPanel{
+
+	private JTextArea textArea;
+	private JButton clearButton;
+	
+	private PipedInputStream outPipedInputStream;
+	private PipedInputStream errorPipedInputStream;
+
+	private boolean quit;
+	private Thread outReaderThread;
+	private Thread errorReaderThread;
+	
+	/** 字符串最大的个数 */
+	private static final int MAX_CHARACTER_COUNT = 100000;
+	
+	public LogConsole(PipedInputStream outPipedInputStream, PipedInputStream errorPipedInputStream) {
+		this.outPipedInputStream = outPipedInputStream;
+		this.errorPipedInputStream = errorPipedInputStream;
+		initData();
+		initView();
+	}
+	
+	public void 	setPipedInputStream(PipedInputStream outPipedInputStream, PipedInputStream errorPipedInputStream) {
+		this.outPipedInputStream = outPipedInputStream;
+		this.errorPipedInputStream = errorPipedInputStream;
+	}
+	
+	/**
+	 * 初始化数据
+	 */
+	private void initData() {
+		// signals the Threads that they should exit
+		quit=false; 
+		
+		// Starting two seperate threads to read from the PipedInputStreams				
+		outReaderThread=new Thread(outRunnable);
+		outReaderThread.setDaemon(true);	
+		outReaderThread.start();	
+		
+		errorReaderThread=new Thread(errorRunnable);	
+		errorReaderThread.setDaemon(true);	
+		errorReaderThread.start();
+	}
+	
+	/**
+	 * 初始化界面
+	 */
+	private void initView() {
+		textArea=new JTextArea();
+		textArea.setEditable(false);
+		clearButton=new JButton("清空");
+		
+		setLayout(new BorderLayout());
+		add(new JScrollPane(textArea),BorderLayout.CENTER);
+		add(clearButton,BorderLayout.SOUTH);
+		
+		clearButton.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				textArea.setText(null);
+			}
+		});
+	}
+
+	private Runnable outRunnable = new Runnable() {
+		@Override
+		public synchronized void run() {
+			try {
+				while (!quit) {
+					try {
+						this.wait(100);
+					} catch (InterruptedException ie) {
+					}
+					if (outPipedInputStream != null && outPipedInputStream.available() != 0) {
+						String input = readLine(outPipedInputStream);
+						textArea.append(input);
+					}
+				}
+			} catch (Exception e) {
+				textArea.append("\nConsole reports an Internal error.");
+				textArea.append("The error is: " + e);
+			}
+		}
+	};
+	
+	
+	private Runnable errorRunnable = new Runnable() {
+		@Override
+		public synchronized void run() {
+			try {
+				while (!quit) {
+					try {
+						this.wait(100);
+					} catch (InterruptedException ie) {
+					}
+					if (errorPipedInputStream != null && errorPipedInputStream.available() != 0) {
+						String input = readLine(errorPipedInputStream);
+						textArea.append(input);
+					}
+				}
+			} catch (Exception e) {
+				textArea.append("\nConsole reports an Internal error.");
+				textArea.append("The error is: " + e);
+			}
+		}
+	};
+
+	private String readLine(InputStream inputStream) throws IOException {
+		String input = "";
+		do {
+			int available = inputStream.available();
+			if (available == 0)
+				break;
+			byte b[] = new byte[available];
+			inputStream.read(b);
+			input = input + new String(b, 0, b.length, "GBK");
+		} while (!input.endsWith("\n") && !input.endsWith("\r\n") && !quit);
+		return input;
+	}
+	
+	/**
+	 * 保留最多的字符串
+	 */
+	public void reserveMaxCharacter() {
+		String text = textArea.getText();
+		if(text.length() > MAX_CHARACTER_COUNT) {
+			text = text.substring(text.length() - MAX_CHARACTER_COUNT *2/3);
+			textArea.setText(text);
+		}
+	}
+}

+ 1 - 1
src/main/java/org/leanwo/management/exception/BeanNotInjectException.java → src/main/java/com/leanwo/management/exception/BeanNotInjectException.java

@@ -1,4 +1,4 @@
-package org.leanwo.management.exception;
+package com.leanwo.management.exception;
 
 /**
  * Bean未注入异常

+ 1 - 1
src/main/java/org/leanwo/management/exception/ConfigFileException.java → src/main/java/com/leanwo/management/exception/ConfigFileException.java

@@ -1,4 +1,4 @@
-package org.leanwo.management.exception;
+package com.leanwo.management.exception;
 
 /**
  * 配置文件异常

+ 101 - 87
src/main/java/com/leanwo/management/model/ApplicationSetting.java

@@ -7,6 +7,9 @@ import java.util.List;
 
 import org.apache.commons.exec.ExecuteWatchdog;
 
+import com.leanwo.management.service.ProgramRunResult;
+import com.leanwo.management.util.CloseableUtil;
+
 /**
  * 应用程序实体类.
  *
@@ -14,123 +17,91 @@ import org.apache.commons.exec.ExecuteWatchdog;
  */
 public class ApplicationSetting {
 	
-	/**
-	 * 应用程序名称.
-	 */
+	/** 应用程序名称. */
 	private String name;
 
-	/**
-	 * 安装路径.
-	 */
+	/** 安装路径. */
 	private String installPath;
 	
-	/**
-	 * 应用程序状态.
-	 */
-	private String status;
-
-	/**
-	 * 启动程序BAT文件路径.
-	 */
+	/** 启动程序命令. */
+	private String startCommand;
+	
+	/** 启动程序BAT文件路径. */
 	private String startBatFile;
 
-	/**
-	 * 停止程序BAT文件路径.
-	 */
+	/** 停止程序BAT文件路径. */
 	private String stopBatFile;
 	
-	/** The execute watchdog. */
-	private ExecuteWatchdog executeWatchdog;
-
 	/** 监控地址. */
 	private String monitorUrl;
 	
 	/** token. */
 	private String token;
-	
-	
-	
-	/**
-	 * Gets the token.
-	 *
-	 * @return the token
-	 */
-	public String getToken() {
-		return token;
-	}
 
-	/**
-	 * 自动更新的文件名.
-	 */
+	/** 自动更新的文件名.	 */
 	private List<String> autoUpdateFileNames;
 
-	/**
-	 * XML文件配置.
-	 */
+	/** XML文件配置. */
 	private XmlConfigPath xmlConfigPath;
-	
-	
-	/**
-	 *
-	 * @param token the new token
-	 */
-	public void setToken(String token) {
-		this.token = token;
-	}
+		
+	/** 应用程序是否在线(计算值). */
+	private boolean online;
+
+	/** 程序运行结果(计算值). */
+	private ProgramRunResult programRunResult;
 
 	/**
-	 * Gets the 监控地址.
+	 * Gets the 应用程序名称.
 	 *
-	 * @return the 监控地址
+	 * @return the 应用程序名称
 	 */
-	public String getMonitorUrl() {
-		return monitorUrl;
+	public String getName() {
+		return name;
 	}
 
 	/**
-	 * Sets the 监控地址.
+	 * Sets the 应用程序名称.
 	 *
-	 * @param monitorUrl the new 监控地址
+	 * @param name the new 应用程序名称
 	 */
-	public void setMonitorUrl(String monitorUrl) {
-		this.monitorUrl = monitorUrl;
+	public void setName(String name) {
+		this.name = name;
 	}
 
-	
 	/**
-	 * Gets the 应用程序名称.
+	 * Gets the 安装路径.
 	 *
-	 * @return the 应用程序名称
+	 * @return the 安装路径
 	 */
-	public String getName() {
-		return name;
+	public String getInstallPath() {
+		return installPath;
 	}
 
 	/**
-	 * Sets the 应用程序名称.
+	 * Sets the 安装路径.
 	 *
-	 * @param name the new 应用程序名称
+	 * @param installPath the new 安装路径
 	 */
-	public void setName(String name) {
-		this.name = name;
+	public void setInstallPath(String installPath) {
+		this.installPath = installPath;
 	}
 
 	/**
-	 * Gets the 应用程序状态.
+	 * Gets the 启动程序命令.
 	 *
-	 * @return the 应用程序状态
+	 * @return the 启动程序命令
 	 */
-	public String getStatus() {
-		return status;
+	public String getStartCommand() {
+		return startCommand;
 	}
 
 	/**
-	 * Sets the 应用程序状态.
+	 * Sets the 启动程序命令.
 	 *
-	 * @param status the new 应用程序状态
+	 * @param startCommand the new 启动程序命令
 	 */
-	public void setStatus(String status) {
-		this.status = status;
+	public void setStartCommand(String startCommand) {
+		this.startCommand = startCommand;
 	}
 
 	/**
@@ -170,39 +141,39 @@ public class ApplicationSetting {
 	}
 
 	/**
-	 * Gets the execute watchdog.
+	 * Gets the 监控地址.
 	 *
-	 * @return the execute watchdog
+	 * @return the 监控地址
 	 */
-	public ExecuteWatchdog getExecuteWatchdog() {
-		return executeWatchdog;
+	public String getMonitorUrl() {
+		return monitorUrl;
 	}
 
 	/**
-	 * Sets the execute watchdog.
+	 * Sets the 监控地址.
 	 *
-	 * @param executeWatchdog the new execute watchdog
+	 * @param monitorUrl the new 监控地址
 	 */
-	public void setExecuteWatchdog(ExecuteWatchdog executeWatchdog) {
-		this.executeWatchdog = executeWatchdog;
+	public void setMonitorUrl(String monitorUrl) {
+		this.monitorUrl = monitorUrl;
 	}
 
 	/**
-	 * Gets the 安装路径.
+	 * Gets the token.
 	 *
-	 * @return the 安装路径
+	 * @return the token
 	 */
-	public String getInstallPath() {
-		return installPath;
+	public String getToken() {
+		return token;
 	}
 
 	/**
-	 * Sets the 安装路径.
+	 * Sets the token.
 	 *
-	 * @param installPath the new 安装路径
+	 * @param token the new token
 	 */
-	public void setInstallPath(String installPath) {
-		this.installPath = installPath;
+	public void setToken(String token) {
+		this.token = token;
 	}
 
 	/**
@@ -240,4 +211,47 @@ public class ApplicationSetting {
 	public void setXmlConfigPath(XmlConfigPath xmlConfigPath) {
 		this.xmlConfigPath = xmlConfigPath;
 	}
+
+	/**
+	 * Checks if is 应用程序是否在线(计算值).
+	 *
+	 * @return the 应用程序是否在线(计算值)
+	 */
+	public boolean isOnline() {
+		return online;
+	}
+
+	/**
+	 * Sets the 应用程序是否在线(计算值).
+	 *
+	 * @param online the new 应用程序是否在线(计算值)
+	 */
+	public void setOnline(boolean online) {
+		this.online = online;
+	}
+
+	/**
+	 * Gets the 程序运行结果(计算值).
+	 *
+	 * @return the 程序运行结果(计算值)
+	 */
+	public ProgramRunResult getProgramRunResult() {
+		return programRunResult;
+	}
+
+	/**
+	 * Sets the 程序运行结果(计算值).
+	 *
+	 * @param programRunResult the new 程序运行结果(计算值)
+	 */
+	public void setProgramRunResult(ProgramRunResult programRunResult) {
+		if(programRunResult == null) {
+			if(this.programRunResult != null) {
+				CloseableUtil.close(this.programRunResult.getErrorPipedInputStream(), 
+						this.programRunResult.getOutPipedInputStream());
+			}
+		}
+		this.programRunResult = programRunResult;
+	}
+
 }

+ 3 - 1
src/main/java/org/leanwo/management/util/AutoUpdateService.java → src/main/java/com/leanwo/management/service/AutoUpdateService.java

@@ -1,4 +1,4 @@
-package org.leanwo.management.util;
+package com.leanwo.management.service;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -23,6 +23,8 @@ import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
 import org.apache.log4j.Logger;
+import org.springframework.stereotype.Service;
+
 import com.leanwo.management.model.ApplicationSetting;
 
 /**

+ 95 - 0
src/main/java/com/leanwo/management/service/FileService.java

@@ -0,0 +1,95 @@
+package com.leanwo.management.service;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+public class FileService {
+
+	private static Logger logger = Logger.getLogger(FileService.class);
+
+	
+	public List<File> getFileList(String fullPath) {
+		File folder = new File(fullPath);
+		File[] files = folder.listFiles();
+		List<File> fileList = new ArrayList<>();
+		if (files != null && files.length > 0) {
+			for (File file : files) {
+				fileList.add(file);
+			}
+
+			// 根据文件名按照时间进行排序
+			Collections.sort(fileList, new Comparator<File>() {
+				
+				public int compare(File o1, File o2) {
+					return o1.getName().compareTo(o2.getName());
+				}
+			});
+		}
+		return fileList;
+	}
+
+	
+	public String readFile(String path) {
+		File templateFile = new File(path);
+		if(!templateFile.exists()) {
+			return null;
+		}
+		return readFile(templateFile);
+	}
+
+	
+	public String readFile(File file) {
+		StringBuilder sb = new StringBuilder();
+		InputStream inputStream = null;
+		InputStreamReader inputStreamReader = null;
+		BufferedReader bufferedReader = null;
+		String data = null;
+		try {
+			inputStream = new FileInputStream(file);
+			inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
+			bufferedReader = new BufferedReader(inputStreamReader);
+			while ((data = bufferedReader.readLine()) != null) {
+				sb.append(data).append("\r\n");
+			}
+		} catch (FileNotFoundException e) {
+			logger.error("文件不存在", e);
+		} catch (IOException e) {
+			logger.error("", e);
+		} finally {
+			if (bufferedReader != null) {
+				try {
+					bufferedReader.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+			if(inputStreamReader != null) {
+				try {
+					inputStreamReader.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+			if(inputStream != null) {
+				try {
+					inputStream.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+		return sb.toString();
+	}
+
+}

+ 54 - 0
src/main/java/com/leanwo/management/service/HttpService.java

@@ -0,0 +1,54 @@
+package com.leanwo.management.service;
+
+import java.util.Date;
+
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import com.leanwo.management.model.ApplicationSetting;
+
+/**
+ * HTTP 状态服务
+ * @author YangZhiJie1
+ *
+ */
+public class HttpService implements StatusService {
+	
+	/**
+	 * 获取服务器的状态
+	 * @param setting
+	 * @return true: 运行中 false: 不在运行
+	 */
+	@Override
+	public Boolean getStatus(ApplicationSetting setting) {
+		// 监控各个服务程序是否正在运行
+		String url = setting.getMonitorUrl();
+		String token = setting.getToken();
+		if(url == null || "".equals(url) || token == null || "".equals(token)){
+			return false;
+		}
+		RestTemplate restTemplate = new RestTemplate();		
+		restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
+		HttpHeaders headers = new HttpHeaders();
+		headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
+		headers.add("account", "2");
+		headers.add("token", token);
+		HttpEntity entity = new HttpEntity(headers);
+		try{			
+			ResponseEntity<Long> response = restTemplate.exchange(url, HttpMethod.GET, entity, Long.class);
+			((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setReadTimeout(1000*30);
+			((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setConnectTimeout(1000*30);
+			Long result = response.getBody();
+			return true;
+		}catch(Exception ex){
+			return false;
+		}
+	}
+}

+ 188 - 0
src/main/java/com/leanwo/management/service/ProcessService.java

@@ -0,0 +1,188 @@
+package com.leanwo.management.service;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.List;
+
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.DefaultExecuteResultHandler;
+import org.apache.commons.exec.DefaultExecutor;
+import org.apache.commons.exec.ExecuteWatchdog;
+import org.apache.commons.exec.LogOutputStream;
+import org.apache.commons.exec.PumpStreamHandler;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Service;
+
+import com.leanwo.management.ServerLogFrame;
+import com.leanwo.management.model.ApplicationSetting;
+import com.leanwo.management.util.SpringUtil;
+
+/**
+ * 进程服务
+ * @author YangZhiJie1
+ *
+ */
+public class ProcessService implements StatusService {
+	
+	private static Logger logger = Logger.getLogger(ProcessService.class);
+	
+	/**
+	 * 启动新的程序
+	 * @param setting
+	 * @return
+	 * @throws IOException
+	 */
+	public ProgramRunResult startProgram(ApplicationSetting setting) throws IOException{
+		File workingDirectory = new File(setting.getInstallPath());
+		ProgramRunResult programRunResult = null;
+		
+		if(setting.getStartCommand() != null && setting.getStartCommand().length() > 0) {
+			programRunResult = runProgram(workingDirectory, setting.getStartCommand());
+		}else if(setting.getStartBatFile() != null && setting.getStartBatFile().length() > 0) {
+			String fullPath = setting.getInstallPath() + File.separator + setting.getStartBatFile();
+			File batFile = new File(fullPath);
+			programRunResult = runProgram(workingDirectory, batFile);
+		}
+		return programRunResult;
+	}
+	
+	/**
+	 * 关闭程序
+	 * @param setting
+	 * @return
+	 * @throws IOException
+	 */
+	public ProgramRunResult stopProgram(ApplicationSetting setting) throws IOException{
+		File workingDirectory = new File(setting.getInstallPath());
+		ProgramRunResult programRunResult = null;
+
+		if(setting.getStopBatFile() != null && setting.getStopBatFile().length() > 0) {
+			String fullPath = setting.getInstallPath() + File.separator + setting.getStopBatFile();
+			File batFile = new File(fullPath);
+			programRunResult = runProgram(workingDirectory, batFile);
+		}
+		
+		return programRunResult;
+	}
+	
+	/**
+	 * 运行程序
+	 * @param workingDirectory
+	 * @param command
+	 * @return
+	 * @throws IOException
+	 */
+	public ProgramRunResult runProgram(File workingDirectory, File batFile) throws IOException{
+		if(!workingDirectory.exists()) {
+			throw new FileNotFoundException("安装目录:" + workingDirectory.getAbsolutePath() + "不存在。" );
+		}
+		if(!workingDirectory.isDirectory()) {
+			throw new FileNotFoundException("安装目录:" + workingDirectory.getAbsolutePath() + "不是目录。" );
+		}
+		
+		if(!batFile.exists()) {
+			throw new FileNotFoundException("BAT执行文件:" + batFile.getAbsolutePath() + "不存在。" );
+		}
+		if(!batFile.isFile()) {
+			throw new FileNotFoundException("BAT执行文件:" + batFile.getAbsolutePath() + "不是文件。" );
+		}
+		
+		return runProgram(workingDirectory, batFile.getAbsolutePath());
+	}
+	
+	/**
+	 * 运行流程
+	 * @param command "cmd.exe /c start c://example.exe"
+	 * @return
+	 * @throws IOException
+	 */
+	public ProgramRunResult runProgram(File workingDirectory, String command) throws IOException {
+		if(command == null || command.length() == 0) {
+			return null;
+		}
+		
+		logger.info("即将运行命令:" + command);
+		
+		final CommandLine cmdLine = CommandLine.parse(command);
+		
+		final ExecuteWatchdogEx watchDog = new ExecuteWatchdogEx(Long.MAX_VALUE);
+		
+		// 非阻塞方式执行进程
+		final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
+		DefaultExecutor executor = new DefaultExecutor();
+		executor.setWatchdog(watchDog);
+		
+		PipedOutputStream outPipedOutputStream = new PipedOutputStream();
+		PipedOutputStream errorPipedOutputStream = new PipedOutputStream();
+
+		PipedInputStream outPipedInputStream = new PipedInputStream(outPipedOutputStream);
+		PipedInputStream errorPipedInputStream = new PipedInputStream(errorPipedOutputStream);
+		
+		executor.setStreamHandler(new PumpStreamHandler(outPipedOutputStream, errorPipedOutputStream));
+		
+		executor.setWorkingDirectory(workingDirectory);
+		executor.execute(cmdLine, resultHandler);
+
+		ProgramRunResult programRunResult = new ProgramRunResult();
+		programRunResult.setWatchDog(watchDog);
+		programRunResult.setOutPipedInputStream(outPipedInputStream);
+		programRunResult.setErrorPipedInputStream(errorPipedInputStream);
+		
+		return programRunResult;
+	}
+	
+
+	/**
+	 * 程序自动运行
+	 */
+	public void autoStart(List<ApplicationSetting> settings, ServerLogFrame serverLogFrame) {
+		if (settings != null && settings.size() > 0) {
+			for(int i = 0; i < settings.size(); i ++) {
+				final ApplicationSetting setting = settings.get(i);
+				ProgramRunResult programRunResult;
+				try {
+					programRunResult = startProgram(setting);
+					if(programRunResult != null && programRunResult.getWatchDog() != null) {
+						boolean isAlive = programRunResult.getWatchDog().isAlive();
+						if(! isAlive) {
+							logger.error("程序" + setting.getName() + "启动失败");
+						}
+						setting.setProgramRunResult(programRunResult);
+						serverLogFrame.updateProgramRunResult(i, programRunResult);
+					}
+				} catch (IOException e) {
+					logger.error("程序" + setting.getName() + "启动失败", e);
+				}
+			}
+		}
+	}
+	
+
+	/**
+	 * 获取服务器的状态
+	 * @param setting
+	 * @return true: 运行中 false: 不在运行
+	 */
+	@Override
+	public Boolean getStatus(ApplicationSetting setting) {
+		ProgramRunResult programRunResult = setting.getProgramRunResult();
+		if(programRunResult != null) {
+			ExecuteWatchdogEx executeWatchdog = programRunResult.getWatchDog();
+			if(executeWatchdog == null) {
+				return false;
+			}else{
+				if(executeWatchdog.isAlive()) {
+					return true;
+				}else {
+					return false;
+				}
+			}
+		}else {
+			return false;
+		}
+	}
+}

+ 50 - 0
src/main/java/com/leanwo/management/service/ProgramRunResult.java

@@ -0,0 +1,50 @@
+package com.leanwo.management.service;
+
+import java.io.PipedInputStream;
+
+import org.apache.commons.exec.ExecuteWatchdog;
+
+/**
+ * 程序运行结果
+ * @author YangZhiJie1
+ *
+ */
+public class ProgramRunResult {
+	
+	private ExecuteWatchdogEx watchDog;
+	
+	/**
+	 * Out输入流
+	 */
+	private PipedInputStream outPipedInputStream;
+	
+	/**
+	 * Error输入流
+	 */
+	private PipedInputStream errorPipedInputStream;
+
+	public ExecuteWatchdogEx getWatchDog() {
+		return watchDog;
+	}
+
+	public void setWatchDog(ExecuteWatchdogEx watchDog) {
+		this.watchDog = watchDog;
+	}
+
+
+	public PipedInputStream getOutPipedInputStream() {
+		return outPipedInputStream;
+	}
+
+	public void setOutPipedInputStream(PipedInputStream outPipedInputStream) {
+		this.outPipedInputStream = outPipedInputStream;
+	}
+
+	public PipedInputStream getErrorPipedInputStream() {
+		return errorPipedInputStream;
+	}
+
+	public void setErrorPipedInputStream(PipedInputStream errorPipedInputStream) {
+		this.errorPipedInputStream = errorPipedInputStream;
+	}
+}

+ 18 - 0
src/main/java/com/leanwo/management/service/StatusService.java

@@ -0,0 +1,18 @@
+package com.leanwo.management.service;
+
+import com.leanwo.management.model.ApplicationSetting;
+
+/**
+ * 状态服务
+ * @author YangZhiJie1
+ *
+ */
+public interface StatusService {
+
+	/**
+	 * 获取服务器的状态
+	 * @param setting
+	 * @return true: 运行中 false: 不在运行
+	 */
+	public Boolean getStatus(ApplicationSetting setting);
+}

+ 51 - 0
src/main/java/com/leanwo/management/util/CloseableUtil.java

@@ -0,0 +1,51 @@
+package com.leanwo.management.util;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+/**
+ * 需关闭资源工具类
+ * @author YangZhiJie
+ *
+ */
+public class CloseableUtil {
+	private final static Logger logger = Logger.getLogger(CloseableUtil.class);
+
+	/**
+	 * 关闭资源
+	 * @param closeables
+	 */
+	public static void close(Closeable... closeables) {
+		if (closeables != null && closeables.length > 0) {
+			for (int i = 0; i < closeables.length; i++) {
+				if (closeables[i] != null) {
+					try {
+						closeables[i].close();
+					} catch (IOException e) {
+						logger.error("资源释放失败", e);
+					}
+				}
+			}
+		}
+	}
+	
+	/**
+	 * 关闭资源
+	 * @param closeables
+	 */
+	public static void close(AutoCloseable... closeables) {
+		if(closeables != null && closeables.length > 0) {
+			for(int i = 0; i < closeables.length ; i ++) {
+				if(closeables[i] != null) {
+					try {
+						closeables[i].close();
+					} catch (Exception e) {
+						logger.error("资源释放失败", e);
+					}
+				}
+			}
+		}
+	}
+}

+ 1 - 1
src/main/java/org/leanwo/management/util/ProgramAutoStartUtil.java → src/main/java/com/leanwo/management/util/ProgramAutoStartUtil.java

@@ -1,4 +1,4 @@
-package org.leanwo.management.util;
+package com.leanwo.management.util;
 
 import java.io.BufferedWriter;
 import java.io.File;

+ 1 - 1
src/main/java/org/leanwo/management/util/ProgramStartUtil.java → src/main/java/com/leanwo/management/util/ProgramStartUtil.java

@@ -1,4 +1,4 @@
-package org.leanwo.management.util;
+package com.leanwo.management.util;
 
 import java.io.BufferedWriter;
 import java.io.File;

+ 1 - 1
src/main/java/org/leanwo/management/util/ProgramStopUtil.java → src/main/java/com/leanwo/management/util/ProgramStopUtil.java

@@ -1,4 +1,4 @@
-package org.leanwo.management.util;
+package com.leanwo.management.util;
 
 import java.io.BufferedWriter;
 import java.io.File;

+ 3 - 2
src/main/java/org/leanwo/management/util/SpringUtil.java → src/main/java/com/leanwo/management/util/SpringUtil.java

@@ -1,14 +1,15 @@
-package org.leanwo.management.util;
+package com.leanwo.management.util;
 
 import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.leanwo.management.exception.BeanNotInjectException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
 
+import com.leanwo.management.exception.BeanNotInjectException;
+
 
 public class SpringUtil implements ApplicationContextAware {
 	private static Log logger = LogFactory.getLog(SpringUtil.class);

+ 2 - 2
src/main/java/org/leanwo/management/util/XmlConfigPathService.java → src/main/java/com/leanwo/management/util/XmlConfigPathService.java

@@ -1,4 +1,4 @@
-package org.leanwo.management.util;
+package com.leanwo.management.util;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
@@ -24,8 +24,8 @@ import org.dom4j.Element;
 import org.dom4j.io.OutputFormat;
 import org.dom4j.io.SAXReader;
 import org.dom4j.io.XMLWriter;
-import org.leanwo.management.exception.ConfigFileException;
 
+import com.leanwo.management.exception.ConfigFileException;
 import com.leanwo.management.model.ApplicationSetting;
 import com.leanwo.management.model.XmlConfigPath;
 

+ 43 - 0
src/main/java/com/leanwo/management/widget/ColorCellRenderer.java

@@ -0,0 +1,43 @@
+package com.leanwo.management.widget;
+
+import java.awt.Color;
+import java.awt.Component;
+
+import javax.swing.JTable;
+import javax.swing.table.DefaultTableCellRenderer;
+
+import com.leanwo.management.util.Variable;
+
+public class ColorCellRenderer extends DefaultTableCellRenderer {
+    @Override
+    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
+        Component com = super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
+        
+        if(column == 0 || column == 1) {
+	    	Color foreground, background;   
+			if (row == table.getSelectedRow()) {
+				foreground = Color.BLUE;
+				background = Color.BLUE;
+			} else {
+				foreground = Color.BLACK;
+				background = Color.BLACK;
+			} 
+	        com.setForeground(foreground);   
+	        com.setBackground(background); 
+        }
+        
+        
+        if (column == 2) {
+        	if(value != null && value.toString().equals(Variable.RUNNING)) {
+                com.setBackground(Color.GREEN);
+        	}else if(value != null && value.toString().equals(Variable.NOT_RUNNING)){
+                com.setBackground(Color.RED);
+        	}else {
+                com.setBackground(Color.GRAY);        		
+        	}
+        }else {
+            com.setBackground(Color.WHITE);  
+        }
+        return com;
+    }
+}

+ 30 - 0
src/main/java/com/leanwo/management/widget/DefaultMenuListener.java

@@ -0,0 +1,30 @@
+package com.leanwo.management.widget;
+
+import javax.swing.JMenu;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
+
+public class DefaultMenuListener implements MenuListener{
+
+	private JMenu menu;
+	
+	public DefaultMenuListener(JMenu menu) {
+		this.menu = menu;
+	}
+	
+	@Override
+	public void menuSelected(MenuEvent e) {
+		menu.setSelected(false);
+	}
+
+	@Override
+	public void menuDeselected(MenuEvent e) {
+		menu.setSelected(false);
+	}
+
+	@Override
+	public void menuCanceled(MenuEvent e) {
+		menu.setSelected(false);
+	}
+
+}

+ 12 - 0
src/main/java/com/leanwo/management/widget/SelectEventListener.java

@@ -0,0 +1,12 @@
+package com.leanwo.management.widget;
+
+import java.util.EventListener;
+
+/**
+ * 表格选择事件
+ * @author YangZhiJie1
+ *
+ */
+public interface SelectEventListener extends EventListener{
+	public void onSelect(SelectObject event);
+}

+ 20 - 0
src/main/java/com/leanwo/management/widget/SelectObject.java

@@ -0,0 +1,20 @@
+package com.leanwo.management.widget;
+
+import java.util.EventObject;
+
+public class SelectObject extends EventObject{
+	private int index;
+	
+	public SelectObject(Object source, int index) {
+		super(source);
+		this.index = index;
+	}
+
+	public int getIndex() {
+		return index;
+	}
+
+	public void setIndex(int index) {
+		this.index = index;
+	}
+}

+ 78 - 0
src/main/java/com/leanwo/management/widget/TableButtonCell.java

@@ -0,0 +1,78 @@
+package com.leanwo.management.widget;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.EventObject;
+
+import javax.swing.AbstractCellEditor;
+import javax.swing.JButton;
+import javax.swing.JOptionPane;
+import javax.swing.JTable;
+import javax.swing.UIManager;
+import javax.swing.table.TableCellEditor;
+import javax.swing.table.TableCellRenderer;
+
+public class TableButtonCell extends AbstractCellEditor implements TableCellEditor, TableCellRenderer{
+	private static final long serialVersionUID = 1L;
+	private JButton button = null;
+	
+	private int selectedRow;
+	private int selectedColumn;
+	
+	private String label;
+
+	public TableButtonCell(TableButtonListener tableButtonListener) {
+		button = new JButton();
+		button.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+
+				// 非常重要
+				// 触发取消编辑的事件,不会调用tableModel的setValue方法。
+                fireEditingCanceled();  
+                
+				if(tableButtonListener != null) {
+					tableButtonListener.tableButtonClicked(selectedRow, selectedColumn);
+				}
+				
+				// 非常重要
+                fireEditingStopped();
+			}
+		});
+	}
+
+	
+	@Override
+	public Object getCellEditorValue() {
+		//return button.getText();
+		return null;
+	}
+
+	@Override
+	public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
+		selectedRow = row;
+		selectedColumn = column;
+		
+		if (isSelected) {
+			button.setForeground(table.getSelectionForeground());
+			button.setBackground(table.getSelectionBackground());
+		} else {
+			button.setForeground(table.getForeground());
+			button.setBackground(table.getBackground());
+		}
+		
+		label = (value == null) ? "" : value.toString();
+		button.setText(label);
+		return button;
+	}
+	
+
+	@Override
+	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
+	
+		
+		button.setText((value == null) ? "" : value.toString());
+		return button;
+	}
+}

+ 7 - 0
src/main/java/com/leanwo/management/widget/TableButtonListener.java

@@ -0,0 +1,7 @@
+package com.leanwo.management.widget;
+
+import java.util.EventListener;
+
+public interface TableButtonListener extends EventListener {
+	public void tableButtonClicked(int row, int column);
+}

+ 0 - 0
src/main/java/com/leanwo/management/prodog_16.png → src/main/resources/com/leanwo/management/prodog_16.png


+ 0 - 0
src/main/java/commons-logging.properties → src/main/resources/commons-logging.properties


+ 0 - 0
src/main/java/log4j.properties → src/main/resources/log4j.properties