1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/mywork-model/pom.xml Wed Nov 23 17:52:25 2011 +0300
1.3 @@ -0,0 +1,104 @@
1.4 +<?xml version="1.0" encoding="UTF-8"?>
1.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1.6 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
1.7 + <modelVersion>4.0.0</modelVersion>
1.8 + <groupId>ru.indvdum.mywork</groupId>
1.9 + <artifactId>mywork-model</artifactId>
1.10 + <name>mywork-model</name>
1.11 + <packaging>jar</packaging>
1.12 + <description>mywork-model</description>
1.13 + <parent>
1.14 + <groupId>ru.indvdum.mywork</groupId>
1.15 + <artifactId>mywork-all</artifactId>
1.16 + <version>0.0.1.0-SNAPSHOT</version>
1.17 + </parent>
1.18 + <build>
1.19 + <plugins>
1.20 + <plugin>
1.21 + <artifactId>maven-compiler-plugin</artifactId>
1.22 + <version>${maven-compiler-plugin.version}</version>
1.23 + <configuration>
1.24 + <compilerId>groovy-eclipse-compiler</compilerId>
1.25 + <compilerArgument>nowarn</compilerArgument>
1.26 + <verbose>true</verbose>
1.27 + </configuration>
1.28 + <dependencies>
1.29 + <dependency>
1.30 + <groupId>org.codehaus.groovy</groupId>
1.31 + <artifactId>groovy-eclipse-compiler</artifactId>
1.32 + <version>${groovy-eclipse-compiler.version}</version>
1.33 + </dependency>
1.34 + </dependencies>
1.35 + </plugin>
1.36 + <plugin>
1.37 + <groupId>org.codehaus.mojo</groupId>
1.38 + <artifactId>build-helper-maven-plugin</artifactId>
1.39 + <version>${build-helper-maven-plugin.version}</version>
1.40 + <executions>
1.41 + <execution>
1.42 + <id>add-source</id>
1.43 + <phase>generate-sources</phase>
1.44 + <goals>
1.45 + <goal>add-source</goal>
1.46 + </goals>
1.47 + <configuration>
1.48 + <sources>
1.49 + <source>src/main/groovy</source>
1.50 + <source>src/test/groovy</source>
1.51 + </sources>
1.52 + </configuration>
1.53 + </execution>
1.54 + </executions>
1.55 + </plugin>
1.56 + <plugin>
1.57 + <groupId>org.codehaus.mojo</groupId>
1.58 + <artifactId>openjpa-maven-plugin</artifactId>
1.59 + <configuration>
1.60 + <includes>**/model/**/*.class</includes>
1.61 + <addDefaultConstructor>true</addDefaultConstructor>
1.62 + <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
1.63 + </configuration>
1.64 + <executions>
1.65 + <execution>
1.66 + <id>enhancer</id>
1.67 + <phase>process-classes</phase>
1.68 + <goals>
1.69 + <goal>enhance</goal>
1.70 + </goals>
1.71 + </execution>
1.72 + </executions>
1.73 + <dependencies>
1.74 + <dependency>
1.75 + <groupId>org.apache.openjpa</groupId>
1.76 + <artifactId>openjpa</artifactId>
1.77 + <version>${openjpa.version}</version>
1.78 + </dependency>
1.79 + </dependencies>
1.80 + </plugin>
1.81 + </plugins>
1.82 + </build>
1.83 + <dependencies>
1.84 + <dependency>
1.85 + <groupId>org.codehaus.groovy</groupId>
1.86 + <artifactId>groovy-all</artifactId>
1.87 + <version>${groovy.version}</version>
1.88 + </dependency>
1.89 + <dependency>
1.90 + <groupId>org.apache.openjpa</groupId>
1.91 + <artifactId>openjpa</artifactId>
1.92 + <version>${openjpa.version}</version>
1.93 + </dependency>
1.94 + <dependency>
1.95 + <groupId>commons-dbcp</groupId>
1.96 + <artifactId>commons-dbcp</artifactId>
1.97 + <version>${commons-dbcp.version}</version>
1.98 + <scope>test</scope>
1.99 + </dependency>
1.100 + <dependency>
1.101 + <groupId>org.apache.derby</groupId>
1.102 + <artifactId>derby</artifactId>
1.103 + <version>${derby.version}</version>
1.104 + <scope>test</scope>
1.105 + </dependency>
1.106 + </dependencies>
1.107 +</project>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/mywork-model/src/main/resources/META-INF/persistence.xml Wed Nov 23 17:52:25 2011 +0300
2.3 @@ -0,0 +1,18 @@
2.4 +<?xml version="1.0" encoding="UTF-8"?>
2.5 +<persistence xmlns="http://java.sun.com/xml/ns/persistence"
2.6 + version="1.0">
2.7 + <persistence-unit name="mywork-model">
2.8 + <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
2.9 + <non-jta-data-source>jdbc/MyworkDataSource</non-jta-data-source>
2.10 +
2.11 + <properties>
2.12 + <property name="openjpa.jdbc.DBDictionary" value="batchLimit=-1"/>
2.13 + <property name="openjpa.FetchBatchSize" value="0" />
2.14 + <property name="openjpa.Multithreaded" value="true" />
2.15 + <property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)" />
2.16 + <property name="openjpa.jdbc.EagerFetchMode" value="join" />
2.17 + <property name="openjpa.jdbc.SubclassFetchMode" value="parallel" />
2.18 + <property name="openjpa.Log" value="DefaultLevel=INFO, Tool=INFO" />
2.19 + </properties>
2.20 + </persistence-unit>
2.21 +</persistence>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/mywork-model/src/main/resources/jndi.properties Wed Nov 23 17:52:25 2011 +0300
3.3 @@ -0,0 +1,1 @@
3.4 +java.naming.factory.initial=ru.indvdum.logisticssolution.jndi.SimpleContextFactory
3.5 \ No newline at end of file
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/mywork-web/pom.xml Wed Nov 23 17:52:25 2011 +0300
4.3 @@ -0,0 +1,102 @@
4.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.5 + <modelVersion>4.0.0</modelVersion>
4.6 + <groupId>ru.indvdum.mywork</groupId>
4.7 + <artifactId>mywork-web</artifactId>
4.8 + <version>0.0.1.0-SNAPSHOT</version>
4.9 + <description>My Work WEB</description>
4.10 + <parent>
4.11 + <groupId>ru.indvdum.mywork</groupId>
4.12 + <artifactId>mywork-all</artifactId>
4.13 + <version>0.0.1.0-SNAPSHOT</version>
4.14 + </parent>
4.15 + <properties>
4.16 + <jetty.version>6.1.26</jetty.version>
4.17 + <vaadin.version>6.5.0</vaadin.version>
4.18 + <gwt.version>2.1.1</gwt.version>
4.19 + <oracle.jdbc.version>10.1.0.5.0</oracle.jdbc.version>
4.20 + </properties>
4.21 + <build>
4.22 + <plugins>
4.23 + <plugin>
4.24 + <groupId>org.apache.maven.plugins</groupId>
4.25 + <artifactId>maven-resources-plugin</artifactId>
4.26 + <version>${maven-resources-plugin.version}</version>
4.27 + <configuration>
4.28 + <encoding>UTF-8</encoding>
4.29 + </configuration>
4.30 + </plugin>
4.31 + <plugin>
4.32 + <artifactId>maven-source-plugin</artifactId>
4.33 + <configuration>
4.34 + <attach>true</attach>
4.35 + </configuration>
4.36 + <executions>
4.37 + <execution>
4.38 + <phase>generate-sources</phase>
4.39 + <goals>
4.40 + <goal>jar</goal>
4.41 + </goals>
4.42 + </execution>
4.43 + </executions>
4.44 + </plugin>
4.45 + <plugin>
4.46 + <groupId>org.codehaus.mojo</groupId>
4.47 + <artifactId>exec-maven-plugin</artifactId>
4.48 + <version>1.2</version>
4.49 + <executions>
4.50 + <execution>
4.51 + <goals>
4.52 + <goal>exec</goal>
4.53 + </goals>
4.54 + </execution>
4.55 + </executions>
4.56 + <configuration>
4.57 + <executable>java</executable>
4.58 + <arguments>
4.59 + <argument>-classpath</argument>
4.60 + <classpath/>
4.61 + <argument>ru.indvdum.mywork.MyWork</argument>
4.62 + </arguments>
4.63 + </configuration>
4.64 + </plugin>
4.65 + </plugins>
4.66 + </build>
4.67 + <dependencies>
4.68 + <dependency>
4.69 + <groupId>org.mortbay.jetty</groupId>
4.70 + <artifactId>jetty</artifactId>
4.71 + <version>${jetty.version}</version>
4.72 + </dependency>
4.73 + <dependency>
4.74 + <groupId>com.vaadin</groupId>
4.75 + <artifactId>vaadin</artifactId>
4.76 + <version>${vaadin.version}</version>
4.77 + </dependency>
4.78 + <dependency>
4.79 + <groupId>com.vaadin.addon</groupId>
4.80 + <artifactId>jpacontainer-addon-agpl-3.0</artifactId>
4.81 + <version>1.2.0</version>
4.82 + <exclusions>
4.83 + <exclusion>
4.84 + <groupId>javax.persistence</groupId>
4.85 + <artifactId>persistence-api</artifactId>
4.86 + </exclusion>
4.87 + </exclusions>
4.88 + </dependency>
4.89 + <dependency>
4.90 + <groupId>com.google.gwt</groupId>
4.91 + <artifactId>gwt-user</artifactId>
4.92 + <version>${gwt.version}</version>
4.93 + </dependency>
4.94 + <!--dependency>
4.95 + <groupId>com.oracle</groupId>
4.96 + <artifactId>ojdbc14</artifactId>
4.97 + <version>${oracle.jdbc.version}</version>
4.98 + </dependency-->
4.99 + <dependency>
4.100 + <groupId>org.apache.openjpa</groupId>
4.101 + <artifactId>openjpa</artifactId>
4.102 + <version>${openjpa.version}</version>
4.103 + </dependency>
4.104 + </dependencies>
4.105 +</project>
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/mywork-web/src/main/java/ru/indvdum/mywork/MyWork.java Wed Nov 23 17:52:25 2011 +0300
5.3 @@ -0,0 +1,78 @@
5.4 +package ru.indvdum.mywork;
5.5 +
5.6 +import java.util.Date;
5.7 +
5.8 +import javax.persistence.EntityManager;
5.9 +import javax.persistence.EntityManagerFactory;
5.10 +import javax.persistence.Persistence;
5.11 +
5.12 +import org.mortbay.component.LifeCycle;
5.13 +import org.mortbay.component.LifeCycle.Listener;
5.14 +import org.mortbay.jetty.Connector;
5.15 +import org.mortbay.jetty.Server;
5.16 +import org.mortbay.jetty.servlet.Context;
5.17 +import org.mortbay.jetty.servlet.ServletHolder;
5.18 +
5.19 +import com.vaadin.terminal.gwt.server.ApplicationServlet;
5.20 +
5.21 +/**
5.22 + * @author indvdum
5.23 + * 12.08.2011 17:31:37
5.24 + *
5.25 + */
5.26 +public class MyWork {
5.27 + public static EntityManagerFactory EMF = null;
5.28 + public static EntityManager EM = null;
5.29 +
5.30 + /**
5.31 + * @param args
5.32 + * @throws Exception
5.33 + */
5.34 + public static void main(String[] args) throws Exception {
5.35 + Server server = new Server();
5.36 + Connector connector = new org.mortbay.jetty.nio.SelectChannelConnector();
5.37 + connector.setPort(8080);
5.38 + connector.setMaxIdleTime(720000);
5.39 + server.addConnector(connector);
5.40 +
5.41 + Context root = new Context(server, "/", Context.SESSIONS);
5.42 + ServletHolder vaadinServlet = new ServletHolder(new ApplicationServlet());
5.43 + vaadinServlet.setInitParameter("application", "ru.indvdum.mywork.vaadin.MyWorkApplication");
5.44 + root.addServlet(vaadinServlet, "/*");
5.45 +
5.46 + server.addLifeCycleListener(new Listener(){
5.47 +
5.48 + @Override
5.49 + public void lifeCycleFailure(LifeCycle event, Throwable cause) {
5.50 +
5.51 + }
5.52 +
5.53 + @Override
5.54 + public void lifeCycleStarted(LifeCycle event) {
5.55 + EMF = Persistence.createEntityManagerFactory("mywork");
5.56 + EM = EMF.createEntityManager();
5.57 + }
5.58 +
5.59 + @Override
5.60 + public void lifeCycleStarting(LifeCycle event) {
5.61 +
5.62 + }
5.63 +
5.64 + @Override
5.65 + public void lifeCycleStopped(LifeCycle event) {
5.66 +
5.67 + }
5.68 +
5.69 + @Override
5.70 + public void lifeCycleStopping(LifeCycle event) {
5.71 + EM.close();
5.72 + EMF.close();
5.73 + }
5.74 +
5.75 + });
5.76 +
5.77 + server.start();
5.78 + System.out.println("Jetty server started at " + new Date());
5.79 + }
5.80 +
5.81 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/mywork-web/src/main/java/ru/indvdum/mywork/openjpa/model/Day.java Wed Nov 23 17:52:25 2011 +0300
6.3 @@ -0,0 +1,119 @@
6.4 +package ru.indvdum.mywork.openjpa.model;
6.5 +
6.6 +import java.sql.Time;
6.7 +import java.text.DateFormat;
6.8 +import java.text.SimpleDateFormat;
6.9 +import java.util.Date;
6.10 +
6.11 +import javax.persistence.Column;
6.12 +import javax.persistence.Entity;
6.13 +import javax.persistence.GeneratedValue;
6.14 +import javax.persistence.GenerationType;
6.15 +import javax.persistence.Id;
6.16 +import javax.persistence.Table;
6.17 +
6.18 +/**
6.19 + * @author indvdum
6.20 + * 12.08.2011 17:31:00
6.21 + *
6.22 + */
6.23 +@Entity
6.24 +@Table(name = "DAYS")
6.25 +public class Day implements IDatabaseObject {
6.26 +
6.27 + private static final long serialVersionUID = 1471705339524132968L;
6.28 +
6.29 + @Id
6.30 + @GeneratedValue(strategy = GenerationType.IDENTITY)
6.31 + @Column(name = "ID", nullable = false)
6.32 + private Integer id = null;
6.33 +
6.34 + @Column(name = "DAY")
6.35 + private Date day = null;
6.36 +
6.37 + @Column(name = "STARTWORK")
6.38 + private Time startWork = null;
6.39 +
6.40 + @Column(name = "ENDWORK")
6.41 + private Time endWork = null;
6.42 +
6.43 + @Column(name = "HOURS")
6.44 + private Float hours = null;
6.45 +
6.46 + public Day(){
6.47 +
6.48 + }
6.49 +
6.50 + @Override
6.51 + public boolean equals(Object obj) {
6.52 + if (this == obj)
6.53 + return true;
6.54 + if (obj == null)
6.55 + return false;
6.56 + if (!(obj instanceof Day))
6.57 + return false;
6.58 + final Day other = (Day) obj;
6.59 + return (getId() == other.getId() || (getId() != null && getId().equals(other.getId())));
6.60 + }
6.61 +
6.62 + @Override
6.63 + public int hashCode() {
6.64 + if(getId() != null && getId() != 0)
6.65 + return getId().hashCode();
6.66 + else
6.67 + return super.hashCode();
6.68 + }
6.69 +
6.70 + @Override
6.71 + public String toString() {
6.72 + return getDateFormatter().format(getDay());
6.73 + }
6.74 +
6.75 + public Integer getId() {
6.76 + return id;
6.77 + }
6.78 +
6.79 + public void setId(Integer id) {
6.80 + this.id = id;
6.81 + }
6.82 +
6.83 + public Date getDay() {
6.84 + return day;
6.85 + }
6.86 +
6.87 + public String getFormattedDay() {
6.88 + return toString();
6.89 + }
6.90 +
6.91 + public void setDay(Date day) {
6.92 + this.day = day;
6.93 + }
6.94 +
6.95 + public Time getStartWork() {
6.96 + return startWork;
6.97 + }
6.98 +
6.99 + public void setStartWork(Time startWork) {
6.100 + this.startWork = startWork;
6.101 + }
6.102 +
6.103 + public Time getEndWork() {
6.104 + return endWork;
6.105 + }
6.106 +
6.107 + public void setEndWork(Time endWork) {
6.108 + this.endWork = endWork;
6.109 + }
6.110 +
6.111 + public Float getHours() {
6.112 + return hours;
6.113 + }
6.114 +
6.115 + public void setHours(Float hours) {
6.116 + this.hours = hours;
6.117 + }
6.118 +
6.119 + protected DateFormat getDateFormatter() {
6.120 + return new SimpleDateFormat("dd.MM.yyyy");
6.121 + }
6.122 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/mywork-web/src/main/java/ru/indvdum/mywork/openjpa/model/IDatabaseObject.java Wed Nov 23 17:52:25 2011 +0300
7.3 @@ -0,0 +1,12 @@
7.4 +package ru.indvdum.mywork.openjpa.model;
7.5 +
7.6 +import java.io.Serializable;
7.7 +
7.8 +/**
7.9 + * @author indvdum
7.10 + * 12.08.2011 17:31:11
7.11 + *
7.12 + */
7.13 +public interface IDatabaseObject extends Serializable {
7.14 +
7.15 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/mywork-web/src/main/java/ru/indvdum/mywork/openjpa/model/Task.java Wed Nov 23 17:52:25 2011 +0300
8.3 @@ -0,0 +1,84 @@
8.4 +package ru.indvdum.mywork.openjpa.model;
8.5 +
8.6 +import javax.persistence.Column;
8.7 +import javax.persistence.Entity;
8.8 +import javax.persistence.GeneratedValue;
8.9 +import javax.persistence.GenerationType;
8.10 +import javax.persistence.Id;
8.11 +import javax.persistence.Table;
8.12 +
8.13 +/**
8.14 + * @author indvdum
8.15 + * 16.08.2011 9:02:32
8.16 + *
8.17 + */
8.18 +@Entity
8.19 +@Table(name = "TASKS")
8.20 +public class Task implements IDatabaseObject {
8.21 +
8.22 + private static final long serialVersionUID = -4457948503094306717L;
8.23 +
8.24 + @Id
8.25 + @GeneratedValue(strategy = GenerationType.SEQUENCE)
8.26 + @Column(name = "ID", nullable = false)
8.27 + private Integer id = null;
8.28 +
8.29 + @Column(name = "NAME")
8.30 + private String name = null;
8.31 +
8.32 + @Column(name = "DESCRIPTION")
8.33 + private String description = null;
8.34 +
8.35 + public Task(){
8.36 +
8.37 + }
8.38 +
8.39 + @Override
8.40 + public boolean equals(Object obj) {
8.41 + if (this == obj)
8.42 + return true;
8.43 + if (obj == null)
8.44 + return false;
8.45 + if (!(obj instanceof Task))
8.46 + return false;
8.47 + final Task other = (Task) obj;
8.48 + return (getId() == other.getId() || (getId() != null && getId().equals(other.getId())));
8.49 + }
8.50 +
8.51 + @Override
8.52 + public int hashCode() {
8.53 + if(getId() != null && getId() != 0)
8.54 + return getId().hashCode();
8.55 + else
8.56 + return super.hashCode();
8.57 + }
8.58 +
8.59 + @Override
8.60 + public String toString() {
8.61 + return getName();
8.62 + }
8.63 +
8.64 + public Integer getId() {
8.65 + return id;
8.66 + }
8.67 +
8.68 + public void setId(Integer id) {
8.69 + this.id = id;
8.70 + }
8.71 +
8.72 + public String getName() {
8.73 + return name != null ? name : "";
8.74 + }
8.75 +
8.76 + public void setName(String name) {
8.77 + this.name = name;
8.78 + }
8.79 +
8.80 + public String getDescription() {
8.81 + return description != null ? description : "";
8.82 + }
8.83 +
8.84 + public void setDescription(String description) {
8.85 + this.description = description;
8.86 + }
8.87 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/mywork-web/src/main/java/ru/indvdum/mywork/openjpa/model/Work.java Wed Nov 23 17:52:25 2011 +0300
9.3 @@ -0,0 +1,84 @@
9.4 +package ru.indvdum.mywork.openjpa.model;
9.5 +
9.6 +import javax.persistence.Column;
9.7 +import javax.persistence.EmbeddedId;
9.8 +import javax.persistence.Entity;
9.9 +import javax.persistence.FetchType;
9.10 +import javax.persistence.GeneratedValue;
9.11 +import javax.persistence.ManyToOne;
9.12 +import javax.persistence.MapsId;
9.13 +import javax.persistence.Table;
9.14 +
9.15 +/**
9.16 + * @author indvdum
9.17 + * 16.08.2011 13:55:51
9.18 + *
9.19 + */
9.20 +@Entity
9.21 +@Table(name = "WORK")
9.22 +public class Work implements IDatabaseObject {
9.23 +
9.24 + private static final long serialVersionUID = 7138260708537798813L;
9.25 +
9.26 + @EmbeddedId
9.27 + private WorkId id = null;
9.28 +
9.29 + @Column(name = "HOURS")
9.30 + private Float hours = null;
9.31 +
9.32 + @Column(name = "RESULT")
9.33 + private String result = null;
9.34 +
9.35 + @MapsId("dayId")
9.36 + @ManyToOne(fetch = FetchType.EAGER)
9.37 + private Day day = null;
9.38 +
9.39 + @MapsId("taskId")
9.40 + @ManyToOne(fetch = FetchType.EAGER)
9.41 + private Task task = null;
9.42 +
9.43 + public Work(){
9.44 +
9.45 + }
9.46 +
9.47 + public Float getHours() {
9.48 + return hours;
9.49 + }
9.50 +
9.51 + public void setHours(Float hours) {
9.52 + this.hours = hours;
9.53 + }
9.54 +
9.55 + public String getResult() {
9.56 + return result;
9.57 + }
9.58 +
9.59 + public void setResult(String result) {
9.60 + this.result = result;
9.61 + }
9.62 +
9.63 + public Day getDay() {
9.64 + return day;
9.65 + }
9.66 +
9.67 + public void setDay(Day day) {
9.68 + this.day = day;
9.69 + }
9.70 +
9.71 + public Task getTask() {
9.72 + return task;
9.73 + }
9.74 +
9.75 + public void setTask(Task task) {
9.76 + this.task = task;
9.77 + }
9.78 +
9.79 + public WorkId getId() {
9.80 + return id;
9.81 + }
9.82 +
9.83 + public void setId(WorkId id) {
9.84 + this.id = id;
9.85 + }
9.86 +
9.87 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/mywork-web/src/main/java/ru/indvdum/mywork/openjpa/model/WorkId.java Wed Nov 23 17:52:25 2011 +0300
10.3 @@ -0,0 +1,42 @@
10.4 +package ru.indvdum.mywork.openjpa.model;
10.5 +
10.6 +import javax.persistence.Embeddable;
10.7 +
10.8 +/**
10.9 + * @author indvdum
10.10 + * 17.08.2011 15:00:35
10.11 + *
10.12 + */
10.13 +@Embeddable
10.14 +public class WorkId{
10.15 +
10.16 + public Integer dayId;
10.17 + public Integer taskId;
10.18 +
10.19 + @Override
10.20 + public boolean equals(Object obj) {
10.21 + if (this == obj)
10.22 + return true;
10.23 + if (obj == null)
10.24 + return false;
10.25 + if (!(obj instanceof WorkId))
10.26 + return false;
10.27 + final WorkId other = (WorkId) obj;
10.28 + return (
10.29 + this.dayId == other.dayId
10.30 + && this.taskId == other.taskId
10.31 + || (
10.32 + this.dayId != null
10.33 + && this.dayId.equals(other.dayId)
10.34 + && this.taskId != null
10.35 + && this.taskId.equals(other.taskId)
10.36 + )
10.37 + );
10.38 + }
10.39 +
10.40 + @Override
10.41 + public int hashCode() {
10.42 + return dayId ^ taskId;
10.43 + }
10.44 +
10.45 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/mywork-web/src/main/java/ru/indvdum/mywork/vaadin/EditDayDialog.java Wed Nov 23 17:52:25 2011 +0300
11.3 @@ -0,0 +1,243 @@
11.4 +package ru.indvdum.mywork.vaadin;
11.5 +
11.6 +import static ru.indvdum.mywork.MyWork.EM;
11.7 +
11.8 +import java.sql.Time;
11.9 +import java.text.SimpleDateFormat;
11.10 +import java.util.Calendar;
11.11 +import java.util.Date;
11.12 +
11.13 +import ru.indvdum.mywork.openjpa.model.Day;
11.14 +
11.15 +import com.vaadin.data.Property.ValueChangeEvent;
11.16 +import com.vaadin.data.Property.ValueChangeListener;
11.17 +import com.vaadin.ui.Alignment;
11.18 +import com.vaadin.ui.Button;
11.19 +import com.vaadin.ui.HorizontalLayout;
11.20 +import com.vaadin.ui.Label;
11.21 +import com.vaadin.ui.PopupDateField;
11.22 +import com.vaadin.ui.TextField;
11.23 +import com.vaadin.ui.VerticalLayout;
11.24 +import com.vaadin.ui.Window;
11.25 +import com.vaadin.ui.Button.ClickEvent;
11.26 +import com.vaadin.ui.Button.ClickListener;
11.27 +
11.28 +/**
11.29 + * @author indvdum
11.30 + * 23.08.2011 19:11:35
11.31 + *
11.32 + */
11.33 +public class EditDayDialog extends Window implements ValueChangeListener, ClickListener {
11.34 +
11.35 + private MyWorkApplication myApp = null;
11.36 + private EditState state = null;
11.37 + private Day day = null;
11.38 + private PopupDateField dayStartTime = null;
11.39 + private PopupDateField dayEndTime = null;
11.40 + private PopupDateField dayDate = null;
11.41 + private TextField dayHours = null;
11.42 +
11.43 + public EditDayDialog(MyWorkApplication myApp, Day day) throws Exception {
11.44 + super();
11.45 + this.myApp = myApp;
11.46 + if(day == null)
11.47 + state = EditState.CREATE;
11.48 + else
11.49 + state = EditState.EDIT;
11.50 + switch(state){
11.51 + case CREATE:
11.52 + setCaption("Creating new day");
11.53 + day = new Day();
11.54 + Calendar calDay = Calendar.getInstance();
11.55 + calDay.set(Calendar.HOUR_OF_DAY, 0);
11.56 + calDay.set(Calendar.MINUTE, 0);
11.57 + calDay.set(Calendar.SECOND, 0);
11.58 + calDay.set(Calendar.MILLISECOND, 0);
11.59 + day.setDay(calDay.getTime());
11.60 + Calendar calStart = Calendar.getInstance();
11.61 + calStart.set(Calendar.HOUR_OF_DAY, 9);
11.62 + calStart.set(Calendar.MINUTE, 0);
11.63 + calStart.set(Calendar.SECOND, 0);
11.64 + calStart.set(Calendar.MILLISECOND, 0);
11.65 + day.setStartWork(new Time(calStart.getTime().getTime()));
11.66 + Calendar calEnd = Calendar.getInstance();
11.67 + calEnd.set(Calendar.HOUR_OF_DAY, 18);
11.68 + calEnd.set(Calendar.MINUTE, 0);
11.69 + calEnd.set(Calendar.SECOND, 0);
11.70 + calEnd.set(Calendar.MILLISECOND, 0);
11.71 + day.setEndWork(new Time(calEnd.getTime().getTime()));
11.72 + day.setHours(8f);
11.73 + this.day = day;
11.74 + break;
11.75 + case EDIT:
11.76 + setCaption("Editing day");
11.77 + this.day = day;
11.78 + break;
11.79 + }
11.80 + init();
11.81 + }
11.82 +
11.83 + private void init(){
11.84 + setModal(true);
11.85 + setWidth("480px");
11.86 + setHeight("300px");
11.87 + VerticalLayout vl = new VerticalLayout();
11.88 + vl.setSizeFull();
11.89 + vl.setSpacing(true);
11.90 + vl.setMargin(true);
11.91 + setContent(vl);
11.92 +
11.93 + HorizontalLayout hlDay = new HorizontalLayout();
11.94 + hlDay.setWidth("100%");
11.95 + Label lblDay = new Label("Day:");
11.96 + lblDay.setWidth("100%");
11.97 + hlDay.addComponent(lblDay);
11.98 + hlDay.setExpandRatio(lblDay, 1f);
11.99 + dayDate = new PopupDateField();
11.100 + dayDate.setWidth("100%");
11.101 + dayDate.setInputPrompt("Enter date");
11.102 + dayDate.setResolution(PopupDateField.RESOLUTION_DAY);
11.103 + dayDate.setImmediate(true);
11.104 + dayDate.setValue(day.getDay());
11.105 + dayDate.addListener(this);
11.106 + dayDate.setDateFormat("dd.MM.yyyy");
11.107 + hlDay.addComponent(dayDate);
11.108 + hlDay.setExpandRatio(dayDate, 5f);
11.109 + vl.addComponent(hlDay);
11.110 +
11.111 + HorizontalLayout hlStart = new HorizontalLayout();
11.112 + hlStart.setWidth("100%");
11.113 + Label lblStart = new Label("Start time:");
11.114 + lblStart.setWidth("100%");
11.115 + hlStart.addComponent(lblStart);
11.116 + hlStart.setExpandRatio(lblStart, 1f);
11.117 + dayStartTime = new PopupDateField();
11.118 + dayStartTime.setWidth("100%");
11.119 + dayStartTime.setInputPrompt("Enter time");
11.120 + dayStartTime.setResolution(PopupDateField.RESOLUTION_MIN);
11.121 + dayStartTime.setImmediate(true);
11.122 + dayStartTime.setValue(day.getStartWork());
11.123 + dayStartTime.setDateFormat("HH:mm");
11.124 + hlStart.addComponent(dayStartTime);
11.125 + hlStart.setExpandRatio(dayStartTime, 5f);
11.126 + vl.addComponent(hlStart);
11.127 +
11.128 + HorizontalLayout hlEnd = new HorizontalLayout();
11.129 + hlEnd.setWidth("100%");
11.130 + Label lblEnd = new Label("End time:");
11.131 + lblEnd.setWidth("100%");
11.132 + hlEnd.addComponent(lblEnd);
11.133 + hlEnd.setExpandRatio(lblEnd, 1f);
11.134 + dayEndTime = new PopupDateField();
11.135 + dayEndTime.setWidth("100%");
11.136 + dayEndTime.setInputPrompt("Enter time");
11.137 + dayEndTime.setResolution(PopupDateField.RESOLUTION_MIN);
11.138 + dayEndTime.setImmediate(true);
11.139 + dayEndTime.setValue(day.getEndWork());
11.140 + dayEndTime.setDateFormat("HH:mm");
11.141 + hlEnd.addComponent(dayEndTime);
11.142 + hlEnd.setExpandRatio(dayEndTime, 5f);
11.143 + vl.addComponent(hlEnd);
11.144 +
11.145 + HorizontalLayout hlHours = new HorizontalLayout();
11.146 + hlHours.setWidth("100%");
11.147 + Label lblHours = new Label("Work hours count:");
11.148 + lblHours.setWidth("100%");
11.149 + hlHours.addComponent(lblHours);
11.150 + hlHours.setExpandRatio(lblHours, 1f);
11.151 + dayHours = new TextField();
11.152 + dayHours.setWidth("100%");
11.153 + dayHours.setValue(day.getHours());
11.154 + dayHours.setImmediate(true);
11.155 + hlHours.addComponent(dayHours);
11.156 + hlHours.setExpandRatio(dayHours, 5f);
11.157 + vl.addComponent(hlHours);
11.158 +
11.159 + HorizontalLayout hlOk = new HorizontalLayout();
11.160 + hlOk.setSizeFull();
11.161 + Button okButton = new Button();
11.162 + switch(state){
11.163 + case CREATE:
11.164 + okButton.setCaption("Create");
11.165 + break;
11.166 + case EDIT:
11.167 + okButton.setCaption("Save");
11.168 + break;
11.169 + }
11.170 + okButton.addListener((ClickListener)this);
11.171 + hlOk.addComponent(okButton);
11.172 + hlOk.setComponentAlignment(okButton, Alignment.BOTTOM_RIGHT);
11.173 + vl.addComponent(hlOk);
11.174 + vl.setExpandRatio(hlOk, 1f);
11.175 + }
11.176 +
11.177 + @Override
11.178 + public void valueChange(ValueChangeEvent event) {
11.179 + Object value = event.getProperty().getValue();
11.180 + Object startValue = dayStartTime.getValue();
11.181 + Object endValue = dayEndTime.getValue();
11.182 + if (value == null || !(value instanceof Date) || !(startValue instanceof Date) || !(endValue instanceof Date)) {
11.183 + getWindow().showNotification("Invalid date entered");
11.184 + } else {
11.185 + Date date = (Date)value;
11.186 + Date start = (Date)startValue;
11.187 + Date end = (Date)endValue;
11.188 + Calendar calStart = Calendar.getInstance();
11.189 + calStart.setTime(start);
11.190 + Calendar calEnd = Calendar.getInstance();
11.191 + calEnd.setTime(end);
11.192 + Calendar cal = Calendar.getInstance();
11.193 + cal.setTime(date);
11.194 + calStart.set(Calendar.YEAR, cal.get(Calendar.YEAR));
11.195 + calStart.set(Calendar.MONTH, cal.get(Calendar.MONTH));
11.196 + calStart.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH));
11.197 + calStart.set(Calendar.SECOND, cal.get(Calendar.SECOND));
11.198 + calStart.set(Calendar.MILLISECOND, cal.get(Calendar.MILLISECOND));
11.199 + calEnd.set(Calendar.YEAR, cal.get(Calendar.YEAR));
11.200 + calEnd.set(Calendar.MONTH, cal.get(Calendar.MONTH));
11.201 + calEnd.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH));
11.202 + calEnd.set(Calendar.SECOND, cal.get(Calendar.SECOND));
11.203 + calEnd.set(Calendar.MILLISECOND, cal.get(Calendar.MILLISECOND));
11.204 + dayStartTime.setValue(calStart.getTime());
11.205 + dayEndTime.setValue(calEnd.getTime());
11.206 + }
11.207 + }
11.208 +
11.209 + @Override
11.210 + public void buttonClick(ClickEvent event) {
11.211 + Object value = dayDate.getValue();
11.212 + Object startValue = dayStartTime.getValue();
11.213 + Object endValue = dayEndTime.getValue();
11.214 + Object hoursValue = dayHours.getValue();
11.215 + if (
11.216 + value == null
11.217 + || !(value instanceof Date)
11.218 + || !(startValue instanceof Date)
11.219 + || !(endValue instanceof Date)
11.220 + || !(hoursValue.toString().matches("^[0-9]+[\\.]{0,1}[0-9]*"))
11.221 + ) {
11.222 + getWindow().showNotification("Invalid information entered");
11.223 + } else {
11.224 + Date date = (Date)value;
11.225 + Date start = (Date)startValue;
11.226 + Date end = (Date)endValue;
11.227 + Float hours = Float.parseFloat(hoursValue.toString());
11.228 + day.setDay(date);
11.229 + day.setStartWork(new Time(start.getTime()));
11.230 + day.setEndWork(new Time(end.getTime()));
11.231 + day.setHours(hours);
11.232 + try{
11.233 + EM.getTransaction().begin();
11.234 + EM.persist(day);
11.235 + EM.getTransaction().commit();
11.236 + EM.clear();
11.237 + } finally {
11.238 + if(EM.getTransaction().isActive())
11.239 + EM.getTransaction().rollback();
11.240 + }
11.241 + getParent().removeWindow(this);
11.242 + myApp.getDayTable().requestRepaint();
11.243 + }
11.244 + }
11.245 +
11.246 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/mywork-web/src/main/java/ru/indvdum/mywork/vaadin/EditState.java Wed Nov 23 17:52:25 2011 +0300
12.3 @@ -0,0 +1,11 @@
12.4 +package ru.indvdum.mywork.vaadin;
12.5 +
12.6 +/**
12.7 + * @author indvdum
12.8 + * 23.08.2011 19:11:44
12.9 + *
12.10 + */
12.11 +public enum EditState {
12.12 + CREATE,
12.13 + EDIT,
12.14 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/mywork-web/src/main/java/ru/indvdum/mywork/vaadin/EditTaskDialog.java Wed Nov 23 17:52:25 2011 +0300
13.3 @@ -0,0 +1,116 @@
13.4 +package ru.indvdum.mywork.vaadin;
13.5 +
13.6 +import static ru.indvdum.mywork.MyWork.EM;
13.7 +import ru.indvdum.mywork.openjpa.model.Task;
13.8 +
13.9 +import com.vaadin.ui.Alignment;
13.10 +import com.vaadin.ui.Button;
13.11 +import com.vaadin.ui.HorizontalLayout;
13.12 +import com.vaadin.ui.Label;
13.13 +import com.vaadin.ui.RichTextArea;
13.14 +import com.vaadin.ui.TextField;
13.15 +import com.vaadin.ui.VerticalLayout;
13.16 +import com.vaadin.ui.Window;
13.17 +import com.vaadin.ui.Button.ClickEvent;
13.18 +import com.vaadin.ui.Button.ClickListener;
13.19 +
13.20 +/**
13.21 + * @author indvdum
13.22 + * 23.08.2011 19:11:50
13.23 + *
13.24 + */
13.25 +public class EditTaskDialog extends Window implements ClickListener {
13.26 +
13.27 + private MyWorkApplication myApp = null;
13.28 + private EditState state = null;
13.29 + private Task task = null;
13.30 + private TextField taskName = null;
13.31 + private RichTextArea taskDescription = null;
13.32 +
13.33 + public EditTaskDialog(MyWorkApplication myApp, Task task) throws Exception {
13.34 + super();
13.35 + this.myApp = myApp;
13.36 + if(task == null)
13.37 + state = EditState.CREATE;
13.38 + else
13.39 + state = EditState.EDIT;
13.40 + switch(state){
13.41 + case CREATE:
13.42 + setCaption("Creating new task");
13.43 + task = new Task();
13.44 + task.setName("");
13.45 + task.setDescription("");
13.46 + this.task = task;
13.47 + break;
13.48 + case EDIT:
13.49 + setCaption("Editing task");
13.50 + this.task = task;
13.51 + break;
13.52 + }
13.53 + init();
13.54 + }
13.55 +
13.56 + private void init(){
13.57 + setModal(true);
13.58 + setWidth("640px");
13.59 + setHeight("480px");
13.60 + VerticalLayout vl = new VerticalLayout();
13.61 + vl.setSizeFull();
13.62 + vl.setSpacing(true);
13.63 + vl.setMargin(true);
13.64 + setContent(vl);
13.65 +
13.66 + HorizontalLayout hlName = new HorizontalLayout();
13.67 + hlName.setWidth("100%");
13.68 + Label lblName = new Label("Name:");
13.69 + lblName.setWidth("100%");
13.70 + hlName.addComponent(lblName);
13.71 + hlName.setExpandRatio(lblName, 1f);
13.72 + taskName = new TextField();
13.73 + taskName.setWidth("100%");
13.74 + taskName.setValue(task.getName());
13.75 + hlName.addComponent(taskName);
13.76 + hlName.setExpandRatio(taskName, 5f);
13.77 + vl.addComponent(hlName);
13.78 +
13.79 + taskDescription = new RichTextArea("Description");
13.80 + taskDescription.setValue(task.getDescription());
13.81 + taskDescription.setSizeFull();
13.82 + vl.addComponent(taskDescription);
13.83 + vl.setExpandRatio(taskDescription, 1f);
13.84 +
13.85 + HorizontalLayout hlOk = new HorizontalLayout();
13.86 + hlOk.setWidth("100%");
13.87 + Button okButton = new Button();
13.88 + switch(state){
13.89 + case CREATE:
13.90 + okButton.setCaption("Create");
13.91 + break;
13.92 + case EDIT:
13.93 + okButton.setCaption("Save");
13.94 + break;
13.95 + }
13.96 + okButton.addListener((ClickListener)this);
13.97 + hlOk.addComponent(okButton);
13.98 + hlOk.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);
13.99 + vl.addComponent(hlOk);
13.100 + }
13.101 +
13.102 + @Override
13.103 + public void buttonClick(ClickEvent event) {
13.104 + task.setName(taskName.getValue().toString());
13.105 + task.setDescription(taskDescription.getValue().toString());
13.106 + try{
13.107 + EM.getTransaction().begin();
13.108 + EM.persist(task);
13.109 + EM.getTransaction().commit();
13.110 + EM.clear();
13.111 + } finally {
13.112 + if(EM.getTransaction().isActive())
13.113 + EM.getTransaction().rollback();
13.114 + }
13.115 + getParent().removeWindow(this);
13.116 + myApp.getTaskTable().requestRepaint();
13.117 + }
13.118 +
13.119 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/mywork-web/src/main/java/ru/indvdum/mywork/vaadin/EditWorkDialog.java Wed Nov 23 17:52:25 2011 +0300
14.3 @@ -0,0 +1,234 @@
14.4 +package ru.indvdum.mywork.vaadin;
14.5 +
14.6 +import static ru.indvdum.mywork.MyWork.EM;
14.7 +
14.8 +import java.util.Calendar;
14.9 +import java.util.List;
14.10 +
14.11 +import javax.persistence.Query;
14.12 +
14.13 +import ru.indvdum.mywork.openjpa.model.Day;
14.14 +import ru.indvdum.mywork.openjpa.model.Task;
14.15 +import ru.indvdum.mywork.openjpa.model.Work;
14.16 +
14.17 +import com.vaadin.data.Property.ValueChangeEvent;
14.18 +import com.vaadin.data.Property.ValueChangeListener;
14.19 +import com.vaadin.ui.Alignment;
14.20 +import com.vaadin.ui.Button;
14.21 +import com.vaadin.ui.ComboBox;
14.22 +import com.vaadin.ui.HorizontalLayout;
14.23 +import com.vaadin.ui.Label;
14.24 +import com.vaadin.ui.RichTextArea;
14.25 +import com.vaadin.ui.TextField;
14.26 +import com.vaadin.ui.VerticalLayout;
14.27 +import com.vaadin.ui.Window;
14.28 +import com.vaadin.ui.AbstractSelect.Filtering;
14.29 +import com.vaadin.ui.Button.ClickEvent;
14.30 +import com.vaadin.ui.Button.ClickListener;
14.31 +
14.32 +/**
14.33 + * @author indvdum
14.34 + * 23.08.2011 19:11:56
14.35 + *
14.36 + */
14.37 +public class EditWorkDialog extends Window implements ClickListener {
14.38 +
14.39 + private MyWorkApplication myApp = null;
14.40 + private EditState state = null;
14.41 + private Work work = null;
14.42 + private ComboBox workDay = null;
14.43 + private ComboBox workTask = null;
14.44 + private TextField workHours = null;
14.45 + private RichTextArea workResult = null;
14.46 +
14.47 + public EditWorkDialog(MyWorkApplication myApp, Work work) throws Exception {
14.48 + super();
14.49 + this.myApp = myApp;
14.50 + if(work == null)
14.51 + state = EditState.CREATE;
14.52 + else
14.53 + state = EditState.EDIT;
14.54 + switch(state){
14.55 + case CREATE:
14.56 + setCaption("Creating new work");
14.57 + work = new Work();
14.58 + work.setHours(0f);
14.59 + work.setResult("");
14.60 + this.work = work;
14.61 + break;
14.62 + case EDIT:
14.63 + setCaption("Editing work");
14.64 + this.work = work;
14.65 + break;
14.66 + }
14.67 + init();
14.68 + }
14.69 +
14.70 + private void init(){
14.71 + setModal(true);
14.72 + setWidth("640px");
14.73 + setHeight("480px");
14.74 + VerticalLayout vl = new VerticalLayout();
14.75 + vl.setSizeFull();
14.76 + vl.setSpacing(true);
14.77 + vl.setMargin(true);
14.78 + setContent(vl);
14.79 +
14.80 + HorizontalLayout hlDay = new HorizontalLayout();
14.81 + hlDay.setWidth("100%");
14.82 + Label lblDay = new Label("Day:");
14.83 + lblDay.setWidth("100%");
14.84 + hlDay.addComponent(lblDay);
14.85 + hlDay.setExpandRatio(lblDay, 1f);
14.86 + workDay = new ComboBox();
14.87 + workDay.setWidth("100%");
14.88 + workDay.setImmediate(true);
14.89 + workDay.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
14.90 + updateDays("select d from " + Day.class.getName() + " d order by d.day");
14.91 + workDay.addListener(new ValueChangeListener(){
14.92 +
14.93 + @Override
14.94 + public void valueChange(ValueChangeEvent event) {
14.95 + Day day = (Day)event.getProperty().getValue();
14.96 + if(day == null)
14.97 + updateTasks("select t from " + Task.class.getName() + " t order by t.id desc");
14.98 + else
14.99 + updateTasks("select t from " + Task.class.getName() + " t where t.id not in (select w.task.id from " + Work.class.getName() + " w where w.day.id = " + day.getId() + ") order by t.id desc");
14.100 + }
14.101 +
14.102 + });
14.103 + hlDay.addComponent(workDay);
14.104 + hlDay.setExpandRatio(workDay, 5f);
14.105 + vl.addComponent(hlDay);
14.106 +
14.107 + HorizontalLayout hlTask = new HorizontalLayout();
14.108 + hlTask.setWidth("100%");
14.109 + Label lblStart = new Label("Task:");
14.110 + lblStart.setWidth("100%");
14.111 + hlTask.addComponent(lblStart);
14.112 + hlTask.setExpandRatio(lblStart, 1f);
14.113 + workTask = new ComboBox();
14.114 + workTask.setWidth("100%");
14.115 + workTask.setImmediate(true);
14.116 + workTask.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
14.117 + Day day = (Day)workDay.getValue();
14.118 + if(day == null)
14.119 + updateTasks("select t from " + Task.class.getName() + " t order by t.id desc");
14.120 + else
14.121 + updateTasks("select t from " + Task.class.getName() + " t where t.id not in (select w.task.id from " + Work.class.getName() + " w where w.day.id = " + day.getId() + ") order by t.id desc");
14.122 + workTask.addListener(new ValueChangeListener(){
14.123 +
14.124 + @Override
14.125 + public void valueChange(ValueChangeEvent event) {
14.126 + Task task = (Task)event.getProperty().getValue();
14.127 + if(task == null)
14.128 + updateDays("select d from " + Day.class.getName() + " d order by d.day");
14.129 + else
14.130 + updateDays("select d from " + Day.class.getName() + " d where d.id not in (select w.day.id from " + Work.class.getName() + " w where w.task.id = " + task.getId() + ") order by d.day");
14.131 + }
14.132 +
14.133 + });
14.134 + hlTask.addComponent(workTask);
14.135 + hlTask.setExpandRatio(workTask, 5f);
14.136 + vl.addComponent(hlTask);
14.137 +
14.138 + HorizontalLayout hlHours = new HorizontalLayout();
14.139 + hlHours.setWidth("100%");
14.140 + Label lblHours = new Label("Hours:");
14.141 + lblHours.setWidth("100%");
14.142 + hlHours.addComponent(lblHours);
14.143 + hlHours.setExpandRatio(lblHours, 1f);
14.144 + workHours = new TextField();
14.145 + workHours.setWidth("100%");
14.146 + workHours.setValue(work.getHours());
14.147 + workHours.setImmediate(true);
14.148 + hlHours.addComponent(workHours);
14.149 + hlHours.setExpandRatio(workHours, 5f);
14.150 + vl.addComponent(hlHours);
14.151 +
14.152 + workResult = new RichTextArea("Result");
14.153 + workResult.setValue(work.getResult());
14.154 + workResult.setSizeFull();
14.155 + vl.addComponent(workResult);
14.156 + vl.setExpandRatio(workResult, 5f);
14.157 +
14.158 + HorizontalLayout hlOk = new HorizontalLayout();
14.159 + hlOk.setWidth("100%");
14.160 + Button okButton = new Button();
14.161 + switch(state){
14.162 + case CREATE:
14.163 + okButton.setCaption("Create");
14.164 + break;
14.165 + case EDIT:
14.166 + okButton.setCaption("Save");
14.167 + break;
14.168 + }
14.169 + okButton.addListener((ClickListener)this);
14.170 + hlOk.addComponent(okButton);
14.171 + hlOk.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);
14.172 + vl.addComponent(hlOk);
14.173 + }
14.174 +
14.175 + private void updateDays(String jpql){
14.176 + if(workTask != null && workTask.getValue() != null && workDay != null && workDay.getValue() != null)
14.177 + return;
14.178 + workDay.removeAllItems();
14.179 + Query query = EM.createQuery(jpql);
14.180 + List list = query.getResultList();
14.181 + for(Day day: (List<Day>)list){
14.182 + workDay.addItem(day);
14.183 + Calendar currCal = Calendar.getInstance();
14.184 + currCal.set(Calendar.HOUR_OF_DAY, 0);
14.185 + currCal.set(Calendar.MINUTE, 0);
14.186 + currCal.set(Calendar.SECOND, 0);
14.187 + currCal.set(Calendar.MILLISECOND, 0);
14.188 + if(day.getDay().equals(currCal.getTime()))
14.189 + workDay.select(day);
14.190 + }
14.191 + }
14.192 +
14.193 + private void updateTasks(String jpql){
14.194 + if(workTask != null && workTask.getValue() != null && workDay != null && workDay.getValue() != null)
14.195 + return;
14.196 + workTask.removeAllItems();
14.197 + Query query = EM.createQuery(jpql);
14.198 + List list = query.getResultList();
14.199 + for(Task task: (List<Task>)list)
14.200 + workTask.addItem(task);
14.201 + }
14.202 +
14.203 + @Override
14.204 + public void buttonClick(ClickEvent event) {
14.205 + Object dayObj = workDay.getValue();
14.206 + Object taskObj = workTask.getValue();
14.207 + Object hoursObj = workHours.getValue();
14.208 + String result = workResult.getValue().toString();
14.209 + if (
14.210 + !(dayObj instanceof Day)
14.211 + || !(taskObj instanceof Task)
14.212 + || !(hoursObj.toString().matches("^[0-9]+[\\.]{0,1}[0-9]*"))
14.213 + ) {
14.214 + getWindow().showNotification("Invalid information entered");
14.215 + } else {
14.216 + Day day = (Day)dayObj;
14.217 + Task task = (Task)taskObj;
14.218 + Float hours = Float.parseFloat(hoursObj.toString());
14.219 + work.setDay(day);
14.220 + work.setTask(task);
14.221 + work.setHours(hours);
14.222 + work.setResult(result);
14.223 + try{
14.224 + EM.getTransaction().begin();
14.225 + EM.persist(work);
14.226 + EM.getTransaction().commit();
14.227 + EM.clear();
14.228 + } finally {
14.229 + if(EM.getTransaction().isActive())
14.230 + EM.getTransaction().rollback();
14.231 + }
14.232 + getParent().removeWindow(this);
14.233 + myApp.getWorkTable().requestRepaint();
14.234 + }
14.235 + }
14.236 +
14.237 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/mywork-web/src/main/java/ru/indvdum/mywork/vaadin/MyWorkApplication.java Wed Nov 23 17:52:25 2011 +0300
15.3 @@ -0,0 +1,231 @@
15.4 +package ru.indvdum.mywork.vaadin;
15.5 +
15.6 +import static ru.indvdum.mywork.MyWork.EM;
15.7 +
15.8 +import java.util.List;
15.9 +
15.10 +import javax.persistence.Query;
15.11 +
15.12 +import ru.indvdum.mywork.openjpa.model.Day;
15.13 +import ru.indvdum.mywork.openjpa.model.Task;
15.14 +import ru.indvdum.mywork.openjpa.model.Work;
15.15 +
15.16 +import com.vaadin.Application;
15.17 +import com.vaadin.addon.jpacontainer.EntityContainer;
15.18 +import com.vaadin.addon.jpacontainer.EntityProvider;
15.19 +import com.vaadin.addon.jpacontainer.HierarchicalEntityContainer;
15.20 +import com.vaadin.addon.jpacontainer.JPAContainer;
15.21 +import com.vaadin.addon.jpacontainer.provider.BatchableLocalEntityProvider;
15.22 +import com.vaadin.addon.jpacontainer.provider.CachingBatchableLocalEntityProvider;
15.23 +import com.vaadin.addon.jpacontainer.provider.CachingLocalEntityProvider;
15.24 +import com.vaadin.addon.jpacontainer.provider.CachingMutableLocalEntityProvider;
15.25 +import com.vaadin.addon.jpacontainer.provider.LocalEntityProvider;
15.26 +import com.vaadin.ui.Alignment;
15.27 +import com.vaadin.ui.Button;
15.28 +import com.vaadin.ui.HorizontalLayout;
15.29 +import com.vaadin.ui.MenuBar;
15.30 +import com.vaadin.ui.TabSheet;
15.31 +import com.vaadin.ui.Table;
15.32 +import com.vaadin.ui.VerticalLayout;
15.33 +import com.vaadin.ui.Window;
15.34 +import com.vaadin.ui.Button.ClickEvent;
15.35 +import com.vaadin.ui.Button.ClickListener;
15.36 +import com.vaadin.ui.MenuBar.Command;
15.37 +import com.vaadin.ui.MenuBar.MenuItem;
15.38 +
15.39 +/**
15.40 + * @author indvdum
15.41 + * 12.08.2011 17:31:53
15.42 + *
15.43 + */
15.44 +public class MyWorkApplication extends Application {
15.45 +
15.46 + private MyWorkApplication thisObject = this;
15.47 + private Table dayTable = null;
15.48 + private Table taskTable = null;
15.49 + private Table workTable = null;
15.50 +
15.51 + private Command newDayCommand = new Command() {
15.52 + public void menuSelected(MenuItem selectedItem) {
15.53 + EditDayDialog dialog = null;
15.54 + try {
15.55 + dialog = new EditDayDialog(thisObject, null);
15.56 + } catch (Exception e) {
15.57 + e.printStackTrace();
15.58 + }
15.59 + getMainWindow().addWindow(dialog);
15.60 + }
15.61 + };
15.62 + private Command newTaskCommand = new Command() {
15.63 + public void menuSelected(MenuItem selectedItem) {
15.64 + EditTaskDialog dialog = null;
15.65 + try {
15.66 + dialog = new EditTaskDialog(thisObject, null);
15.67 + } catch (Exception e) {
15.68 + e.printStackTrace();
15.69 + }
15.70 + getMainWindow().addWindow(dialog);
15.71 + }
15.72 + };
15.73 + private Command newWorkCommand = new Command() {
15.74 + public void menuSelected(MenuItem selectedItem) {
15.75 + EditWorkDialog dialog = null;
15.76 + try {
15.77 + dialog = new EditWorkDialog(thisObject, null);
15.78 + } catch (Exception e) {
15.79 + e.printStackTrace();
15.80 + }
15.81 + getMainWindow().addWindow(dialog);
15.82 + }
15.83 + };
15.84 + private Command editDayCommand = new Command() {
15.85 + public void menuSelected(MenuItem selectedItem) {
15.86 + EditDayDialog dialog = null;
15.87 + Day day = EM.find(Day.class, dayTable.getValue());
15.88 + if(day == null)
15.89 + return;
15.90 + try {
15.91 + dialog = new EditDayDialog(thisObject, day);
15.92 + } catch (Exception e) {
15.93 + e.printStackTrace();
15.94 + }
15.95 + getMainWindow().addWindow(dialog);
15.96 + }
15.97 + };
15.98 + private Command editTaskCommand = new Command() {
15.99 + public void menuSelected(MenuItem selectedItem) {
15.100 + EditTaskDialog dialog = null;
15.101 + Task task = EM.find(Task.class, taskTable.getValue());
15.102 + if(task == null)
15.103 + return;
15.104 + try {
15.105 + dialog = new EditTaskDialog(thisObject, task);
15.106 + } catch (Exception e) {
15.107 + e.printStackTrace();
15.108 + }
15.109 + getMainWindow().addWindow(dialog);
15.110 + }
15.111 + };
15.112 + private Command editWorkCommand = new Command() {
15.113 + public void menuSelected(MenuItem selectedItem) {
15.114 + EditWorkDialog dialog = null;
15.115 + Work work = EM.find(Work.class, workTable.getValue());
15.116 + if(work == null)
15.117 + return;
15.118 + try {
15.119 + dialog = new EditWorkDialog(thisObject, work);
15.120 + } catch (Exception e) {
15.121 + e.printStackTrace();
15.122 + }
15.123 + getMainWindow().addWindow(dialog);
15.124 + }
15.125 + };
15.126 +
15.127 + @Override
15.128 + public void init() {
15.129 + Window window = new Window();
15.130 + setMainWindow(window);
15.131 +
15.132 + TabSheet tabSheet = new TabSheet();
15.133 + tabSheet.setSizeFull();
15.134 + window.setContent(tabSheet);
15.135 +
15.136 + VerticalLayout vlMain = new VerticalLayout();
15.137 + vlMain.setSizeFull();
15.138 + vlMain.setMargin(true);
15.139 + vlMain.setSpacing(true);
15.140 + tabSheet.addTab(vlMain, "Main page", null);
15.141 +
15.142 + MenuBar menuBar = new MenuBar();
15.143 + MenuItem file = menuBar.addItem("File", null);
15.144 + MenuItem newItem = file.addItem("New", null);
15.145 + newItem.addItem("Day...", newDayCommand);
15.146 + newItem.addItem("Task...", newTaskCommand);
15.147 + newItem.addItem("Work...", newWorkCommand);
15.148 + MenuItem edit = menuBar.addItem("Edit", null);
15.149 + edit.addItem("Day...", editDayCommand);
15.150 + edit.addItem("Task...", editTaskCommand);
15.151 + edit.addItem("Work...", editWorkCommand);
15.152 + vlMain.addComponent(menuBar);
15.153 +
15.154 + LocalEntityProvider dayProvider = new CachingLocalEntityProvider(Day.class);
15.155 + dayProvider.setEntityManager(EM);
15.156 + JPAContainer<Day> dayContainer = new JPAContainer(Day.class);
15.157 + dayContainer.setEntityProvider(dayProvider);
15.158 +
15.159 + dayTable = new Table();
15.160 + dayTable.setSelectable(true);
15.161 + dayTable.setEditable(false);
15.162 + dayTable.setImmediate(true);
15.163 + dayTable.setSizeFull();
15.164 + dayTable.setContainerDataSource(dayContainer);
15.165 + dayTable.setVisibleColumns(new String[]{
15.166 + "formattedDay",
15.167 + "startWork",
15.168 + "endWork",
15.169 + "hours",
15.170 + });
15.171 + dayTable.setSortContainerPropertyId("day");
15.172 + dayTable.setColumnHeaders(new String[]{
15.173 + "day",
15.174 + "startWork",
15.175 + "endWork",
15.176 + "hours",
15.177 + });
15.178 + vlMain.addComponent(dayTable);
15.179 + vlMain.setExpandRatio(dayTable, 1f);
15.180 +
15.181 + LocalEntityProvider taskProvider = new CachingLocalEntityProvider(Task.class);
15.182 + taskProvider.setEntityManager(EM);
15.183 + JPAContainer<Task> taskContainer = new JPAContainer(Task.class);
15.184 + taskContainer.setEntityProvider(taskProvider);
15.185 +
15.186 + taskTable = new Table();
15.187 + taskTable.setSelectable(true);
15.188 + taskTable.setEditable(false);
15.189 + taskTable.setImmediate(true);
15.190 + taskTable.setSizeFull();
15.191 + taskTable.setContainerDataSource(taskContainer);
15.192 + taskTable.setVisibleColumns(new String[]{
15.193 + "name",
15.194 + "description",
15.195 + });
15.196 + taskTable.setColumnWidth("description", 300);
15.197 + vlMain.addComponent(taskTable);
15.198 + vlMain.setExpandRatio(taskTable, 1f);
15.199 +
15.200 + LocalEntityProvider workProvider = new CachingLocalEntityProvider(Work.class);
15.201 + workProvider.setEntityManager(EM);
15.202 + JPAContainer<Task> workContainer = new JPAContainer(Work.class);
15.203 + workContainer.setEntityProvider(workProvider);
15.204 +
15.205 + workTable = new Table();
15.206 + workTable.setSelectable(false);
15.207 + workTable.setEditable(false);
15.208 + workTable.setImmediate(true);
15.209 + workTable.setSizeFull();
15.210 + workTable.setContainerDataSource(workContainer);
15.211 + workTable.setVisibleColumns(new String[]{
15.212 + "day",
15.213 + "task",
15.214 + "hours",
15.215 + "result",
15.216 + });
15.217 + workTable.setColumnWidth("result", 200);
15.218 + workTable.setSortContainerPropertyId("day");
15.219 + vlMain.addComponent(workTable);
15.220 + vlMain.setExpandRatio(workTable, 1f);
15.221 + }
15.222 +
15.223 + public Table getDayTable() {
15.224 + return dayTable;
15.225 + }
15.226 +
15.227 + public Table getTaskTable() {
15.228 + return taskTable;
15.229 + }
15.230 +
15.231 + public Table getWorkTable() {
15.232 + return workTable;
15.233 + }
15.234 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/mywork-web/src/main/resources/META-INF/persistence.xml Wed Nov 23 17:52:25 2011 +0300
16.3 @@ -0,0 +1,21 @@
16.4 +<?xml version="1.0" encoding="UTF-8"?>
16.5 +<persistence
16.6 + version="1.0"
16.7 + xmlns="http://java.sun.com/xml/ns/persistence"
16.8 + >
16.9 + <persistence-unit name="mywork">
16.10 + <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
16.11 +
16.12 + <class>ru.indvdum.mywork.openjpa.model.Day</class>
16.13 + <class>ru.indvdum.mywork.openjpa.model.Task</class>
16.14 + <class>ru.indvdum.mywork.openjpa.model.Work</class>
16.15 + <class>ru.indvdum.mywork.openjpa.model.WorkId</class>
16.16 +
16.17 + <properties>
16.18 + <property name="openjpa.ConnectionPassword" value="1"/>
16.19 + <property name="openjpa.ConnectionDriverName" value="oracle.jdbc.OracleDriver"/>
16.20 + <property name="openjpa.ConnectionUserName" value="d_mywork"/>
16.21 + <property name="openjpa.ConnectionURL" value="jdbc:oracle:thin:@minidev:1521:ora"/>
16.22 + </properties>
16.23 + </persistence-unit>
16.24 +</persistence>
17.1 --- a/pom.xml Wed Nov 23 17:25:20 2011 +0300
17.2 +++ b/pom.xml Wed Nov 23 17:52:25 2011 +0300
17.3 @@ -1,18 +1,16 @@
17.4 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
17.5 +<?xml version="1.0" encoding="UTF-8"?>
17.6 +<project>
17.7 <modelVersion>4.0.0</modelVersion>
17.8 - <groupId>ru.indvdum</groupId>
17.9 - <artifactId>mywork</artifactId>
17.10 - <version>0.0.1-SNAPSHOT</version>
17.11 - <description>My Work</description>
17.12 + <groupId>ru.indvdum.mywork</groupId>
17.13 + <artifactId>mywork-all</artifactId>
17.14 + <name>mywork</name>
17.15 + <version>0.0.1.0-SNAPSHOT</version>
17.16 + <packaging>pom</packaging>
17.17 <properties>
17.18 - <jetty.version>6.1.26</jetty.version>
17.19 - <vaadin.version>6.5.0</vaadin.version>
17.20 - <gwt.version>2.1.1</gwt.version>
17.21 - <oracle.jdbc.version>10.1.0.5.0</oracle.jdbc.version>
17.22 - <openjpa.version>2.1.1</openjpa.version>
17.23 <commons-dbcp.version>1.4</commons-dbcp.version>
17.24 <derby.version>10.8.2.2</derby.version>
17.25 <groovy.version>1.8.0</groovy.version>
17.26 + <openjpa.version>2.1.1</openjpa.version>
17.27 <maven-compiler-plugin.version>2.3.2</maven-compiler-plugin.version>
17.28 <groovy-eclipse-compiler.version>2.5.1-1</groovy-eclipse-compiler.version>
17.29 <build-helper-maven-plugin.version>1.5</build-helper-maven-plugin.version>
17.30 @@ -25,70 +23,22 @@
17.31 <resources>
17.32 <resource>
17.33 <directory>src/main/resources</directory>
17.34 - <filtering>false</filtering>
17.35 + <filtering>true</filtering>
17.36 </resource>
17.37 </resources>
17.38 <plugins>
17.39 <plugin>
17.40 + <groupId>org.apache.maven.plugins</groupId>
17.41 <artifactId>maven-compiler-plugin</artifactId>
17.42 <version>${maven-compiler-plugin.version}</version>
17.43 <configuration>
17.44 - <compilerId>groovy-eclipse-compiler</compilerId>
17.45 - <compilerArgument>nowarn</compilerArgument>
17.46 - <verbose>true</verbose>
17.47 + <source>1.6</source>
17.48 + <target>1.6</target>
17.49 + <encoding>UTF-8</encoding>
17.50 + <fork>true</fork>
17.51 + <meminitial>128m</meminitial>
17.52 + <maxmem>512m</maxmem>
17.53 </configuration>
17.54 - <dependencies>
17.55 - <dependency>
17.56 - <groupId>org.codehaus.groovy</groupId>
17.57 - <artifactId>groovy-eclipse-compiler</artifactId>
17.58 - <version>${groovy-eclipse-compiler.version}</version>
17.59 - </dependency>
17.60 - </dependencies>
17.61 - </plugin>
17.62 - <plugin>
17.63 - <groupId>org.codehaus.mojo</groupId>
17.64 - <artifactId>build-helper-maven-plugin</artifactId>
17.65 - <version>${build-helper-maven-plugin.version}</version>
17.66 - <executions>
17.67 - <execution>
17.68 - <id>add-source</id>
17.69 - <phase>generate-sources</phase>
17.70 - <goals>
17.71 - <goal>add-source</goal>
17.72 - </goals>
17.73 - <configuration>
17.74 - <sources>
17.75 - <source>src/main/groovy</source>
17.76 - <source>src/test/groovy</source>
17.77 - </sources>
17.78 - </configuration>
17.79 - </execution>
17.80 - </executions>
17.81 - </plugin>
17.82 - <plugin>
17.83 - <groupId>org.codehaus.mojo</groupId>
17.84 - <artifactId>openjpa-maven-plugin</artifactId>
17.85 - <configuration>
17.86 - <includes>**/model/**/*.class</includes>
17.87 - <addDefaultConstructor>true</addDefaultConstructor>
17.88 - <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
17.89 - </configuration>
17.90 - <executions>
17.91 - <execution>
17.92 - <id>enhancer</id>
17.93 - <phase>process-classes</phase>
17.94 - <goals>
17.95 - <goal>enhance</goal>
17.96 - </goals>
17.97 - </execution>
17.98 - </executions>
17.99 - <dependencies>
17.100 - <dependency>
17.101 - <groupId>org.apache.openjpa</groupId>
17.102 - <artifactId>openjpa</artifactId>
17.103 - <version>${openjpa.version}</version>
17.104 - </dependency>
17.105 - </dependencies>
17.106 </plugin>
17.107 <plugin>
17.108 <groupId>org.apache.maven.plugins</groupId>
17.109 @@ -98,40 +48,6 @@
17.110 <encoding>UTF-8</encoding>
17.111 </configuration>
17.112 </plugin>
17.113 - <plugin>
17.114 - <artifactId>maven-source-plugin</artifactId>
17.115 - <configuration>
17.116 - <attach>true</attach>
17.117 - </configuration>
17.118 - <executions>
17.119 - <execution>
17.120 - <phase>generate-sources</phase>
17.121 - <goals>
17.122 - <goal>jar</goal>
17.123 - </goals>
17.124 - </execution>
17.125 - </executions>
17.126 - </plugin>
17.127 - <plugin>
17.128 - <groupId>org.codehaus.mojo</groupId>
17.129 - <artifactId>exec-maven-plugin</artifactId>
17.130 - <version>1.2</version>
17.131 - <executions>
17.132 - <execution>
17.133 - <goals>
17.134 - <goal>exec</goal>
17.135 - </goals>
17.136 - </execution>
17.137 - </executions>
17.138 - <configuration>
17.139 - <executable>java</executable>
17.140 - <arguments>
17.141 - <argument>-classpath</argument>
17.142 - <classpath/>
17.143 - <argument>ru.indvdum.mywork.MyWork</argument>
17.144 - </arguments>
17.145 - </configuration>
17.146 - </plugin>
17.147 </plugins>
17.148 <pluginManagement>
17.149 <plugins>
17.150 @@ -169,6 +85,20 @@
17.151 </plugins>
17.152 </pluginManagement>
17.153 </build>
17.154 + <dependencyManagement>
17.155 + <dependencies>
17.156 + <dependency>
17.157 + <groupId>ru.indvdum.mywork</groupId>
17.158 + <artifactId>mywork-model</artifactId>
17.159 + <version>${project.version}</version>
17.160 + </dependency>
17.161 + <dependency>
17.162 + <groupId>ru.indvdum.mywork</groupId>
17.163 + <artifactId>mywork-web</artifactId>
17.164 + <version>${project.version}</version>
17.165 + </dependency>
17.166 + </dependencies>
17.167 + </dependencyManagement>
17.168 <dependencies>
17.169 <dependency>
17.170 <groupId>org.slf4j</groupId>
17.171 @@ -181,58 +111,9 @@
17.172 <version>${junit.version}</version>
17.173 <scope>test</scope>
17.174 </dependency>
17.175 - <dependency>
17.176 - <groupId>org.mortbay.jetty</groupId>
17.177 - <artifactId>jetty</artifactId>
17.178 - <version>${jetty.version}</version>
17.179 - </dependency>
17.180 - <dependency>
17.181 - <groupId>com.vaadin</groupId>
17.182 - <artifactId>vaadin</artifactId>
17.183 - <version>${vaadin.version}</version>
17.184 - </dependency>
17.185 - <dependency>
17.186 - <groupId>com.vaadin.addon</groupId>
17.187 - <artifactId>jpacontainer-addon-agpl-3.0</artifactId>
17.188 - <version>1.2.0</version>
17.189 - <exclusions>
17.190 - <exclusion>
17.191 - <groupId>javax.persistence</groupId>
17.192 - <artifactId>persistence-api</artifactId>
17.193 - </exclusion>
17.194 - </exclusions>
17.195 - </dependency>
17.196 - <dependency>
17.197 - <groupId>com.google.gwt</groupId>
17.198 - <artifactId>gwt-user</artifactId>
17.199 - <version>${gwt.version}</version>
17.200 - </dependency>
17.201 - <dependency>
17.202 - <groupId>com.oracle</groupId>
17.203 - <artifactId>ojdbc14</artifactId>
17.204 - <version>${oracle.jdbc.version}</version>
17.205 - </dependency>
17.206 - <dependency>
17.207 - <groupId>org.apache.openjpa</groupId>
17.208 - <artifactId>openjpa</artifactId>
17.209 - <version>${openjpa.version}</version>
17.210 - </dependency>
17.211 - <dependency>
17.212 - <groupId>org.codehaus.groovy</groupId>
17.213 - <artifactId>groovy-all</artifactId>
17.214 - <version>${groovy.version}</version>
17.215 - </dependency>
17.216 - <dependency>
17.217 - <groupId>commons-dbcp</groupId>
17.218 - <artifactId>commons-dbcp</artifactId>
17.219 - <version>${commons-dbcp.version}</version>
17.220 - <scope>test</scope>
17.221 - </dependency>
17.222 - <dependency>
17.223 - <groupId>org.apache.derby</groupId>
17.224 - <artifactId>derby</artifactId>
17.225 - <version>${derby.version}</version>
17.226 - <scope>test</scope>
17.227 - </dependency>
17.228 </dependencies>
17.229 + <modules>
17.230 + <module>mywork-model</module>
17.231 + <module>mywork-web</module>
17.232 + </modules>
17.233 </project>
18.1 --- a/src/main/java/ru/indvdum/mywork/MyWork.java Wed Nov 23 17:25:20 2011 +0300
18.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
18.3 @@ -1,78 +0,0 @@
18.4 -package ru.indvdum.mywork;
18.5 -
18.6 -import java.util.Date;
18.7 -
18.8 -import javax.persistence.EntityManager;
18.9 -import javax.persistence.EntityManagerFactory;
18.10 -import javax.persistence.Persistence;
18.11 -
18.12 -import org.mortbay.component.LifeCycle;
18.13 -import org.mortbay.component.LifeCycle.Listener;
18.14 -import org.mortbay.jetty.Connector;
18.15 -import org.mortbay.jetty.Server;
18.16 -import org.mortbay.jetty.servlet.Context;
18.17 -import org.mortbay.jetty.servlet.ServletHolder;
18.18 -
18.19 -import com.vaadin.terminal.gwt.server.ApplicationServlet;
18.20 -
18.21 -/**
18.22 - * @author indvdum
18.23 - * 12.08.2011 17:31:37
18.24 - *
18.25 - */
18.26 -public class MyWork {
18.27 - public static EntityManagerFactory EMF = null;
18.28 - public static EntityManager EM = null;
18.29 -
18.30 - /**
18.31 - * @param args
18.32 - * @throws Exception
18.33 - */
18.34 - public static void main(String[] args) throws Exception {
18.35 - Server server = new Server();
18.36 - Connector connector = new org.mortbay.jetty.nio.SelectChannelConnector();
18.37 - connector.setPort(8080);
18.38 - connector.setMaxIdleTime(720000);
18.39 - server.addConnector(connector);
18.40 -
18.41 - Context root = new Context(server, "/", Context.SESSIONS);
18.42 - ServletHolder vaadinServlet = new ServletHolder(new ApplicationServlet());
18.43 - vaadinServlet.setInitParameter("application", "ru.indvdum.mywork.vaadin.MyWorkApplication");
18.44 - root.addServlet(vaadinServlet, "/*");
18.45 -
18.46 - server.addLifeCycleListener(new Listener(){
18.47 -
18.48 - @Override
18.49 - public void lifeCycleFailure(LifeCycle event, Throwable cause) {
18.50 -
18.51 - }
18.52 -
18.53 - @Override
18.54 - public void lifeCycleStarted(LifeCycle event) {
18.55 - EMF = Persistence.createEntityManagerFactory("mywork");
18.56 - EM = EMF.createEntityManager();
18.57 - }
18.58 -
18.59 - @Override
18.60 - public void lifeCycleStarting(LifeCycle event) {
18.61 -
18.62 - }
18.63 -
18.64 - @Override
18.65 - public void lifeCycleStopped(LifeCycle event) {
18.66 -
18.67 - }
18.68 -
18.69 - @Override
18.70 - public void lifeCycleStopping(LifeCycle event) {
18.71 - EM.close();
18.72 - EMF.close();
18.73 - }
18.74 -
18.75 - });
18.76 -
18.77 - server.start();
18.78 - System.out.println("Jetty server started at " + new Date());
18.79 - }
18.80 -
18.81 -}
19.1 --- a/src/main/java/ru/indvdum/mywork/openjpa/model/Day.java Wed Nov 23 17:25:20 2011 +0300
19.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
19.3 @@ -1,119 +0,0 @@
19.4 -package ru.indvdum.mywork.openjpa.model;
19.5 -
19.6 -import java.sql.Time;
19.7 -import java.text.DateFormat;
19.8 -import java.text.SimpleDateFormat;
19.9 -import java.util.Date;
19.10 -
19.11 -import javax.persistence.Column;
19.12 -import javax.persistence.Entity;
19.13 -import javax.persistence.GeneratedValue;
19.14 -import javax.persistence.GenerationType;
19.15 -import javax.persistence.Id;
19.16 -import javax.persistence.Table;
19.17 -
19.18 -/**
19.19 - * @author indvdum
19.20 - * 12.08.2011 17:31:00
19.21 - *
19.22 - */
19.23 -@Entity
19.24 -@Table(name = "DAYS")
19.25 -public class Day implements IDatabaseObject {
19.26 -
19.27 - private static final long serialVersionUID = 1471705339524132968L;
19.28 -
19.29 - @Id
19.30 - @GeneratedValue(strategy = GenerationType.IDENTITY)
19.31 - @Column(name = "ID", nullable = false)
19.32 - private Integer id = null;
19.33 -
19.34 - @Column(name = "DAY")
19.35 - private Date day = null;
19.36 -
19.37 - @Column(name = "STARTWORK")
19.38 - private Time startWork = null;
19.39 -
19.40 - @Column(name = "ENDWORK")
19.41 - private Time endWork = null;
19.42 -
19.43 - @Column(name = "HOURS")
19.44 - private Float hours = null;
19.45 -
19.46 - public Day(){
19.47 -
19.48 - }
19.49 -
19.50 - @Override
19.51 - public boolean equals(Object obj) {
19.52 - if (this == obj)
19.53 - return true;
19.54 - if (obj == null)
19.55 - return false;
19.56 - if (!(obj instanceof Day))
19.57 - return false;
19.58 - final Day other = (Day) obj;
19.59 - return (getId() == other.getId() || (getId() != null && getId().equals(other.getId())));
19.60 - }
19.61 -
19.62 - @Override
19.63 - public int hashCode() {
19.64 - if(getId() != null && getId() != 0)
19.65 - return getId().hashCode();
19.66 - else
19.67 - return super.hashCode();
19.68 - }
19.69 -
19.70 - @Override
19.71 - public String toString() {
19.72 - return getDateFormatter().format(getDay());
19.73 - }
19.74 -
19.75 - public Integer getId() {
19.76 - return id;
19.77 - }
19.78 -
19.79 - public void setId(Integer id) {
19.80 - this.id = id;
19.81 - }
19.82 -
19.83 - public Date getDay() {
19.84 - return day;
19.85 - }
19.86 -
19.87 - public String getFormattedDay() {
19.88 - return toString();
19.89 - }
19.90 -
19.91 - public void setDay(Date day) {
19.92 - this.day = day;
19.93 - }
19.94 -
19.95 - public Time getStartWork() {
19.96 - return startWork;
19.97 - }
19.98 -
19.99 - public void setStartWork(Time startWork) {
19.100 - this.startWork = startWork;
19.101 - }
19.102 -
19.103 - public Time getEndWork() {
19.104 - return endWork;
19.105 - }
19.106 -
19.107 - public void setEndWork(Time endWork) {
19.108 - this.endWork = endWork;
19.109 - }
19.110 -
19.111 - public Float getHours() {
19.112 - return hours;
19.113 - }
19.114 -
19.115 - public void setHours(Float hours) {
19.116 - this.hours = hours;
19.117 - }
19.118 -
19.119 - protected DateFormat getDateFormatter() {
19.120 - return new SimpleDateFormat("dd.MM.yyyy");
19.121 - }
19.122 -}
20.1 --- a/src/main/java/ru/indvdum/mywork/openjpa/model/IDatabaseObject.java Wed Nov 23 17:25:20 2011 +0300
20.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
20.3 @@ -1,12 +0,0 @@
20.4 -package ru.indvdum.mywork.openjpa.model;
20.5 -
20.6 -import java.io.Serializable;
20.7 -
20.8 -/**
20.9 - * @author indvdum
20.10 - * 12.08.2011 17:31:11
20.11 - *
20.12 - */
20.13 -public interface IDatabaseObject extends Serializable {
20.14 -
20.15 -}
21.1 --- a/src/main/java/ru/indvdum/mywork/openjpa/model/Task.java Wed Nov 23 17:25:20 2011 +0300
21.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
21.3 @@ -1,84 +0,0 @@
21.4 -package ru.indvdum.mywork.openjpa.model;
21.5 -
21.6 -import javax.persistence.Column;
21.7 -import javax.persistence.Entity;
21.8 -import javax.persistence.GeneratedValue;
21.9 -import javax.persistence.GenerationType;
21.10 -import javax.persistence.Id;
21.11 -import javax.persistence.Table;
21.12 -
21.13 -/**
21.14 - * @author indvdum
21.15 - * 16.08.2011 9:02:32
21.16 - *
21.17 - */
21.18 -@Entity
21.19 -@Table(name = "TASKS")
21.20 -public class Task implements IDatabaseObject {
21.21 -
21.22 - private static final long serialVersionUID = -4457948503094306717L;
21.23 -
21.24 - @Id
21.25 - @GeneratedValue(strategy = GenerationType.SEQUENCE)
21.26 - @Column(name = "ID", nullable = false)
21.27 - private Integer id = null;
21.28 -
21.29 - @Column(name = "NAME")
21.30 - private String name = null;
21.31 -
21.32 - @Column(name = "DESCRIPTION")
21.33 - private String description = null;
21.34 -
21.35 - public Task(){
21.36 -
21.37 - }
21.38 -
21.39 - @Override
21.40 - public boolean equals(Object obj) {
21.41 - if (this == obj)
21.42 - return true;
21.43 - if (obj == null)
21.44 - return false;
21.45 - if (!(obj instanceof Task))
21.46 - return false;
21.47 - final Task other = (Task) obj;
21.48 - return (getId() == other.getId() || (getId() != null && getId().equals(other.getId())));
21.49 - }
21.50 -
21.51 - @Override
21.52 - public int hashCode() {
21.53 - if(getId() != null && getId() != 0)
21.54 - return getId().hashCode();
21.55 - else
21.56 - return super.hashCode();
21.57 - }
21.58 -
21.59 - @Override
21.60 - public String toString() {
21.61 - return getName();
21.62 - }
21.63 -
21.64 - public Integer getId() {
21.65 - return id;
21.66 - }
21.67 -
21.68 - public void setId(Integer id) {
21.69 - this.id = id;
21.70 - }
21.71 -
21.72 - public String getName() {
21.73 - return name != null ? name : "";
21.74 - }
21.75 -
21.76 - public void setName(String name) {
21.77 - this.name = name;
21.78 - }
21.79 -
21.80 - public String getDescription() {
21.81 - return description != null ? description : "";
21.82 - }
21.83 -
21.84 - public void setDescription(String description) {
21.85 - this.description = description;
21.86 - }
21.87 -}
22.1 --- a/src/main/java/ru/indvdum/mywork/openjpa/model/Work.java Wed Nov 23 17:25:20 2011 +0300
22.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
22.3 @@ -1,84 +0,0 @@
22.4 -package ru.indvdum.mywork.openjpa.model;
22.5 -
22.6 -import javax.persistence.Column;
22.7 -import javax.persistence.EmbeddedId;
22.8 -import javax.persistence.Entity;
22.9 -import javax.persistence.FetchType;
22.10 -import javax.persistence.GeneratedValue;
22.11 -import javax.persistence.ManyToOne;
22.12 -import javax.persistence.MapsId;
22.13 -import javax.persistence.Table;
22.14 -
22.15 -/**
22.16 - * @author indvdum
22.17 - * 16.08.2011 13:55:51
22.18 - *
22.19 - */
22.20 -@Entity
22.21 -@Table(name = "WORK")
22.22 -public class Work implements IDatabaseObject {
22.23 -
22.24 - private static final long serialVersionUID = 7138260708537798813L;
22.25 -
22.26 - @EmbeddedId
22.27 - private WorkId id = null;
22.28 -
22.29 - @Column(name = "HOURS")
22.30 - private Float hours = null;
22.31 -
22.32 - @Column(name = "RESULT")
22.33 - private String result = null;
22.34 -
22.35 - @MapsId("dayId")
22.36 - @ManyToOne(fetch = FetchType.EAGER)
22.37 - private Day day = null;
22.38 -
22.39 - @MapsId("taskId")
22.40 - @ManyToOne(fetch = FetchType.EAGER)
22.41 - private Task task = null;
22.42 -
22.43 - public Work(){
22.44 -
22.45 - }
22.46 -
22.47 - public Float getHours() {
22.48 - return hours;
22.49 - }
22.50 -
22.51 - public void setHours(Float hours) {
22.52 - this.hours = hours;
22.53 - }
22.54 -
22.55 - public String getResult() {
22.56 - return result;
22.57 - }
22.58 -
22.59 - public void setResult(String result) {
22.60 - this.result = result;
22.61 - }
22.62 -
22.63 - public Day getDay() {
22.64 - return day;
22.65 - }
22.66 -
22.67 - public void setDay(Day day) {
22.68 - this.day = day;
22.69 - }
22.70 -
22.71 - public Task getTask() {
22.72 - return task;
22.73 - }
22.74 -
22.75 - public void setTask(Task task) {
22.76 - this.task = task;
22.77 - }
22.78 -
22.79 - public WorkId getId() {
22.80 - return id;
22.81 - }
22.82 -
22.83 - public void setId(WorkId id) {
22.84 - this.id = id;
22.85 - }
22.86 -
22.87 -}
23.1 --- a/src/main/java/ru/indvdum/mywork/openjpa/model/WorkId.java Wed Nov 23 17:25:20 2011 +0300
23.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
23.3 @@ -1,42 +0,0 @@
23.4 -package ru.indvdum.mywork.openjpa.model;
23.5 -
23.6 -import javax.persistence.Embeddable;
23.7 -
23.8 -/**
23.9 - * @author indvdum
23.10 - * 17.08.2011 15:00:35
23.11 - *
23.12 - */
23.13 -@Embeddable
23.14 -public class WorkId{
23.15 -
23.16 - public Integer dayId;
23.17 - public Integer taskId;
23.18 -
23.19 - @Override
23.20 - public boolean equals(Object obj) {
23.21 - if (this == obj)
23.22 - return true;
23.23 - if (obj == null)
23.24 - return false;
23.25 - if (!(obj instanceof WorkId))
23.26 - return false;
23.27 - final WorkId other = (WorkId) obj;
23.28 - return (
23.29 - this.dayId == other.dayId
23.30 - && this.taskId == other.taskId
23.31 - || (
23.32 - this.dayId != null
23.33 - && this.dayId.equals(other.dayId)
23.34 - && this.taskId != null
23.35 - && this.taskId.equals(other.taskId)
23.36 - )
23.37 - );
23.38 - }
23.39 -
23.40 - @Override
23.41 - public int hashCode() {
23.42 - return dayId ^ taskId;
23.43 - }
23.44 -
23.45 -}
24.1 --- a/src/main/java/ru/indvdum/mywork/vaadin/EditDayDialog.java Wed Nov 23 17:25:20 2011 +0300
24.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
24.3 @@ -1,243 +0,0 @@
24.4 -package ru.indvdum.mywork.vaadin;
24.5 -
24.6 -import static ru.indvdum.mywork.MyWork.EM;
24.7 -
24.8 -import java.sql.Time;
24.9 -import java.text.SimpleDateFormat;
24.10 -import java.util.Calendar;
24.11 -import java.util.Date;
24.12 -
24.13 -import ru.indvdum.mywork.openjpa.model.Day;
24.14 -
24.15 -import com.vaadin.data.Property.ValueChangeEvent;
24.16 -import com.vaadin.data.Property.ValueChangeListener;
24.17 -import com.vaadin.ui.Alignment;
24.18 -import com.vaadin.ui.Button;
24.19 -import com.vaadin.ui.HorizontalLayout;
24.20 -import com.vaadin.ui.Label;
24.21 -import com.vaadin.ui.PopupDateField;
24.22 -import com.vaadin.ui.TextField;
24.23 -import com.vaadin.ui.VerticalLayout;
24.24 -import com.vaadin.ui.Window;
24.25 -import com.vaadin.ui.Button.ClickEvent;
24.26 -import com.vaadin.ui.Button.ClickListener;
24.27 -
24.28 -/**
24.29 - * @author indvdum
24.30 - * 23.08.2011 19:11:35
24.31 - *
24.32 - */
24.33 -public class EditDayDialog extends Window implements ValueChangeListener, ClickListener {
24.34 -
24.35 - private MyWorkApplication myApp = null;
24.36 - private EditState state = null;
24.37 - private Day day = null;
24.38 - private PopupDateField dayStartTime = null;
24.39 - private PopupDateField dayEndTime = null;
24.40 - private PopupDateField dayDate = null;
24.41 - private TextField dayHours = null;
24.42 -
24.43 - public EditDayDialog(MyWorkApplication myApp, Day day) throws Exception {
24.44 - super();
24.45 - this.myApp = myApp;
24.46 - if(day == null)
24.47 - state = EditState.CREATE;
24.48 - else
24.49 - state = EditState.EDIT;
24.50 - switch(state){
24.51 - case CREATE:
24.52 - setCaption("Creating new day");
24.53 - day = new Day();
24.54 - Calendar calDay = Calendar.getInstance();
24.55 - calDay.set(Calendar.HOUR_OF_DAY, 0);
24.56 - calDay.set(Calendar.MINUTE, 0);
24.57 - calDay.set(Calendar.SECOND, 0);
24.58 - calDay.set(Calendar.MILLISECOND, 0);
24.59 - day.setDay(calDay.getTime());
24.60 - Calendar calStart = Calendar.getInstance();
24.61 - calStart.set(Calendar.HOUR_OF_DAY, 9);
24.62 - calStart.set(Calendar.MINUTE, 0);
24.63 - calStart.set(Calendar.SECOND, 0);
24.64 - calStart.set(Calendar.MILLISECOND, 0);
24.65 - day.setStartWork(new Time(calStart.getTime().getTime()));
24.66 - Calendar calEnd = Calendar.getInstance();
24.67 - calEnd.set(Calendar.HOUR_OF_DAY, 18);
24.68 - calEnd.set(Calendar.MINUTE, 0);
24.69 - calEnd.set(Calendar.SECOND, 0);
24.70 - calEnd.set(Calendar.MILLISECOND, 0);
24.71 - day.setEndWork(new Time(calEnd.getTime().getTime()));
24.72 - day.setHours(8f);
24.73 - this.day = day;
24.74 - break;
24.75 - case EDIT:
24.76 - setCaption("Editing day");
24.77 - this.day = day;
24.78 - break;
24.79 - }
24.80 - init();
24.81 - }
24.82 -
24.83 - private void init(){
24.84 - setModal(true);
24.85 - setWidth("480px");
24.86 - setHeight("300px");
24.87 - VerticalLayout vl = new VerticalLayout();
24.88 - vl.setSizeFull();
24.89 - vl.setSpacing(true);
24.90 - vl.setMargin(true);
24.91 - setContent(vl);
24.92 -
24.93 - HorizontalLayout hlDay = new HorizontalLayout();
24.94 - hlDay.setWidth("100%");
24.95 - Label lblDay = new Label("Day:");
24.96 - lblDay.setWidth("100%");
24.97 - hlDay.addComponent(lblDay);
24.98 - hlDay.setExpandRatio(lblDay, 1f);
24.99 - dayDate = new PopupDateField();
24.100 - dayDate.setWidth("100%");
24.101 - dayDate.setInputPrompt("Enter date");
24.102 - dayDate.setResolution(PopupDateField.RESOLUTION_DAY);
24.103 - dayDate.setImmediate(true);
24.104 - dayDate.setValue(day.getDay());
24.105 - dayDate.addListener(this);
24.106 - dayDate.setDateFormat("dd.MM.yyyy");
24.107 - hlDay.addComponent(dayDate);
24.108 - hlDay.setExpandRatio(dayDate, 5f);
24.109 - vl.addComponent(hlDay);
24.110 -
24.111 - HorizontalLayout hlStart = new HorizontalLayout();
24.112 - hlStart.setWidth("100%");
24.113 - Label lblStart = new Label("Start time:");
24.114 - lblStart.setWidth("100%");
24.115 - hlStart.addComponent(lblStart);
24.116 - hlStart.setExpandRatio(lblStart, 1f);
24.117 - dayStartTime = new PopupDateField();
24.118 - dayStartTime.setWidth("100%");
24.119 - dayStartTime.setInputPrompt("Enter time");
24.120 - dayStartTime.setResolution(PopupDateField.RESOLUTION_MIN);
24.121 - dayStartTime.setImmediate(true);
24.122 - dayStartTime.setValue(day.getStartWork());
24.123 - dayStartTime.setDateFormat("HH:mm");
24.124 - hlStart.addComponent(dayStartTime);
24.125 - hlStart.setExpandRatio(dayStartTime, 5f);
24.126 - vl.addComponent(hlStart);
24.127 -
24.128 - HorizontalLayout hlEnd = new HorizontalLayout();
24.129 - hlEnd.setWidth("100%");
24.130 - Label lblEnd = new Label("End time:");
24.131 - lblEnd.setWidth("100%");
24.132 - hlEnd.addComponent(lblEnd);
24.133 - hlEnd.setExpandRatio(lblEnd, 1f);
24.134 - dayEndTime = new PopupDateField();
24.135 - dayEndTime.setWidth("100%");
24.136 - dayEndTime.setInputPrompt("Enter time");
24.137 - dayEndTime.setResolution(PopupDateField.RESOLUTION_MIN);
24.138 - dayEndTime.setImmediate(true);
24.139 - dayEndTime.setValue(day.getEndWork());
24.140 - dayEndTime.setDateFormat("HH:mm");
24.141 - hlEnd.addComponent(dayEndTime);
24.142 - hlEnd.setExpandRatio(dayEndTime, 5f);
24.143 - vl.addComponent(hlEnd);
24.144 -
24.145 - HorizontalLayout hlHours = new HorizontalLayout();
24.146 - hlHours.setWidth("100%");
24.147 - Label lblHours = new Label("Work hours count:");
24.148 - lblHours.setWidth("100%");
24.149 - hlHours.addComponent(lblHours);
24.150 - hlHours.setExpandRatio(lblHours, 1f);
24.151 - dayHours = new TextField();
24.152 - dayHours.setWidth("100%");
24.153 - dayHours.setValue(day.getHours());
24.154 - dayHours.setImmediate(true);
24.155 - hlHours.addComponent(dayHours);
24.156 - hlHours.setExpandRatio(dayHours, 5f);
24.157 - vl.addComponent(hlHours);
24.158 -
24.159 - HorizontalLayout hlOk = new HorizontalLayout();
24.160 - hlOk.setSizeFull();
24.161 - Button okButton = new Button();
24.162 - switch(state){
24.163 - case CREATE:
24.164 - okButton.setCaption("Create");
24.165 - break;
24.166 - case EDIT:
24.167 - okButton.setCaption("Save");
24.168 - break;
24.169 - }
24.170 - okButton.addListener((ClickListener)this);
24.171 - hlOk.addComponent(okButton);
24.172 - hlOk.setComponentAlignment(okButton, Alignment.BOTTOM_RIGHT);
24.173 - vl.addComponent(hlOk);
24.174 - vl.setExpandRatio(hlOk, 1f);
24.175 - }
24.176 -
24.177 - @Override
24.178 - public void valueChange(ValueChangeEvent event) {
24.179 - Object value = event.getProperty().getValue();
24.180 - Object startValue = dayStartTime.getValue();
24.181 - Object endValue = dayEndTime.getValue();
24.182 - if (value == null || !(value instanceof Date) || !(startValue instanceof Date) || !(endValue instanceof Date)) {
24.183 - getWindow().showNotification("Invalid date entered");
24.184 - } else {
24.185 - Date date = (Date)value;
24.186 - Date start = (Date)startValue;
24.187 - Date end = (Date)endValue;
24.188 - Calendar calStart = Calendar.getInstance();
24.189 - calStart.setTime(start);
24.190 - Calendar calEnd = Calendar.getInstance();
24.191 - calEnd.setTime(end);
24.192 - Calendar cal = Calendar.getInstance();
24.193 - cal.setTime(date);
24.194 - calStart.set(Calendar.YEAR, cal.get(Calendar.YEAR));
24.195 - calStart.set(Calendar.MONTH, cal.get(Calendar.MONTH));
24.196 - calStart.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH));
24.197 - calStart.set(Calendar.SECOND, cal.get(Calendar.SECOND));
24.198 - calStart.set(Calendar.MILLISECOND, cal.get(Calendar.MILLISECOND));
24.199 - calEnd.set(Calendar.YEAR, cal.get(Calendar.YEAR));
24.200 - calEnd.set(Calendar.MONTH, cal.get(Calendar.MONTH));
24.201 - calEnd.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH));
24.202 - calEnd.set(Calendar.SECOND, cal.get(Calendar.SECOND));
24.203 - calEnd.set(Calendar.MILLISECOND, cal.get(Calendar.MILLISECOND));
24.204 - dayStartTime.setValue(calStart.getTime());
24.205 - dayEndTime.setValue(calEnd.getTime());
24.206 - }
24.207 - }
24.208 -
24.209 - @Override
24.210 - public void buttonClick(ClickEvent event) {
24.211 - Object value = dayDate.getValue();
24.212 - Object startValue = dayStartTime.getValue();
24.213 - Object endValue = dayEndTime.getValue();
24.214 - Object hoursValue = dayHours.getValue();
24.215 - if (
24.216 - value == null
24.217 - || !(value instanceof Date)
24.218 - || !(startValue instanceof Date)
24.219 - || !(endValue instanceof Date)
24.220 - || !(hoursValue.toString().matches("^[0-9]+[\\.]{0,1}[0-9]*"))
24.221 - ) {
24.222 - getWindow().showNotification("Invalid information entered");
24.223 - } else {
24.224 - Date date = (Date)value;
24.225 - Date start = (Date)startValue;
24.226 - Date end = (Date)endValue;
24.227 - Float hours = Float.parseFloat(hoursValue.toString());
24.228 - day.setDay(date);
24.229 - day.setStartWork(new Time(start.getTime()));
24.230 - day.setEndWork(new Time(end.getTime()));
24.231 - day.setHours(hours);
24.232 - try{
24.233 - EM.getTransaction().begin();
24.234 - EM.persist(day);
24.235 - EM.getTransaction().commit();
24.236 - EM.clear();
24.237 - } finally {
24.238 - if(EM.getTransaction().isActive())
24.239 - EM.getTransaction().rollback();
24.240 - }
24.241 - getParent().removeWindow(this);
24.242 - myApp.getDayTable().requestRepaint();
24.243 - }
24.244 - }
24.245 -
24.246 -}
25.1 --- a/src/main/java/ru/indvdum/mywork/vaadin/EditState.java Wed Nov 23 17:25:20 2011 +0300
25.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
25.3 @@ -1,11 +0,0 @@
25.4 -package ru.indvdum.mywork.vaadin;
25.5 -
25.6 -/**
25.7 - * @author indvdum
25.8 - * 23.08.2011 19:11:44
25.9 - *
25.10 - */
25.11 -public enum EditState {
25.12 - CREATE,
25.13 - EDIT,
25.14 -}
26.1 --- a/src/main/java/ru/indvdum/mywork/vaadin/EditTaskDialog.java Wed Nov 23 17:25:20 2011 +0300
26.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
26.3 @@ -1,116 +0,0 @@
26.4 -package ru.indvdum.mywork.vaadin;
26.5 -
26.6 -import static ru.indvdum.mywork.MyWork.EM;
26.7 -import ru.indvdum.mywork.openjpa.model.Task;
26.8 -
26.9 -import com.vaadin.ui.Alignment;
26.10 -import com.vaadin.ui.Button;
26.11 -import com.vaadin.ui.HorizontalLayout;
26.12 -import com.vaadin.ui.Label;
26.13 -import com.vaadin.ui.RichTextArea;
26.14 -import com.vaadin.ui.TextField;
26.15 -import com.vaadin.ui.VerticalLayout;
26.16 -import com.vaadin.ui.Window;
26.17 -import com.vaadin.ui.Button.ClickEvent;
26.18 -import com.vaadin.ui.Button.ClickListener;
26.19 -
26.20 -/**
26.21 - * @author indvdum
26.22 - * 23.08.2011 19:11:50
26.23 - *
26.24 - */
26.25 -public class EditTaskDialog extends Window implements ClickListener {
26.26 -
26.27 - private MyWorkApplication myApp = null;
26.28 - private EditState state = null;
26.29 - private Task task = null;
26.30 - private TextField taskName = null;
26.31 - private RichTextArea taskDescription = null;
26.32 -
26.33 - public EditTaskDialog(MyWorkApplication myApp, Task task) throws Exception {
26.34 - super();
26.35 - this.myApp = myApp;
26.36 - if(task == null)
26.37 - state = EditState.CREATE;
26.38 - else
26.39 - state = EditState.EDIT;
26.40 - switch(state){
26.41 - case CREATE:
26.42 - setCaption("Creating new task");
26.43 - task = new Task();
26.44 - task.setName("");
26.45 - task.setDescription("");
26.46 - this.task = task;
26.47 - break;
26.48 - case EDIT:
26.49 - setCaption("Editing task");
26.50 - this.task = task;
26.51 - break;
26.52 - }
26.53 - init();
26.54 - }
26.55 -
26.56 - private void init(){
26.57 - setModal(true);
26.58 - setWidth("640px");
26.59 - setHeight("480px");
26.60 - VerticalLayout vl = new VerticalLayout();
26.61 - vl.setSizeFull();
26.62 - vl.setSpacing(true);
26.63 - vl.setMargin(true);
26.64 - setContent(vl);
26.65 -
26.66 - HorizontalLayout hlName = new HorizontalLayout();
26.67 - hlName.setWidth("100%");
26.68 - Label lblName = new Label("Name:");
26.69 - lblName.setWidth("100%");
26.70 - hlName.addComponent(lblName);
26.71 - hlName.setExpandRatio(lblName, 1f);
26.72 - taskName = new TextField();
26.73 - taskName.setWidth("100%");
26.74 - taskName.setValue(task.getName());
26.75 - hlName.addComponent(taskName);
26.76 - hlName.setExpandRatio(taskName, 5f);
26.77 - vl.addComponent(hlName);
26.78 -
26.79 - taskDescription = new RichTextArea("Description");
26.80 - taskDescription.setValue(task.getDescription());
26.81 - taskDescription.setSizeFull();
26.82 - vl.addComponent(taskDescription);
26.83 - vl.setExpandRatio(taskDescription, 1f);
26.84 -
26.85 - HorizontalLayout hlOk = new HorizontalLayout();
26.86 - hlOk.setWidth("100%");
26.87 - Button okButton = new Button();
26.88 - switch(state){
26.89 - case CREATE:
26.90 - okButton.setCaption("Create");
26.91 - break;
26.92 - case EDIT:
26.93 - okButton.setCaption("Save");
26.94 - break;
26.95 - }
26.96 - okButton.addListener((ClickListener)this);
26.97 - hlOk.addComponent(okButton);
26.98 - hlOk.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);
26.99 - vl.addComponent(hlOk);
26.100 - }
26.101 -
26.102 - @Override
26.103 - public void buttonClick(ClickEvent event) {
26.104 - task.setName(taskName.getValue().toString());
26.105 - task.setDescription(taskDescription.getValue().toString());
26.106 - try{
26.107 - EM.getTransaction().begin();
26.108 - EM.persist(task);
26.109 - EM.getTransaction().commit();
26.110 - EM.clear();
26.111 - } finally {
26.112 - if(EM.getTransaction().isActive())
26.113 - EM.getTransaction().rollback();
26.114 - }
26.115 - getParent().removeWindow(this);
26.116 - myApp.getTaskTable().requestRepaint();
26.117 - }
26.118 -
26.119 -}
27.1 --- a/src/main/java/ru/indvdum/mywork/vaadin/EditWorkDialog.java Wed Nov 23 17:25:20 2011 +0300
27.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
27.3 @@ -1,234 +0,0 @@
27.4 -package ru.indvdum.mywork.vaadin;
27.5 -
27.6 -import static ru.indvdum.mywork.MyWork.EM;
27.7 -
27.8 -import java.util.Calendar;
27.9 -import java.util.List;
27.10 -
27.11 -import javax.persistence.Query;
27.12 -
27.13 -import ru.indvdum.mywork.openjpa.model.Day;
27.14 -import ru.indvdum.mywork.openjpa.model.Task;
27.15 -import ru.indvdum.mywork.openjpa.model.Work;
27.16 -
27.17 -import com.vaadin.data.Property.ValueChangeEvent;
27.18 -import com.vaadin.data.Property.ValueChangeListener;
27.19 -import com.vaadin.ui.Alignment;
27.20 -import com.vaadin.ui.Button;
27.21 -import com.vaadin.ui.ComboBox;
27.22 -import com.vaadin.ui.HorizontalLayout;
27.23 -import com.vaadin.ui.Label;
27.24 -import com.vaadin.ui.RichTextArea;
27.25 -import com.vaadin.ui.TextField;
27.26 -import com.vaadin.ui.VerticalLayout;
27.27 -import com.vaadin.ui.Window;
27.28 -import com.vaadin.ui.AbstractSelect.Filtering;
27.29 -import com.vaadin.ui.Button.ClickEvent;
27.30 -import com.vaadin.ui.Button.ClickListener;
27.31 -
27.32 -/**
27.33 - * @author indvdum
27.34 - * 23.08.2011 19:11:56
27.35 - *
27.36 - */
27.37 -public class EditWorkDialog extends Window implements ClickListener {
27.38 -
27.39 - private MyWorkApplication myApp = null;
27.40 - private EditState state = null;
27.41 - private Work work = null;
27.42 - private ComboBox workDay = null;
27.43 - private ComboBox workTask = null;
27.44 - private TextField workHours = null;
27.45 - private RichTextArea workResult = null;
27.46 -
27.47 - public EditWorkDialog(MyWorkApplication myApp, Work work) throws Exception {
27.48 - super();
27.49 - this.myApp = myApp;
27.50 - if(work == null)
27.51 - state = EditState.CREATE;
27.52 - else
27.53 - state = EditState.EDIT;
27.54 - switch(state){
27.55 - case CREATE:
27.56 - setCaption("Creating new work");
27.57 - work = new Work();
27.58 - work.setHours(0f);
27.59 - work.setResult("");
27.60 - this.work = work;
27.61 - break;
27.62 - case EDIT:
27.63 - setCaption("Editing work");
27.64 - this.work = work;
27.65 - break;
27.66 - }
27.67 - init();
27.68 - }
27.69 -
27.70 - private void init(){
27.71 - setModal(true);
27.72 - setWidth("640px");
27.73 - setHeight("480px");
27.74 - VerticalLayout vl = new VerticalLayout();
27.75 - vl.setSizeFull();
27.76 - vl.setSpacing(true);
27.77 - vl.setMargin(true);
27.78 - setContent(vl);
27.79 -
27.80 - HorizontalLayout hlDay = new HorizontalLayout();
27.81 - hlDay.setWidth("100%");
27.82 - Label lblDay = new Label("Day:");
27.83 - lblDay.setWidth("100%");
27.84 - hlDay.addComponent(lblDay);
27.85 - hlDay.setExpandRatio(lblDay, 1f);
27.86 - workDay = new ComboBox();
27.87 - workDay.setWidth("100%");
27.88 - workDay.setImmediate(true);
27.89 - workDay.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
27.90 - updateDays("select d from " + Day.class.getName() + " d order by d.day");
27.91 - workDay.addListener(new ValueChangeListener(){
27.92 -
27.93 - @Override
27.94 - public void valueChange(ValueChangeEvent event) {
27.95 - Day day = (Day)event.getProperty().getValue();
27.96 - if(day == null)
27.97 - updateTasks("select t from " + Task.class.getName() + " t order by t.id desc");
27.98 - else
27.99 - updateTasks("select t from " + Task.class.getName() + " t where t.id not in (select w.task.id from " + Work.class.getName() + " w where w.day.id = " + day.getId() + ") order by t.id desc");
27.100 - }
27.101 -
27.102 - });
27.103 - hlDay.addComponent(workDay);
27.104 - hlDay.setExpandRatio(workDay, 5f);
27.105 - vl.addComponent(hlDay);
27.106 -
27.107 - HorizontalLayout hlTask = new HorizontalLayout();
27.108 - hlTask.setWidth("100%");
27.109 - Label lblStart = new Label("Task:");
27.110 - lblStart.setWidth("100%");
27.111 - hlTask.addComponent(lblStart);
27.112 - hlTask.setExpandRatio(lblStart, 1f);
27.113 - workTask = new ComboBox();
27.114 - workTask.setWidth("100%");
27.115 - workTask.setImmediate(true);
27.116 - workTask.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
27.117 - Day day = (Day)workDay.getValue();
27.118 - if(day == null)
27.119 - updateTasks("select t from " + Task.class.getName() + " t order by t.id desc");
27.120 - else
27.121 - updateTasks("select t from " + Task.class.getName() + " t where t.id not in (select w.task.id from " + Work.class.getName() + " w where w.day.id = " + day.getId() + ") order by t.id desc");
27.122 - workTask.addListener(new ValueChangeListener(){
27.123 -
27.124 - @Override
27.125 - public void valueChange(ValueChangeEvent event) {
27.126 - Task task = (Task)event.getProperty().getValue();
27.127 - if(task == null)
27.128 - updateDays("select d from " + Day.class.getName() + " d order by d.day");
27.129 - else
27.130 - updateDays("select d from " + Day.class.getName() + " d where d.id not in (select w.day.id from " + Work.class.getName() + " w where w.task.id = " + task.getId() + ") order by d.day");
27.131 - }
27.132 -
27.133 - });
27.134 - hlTask.addComponent(workTask);
27.135 - hlTask.setExpandRatio(workTask, 5f);
27.136 - vl.addComponent(hlTask);
27.137 -
27.138 - HorizontalLayout hlHours = new HorizontalLayout();
27.139 - hlHours.setWidth("100%");
27.140 - Label lblHours = new Label("Hours:");
27.141 - lblHours.setWidth("100%");
27.142 - hlHours.addComponent(lblHours);
27.143 - hlHours.setExpandRatio(lblHours, 1f);
27.144 - workHours = new TextField();
27.145 - workHours.setWidth("100%");
27.146 - workHours.setValue(work.getHours());
27.147 - workHours.setImmediate(true);
27.148 - hlHours.addComponent(workHours);
27.149 - hlHours.setExpandRatio(workHours, 5f);
27.150 - vl.addComponent(hlHours);
27.151 -
27.152 - workResult = new RichTextArea("Result");
27.153 - workResult.setValue(work.getResult());
27.154 - workResult.setSizeFull();
27.155 - vl.addComponent(workResult);
27.156 - vl.setExpandRatio(workResult, 5f);
27.157 -
27.158 - HorizontalLayout hlOk = new HorizontalLayout();
27.159 - hlOk.setWidth("100%");
27.160 - Button okButton = new Button();
27.161 - switch(state){
27.162 - case CREATE:
27.163 - okButton.setCaption("Create");
27.164 - break;
27.165 - case EDIT:
27.166 - okButton.setCaption("Save");
27.167 - break;
27.168 - }
27.169 - okButton.addListener((ClickListener)this);
27.170 - hlOk.addComponent(okButton);
27.171 - hlOk.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);
27.172 - vl.addComponent(hlOk);
27.173 - }
27.174 -
27.175 - private void updateDays(String jpql){
27.176 - if(workTask != null && workTask.getValue() != null && workDay != null && workDay.getValue() != null)
27.177 - return;
27.178 - workDay.removeAllItems();
27.179 - Query query = EM.createQuery(jpql);
27.180 - List list = query.getResultList();
27.181 - for(Day day: (List<Day>)list){
27.182 - workDay.addItem(day);
27.183 - Calendar currCal = Calendar.getInstance();
27.184 - currCal.set(Calendar.HOUR_OF_DAY, 0);
27.185 - currCal.set(Calendar.MINUTE, 0);
27.186 - currCal.set(Calendar.SECOND, 0);
27.187 - currCal.set(Calendar.MILLISECOND, 0);
27.188 - if(day.getDay().equals(currCal.getTime()))
27.189 - workDay.select(day);
27.190 - }
27.191 - }
27.192 -
27.193 - private void updateTasks(String jpql){
27.194 - if(workTask != null && workTask.getValue() != null && workDay != null && workDay.getValue() != null)
27.195 - return;
27.196 - workTask.removeAllItems();
27.197 - Query query = EM.createQuery(jpql);
27.198 - List list = query.getResultList();
27.199 - for(Task task: (List<Task>)list)
27.200 - workTask.addItem(task);
27.201 - }
27.202 -
27.203 - @Override
27.204 - public void buttonClick(ClickEvent event) {
27.205 - Object dayObj = workDay.getValue();
27.206 - Object taskObj = workTask.getValue();
27.207 - Object hoursObj = workHours.getValue();
27.208 - String result = workResult.getValue().toString();
27.209 - if (
27.210 - !(dayObj instanceof Day)
27.211 - || !(taskObj instanceof Task)
27.212 - || !(hoursObj.toString().matches("^[0-9]+[\\.]{0,1}[0-9]*"))
27.213 - ) {
27.214 - getWindow().showNotification("Invalid information entered");
27.215 - } else {
27.216 - Day day = (Day)dayObj;
27.217 - Task task = (Task)taskObj;
27.218 - Float hours = Float.parseFloat(hoursObj.toString());
27.219 - work.setDay(day);
27.220 - work.setTask(task);
27.221 - work.setHours(hours);
27.222 - work.setResult(result);
27.223 - try{
27.224 - EM.getTransaction().begin();
27.225 - EM.persist(work);
27.226 - EM.getTransaction().commit();
27.227 - EM.clear();
27.228 - } finally {
27.229 - if(EM.getTransaction().isActive())
27.230 - EM.getTransaction().rollback();
27.231 - }
27.232 - getParent().removeWindow(this);
27.233 - myApp.getWorkTable().requestRepaint();
27.234 - }
27.235 - }
27.236 -
27.237 -}
28.1 --- a/src/main/java/ru/indvdum/mywork/vaadin/MyWorkApplication.java Wed Nov 23 17:25:20 2011 +0300
28.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
28.3 @@ -1,231 +0,0 @@
28.4 -package ru.indvdum.mywork.vaadin;
28.5 -
28.6 -import static ru.indvdum.mywork.MyWork.EM;
28.7 -
28.8 -import java.util.List;
28.9 -
28.10 -import javax.persistence.Query;
28.11 -
28.12 -import ru.indvdum.mywork.openjpa.model.Day;
28.13 -import ru.indvdum.mywork.openjpa.model.Task;
28.14 -import ru.indvdum.mywork.openjpa.model.Work;
28.15 -
28.16 -import com.vaadin.Application;
28.17 -import com.vaadin.addon.jpacontainer.EntityContainer;
28.18 -import com.vaadin.addon.jpacontainer.EntityProvider;
28.19 -import com.vaadin.addon.jpacontainer.HierarchicalEntityContainer;
28.20 -import com.vaadin.addon.jpacontainer.JPAContainer;
28.21 -import com.vaadin.addon.jpacontainer.provider.BatchableLocalEntityProvider;
28.22 -import com.vaadin.addon.jpacontainer.provider.CachingBatchableLocalEntityProvider;
28.23 -import com.vaadin.addon.jpacontainer.provider.CachingLocalEntityProvider;
28.24 -import com.vaadin.addon.jpacontainer.provider.CachingMutableLocalEntityProvider;
28.25 -import com.vaadin.addon.jpacontainer.provider.LocalEntityProvider;
28.26 -import com.vaadin.ui.Alignment;
28.27 -import com.vaadin.ui.Button;
28.28 -import com.vaadin.ui.HorizontalLayout;
28.29 -import com.vaadin.ui.MenuBar;
28.30 -import com.vaadin.ui.TabSheet;
28.31 -import com.vaadin.ui.Table;
28.32 -import com.vaadin.ui.VerticalLayout;
28.33 -import com.vaadin.ui.Window;
28.34 -import com.vaadin.ui.Button.ClickEvent;
28.35 -import com.vaadin.ui.Button.ClickListener;
28.36 -import com.vaadin.ui.MenuBar.Command;
28.37 -import com.vaadin.ui.MenuBar.MenuItem;
28.38 -
28.39 -/**
28.40 - * @author indvdum
28.41 - * 12.08.2011 17:31:53
28.42 - *
28.43 - */
28.44 -public class MyWorkApplication extends Application {
28.45 -
28.46 - private MyWorkApplication thisObject = this;
28.47 - private Table dayTable = null;
28.48 - private Table taskTable = null;
28.49 - private Table workTable = null;
28.50 -
28.51 - private Command newDayCommand = new Command() {
28.52 - public void menuSelected(MenuItem selectedItem) {
28.53 - EditDayDialog dialog = null;
28.54 - try {
28.55 - dialog = new EditDayDialog(thisObject, null);
28.56 - } catch (Exception e) {
28.57 - e.printStackTrace();
28.58 - }
28.59 - getMainWindow().addWindow(dialog);
28.60 - }
28.61 - };
28.62 - private Command newTaskCommand = new Command() {
28.63 - public void menuSelected(MenuItem selectedItem) {
28.64 - EditTaskDialog dialog = null;
28.65 - try {
28.66 - dialog = new EditTaskDialog(thisObject, null);
28.67 - } catch (Exception e) {
28.68 - e.printStackTrace();
28.69 - }
28.70 - getMainWindow().addWindow(dialog);
28.71 - }
28.72 - };
28.73 - private Command newWorkCommand = new Command() {
28.74 - public void menuSelected(MenuItem selectedItem) {
28.75 - EditWorkDialog dialog = null;
28.76 - try {
28.77 - dialog = new EditWorkDialog(thisObject, null);
28.78 - } catch (Exception e) {
28.79 - e.printStackTrace();
28.80 - }
28.81 - getMainWindow().addWindow(dialog);
28.82 - }
28.83 - };
28.84 - private Command editDayCommand = new Command() {
28.85 - public void menuSelected(MenuItem selectedItem) {
28.86 - EditDayDialog dialog = null;
28.87 - Day day = EM.find(Day.class, dayTable.getValue());
28.88 - if(day == null)
28.89 - return;
28.90 - try {
28.91 - dialog = new EditDayDialog(thisObject, day);
28.92 - } catch (Exception e) {
28.93 - e.printStackTrace();
28.94 - }
28.95 - getMainWindow().addWindow(dialog);
28.96 - }
28.97 - };
28.98 - private Command editTaskCommand = new Command() {
28.99 - public void menuSelected(MenuItem selectedItem) {
28.100 - EditTaskDialog dialog = null;
28.101 - Task task = EM.find(Task.class, taskTable.getValue());
28.102 - if(task == null)
28.103 - return;
28.104 - try {
28.105 - dialog = new EditTaskDialog(thisObject, task);
28.106 - } catch (Exception e) {
28.107 - e.printStackTrace();
28.108 - }
28.109 - getMainWindow().addWindow(dialog);
28.110 - }
28.111 - };
28.112 - private Command editWorkCommand = new Command() {
28.113 - public void menuSelected(MenuItem selectedItem) {
28.114 - EditWorkDialog dialog = null;
28.115 - Work work = EM.find(Work.class, workTable.getValue());
28.116 - if(work == null)
28.117 - return;
28.118 - try {
28.119 - dialog = new EditWorkDialog(thisObject, work);
28.120 - } catch (Exception e) {
28.121 - e.printStackTrace();
28.122 - }
28.123 - getMainWindow().addWindow(dialog);
28.124 - }
28.125 - };
28.126 -
28.127 - @Override
28.128 - public void init() {
28.129 - Window window = new Window();
28.130 - setMainWindow(window);
28.131 -
28.132 - TabSheet tabSheet = new TabSheet();
28.133 - tabSheet.setSizeFull();
28.134 - window.setContent(tabSheet);
28.135 -
28.136 - VerticalLayout vlMain = new VerticalLayout();
28.137 - vlMain.setSizeFull();
28.138 - vlMain.setMargin(true);
28.139 - vlMain.setSpacing(true);
28.140 - tabSheet.addTab(vlMain, "Main page", null);
28.141 -
28.142 - MenuBar menuBar = new MenuBar();
28.143 - MenuItem file = menuBar.addItem("File", null);
28.144 - MenuItem newItem = file.addItem("New", null);
28.145 - newItem.addItem("Day...", newDayCommand);
28.146 - newItem.addItem("Task...", newTaskCommand);
28.147 - newItem.addItem("Work...", newWorkCommand);
28.148 - MenuItem edit = menuBar.addItem("Edit", null);
28.149 - edit.addItem("Day...", editDayCommand);
28.150 - edit.addItem("Task...", editTaskCommand);
28.151 - edit.addItem("Work...", editWorkCommand);
28.152 - vlMain.addComponent(menuBar);
28.153 -
28.154 - LocalEntityProvider dayProvider = new CachingLocalEntityProvider(Day.class);
28.155 - dayProvider.setEntityManager(EM);
28.156 - JPAContainer<Day> dayContainer = new JPAContainer(Day.class);
28.157 - dayContainer.setEntityProvider(dayProvider);
28.158 -
28.159 - dayTable = new Table();
28.160 - dayTable.setSelectable(true);
28.161 - dayTable.setEditable(false);
28.162 - dayTable.setImmediate(true);
28.163 - dayTable.setSizeFull();
28.164 - dayTable.setContainerDataSource(dayContainer);
28.165 - dayTable.setVisibleColumns(new String[]{
28.166 - "formattedDay",
28.167 - "startWork",
28.168 - "endWork",
28.169 - "hours",
28.170 - });
28.171 - dayTable.setSortContainerPropertyId("day");
28.172 - dayTable.setColumnHeaders(new String[]{
28.173 - "day",
28.174 - "startWork",
28.175 - "endWork",
28.176 - "hours",
28.177 - });
28.178 - vlMain.addComponent(dayTable);
28.179 - vlMain.setExpandRatio(dayTable, 1f);
28.180 -
28.181 - LocalEntityProvider taskProvider = new CachingLocalEntityProvider(Task.class);
28.182 - taskProvider.setEntityManager(EM);
28.183 - JPAContainer<Task> taskContainer = new JPAContainer(Task.class);
28.184 - taskContainer.setEntityProvider(taskProvider);
28.185 -
28.186 - taskTable = new Table();
28.187 - taskTable.setSelectable(true);
28.188 - taskTable.setEditable(false);
28.189 - taskTable.setImmediate(true);
28.190 - taskTable.setSizeFull();
28.191 - taskTable.setContainerDataSource(taskContainer);
28.192 - taskTable.setVisibleColumns(new String[]{
28.193 - "name",
28.194 - "description",
28.195 - });
28.196 - taskTable.setColumnWidth("description", 300);
28.197 - vlMain.addComponent(taskTable);
28.198 - vlMain.setExpandRatio(taskTable, 1f);
28.199 -
28.200 - LocalEntityProvider workProvider = new CachingLocalEntityProvider(Work.class);
28.201 - workProvider.setEntityManager(EM);
28.202 - JPAContainer<Task> workContainer = new JPAContainer(Work.class);
28.203 - workContainer.setEntityProvider(workProvider);
28.204 -
28.205 - workTable = new Table();
28.206 - workTable.setSelectable(false);
28.207 - workTable.setEditable(false);
28.208 - workTable.setImmediate(true);
28.209 - workTable.setSizeFull();
28.210 - workTable.setContainerDataSource(workContainer);
28.211 - workTable.setVisibleColumns(new String[]{
28.212 - "day",
28.213 - "task",
28.214 - "hours",
28.215 - "result",
28.216 - });
28.217 - workTable.setColumnWidth("result", 200);
28.218 - workTable.setSortContainerPropertyId("day");
28.219 - vlMain.addComponent(workTable);
28.220 - vlMain.setExpandRatio(workTable, 1f);
28.221 - }
28.222 -
28.223 - public Table getDayTable() {
28.224 - return dayTable;
28.225 - }
28.226 -
28.227 - public Table getTaskTable() {
28.228 - return taskTable;
28.229 - }
28.230 -
28.231 - public Table getWorkTable() {
28.232 - return workTable;
28.233 - }
28.234 -}
29.1 --- a/src/main/resources/META-INF/persistence.xml Wed Nov 23 17:25:20 2011 +0300
29.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
29.3 @@ -1,21 +0,0 @@
29.4 -<?xml version="1.0" encoding="UTF-8"?>
29.5 -<persistence
29.6 - version="1.0"
29.7 - xmlns="http://java.sun.com/xml/ns/persistence"
29.8 - >
29.9 - <persistence-unit name="mywork">
29.10 - <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
29.11 -
29.12 - <class>ru.indvdum.mywork.openjpa.model.Day</class>
29.13 - <class>ru.indvdum.mywork.openjpa.model.Task</class>
29.14 - <class>ru.indvdum.mywork.openjpa.model.Work</class>
29.15 - <class>ru.indvdum.mywork.openjpa.model.WorkId</class>
29.16 -
29.17 - <properties>
29.18 - <property name="openjpa.ConnectionPassword" value="1"/>
29.19 - <property name="openjpa.ConnectionDriverName" value="oracle.jdbc.OracleDriver"/>
29.20 - <property name="openjpa.ConnectionUserName" value="d_mywork"/>
29.21 - <property name="openjpa.ConnectionURL" value="jdbc:oracle:thin:@minidev:1521:ora"/>
29.22 - </properties>
29.23 - </persistence-unit>
29.24 -</persistence>