... |
... |
@@ -1,162 +1,89 @@ |
1 |
1 |
{{content/}} |
2 |
2 |
|
3 |
|
-The bundle properties offer the plug-in developer the possibility to configure plug-ins externally and thus control the runtime behaviour of the developed plug-ins. |
|
3 |
+Bundle properties are settings a plugin user change change in order to influence or modify the behavior of plugins. |
4 |
4 |
|
5 |
|
-The bundle properties can be used, for example, to make addresses and access information of web service endpoints configurable. |
|
5 |
+As an example, they can be used to allow the user tho change the address to a web services as well as the necessary login data. |
6 |
6 |
|
7 |
|
-They are suitable for externally influencing certain plugin types, such as the //IPluginFormPreRender plugin //or the //IPluginServletAction plugin//, which themselves do not have their own configuration interface in {{formcycle case="dat"/}}. |
|
7 |
+There is a separate user interface for some plugins, eg. //IPluginProcessing//, for which settings can be set when selecting the plugin as an action type. For some plugin types such as {{jpath path="de.xima.fc.interfaces.plugin.retval.form.IPluginFormPreRender"/}} or {{jpath path="de.xima.fc.interfaces.plugin.param.servlet.IPluginServletAction"/}}, there is no special user interface available within {{formcycle/}}. Plugin bundle properties can also be used to pass data to these types of plugins. |
8 |
8 |
|
9 |
|
-== Definition of bundle properties by the plugin developer == |
|
9 |
+== Setting up bundle properties == |
10 |
10 |
|
11 |
|
-{{figure image="plugin_props_config_en.png" title="FORMCYCLE Bundle-Properties: Display in interface" width="500"}} |
12 |
|
-By including the //IBundleProperties// interface, configurable options can be displayed in the {{formcycle case="dat"/}} interface. |
13 |
|
-{{/figure}} |
|
11 |
+When configuring a plugin, {{formcycle/}} allows the user to add new key-value type properties with arbitrary keys. Unless otherwise required, you should define which keys exist yourself to prevent users from entering incorrect keys. This will always provide the user with an overview of which settings can be set without having to read the the docs, and make the plugin easier to use. |
14 |
14 |
|
15 |
|
-The interface of {{formcycle case="dat"/}} offers the possibility to store new properties with name and value at the respective plug-in bundle. |
16 |
|
-In most cases, however, it is useful if the name (access key, must be unique within the bundle properties) and, if necessary, a default value for a property are stored. |
17 |
|
-and, if applicable, a default value for a property, are already defined by the plug-in developer. |
18 |
|
-\\On the one hand, this eliminates typing errors when the access key is created by the plug-in user, and on the other hand |
19 |
|
-on the other hand, the plug-in user receives a view of all configuration values supported by the plug-in developer. |
|
13 |
+To add bundle properties to your plugin, create a new class that implements the interface {{jpath path="de.xima.fc.plugin.config.IBundleProperties"/}}. When uploading the plugin bundle, {{formcycle/}} will search for this class. |
20 |
20 |
|
21 |
|
- |
22 |
22 |
== Interface IBundleProperties == |
23 |
23 |
|
24 |
|
-The interface provides the following method signatures: |
|
17 |
+{{figure image="plugin_props_config_en.png"}} |
|
18 |
+By implementing the interface {{jpath path="de.xima.fc.plugin.config.IBundleProperties"/}}, all available options for the plugin will be visible when configuring the plugin in {{formcycle/}}. |
|
19 |
+{{/figure}} |
25 |
25 |
|
26 |
|
-{{panel title="{{code language='java'~}~}Map<String, IBundleConfigParam> getConfigProperties(IPluginResourceHelper resHelper, Locale currentLocale){{/code~}~}" triggerable="true" fullwidth="true"}} |
27 |
|
-((( |
28 |
|
-The //getConfigProperties// method is used to configure property values that should be available to all Java classes within the plugin bundle. |
29 |
|
-))) |
30 |
|
-**Transfer values:** |
31 |
|
-((( |
32 |
|
-* **IPluginResourceHelper.** |
33 |
|
-* **Objects to access the file resources contained in the plugin bundle.** |
34 |
|
-* **Locale** |
35 |
|
-* **The //Locale// object defined for the currently logged-in user (contains information on the language and region). |
36 |
|
-This can be used to determine language-dependent texts. |
37 |
|
-))) |
|
21 |
+The interface {{jpath path="de.xima.fc.plugin.config.IBundleProperties"/}} contains the method {{code language="none"}}getConfigProperties(){{/code}} that can be used to define the available options for the plugins. This method must return a {{code language="none"}}Map{{/code}} with values of type {{jpath path="de.xima.fc.plugin.config.IBundleConfigParam"/}}. |
38 |
38 |
|
39 |
|
-**Return values:** |
40 |
|
-((( |
41 |
|
-The method must return an object of type //java.util.Map// with Value objects of type //IBundleConfigParam//. |
42 |
|
-There are two possible implementations of //IBundleConfigParam//: |
43 |
|
-))) |
|
23 |
+{{formcycle/}} provides two implementing classes of the {{jpath path="de.xima.fc.plugin.config.IBundleConfigParam"/}} interface you can use: |
44 |
44 |
|
45 |
|
-* **BundleConfigGroupItem**. |
46 |
|
-**This item can be used to structure the list display in the {{formcycle case="dat"/}} interface. |
47 |
|
-* **BundleConfigParam**. |
48 |
|
-** Used to define a bundle property. An object defines the following properties: |
49 |
|
-**: //name// |
50 |
|
-**:: The name or access key of a property. |
51 |
|
-**: //description// |
52 |
|
-**Description of a property. Displayed by //mouseover// over the //Property// name in the interface. Can be used to show the user of the plug-in more detailed information on the use or possible value ranges of the parameter. |
53 |
|
-**: //mandatory// |
54 |
|
-**:: Determines whether the parameter is displayed as a mandatory parameter in the interface and whether a validation for the presence of a value is carried out when saving. |
55 |
|
-**: //crypticValue// |
56 |
|
-**:: Determines whether the value of the property is to be masked as with a password field. Default value is {{code language="none"}}false{/code}}. |
57 |
|
-**: //defaultValue// |
58 |
|
-**:: Allows the developer to set a default value. Default value is {{code language="none"}}null{/code}}. |
|
25 |
+* {{litem title="{{jpath path='de.xima.fc.plugin.models.config.BundleConfigGroupItem'/~}~}"}}Can be used to group several items in the list view of the plugin configuration interface.{{/litem}} |
|
26 |
+* {{litem title="{{jpath path='de.xima.fc.plugin.models.config.BundleConfigParam'/~}~}"}}Defines a plugin bundle property. The following parameters can be passed to the constructor:{{/litem}} |
|
27 |
+** {{litem title="name"}}The name used as the key for the property.{{/litem}} |
|
28 |
+** {{litem title="description"}}Description for the property. It will be shown when hovering the mouse over the name of the property. Can be used to provide further details on the paramters, or inform the user about allowed values.{{/litem}} |
|
29 |
+** {{litem title="isMandatory"}}Whether this property is required and a value must be set.{{/litem}} |
|
30 |
+** {{litem title="crypticValue"}}Whether the value of the property should be masked, similar to password fields. Defaults to {{code language="none"}}false{{/code}}.{{/litem}} |
|
31 |
+** {{litem title="defaultValue"}}A default value for the property when no value has been specified. Defaults to {{code language="none"}}null{{/code}}.{{/litem}} |
59 |
59 |
|
60 |
|
-{{/panel}} |
|
33 |
+{{panel title="Example for an implementation of IBundleProperties" initial="hidden" triggerable="true"}} |
61 |
61 |
|
62 |
|
-== Implementation example == |
63 |
|
- |
64 |
|
-The following code example shows a possible implementation: |
65 |
|
- |
66 |
|
-{{code language="java" title=""}} |
|
35 |
+{{code language="java"}} |
67 |
67 |
@SuppressWarnings("serial") |
68 |
|
-public class MyBundleProperties implements IBundleProperties { |
69 |
|
- |
70 |
|
- /** |
71 |
|
- * Returns a map with definitions of bundle configuration parameters. Key is the parameter name, value is a bundle |
72 |
|
- * parameter definition of type {@link IBundleConfigParam}. |
73 |
|
- * @param resHelper ResourceHelper to determine i18n values from the plugin bundle, if they exists. |
74 |
|
- * @param currentLocale the current locale |
75 |
|
- * @return {@link Map} with objects of type {@link IBundleConfigParam} or <code>null</code>. |
76 |
|
- */ |
77 |
|
- @Override |
78 |
|
- public Map<String, IBundleConfigParam> getConfigProperties(IPluginResourceHelper resHelper, Locale currentLocale) { |
|
37 |
+public class MyBundleProperties implements IBundleProperties, Serializable { |
|
38 |
+ @Override |
|
39 |
+ public Map<String, IBundleConfigParam> getConfigProperties() { |
79 |
79 |
Map<String, IBundleConfigParam> config = new LinkedHashMap<>(); |
80 |
|
- config.put("Group", new BundleConfigGroupItem("Supported parameters:")); |
81 |
|
- config.put("Parameter1", new BundleConfigParam("Parameter1", "Mandatory parameter in scope of plugin with default value", true, "Default value")); |
82 |
|
- config.put("Parameter2", new BundleConfigParam("Parameter2", "Mandatory parameter in the scope of the plug-in", true)); |
83 |
|
- config.put("Parameter3", new BundleConfigParam("Parameter3", "Parameter in scope of plug-in with default value", false, "Initial value")); |
84 |
|
- config.put("Parameter4", new BundleConfigParam("Parameter4", "Parameter in scope of plugin", false)); |
|
41 |
+ config.put("Group", new BundleConfigGroupItem("Unterstützte Parameter:")); |
|
42 |
+ config.put("Parameter1", new BundleConfigParam("Parameter1", "Required parameter with default value", true, "default value")); |
|
43 |
+ config.put("Parameter2", new BundleConfigParam("Parameter2", "Required parameter without default value", true)); |
|
44 |
+ config.put("Parameter3", new BundleConfigParam("Parameter3", "Parameter with default value, not required", false, "initial value")); |
|
45 |
+ config.put("Parameter4", new BundleConfigParam("Parameter4", "Parameter with default value, not required", false)); |
85 |
85 |
return config; |
86 |
86 |
} |
87 |
|
- |
88 |
88 |
} |
89 |
|
- |
90 |
90 |
{{/code}} |
|
50 |
+{{/panel}} |
91 |
91 |
|
92 |
|
-== Access to bundle properties within the plugin logic == |
|
52 |
+== Retrieving bundle properties == |
93 |
93 |
|
94 |
|
-Access to bundle properties within individual plugin implementations is provided via the //IFCPlugin// interface and its provided plugin lifecycle methods. |
95 |
|
-All [[Plugin Types>>doc:Formcycle.PluginDevelopment.Types.WebHome]] inherit from this interface, allowing access to bundle properties in all plugin implementations. |
|
54 |
+By extending the abstract class {{jpath path="de.xima.fc.plugin.abstracts.AFCPlugin"/}}, you can access the values that have been set for the bundle properties. The method {{code language="none"}}getProperties(){{/code}} return an object of type //java.util.Properties// that allows you to access the properties. |
96 |
96 |
|
97 |
|
-== Examples for reading bundle properties == |
|
56 |
+== Example for using bundle properties == |
98 |
98 |
|
99 |
|
-The following example shows how to access the bundle properties within a //IPluginFormPreRender// implementation. |
|
58 |
+An example taken from the //execute// method of a plugin of type [[IPluginFormPreRender>>doc:Formcycle.PluginDevelopment.Types.IPluginFormPreRender]]. |
100 |
100 |
|
101 |
|
-By default, a PreRender plugin is executed on all form calls in the scope of the client in which it was registered. |
102 |
|
-For example, if you want the //PreRenderer// to be executed only when certain forms are called, you can make this configurable using //Bundle-Properties//. |
103 |
|
-The following example reads in the {{code language="none"}}execute{{/code}} method reads the value of the //Bundle-Property// {{code language="none"}}activate.form.alias{/code}}, which contains the names of forms (separated by commas). |
104 |
|
-Then these names are compared with the name of the current form in whose scope the //PreRenderer// is currently running. |
105 |
|
-If the name of the current form does not match a name from the configured list, further processing of the PreRenderer is aborted. |
|
60 |
+Plugins of this type will be executed when opening a form belonging to the same client for which the plugin has been uploaded. To restrict the plugin to certain forms, you can add a bundle property {{code language="none"}}activate.form.alias{{/code}} that contains a list of comma separated names of forms the plugin should be run for. |
106 |
106 |
|
107 |
|
-{{code language="java" title=""}} |
108 |
|
-public class MyPreRenderer implements IPluginFormPreRender { |
|
62 |
+The plugin will exit when called for a form not part of that list. |
109 |
109 |
|
110 |
|
- private Properties bundleProperties = null; |
111 |
|
- |
112 |
|
- /** |
113 |
|
- * Name which makes plugin uniquely identifiable. |
114 |
|
- */ |
|
64 |
+{{code language="java" title=""}} |
|
65 |
+public class MyPreRenderer extends AFCPlugin implements IPluginFormPreRender { |
115 |
115 |
@Override |
116 |
|
- public String getName() { |
117 |
|
- return "My PreRenderer"; |
118 |
|
- } |
119 |
|
- |
120 |
|
- /** |
121 |
|
- * Plugin lifecycle method, which is called when the object instance is created. |
122 |
|
- */ |
123 |
|
- @Override |
124 |
|
- public void initialize(IPluginInitializeData initializeData) throws FCPluginException { |
125 |
|
- bundleProperties = initializeData.getProperties(); |
126 |
|
- } |
127 |
|
- |
128 |
|
- /** |
129 |
|
- * Method for executing plugin logic. |
130 |
|
- */ |
131 |
|
- @Override |
132 |
|
- public IPluginFormPreRenderRetVal execute(IPluginFormPreRenderParams params) throws FCPluginException { |
133 |
|
- // Read bundle property 'activate.form.alias'. |
|
67 |
+ public IPluginFormPreRenderRetVal execute(IPluginFormPreRenderParams preRenderParams) throws FCPluginException { |
|
68 |
+ // Read the bundle property 'activate.form.alias' |
134 |
134 |
Set<String> alias = getConfiguredFormAlias("activate.form.alias"); |
135 |
135 |
|
136 |
|
- // Is PreRender plugin enabled for current form instance? |
137 |
|
- IExtendedFormRequestContext ctx = (IExtendedFormRequestContext)params.getFormRequestContext(); |
138 |
|
- if (!alias.contains(ctx.getProject().getName())) { |
139 |
|
- // no form activation found -> cancel processing |
140 |
|
- return new PluginFormPreRenderRetVal(Collections.EMPTY_MAP, true); |
141 |
|
- } |
142 |
|
- |
143 |
|
- // further PreRender implementation |
|
71 |
+ // Check whether the current form is on the white list |
|
72 |
+ IExtendedFormRequestContext ctx = (IExtendedFormRequestContext)preRenderParams.getFormRequestContext(); |
|
73 |
+ if(!alias.contains(ctx.getProjekt().getName())) return null; |
|
74 |
+ |
|
75 |
+ // Actual plugin logic |
144 |
144 |
// .... |
145 |
145 |
|
146 |
|
- return new PluginFormPreRenderRetVal(Collections.EMPTY_MAP, true); |
|
78 |
+ return null; |
147 |
147 |
} |
148 |
148 |
|
149 |
|
- /** |
150 |
|
- * Function to determine a bundle property value. |
151 |
|
- * The determined value is separated by a comma |
152 |
|
- * and returned as a HashSet. |
153 |
|
- * @param propertyName |
154 |
|
- * @return a {@link HashSet} |
155 |
|
- */ |
156 |
156 |
protected Set<String> getConfiguredFormAlias(String propertyName) { |
157 |
|
- String formAlias = bundleProperties.getProperty(propertyName, null); |
158 |
|
- if (XStringUtils.isBlank(formAlias)) { return Collections.emptySet(); } |
159 |
|
- String[] arr = XStringUtils.split(formAlias, ","); |
|
82 |
+ String formAlias = getProperties().getProperty(propertyName, null); |
|
83 |
+ if(StringUtils.isBlank(formAlias)) { |
|
84 |
+ return Collections.emptySet(); |
|
85 |
+ } |
|
86 |
+ String[] arr = StringUtils.split(formAlias, ","); |
160 |
160 |
return new HashSet<String>(Arrays.asList(arr)); |
161 |
161 |
} |
162 |
162 |
} |