/******************************************************************************
 GSimpleFileTreeNode.h

	Interface for GSimpleFileTreeNode class.

	Copyright <A9> 1997 by Glenn W. Bach. All rights reserved.

 ******************************************************************************/

#ifndef _H_GSimpleFileTreeNode
#define _H_GSimpleFileTreeNode

#include <JUNIXDirEntry.h>
#include <JPtrArray.h>
#include "JNamedTreeNode.h"
#include <JRegex.h>
#include <jTime.h>
#include <JFontStyle.h>

class JUNIXDirInfo;
class GSimpleFileTree;
class JTreeList;
class JError;

class GSimpleFileTreeNode : public JNamedTreeNode
{
public:

	GSimpleFileTreeNode(GSimpleFileTree* tree, JUNIXDirEntry* 	entry,
						const char* name = "BASE",
						const JBoolean isBranch = kTrue);

	GSimpleFileTreeNode(GSimpleFileTree* tree, JUNIXDirEntry* 	entry,
						JNamedTreeNode* parent = NULL,
						const char* name = "BASE",
						const JBoolean isBranch = kTrue);

	virtual ~GSimpleFileTreeNode();
	
	JUNIXDirEntry::Type GetType() const;
	
	virtual JBoolean OKToChange() const;
	
	void 			Update();
	JBoolean		UpdateDir(JTreeList* list);
	void 			ForceUpdate();
	JUNIXDirEntry* 	GetDirEntry();
	JString 		GetFullPathAndName() const;
	virtual void	BuildChildList();
	JBoolean		FindChild(const JCharacter* name, GSimpleFileTreeNode** node);
	
	virtual JFontStyle	GetFontStyle();
	GSimpleFileTree*	GetFileTree();

	void			SetNameAndUpdate(const JCharacter* newName);

protected:

	virtual JBoolean 	OKToOpen() const;
	virtual JBoolean	OKToAppendChild(const JUNIXDirEntry& entry);
	virtual void		CreateChild(JUNIXDirEntry* entry, 
									GSimpleFileTreeNode** node,
									const JBoolean isBranch,
									const JBoolean append = kTrue);
	
private:
	
	void GSimpleFileTreeNodeX(GSimpleFileTree* tree, JUNIXDirEntry* entry,
						const char* name = "BASE",
						const JBoolean isBranch = kTrue);
	void UpdateChildren();
	
private:

	JUNIXDirInfo* 	itsDirInfo;
	JCoordinate 	itsNumChildren;
	JBoolean 		itsChildrenInitialized;
	JUNIXDirEntry* 	itsEntry;
	time_t			itsModTime;
	time_t			itsStatusTime;
	GSimpleFileTree* itsTree;
	JRegex			itsRegex;
	JBoolean		itsUsesCookies;
	JBoolean		itsEmptyOK;

private:

	// not allowed

	GSimpleFileTreeNode(const GSimpleFileTreeNode& source);
	const GSimpleFileTreeNode& operator=(const GSimpleFileTreeNode& source);

};

/******************************************************************************
 GetFileTree

 ******************************************************************************/

inline GSimpleFileTree*	
GSimpleFileTreeNode::GetFileTree()
{
	return itsTree;
}
#endif
