@Override
	public void accept() {
		Program program = getProgram();
		Address address = getAddress();
		Data data = getData();
		DataType dt = data.getBaseDataType();
		/**
		 * Do as much outside the transaction as possible. The tool tends to steal focus away upon
		 * restoring the database, and that causes the input fields to disappear.
		 */
		byte[] encoded;
		AddressRange rng;
		try {
			encoded = dt.encodeRepresentation(input.getText(), data, data, data.getLength());
			rng = new AddressRangeImpl(address, encoded.length);
		}
		catch (DataTypeEncodeException | AddressOverflowException e) {
			tool.setStatusInfo(e.getMessage(), true);
			return;
		}
		try (Transaction tx =
			program.openTransaction("Patch Data @" + address + ": " + input.getText())) {
			applyPatch(rng, encoded);
			hide();
		}
		catch (MemoryAccessException e) {
			Msg.showError(this, null, "Patch Failure", e.getMessage(), e);
		}
		catch (CodeUnitInsertionException e) {
			throw new AssertionError(); // Should have been cleared first
		}
	}
A context menu action to patch data at the current address
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/assembler/PatchDataAction.java