Creating your own Autocomplete Form plugin
Available from the OpenKM version 7.1.41 and the dtd version 3.11
You can create your own autocomplete form.
Conditions:
- The new Default Form Values class must implement the "AutocompleteFormValues" interface.
- The new Default Form Values class must be declared under the package "com.openkm.plugin.form.values".
- The new Default Form Values class must be annotated with "@PluginImplementation".
- The new Default Form Values class must extend of "BasePlugin".
Default Autocomplete Form interface:
package com.openkm.plugin.form.values;
import com.openkm.bean.form.FormElement;
import net.xeoh.plugins.base.Plugin;
import java.util.List;
public interface AutocompleteFormValues extends Plugin {
String getName();
void autocompleteFormValues(String uuid, String grpName, List<FormElement> formElementList);
}
The new class must be loaded into the package com.openkm.plugin.form.values because the application plugins system will try to load it from there. See the sample below:
Do not miss the tag @PluginImplementation otherwise the application plugin system will not be able to retrieve the new class.
More information at: Register a new plugin
Method description
Method | Type | Description |
---|---|---|
autocompleteFormValues(String uuid, String grpName, List<FormElement> formElementList) |
void |
The method autocompletes the form elements of the group. |
Example of the default form values implementation
package com.openkm.plugin.form.values;
import com.openkm.bean.form.FormElement;
import com.openkm.bean.form.HorizontalPanel;
import com.openkm.bean.form.Input;
import com.openkm.bean.form.VerticalPanel;
import com.openkm.plugin.BasePlugin;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
@PluginImplementation
public class SampleAutocompleteFormValues extends BasePlugin implements AutocompleteFormValues {
private static final Logger log = LoggerFactory.getLogger(SampleAutocompleteFormValues.class);
@Override
public String getName() {
return "Sample autocomplete form values implementation";
}
@Override
public void autocompleteFormValues(String uuid, String grpName, List<FormElement> formElementList) {
log.info("autocompleteFormValues({}, {}, {})", uuid, grpName, formElementList);
autocomplete(formElementList);
}
private void autocomplete(List<FormElement> formElementList) {
for (FormElement formElement : formElementList) {
if (formElement instanceof Input) {
Input input = (Input) formElement;
if (StringUtils.isEmpty(input.getValue())) {
input.setValue("Autocomplete with name: " + formElement.getName());
}
} else if (formElement instanceof HorizontalPanel) {
HorizontalPanel hPanel = (HorizontalPanel) formElement;
autocomplete(hPanel.getElements());
} else if (formElement instanceof VerticalPanel) {
VerticalPanel vPanel = (VerticalPanel) formElement;
autocomplete(vPanel.getElements());
}
}
}
}
Metadata definition
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 3.10//EN"
"http://www.openkm.com/dtd/property-groups-3.10.dtd">
<property-groups>
<property-group label="Autocomple sample" name="okg:autocomplete" autocompleteValueClassName="com.openkm.plugin.form.values.SampleAutocompleteFormValues">
<input label="Input label first" name="okp:autocomplete.first" type="text"/>
<hpanel name="okp:autocomplete.horizontal1">
<input label="Input label 1" name="okp:autocomplete.input_h1" />
<input label="Input label 2" name="okp:autocomplete.input_h2" />
</hpanel>
</property-group>
</property-groups>