/******************************************************************************
 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 <JFontStyle.h>
#include <JRegex.h>
#include <jTime.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;
	
	JBoolean		UpdateNode(const JBoolean force);
	JBoolean		UpdateDir(const JBoolean force = kFalse);

	JUNIXDirEntry* 	GetDirEntry();
	
	const JUNIXDirEntry* 	GetDirEntry() const;
	
	JString 		GetFullPathAndName() const;
	virtual void	BuildChildList();
	JBoolean		FindChild(const JCharacter* name, GSimpleFileTreeNode** node);
	
	virtual JFontStyle	GetFontStyle();

	void			SetNameAndUpdate(const JCharacter* newName);
	void			SetFullNameAndUpdate(const JCharacter* newFullName);

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);

	JUNIXDirInfo* 		GetDirInfo();
	const JUNIXDirInfo* GetDirInfo() const;

	void 				UpdateChildren();

	virtual void		PathChanged();

	void	ChangeSort(
				JOrderedSetT::CompareResult (*compareFn)(JTreeNode * const &,
														 JTreeNode * const &),
				const JOrderedSetT::SortOrder order);

	static JOrderedSetT::CompareResult
		CompareUser(JTreeNode * const & e1, JTreeNode * const & e2);

	static JOrderedSetT::CompareResult
		CompareGroup(JTreeNode * const & e1, JTreeNode * const & e2);

	static JOrderedSetT::CompareResult
		CompareSize(JTreeNode * const & e1, JTreeNode * const & e2);

	static JOrderedSetT::CompareResult
		CompareDate(JTreeNode * const & e1, JTreeNode * const & e2);
	
private:

	JUNIXDirInfo* 	itsDirInfo;
	JBoolean 		itsChildrenInitialized;
	JUNIXDirEntry* 	itsEntry;

private:

	void GSimpleFileTreeNodeX(GSimpleFileTree* tree, JUNIXDirEntry* entry,
						const char* name = "BASE",
						const JBoolean isBranch = kTrue);
	
	// not allowed

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

};

/******************************************************************************
 GetDirInfo (protected)

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


inline JUNIXDirInfo*
GSimpleFileTreeNode::GetDirInfo()
{
	return itsDirInfo;
}

inline const JUNIXDirInfo*
GSimpleFileTreeNode::GetDirInfo()
	const
{
	return itsDirInfo;
}

/******************************************************************************
 GetDirEntry

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

inline JUNIXDirEntry*
GSimpleFileTreeNode::GetDirEntry()
{
	return itsEntry;
}

inline const JUNIXDirEntry*
GSimpleFileTreeNode::GetDirEntry()
	const
{
	return itsEntry;
}

#endif
