/* $Id: ShowSpreadAction.java 278 2011-07-29 02:30:03Z ohura $ */
package smart_gs.swingui.toolbar.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

import smart_gs.logical.GSResource;
import smart_gs.logical.Spread;
import smart_gs.logical.SpreadTree;
import smart_gs.smleditor.swingui.GSEditor;
import smart_gs.swingui.IDATNameInGSTabbedPaneManager;
import smart_gs.swingui.WorkspaceWindow;

public class ShowSpreadAction implements ActionListener{
	public void actionPerformed(ActionEvent e) {
		GSResource selected;
		Spread spread;
		TreePath[] paths = SpreadTree.getInstance().getSelectedPaths();
		if (paths != null && paths.length !=0) {
			selected = (GSResource)((DefaultMutableTreeNode)paths[0].getLastPathComponent()).getUserObject();
		} else return;				
		if (selected instanceof Spread) {
			 spread = (Spread)selected;
		} else return;

		if(spread == null){
			JOptionPane.showMessageDialog(WorkspaceWindow.getInstance(), "Select Spread");
			return;
		}
		WorkspaceWindow.getInstance().tabbedPaneSave();
		GSEditor editor = new GSEditor(spread);
		IDATNameInGSTabbedPaneManager.registorGSEditorTabbedPane(editor.getSMLTabbedPane());
		editor.setVisible(true);
	}
}
