Copy and paint attrubutes from one node to another of same node

Having trouble installing Oxygen? Got a bug to report? Post it all here.
shilpa
Posts: 68
Joined: Mon Jul 04, 2022 8:42 am

Copy and paint attrubutes from one node to another of same node

Post by shilpa »

Hi Team,
I would like to know how to copy and paint attributes from one node to another node of same type.
Ex : <head align="center" seq-id="1234">Test1</head>
<head>Test2</head>
In the above example i want to copy first head attributes and paint to second head node how to achieve this?
after painting second head node should be like below
<head align="center" seq-id="1234">Test2</head>

Thanks & Regards
Shilpa.P
Bogdan Dumitru
Site Admin
Posts: 172
Joined: Tue Mar 20, 2018 5:28 pm

Re: Copy and paint attrubutes from one node to another of same node

Post by Bogdan Dumitru »

Hello Shilpa,

Just to be sure, do you want to copy attributes from one element and then paste (the term "paint" you used, might add a little confusion) them into another element?

If yes, you could define an AuthorOperation [0] that stores all the necessary information (all attribute names and values) into the EditingSessionContext[1] (authorDocumentModel.getAuthorAccess().getEditorAccess().getEditingContext()), then define another operation to paste the before-stored context into the new element. The latter shall use the AuthorDocumentController[2] to add the attributes.

Take into account that the solution assumes that you want to paste into the same document, not into another.

Please don't hesitate to ask if you have any questions regarding the proposed solution.

[0] https://www.oxygenxml.com/InstData/Edit ... ation.html
[1] https://www.oxygenxml.com/InstData/Edit ... ntext.html
[2] https://www.oxygenxml.com/InstData/Edit ... orElement-
Bogdan Dumitru
http://www.oxygenxml.com
shilpa
Posts: 68
Joined: Mon Jul 04, 2022 8:42 am

Re: Copy and paint attrubutes from one node to another of same node

Post by shilpa »

Thanks Dumitru for the suggestion.

Yes the word Piant is nothing but Paste. In the above post your suggestion was giving all the attributes from the editor.
But i need the attributes from particular element where i have put my cursor.
Below is the Example Consider there are two head elements.
1. <head seq-no="1123" align="left">Test1</head>
2. <head>Test2</head>
say in the 1st head element i put my cursor and click on copy icon it should copy the attributes of head element (seq-no and align) and again i will put my cursor on the second head element now all the attributes from 1st head should paste to the 2nd head element.
Now after paste second head becomes
<head seq-no="1123" align="left">Test2</head>

Thanks & Regards
Shilpa.P
Last edited by shilpa on Tue Oct 25, 2022 12:55 pm, edited 3 times in total.
Bogdan Dumitru
Site Admin
Posts: 172
Joined: Tue Mar 20, 2018 5:28 pm

Re: Copy and paint attrubutes from one node to another of same node

Post by Bogdan Dumitru »

Hi Shilpa,

In that case, in addition to the previous answer you simply have to use the AuthorSelectionAndCaretModel [0] that can give you the selection (or caret) offset, then you can ask the AuthorDocumentController [1] about the node at that offset (see AuthorDocumentController.getNodeAtOffset()).
The AuthorSelectionAndCaretModel can be accessed via AuthorDocumentModel.getSelectionModel() [2] method.

[0] https://www.oxygenxml.com/InstData/Edit ... Model.html
[1] https://www.oxygenxml.com/InstData/Edit ... ffset-int-
[2] https://www.oxygenxml.com/InstData/Edit ... ionModel--
Bogdan Dumitru
http://www.oxygenxml.com
shilpa
Posts: 68
Joined: Mon Jul 04, 2022 8:42 am

Re: Copy and paint attrubutes from one node to another of same node

Post by shilpa »

Hi Dumitru,
I am using below function to set multiple attributes but attributes are setting to wrong element(parent element) instead of the given elements.
setMultipleAttributes(int parentElementStartOffset, int[] elementOffsets, java.util.Map<java.lang.String,AttrValue> attributes).
I would like to know more about the parameters to pass to the function.

<title.segment>
<cite.query ID="I74a8683008d911e9bf1dae20e5e56f87" w-normalized-cite="Test" w-ref-type="OM" w-seq-number="00003">Test
</cite.query>
<cite.query>Test2
</cite.query>
</title.segment>

In the above screenshot first i am getting all the attributes from the first cite.query and then i am pasting to second cite.query by using setMultipleAttributes(para1, para2, para3) method.
para1 = 1st cite.query startoffset
para2 = 2nd citequery startoffset
para3 = Map<attributeName, AttrValue>

but here the values are setting to title.segment instead of 2nd cite.query

<title.segment w-seq-number="00003" w-normalized-cite="Test" ID="I74a8683008d911e9bf1dae20e5e56f87" w-ref-type="OM">
<cite.query ID="I74a8683008d911e9bf1dae20e5e56f87" w-normalized-cite="Test" w-ref-type="OM" w-seq-number="00003">Test
</cite.query>
<cite.query>Test2
</cite.query>.
</title.segment>

Please let me know where i am doing wrong!!

Thanks
Shilpa
You do not have the required permissions to view the files attached to this post.
Bogdan Dumitru
Site Admin
Posts: 172
Joined: Tue Mar 20, 2018 5:28 pm

Re: Copy and paint attrubutes from one node to another of same node

Post by Bogdan Dumitru »

Hello Shilpa,

Here [0] you can find the JavaDoc for the AuthorDocumentController.setMultipleAttributes() method.
From "para1 = 1st cite.query startoffset" I guess that you wrongly set the first parameter. The code should look like this:

Code: Select all

    
ctrl.setMultipleAttributes(
    targetElement.getParentElement().getStartOffset(),
    new int[] {targetElement.getStartOffset()},
    attrs);
Also note that if the "setMultipleAttributes()" method is hard to be used for your use-case, you can use "setAttribute()" instead.

[0] https://www.oxygenxml.com/InstData/Edit ... .util.Map-

Bogdan.
Bogdan Dumitru
http://www.oxygenxml.com
Post Reply