001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.war.beans.admin.main;
034:
035: import com.flexive.shared.EJBLookup;
036: import com.flexive.shared.FxLanguage;
037: import com.flexive.shared.exceptions.FxApplicationException;
038: import com.flexive.shared.interfaces.LanguageEngine;
039: import com.flexive.faces.messages.FxFacesMsgErr;
040:
041: import javax.faces.event.ActionEvent;
042: import java.util.List;
043:
044: /**
045: * Languages settings
046: *
047: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
048: * @version $Rev
049: */
050: public class LanguagesBean {
051:
052: private boolean ignoreUsage;
053: private LanguageEngine lang;
054: private List<FxLanguage> available = null;
055: private List<FxLanguage> disabled = null;
056: private FxLanguage language;
057:
058: public LanguagesBean() {
059: lang = EJBLookup.getLanguageEngine();
060: language = null;
061: }
062:
063: public boolean isIgnoreUsage() {
064: return ignoreUsage;
065: }
066:
067: public void setIgnoreUsage(boolean ignoreUsage) {
068: this .ignoreUsage = ignoreUsage;
069: }
070:
071: public List<FxLanguage> getAvailable()
072: throws FxApplicationException {
073: if (available == null)
074: available = lang.loadAvailable(true);
075: return available;
076: }
077:
078: public List<FxLanguage> getDisabled() throws FxApplicationException {
079: if (disabled == null)
080: disabled = lang.loadDisabled();
081: return disabled;
082: }
083:
084: public void setAvailable(List<FxLanguage> available) {
085: this .available = available;
086: }
087:
088: public void setDisabled(List<FxLanguage> disabled) {
089: this .disabled = disabled;
090: }
091:
092: public FxLanguage getLanguage() {
093: return language;
094: }
095:
096: public void setLanguage(FxLanguage language) {
097: this .language = language;
098: }
099:
100: public synchronized void moveLanguageUp(ActionEvent event)
101: throws FxApplicationException {
102: getAvailable();
103: for (int i = 0; i < available.size(); i++) {
104: if (available.get(i).getId() == language.getId()) {
105: if (i == 0)
106: return;
107: FxLanguage tmp = available.remove(i);
108: available.add(i - 1, tmp);
109: return;
110: }
111: }
112: }
113:
114: public synchronized void moveLanguageDown(ActionEvent event)
115: throws FxApplicationException {
116: getAvailable();
117: for (int i = 0; i < available.size(); i++) {
118: if (available.get(i).getId() == language.getId()) {
119: if (i == available.size() - 1)
120: return;
121: FxLanguage tmp = available.remove(i);
122: available.add(i + 1, tmp);
123: return;
124: }
125: }
126: }
127:
128: public long getFirst() throws FxApplicationException {
129: getAvailable();
130: if (available.size() == 0)
131: return 0;
132: return available.get(0).getId();
133: }
134:
135: public long getLast() throws FxApplicationException {
136: getAvailable();
137: if (available.size() == 0)
138: return 0;
139: return available.get(available.size() - 1).getId();
140: }
141:
142: public void addLanguage(ActionEvent event)
143: throws FxApplicationException {
144: getAvailable();
145: getDisabled();
146: for (int i = 0; i < disabled.size(); i++) {
147: if (disabled.get(i).getId() == language.getId()) {
148: available.add(disabled.remove(i));
149: return;
150: }
151: }
152: }
153:
154: public void removeLanguage(ActionEvent event)
155: throws FxApplicationException {
156: getAvailable();
157: getDisabled();
158: FxLanguage tmp = null;
159: for (int i = 0; i < available.size(); i++) {
160: if (available.get(i).getId() == language.getId()) {
161: tmp = available.remove(i);
162: break;
163: }
164: }
165: if (tmp == null)
166: return;
167: for (int i = 0; i < disabled.size(); i++) {
168: if (disabled.get(i).getIso2digit().compareTo(
169: language.getIso2digit()) > 0) {
170: disabled.add(i, tmp);
171: return;
172: }
173: }
174: disabled.add(tmp);
175: }
176:
177: /**
178: * Save language settings.
179: *
180: * @return the next page
181: */
182: public String saveSettings() {
183: try {
184: lang.setAvailable(available, ignoreUsage);
185: } catch (FxApplicationException e) {
186: new FxFacesMsgErr(e).addToContext();
187: }
188: return "languages";
189: }
190:
191: }
|