Using oxy_add to assign an attribute value

Oxygen general issues.
john_m
Posts: 32
Joined: Mon Apr 10, 2017 8:56 pm

Using oxy_add to assign an attribute value

Post by john_m »

Hello,

I am using the oxy_add function within the Oxygen Web Author environment to perform calculations on various attribute values.

For example, in my estimatedModCost element, I have attributes that hold values for the number of hours it takes to repair a unit. An estimatedModCost element might look like this:

Code: Select all

<estimatedModCost laborPerUnitPreperation="1.0" laborPerUnitInstallation="2.0" laborPerUnitTesting="0.5">
The css is below, but I use oxy_add to display the total number of hours required.

My question is, if I add an attribute "totalTimeForMod", is it possible to set that value using oxy_add? That is, can I have oxy_add calculate what that value should be and then modify the attribute value somehow?

Thanks!
John

Code: Select all

    /* Labor hours*/
oxy_label(text, "Estimated Labor Hours", styles, "text-decoration:underline;")"\A"
oxy_label(text, "Estimated labor hours per unit for: ", width, 100%)
oxy_label(text, "Preparation: ", width, 12%)
oxy_textfield(edit, "@laborPerUnitPreparation", width, 5%)
oxy_label(text, " ", width, 2%)
oxy_label(text, "Installation: ", width, 12%)
oxy_textfield(edit, "@laborPerUnitInstallation", width, 5%)
oxy_label(text, " ", width, 2%)
oxy_label(text, "Test: ", width, 12%)
oxy_textfield(edit, "@laborPerUnitTest", width, 5%)"\A"
oxy_label(text, "Total labor hours per unit: ", width, 30%)
oxy_add(attr(laborPerUnitPreparation), attr(laborPerUnitInstallation), attr(laborPerUnitTest), 'number')"\A\A"
alex_jitianu
Posts: 1009
Joined: Wed Nov 16, 2005 11:11 am

Re: Using oxy_add to assign an attribute value

Post by alex_jitianu »

Hello,

The recommended way to this this would be to use our Java-based API and implement an AuthorDocumentFilter. Such a filter will be notified whenever an attribute changes and on this event you can update the @totalTimeForMod (if one of the smaller attributes was the one that changed). I recommend implementing an WorkspaceAccess plugin. A sample WorkspaceAccess implementation is found inside our Maven-based SDK sample project (the submodule is named oxygen-sample-plugin-workspace-access).

From such a plugin you can set a filter on all opened documents like this:

Code: Select all


  public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {

pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {
@Override
public void editorOpened(URL editorLocation) {
WSEditor editorAccess = pluginWorkspaceAccess.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA);

WSEditorPage currentPage = editorAccess.getCurrentPage();
if (currentPage instanceof WSAuthorEditorPage) {
WSAuthorEditorPage authorPage = (WSAuthorEditorPage) currentPage;

authorPage.getDocumentController().setDocumentFilter(new AuthorDocumentFilter() {
@Override
public void setAttribute(AuthorDocumentFilterBypass filterBypass, String attributeName,
AttrValue value, AuthorElement element) {
super.setAttribute(filterBypass, attributeName, value, element);

// TODO Check what attribute was changed and recompute @totalTimeForMod
filterBypass.setAttribute("totalTimeForMod ", new AttrValue(total), element);
}
});
}
}
}, PluginWorkspace.MAIN_EDITING_AREA);
There are also a couple of alternatives but all of them involve, to a degree, some user interaction. For example:
- a Schematron check will catch the situations when the attribute values are not synchronized and a Schematron Quick Fix can update the total.
- the user has to click an form control button that will update the total value.

Please let me know which solution would you like to try and perhaps I can give you additional advice.

Best regards,
Alex
Post Reply