/*
 * @(#)RidProjectConfigAction.java
 *
 * Copyright 2001 Nomura Research Institute, LTD. All rights reserved.
 *
 * RID-X : rid project config action
 *
 * @author  Intelligent Technology Inc.
 * @version 1.01 2003/04/09
 */
package jp.co.nri.rid.action;

import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;

import java.io.File;
import java.io.IOException;

import javax.swing.JFileChooser;

import	javax.xml.transform.*;	// Transformer TransformerFactory TransformerConfigurationException TransformerException
import	javax.xml.transform.stream.*;	// StreamResult StreamSource
import	javax.xml.transform.dom.*;

import jp.co.iti.fagot.doc.DocDocument;

import jp.co.iti.fagot.IZApp;
import jp.co.iti.fagot.action.ZAction;

import jp.co.iti.fagot.util.ZInstance;
import jp.co.iti.fagot.util.ZResource;
import jp.co.iti.fagot.util.ZDebug;

import jp.co.nri.Ridual;
import jp.co.nri.Rid;

import jp.co.nri.rid.environment.MessageDialog;
import jp.co.nri.rid.error.RidMessage;

import jp.co.nri.rid.doc.RidExecAction;
import	jp.co.nri.rid.environment.*;

/**
 * Rid Project Config系アクションを定義する
 */
public class RidProjectConfigAction extends ZAction {
	/**
	 * 唯一のコンストラクタです。
	 * @param app アプリケーション
	 * @param szAction アクション名
	 */
	public RidProjectConfigAction(IZApp app,String szAction) { super(app,szAction); }
	
	/**
	 * アクション実行
	 */
	public void doAction(ActionEvent e) {
		if ( getActionName().equals( SET_HTMLDIR ) ) {
			if(null == dialog)	dialog = new HtmlDirDialog();
			dialog.show();
		} else if ( getActionName().equals( CHG_TOPZONEURL ) ) {
			String url = JOptionPane.showInputDialog(getApp().getFrame(), getApp().getResource().getString("msg.topzoneurl.title"), Ridual.getTopZoneURL());
			if(null != url){
				Ridual.setTopZoneURL(url);
			}
		}
/*
		else if ( getActionName().equals( CHG_HTMLDIR ) ) {
	    	if (mDialog == null) {
//				ZResource res = getApp().getResource();
				mDialog = new JFileChooser();
				
				
				// ディレクトリ選択にする
				mDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
			}
			
			File htmldir= new File(Ridual.getHtmlDir());
			mDialog.setSelectedFile(htmldir);
			File parent	= htmldir.getParentFile();
			mDialog.setCurrentDirectory( (null == parent) ? htmldir : parent );
			
			// ダイアログを開く
			int nRet = mDialog.showOpenDialog(getApp().getFrame());
			if ( nRet != JFileChooser.APPROVE_OPTION) return;
			
			File file = mDialog.getSelectedFile();
			Ridual.setHtmlDir(file.getAbsolutePath());
		} else if ( getActionName().equals( CHG_HTMLBASE ) ) {
			String pip = JOptionPane.showInputDialog(getApp().getFrame(), "html dir at PIP", Ridual.getHtmlDirPIP());
//			if(null != pip){
//				Ridual.setHtmlDirPIP(pip);
//				createIndex1();
//			}
		}
*/
	}

	/**
	 * UI更新
	 */
	public void update() {}
	
/*
	private	void createIndex1(){
		File dir = new File(ZInstance.prop().getProperty( Rid.PJ_DIR ) ,getApp().getResource().getString("rid.admin.dir"));
		
		StreamSource	xsl = new StreamSource(new File(dir, "index_1.xsl"));
		
		TransformerFactory factory = TransformerFactory.newInstance();
		
		try{
			Transformer transformer = factory.newTransformer(xsl);
			transformer.setOutputProperty("method", "html");
			transformer.setOutputProperty("encoding", "Shift_JIS");
			
			transformer.transform(new DOMSource((DocDocument)ZInstance.map().get(Rid.DOCUMENT_SITE)), new StreamResult(new File(dir, "index_1.html")));
		} catch(Throwable t) { t.printStackTrace(); }
	}
*/
	
	//## アトリビュート ###############################################
    /**
     * ダイアログボックス
     */
//    private JFileChooser mDialog = null;
    
	private HtmlDirDialog dialog = null;
	
    /**
     * アクション名：HTMLディレクトリ変更
     */
//	final static public String CHG_HTMLDIR			= "changeHtmlDir" ;
	
    /**
     * アクション名：HTMLディレクトリ設定
     */
	final static public String SET_HTMLDIR			= "setHtmlDir" ;
	
    /**
     * アクション名：HTML Base変更
     */
//	final static public String CHG_HTMLBASE			= "changeHtmlBase" ;

	final static public String CHG_TOPZONEURL		= "changeTopZoneURL" ;
}
