001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/wizard/tool/src/java/org/theospi/portfolio/wizard/tool/DecoratedWizardPage.java $
003: * $Id:DecoratedWizardPage.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.wizard.tool;
021:
022: import java.io.IOException;
023: import java.util.Collections;
024:
025: import javax.faces.context.ExternalContext;
026: import javax.faces.context.FacesContext;
027:
028: import org.sakaiproject.tool.api.ToolSession;
029: import org.sakaiproject.tool.cover.SessionManager;
030: import org.theospi.portfolio.matrix.WizardPageHelper;
031: import org.theospi.portfolio.wizard.model.WizardPageSequence;
032:
033: /**
034: * Created by IntelliJ IDEA.
035: * User: John Ellis
036: * Date: Jan 13, 2006
037: * Time: 11:44:37 AM
038: * To change this template use File | Settings | File Templates.
039: */
040: public class DecoratedWizardPage extends DecoratedCategoryChild {
041:
042: private DecoratedCategory category = null;
043: private WizardPageSequence base;
044: private boolean selected = false;
045:
046: public DecoratedWizardPage(DecoratedCategory category,
047: WizardPageSequence base, WizardTool parent, int indent) {
048: super (parent, indent);
049: this .base = base;
050: this .category = category;
051: }
052:
053: public WizardPageSequence getBase() {
054: return base;
055: }
056:
057: public void setBase(WizardPageSequence base) {
058: this .base = base;
059: }
060:
061: public String getTitle() {
062: return getBase().getWizardPageDefinition().getTitle();
063: }
064:
065: /**
066: * This can't be concat-ed because it is in html
067: * @return String
068: */
069: public String getDescription() {
070: String desc = getBase().getWizardPageDefinition()
071: .getDescription();
072: //if(desc.length() > 100)
073: // return desc.substring(0, 100) + "...";
074: return desc;
075: }
076:
077: public boolean isSelected() {
078: return selected;
079: }
080:
081: public void setSelected(boolean selected) {
082: this .selected = selected;
083: }
084:
085: public String moveUp() {
086: if (getBase().getSequence() != 0) {
087: Collections.swap(getBase().getCategory().getChildPages(),
088: getBase().getSequence(),
089: getBase().getSequence() - 1);
090: getCategory().resequencePages();
091: }
092: return null;
093: }
094:
095: public String moveDown() {
096: if (getBase().getSequence() < getBase().getCategory()
097: .getChildPages().size() - 1) {
098: Collections.swap(getBase().getCategory().getChildPages(),
099: getBase().getSequence(),
100: getBase().getSequence() + 1);
101: getCategory().resequencePages();
102: }
103: return null;
104: }
105:
106: public boolean isFirst() {
107: return getBase().getSequence() == 0;
108: }
109:
110: public boolean isLast() {
111: return getBase().getSequence() >= getBase().getCategory()
112: .getChildPages().size() - 1;
113: }
114:
115: public boolean isWizard() {
116: return false;
117: }
118:
119: public DecoratedCategory getCategory() {
120: return category;
121: }
122:
123: public void setCategory(DecoratedCategory category) {
124: this .category = category;
125: }
126:
127: public String processActionEdit() {
128: return processActionEdit(false);
129: }
130:
131: public String processExecPage() {
132: return getParent().processExecPage(base);
133: }
134:
135: public String processActionConfirmDelete() {
136: getParent().setCurrentPage(this );
137: return "confirmDeletePage";
138: }
139:
140: public String processActionDelete() {
141: DecoratedCategory parentCategory = getCategory();
142: parentCategory.getBase().getChildPages().remove(getBase());
143: parentCategory.resequencePages();
144: if (getBase().getId() != null)
145: getParent().getDeletedItems().add(getBase());
146: return "continue";
147: }
148:
149: public String processActionEdit(boolean isNew) {
150: ExternalContext context = FacesContext.getCurrentInstance()
151: .getExternalContext();
152: ToolSession session = SessionManager.getCurrentToolSession();
153: session.setAttribute(WizardPageHelper.WIZARD_PAGE, getBase()
154: .getWizardPageDefinition());
155:
156: if (isNew) {
157: session.setAttribute(DecoratedCategory.NEW_PAGE, getBase());
158: }
159:
160: try {
161: context
162: .redirect("osp.wizard.page.def.helper/wizardPageDefinition.osp");
163: } catch (IOException e) {
164: throw new RuntimeException("Failed to redirect to helper",
165: e);
166: }
167:
168: return null;
169: }
170:
171: public boolean getHasChildren() {
172: return false;
173: }
174: }
|