src/main/java/ru/indvdum/mywork/vaadin/MyWorkApplication.java
changeset 16 2d6a668325f9
parent 15 739f329b9e1e
     1.1 --- a/src/main/java/ru/indvdum/mywork/vaadin/MyWorkApplication.java	Wed Nov 23 17:25:20 2011 +0300
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,231 +0,0 @@
     1.4 -package ru.indvdum.mywork.vaadin;
     1.5 -
     1.6 -import static ru.indvdum.mywork.MyWork.EM;
     1.7 -
     1.8 -import java.util.List;
     1.9 -
    1.10 -import javax.persistence.Query;
    1.11 -
    1.12 -import ru.indvdum.mywork.openjpa.model.Day;
    1.13 -import ru.indvdum.mywork.openjpa.model.Task;
    1.14 -import ru.indvdum.mywork.openjpa.model.Work;
    1.15 -
    1.16 -import com.vaadin.Application;
    1.17 -import com.vaadin.addon.jpacontainer.EntityContainer;
    1.18 -import com.vaadin.addon.jpacontainer.EntityProvider;
    1.19 -import com.vaadin.addon.jpacontainer.HierarchicalEntityContainer;
    1.20 -import com.vaadin.addon.jpacontainer.JPAContainer;
    1.21 -import com.vaadin.addon.jpacontainer.provider.BatchableLocalEntityProvider;
    1.22 -import com.vaadin.addon.jpacontainer.provider.CachingBatchableLocalEntityProvider;
    1.23 -import com.vaadin.addon.jpacontainer.provider.CachingLocalEntityProvider;
    1.24 -import com.vaadin.addon.jpacontainer.provider.CachingMutableLocalEntityProvider;
    1.25 -import com.vaadin.addon.jpacontainer.provider.LocalEntityProvider;
    1.26 -import com.vaadin.ui.Alignment;
    1.27 -import com.vaadin.ui.Button;
    1.28 -import com.vaadin.ui.HorizontalLayout;
    1.29 -import com.vaadin.ui.MenuBar;
    1.30 -import com.vaadin.ui.TabSheet;
    1.31 -import com.vaadin.ui.Table;
    1.32 -import com.vaadin.ui.VerticalLayout;
    1.33 -import com.vaadin.ui.Window;
    1.34 -import com.vaadin.ui.Button.ClickEvent;
    1.35 -import com.vaadin.ui.Button.ClickListener;
    1.36 -import com.vaadin.ui.MenuBar.Command;
    1.37 -import com.vaadin.ui.MenuBar.MenuItem;
    1.38 -
    1.39 -/**
    1.40 - * @author indvdum
    1.41 - * 12.08.2011 17:31:53
    1.42 - *
    1.43 - */
    1.44 -public class MyWorkApplication extends Application {
    1.45 -	
    1.46 -	private MyWorkApplication thisObject = this;
    1.47 -	private Table dayTable = null;
    1.48 -	private Table taskTable = null;
    1.49 -	private Table workTable = null;
    1.50 -	
    1.51 -	private Command newDayCommand = new Command() {
    1.52 -        public void menuSelected(MenuItem selectedItem) {
    1.53 -        	EditDayDialog dialog = null;
    1.54 -			try {
    1.55 -				dialog = new EditDayDialog(thisObject, null);
    1.56 -			} catch (Exception e) {
    1.57 -				e.printStackTrace();
    1.58 -			}
    1.59 -            getMainWindow().addWindow(dialog);
    1.60 -        }
    1.61 -    };
    1.62 -    private Command newTaskCommand = new Command() {
    1.63 -    	public void menuSelected(MenuItem selectedItem) {
    1.64 -    		EditTaskDialog dialog = null;
    1.65 -    		try {
    1.66 -    			dialog = new EditTaskDialog(thisObject, null);
    1.67 -    		} catch (Exception e) {
    1.68 -    			e.printStackTrace();
    1.69 -    		}
    1.70 -    		getMainWindow().addWindow(dialog);
    1.71 -    	}
    1.72 -    };
    1.73 -    private Command newWorkCommand = new Command() {
    1.74 -    	public void menuSelected(MenuItem selectedItem) {
    1.75 -    		EditWorkDialog dialog = null;
    1.76 -    		try {
    1.77 -    			dialog = new EditWorkDialog(thisObject, null);
    1.78 -    		} catch (Exception e) {
    1.79 -    			e.printStackTrace();
    1.80 -    		}
    1.81 -    		getMainWindow().addWindow(dialog);
    1.82 -    	}
    1.83 -    };
    1.84 -    private Command editDayCommand = new Command() {
    1.85 -    	public void menuSelected(MenuItem selectedItem) {
    1.86 -    		EditDayDialog dialog = null;
    1.87 -    		Day day = EM.find(Day.class, dayTable.getValue());
    1.88 -    		if(day == null)
    1.89 -    			return;
    1.90 -    		try {
    1.91 -    			dialog = new EditDayDialog(thisObject, day);
    1.92 -    		} catch (Exception e) {
    1.93 -    			e.printStackTrace();
    1.94 -    		}
    1.95 -    		getMainWindow().addWindow(dialog);
    1.96 -    	}
    1.97 -    };
    1.98 -    private Command editTaskCommand = new Command() {
    1.99 -    	public void menuSelected(MenuItem selectedItem) {
   1.100 -    		EditTaskDialog dialog = null;
   1.101 -    		Task task = EM.find(Task.class, taskTable.getValue());
   1.102 -    		if(task == null)
   1.103 -    			return;
   1.104 -    		try {
   1.105 -    			dialog = new EditTaskDialog(thisObject, task);
   1.106 -    		} catch (Exception e) {
   1.107 -    			e.printStackTrace();
   1.108 -    		}
   1.109 -    		getMainWindow().addWindow(dialog);
   1.110 -    	}
   1.111 -    };
   1.112 -    private Command editWorkCommand = new Command() {
   1.113 -    	public void menuSelected(MenuItem selectedItem) {
   1.114 -    		EditWorkDialog dialog = null;
   1.115 -    		Work work = EM.find(Work.class, workTable.getValue());
   1.116 -    		if(work == null)
   1.117 -    			return;
   1.118 -    		try {
   1.119 -    			dialog = new EditWorkDialog(thisObject, work);
   1.120 -    		} catch (Exception e) {
   1.121 -    			e.printStackTrace();
   1.122 -    		}
   1.123 -    		getMainWindow().addWindow(dialog);
   1.124 -    	}
   1.125 -    };
   1.126 -
   1.127 -	@Override
   1.128 -	public void init() {
   1.129 -		Window window = new Window();
   1.130 -		setMainWindow(window);
   1.131 -		
   1.132 -		TabSheet tabSheet = new TabSheet();
   1.133 -		tabSheet.setSizeFull();
   1.134 -		window.setContent(tabSheet);
   1.135 -		
   1.136 -		VerticalLayout vlMain = new VerticalLayout();
   1.137 -		vlMain.setSizeFull();
   1.138 -		vlMain.setMargin(true);
   1.139 -		vlMain.setSpacing(true);
   1.140 -		tabSheet.addTab(vlMain, "Main page", null);
   1.141 -		
   1.142 -		MenuBar menuBar = new MenuBar();
   1.143 -		MenuItem file = menuBar.addItem("File", null);
   1.144 -		MenuItem newItem = file.addItem("New", null);
   1.145 -		newItem.addItem("Day...", newDayCommand);
   1.146 -        newItem.addItem("Task...", newTaskCommand);
   1.147 -        newItem.addItem("Work...", newWorkCommand);
   1.148 -        MenuItem edit = menuBar.addItem("Edit", null);
   1.149 -        edit.addItem("Day...", editDayCommand);
   1.150 -        edit.addItem("Task...", editTaskCommand);
   1.151 -        edit.addItem("Work...", editWorkCommand);
   1.152 -        vlMain.addComponent(menuBar);
   1.153 -		
   1.154 -		LocalEntityProvider dayProvider = new CachingLocalEntityProvider(Day.class);
   1.155 -		dayProvider.setEntityManager(EM);
   1.156 -		JPAContainer<Day> dayContainer = new JPAContainer(Day.class);
   1.157 -		dayContainer.setEntityProvider(dayProvider);
   1.158 -		
   1.159 -		dayTable = new Table();
   1.160 -		dayTable.setSelectable(true);
   1.161 -		dayTable.setEditable(false);
   1.162 -		dayTable.setImmediate(true);
   1.163 -		dayTable.setSizeFull();
   1.164 -		dayTable.setContainerDataSource(dayContainer);
   1.165 -		dayTable.setVisibleColumns(new String[]{
   1.166 -				"formattedDay",
   1.167 -				"startWork",
   1.168 -				"endWork",
   1.169 -				"hours",
   1.170 -		});
   1.171 -		dayTable.setSortContainerPropertyId("day");
   1.172 -		dayTable.setColumnHeaders(new String[]{
   1.173 -				"day",
   1.174 -				"startWork",
   1.175 -				"endWork",
   1.176 -				"hours",
   1.177 -		});
   1.178 -		vlMain.addComponent(dayTable);
   1.179 -		vlMain.setExpandRatio(dayTable, 1f);
   1.180 -		
   1.181 -		LocalEntityProvider taskProvider = new CachingLocalEntityProvider(Task.class);
   1.182 -		taskProvider.setEntityManager(EM);
   1.183 -		JPAContainer<Task> taskContainer = new JPAContainer(Task.class);
   1.184 -		taskContainer.setEntityProvider(taskProvider);
   1.185 -		
   1.186 -		taskTable = new Table();
   1.187 -		taskTable.setSelectable(true);
   1.188 -		taskTable.setEditable(false);
   1.189 -		taskTable.setImmediate(true);
   1.190 -		taskTable.setSizeFull();
   1.191 -		taskTable.setContainerDataSource(taskContainer);
   1.192 -		taskTable.setVisibleColumns(new String[]{
   1.193 -				"name",
   1.194 -				"description",
   1.195 -		});
   1.196 -		taskTable.setColumnWidth("description", 300);
   1.197 -		vlMain.addComponent(taskTable);
   1.198 -		vlMain.setExpandRatio(taskTable, 1f);
   1.199 -		
   1.200 -		LocalEntityProvider workProvider = new CachingLocalEntityProvider(Work.class);
   1.201 -		workProvider.setEntityManager(EM);
   1.202 -		JPAContainer<Task> workContainer = new JPAContainer(Work.class);
   1.203 -		workContainer.setEntityProvider(workProvider);
   1.204 -		
   1.205 -		workTable = new Table();
   1.206 -		workTable.setSelectable(false);
   1.207 -		workTable.setEditable(false);
   1.208 -		workTable.setImmediate(true);
   1.209 -		workTable.setSizeFull();
   1.210 -		workTable.setContainerDataSource(workContainer);
   1.211 -		workTable.setVisibleColumns(new String[]{
   1.212 -				"day",
   1.213 -				"task",
   1.214 -				"hours",
   1.215 -				"result",
   1.216 -		});
   1.217 -		workTable.setColumnWidth("result", 200);
   1.218 -		workTable.setSortContainerPropertyId("day");
   1.219 -		vlMain.addComponent(workTable);
   1.220 -		vlMain.setExpandRatio(workTable, 1f);
   1.221 -	}
   1.222 -
   1.223 -	public Table getDayTable() {
   1.224 -		return dayTable;
   1.225 -	}
   1.226 -
   1.227 -	public Table getTaskTable() {
   1.228 -		return taskTable;
   1.229 -	}
   1.230 -
   1.231 -	public Table getWorkTable() {
   1.232 -		return workTable;
   1.233 -	}
   1.234 -}