[mozzes] r21 committed - Working on Vaadin example.

4 views
Skip to first unread message

moz...@googlecode.com

unread,
Feb 27, 2010, 12:33:05 PM2/27/10
to mozzes-d...@googlegroups.com
Revision: 21
Author: perica.milosevic
Date: Sat Feb 27 09:32:16 2010
Log: Working on Vaadin example.
http://code.google.com/p/mozzes/source/detail?r=21

Added:

/trunk/mozzesApplication/mozzesApplicationExample/mozzesApplicationExampleServer/src/main/java/org/mozzes/application/example/server/service/ImageUtils.java
Modified:

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

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

=======================================
--- /dev/null
+++
/trunk/mozzesApplication/mozzesApplicationExample/mozzesApplicationExampleServer/src/main/java/org/mozzes/application/example/server/service/ImageUtils.java
Sat Feb 27 09:32:16 2010
@@ -0,0 +1,33 @@
+/*
+ * 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.server.service;
+
+import java.io.File;
+
+public class ImageUtils {
+
+ private static final String IMAGE_PATH = ".." + File.separatorChar
+ "images" + File.separatorChar;
+
+ public static String generateImageFile() {
+ return IMAGE_PATH + "t" + Thread.currentThread().hashCode() +
System.currentTimeMillis();
+ }
+
+}
=======================================
---
/trunk/mozzesApplication/mozzesApplicationExample/mozzesApplicationExampleVaadin/src/main/java/org/mozzes/application/example/vaadin/gui/MainWindow.java
Sat Feb 27 06:56:25 2010
+++
/trunk/mozzesApplication/mozzesApplicationExample/mozzesApplicationExampleVaadin/src/main/java/org/mozzes/application/example/vaadin/gui/MainWindow.java
Sat Feb 27 09:32:16 2010
@@ -44,7 +44,6 @@
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;

-
@SessionScoped
public class MainWindow extends Window {

@@ -55,10 +54,10 @@
private final MozzesClient client;
private BeanItemContainer<Team> teamSource = new
BeanItemContainer<Team>(Team.class);
private BeanItemContainer<Match> matchSource = new
BeanItemContainer<Match>(Match.class);
-
+
private Table teamTable;
private Table matchTable;
-
+
@Inject
public MainWindow(MozzesClient client) {
super(TITLE);
@@ -79,7 +78,7 @@
Panel teamPanel = new Panel("Teams");
teamPanel.setContent(teamLayout);
teamPanel.setSizeFull();
-
+
VerticalLayout matchLayout = new VerticalLayout();
Table matchTable = createMatchTable();
matchLayout.addComponent(matchTable);
@@ -106,8 +105,8 @@

private Table createTeamTable() {
teamTable = new Table(null, teamSource);
- teamTable.setVisibleColumns(new
Object[]{"name", "crestImage", "webAddress"});
- teamTable.setColumnHeaders(new String[]{"Name", "Crest", "Web"});
+ teamTable.setVisibleColumns(new Object[]
{ "name", "crestImage", "webAddress" });
+ teamTable.setColumnHeaders(new String[] { "Name", "Crest", "Web" });
teamTable.setSelectable(true);
teamTable.setSizeFull();
return teamTable;
@@ -118,42 +117,47 @@
refreshTeamsButton.setIcon(new ThemeResource("icons/32/reload.png"));
refreshTeamsButton.addListener(new ClickListener() {
private static final long serialVersionUID = -4440833664676514934L;
+
@Override
public void buttonClick(ClickEvent event) {
reloadTeams();
}
});
-
+
Button newTeamButton = new Button("New team");
newTeamButton.setIcon(new ThemeResource("icons/32/document-add.png"));
newTeamButton.addListener(new ClickListener() {
private static final long serialVersionUID = -5792165786350656817L;
+
@Override
public void buttonClick(ClickEvent event) {
- addWindow(new TeamEditWindow(getApplication(), MainWindow.this, "New
team", new Team(), client.getService(TeamAdministration.class)));
+ addWindow(new TeamEditWindow(getApplication(), MainWindow.this, "New
team", new Team(), client
+ .getService(TeamAdministration.class)));
}
});
-
+
Button editTeamButton = new Button("Edit team");
editTeamButton.setIcon(new ThemeResource("icons/32/document-edit.png"));
editTeamButton.addListener(new ClickListener() {
private static final long serialVersionUID = -5792165786350656817L;
+
@SuppressWarnings("unchecked")
@Override
public void buttonClick(ClickEvent event) {
Object selected = teamTable.getValue();
if (selected != null) {
- Team selectedTeam =
((BeanItem<Team>)teamTable.getItem(selected)).getBean();
- addWindow(new TeamEditWindow(getApplication(), MainWindow.this, "Edit
team", selectedTeam, client.getService(TeamAdministration.class)));
+ Team selectedTeam = ((BeanItem<Team>)
teamTable.getItem(selected)).getBean();
+ addWindow(new TeamEditWindow(getApplication(), MainWindow.this, "Edit
team", selectedTeam, client
+ .getService(TeamAdministration.class)));
;
} else
showNotification("No team selected!");
}
});
-
+
Button deleteTeamButton = new Button("Delete team");
deleteTeamButton.setIcon(new
ThemeResource("icons/32/document-delete.png"));
-
+
GridLayout teamButtonPanel = new GridLayout(4, 1);
teamButtonPanel.setHeight(40, UNITS_PIXELS);
teamButtonPanel.setWidth(100, UNITS_PERCENTAGE);
@@ -170,8 +174,8 @@

private Table createMatchTable() {
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.setVisibleColumns(new Object[]
{ "startTime", "homeTeam", "visitorTeam", "result" });
+ matchTable.setColumnHeaders(new String[] { "Start time", "Home
team", "Visitor team", "Result" });
matchTable.setSizeFull();
return matchTable;
}
@@ -181,15 +185,16 @@
refreshMatchesButton.setIcon(new ThemeResource("icons/32/reload.png"));
refreshMatchesButton.addListener(new ClickListener() {
private static final long serialVersionUID = -4440833664676514934L;
+
@Override
public void buttonClick(ClickEvent event) {
reloadMatches();
}
});
-
+
Button newMatchButton = new Button("New match");
newMatchButton.setIcon(new ThemeResource("icons/32/document-add.png"));
-
+
Button editMatchButton = new Button("Edit match");
editMatchButton.setIcon(new ThemeResource("icons/32/document-edit.png"));
Button deleteMatchButton = new Button("Delete match");
@@ -208,7 +213,7 @@
matchButtonPanel.setComponentAlignment(deleteMatchButton,
Alignment.MIDDLE_LEFT);
return matchButtonPanel;
}
-
+
private void reloadData() {
reloadTeams();
reloadMatches();
@@ -216,23 +221,22 @@

void reloadMatches() {
matchSource.removeAllItems();
- for (Match match : getMatches())
+ for (Match match : getMatches())
matchSource.addBean(match);
}

void reloadTeams() {
teamSource.removeAllItems();
- for (Team team: getTeams())
+ for (Team team : getTeams())
teamSource.addBean(team);
}
-

private List<Team> getTeams() {
return client.getService(TeamAdministration.class).findAll();
}
-
+
private List<Match> getMatches() {
return client.getService(MatchAdministration.class).findAll();
}
-
-}
+
+}
=======================================
---
/trunk/mozzesApplication/mozzesApplicationExample/mozzesApplicationExampleVaadin/src/main/java/org/mozzes/application/example/vaadin/gui/TeamEditWindow.java
Sat Feb 27 09:02:30 2010
+++
/trunk/mozzesApplication/mozzesApplicationExample/mozzesApplicationExampleVaadin/src/main/java/org/mozzes/application/example/vaadin/gui/TeamEditWindow.java
Sat Feb 27 09:32:16 2010
@@ -26,6 +26,7 @@

import org.mozzes.application.example.common.domain.Team;
import org.mozzes.application.example.common.service.Administration;
+import org.mozzes.application.example.server.service.ImageUtils;

import com.vaadin.Application;
import com.vaadin.terminal.FileResource;
@@ -127,8 +128,6 @@
mainWindow.removeWindow(this);
mainWindow.reloadTeams();
}
-
- private static final String IMAGE_PATH = ".." + File.separatorChar
+ "images" + File.separatorChar;

private class ImageUploadListener implements Upload.SucceededListener,
Upload.FailedListener, Upload.Receiver {

@@ -152,7 +151,7 @@
if (team.getCrestImage() != null)
currentFileName = team.getCrestImage();
else
- currentFileName = generateImageFileName() + "." +
MIMEType.substring(MIMEType.indexOf('/') + 1);
+ currentFileName = ImageUtils.generateImageFile() + "." +
MIMEType.substring(MIMEType.indexOf('/') + 1);
file = new File(currentFileName);

try {
@@ -170,10 +169,8 @@
public void uploadSucceeded(SucceededEvent event) {
showNotification("File " + event.getFilename() + " of type '" +
event.getMIMEType() + "' uploaded.",
Notification.TYPE_HUMANIZED_MESSAGE);
- form.removeComponent(crestImage);
- crestImage = new Embedded("Crest", (new FileResource(file,
application)));
+ crestImage.setSource((new FileResource(file, application)));
crestImage.requestRepaint();
- form.addComponent(crestImage);
}

@Override
@@ -181,10 +178,6 @@
showNotification("Uploading " + event.getFilename() + " of type '" +
event.getMIMEType() + "' failed.",
Notification.TYPE_ERROR_MESSAGE);
}
-
- private String generateImageFileName() {
- return IMAGE_PATH + "t" + hashCode() + System.currentTimeMillis();
- }
}

}

Reply all
Reply to author
Forward
0 new messages