[mozzes] r25 committed - Working on Vaadin example.

4 views
Skip to first unread message

moz...@googlecode.com

unread,
Mar 3, 2010, 7:08:26 PM3/3/10
to mozzes-d...@googlegroups.com
Revision: 25
Author: perica.milosevic
Date: Wed Mar 3 15:07:43 2010
Log: Working on Vaadin example.
http://code.google.com/p/mozzes/source/detail?r=25

Added:
/trunk/mozzesApplication/mozzesApplicationExample/images

/trunk/mozzesApplication/mozzesApplicationExample/mozzesApplicationExampleVaadin/src/main/java/org/mozzes/application/example/vaadin/gui/MatchEditWindow.java
Modified:

/trunk/mozzesApplication/mozzesApplicationExample/mozzesApplicationExampleVaadin/src/main/java/org/mozzes/application/example/vaadin/gui/MainWindow.java

=======================================
--- /dev/null
+++
/trunk/mozzesApplication/mozzesApplicationExample/mozzesApplicationExampleVaadin/src/main/java/org/mozzes/application/example/vaadin/gui/MatchEditWindow.java
Wed Mar 3 15:07:43 2010
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2010 Mozzart
+ *
+ *
+ * This file is part of mozzes.
+ *
+ * mozzes is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * mozzes is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with mozzes. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.mozzes.application.example.vaadin.gui;
+
+import java.util.Date;
+import java.util.List;
+
+import org.mozzes.application.example.common.domain.Match;
+import org.mozzes.application.example.common.domain.Team;
+import org.mozzes.application.example.common.service.Administration;
+
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.FormLayout;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Layout;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+
+public class MatchEditWindow extends Window {
+
+ private static final long serialVersionUID = 3432589583281572169L;
+
+ private final MainWindow mainWindow;
+ private final Administration<Match> administration;
+ private final Match match;
+
+ private DateField startTime = new DateField("Start time");
+ private ComboBox homeTeamCombo = new ComboBox("Home team");
+ private ComboBox visitorTeamCombo = new ComboBox("Visitor team");
+
+ MatchEditWindow(MainWindow mainWindow, String title, Match match,
+ Administration<Match> administration, List<Team> teams) {
+ super(title);
+ setModal(true);
+ this.mainWindow = mainWindow;
+ this.administration = administration;
+ this.match = match;
+
+ startTime.setResolution(DateField.RESOLUTION_MIN);
+ homeTeamCombo.setNewItemsAllowed(false);
+ homeTeamCombo.setNullSelectionAllowed(false);
+ homeTeamCombo.addItem("");
+ visitorTeamCombo.setNewItemsAllowed(false);
+ visitorTeamCombo.setNullSelectionAllowed(false);
+ visitorTeamCombo.addItem("");
+ for (Team team : teams) {
+ homeTeamCombo.addItem(team);
+ visitorTeamCombo.addItem(team);
+ }
+
+ setMatch(match);
+
+ FormLayout form = new FormLayout();
+ form.setSizeUndefined();
+ form.addComponent(startTime);
+ form.addComponent(homeTeamCombo);
+ form.addComponent(visitorTeamCombo);
+
+ Button saveButton = new Button("Save");
+ saveButton.addListener(new ClickListener() {
+ private static final long serialVersionUID = 8515020970178194064L;
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ save();
+ }
+ });
+
+ HorizontalLayout actions = new HorizontalLayout();
+ actions.addComponent(saveButton);
+ actions.setComponentAlignment(saveButton, Alignment.MIDDLE_CENTER);
+
+ Layout layout = new VerticalLayout();
+ layout.setStyleName(STYLE_LIGHT);
+ layout.setSizeUndefined();
+ layout.setMargin(true);
+ layout.addComponent(form);
+ layout.addComponent(actions);
+ setContent(layout);
+ }
+
+ private void setMatch(Match match) {
+ startTime.setValue(match.getStartTime());
+ homeTeamCombo.setValue(match.getHomeTeam());
+ visitorTeamCombo.setValue(match.getVisitorTeam());
+ }
+
+ private void save() {
+ match.setStartTime((Date) startTime.getValue());
+ match.setHomeTeam((Team) homeTeamCombo.getValue());
+ match.setVisitorTeam((Team) visitorTeamCombo.getValue());
+ administration.save(match);
+ mainWindow.removeWindow(this);
+ mainWindow.reloadMatches();
+ }
+}
=======================================
---
/trunk/mozzesApplication/mozzesApplicationExample/mozzesApplicationExampleVaadin/src/main/java/org/mozzes/application/example/vaadin/gui/MainWindow.java
Wed Mar 3 13:56:07 2010
+++
/trunk/mozzesApplication/mozzesApplicationExample/mozzesApplicationExampleVaadin/src/main/java/org/mozzes/application/example/vaadin/gui/MainWindow.java
Wed Mar 3 15:07:43 2010
@@ -27,6 +27,7 @@
import org.mozzes.application.common.client.MozzesClient;
import org.mozzes.application.example.common.domain.Match;
import org.mozzes.application.example.common.domain.Team;
+import org.mozzes.application.example.common.exception.ExampleException;
import org.mozzes.application.example.common.service.MatchAdministration;
import org.mozzes.application.example.common.service.TeamAdministration;

@@ -107,8 +108,8 @@

private Table createTeamTable() {
teamTable = new Table(null, teamSource);
- teamTable.setVisibleColumns(new Object[] { "name", "image", "webAddress"
});
- teamTable.setColumnHeaders(new String[] { "Name", "Crest", "Web" });
+ teamTable.setVisibleColumns(new Object[] { "name", "webAddress" });
+ teamTable.setColumnHeaders(new String[] { "Name", "Web address" });
teamTable.setSelectable(true);
teamTable.setSizeFull();
return teamTable;
@@ -168,6 +169,26 @@

Button deleteTeamButton = new Button("Delete team");
deleteTeamButton.setIcon(new
ThemeResource("icons/32/document-delete.png"));
+ deleteTeamButton.addListener(new ClickListener() {
+ private static final long serialVersionUID = -2947855038156930283L;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Object selected = teamTable.getValue();
+ if (selected != null) {
+ Team selectedTeam = ((BeanItem<Team>)
teamTable.getItem(selected)).getBean();
+ try {
+ client.getService(TeamAdministration.class).delete(selectedTeam);
+ reloadTeams();
+ showNotification("Team " + selectedTeam.getName() + " deleted.");
+ } catch (ExampleException e) {
+ log.error(e.getMessage(), e);
+ }
+ } else
+ showNotification("No team selected!");
+ }
+ });

GridLayout teamButtonPanel = new GridLayout(4, 1);
teamButtonPanel.setHeight(40, UNITS_PIXELS);
@@ -187,6 +208,7 @@
matchTable = new Table(null, matchSource);
matchTable.setVisibleColumns(new Object[]
{ "startTime", "homeTeam", "visitorTeam", "result" });
matchTable.setColumnHeaders(new String[] { "Start time", "Home
team", "Visitor team", "Result" });
+ matchTable.setSelectable(true);
matchTable.setSizeFull();
return matchTable;
}
@@ -205,11 +227,59 @@

Button newMatchButton = new Button("New match");
newMatchButton.setIcon(new ThemeResource("icons/32/document-add.png"));
+ newMatchButton.addListener(new ClickListener() {
+ private static final long serialVersionUID = -5077272694928231857L;
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ addWindow(new MatchEditWindow(MainWindow.this, "New match",
+ new Match(), client
+ .getService(MatchAdministration.class), client
+ .getService(TeamAdministration.class).findAll()));
+ }
+ });

Button editMatchButton = new Button("Edit match");
editMatchButton.setIcon(new ThemeResource("icons/32/document-edit.png"));
+ editMatchButton.addListener(new ClickListener() {
+ private static final long serialVersionUID = -5792165786350656817L;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Object selected = matchTable.getValue();
+ if (selected != null) {
+ Match selectedMatch = ((BeanItem<Match>)
matchTable.getItem(selected)).getBean();
+ addWindow(new MatchEditWindow(MainWindow.this, "New match",
selectedMatch, client.getService(MatchAdministration.class),
+ client.getService(TeamAdministration.class).findAll()));
+ } else
+ showNotification("No match selected!");
+ }
+ });
+
+
Button deleteMatchButton = new Button("Delete match");
deleteMatchButton.setIcon(new
ThemeResource("icons/32/document-delete.png"));
+ deleteMatchButton.addListener(new ClickListener() {
+ private static final long serialVersionUID = 7338030844267083993L;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Object selected = matchTable.getValue();
+ if (selected != null) {
+ Match selectedMatch = ((BeanItem<Match>)
matchTable.getItem(selected)).getBean();
+ try {
+ client.getService(MatchAdministration.class).delete(selectedMatch);
+ reloadMatches();
+ showNotification("Match " + selectedMatch + " deleted.");
+ } catch (ExampleException e) {
+ log.error(e.getMessage(), e);
+ }
+ } else
+ showNotification("No match selected!");
+ }
+ });

GridLayout matchButtonPanel = new GridLayout(4, 1);
matchButtonPanel.setHeight(40, UNITS_PIXELS);

Reply all
Reply to author
Forward
0 new messages