### Setup Tomcat Server (Bash)
Source: https://github.com/cuba-platform/documentation/blob/master/README.md
Executes the Gradle task to install and set up a local Tomcat server for deploying CUBA Platform documentation. The server is typically installed in `./deploy/tomcat` and listens on port 6080.
```bash
./gradlew setupTomcat
```
--------------------------------
### Initialize Process Actions (Java)
Source: https://github.com/cuba-platform/documentation/blob/master/content/workflow/adoc/en/chapter2.adoc
The `initProcessActions` method loads assignment information for the EBook. It then uses the `wfService` to get assignment details and potentially create corresponding action buttons for the user.
```java
private void initProcessActions(EBook eBook) {
AssignmentInfo assignmentInfo = wfService.getAssignmentInfo(eBook);
}
```
--------------------------------
### Define Process Start Form (XML)
Source: https://github.com/cuba-platform/documentation/blob/master/content/bpm/adoc/en/functionality/start_process_form.adoc
Configures a form to be displayed when a process starts. This is achieved by setting the 'Start form' property on the 'Start event' node. The example shows how to specify a form name and parameters.
```xml
```
--------------------------------
### Diagnose LibreOffice Startup Errors on Ubuntu
Source: https://github.com/cuba-platform/documentation/blob/master/content/reporting/adoc/en/open_office.adoc
This command uses strace to trace signals and diagnose errors when starting LibreOffice in headless mode on Ubuntu.
```bash
$ strace -e trace=signal /usr/lib/libreoffice/program/soffice.bin --headless --accept="socket,host=localhost,port=8100;urp" --nologo --nolockcheck
```
--------------------------------
### ContainerDataProvider Setup (XML and Java)
Source: https://github.com/cuba-platform/documentation/blob/master/content/charts/adoc/en/chart/chart_data_binding.adoc
Provides an example of setting up a ContainerDataProvider in XML and configuring it in a screen controller. This method binds chart data to a CollectionContainer.
```xml
include::{sourcesdir}/chart/containerDataProvider_example.xml[]
```
```java
include::{sourcesdir}/chart/ContainerDataProvider_example.java[]
```
--------------------------------
### Start Tomcat Server (Bash)
Source: https://github.com/cuba-platform/documentation/blob/master/README.md
Starts the local Tomcat server after it has been set up and documentation has been deployed. The server is typically located in `./deploy/tomcat`.
```bash
./deploy/tomcat/bin/startup.sh
```
--------------------------------
### Start Jetty Server for Application
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/deployment/deployment_variants/war_deployment.adoc
This command starts the Jetty server using the configured base directory, loading the deployed WAR files and making the application accessible via HTTP.
```bash
java -jar c:\work\jetty-base\start.jar
```
--------------------------------
### HTML: Navigation Example with app-route and iron-lazy-pages
Source: https://github.com/cuba-platform/documentation/blob/master/content/polymer/adoc/en/recipes/recipes__navigation.adoc
This HTML code demonstrates a basic navigation setup using `app-route` to parse the URL and `iron-lazy-pages` to manage content display. It's designed to be run within an iframe to allow URL changes.
```html
App with Navigation
Home Page
About Page
Contact Page
```
--------------------------------
### Install Asciidoctor and Coderay (Ruby)
Source: https://github.com/cuba-platform/documentation/blob/master/README.md
Installs Asciidoctor for converting AsciiDoc to HTML and Coderay for syntax highlighting. Requires Ruby to be installed first.
```bash
gem install asciidoctor -v 1.5.2
gem install coderay
```
--------------------------------
### Install LibreOffice Package on Ubuntu Server
Source: https://github.com/cuba-platform/documentation/blob/master/content/reporting/adoc/en/open_office.adoc
This command installs the LibreOffice package on an Ubuntu server using the apt-get package manager.
```bash
$ sudo apt-get install libreoffice
```
--------------------------------
### Example Filter XML Configuration
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/gui_framework/gui_vcl/gui_components/gui_Filter.adoc
Provides an example of an XML configuration for a filter component, likely demonstrating the usage of various properties and custom conditions.
```xml
include::{sourcesdir}/gui_vcl/filter_5.xml[]
```
--------------------------------
### XML Chart Configuration Example
Source: https://github.com/cuba-platform/documentation/blob/master/content/charts/adoc/en/chart/chart_example/custom_json.adoc
Example of an initial XML configuration for a serial chart. This sets up the basic structure and properties of the chart before applying JSON configurations.
```xml
include::{sourcesdir}/chart/custom_json_1.xml[]
```
--------------------------------
### XML Menu Configuration Example
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/config_files/menu.xml.adoc
An example of an XML file defining menu items and their associated properties and permissions. This structure allows for hierarchical menus and granular control over user access.
```xml
```
--------------------------------
### Example views.xml Configuration
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/config_files/views.xml.adoc
An example demonstrating the structure of a views.xml file, showcasing the definition of different entity views with properties and nested properties. This configuration is essential for defining how entity data is fetched and displayed.
```xml
```
--------------------------------
### Install Ruby Gems for Theme Building (Bash)
Source: https://github.com/cuba-platform/documentation/blob/master/README.md
Installs the necessary Ruby gems for building the CUBA theme using Asciidoctor stylesheet factory. Includes Sass, Compass, and Zurb Foundation.
```bash
gem install --no-rdoc --no-ri sass -v 3.4.22
gem install --no-rdoc --no-ri compass
gem install zurb-foundation
```
--------------------------------
### Initialize EBook Instance and Check for New Instance (Java)
Source: https://github.com/cuba-platform/documentation/blob/master/content/workflow/adoc/en/chapter2.adoc
The `postInit` method checks if the EBook instance is new. If it is, it calls `initProcess` to set up the initial process. This method is invoked after the screen is initialized and the EBook instance is loaded.
```java
protected void postInit() {
EBook eBook = getItem();
if (PersistenceHelper.isNew(eBook)) {
initProcess(eBook);
}
}
```
--------------------------------
### Initialize UI Components Based on EBook State (Java)
Source: https://github.com/cuba-platform/documentation/blob/master/content/workflow/adoc/en/chapter2.adoc
After checking the EBook instance, `postInit` initializes UI components like `stateLabel` and `fieldGroup`. It displays the EBook's state and prevents editing if the process has already started.
```java
protected void postInit() {
...
if (eBook.getState() == null) {
stateLabel.setValue("State: not started");
} else {
stateLabel.setValue("State: " + eBook.getLocState());
fieldGroup.setEditable(false);
}
}
```
--------------------------------
### Initialize Process Actions and Attachments Table (Java)
Source: https://github.com/cuba-platform/documentation/blob/master/content/workflow/adoc/en/chapter2.adoc
The `postInit` method also calls methods to initialize user actions and the attachments table. This ensures that relevant actions and attachment management are available to the user based on the current state.
```java
protected void postInit() {
...
initProcessActions(eBook);
initAttachmentsTable();
}
}
```
--------------------------------
### PasswordField XML Configuration
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/gui_framework/gui_vcl/gui_components/gui_PasswordField.adoc
Example of how to declare and configure a PasswordField component in an XML layout file. It demonstrates basic setup and attribute usage.
```xml
include::{sourcesdir}/gui_vcl/passwordfield_1.xml[]
```
--------------------------------
### Load and Set Process Instance for EBook (Java)
Source: https://github.com/cuba-platform/documentation/blob/master/content/workflow/adoc/en/chapter2.adoc
The `initProcess` method loads a `Proc` object from the database using a specific code ('book_scanning'). If found, it sets this `Proc` instance to the `EBook` object. This establishes the process associated with the EBook.
```java
private void initProcess(final EBook eBook) {
LoadContext loadContext = new LoadContext(Proc.class);
loadContext.setQueryString("select p from wf$Proc p where p.code = :code")
.setParameter("code", "book_scanning");
loadContext.setView("start-process");
Proc proc = dataSupplier.load(loadContext);
if (proc != null)
eBook.setProc(proc);
else
throw new IllegalStateException("Process not found");
}
```
--------------------------------
### TokenList XML Configuration
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/gui_framework/gui_vcl/gui_components/gui_TokenList.adoc
Example of how to define a TokenList component in an XML screen descriptor. It shows the setup of data containers and the TokenList itself for managing product selections.
```xml
include::{sourcesdir}/gui_vcl/tokenList_1.xml[]
```
--------------------------------
### EBook Editor Controller Implementation (Java)
Source: https://github.com/cuba-platform/documentation/blob/master/content/workflow/adoc/en/chapter2.adoc
Provides the Java code for the EBook editor controller. This snippet includes necessary imports for Cuba Platform entities, commit contexts, and load contexts, setting the stage for implementing editor logic related to business processes.
```java
package com.sample.library.gui.ebook;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.CommitContext;
import com.haulmont.cuba.core.global.LoadContext;
import com.haulmont.cuba.core.global.PersistenceHelper;
```
--------------------------------
### Heroku system.properties for Java Runtime
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/deployment/deployment_variants/heroku_deployment/heroku_github_deployment.adoc
This plain text file, `system.properties`, specifies the Java runtime version required for your application on Heroku. The example indicates Java 1.8.0_121.
```plain
java.runtime.version=1.8.0_121
```
--------------------------------
### Initialize EBook Editor and Workflow Process (Java)
Source: https://github.com/cuba-platform/documentation/blob/master/content/workflow/adoc/en/chapter2.adoc
Initializes the EBook editor, checks if the EBook is new, and sets up the initial workflow process if necessary. It also updates the state label and field group editability based on the EBook's state. This method is called after the component's initialization.
```Java
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.data.DataSupplier;
import com.haulmont.cuba.gui.data.DsContext;
import com.haulmont.cuba.gui.export.ExportDisplay;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
import com.haulmont.workflow.core.app.WfService;
import com.haulmont.workflow.core.entity.*;
import com.haulmont.workflow.core.global.AssignmentInfo;
import com.haulmont.workflow.core.global.WfConstants;
import com.haulmont.workflow.gui.base.action.ProcessAction;
import com.sample.library.entity.EBook;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class EBookEdit extends AbstractEditor {
@Inject
protected WfService wfService;
@Inject
protected ComponentsFactory componentsFactory;
@Inject
protected BoxLayout actionsBox;
@Inject
protected DataSupplier dataSupplier;
@Inject
protected Label stateLabel;
@Inject
protected FieldGroup fieldGroup;
@Inject
protected Table attachmentsTable;
@Inject
protected ExportDisplay exportDisplay;
@Override
public void init(Map params) {
}
@Override
protected void postInit() {
EBook eBook = getItem();
if (PersistenceHelper.isNew(eBook)) {
initProcess(eBook);
}
if (eBook.getState() == null) {
stateLabel.setValue("State: not started");
} else {
stateLabel.setValue("State: " + eBook.getLocState());
fieldGroup.setEditable(false);
}
initProcessActions(eBook);
initAttachmentsTable();
}
private void initProcess(final EBook eBook) {
LoadContext loadContext = new LoadContext(Proc.class);
loadContext.setQueryString("select p from wf$Proc p where p.code = :code")
.setParameter("code", "book_scanning");
loadContext.setView("start-process");
Proc proc = dataSupplier.load(loadContext);
if (proc != null)
eBook.setProc(proc);
else
throw new IllegalStateException("Process not found");
eBook.setRoles(new ArrayList());
for (ProcRole procRole : proc.getRoles()) {
if (procRole.getAssignToCreator())
continue;
CardRole cardRole = new CardRole();
cardRole.setCard(eBook);
cardRole.setProcRole(procRole);
List defaultProcActors = procRole.getDefaultProcActors();
if (defaultProcActors.isEmpty())
throw new IllegalStateException("Default actor is not assigned for role " + procRole.getName());
cardRole.setUser(defaultProcActors.get(0).getUser());
eBook.getRoles().add(cardRole);
}
getDsContext().addListener(new DsContext.CommitListener() {
@Override
public void beforeCommit(CommitContext context) {
context.getCommitInstances().addAll(eBook.getRoles());
}
@Override
public void afterCommit(CommitContext context, Set result) {
}
});
}
private void initProcessActions(EBook eBook) {
AssignmentInfo assignmentInfo = wfService.getAssignmentInfo(eBook);
if (eBook.getJbpmProcessId() == null && eBook.getState() == null) {
addProcessAction(WfConstants.ACTION_START, assignmentInfo);
} else if (assignmentInfo != null) {
for (String actionName : assignmentInfo.getActions()) {
addProcessAction(actionName, assignmentInfo);
}
}
}
private void addProcessAction(String actionName, AssignmentInfo assignmentInfo) {
ProcessAction action = new ProcessAction(getItem(), actionName, assignmentInfo, this);
Button button = componentsFactory.createComponent(Button.NAME);
button.setAction(action);
button.setAlignment(Alignment.MIDDLE_RIGHT);
actionsBox.add(button);
}
private void initAttachmentsTable() {
attachmentsTable.addGeneratedColumn("file", new Table.ColumnGenerator() {
@Override
public Component generateCell(final CardAttachment attachment) {
LinkButton link = componentsFactory.createComponent(LinkButton.NAME);
link.setCaption(attachment.getFile().getName());
link.setAction(new AbstractAction("") {
@Override
public void actionPerform(Component component) {
exportDisplay.show(attachment.getFile());
}
});
return link;
}
});
}
}
```
--------------------------------
### Programmatically Add Validator (Java)
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/gui_framework/gui_vcl/gui_misc/gui_validator.adoc
Example demonstrating how to programmatically add a validator to a component in a screen controller. This involves getting a validator instance and passing it to the component's addValidator() method.
```java
public class AddressEditor extends AbstractEditor {
// ...
@Subscribe("zipCodeField")
public void onZipCodeFieldValidate(Field.ValidationEvent event) {
String zipCode = (String) event.getValue();
if (!zipCode.matches("\\d{5}(?:-\\d{4})?@")) {
throw new ValidationException(String.format("Invalid zip code: %s", zipCode));
}
}
// Alternative programmatic approach using addValidator
@Override
public void init(Map params) {
super.init(params);
zipCodeField.addValidator(new Consumer() {
@Override
public void accept(String value) {
if (!value.matches("\\d{5}(?:-\\d{4})?@")) {
throw new ValidationException(String.format("Invalid zip code: %s", value));
}
}
});
}
}
```
--------------------------------
### Periodic Data Refresh with Java using BackgroundTaskWrapper
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/gui_framework/background_tasks/background_task_examples.adoc
Illustrates using `BackgroundTaskWrapper` for repetitive background tasks like automatically updating screen data. This utility simplifies scenarios where background tasks are frequently started, restarted, and cancelled. The example demonstrates refreshing rank monitoring data, showing the last update time, and handling potential errors or timeouts during data loading.
```java
public class RankMonitor extends Screen {
@Inject
private Timer timer;
@Inject
private RankService rankService;
private BackgroundTaskWrapper> refreshTaskWrapper;
@Subscribe
public void onInit(OnInitEvent event) {
// Initialize BackgroundTaskWrapper with no-arg constructor
refreshTaskWrapper = new BackgroundTaskWrapper>(this) {
@Override
protected Void doWork(Void... params) throws Exception {
// Call custom service to load data
return rankService.loadRanks(filterCheckbox.getValue());
}
@Override
protected void doPostSuccess(List result) {
// Apply successfully obtained result to screen's components
updateRankList(result);
lastUpdatedLabel.setValue(formatTimestamp(new Date()));
}
@Override
protected void doPostFail(Exception exception) {
// Inform user that data loading has failed
notifications.create()
.withCaption("Error loading ranks.")
.withDescription(exception.getMessage())
.show();
}
};
// Immediately trigger a background data refresh after screen initialization
refreshTaskWrapper.run();
// Start timer for periodic refresh
timer.scheduleAtFixedRate(new Timer.Task() {
@Override
public void run() {
// Every timer tick triggers a data refresh in the background
refreshTaskWrapper.run();
}
}, 5000, 10000); // Start after 5 seconds, repeat every 10 seconds
}
@Subscribe("filterCheckbox")
public void onFilterCheckboxValueChange(HasValue.ValueChangeEvent event) {
// Immediately trigger a background data refresh after checkbox value has changed
refreshTaskWrapper.run();
}
private void updateRankList(List ranks) {
// Update UI with the new list of ranks
}
private String formatTimestamp(Date date) {
// Format date to string
return "...";
}
}
```
--------------------------------
### Showing a Screen with ScreenFacet in Java
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/gui_framework/gui_facets/gui_ScreenFacet.adoc
Illustrates how to programmatically show a screen configured with a ScreenFacet using the `show()` method in Java. This is an alternative to using action or button subscriptions.
```java
ScreenFacet screenFacet = facets.create(ScreenFacet.class, "myScreenFacet");
screenFacet.show();
```
--------------------------------
### Gradle Build Task Examples (Bash)
Source: https://github.com/cuba-platform/documentation/blob/master/README.md
Demonstrates common Gradle build tasks for CUBA Platform documentation. Tasks follow a {purpose}{doc}{lang} structure for building, deploying, and generating PDFs.
```bash
# Build single-HTML document for English manual
./gradlew buildManualEn
# Build multi-page document for Russian manual
./gradlew chopManualRu
# Build WAR file for the manual
./gradlew warManual
# Deploy WAR to Tomcat
./gradlew deployManualEn
# Generate PDF for the manual
./gradlew pdfManualEn
```
--------------------------------
### DataGrid Generated Column Declarative Example (Java)
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/gui_framework/gui_vcl/gui_components/gui_DataGrid.adoc
Illustrates how to add a generated column to a DataGrid declaratively using the @Install annotation in a screen controller. The ColumnGeneratorEvent provides context about the entity and column being displayed.
```java
include::{sourcesdir}/gui_vcl/datagrid_columnGenerator.java[]
```
--------------------------------
### Replace PivotSampleScreen Controller Content with Java Code
Source: https://github.com/cuba-platform/documentation/blob/master/content/charts/adoc/en/pivotTable/pivotTable_examples/pivotTable_examples_data/pt_screen_controller.adoc
This snippet replaces the existing content of the PivotSampleScreen controller with new Java code. The 'onInit' method is specifically designed to populate the 'tipsDc' data container with data. Ensure the 'sourcesdir' variable is correctly set in your project configuration.
```java
package com.company.sample.web.screens.pivot;
import com.haulmont.cuba.gui.components.Screen;
import com.haulmont.cuba.gui.model.InstanceContainer;
import com.haulmont.cuba.gui.screen.*;
import com.company.sample.entity.Tip;
import javax.inject.Inject;
@UiController("pivotSampleScreen")
@UiDescriptor("pivotSampleScreen.xml")
public class PivotSampleScreen extends Screen {
@Inject
private InstanceContainer tipsDc;
@Subscribe
public void onInit(InitEvent event) {
// Populate tipsDc with data
// Example:
Tip tip1 = new Tip();
tip1.setName("Tip 1");
tip1.setDescription("Description for Tip 1");
tipsDc.setItem(tip1);
}
}
```
--------------------------------
### Monitor Heroku Application Logs
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/deployment/deployment_variants/heroku_deployment/heroku_github_deployment.adoc
This command allows you to monitor the real-time logs of your Heroku application. It's essential for debugging and understanding application behavior. Ensure you have the Heroku CLI installed and are logged in to your Heroku account.
```plain
heroku logs --tail --app space-sheep-02453
```
--------------------------------
### Start Jetty Server with Deployment Modules
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/deployment/deployment_variants/war_deployment.adoc
This command initializes the Jetty base directory, adding essential modules for deployment, JNDI, and other functionalities required for the CUBA application.
```bash
java -jar c:\work\jetty-home\start.jar --add-to-start=http,jndi,deploy,plus,ext,resources
```
--------------------------------
### Define Timer in XML and Control via Controller Methods
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/gui_framework/gui_facets/gui_Timer.adoc
This example shows how to define a timer in XML and then programmatically start and stop it from the Java screen controller. It also includes event listeners for timer actions and stop events.
```xml
...
```
```java
// timer_4.java
import com.haulmont.cuba.gui.components.Timer;
import com.haulmont.cuba.gui.screen.Screen;
import com.haulmont.cuba.gui.screen.Subscribe;
import com.haulmont.cuba.gui.screen.UiController;
import com.haulmont.cuba.gui.screen.UiDescriptor;
import javax.inject.Inject;
@UiController("ControllableTimerScreen")
@UiDescriptor("controllable-timer-screen.xml")
public class ControllableTimerScreen extends Screen {
@Inject
private Timer controllableTimer;
@Subscribe
private void onInit(InitEvent event) {
// Start the timer manually
controllableTimer.start();
}
@Subscribe("controllableTimer")
private void onControllableTimerTimerAction(Timer.TimerActionEvent event) {
// Timer execution handler
System.out.println("Controllable timer ticked!");
}
@Subscribe("controllableTimer")
private void onControllableTimerTimerStop(Timer.TimerStopEvent event) {
// Timer stop event
System.out.println("Controllable timer stopped.");
}
// Method to stop the timer, could be called by a button click etc.
public void stopTimer() {
controllableTimer.stop();
}
}
```
--------------------------------
### Configure uberJar Dependencies in Groovy Build File
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/development/build_scripts/build.gradle_tasks/build.gradle_buildUberJar.adoc
This code snippet demonstrates how to add a dependency to the uberJar configuration in a Groovy build file. This ensures the specified library is loaded before the application starts. The example adds the `logstash-logback-encoder` dependency.
```groovy
buildscript {
//build script definitions
}
dependencies {
//app components definitions
uberJar ('net.logstash.logback:logstash-logback-encoder:6.3')
}
//modules and task definitions, etc.
```
--------------------------------
### Building CUBA Platform Documentation with Gradle
Source: https://context7.com/cuba-platform/documentation/llms.txt
This snippet outlines the Gradle commands used to build the CUBA Platform documentation. It includes steps for installing prerequisites like Asciidoctor, setting up Tomcat, and building various documentation formats (single HTML, multi-page HTML, WAR).
```bash
# Install prerequisites
gem install asciidoctor -v 1.5.2
gem install coderay
gem install asciidoctor-pdf -v 1.5.2 # Optional, for PDF generation
# Set up local Tomcat server for viewing
./gradlew setupTomcat
# Build single-HTML document
./gradlew buildManualEn # English manual
./gradlew buildManualRu # Russian manual
# Build multi-page (chopped) document
./gradlew chopManualEn
# Build WAR file for deployment
./gradlew warManualEn
# Deploy to local Tomcat
./gradlew deployManualEn
# Start Tomcat server
./deploy/tomcat/bin/startup.sh
# Access at: http://localhost:6080/manual-7.2
```
--------------------------------
### Programmatic Transaction Management Example - Java
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/middleware/transactions/transactions_prog.adoc
Demonstrates basic programmatic transaction management using the createTransaction() method to start, commit, and end a transaction. It also shows how to handle nested transactions by suspending and resuming outer transactions.
```java
Transaction tx = persistence.createTransaction();
try {
// Your code here
// ...
tx.commit();
} catch (Exception e) {
tx.rollback();
throw e;
}
```
--------------------------------
### XML Screen Layout for EBook Editor
Source: https://github.com/cuba-platform/documentation/blob/master/content/workflow/adoc/en/chapter2.adoc
Defines the XML structure for the EBook editor screen, including data sources, layout components like fieldGroup, groupBox, table, and iframe. It configures datasources for EBook entities and attachments, and specifies UI elements for displaying publication, description, process state, actions, and attachments.
```xml
```
--------------------------------
### Start Process Programmatically Without ProcActionsFragment
Source: https://github.com/cuba-platform/documentation/blob/master/content/bpm/adoc/en/examples/task_execution_sample.adoc
Shows how to initiate a new process instance programmatically without relying on the ProcActionsFragment, providing a direct method for process startup.
```java
/**
* Demonstrates starting a new process instance programmatically without the ProcActionsFragment.
*/
public void onStartProcessProgrammaticallyBtnClick() {
// Assuming 'proc' is an instance of Process object
// Assuming 'dataManager' is an instance of DataManager
// Assuming 'processStarted' is a method to handle post-start logic
proc = dataManager.create(Process.class);
proc.setCaption("Programmatic process");
// Set other process properties as needed
dataManager.save(proc);
// Start the process instance
processStarted(proc.getId());
}
```
--------------------------------
### Groovy Visibility Script for Application Folders
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/features/folders_pane/application_folder.adoc
This Groovy script example defines the visibility of an application folder based on the current user's login. It returns a Boolean value, determining if the folder should be displayed. This is executed at the start of a user session.
```groovy
userSession.currentOrSubstitutedUser.login == 'admin'
```
--------------------------------
### Add Process Actions Dynamically in Java
Source: https://github.com/cuba-platform/documentation/blob/master/content/workflow/adoc/en/chapter2.adoc
This Java snippet demonstrates how to dynamically add process action buttons to a UI component. It checks for specific conditions on an eBook object to determine whether to start a new process or iterate through existing assignment actions. It utilizes a helper method `addProcessAction` to create and configure `Button` components, attaching them to an `actionsBox`.
```java
if (eBook.getJbpmProcessId() == null && eBook.getState() == null) {
addProcessAction(WfConstants.ACTION_START, assignmentInfo);
} else if (assignmentInfo != null) {
for (String actionName : assignmentInfo.getActions()) {
addProcessAction(actionName, assignmentInfo);
}
}
}
private void addProcessAction(String actionName, AssignmentInfo assignmentInfo) {
ProcessAction action = new ProcessAction(getItem(), actionName, assignmentInfo, this);
Button button = componentsFactory.createComponent(Button.NAME);
button.setAction(action);
button.setAlignment(Alignment.MIDDLE_RIGHT);
actionsBox.add(button);
}
```
--------------------------------
### Groovy Quantity Script for Application Folders
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/features/folders_pane/application_folder.adoc
This Groovy script example calculates the record count for an application folder and optionally sets a display style. It retrieves an entity count and can set a 'style' variable for visual emphasis. This script is executed at the start of a user session and on a timer.
```java
def em = persistence.getEntityManager()
def q = em.createQuery('select count(o) from sales_Order o')
def count = q.getSingleResult()
style = count > 0 ? 'emphasized' : null
return count
```
--------------------------------
### Example Configuration Interface in Java
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/common_components/app_properties/config_interfaces/config_interface_usage.adoc
This Java code demonstrates the structure of a configuration interface using CUBA Platform's annotations. It shows how to define property sources using @Source and property names using @Property, along with getter methods for accessing configuration values.
```java
package com.company.sample.core;
import com.haulmont.cuba.core.config.Config;
import com.haulmont.cuba.core.config.Property;
import com.haulmont.cuba.core.config.Source;
import com.haulmont.cuba.core.config.SourceType;
@Source(type = SourceType.APP)
public interface AppPropertiesConfig extends Config {
@Property("mail.smtp.host")
String getSmtpHost();
@Property("mail.smtp.port")
Integer getSmtpPort();
@Source(type = SourceType.SYSTEM)
@Property("user.timezone")
String getUserTimezone();
@Source(type = SourceType.DATABASE)
@Property("custom.db.property")
String getCustomDbProperty();
@Source(type = SourceType.DATABASE)
@Property("secret.db.property")
// @Secret // Uncomment to mask the property in the UI
String getSecretDbProperty();
}
```
--------------------------------
### Fetch Data using Fetch API in Polymer Element (JavaScript)
Source: https://github.com/cuba-platform/documentation/blob/master/polymer-build/src/recipes/ajax/fetch-example.html
This snippet illustrates using the `fetch` API to perform a GET request to a specified URL. It handles the promise returned by `fetch`, checks the response status, and parses the JSON response. It's designed to be used within a Polymer custom element.
```javascript
class FetchExample extends Polymer.Element {
static get is() { return 'fetch-example'; }
connectedCallback() {
super.connectedCallback();
fetch('http://www.there-could-be-your-url.com/some-important-resource', {
method: 'GET',
headers: {
accept: 'application/json'
}
})
// 'fetch' returns a promise
.then(function(response) {
if (response.status !== 200) {
// Do something there if a error response came from the server
}
// 'json()' returns a promise
return response.json();
})
.then(function(jsonObject) {
// Do something there with the response.
});
}
}
customElements.define(FetchExample.is, FetchExample);
```
--------------------------------
### Showing a Screen Configured with ScreenFacet
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/gui_framework/gui_facets/gui_ScreenFacet.adoc
Demonstrates how to explicitly show a screen that has been configured using the ScreenFacet component.
```APIDOC
## Showing a Screen Configured with ScreenFacet
### Description
This section illustrates how to programmatically invoke the `show()` method on a `ScreenFacet` instance to display the configured screen.
### Method
`show()`
### Endpoint
None (Java method invocation)
### Parameters
None
### Request Example
```java
ScreenFacet screenFacet = uiComponents.create(ScreenFacet.class);
// ... configure screenFacet properties like screenId, openMode etc.
screenFacet.show();
```
### Response
None (Screen is displayed)
### Error Handling
Errors may occur if the `screenId` is invalid or if there are issues with screen opening parameters.
```
--------------------------------
### Replace Pentaho Libraries for Saiku Plugin
Source: https://github.com/cuba-platform/documentation/blob/master/content/bi/adoc/en/setup_pentaho.adoc
This step involves removing specific older JAR files related to CPF and replacing them with newer versions to ensure compatibility of the Saiku plugin with the Pentaho Server. Ensure to use the correct libraries based on your Pentaho version.
```plain
cpf-core-7.1.0.0-12.jar
cpf-pentaho-7.1.0.0-12.jar
cpk-core-7.1.0.0-12.jar
cpk-pentaho5-7.1.0.0-12.jar
```
--------------------------------
### Install Asciidoctor PDF (Ruby)
Source: https://github.com/cuba-platform/documentation/blob/master/README.md
Installs the Asciidoctor PDF extension for generating PDF documents from AsciiDoc files. Requires Ruby to be installed first.
```bash
gem install asciidoctor-pdf -v 1.5.2
```
--------------------------------
### Install Nginx Server
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/deployment/proxy_configuration_tomcat.adoc
Installs the Nginx web server using the apt-get package manager on Ubuntu 18.04. This command fetches and installs Nginx and its dependencies from the default repositories.
```bash
sudo apt-get install nginx
```
--------------------------------
### Basic cuba-app Integration in index.html
Source: https://github.com/cuba-platform/documentation/blob/master/content/polymer/adoc/en/cuba_components/cuba_app.adoc
This HTML snippet demonstrates the fundamental inclusion of the `cuba-app` element within the main application's index.html file. It shows the necessary link to the CUBA initialization script and the placement of the custom `empty-app` tag, which likely bootstraps the `cuba-app` component. This setup is critical for the proper functioning of other CUBA Polymer components.
```html
```
--------------------------------
### Install Apache and mod_jk on Ubuntu
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/deployment/scaling/cluster_webclient/cluster_webclient_lb.adoc
Installs the Apache HTTP Server and the mod_jk module required for load balancing. This command is executed on an Ubuntu 14.04 system.
```bash
$ sudo apt-get install apache2 libapache2-mod-jk
```
--------------------------------
### Java Data Loading Example
Source: https://github.com/cuba-platform/documentation/blob/master/content/charts/adoc/en/chart/chart_example/custom_json.adoc
Demonstrates how to load data for a chart using Java. This snippet illustrates the data structure and population methods relevant to chart data handling in Cuba Platform.
```java
include::{sourcesdir}/chart/custom_json_2.java[]
```
--------------------------------
### JPQL Example
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/gui_framework/gui_vcl/gui_components/gui_Filter.adoc
Example of a JPQL query used within the Filter component, demonstrating joins and WHERE clauses.
```APIDOC
## JPQL Query Example
### Description
This example shows a JPQL query that joins the `sample_Car` entity with its repairs (`cr`) and filters based on the repair description.
### Method
N/A (JPQL is used within the Filter component's configuration)
### Endpoint
N/A
### Parameters
#### Query Parameters
- **`?`** (string) - Required - Placeholder for the description pattern.
### Request Example
```jpql
select c from sample_Car c join c.repairs cr
where (cr.description like ?)
order by c.createTs
```
### Response
#### Success Response (200)
- **`c`** (sample_Car) - The selected car entities.
#### Response Example
(Response depends on the executed query and data)
```
--------------------------------
### Create Downloadable Attachment Link in Java
Source: https://github.com/cuba-platform/documentation/blob/master/content/workflow/adoc/en/chapter2.adoc
This Java code initializes a table column to display attachment file names as clickable links. Clicking a link triggers a file download using the `ExportDisplay` interface. This is achieved by generating a `LinkButton` for each `CardAttachment` and assigning an action that invokes `exportDisplay.show(attachment.getFile())`.
```java
private void initAttachmentsTable() {
attachmentsTable.addGeneratedColumn("file", new Table.ColumnGenerator() {
@Override
public Component generateCell(final CardAttachment attachment) {
LinkButton link = componentsFactory.createComponent(LinkButton.NAME);
link.setCaption(attachment.getFile().getName());
link.setAction(new AbstractAction("") {
@Override
public void actionPerform(Component component) {
exportDisplay.show(attachment.getFile());
}
});
return link;
}
});
}
```
--------------------------------
### Configure Reporting Path for LibreOffice on Windows
Source: https://github.com/cuba-platform/documentation/blob/master/content/reporting/adoc/en/open_office.adoc
This snippet demonstrates setting the 'reporting.office.path' property for LibreOffice installations on Windows systems.
```properties
reporting.office.path = C:/Program Files (x86)/LibreOffice 5/program
```
--------------------------------
### Initialize Card Roles from Process Roles (Java)
Source: https://github.com/cuba-platform/documentation/blob/master/content/workflow/adoc/en/chapter2.adoc
This part of `initProcess` initializes `CardRole` objects based on the `ProcRole` definitions. It iterates through process roles, creates corresponding card roles, assigns users from `DefaultProcActor` objects, and adds them to the EBook's roles.
```java
private void initProcess(final EBook eBook) {
...
eBook.setRoles(new ArrayList());
for (ProcRole procRole : proc.getRoles()) {
if (procRole.getAssignToCreator())
continue;
CardRole cardRole = new CardRole();
cardRole.setCard(eBook);
cardRole.setProcRole(procRole);
List defaultProcActors = procRole.getDefaultProcActors();
if (defaultProcActors.isEmpty())
throw new IllegalStateException("Default actor is not assigned for role " + procRole.getName());
cardRole.setUser(defaultProcActors.get(0).getUser());
eBook.getRoles().add(cardRole);
}
}
```
--------------------------------
### SimpleDataItem Example (Java)
Source: https://github.com/cuba-platform/documentation/blob/master/content/charts/adoc/en/chart/chart_data_binding.adoc
Illustrates the use of SimpleDataItem, which allows data to be taken from any public class instance. This offers flexibility when dealing with custom data objects.
```java
include::{sourcesdir}/chart/SimpleDataItem_example.java[]
```
--------------------------------
### BrowserFrame HTML Integration Example (XML and Java)
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/gui_framework/gui_vcl/gui_components/gui_BrowserFrame.adoc
Demonstrates how to integrate dynamic HTML content into a `BrowserFrame` component. This example shows the XML structure for the component and the Java code for generating and setting the HTML content at runtime.
```xml
include::{sourcesdir}/gui_vcl/gui_browserFrame_12.xml[]
```
```java
include::{sourcesdir}/gui_vcl/gui_browserFrame_13.java[]
```
--------------------------------
### Logback Configuration Example
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/deployment/deployment_variants/tomcat_war_deployment.adoc
This is an example of a `logback.xml` configuration snippet. It sets the log directory relative to the application home.
```xml
```
--------------------------------
### Nested Transaction Data Read/Modify Java Example (Dependent)
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/middleware/transactions/transactions_interaction.adoc
Illustrates reading and modifying data within a dependent nested transaction created using getTransaction(). This example demonstrates that modifications within the nested transaction are visible to the outer transaction because they share the same persistent context.
```java
include::{sourcesdir}/middleware/transactions_4.java[]
```
--------------------------------
### Nested Transaction Data Read/Modify Java Example (Independent)
Source: https://github.com/cuba-platform/documentation/blob/master/content/manual/adoc/en/framework/middleware/transactions/transactions_interaction.adoc
Shows how reading and modifying data behaves in an independent nested transaction created with createTransaction(). This example highlights that changes within this type of nested transaction do not affect the outer transaction's context until explicitly committed.
```java
include::{sourcesdir}/middleware/transactions_5.java[]
```