1 11 package org.eclipse.help.internal.webapp.data; 12 13 import javax.servlet.*; 14 import javax.servlet.http.*; 15 16 import org.eclipse.help.internal.webapp.servlet.*; 17 import org.eclipse.help.internal.workingset.*; 18 19 22 public class WorkingSetData extends RequestData { 23 public final static short STATE_UNCHECKED = 0; 24 public final static short STATE_GRAYED = 1; 25 public final static short STATE_CHECKED = 2; 26 27 private WebappWorkingSetManager wsmgr; 28 29 private AdaptableToc[] tocs; 30 private boolean isEditMode; 31 32 public WorkingSetData(ServletContext context, HttpServletRequest request, 33 HttpServletResponse response) { 34 super(context, request, response); 35 wsmgr = new WebappWorkingSetManager(request, response, getLocale()); 36 AdaptableTocsArray adaptableTocs = wsmgr.getRoot(); 37 tocs = (AdaptableToc[]) adaptableTocs.getChildren(); 38 isEditMode = "edit".equals(getOperation()); } 40 41 public boolean isEditMode() { 42 return isEditMode; 43 } 44 45 public String getWorkingSetName() { 46 String name = request.getParameter("workingSet"); if (name == null) 48 name = ""; return name; 50 } 51 52 public WorkingSet getWorkingSet() { 53 String name = getWorkingSetName(); 54 if (name != null && name.length() > 0) 55 return wsmgr.getWorkingSet(name); 56 return null; 57 } 58 59 64 public short getTocState(int toc) { 65 if (!isEditMode()) 66 return STATE_UNCHECKED; 67 WorkingSet ws = getWorkingSet(); 68 if (ws == null) 69 return STATE_UNCHECKED; 70 if (toc < 0 || toc >= tocs.length) 71 return STATE_UNCHECKED; 72 73 AdaptableToc adaptableToc = tocs[toc]; 75 AdaptableHelpResource[] elements = ws.getElements(); 76 for (int i = 0; i < elements.length; i++) { 77 if (elements[i] == adaptableToc) 78 return STATE_CHECKED; 79 } 80 81 int topics = adaptableToc.getChildren().length; 83 boolean allTheSame = true; 84 short baseValue = STATE_UNCHECKED; 85 if (topics > 0) 87 baseValue = getTopicState(toc, 0); 88 for (int i = 1; allTheSame && i < topics; i++) 89 allTheSame = allTheSame && (getTopicState(toc, i) == baseValue); 90 91 if (!allTheSame) 92 return STATE_GRAYED; 93 return STATE_UNCHECKED; 94 } 95 96 107 public short getTopicState(int toc, int topic) { 108 if (!isEditMode) 109 return STATE_UNCHECKED; 110 WorkingSet ws = getWorkingSet(); 111 if (ws == null) 112 return STATE_UNCHECKED; 113 if (toc < 0 || toc >= tocs.length) 114 return STATE_UNCHECKED; 115 116 AdaptableToc parent = tocs[toc]; 117 AdaptableTopic[] topics = (AdaptableTopic[]) parent.getChildren(); 118 if (topic < 0 || topic >= topics.length) 119 return STATE_UNCHECKED; 120 AdaptableTopic adaptableTopic = topics[topic]; 121 AdaptableHelpResource[] elements = ws.getElements(); 122 for (int i = 0; i < elements.length; i++) { 123 if (elements[i] == adaptableTopic) 124 return STATE_CHECKED; 125 } 126 return STATE_UNCHECKED; 127 } 128 129 public String getOperation() { 130 return request.getParameter("operation"); } 132 133 137 public int getTocCount() { 138 return tocs.length; 139 } 140 141 public String getTocLabel(int i) { 142 return tocs[i].getLabel(); 143 } 144 145 public String getTocHref(int i) { 146 return tocs[i].getHref(); 147 } 148 149 public int getTopicCount(int toc) { 150 return tocs[toc].getTopics().length; 151 } 152 153 public String getTopicLabel(int toc, int topic) { 154 return tocs[toc].getTopics()[topic].getLabel(); 155 } 156 } 157 | Popular Tags |