/*
 * Copyright (C) 2005 NTT DATA Corporation
 * 
 */
package org.postgresforest.tool.view.action;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.IViewPart;
import org.postgresforest.tool.action.DbInstanceAction;
import org.postgresforest.tool.db.GSCdata;
import org.postgresforest.tool.dialog.addinstance.AddInstanceDialog;
import org.postgresforest.tool.util.ErrorLog;
import org.postgresforest.tool.util.SessionProperty;

/**
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class AddInstanceAction extends ActionBase {
    public static final String ID = "org.postgresforest.tool.view.action.AddInstanceAction";
	private AddInstanceDialog m_dialog;
	
	public void init(IViewPart view) {
		super.init(view);
		m_dialog = new AddInstanceDialog();

	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
	public void run(IAction action) {
		//インスタンス登録ダイアログを表示する
		if (m_dialog.open() == Window.OK) {
			//ホスト名、ポートNoを取得
			String host = m_dialog.getHostName();
			String port = m_dialog.getPort();
	
			
			//インスタンス登録
			if(host != "" && port != ""){
				DbInstanceAction instance = new DbInstanceAction((GSCdata)SessionProperty.get("gsc"));
				try {
					instance.addInstance(host, port);
				} catch (Exception e1) {
					ErrorLog.log("", e1);
				}
			}
		}
		//インスタンスビューを更新
		m_view.update();
		
	}


}
