Resolve editor variables in string parameter default values of refactoring operations

Are you missing a feature? Request its implementation here.
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Resolve editor variables in string parameter default values of refactoring operations

Post by chrispitude »

In an XSLT refactoring operation, I would like the default value of a string parameter to default to the current user ID by using an Oxygen editor variable:

Code: Select all

<parameter type="TEXT" name="my-string-user" label="my-string-user">
    <description>my-string-user, defaults to ${author.name}</description>
    <possibleValues>
        <value name="string-default" default="true">${author.name}</value>
    </possibleValues>
</parameter>
However, currently editor variables are not resolved:

image.png
image.png (2.68 KiB) Viewed 722 times

It would be great if this were supported. (It would be nice if they also resolved in the descriptions, but this is not necessary as the default value will make itself obvious.)

A testcase is included:

oxygen_refactoring_string_default_vars.zip
(2.4 KiB) Downloaded 97 times
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Resolve editor variables in string parameter default values of refactoring operations

Post by Radu »

Hi Chris,

I added your comment on an already opened internal issue:
EXM-33203 XML Refactoring operations should be able to use and expand editor variables

So ideally we should expand editor variables in parameter values before they are passed to the XML refactoring stylesheets.
But you do have an uglier workaround, call a static Java method we provide directly in the XSLT code to expand editor variables:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  version="3.0"
	xmlns:edVars="java:ro.sync.util.editorvars.EditorVariables">

	<xsl:template match="node() | @*">
		<xsl:message><xsl:value-of select="edVars:expandEditorVariables('${author.name}', '')"/></xsl:message>
		<xsl:copy>
			<xsl:apply-templates select="node() | @*"/>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>
So if for example the end user leaves the author name parameter empty, you could expand in the XSLT stylesheet the ${author.name} editor variable and use that instead.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: Resolve editor variables in string parameter default values of refactoring operations

Post by chrispitude »

Thanks Radu!

In my testcase, TEXT parameters do not accept empty values; the Next and Finish buttons are disabled until text is present in every TEXT field.

Some TEXT parameters might require values while others are optional and can be blank. Is there a way to specify this in the descriptor file?
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Resolve editor variables in string parameter default values of refactoring operations

Post by Radu »

Hi Chris,

I think specifying optional=true on it should work:

Code: Select all

<parameter type="TEXT" name="my-string-user" label="my-string-user" optional="true">
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply