|
@ScheduledTask @ScheduledTaskScript( "js/example-form.js" ) public class ExampleScheduledTask { @Define public void definition( ScheduledTaskDefinitionBuilder builder ) { builder .id( "example-scheduled-task" ) .name( "example.scheduled.task.name" ) .description( "example.scheduled.task.desc" ) .cancelable() .parameter() .id( "scheduled-task-param" ) .name( "example.scheduled.task.param.name" ) .description( "example.scheduled.task.param.desc" ) .type( Types.STRING ) .create(); } public void execute( @Param( value = "scheduled-task-param" ) String param ) { // Ciało zadania zaplanowanego ... } } |
Od wersji 4.1.2 jest możliwość dodawania nowych parametry do istniejących zadań zaplanowanych pod warunkiem spełnienia minimum jednego z warunków:
Przed tą wersją bezpośrednie rozszerzanie istniejących zadań zaplanowanych nie jest wspierane. |
Zadanie zaplanowane musi posiadać metodę o nazwie execute. Metoda może posiadać następujące typy parametrów:
Jeżeli zadanie zaplanowane 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 komponentów (m.in. zadań zaplanowanych) --> <workflow-components key="components" /> |
Zadanie zaplanowane we wtyczce nie musi być komponentem. Może zostać stworzone tak samo, jak zadania zaplanowane definiowane w projektach klienckich - zadanie zaplanowane jako wywołanie publicznej metody.
Np. po stworzeniu klasy we wtyczce:
package com.suncode.plugin; public class SomePluginClass { public void someMethod( String text, Integer number ) { System.out.println( "Text: " + text + ", number: " + number ); } public void someMethod2( String text, Double number ) { System.out.println( "Text: " + text + ", number: " + number ); } } |
Po wpisaniu com.suncode.plugin.SomePluginClass w pole Nazwa klasy w oknie dodawania nowego zadania zaplanowanego wyświetlone zostaną metody someMethod oraz someMethod2, które można wybrać i dodać jako zadanie zaplanowane.
Takie zadania mają jednak ograniczenia:
Ze względu na powyższe ograniczenia funkcjonalność ta powinna służyć jedynie do testowania własnych klas we wtyczkach. Preferowane jest, aby docelowo zadania zaplanowane we wtyczkach były komponentami.
Jeśli zadanie zaplanowane jest napisane jako rozszerzenie klasy AbstractAdvancedTask i ma włączoną adnotację cancelable = true to by przerwać wykonywanie takiego zadania należy w kodzie metody dodać warunek:
|
Dynamiczny formularz umożliwia zdefiniowanie formularza parametrów zadania zaplanowanego.
Dynamiczny formularz rejestrowany jest poprzez przekazanie ścieżki do skryptu js (z classpath wtyczki) zawierającego definicję formularza dynamicznego w adnotacji @ScheduledTaskScript dodanej na poziomie klasy komponentu zadania zaplanowanego.
Przykładowa rejestracja skryptu na klasie po stronie Javy:
@ScheduledTask @ScheduledTaskScript( "js/example-form.js" ) public class ExampleScheduledTask { @Define public void definition( ScheduledTaskDefinitionBuilder builder ) { builder .id( "example-scheduled-task" ) // identyfikator zadania zaplanowanego ... // pozostałe parametry } ... } |
Przykładowa zawartość skryptu rejestrującego dynamiczny formularz po stronie Javascript:
// kluczem w metodzie register jest identyfikator zadania zaplanowanego PW.ScheduledTasks.register('example-scheduled-task', { buildParams: function (form) { form.addCombobox({ id: 'example-scheduled-task', values: [ ['wartosc1', 'Wartosc 1'], ['wartosc2', 'Wartosc 2'], ['wartosc3', 'Wartosc 3'] ] }); } } |
Funkcja | Parametry | Opis | |||
---|---|---|---|---|---|
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. | Przykład dodania parametru:
Przykład dodania parametru z reagowaniem na zmianę wartości:
| |||
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. listeners - obiekt definiujacy funkcje zdarzeń na zmiennej
| Dodanie parametru jako pole typu `TextArea`.
Przykład:
lub
| |||
addCombobox(definition, [position]) | definition - obiekt zawierający definicję pola Definicja powinna zawierać nastepujące pola:
position - pozycja na której dodany mam zostać parametr. Gdy position nie zostanie podany, parametr zostanie dodany na końcu formularza
Endpoint zdalnego comboboxa ma następującą strukturę: Parametry wysyłane:
Dane zwracane:
| Dodanie parametru jako pole typu `Combobox`. Przykład dodania pola typu 'Combobox' lokalnego (local):
Przykład dodania pola typu 'Combobox' zdalnego (remote):
| |||
setComboboxRemoteUrl(elementId, url) | elementId - identyfikator elementu url - ades URL | Docelowy element musi być combobox'em typu zdalnego. Przykład:
| |||
setComboboxRemoteParams(elementId, params) | elementId - identyfikator elementu params - obiekt zawierający pola z dokładanymi parametrami do żądań http
| Docelowy element musi być combobox'em typu zdalnego. Przykład:
| |||
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. listeners - obiekt definiujacy funkcje zdarzeń na zmiennej
| Przykład:
Jeżeli podpinamy to pod parametr komponentu, to typ tego parametru musi być boolean. | |||
addRow( [definition] ) | definition - definicja wiersza. Zawiera następujące pola:
| Dodaje i zwraca "pusty" wiersz. Zwrócony wiersz umożliwia dodanie do niego pól. Pola będą dodawane obok siebie. Przykład:
| |||
addTable( [definition] ) | definition - definicja tabeli. Zawiera następujące pola:
| Dodaje i zwraca "pustą" tabele. Zwrócona tabela umożliwia dodanie do niej parametrów tablicowych jako kolumn tabeli. Pola tablicowe będą wyświetlane obok siebie i razem pogrupowane. Inne elementy niż parametry tablicowe nie są wspierane. Przykład:
| |||
addButton(definition, [position] ) | definition - definicja 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:
| |||
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. listeners - obiekt definiujacy funkcje zdarzeń na zmiennej
| Dodanie parametru jako pole typu 'Password'.
Przykład:
lub
| |||
hide(elementId) | elementId - identyfikator elementu | Ukrywa pole o podanym id. Przykład
| |||
show(elementId) | elementId - identyfikator elementu | Pokazuje pole o podanym id. Przykład:
| |||
disable(elementId) | elementId - identyfikator elementu | Wyłącza możliwość edycji pola o podanym id. Przykład:
| |||
enable(elementId) | elementId - identyfikator elementu | Włącza możliwość edycji pola o podanym id. Przykład:
| |||
getValue(elementId) | elementId - identyfikator elementu | Pobiera wartość parametru o podanym id. Przykład:
| |||
setValue(elementId, value) | elementId - identyfikator elementu value - wartość do ustawienia | Ustawia przekazaną wartość do parametru o podanym id. Dla typów tablicowych wartością jest tablica wartości. Przykład:
| |||
setRequired(elementId, value) Dostępne od wersji 4.1.3 | elementId - identyfikator elementu value - wymagalność parametru | Dostępne od wersji 4.1.3. Ustawia wymagalność parametru o podanym id. Tylko parametry zadeklarowane wstępnie jako opcjonalne mogą mieć zmienioną wymagalność na formularzu. Przykład:
| |||
mask(onlyForm) | onlyForm - prawda by nałożyć maskę tylko na formularz parametrów, fałsz by nałożyć maskę na zawartość całego okna. | Nakłada maskę na formularz parametrów lub zawartość okna. Przykład:
| |||
unmask(onlyForm) | onlyForm - prawda by usunąć maskę tylko z formularza parametrów, fałsz by usunąć maskę z zawartości całego okna | Usuwa maskę z formularza parametrów lub zawartości okna. Przykład:
|
|
@ScheduledTask @ScheduledTaskScript( "js/example-form.js" ) public class ExampleScheduledTask { @Define public void definition( ScheduledTaskDefinitionBuilder builder ) { builder .id( "example-scheduled-task" ) .name( "example.scheduled.task.name" ) .description( "example.scheduled.task.desc" ) .cancelable() .parameter() .id( "scheduled-task-param" ) .name( "example.scheduled.task.param.name" ) .description( "example.scheduled.task.param.desc" ) .type( Types.STRING ) .create(); } public void execute( @Param( value = "scheduled-task-param" ) String param ) { // Body of scheduled task ... } } |
A scheduled task must have a method named execute. The method can have the following parameter types:
If the scheduled task is defined in the plugin then you need to additionally indicate that the plugin provides components. To do this, add an entry in the suncode-plugin.xml file:
<!-- Sharing components (among other scheduled tasks) --> <workflow-components key="components" /> |
A scheduled task in a plugin does not have to be a component. It can be created in the same way as scheduled tasks defined in client projects - a scheduled task as a public method call.
For example, after creating a class in a plug-in
package com.suncode.plugin; public class SomePluginClass { public void someMethod( String text, Integer number ) { System.out.println( "Text: " + text + ", number: " + number ); } public void someMethod2( String text, Double number ) { System.out.println( "Text: " + text + ", number: " + number ); } } |
After typing com.suncode.plugin.SomePluginClass in the Class Name field, the window for adding a new scheduled task will display someMethod1 and someMethod2 methods, which can be selected and added as a scheduled task.
However, such tasks have limitations:
Due to the above limitations, this functionality should only be used for testing custom classes in plugins. It is preferred that ultimately the tasks scheduled in plugins are components.
If a scheduled task is written as an extension of the AbstractAdvancedTask class and has the cancelable = true annotation enabled, then to stop the execution of such a task you need to add a condition in the method code:
|
The dynamic form allows you to define a scheduled task parameter form.
PW.ScheduledTasks.register('example-scheduled-task', { buildParams: function (form) { form.addCombobox({ id: 'example-scheduled-task', values: [ ['wartosc1', 'Wartosc 1'], ['wartosc2', 'Wartosc 2'], ['wartosc3', 'Wartosc 3'] ] }); } } |
If, when adding an element to the form, you define the id of the element and this value refers 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, you want to add a field that is not related to any parameter, then you should define the name, description, type and requirement. |
Function | Parameters | Description | |||
---|---|---|---|---|---|
addField(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. listeners - an object that defines the function of events on the variable
| Adding parameter. Example:
If we add a field unrelated to the component parameter, we can specify what type the field should be. The following types are available: string, integer, float, date, datetime, boolean, string[], integer[], float[], date[], datetime[], boolean[].
| |||
addTextArea(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 position is not specified, the paramter will be added at the end of the form. listeners - an object that defines the function of events on the variable
| Adding a parameter as a field of type `TextArea`.
Example
or
| |||
addCombobox(definition, [position]) | definition - object containing the definition of a field The definition should contain the following fields:
position - The position on which the parameter is to be added. When position is not specified, the parameter will be added to the end of the form
| Adding a parameter as a field of type `Combobox`. Example of adding a field of type `Combobox` local (local):
Example of adding a field of type 'Combobox' remote (remote):
| |||
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 position is not specified, the paramter will be added at the end of the form. listeners - an object that defines the function of events on the variable change - a function called when the value of a field changes.The function can use the following parameters:
| Example:
If we pin this to a component parameter, the type of this parameter must be boolean. | |||
addRow( [definition] ) | definition - definition of a row. It contains the following fields:
| 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:
| |||
addButton(definition, [position] ) | definition - button definition.
position - the position at which the parameter is to be added. When position is not specified, the paramter will be added at the end of the form. | Adding a button on the form. Example:
| |||
addPassword(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 If position is not specified, the parameter will be added at the end of the form. listeners - an object that defines event functions on the variable
| Adding a parameter as a field of type 'Password'.
Example
or
| |||
hide(elementId) | elementId - element identifier | Hides the field with the specified id. Example
| |||
show(elementId) | elementId - element identifier | Hides the field with the specified id. Example
| |||
disable(elementId) | elementId - element identifier | Hides the field with the specified id. Example
| |||
enable(elementId) | elementId - element identifier | Hides the field with the specified id. Example
| |||
getValue(elementId) | elementId - element identifier | Hides the field with the specified id. Example
| |||
setValue(elementId, value) | elementId - element identifier value - value to be set | Sets the forwarded value to the parameter with the specified id. For array types, the value is an array of values. Example
| |||
mask(onlyForm) | onlyForm - true - to apply the mask only to the parameter form, false - to apply the mask to the contents of the entire window. | Applies a mask to a parameter form or window content. Example
| |||
unmask(onlyForm) | onlyForm - true - to apply the mask only to the parameter form, false - to apply the mask to the contents of the entire window. | Applies a mask to a parameter form or window content. Example
|