package com.github.SimonXianyu.codefather.ui;

import com.github.SimonXianyu.codefather.BaseCodeFatherMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

import javax.swing.*;

/**
 * Created by Simon Xianyu on 2014/11/4.
 * @goal gui
 */
public class GuiMojo extends BaseCodeFatherMojo {
    private MainPanel mainPanel;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        if (!init()) {
            return;
        }

        mainPanel = new MainPanel();
        mainPanel.initGui();

        readGlobalConfig();
//        collectTemplate();
        collectEntities();


        JFrame mainFrame = new JFrame("Code father gui");
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainFrame.setContentPane(mainPanel);
        mainFrame.pack();
        mainFrame.setLocationRelativeTo(null);
        mainFrame.setVisible(true);
    }

    private boolean init() {
        return !checkCodeFatherPath();
    }
}

@@ -231,16 +231,138 @@
 swing.*;
+%0Aimport java.awt.event.WindowAdapter;%0Aimport java.awt.event.WindowEvent;%0Aimport java.util.concurrent.atomic.AtomicBoolean;
 %0A%0A/**%0A *
@@ -467,16 +467,17 @@
 rMojo %7B%0A
+%0A
     priv
@@ -484,27 +484,97 @@
 ate 
-MainPanel mainPanel
+AtomicBoolean runFlag = new AtomicBoolean(false);%0A%0A    private Object lock = new Object()
 ;%0A%0A 
@@ -720,24 +720,25 @@
      %7D%0A%0A
+%0A
         
 mainPane
@@ -721,32 +721,42 @@
     %7D%0A%0A%0A        
+MainPanel 
 mainPanel = new 
@@ -883,16 +883,573 @@
 ies();%0A%0A
+        runFlag.set(true);%0A        Thread waitingThread= new Thread() %7B%0A            @Override%0A            public void run() %7B%0A                synchronized (lock) %7B%0A                    while (runFlag.get() ) %7B%0A                        try %7B%0A                            lock.wait();%0A                        %7D catch (InterruptedException e) %7B%0A//                            e.printStackTrace();%0A                            // no need care.%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D%0A        %7D;%0A        waitingThread.start();%0A
 %0A       
@@ -1553,12 +1553,15 @@
 ame.
-EXIT
+DISPOSE
 _ON_
@@ -1590,143 +1590,513 @@
 ame.
-setContentPane(mainPanel);%0A        mainFrame.pack();%0A        mainFrame.setLocationRelativeTo(null);%0A        mainFrame.setVisible(true);
+addWindowListener(new WindowAdapter() %7B%0A            @Override%0A            public void windowClosed(WindowEvent e) %7B%0A                super.windowClosed(e);%0A                runFlag.set(false);%0A            %7D%0A        %7D);%0A        mainFrame.setContentPane(mainPanel);%0A        mainFrame.pack();%0A        mainFrame.setLocationRelativeTo(null);%0A        mainFrame.setVisible(true);%0A%0A        try %7B%0A            waitingThread.join();%0A        %7D catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A        %7D
 %0A   

make thread to wait jframe closed