diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ddd07d --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.gradle +*.ipr +*.iml +*.iws +build/* +modules/*/build/* +out +test-run \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..53349c2 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Screen Manipulation + +This project demonstrates how to programmatically manipulate screens in [CUBA](https://www.cuba-platform.com) applications. + +* `CustomerEdit` screen controller defines dialog options in its `init()` method. + +* `CustomerList` is a controller of the simple screen that contains a drop-down list of customers. + +* `OrderEdit` screen controller demonstrates two ways of looking up an entity: from a lookup screen and from an arbitrary screen. + +Based on CUBA Platform 6.1.1 \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..d4f114b --- /dev/null +++ b/build.gradle @@ -0,0 +1,223 @@ + +buildscript { + ext.cubaVersion = '6.1.1' + repositories { + maven { + url 'https://repo.cuba-platform.com/content/groups/work' + credentials { + username(rootProject.hasProperty('repoUser') ? rootProject['repoUser'] : 'cuba') + password(rootProject.hasProperty('repoPass') ? rootProject['repoPass'] : 'cuba123') + } + } + + } + dependencies { + classpath "com.haulmont.gradle:cuba-plugin:$cubaVersion" + } +} + +def globalModule = project(':app-global') +def coreModule = project(':app-core') +def guiModule = project(':app-gui') +def webModule = project(':app-web') + +def servletApi = 'org.apache.tomcat:tomcat-servlet-api:8.0.26' + + +apply(plugin: 'idea') +apply(plugin: 'cuba') + +cuba { + artifact { + group = 'com.company.sample' + version = '0.1' + isSnapshot = true + } + tomcat { + dir = "$project.rootDir/build/tomcat" + } + ide { + copyright = '''Copyright (c) ${today.year} ${project.name}''' // Copyright Notice for IDEA project + classComment ='''/** + * @author ${USER} + */''' + vcs = 'Git' + + } +} + +def hsql = 'org.hsqldb:hsqldb:2.2.9' + +configure([globalModule, coreModule, guiModule, webModule]) { + apply(plugin: 'java') + apply(plugin: 'maven') + apply(plugin: 'idea') + apply(plugin: 'cuba') + + dependencies { + testCompile('junit:junit:4.12') + } + + task sourceJar(type: Jar) { + from file('src') + classifier = 'sources' + } + + artifacts { + archives sourceJar + } +} + +configure(globalModule) { + dependencies { + compile("com.haulmont.cuba:cuba-global:$cubaVersion") + + } + + task enhance(type: CubaEnhancing) + +} + +configure(coreModule) { + + configurations { + jdbc + dbscripts + } + + dependencies { + compile(globalModule) + provided(servletApi) + jdbc(hsql) + testRuntime(hsql) + compile("com.haulmont.cuba:cuba-core:$cubaVersion") + testCompile("com.haulmont.cuba:cuba-core-tests:$cubaVersion") + testCompile("com.haulmont.cuba:cuba-shared-lib:$cubaVersion") + dbscripts("com.haulmont.cuba:cuba-core:$cubaVersion:db@zip") + + } + + task cleanConf(description: 'Cleans up conf directory') << { + def dir = new File(cuba.tomcat.dir, '/conf/app-core') + if (dir.isDirectory()) { + ant.delete(includeemptydirs: true) { + fileset(dir: dir, includes: '**/*', excludes: 'local.app.properties') + } + } + } + + task deploy(dependsOn: [assemble, cleanConf], type: CubaDeployment) { + appName = 'app-core' + appJars('cuba-core', 'cuba-global', + 'app-global', 'app-core') + } + + task createDb(dependsOn: assembleDbScripts, description: 'Creates local database', type: CubaDbCreation) { + dbms = 'hsql' + dbmsVersion = 'null' + host = 'localhost' + dbName = 'sample' + dbUser = 'sa' + dbPassword = '' + } + + task updateDb(dependsOn: assembleDbScripts, description: 'Updates local database', type: CubaDbUpdate) { + dbms = 'hsql' + dbmsVersion = 'null' + host = 'localhost' + dbName = 'sample' + dbUser = 'sa' + dbPassword = '' + } +} + +configure(guiModule) { + dependencies { + compile(globalModule) + compile("com.haulmont.cuba:cuba-gui:$cubaVersion") + testCompile("com.haulmont.cuba:cuba-client-tests:$cubaVersion") + + } + + task deployConf(type: Copy) { + from file('src') + include "com/company/sample/**" + into "$cuba.tomcat.dir/conf/app" + } +} + +configure(webModule) { + configurations { + webcontent + + } + + dependencies { + provided(servletApi) + compile(guiModule) + compile("com.haulmont.cuba:cuba-web:$cubaVersion") + webcontent("com.haulmont.cuba:cuba-web:$cubaVersion:web@zip") + webcontent("com.haulmont.cuba:cuba-web-toolkit:$cubaVersion:web@zip") + testCompile("com.haulmont.cuba:cuba-client-tests:$cubaVersion") + + } + + task webArchive(type: Zip) { + from file('web') + classifier = 'web' + } + + artifacts { + archives webArchive + } + + task deployConf(type: Copy) { + from file('src') + include "com/company/sample/**" + into "$cuba.tomcat.dir/conf/app" + } + + task clearMessagesCache(type: CubaClearMessagesCache) { + appName = 'app' + } + deployConf.dependsOn clearMessagesCache + + task cleanConf(description: 'Cleans up conf directory') << { + def dir = new File(cuba.tomcat.dir, '/conf/app') + if (dir.isDirectory()) { + ant.delete(includeemptydirs: true) { + fileset(dir: dir, includes: '**/*', excludes: 'local.app.properties') + } + } + } + + task deploy(dependsOn: [assemble, cleanConf], type: CubaDeployment) { + appName = 'app' + appJars('cuba-client', 'cuba-gui', 'cuba-rest-api', 'cuba-web', 'cuba-global', + 'app-global', 'app-gui', 'app-web') + } +} + + + + +task undeploy(type: Delete, dependsOn: ':app-web:cleanConf') { + delete("$cuba.tomcat.dir/shared") + delete("$cuba.tomcat.dir/webapps/app-core") + delete("$cuba.tomcat.dir/webapps/app") +} + +task restart(dependsOn: ['stop', ':app-core:deploy', ':app-web:deploy'], description: 'Redeploys applications and restarts local Tomcat') << { + ant.waitfor(maxwait: 6, maxwaitunit: 'second', checkevery: 2, checkeveryunit: 'second') { + not { + socket(server: 'localhost', port: '8787') + } + } + start.execute() +} + +task wrapper(type: Wrapper) { + gradleVersion = '2.6' +} + +apply from: 'extra.gradle' diff --git a/extra.gradle b/extra.gradle new file mode 100644 index 0000000..e69de29 diff --git a/modules/core/db/init/hsql/10.create-db.sql b/modules/core/db/init/hsql/10.create-db.sql new file mode 100644 index 0000000..71384ed --- /dev/null +++ b/modules/core/db/init/hsql/10.create-db.sql @@ -0,0 +1,35 @@ +-- begin SAMPLE_CUSTOMER +create table SAMPLE_CUSTOMER ( + ID varchar(36) not null, + CREATE_TS timestamp, + CREATED_BY varchar(50), + VERSION integer not null, + UPDATE_TS timestamp, + UPDATED_BY varchar(50), + DELETE_TS timestamp, + DELETED_BY varchar(50), + -- + NAME varchar(255), + EMAIL varchar(100), + -- + primary key (ID) +)^ +-- end SAMPLE_CUSTOMER +-- begin SAMPLE_ORDER +create table SAMPLE_ORDER ( + ID varchar(36) not null, + CREATE_TS timestamp, + CREATED_BY varchar(50), + VERSION integer not null, + UPDATE_TS timestamp, + UPDATED_BY varchar(50), + DELETE_TS timestamp, + DELETED_BY varchar(50), + -- + DATE_ date, + NUM varchar(100), + CUSTOMER_ID varchar(36), + -- + primary key (ID) +)^ +-- end SAMPLE_ORDER diff --git a/modules/core/db/init/hsql/20.create-db.sql b/modules/core/db/init/hsql/20.create-db.sql new file mode 100644 index 0000000..9e17ba2 --- /dev/null +++ b/modules/core/db/init/hsql/20.create-db.sql @@ -0,0 +1,4 @@ +-- begin SAMPLE_ORDER +alter table SAMPLE_ORDER add constraint FK_SAMPLE_ORDER_CUSTOMER_ID foreign key (CUSTOMER_ID) references SAMPLE_CUSTOMER(ID)^ +create index IDX_SAMPLE_ORDER_CUSTOMER on SAMPLE_ORDER (CUSTOMER_ID)^ +-- end SAMPLE_ORDER diff --git a/modules/core/db/init/hsql/30.create-db.sql b/modules/core/db/init/hsql/30.create-db.sql new file mode 100644 index 0000000..eadc258 --- /dev/null +++ b/modules/core/db/init/hsql/30.create-db.sql @@ -0,0 +1,11 @@ +insert into SAMPLE_CUSTOMER +(ID, CREATE_TS, CREATED_BY, VERSION, UPDATE_TS, UPDATED_BY, DELETE_TS, DELETED_BY, NAME, EMAIL) +values ('405d5d7d-ed85-10e5-5e45-eeea2e574d18', '2016-04-11 09:34:55', 'admin', 1, '2016-04-11 09:34:55', null, null, null, 'Globex Corporation', 'info@globex.com'); + +insert into SAMPLE_CUSTOMER +(ID, CREATE_TS, CREATED_BY, VERSION, UPDATE_TS, UPDATED_BY, DELETE_TS, DELETED_BY, NAME, EMAIL) +values ('d43d25fd-563e-0eb7-0766-0c01c27aae19', '2016-04-11 09:35:13', 'admin', 1, '2016-04-11 09:35:13', null, null, null, 'Sirius Cybernetics Corporation', 'info@sirius.com'); + +insert into SAMPLE_CUSTOMER +(ID, CREATE_TS, CREATED_BY, VERSION, UPDATE_TS, UPDATED_BY, DELETE_TS, DELETED_BY, NAME, EMAIL) +values ('b01cfb8c-4797-6767-96cc-0b186e18de55', '2016-04-11 09:35:33', 'admin', 1, '2016-04-11 09:35:33', null, null, null, 'Initech', 'info@initech.com'); diff --git a/modules/core/src/app.properties b/modules/core/src/app.properties new file mode 100644 index 0000000..853f359 --- /dev/null +++ b/modules/core/src/app.properties @@ -0,0 +1,23 @@ +############################################################################### +# Configuration # +############################################################################### + +cuba.dbmsType = hsql + +cuba.springContextConfig = cuba-spring.xml spring.xml + +cuba.persistenceConfig = cuba-persistence.xml persistence.xml + +cuba.metadataConfig = cuba-metadata.xml metadata.xml + +cuba.viewsConfig = cuba-views.xml views.xml + +cuba.mainMessagePack = com.haulmont.cuba.core com.company.sample.core + +############################################################################### +# Other # +############################################################################### + +cuba.webContextName = app-core +cuba.availableLocales = English|en +cuba.localeSelectVisible = false diff --git a/modules/core/src/com/company/sample/core/messages.properties b/modules/core/src/com/company/sample/core/messages.properties new file mode 100644 index 0000000..e69de29 diff --git a/modules/core/src/spring.xml b/modules/core/src/spring.xml new file mode 100644 index 0000000..e9bd820 --- /dev/null +++ b/modules/core/src/spring.xml @@ -0,0 +1,15 @@ + + + + + + + diff --git a/modules/core/web/META-INF/context.xml b/modules/core/web/META-INF/context.xml new file mode 100644 index 0000000..87487a2 --- /dev/null +++ b/modules/core/web/META-INF/context.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/modules/core/web/WEB-INF/web.xml b/modules/core/web/WEB-INF/web.xml new file mode 100644 index 0000000..a15b061 --- /dev/null +++ b/modules/core/web/WEB-INF/web.xml @@ -0,0 +1,34 @@ + + + + + + appPropertiesConfig + + classpath:cuba-app.properties + classpath:app.properties + /WEB-INF/local.app.properties + "file:${catalina.home}/conf/app-core/local.app.properties" + + + + + com.haulmont.cuba.core.sys.AppContextLoader + + + + remoting + com.haulmont.cuba.core.sys.remoting.RemotingServlet + 1 + + + + remoting + /remoting/* + + + diff --git a/modules/global/src/com/company/sample/entity/Customer.java b/modules/global/src/com/company/sample/entity/Customer.java new file mode 100644 index 0000000..9adb2ef --- /dev/null +++ b/modules/global/src/com/company/sample/entity/Customer.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 screen-manipulation + */ +package com.company.sample.entity; + +import javax.persistence.Entity; +import javax.persistence.Table; +import javax.persistence.Column; +import com.haulmont.cuba.core.entity.StandardEntity; +import com.haulmont.chile.core.annotations.NamePattern; + +/** + * @author knst + */ +@NamePattern("%s|name") +@Table(name = "SAMPLE_CUSTOMER") +@Entity(name = "sample$Customer") +public class Customer extends StandardEntity { + private static final long serialVersionUID = 738326219647053638L; + + @Column(name = "NAME") + protected String name; + + @Column(name = "EMAIL", length = 100) + protected String email; + + public void setEmail(String email) { + this.email = email; + } + + public String getEmail() { + return email; + } + + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + +} \ No newline at end of file diff --git a/modules/global/src/com/company/sample/entity/Order.java b/modules/global/src/com/company/sample/entity/Order.java new file mode 100644 index 0000000..4ed66b4 --- /dev/null +++ b/modules/global/src/com/company/sample/entity/Order.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016 screen-manipulation + */ +package com.company.sample.entity; + +import javax.persistence.Entity; +import javax.persistence.Table; +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import com.haulmont.cuba.core.entity.StandardEntity; + +/** + * @author knst + */ +@Table(name = "SAMPLE_ORDER") +@Entity(name = "sample$Order") +public class Order extends StandardEntity { + private static final long serialVersionUID = -3292919444177021479L; + + @Temporal(TemporalType.DATE) + @Column(name = "DATE_") + protected Date date; + + @Column(name = "NUM", length = 100) + protected String num; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "CUSTOMER_ID") + protected Customer customer; + + public void setDate(Date date) { + this.date = date; + } + + public Date getDate() { + return date; + } + + public void setNum(String num) { + this.num = num; + } + + public String getNum() { + return num; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + + public Customer getCustomer() { + return customer; + } + + +} \ No newline at end of file diff --git a/modules/global/src/com/company/sample/entity/messages.properties b/modules/global/src/com/company/sample/entity/messages.properties new file mode 100644 index 0000000..8c6845b --- /dev/null +++ b/modules/global/src/com/company/sample/entity/messages.properties @@ -0,0 +1,7 @@ +Customer.name = Name +Customer = Customer +Customer.email = Email +Order.customer = Customer +Order.date = Date +Order.num = Num +Order = Order diff --git a/modules/global/src/metadata.xml b/modules/global/src/metadata.xml new file mode 100644 index 0000000..3450166 --- /dev/null +++ b/modules/global/src/metadata.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/modules/global/src/persistence.xml b/modules/global/src/persistence.xml new file mode 100644 index 0000000..cb3a569 --- /dev/null +++ b/modules/global/src/persistence.xml @@ -0,0 +1,9 @@ + + + + com.company.sample.entity.Customer + com.company.sample.entity.Order + + diff --git a/modules/global/src/views.xml b/modules/global/src/views.xml new file mode 100644 index 0000000..eb399a2 --- /dev/null +++ b/modules/global/src/views.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/modules/gui/src/com/company/sample/gui/messages.properties b/modules/gui/src/com/company/sample/gui/messages.properties new file mode 100644 index 0000000..df53089 --- /dev/null +++ b/modules/gui/src/com/company/sample/gui/messages.properties @@ -0,0 +1,7 @@ + +application.caption = CUBA Application +application.logoImage = branding/app-icon-menu.png + +loginWindow.caption = CUBA Login +loginWindow.welcomeLabel = Welcome to CUBA! +loginWindow.logoImage = branding/app-icon-login.png diff --git a/modules/gui/src/screens.xml b/modules/gui/src/screens.xml new file mode 100644 index 0000000..22e5cdb --- /dev/null +++ b/modules/gui/src/screens.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/modules/web/src/com/company/sample/web/App.java b/modules/web/src/com/company/sample/web/App.java new file mode 100644 index 0000000..c5e17a2 --- /dev/null +++ b/modules/web/src/com/company/sample/web/App.java @@ -0,0 +1,6 @@ +package com.company.sample.web; + +import com.haulmont.cuba.web.DefaultApp; + +public class App extends DefaultApp { +} \ No newline at end of file diff --git a/modules/web/src/com/company/sample/web/customer/CustomerBrowse.java b/modules/web/src/com/company/sample/web/customer/CustomerBrowse.java new file mode 100644 index 0000000..e54c024 --- /dev/null +++ b/modules/web/src/com/company/sample/web/customer/CustomerBrowse.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2016 screen-manipulation + */ +package com.company.sample.web.customer; + +import com.haulmont.cuba.gui.components.AbstractLookup; + +/** + * @author knst + */ +public class CustomerBrowse extends AbstractLookup { +} \ No newline at end of file diff --git a/modules/web/src/com/company/sample/web/customer/CustomerEdit.java b/modules/web/src/com/company/sample/web/customer/CustomerEdit.java new file mode 100644 index 0000000..79dd08c --- /dev/null +++ b/modules/web/src/com/company/sample/web/customer/CustomerEdit.java @@ -0,0 +1,17 @@ +package com.company.sample.web.customer; + +import com.haulmont.cuba.gui.components.AbstractEditor; +import com.company.sample.entity.Customer; + +import java.util.Map; + +public class CustomerEdit extends AbstractEditor { + + @Override + public void init(Map params) { + // The same can be done using the element in the XML descriptor + getDialogOptions() + .setWidth(300) // fixed width + .setForceDialog(true); // always open as a dialog + } +} \ No newline at end of file diff --git a/modules/web/src/com/company/sample/web/customer/CustomerList.java b/modules/web/src/com/company/sample/web/customer/CustomerList.java new file mode 100644 index 0000000..a053dfd --- /dev/null +++ b/modules/web/src/com/company/sample/web/customer/CustomerList.java @@ -0,0 +1,34 @@ +package com.company.sample.web.customer; + +import com.company.sample.entity.Customer; +import com.haulmont.cuba.gui.components.AbstractWindow; +import com.haulmont.cuba.gui.components.Component; +import com.haulmont.cuba.gui.components.Window; +import com.haulmont.cuba.gui.data.CollectionDatasource; + +import javax.inject.Inject; +import java.util.Map; +import java.util.UUID; + +public class CustomerList extends AbstractWindow { + + @Inject + protected CollectionDatasource customersDs; + + @Override + public void init(Map params) { + customersDs.refresh(); + } + + public void select(Component source) { + close(Window.COMMIT_ACTION_ID); + } + + public void cancel(Component source) { + close(Window.CLOSE_ACTION_ID); + } + + public Customer getSelectedCustomer() { + return customersDs.getItem(); + } +} \ No newline at end of file diff --git a/modules/web/src/com/company/sample/web/customer/customer-browse.xml b/modules/web/src/com/company/sample/web/customer/customer-browse.xml new file mode 100644 index 0000000..2593931 --- /dev/null +++ b/modules/web/src/com/company/sample/web/customer/customer-browse.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
diff --git a/modules/web/src/com/company/sample/web/customer/customer-edit.xml b/modules/web/src/com/company/sample/web/customer/customer-edit.xml new file mode 100644 index 0000000..bc40598 --- /dev/null +++ b/modules/web/src/com/company/sample/web/customer/customer-edit.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + diff --git a/modules/web/src/com/company/sample/web/customer/customer-list.xml b/modules/web/src/com/company/sample/web/customer/customer-list.xml new file mode 100644 index 0000000..37c1481 --- /dev/null +++ b/modules/web/src/com/company/sample/web/customer/customer-list.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + +