This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 3 - Pages: 1 - Last Post: 23-Dec-2015 20:08 Last Post By: davidekholm
RobM

Posts: 4,890
Registered: 4-Aug-2006
How to get a project's parent folder
Posted: 12-Dec-2015 22:54
 
  Click to reply to this thread Reply
Is there a way of extending jAlbum objects such that a project's parent folder is accessible?

Reason: When making an album of albums the conventional navigation is up/down the folder structure. I want to be able to navigate from anywhere in one sub-project directly to anywhere in another. At the moment I do this by asking for the name of the master project when making a sub-project, but being able to find that programmatically would be tidier and remove the chance of a wrong entry by a user.

Edited by: RobM on 12-Dec-2015 22:11
Something like this is what I would like
for (AlbumObject ao : rootFolder.getParent().getChildren()) {
			if (ao.isIncluded() && !ao.isHidden()) {
davidekholm

Posts: 21,773
Registered: 18-Oct-2002
Re: How to get a project's parent folder
Posted: 14-Dec-2015 10:23   in response to: RobM in response to: RobM
Helpful
  Click to reply to this thread Reply
Here's an untested example of getting another "sibling" folder tree:
File siblingRoot = new File(rootFolder.getFile().getParentFile(), "sibling");
AlbumObject siblingRoot = rootFolder.getFactory().createInstance(siblingFile);
// Now use siblingRoot.getChildren() to traverse the sibling tree
RobM

Posts: 4,890
Registered: 4-Aug-2006
Re: How to get a project's parent folder
Posted: 16-Dec-2015 23:46   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Thanks David, that gave me the information I needed to make it work.
For anyone else interested in navigating between sub-projects in a
master/sub-project configuration this is how I did it. In init.bsh add
// Generate navigation links for sub-projects that are part of a master project
void projectNavigationMenu() {
// Get the master project's folder by going up two levels and down one to the actual folder
File masterProjectFolder = new File(rootFolder.getFile().getParentFile().getParentFile(), rootFolder.getFile().getParentFile().getName());
// Make the master project's folder an object
AlbumObject masterProjectObject = rootFolder.getFactory().createInstance(masterProjectFolder);
 
// Now use masterProjectObject.getChildren() to traverse all of the sub-projects
	// Set a flag for adding a separator after the first link
	boolean first = true;
	// Iterate over all sub-projects of the master project
	for (AlbumObject ao : masterProjectObject.getChildren()) {
		// Get the category of the object ao
		Category cat = ao.getCategory();
		// Get the variables for the object ao
		Scope vars = ao.getVars();
		// Only add links for web pages and folders, and only if not hidden nor excluded
		// Note 'excludeSiblingLink' variable can be used as a user variable to exclude specific items from the generated links
		if ((cat == Category.webPage || cat == Category.folder) && !ao.isHidden() && ao.isIncluded() && vars.get("excludeSiblingLink").toString().toLowerCase().equals("false")) {
			// If this is not the first link then add a separator between links
			if (!first) {
				out.print(" | ");
			}
			// the first link has been made so set first to false
			first = false;
			// Get the Title for the object ao
			String name = vars.get("title");
			// If object ao is the current sub-projects root folder don't make it a link, otherwise make a link
			if (ao.getName().equals(rootFolder.getName()))
				out.print("<b>" + name + "</b>");
			else
				// The link needs to be one level up from a 'normal' project link, so add '../'
				out.print("<a href=\"../" + vars.get("closeupPath") + "\">" + name + "</a>");
			
			// This next block makes links within the sub-project, remove or add a GUI control to toggle on/off
			// by adding another && test below
			// Already limited to folder or web pages so only need to limit folders
			if(cat == Category.folder) {
				// Iterate over the sub-projects folders
				for (AlbumObject aoC : ao.getChildren()) {
					// Only include links to sub folders as the root index is already included above
					if (aoC.isIncluded() && !aoC.isHidden() && !aoC.getName().equals("index.htt")) {
						// Get the category of the sub-object aoC
						Category catC = aoC.getCategory();
						// Get the variable for object aoC 
						Scope varsC = aoC.getVars();
						// already made the first link so just add a separator
						out.print(" | ");
						// Get the Title of object aoC
						String name = varsC.get("title");
						// The link needs to be relative to the sub-project so add 						// The link needs to be relative to the sub-project so add '/../ao.getName()/'
						out.print("<a href=\""+ theRootPath + "/../" + ao.getName() + "/" + varsC.get("closeupPath") + "\">" + name + "</a>");
					}
				}
			}
		}
	}
}

Then when you want to use it just call
projectNavigationMenu();
in the sub-projects.
davidekholm

Posts: 21,773
Registered: 18-Oct-2002
Re: How to get a project's parent folder
Posted: 23-Dec-2015 20:08   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Thanks for the contribution.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums