private ProgramFragment makeFragment(Listing listing, Address start, Address end,
				String fragmentName, ProgramModule parent) {

			try {
				parent.createFragment(fragmentName);
			}
			catch (DuplicateNameException e) {
				// ignore
			}
			ProgramFragment frag = listing.getFragment(programTreeName, fragmentName);

			try {
				frag.move(start, end);
			}
			catch (NotFoundException e) {
				Msg.error(this,
					"couln't find addresses for fragment " + fragmentName + " : " + start, e);
			}
			return frag;
		}
Background command that will create the new tree and organize it.
Ghidra/Extensions/sample/src/main/java/ghidra/examples/SampleProgramTreePlugin.java