/* $Id: NewCompactEditorAction.java 535 2012-08-21 04:55:59Z shayashi $ */
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 NewCompactEditorAction 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,GSEditor.COMPACT);
		IDATNameInGSTabbedPaneManager.registorGSEditorTabbedPane(editor.getSMLTabbedPane());
		editor.setVisible(true);
	}
}
