Page 1 of 1

How can we get possible parent element

Posted: Fri Dec 02, 2022 5:21 pm
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 857 times
Can you please tell if there is any method which will help me here?

Thanks,
Smita

Re: How can we get possible parent element

Posted: Mon Dec 05, 2022 9:11 am
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

Re: How can we get possible parent element

Posted: Mon Dec 05, 2022 3:25 pm
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 786 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

Re: How can we get possible parent element

Posted: Mon Dec 05, 2022 3:37 pm
by Radu
Hi Smita,

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

Regards,
Radu

Re: How can we get possible parent element

Posted: Tue Dec 06, 2022 6:30 am
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 771 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

Re: How can we get possible parent element

Posted: Tue Dec 06, 2022 3:13 pm
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

Re: How can we get possible parent element

Posted: Wed Dec 07, 2022 6:55 pm
by SmitaPatil
Hi Radu,

Thank you. It resolved.

Thanks,
Smita