Using oxy_add to assign an attribute value

<oXygen/> general issues.
Posts: 32

Using oxy_add to assign an attribute value

Fri Jul 28, 2017 6:21 pm


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?


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"
Posts: 650

Re: Using oxy_add to assign an attribute value

Mon Jul 31, 2017 5:32 pm


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() {
      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() {
               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,

Return to “Other Issues”

Who is online

Users browsing this forum: No registered users and 4 guests