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.faces.FxJsfUtils;
036: import com.flexive.faces.messages.FxFacesMsgErr;
037: import com.flexive.faces.messages.FxFacesMsgInfo;
038: import com.flexive.shared.CacheAdmin;
039: import static com.flexive.shared.EJBLookup.getWorkflowStepDefinitionEngine;
040: import com.flexive.shared.value.FxString;
041: import com.flexive.shared.workflow.StepDefinition;
042: import com.flexive.shared.workflow.StepDefinitionEdit;
043:
044: import javax.faces.model.SelectItem;
045: import java.util.List;
046: import java.util.ArrayList;
047:
048: /**
049: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
050: * @version $Rev: 180 $
051: */
052: public class StepDefinitionBean {
053: private long stepDefinitionId = -1;
054: private StepDefinitionEdit stepDefinition;
055:
056: /**
057: * Step definition overview.
058: *
059: * @return the overview page
060: */
061: public String overview() {
062: return "stepDefinitionOverview";
063: }
064:
065: /**
066: * Initialize the edit form (load selected step definition)
067: *
068: * @return the edit form
069: */
070: public String edit() {
071: stepDefinition = CacheAdmin.getEnvironment().getStepDefinition(
072: stepDefinitionId).asEditable();
073: return "stepDefinitionEdit";
074: }
075:
076: /**
077: * Delete the selected step definition.
078: *
079: * @return the overview page
080: */
081: public String delete() {
082: try {
083: FxString name = CacheAdmin.getEnvironment()
084: .getStepDefinition(stepDefinitionId).getLabel();
085: getWorkflowStepDefinitionEngine().remove(stepDefinitionId);
086: new FxFacesMsgInfo("StepDefinition.nfo.deleted", name)
087: .addToContext();
088: } catch (Exception e) {
089: new FxFacesMsgErr(e).addToContext();
090: }
091: return overview();
092: }
093:
094: /**
095: * Create a new stepdefinition with the posted values.
096: *
097: * @return the overview page if creation was successful, or redisplay the edit form if it was not
098: */
099: public String create() {
100: try {
101: stepDefinitionId = getWorkflowStepDefinitionEngine()
102: .create(stepDefinition);
103: new FxFacesMsgInfo("StepDefinition.nfo.created",
104: stepDefinition.getLabel()).addToContext();
105: return overview();
106: } catch (Exception e) {
107: new FxFacesMsgErr(e, "StepDefinition.err.create", e)
108: .addToContext();
109: return "stepDefinitionEdit";
110: }
111: }
112:
113: /**
114: * Save an existing step definition.
115: *
116: * @return overview page if the update was successful, otherwise redisplay the edit form
117: */
118: public String save() {
119: try {
120: getWorkflowStepDefinitionEngine().update(stepDefinition);
121: new FxFacesMsgInfo("StepDefinition.nfo.updated",
122: stepDefinition.getLabel()).addToContext();
123: return overview();
124: } catch (Exception e) {
125: new FxFacesMsgErr(e).addToContext();
126: return "stepDefinitionEdit";
127: }
128: }
129:
130: public List<StepDefinition> getList() {
131: return CacheAdmin.getFilteredEnvironment().getStepDefinitions();
132: }
133:
134: public long getStepDefinitionId() {
135: return stepDefinitionId;
136: }
137:
138: public void setStepDefinitionId(long stepDefinitionId) {
139: this .stepDefinitionId = stepDefinitionId;
140: }
141:
142: public StepDefinitionEdit getStepDefinition() {
143: if (stepDefinition != null) {
144: return stepDefinition;
145: }
146: stepDefinition = new StepDefinitionEdit(new StepDefinition(-1,
147: new FxString(""), null, -1));
148: return stepDefinition;
149: }
150:
151: public void setStepDefinition(StepDefinitionEdit stepDefinition) {
152: this .stepDefinition = stepDefinition;
153: }
154:
155: public List<SelectItem> getStepDefinitions() {
156: List<StepDefinition> sdList = CacheAdmin
157: .getFilteredEnvironment().getStepDefinitions();
158: List<StepDefinition> filteredList = new ArrayList<StepDefinition>(
159: sdList.size());
160: for (StepDefinition sd : sdList)
161: if (sd.getId() != stepDefinition.getId()) {
162: filteredList.add(sd);
163: }
164: return FxJsfUtils.asIdSelectListWithLabel(filteredList);
165: }
166: }
|