### 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