private ExternalLocation addExternalLocation(ExternalLocation extLocation, String libraryName,
			String libraryProgramPathname, String label, Address addr, boolean shouldBeFunction)
			throws InvalidInputException, DuplicateNameException {
		int txId = program.startTransaction("Create External Location");
		boolean success = false;
		try {
			ExternalManager externalManager = program.getExternalManager();
			getOrCreateExternalLibrary(libraryName, libraryProgramPathname);

			// Create the location.
			extLocation =
				externalManager.addExtLocation(libraryName, label, addr, SourceType.USER_DEFINED);
			if (shouldBeFunction && !extLocation.isFunction()) {
				extLocation.createFunction();
			}
			success = true;
			return extLocation;
		}
		finally {
			program.endTransaction(txId, success);
		}
	}
Pop up the data tree dialog so the user can choose the external program.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/EditExternalLocationPanel.java