001: package org.sakaiproject.site.tool.helper.order.rsf;
002:
003: import java.util.List;
004:
005: import org.sakaiproject.site.api.SitePage;
006: import org.sakaiproject.site.api.ToolConfiguration;
007: import org.sakaiproject.site.tool.helper.order.impl.SitePageEditHandler;
008: import org.sakaiproject.tool.api.Tool;
009:
010: import uk.org.ponder.messageutil.MessageLocator;
011: import uk.org.ponder.rsf.components.UIBranchContainer;
012: import uk.org.ponder.rsf.components.UIContainer;
013: import uk.org.ponder.rsf.components.UIInput;
014: import uk.org.ponder.rsf.components.UIInternalLink;
015: import uk.org.ponder.rsf.components.UIJointContainer;
016: import uk.org.ponder.rsf.components.UIOutput;
017: import uk.org.ponder.rsf.components.decorators.DecoratorList;
018: import uk.org.ponder.rsf.components.decorators.UITooltipDecorator;
019: import uk.org.ponder.rsf.view.ComponentChecker;
020: import uk.org.ponder.rsf.view.ViewComponentProducer;
021: import uk.org.ponder.rsf.viewstate.ViewParameters;
022: import uk.org.ponder.rsf.viewstate.ViewParamsReporter;
023:
024: /**
025: *
026: * @author Joshua Ryan joshua.ryan@asu.edu
027: *
028: */
029: public class PageAddProducer implements ViewComponentProducer,
030: ViewParamsReporter {
031:
032: public static final String VIEW_ID = "PageAdd";
033:
034: public SitePageEditHandler handler;
035: public MessageLocator messageLocator;
036:
037: public String getViewID() {
038: return VIEW_ID;
039: }
040:
041: public void fillComponents(UIContainer arg0, ViewParameters arg1,
042: ComponentChecker arg2) {
043: PageAddViewParameters params = null;
044:
045: String toolId = null;
046: String newTitle = null;
047: String mode = null;
048:
049: UIBranchContainer responseMode = null;
050:
051: try {
052: params = (PageAddViewParameters) arg1;
053: toolId = params.toolId;
054: mode = params.mode;
055: newTitle = params.newTitle;
056:
057: } catch (Exception e) {
058: e.printStackTrace();
059: responseMode = UIBranchContainer.make(arg0, "mode-failed:");
060: UIOutput.make(responseMode, "message", e
061: .getLocalizedMessage());
062: return;
063: }
064:
065: if ("list".equals(mode)) {
066: List tools = handler.getAvailableTools();
067: responseMode = UIBranchContainer.make(arg0, "mode-pass:");
068:
069: UIOutput.make(responseMode, "message", messageLocator
070: .getMessage("add_inst"));
071:
072: UIBranchContainer toolList = UIBranchContainer.make(
073: responseMode, "tool-list:");
074: toolList.decorators = new DecoratorList(
075: new UITooltipDecorator(messageLocator
076: .getMessage("page_dragadd")));
077:
078: UIOutput.make(toolList, "option-label", messageLocator
079: .getMessage("avail_pages"));
080:
081: PageAddViewParameters refreshParam = new PageAddViewParameters();
082: refreshParam.mode = "list";
083: refreshParam.viewID = PageAddProducer.VIEW_ID;
084: UIInternalLink.make(toolList, "refresh-link", refreshParam).decorators = new DecoratorList(
085: new UITooltipDecorator(messageLocator
086: .getMessage("page_refresh_add")));
087:
088: for (int i = 0; i < tools.size(); i++) {
089: UIBranchContainer toolrow = UIBranchContainer.make(
090: toolList, "tool-row:");
091: Tool tool = (Tool) tools.get(i);
092: toolrow.localID = tool.getId();
093:
094: UIOutput.make(toolrow, "tool-name", tool.getTitle());
095: UIOutput.make(toolrow, "tool-id", tool.getId());
096: UIOutput.make(toolrow, "tool-description", tool
097: .getDescription());
098:
099: PageAddViewParameters addParam = new PageAddViewParameters();
100: addParam.mode = "add";
101: addParam.toolId = tool.getId();
102: addParam.newTitle = tool.getTitle();
103: addParam.viewID = PageAddProducer.VIEW_ID;
104: UIInternalLink.make(toolrow, "tool-add-url", addParam).decorators = new DecoratorList(
105: new UITooltipDecorator(messageLocator
106: .getMessage("page_add")));
107: ;
108:
109: }
110: } else if ("add".equals(mode)) {
111:
112: SitePage page = handler.addPage(toolId, newTitle);
113:
114: if (page != null) {
115: UIJointContainer pagerow = new UIJointContainer(arg0,
116: "page-row:", "page-row:");
117:
118: //needed in order for each tag in the list to have a unique id
119: pagerow.localID = page.getId();
120:
121: UIOutput.make(pagerow, "page-name", page.getTitle());
122: UIInput.make(pagerow, "page-name-input", null, page
123: .getTitle());
124:
125: PageEditViewParameters param = new PageEditViewParameters();
126:
127: param.pageId = page.getId();
128: param.viewID = PageDelProducer.VIEW_ID;
129: UIInternalLink.make(pagerow, "del-link", param);
130:
131: param.viewID = PageEditProducer.VIEW_ID;
132: UIInternalLink.make(pagerow, "edit-link", param);
133:
134: if (page.getTools().size() == 1) {
135: ToolConfiguration tool = (ToolConfiguration) page
136: .getTools().get(0);
137: if ("sakai.iframe".equals(tool.getToolId())) {
138:
139: UIOutput.make(pagerow, "new-config-label",
140: "URL:");
141: UIInput.make(pagerow, "page-config-input",
142: null, tool.getPlacementConfig()
143: .getProperty("source"));
144: }
145: }
146:
147: if (handler.allowsHide(page)) {
148: param.viewID = PageEditProducer.VIEW_ID;
149: if (handler.isVisible(page)) {
150: param.visible = "false";
151: UIInternalLink
152: .make(pagerow, "hide-link", param).decorators = new DecoratorList(
153: new UITooltipDecorator(messageLocator
154: .getMessage("page_hide")));
155: param.visible = "true";
156: UIInternalLink.make(pagerow, "show-link-off",
157: param).decorators = new DecoratorList(
158: new UITooltipDecorator(messageLocator
159: .getMessage("page_show")));
160: } else {
161: param.visible = "true";
162: UIInternalLink
163: .make(pagerow, "show-link", param).decorators = new DecoratorList(
164: new UITooltipDecorator(messageLocator
165: .getMessage("page_show")));
166:
167: param.visible = "false";
168: UIInternalLink.make(pagerow, "hide-link-off",
169: param).decorators = new DecoratorList(
170: new UITooltipDecorator(messageLocator
171: .getMessage("page_hide")));
172: }
173: }
174:
175: responseMode = UIBranchContainer
176: .make(arg0, "add-pass:");
177:
178: UIOutput.make(responseMode, "message", page.getTitle()
179: + " "
180: + messageLocator.getMessage("success_add"));
181:
182: } else {
183:
184: }
185: }
186: }
187:
188: public ViewParameters getViewParameters() {
189: PageAddViewParameters params = new PageAddViewParameters();
190: params.mode = "nil";
191: params.toolId = "nil";
192: params.newTitle = "nil";
193: return params;
194: }
195:
196: }
|