Setting the review author name by API

Oxygen general issues.
Vince
Posts: 64
Joined: Wed Dec 03, 2014 11:25 am

Setting the review author name by API

Post by Vince »

Hello,
Is-it possible to set the author name by API ?
I'm talking about the option in Oxygen Preferences / Editor / Edit Modes / Author / Review

And can we lazy expand this information at use by review panel and tooltips ?
Suppose that I set a user id and I want to show a user display name

Thanks
Vince
Posts: 64
Joined: Wed Dec 03, 2014 11:25 am

Re: Setting the review author name by API

Post by Vince »

I just find a response to my first question with :

Code: Select all

PluginWorkspaceProvider.getPluginWorkspace().setGlobalObjectProperty(APIAccessibleOptionTags.CHANGE_TRACKING_AUTHOR, "00001");
For the second point, I try without success :

Code: Select all

PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().addCustomEditorVariablesResolver(new EditorVariablesResolver() {
                @Override
                public String resolveEditorVariables(String contentWithEditorVariables, String currentEditedFileURL) {
                    if (contentWithEditorVariables.equals("${author.name}")) return "my display name";
                    return super.resolveEditorVariables(contentWithEditorVariables, currentEditedFileURL);
                }
 });
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: Setting the review author name by API

Post by Radu »

Hi,

So:
Is-it possible to set the author name by API ?
I'm talking about the option in Oxygen Preferences / Editor / Edit Modes / Author / Review
We also have API available at opened XML file level:

Code: Select all

authorAccess.getReviewController().setReviewerAuthorName(authorName);
https://www.oxygenxml.com/InstData/Edit ... oller.html
And can we lazy expand this information at use by review panel and tooltips ?
Suppose that I set a user id and I want to show a user display name
I'm afraid we do not have a particular API for mapping the author name to a certain author display name, the author name is usually saved in the XML document and displayed as it is.
We have for example API to customize the tooltip shown when hovering a highlight:
ro.sync.ecss.extensions.api.AuthorReviewController.setReviewRenderer(PersistentHighlightRenderer)
or API to customize how things are displayed in the Review view:
ro.sync.ecss.extensions.api.review.ReviewsRenderingInformationProvider
and the same thing when presenting callout bubbles on the right side of the editing area:
ro.sync.ecss.extensions.api.callouts.CalloutsRenderingInformationProvider

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Vince
Posts: 64
Joined: Wed Dec 03, 2014 11:25 am

Re: Setting the review author name by API

Post by Vince »

Hi Radu,

Thanks a lot for your answer.

With given entry points to customize, I can modify user to display what I want in tooltip and review panel.

I'm encountering a problem registering a custom CalloutsRenderingInformationProvider in AuthorExtensionStateListener. It 's never used.

Can you give me more help for this point ?


Code: Select all

 AuthorReviewController reviewController = authorAccess.getReviewController();
        reviewController.getAuthorCalloutsController().setCalloutsRenderingInformationProvider(new CalloutsRenderingInformationProvider() {
            @Override
            public AuthorCalloutRenderingInformation getCalloutRenderingInformation(AuthorPersistentHighlight highlight) {
                return new AuthorCalloutRenderingInformation() {
                    @Override
                    public String getAuthor() {
                        return "author display name";
                    }

                };
            }

            @Override
            public boolean shouldRenderAsCallout(AuthorPersistentHighlight highlight) {
                return true;
            }
        });
Regards,
Vince
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: Setting the review author name by API

Post by Radu »

Hi Vince,

I have not worked with the API for quite some time, so focusing on the callouts customization (those side bubbles), here's the code I wrote to test this in a plugin on my side:

Code: Select all

    @Override
    public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
      pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {
        @Override
        public void editorOpened(URL editorLocation) {
          WSEditor editor = pluginWorkspaceAccess.getEditorAccess(editorLocation, StandalonePluginWorkspace.MAIN_EDITING_AREA);
          WSEditorPage cp = editor.getCurrentPage();
          if(cp instanceof WSAuthorEditorPage) {
            WSAuthorEditorPage authorPage = (WSAuthorEditorPage) cp;
            AuthorReviewController reviewController = authorPage.getAuthorAccess().getReviewController();
            reviewController.getAuthorCalloutsController().setCalloutsRenderingInformationProvider(new CalloutsRenderingInformationProvider() {
                @Override
                public AuthorCalloutRenderingInformation getCalloutRenderingInformation(AuthorPersistentHighlight highlight) {
                    return new AuthorCalloutRenderingInformation() {
                        @Override
                        public String getAuthor() {
                            return "author display name";
                        }

                        @Override
                        public long getTimestamp() {
                          return 0;
                        }

                        @Override
                        public String getComment(int limit) {
                          return "Comment";
                        }

                        @Override
                        public String getContentFromTarget(int limit) {
                          return "CONTENT";
                        }

                        @Override
                        public Map<String, String> getAdditionalData() {
                          return null;
                        }

                        @Override
                        public String getCalloutType() {
                          return "CT";
                        }

                        @Override
                        public ro.sync.exml.view.graphics.Color getColor() {
                          return ro.sync.exml.view.graphics.Color.COLOR_RED;
                        }
                    };
                }

                @Override
                public boolean shouldRenderAsCallout(AuthorPersistentHighlight highlight) {
                    return true;
                }
                /**
                * @see ro.sync.ecss.extensions.api.callouts.CalloutsRenderingInformationProvider#handlesAlsoDefaultHighlights()
                */
                @Override
                public boolean handlesAlsoDefaultHighlights() {
                  return true;
                }
            });
          }
        };
      }, StandalonePluginWorkspace.MAIN_EDITING_AREA);
    }
Notice that "handlesAlsoDefaultHighlights" override I added to tell the API that I want to take control of everything (insertions/deletions/comments).
A highlight has a set of properties "ro.sync.ecss.extensions.api.highlights.AuthorPersistentHighlight.getClonedProperties()" and most of those callback methods can be answered by looking at the value for such a property.

Unfortunately the API does not allow you to just override the author name display computation. So you will need to re-implement all other methods, similar to how we implement them in our code, for example this method which returns the callout type uses some of our translated strings depending on the higlight type:

Code: Select all

  /**
     * @see ro.sync.ecss.extensions.api.callouts.AuthorCalloutRenderingInformation#getCalloutType()
     */
    @Override
    public String getCalloutType() {
      String typeStr = null;

      PersistentHighlightType type = marker.getType();
      switch (type) {
        //Attribute changes.
        case CHANGE_ATTRIBUTE_INSERTED:
          typeStr =  "@ " + messages.getString(Tags.INSERTED);
          break;
        case CHANGE_ATTRIBUTE_DELETED:
          typeStr = "@ " + messages.getString(Tags.DELETED);
          break;
        case CHANGE_ATTRIBUTE_MODIFIED:
          typeStr = "@ " + messages.getString(Tags.MODIFIED);
          break;
        case CHANGE_INSERT:
          if(ChangeMarker.TYPE_SPLIT.equals(marker.getChangeSubType())) {
            typeStr = messages.getString(Tags.SPLIT); 
          } else if(ChangeMarker.TYPE_SURROUND.equals(marker.getChangeSubType())) {
            typeStr = messages.getString(Tags.SURROUNDED); 
          } else {
            typeStr = messages.getString(Tags.INSERTED);
          }
          break;
        case CHANGE_DELETE:
          typeStr = messages.getString(Tags.DELETED);
          break;
        case COMMENT:
          typeStr = messages.getString(Tags.COMMENTED);
          break;
      }

      return typeStr;
    }
The "getColor()" method, I'm not sure how it could be implemented on your side so that it can be similar with ours though, it should be the same color as the highlight in the editor.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply