// File: ActionShowDocuments.java
// Classes: ActionShowDocuments
// Author: Kedar Patankar

package EDU.neu.ccs.demeter.tools.apstudio.graphedit;

import java.util.Vector;
import java.util.Enumeration;


/** Action to show the help topics */

public class ActionShowDocuments extends Action
{
	private Vector openDocumentNames;

	public ActionShowDocuments(Editor e,Vector v)
	{
		super(e);
		openDocumentNames=v;
	}

	public String name() { return "Show Documents dialog"; }

	public void doIt()
	{
		WindowDialog wd = new WindowDialog(_editor,"Windows",openDocumentNames);
		wd.setVisible(true);

		String choice=wd.getRequest();
		Vector v = wd.getSelection();
		if(choice.equals("SHOW"))
		{
			_editor.showDocument((String)v.elementAt(0));
			_editor.setCurrentMenuString((String)v.elementAt(0));
			return;
		}
		else
		if(choice.equals("CANCEL"))
			return;
// Control comes here when the choice is other than Show and Cancel which will be Close
// If only one filename was selected call ActionClose 
		if(v.size()==1)
		{
			Action act=new ActionClose(_editor,_editor.getDocument((String)v.elementAt(0)));
			act.doIt();
		}
		else
		{
// else separate files into modified and nomodified vectors.
			Vector all = v;
			Vector non = _editor.get_outStanding();
			Vector vClose = new Vector();
			Vector vSaveNClose = new Vector();

			int j=all.size();
			for(int i=0;i<j;i++)
			{
				String name = (String) all.elementAt(i);
				if(non.contains(name))
					vSaveNClose.addElement(name);
				else
					vClose.addElement(name);
			}
// Call ActionClose on nonmodified iteratively
			j=vClose.size();
			for(int i=0;i<j;i++)
			{
				ActionClose act= new ActionClose(_editor,_editor.getDocument((String) vClose.elementAt(i)));
				act.doIt();
			}
// Call ActionCloseMultiple with the list of modified filenames
// Files those need saving are passed to ActionCloseMultiple to handle
			ActionCloseMultipleCds act = new ActionCloseMultipleCds(_editor,vSaveNClose); 
			act.doIt(); // This can come out inbetween because user clicked cancel sometime during saving.
		}
		
	}

	public void undoIt() { }

} /* end class ActionShowDocuments */

