private void createDefaultTreeView(Program program, String defaultTreeName) {
			String treeName = defaultTreeName;
			int oneUp = 1;
			Listing listing = program.getListing();
			while (listing.getRootModule(treeName) != null) {
				treeName = defaultTreeName + "_" + oneUp;
				oneUp++;
			}
			CreateDefaultTreeCmd cmd = new CreateDefaultTreeCmd(defaultTreeName);
			cmd.applyTo(program);
		}
Background command that will create the new tree and organize it.
Ghidra/Extensions/sample/src/main/java/ghidra/examples/SampleProgramTreePlugin.java