<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi Adam,<br>
    <br>
    As far as I can say, I see no reason why JTextArea#replaceRange
    wouldn't work. Have you added some log to make sure it really gets
    executed, with the correct values? JTextArea#replaceRange
    implementation uses the javax.swing.text.Document API to do the
    actual work but I don't think you'll see any differences if you use
    the document API instead.<br>
    <br>
    It might be a problem with the offsets given to the method. At a
    first glance I would say that the interval to replace should be (to
    cover the case when start > 0):<br>
    <br>
        jTextArea.replaceRange(suggestion, <b>start + </b>lastIndex, <b>start
      + </b>lastIndex + ADD_NEW.length());<br>
    <br>
    <br>
    Perhaps you can also resolve the use case without a timer.
    CIValue#getInsertString() gets called after the user chooses a value
    in the content completion window, at the moment when we have to
    decide what to insert in the document. I suggest overriding this
    method and getting the value from the user then. I've tested it in
    Oxygen v17.1 and it worked well.<br>
    <br>
      <font color="#6666cc">public List<CIValue>
      filterAttributeValues(List<CIValue> attributeValues,<br>
            WhatPossibleValuesHasAttributeContext context) {<br>
          // If the element from the current context is the "image"
      element and the current context <br>
          // attribute is "href" then add a custom URL value to the list
      of default content completion <br>
          // proposals.<br>
          if (context != null) {<br>
            ContextElement currentElement = context.getParentElement();<br>
            String attributeName = context.getAttributeName();<br>
            if("image".equals(currentElement.getQName()) &&
      "href".equals(attributeName)) {<br>
              CIValue newValue = new CIValue("Add new...") {<br>
                String insertValue = null;<br>
                @Override<br>
                public String getInsertString() {<br>
                  if (insertValue == null) {<br>
                     // This call might come multiple times. Make sure
      we present the dialog only once.<br>
                    insertValue = getValue();<br>
                    <br>
                    String valueFromUser =
      JOptionPane.showInputDialog("Give me a value: ", "");<br>
                    if (valueFromUser != null) {<br>
                      insertValue = valueFromUser;<br>
                    }<br>
                    <br>
                  }<br>
                  return insertValue;<br>
                }<br>
              };<br>
              if (attributeValues == null) {<br>
                attributeValues = new ArrayList<CIValue>();<br>
              }<br>
              // Add the new value.<br>
              attributeValues.add(newValue);<br>
            }<br>
          }<br>
          return attributeValues;<br>
        }</font><br>
    <pre class="moz-signature" cols="72">Best regards,
Alex
-- 
Alex Jitianu
<oXygen/>  XML Editor, Schema Editor and XSLT Editor/Debugger
<a class="moz-txt-link-freetext" href="http://www.oxygenxml.com">http://www.oxygenxml.com</a> </pre>
    <div class="moz-cite-prefix">On 4/8/2016 7:32 AM, Adam Retter wrote:<br>
    </div>
    <blockquote
cite="mid:CAPK0ichOKsXmWGbKJwZqQ4t5W4tOwSbYCFiHMA2mQhf0goR7fg@mail.gmail.com"
      type="cite">
      <pre wrap="">We have created a plugin for Oxygen that provides suggestions for the
values of various attributes.

However we want the ability to add a new value to our list of
suggestions from within the UI. I have been able to do this, by making
one of the suggested attribute values in the CIValue list "Add New..."
and then displaying a dialog box to the user when they select this
(i.e. detecting when it is written into the attribute value in the
document).

However, I then want to replace the attribute value (currently "Add
New...") with the actual value they entered into the document, I
believe that I am doing this correctly by calling
JTextArea#replaceRange, however after that call the attribute value in
the Oxygen editor window does not seem to change.

Here is the code where I call `replaceRange`:
<a class="moz-txt-link-freetext" href="https://github.com/adamretter/TEI-Authorizer/blob/master/src/main/java/org/humanistika/oxygen/tei/authorizer/TeiAuthorizer.java#L150">https://github.com/adamretter/TEI-Authorizer/blob/master/src/main/java/org/humanistika/oxygen/tei/authorizer/TeiAuthorizer.java#L150</a>

Any ideas why replaceRange doesn't work, or if there is a different
API I should be using to do this?

Cheers Adam.

</pre>
    </blockquote>
    <br>
  </body>
</html>