Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/shared/model/ThemeList.java @ 597:14e5e51a7de4
Improved the project list - listeners are notified after setting the name and ttl of a project.
flys-client/trunk@2199 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 22 Jun 2011 10:14:57 +0000 |
parents | 39d9291513cc |
children | f6fbfdc813f0 |
line wrap: on
line source
package de.intevation.flys.client.shared.model; import java.io.Serializable; import java.util.List; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class ThemeList implements Serializable { public List<Theme> themes; public ThemeList() { } public ThemeList(List<Theme> themes) { this.themes = themes; } public List<Theme> getThemes() { return themes; } public int getThemeCount() { return themes.size(); } /** * Returns a theme at a specific position. <b>NOTE: Themes start at position * 1. So, take care in loops, that might start at index 0!</b> * * @param pos The position of the desired theme. * * @return a theme. */ public Theme getThemeAt(int pos) { for (Theme theme: themes) { if (theme.getPosition() == pos) { return theme; } } return null; } public void removeTheme(Theme theme) { if (theme != null) { themes.remove(theme); } } public void addTheme(Theme theme) { if (theme != null) { themes.add(theme); } } /** * Modifies the order of themes in this list and the position of the * <i>theme</i> itself. * * @param theme The theme which position has to be modified. * @param newPos The new position. */ public void setThemePosition(Theme theme, int newPos) { int count = getThemeCount(); int oldPos = theme.getPosition(); if (newPos == oldPos || newPos > count || newPos < 1) { return; } boolean moveUp = newPos < oldPos; for (Theme aTheme: themes) { int tmpPos = aTheme.getPosition(); if (theme.equals(aTheme)) { theme.setPosition(newPos); } else if (tmpPos >= newPos && tmpPos < oldPos && moveUp) { aTheme.setPosition(tmpPos+1); } else if (tmpPos <= newPos && tmpPos > oldPos && !moveUp) { aTheme.setPosition(tmpPos-1); } } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :