/* $Id: WebDavSyncActionListener.java 220 2011-06-12 02:37:52Z minao $ */
package smart_gs.swingui.toolbar.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.Stack;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

import smart_gs.swingui.WorkspaceWindow;
import smart_gs.logical.Preference;
import webdav.WebDavChooser;
import webdav.WebDavDownLoadEvent;
import webdav.WebDavListenerAction;
import webdav.WebDavProcessor;
public class WebDavSyncActionListener implements ActionListener {

	public void actionPerformed(ActionEvent e) {

		//2009/01/23 North Grid
		Preference preference = Preference.getInstance();
		//2008/9/8 North Grid
		//更新時に確認ダイアログを表示する仕組みを追加
		WorkspaceWindow window = WorkspaceWindow.getInstance();
		if( WorkspaceWindow.isUpdated() ){
			File file = window.getCurrentFile();
			String filename = null;
			if (file != null) {
				filename = file.getName();
			}
			int input = JOptionPane.showConfirmDialog(window, 
					(filename == null ? 
							"Save the edited contents?" :
							"\""+ filename + "\"   Save this file?")
					);
			
			if (input == JOptionPane.OK_OPTION) {
				
				if(window.getLastsave() == 0){
					if( window.saveAll() == false ) return;
				}else{
					WebDavListenerAction webDavListenerAction = new WebDavListenerAction();
					webDavListenerAction.save();
				}
			} else if (input == JOptionPane.NO_OPTION) {

			} else if (input == JOptionPane.CANCEL_OPTION) {
				return;
			}
		}		
		
		//2007/10/7 kazuhiro kobayashi
		//2009/01/23 North Grid
		WebDavListenerAction webDavListenerAction = new WebDavListenerAction();
		webDavListenerAction.sync();
	}
	
}
