How can we get possible parent element

Having trouble installing Oxygen? Got a bug to report? Post it all here.
SmitaPatil
Posts: 93
Joined: Mon Aug 08, 2022 2:32 pm

How can we get possible parent element

Post by SmitaPatil »

Hi Team.
can you please tell if node is fully selected then How can we get list of valid possible parent element using which we can wrap selected node.
as shown in below screenshot.
For example in this screenshot, venue.name has selected so we want to display the list of element which can insert as parent of selected element and children of content.venue element.
image.png
image.png (25.52 KiB) Viewed 827 times
Can you please tell if there is any method which will help me here?

Thanks,
Smita
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: How can we get possible parent element

Post by Radu »

Hi Smita,

We do not have a specific API method for this.
Why don't you use our contextual menu "Surround with..." functionality?
We also have API to ask the associated schema what elements can be inserted at a certain offset:

Code: Select all

      AuthorNode selected = authorAccess.getEditorAccess().getFullySelectedNode();
      if(selected instanceof AuthorElement) {
        AuthorElement elem = (AuthorElement) selected;
        AuthorSchemaManager schemaManager = authorAccess.getDocumentController().getAuthorSchemaManager();
        WhatElementsCanGoHereContext context = schemaManager.createWhatElementsCanGoHereContext(elem.getStartOffset());
        List<CIElement> possibleElementsBeforeSelectedElement = schemaManager.getChildrenElements(context);
        CIElement chosen = ...;
        AuthorDocumentFragment fragForCIElement = schemaManager.createAuthorDocumentFragment(chosen);
        authorAccess.getDocumentController().surroundInFragment(fragForCIElement, elem.getStartOffset(), elem.getEndOffset());
      }
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
SmitaPatil
Posts: 93
Joined: Mon Aug 08, 2022 2:32 pm

Re: How can we get possible parent element

Post by SmitaPatil »

Hi Radu,

I think there is some confusion in requirement.
I will explain again the requirement is if user select venue.name node then we have to display the list of parent elements using which we can wrap it. Currently I am getting below list of elements. I am getting it using getchildren method. but the issue here is it also contain some elements which is not valid for wrapping venue.name.
image.png
image.png (68.79 KiB) Viewed 756 times
So I thought if somehow I could able to get list of possible parent elements for selected element. that will help me here.
In short, I have to give list of elements which is valid to use as parent of selected element before wrapping it and checking for validation.
If I go this way by getting ChildrenElements list and then creating fragment and checking for each element whether its valid to wrap it or not. In case of large list of childrenElement list it may take longer time. That's why I thought to check if there is any method present.
Please let me know if you need any more information



Thanks,
Smita
Last edited by SmitaPatil on Mon Dec 05, 2022 3:41 pm, edited 2 times in total.
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: How can we get possible parent element

Post by Radu »

Hi Smita,

Unfortunately we do not have a specific API method for what you want.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
SmitaPatil
Posts: 93
Joined: Mon Aug 08, 2022 2:32 pm

Re: How can we get possible parent element

Post by SmitaPatil »

Hi Radu,
oh okay.
I have seen if I select element and click on enter I am getting valid list of element using which I can wrap selected element as shown in below screenshot. selected element is venue.name
image.png
image.png (18.6 KiB) Viewed 741 times
To achieve this which other are getting used if you can tell me it will be helpful for me.
and one more question, can we create a context for completed selected node or if I can given and start and end offset somehow?

Thanks,
Smita
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: How can we get possible parent element

Post by Radu »

Hi Smita,

Maybe you can implement a custom AuthorOperationWithResult and add it to the framework on the server side then invoke it from the Javascript code on the client side:
https://www.oxygenxml.com/maven/com/oxy ... esult.html

The method "AuthorOperationWithResult.doOperation(AuthorDocumentModel, ArgumentsMap)" receives an "AuthorDocumentModel" which could use this API to ask our code what proposed choices are to surround the current selected content:

Code: Select all

List<CCItemProxy> proposedElementsForSurround = model.getContentCompletionManager().getProposedElementsForSurround(model.getSelectionModel());
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
SmitaPatil
Posts: 93
Joined: Mon Aug 08, 2022 2:32 pm

Re: How can we get possible parent element

Post by SmitaPatil »

Hi Radu,

Thank you. It resolved.

Thanks,
Smita
Post Reply