@Override
		public boolean applyTo(Program program, TaskMonitor monitor) {

			Listing listing = program.getListing();

			createDefaultTreeView(program, programTreeName);

			Memory mem = program.getMemory();

			ProgramModule root_module = listing.getRootModule(programTreeName);

			AddressSet set = new AddressSet(mem);

			try {
				root_module.createModule("Fragments");
			}
			catch (DuplicateNameException e) {
				// don't care???
			}
			ProgramModule frags = listing.getModule(programTreeName, "Fragments");

			long startCount = set.getNumAddresses();
			monitor.initialize(startCount);
			while (!monitor.isCancelled() && !set.isEmpty()) {
				MemoryBlock block = mem.getBlock(set.getMinAddress());
				Address start = block.getStart();
				Address end = block.getEnd();

				set.deleteRange(block.getStart(), block.getEnd());

				long numLeft = set.getNumAddresses();
				monitor.setProgress(startCount - numLeft);

				String mod_name = block.getName();

				monitor.setMessage("Module " + start + " : " + mod_name);

				ProgramModule mod = make_module(listing, mod_name, frags);
				makeFragment(listing, start, end, "frag_" + fragment_count, mod);
				fragment_count++;
			}

			return true;
		}
Background command that will create the new tree and organize it.
Ghidra/Extensions/sample/src/main/java/ghidra/examples/SampleProgramTreePlugin.java