Źródła danych

Źródła danych to komponenty umożliwiające dokonywanie operacji na danych, takich jak odczyt danych, zapis, usuwanie lub modyfikacja. Źródłem danych może być tabela w bazie danych, zapytanie do bazy danych, plik na dysku, webservice, itp.

Źródła danych nie komponentami samowystarczalnymi, tak jak inne komponenty. Mogą one natomiast być wykorzystywane w innych komponentach. Dla przykładu może to być Datachooser, który wyświetla dane wybranego źródła danych.

Definiowanie źródła danych

Źródła danych tworzone są w oparciu o ich definicję stworzoną przez użytkownika. Definicja taka musi zawierać następujące elementy:

  1. Adnotację @DataSource (jeżeli źródło danych nie jest definiowane we wtyczce, musi ona pochodzić z pakietu com.suncode)
  2. Publiczną metodę oznaczoną adnotacją  z jednym parametrem DataSourceDefinitionBuilder
  3. Publiczną metodę o nazwie datasource, która odpowiada za zwrócenie implementacji DataSourceInstance z logiką źródła danych.
  4. (opcjonalnie) Publiczną metodę o nazwie validator, która odpowiada za zwrócenie implementacji DataSourceValidator z logiką walidacji deklaracji źródła danych.

Definicja może zawierać również adnotację . Adnotacja ta przekazuje ścieżkę do skryptu (z classpath) zawierającego definicję formularza dynamicznego.

Można również przekazać ścieżkę do skryptów, które chcemy użyć na formularzu. W tym celu należy użyć adnotacji @DataSourceInjectScript. Można przekazać ścieżki do wielu skruptów podajęc je w formie @DataSourceInjectScript({skryptPath1, skryptPath2, ..})

Źródło danych może również dostarczać skrypt, który buduje wygląd parametrów podczas jego definiowania w PWE. W tym celu należy dodać kolejną adnotację dla klasy  z przekazaną ścieżką do skryptu (z classpath).

Przykładowa definicja przedstawiona jest poniżej.

@DataSource
@DataSourceScript("js/datasource.js")
@ComponentsFormScript( "path/example-form.js" )
public class DataSourceExample
{
    @Define
    public void definition( DataSourceDefinitionBuilder builder )
    {
        builder
            .id( "example-datasource" )
            .name( "datasource.example" )
            .description( "datasource.example.desc" )
            .category( Categories.TEST )
			.operations( DataSourceOperation.READ )
            .parameter()
                .id( "tableName" )
                .name( "datasource.parameter.tableName.name" )
                .description( "datasource.parameter.tableName.desc" )
                .type( Types.STRING)
                .create();
    }
 
    public DataSourceInstance datasource( @Param String tableName )
    {
        return new DatabaseTableSource( tableName );
    }

    public DataSourceValidator validator() {
        return new TableSourceValidator();
    }

}

Implementacja źródła danych

Źródło danych musi posiadać metodę o nazwie datasource. Metoda może posiadać następujące typy parametrów:

  • pojedynczy parametr źródłą danych - typ parametru musi być zgodny ze zdefiniowanym typem oraz musi być poprzedzony adnotacją ,
  • parametr mapujący dwa parametry tablicowe (klucz, wartość) - typ parametru musi być typu java.util.Map<K,V>, gdzie K to zdefiniowany typ parametru komponentu będącego kluczem, a V to zdefiniowany typ parametru komponentu będącego wartością dla klucza. Parametr musi być oznaczony adnotacją  ze zdefiniowanymi właściwościami (key - id parametry będącego kluczem, value - id parametru będącego wartością).
  • pojedynczy parametr typu  oznaczony adnotacją  - jeżeli posiadamy taki typ, to wstrzyknięty zostanie obiekt DataSourceInstance na podstawie wartości tego parametru, która musi być id źródła danych.
  •  - zawiera wszystkie zdefiniowane parametry walidatora wraz z ich wartościami, jest to alternatywa dla pobierania parametru za pomocą wyżej wspomnianej adnotacji,
  •  - translator dla tego komponentu, więcej informacji tutaj,
  •  - obiekt zawierający informacje na temat użytkownika wykorzystującego źródło danych.

Metoda ta musi zwracać obiekt implementujący interfejs DataSourceInstance. Tak naprawdę ta implementacja powinna rozszerzać abstrakcyjną klasę AbstractDataSourceInstance, aby w przyszłości nie było błędów kompilacji, jeżeli będą dochodzić jakieś nowe metody do interfejsu DataSourceInstance.

Przykład implementacji:

public class DatabaseTableSource extends AbstractDataSourceInstance
{
	private String tableName;
 
	public DatabaseTableSource( String tableName )
	{
		this.tableName = tableName;
	}
    @Override
    public CountedResult<Map<String, Object>> getCountedData()
	{
		return new CountedResult<Map<String, Object>>(0, Maps.newHashMap())
	}
 
     @Override
     public void save( Map<String, Object> data )
     {
     }

     @Override
     public void update( Object key, Map<String, Object> data )
     {
     }

	 @Override
     public void delete( Object key )
     {
     }
}

Implementacja nie musi implementować wszystkich metod. Wymagane jest tylko pobieranie danych, gdyż nie każde źródło musi obsługiwać wszystkie operacji na danych.

Walidacja źródła danych

Źródło danych może opcjonalnie posiadać metodę o nazwie validator.

Metoda:

  • jest bezparametrowa,
  • zwraca obiekt implementujący interfejs DataSourceValidator,
  • zwracany obiekt powinien rzucać wyjątek DataSourceValidateException w przypadku niepoprawnej deklaracji źródła danych.

Walidator jest wykorzystywany przy zapisie (utworzenie i aktualizacja) źródła danych.

Przykład implementacji:

public class TableSourceValidator implements DataSourceValidator
{
    @Override
    public void validate( DataSourceDeclaration declaration )
    {
        ParameterDeclaration someParam = declaration.getParameter( "someParam" );
        if ( !someParam.isArray() )
        {
            return;
        }

        ParameterValue someValue = someParam.getValue();

        if ( someValue.getValue().equals( "zła wartość" ) )
        {
            throw new DataSourceValidateException( "Wartość jest nieprawidłowa" );
        }
    }
}

Rejestracja źródła danych we wtyczce

Jeżeli źródło danych jest definiowane we wtyczce to należy dodatkowo zaznaczyć, że wtyczka ta udostępnia komponenty. W tym celu należy w pliku suncode-plugin.xml dodać wpis:

<!-- Udostępnianie zadań autoamtycznych--> 
<workflow-components key="components" />

Dynamiczny formularz

Dynamiczny formularz umożliwia zdefiniowanie formularza parametrów.

Rejestracja dynamicznego formularza

PW.DataSources.register('system-database-with-build-param', { // Identyfikator źródła danych
	buildParams: function(form){ // funkcja `buildParam`, która zostanie wykorzystana do zbudowania formularza parametrów źródła danych
		form.addField('param-1');
		form.addTextAreaField('param-2');
		form.addCombobox({
    		id : 'param-3',
    		values : [{id : 'activity', display : 'Activity'},
    		          {id : 'stage', display : 'Stage'},
    		          {id : 'process', display : 'Process'}]
    	});
		
		form.addTable(['param-4', 'param-5', 'param-6'], {
			tableId: 'fieldMap', name: 'Grupa', description: 'Grupa pól'
		});
 	}
});

Jeżeli podczas dodawania elementu do formularza zdefiniujemy mu id i ta wartość będzie odnośić się do id parametru zdefiniowanego w komponencie, to wszystkie właściwości dla pola zostaną odczytane z definicji parametru (nazwa, opis, wymagalność, typ).

Jeżeli natomiast chcemy dodać pole, które nie jest związane z żadnym parametrem (nie będzie ono zapisane w deklaracji źródła), to powinniśmy określić nazwę, opis, typ oraz wymagalność.

Dostępne funkcję dynamicznego formularza

FunkcjaParametryOpis
addField(definition, [position])

definition - identyfikator dodawanego parametru

lub obiekt zawierający definicję pola

position - pozycja na której dodany mam zostać parametr.

Gdy position nie zostanie podany, parametr zostanie

dodany na końcu formularza.

Dodanie parametru.

Przykład:

...
form.addField('param-1');
...

Jeżeli dodajemy pole niezwiązane z parametrem komponentu, to możemy określić jakiego typu ma być to pole.

Dostępne są następujące typy: string, integer, float, date, datetime, boolean.

...
form.addField({
	id: 'custom',
	type: 'date',
	...
});
...
 addTextArea(definition, [position])definition - identyfikator dodawanego parametru

lub obiekt zawierający definicję pola

position - pozycja na której dodany mam zostać parametr.

Gdy position nie zostanie podany, parametr zostanie

dodany na końcu formularza.

Dodanie parametru jako pole typu `TextArea`.

Parametr musi być typu .

 

Przykład:

...
form.addTextArea('param-1');
...

lub

...
form.addTextArea({
	id: 'param-1',
	...
});
...
addCombobox(definition, [position])definition - obiekt zawierający definicję pola

Definicja powinna zawierać nastepujące pola:

  • id - identyfikator parametru (opcjonalne)
  • valueField - nazwa pola, ustawiającego
    wartość pola
  • displayField - nazwa pola, którego wartość
    zostanie wyświetlona w polu
  • minChars - minimalna liczba wpisanych znaków,
    po której Combobox rozpoczyna filtrowanie.
    Domyślnie: 0.
  • fields - definicja pól Comboboxa w postaci
    tablicy obiektów zawierających nastepujące pola:
    • name - nazwa pola
    • type - typ pola
  • values - ((info) dla typu lokalnego) tablica wartości
    wyświetlanych pola.
  • remote - ((info) dla typu zdalnego) obiekt zawierający
    definicję zdalnego pobierania danych. Obiekt zawiera
    następujące pola:
    • url - adres URL
    • remoteSort - określa czy dane powinny
      być sortowane po stronie serwera (wartość true)
      czy po stronie przeglądarki (wartość false).
      Domyslnie false.
    • pageSize - liczba wyświetlanych wyników na stronie.
      Domyslnie 25.
  • sort - tablica obiektów definiujących sposób sortowania.
    Obiekt zawiera następujące pola:
    • property - pole po jakim chcemy sortować
    • direction - kierunek po jakim chcemy sortować.
      ASC dla kierunku rosnącego,
      DESC dla kierunku malejącego.
  • onChange - funkcja wywoływana, gdy zmieni się
    wartość pola.
    Funkcja może korzystać z następujących parametrów:
    • combo - pole Combox dla którego nastąpiła zmiana
    • newValue - nowa wartość pola
    • oldValue - stara wartość pola
  • forceSelection - informuje, że parametr może przyjmować
    tylko wartości znajdujące się na liście (domyślnie: true)
  • template - szablon opisujący sposób wyświetlania wartości na liście (opcjonalne)
    Właściwość jest tablicą obiektów, z których każdy posiada następujące własności:
    • label - etykieta dla pola
    • field - nazwa pola

position - pozycja na której dodany mam zostać parametr.

Gdy position nie zostanie podany, parametr zostanie

dodany na końcu formularza

 

Dodanie parametru jako pole typu `Combobox`.

Przykład dodanie pola typu 'Combobox' lokalnego (local):

...
form.addCombobox({
	id: 'param-1',
	valueField: 'id',
	displayField: 'display',
	fields: [
		{name: 'id', type: 'string'},
		{name: 'display', type: 'string'}
	],
	values : [{id : 'activity', display : 'Zadanie'},
		  {id : 'stage', display : 'Etap'},
		  {id : 'process', display : 'Proces'}],
	sort: [{
		property: 'display',
		direction: 'DESC'
	}],
	onChange: function(combo, newValue, oldValue){
		...
	},
	forceSelection: false,
	template: [
		{label: 'Id', field: 'id'},
    	{label: 'Wartość', field: 'display'}
	]
});
...

Przykład dodanie pola typu 'Combobox' zdalnego (remote):

...
form.addCombobox({
	id: 'param-1',
	valueField: 'id',
	displayField: 'display',
	fields: [
		{name: 'id', type: 'string'},
		{name: 'display', type: 'string'}
	],
	remote: {
		url: Suncode.getAbsolutePath('plugin/com.suncode.example-plugin/example-combo/get'),
		remoteSort: false,
		pageSize: 20
	},
	sort: [{
		property: 'display',
		direction: 'DESC'
	}],
	onChange: function(combo, newValue, oldValue){
		...
	},
	forceSelection: false,
	template: [
		{label: 'Id', field: 'id'},
    	{label: 'Wartość', field: 'display'}
	]
});
...
addCheckbox(definition, [position])definition - identyfikator dodawanego parametru

lub obiekt zawierający definicję pola

position - pozycja na której dodany mam zostać parametr.

Gdy position nie zostanie podany, parametr zostanie

dodany na końcu formularza.

Przykład:

...
form.addCheckbox('param-1');
...

Jeżeli podpinamy to pod parametr komponentu, to typ tego parametru musi być boolean.

addTable( [definition] )

definition - podstawowa definicja tabeli z parametrami.

Zawiera następujące pola:

  • id - identyfikator tabeli
  • name - wyświetlana nazwa tabeli
  • description - opis tabeli

Dodaje i zwraca "pustą" tabelę ze zgrupowanymi parametrami. Zwrócony obiekt tabeli umożliwia dodanie do niego pól.

Przykład:

var table = form.addTable();
table.addField('param-1');
table.addField('param-2');
table.addCombobox(...);

 

 

addRow( [definition] )

definition - definicja wiersza.

Zawiera następujące pola:

  • id - identyfikator wiersza (opcjonalny)
  • fieldsSpace - odstęp w pikselach pomiędzy elementami wiersza. Domyślnie 5.

Dodaje i zwraca "pusty" wiersz. Zwrócony wiersz umożliwia dodanie do niego pol. Pola będą dodawane obok siebie.

Przykład:

var row = form.addRow();
row.addField('param-1');
row.addField('param-2');
row.addCombobox(...);
addButton(definition, [position] )

definition - definicja przycisku.
Zawiera następujące pola:

  • id - identyfikator przycisku
  • text - wyświetlany tekst przycisku
  • handler - funkcja wywołująca się po kliknieciu przycisku

position - pozycja na której dodany mam zostać parametr.

Gdy position nie zostanie podany, parametr zostanie

dodany na końcu formularza

Dodanie przycisku na formularzu.

Przykład:

form.addButton({
	id: 'btn-1',
	text: 'Przycisk',
	handler: function(){
	...
	}
})
addPassword(definition, [position] )definition - identyfikator dodawanego parametru

lub obiekt zawierający definicję pola

position - pozycja na której dodany mam zostać parametr.

Gdy position nie zostanie podany, parametr zostanie

dodany na końcu formularza.

Dodanie parametru jako pole typu 'Password'.

Parametr musi być typu .

Przykład:

...
form.addTextPassword('param-1');
...

lub

...
form.addPassword({
	id: 'param-1',
	...
});
...
hide(elementId)elementId - identyfikator elementu

Ukrywa pole o podanym id.

Przykład

...
form.hide('param-1');
...
show(elementId)elementId - identyfikator elementu

Pokazuje pole o podanym id.

Przykład:

...
form.show('param-1');
...
 getValue(elementId) elementId - identyfikator elementu

 Pobiera wartość parametru o podanym id.

...
form.getValue('param-1');
...
setValue(elementId, value)

 elementId - identyfikator elementu

value - wartość do ustawienia

Ustawia przekazaną wartość do parametru o podanym id. (Obsługuje tylko zmienne nagłówkowe)

...
form.setValue('param-1', 'value');
...

 

@ComponentsFormScript( "actions/example-form.js" )

Cache

  • Cache jest dostępny dla każdego typu źródła
  • Cache może być włączony (i ustawiony czas) dla konkretnej definicji źródła. Decyduje o tym użytkownik w GUI
  • Po aktualizacji systemu bez wchodzenia w zakładkę źródeł danych domyślnie wszystkie wtyczki maja cache wyłączony
  • W builderze wtyczki (DataSourceDefinitionBuilder ) można skonfigurować parametr supportsPagination,  który określa czy wtyczka sama obsługuje paginację. Domyślnie jest ustawiony na true.

  • jeśli jest włączony cache i paginacja po stronie systemu - pobierane są wszystkie wyniki z DSa nie przekazując paginacji, cachowane są i kolejne wywołania brane są z cache'a (paginując programowo)
  • jeśli jest wyłączony cache i paginacja po stronie systemu - za każdym razem pobierane są wszystkie wyniki z DSa i paginacja nakładana jest programowo

 

Data sources

Data sources are components that allow you to perform operations on data, such as reading data, writing, deleting or modifying it. A data source can be a table in a database, a database query, a file on disk, a webservice, etc.

Data sources are not self-sufficient components like other components. Instead, they can be used in other components. For example, it could be Datachooser, which displays the data of a selected data source.


Defining a data source

Data sources are created based on their definition created by the user. Such a definition must contain the following elements:

  1. @DataSource annotation (if the data source is not defined in the plug-in, it must come from the com.suncode package)
  2. A public method marked with an annotation  with one parameter DataSourceDefinitionBuilder
  3. A public method named datasource, which is responsible for returning an implementation of DataSourceInstance with data source logic.
  4. (Optional) A public method named validator, which is responsible for returning an implementation of DataSourceValidator with data source declaration validation logic.

The definition can also contain an annotation . This annotation passes the path to the script (from classpath) that contains the definition of the dynamic form.

You can also pass the path to the scripts you want to use on the form. To do this, use the @DataSourceInjectScript annotation. You can pass paths to multiple scripts by specifying them in the form @DataSourceInjectScript({scriptPath1, scriptPath2, ..})

A data source can also provide a script that builds the appearance of parameters when it is defined in the PWE. To do this, add another annotation for the class  with the passed path to the script (from classpath).

An example definition:

@DataSource
@DataSourceScript("js/datasource.js")
@ComponentsFormScript( "path/example-form.js" )
public class DataSourceExample
{
    @Define
    public void definition( DataSourceDefinitionBuilder builder )
    {
        builder
            .id( "example-datasource" )
            .name( "datasource.example" )
            .description( "datasource.example.desc" )
            .category( Categories.TEST )
			.operations( DataSourceOperation.READ )
            .parameter()
                .id( "tableName" )
                .name( "datasource.parameter.tableName.name" )
                .description( "datasource.parameter.tableName.desc" )
                .type( Types.STRING)
                .create();
    }
 
    public DataSourceInstance datasource( @Param String tableName )
    {
        return new DatabaseTableSource( tableName );
    }

    public DataSourceValidator validator() {
        return new TableSourceValidator();
    }

}

Data source implementation

The data source must have a method named datasource. The method can have the following types of parameters:

  • a single data source parameter - the type of the parameter must conform to the defined type and must be preceded by the annotation ,
  • parameter mapping two array parameters (key, value) - the type of the parameter must be of type java.util.Map<K,V>, where K is the defined type of the component parameter being the key, and V is the defined type of the component parameter being the value for the key. The parameter must be annotated  with defined properties (key - id of the parameter being the key, value - id of the parameter being the value).
  • a single data source parameter  marked annotation   - if we have such a type, the DataSourceInstance object will be injected based on the value of this parameter, which must be the id of the data source.
  •  - contains all the defined validator parameters with their values, this is an alternative to retrieving the parameter using the aforementioned annotation ,
  •  - Translator for this component, more information here,
  •  - object containing information about the user using the data source.

This method must return an object implementing the DataSourceInstance interface. In fact, this implementation should extend the AbstractDataSourceInstance class, so that there will be no compilation errors in the future if any new methods come to the DataSourceInstance interface.

Implementation example:

public class DatabaseTableSource extends AbstractDataSourceInstance
{
	private String tableName;
 
	public DatabaseTableSource( String tableName )
	{
		this.tableName = tableName;
	}
    @Override
    public CountedResult<Map<String, Object>> getCountedData()
	{
		return new CountedResult<Map<String, Object>>(0, Maps.newHashMap())
	}
 
     @Override
     public void save( Map<String, Object> data )
     {
     }

     @Override
     public void update( Object key, Map<String, Object> data )
     {
     }

	 @Override
     public void delete( Object key )
     {
     }
}

The implementation does not have to implement all methods. Only data retrieval is required, as not every source needs to support all data operations.

Data source validation

The data source can optionally have a method called validator.

Method:

  • is without parameters
  • returns an object implementing the DataSourceValidator interface
  • the returned object should throw a DataSourceValidateException if the data source is declared incorrectly

The validator is used when saving (creating and updating) a data source.

Implementation example:

public class TableSourceValidator implements DataSourceValidator
{
    @Override
    public void validate( DataSourceDeclaration declaration )
    {
        ParameterDeclaration someParam = declaration.getParameter( "someParam" );
        if ( !someParam.isArray() )
        {
            return;
        }

        ParameterValue someValue = someParam.getValue();

        if ( someValue.getValue().equals( "zła wartość" ) )
        {
            throw new DataSourceValidateException( "Wartość jest nieprawidłowa" );
        }
    }
}

Registration of the data source in the plugin

If the data source is defined in the plugin, then you must additionally indicate that the plugin provides components. To do this, add an entry in the suncode-plugin.xml file:

<!-- Sharing autoamtic tasks--> 
<workflow-components key="components" />

Dynamic form

The dynamic form allows you to define a parameter form.

Registration of the dynamic form

PW.DataSources.register('system-database-with-build-param', { // Data source id
	buildParams: function(form){ // The `buildParam` function, which will be used to build the data source parameter form
		form.addField('param-1');
		form.addTextAreaField('param-2');
		form.addCombobox({
    		id : 'param-3',
    		values : [{id : 'activity', display : 'Activity'},
    		          {id : 'stage', display : 'Stage'},
    		          {id : 'process', display : 'Process'}]
    	});
		
		form.addTable(['param-4', 'param-5', 'param-6'], {
			tableId: 'fieldMap', name: 'Grupa', description: 'Grupa pól'
		});
 	}
});

If, when adding an element to the form, we define its id and this value will refer to the id of the parameter defined in the component, then all properties for the field will be read from the parameter definition (name, description, requirement, type).

If, on the other hand, we want to add a field that is not related to any parameter (it will not be stored in the source declaration), then we should define the name, description, type and requiredness.

Dostępne funkcję dynamicznego formularza

FunctionParametersDescription
addField(definition, [position])

definition - the identifier of the added parameter or the object containing the field definition

position - the position at which the parameter is to be added.

When position is not specified, the parameter will be added at the end of the form.


Adding parameter

Example:

...
form.addField('param-1');
...

If we add a field unrelated to the component parameter, we can specify what type this field should be.

The following types are available: string, integer, float, date, datetime, boolean.

...
form.addField({
	id: 'custom',
	type: 'date',
	...
});
...
 addTextArea(definition, [position])

definition - the identifier of the added parameter or the object containing the field definition

position - the position at which the parameter is to be added.

When position is not specified, the parameter will be added at the end of the form.

Adding a parameter as a field of type `TextArea`

The parameter must be of type .

 

example:

...
form.addTextArea('param-1');
...

or

...
form.addTextArea({
	id: 'param-1',
	...
});
...
addCombobox(definition, [position])definitionthe object containing the field definition

The definition should include the following fields:

  • id - identifier of the parameter (optional)
  • valueField - name of the field, setting the value of the field
  • displayField - the name of the field, whose value will be displayed in the field
  • minChars - the minimum number of characters entered, after which Combobox starts filtering. Default: 0.
  • fields - definition of Combobox fields in the form of an array of objects containing the following fields:
    • name - field name
    • type - field type
  • values - ((info) for local type) an array of values displayed fields.
  • remote - ((info) for remote type) object containing the definition of remote data retrieval. The object contains the following fields:
    • url - URL address
    • remoteSort - determines whether the data should be sorted on the server side (value true) or on the browser side (value false).

      Default value is false.

    • pageSize - the number of displayed results on the page.

      Default is 25.

  • sort -an array of objects defining the method of sorting.

    The object contains the following fields:

    • property - the field by which we want to sort
    • direction - the direction by which we want to sort.
      ASC for ascending direction,
      DESC for decreasing direction.
  • onChange - a function called when the value of the field.
    The function can use the following parameters:
    • combo - Combox field for which the change occurred
    • newValue - the new value of the field
    • oldValue - the old value of the field

position - the position at which the parameter is to be added.

 

When the position is not specified, the parameter will be added at the end of the form

 

Adding a parameter as a field of type `Combobox`.

Example of adding a field of type `Combobox` local (local):

...
form.addCombobox({
	id: 'param-1',
	valueField: 'id',
	displayField: 'display',
	fields: [
		{name: 'id', type: 'string'},
		{name: 'display', type: 'string'}
	],
	values : [{id : 'activity', display : 'Zadanie'},
		  {id : 'stage', display : 'Etap'},
		  {id : 'process', display : 'Proces'}],
	sort: [{
		property: 'display',
		direction: 'DESC'
	}],
	onChange: function(combo, newValue, oldValue){
		...
	}
});
...

Example of adding a field of type 'Combobox' remote (remote):

...
form.addCombobox({
	id: 'param-1',
	valueField: 'id',
	displayField: 'display',
	fields: [
		{name: 'id', type: 'string'},
		{name: 'display', type: 'string'}
	],
	remote: {
		url: Suncode.getAbsolutePath('plugin/com.suncode.example-plugin/example-combo/get'),
		remoteSort: false,
		pageSize: 20
	},
	sort: [{
		property: 'display',
		direction: 'DESC'
	}],
	onChange: function(combo, newValue, oldValue){
		...
	}
});
...
addCheckbox(definition, [position])definition - identifier of the added parameter or object containing the definition of the field

position - the position at which the parameter is to be added.

 

When the position is not specified, the parameter will be added at the end of the form

Example:

...
form.addCheckbox('param-1');
...

If we plug this into a component parameter, the type of this parameter must be boolean.

addTable( [definition] )

definition - a basic definition of a table with parameters.

 

It contains the following fields:
  • id - identifier of the table
  • name - displayed name of the table
  • description - description of the table

Adds and returns an "empty" table with grouped parameters. The returned table object allows you to add fields to it.

Example:

var table = form.addTable();
table.addField('param-1');
table.addField('param-2');
table.addCombobox(...);

 

 

addRow( [definition] )

definition - definition of a row.

It contains the following fields:

  • id - row identifier (optional).
  • fieldsSpace - space in pixels between the elements of the row. Default is 5.

Adds and returns an "empty" row. The returned row allows you to add fields to it. The fields will be added side by side.

Example:

var row = form.addRow();
row.addField('param-1');
row.addField('param-2');
row.addCombobox(...);
addButton(definition, [position] )

definition - definition of the button.
It contains the following fields:

  • id - identifier of the button
  • text - displayed text of the button
  • handler - function that is called when the button is clicked

position - the position on which the parameter is to be added.

 

When the position is not specified, the parameter will be added at the end of the form

Adding a button on the form.

Example:

form.addButton({
	id: 'btn-1',
	text: 'Przycisk',
	handler: function(){
	...
	}
})
addPassword(definition, [position] )definition - identifier of the added parameter or object containing the definition of the field

position - the position at which the parameter is to be added.

 

When the position is not specified, the parameter will be added at the end of the form

Adding a parameter as a field of type 'Password'.

The parameter must be of type .

Example:

...
form.addTextPassword('param-1');
...

or

...
form.addPassword({
	id: 'param-1',
	...
});
...
hide(elementId)elementId - element identifier

Hides the field with the specified id.

Example:

...
form.hide('param-1');
...
show(elementId)elementId - element identifier

Shows the field with the specified id.

Example:

...
form.show('param-1');
...
 getValue(elementId)elementId - element identifier

Retrieves the value of the parameter with the specified id.

...
form.getValue('param-1');
...
setValue(elementId, value)

elementId - element identifier

value - value to set

Sets the passed value to the parameter with the specified id. (Supports only header variables)

...
form.setValue('param-1', 'value');
...

 

@ComponentsFormScript( "actions/example-form.js" )

Cache

  • Cache is available for any type of source
  • Cache can be enabled (and time set) for a specific source definition. This is decided by the user in the GUI
  • After a system update without entering the data sources tab, all plugins have cache disabled by default
  • In the plugin builder (DataSourceDefinitionBuilder ) you can configure the supportsPagination parameter, which determines whether the plugin itself supports pagination. By default, it is set to true.

  • If cache and pagination on the system side is enabled - all results from DS are downloaded without passing pagination, cached and subsequent calls are taken from the cache (pagination programmatically)
  • If cache and pagination on the system side is disabled - each time all results from DS are downloaded and pagination is applied by software