001 /** 002 * 003 */ 004 package org.hackystat.projectbrowser.page.projects; 005 006 import org.apache.wicket.markup.html.basic.Label; 007 import org.apache.wicket.markup.html.basic.MultiLineLabel; 008 import org.apache.wicket.markup.html.form.Button; 009 import org.apache.wicket.markup.html.form.Form; 010 import org.apache.wicket.markup.html.form.ListMultipleChoice; 011 import org.apache.wicket.markup.html.list.ListItem; 012 import org.apache.wicket.markup.html.list.ListView; 013 import org.apache.wicket.markup.html.panel.Panel; 014 import org.apache.wicket.model.PropertyModel; 015 import org.hackystat.projectbrowser.ProjectBrowserApplication; 016 import org.hackystat.projectbrowser.ProjectBrowserProperties; 017 import org.hackystat.projectbrowser.ProjectBrowserSession; 018 import org.hackystat.sensorbase.resource.projects.jaxb.Project; 019 020 /** 021 * First page in projects area that list all projects. 022 * 023 * @author Randy Cox 024 */ 025 public class ProjListPanel extends Panel { 026 /** Support serialization. */ 027 private static final long serialVersionUID = 1L; 028 029 /** 030 * Constructor for this class. 031 * 032 * @param id the wicket id. 033 */ 034 public ProjListPanel(String id) { 035 super(id); 036 037 final ProjectsSession session = ProjectBrowserSession.get().getProjectsSession(); 038 final ProjectsModel model = session.getProjectsModel(); 039 040 Form projectForm = new Form("projListForm"); 041 042 Button newButton = new Button("newButton") { 043 /** For serialization. */ 044 private static final long serialVersionUID = 1L; 045 046 /** Create empty project in edit form for data entry. */ 047 @Override 048 public void onSubmit() { 049 model.createProject(); 050 model.setFeedback(""); 051 session.setNewProject(true); 052 session.getProjListPanel().setVisible(false); 053 session.getProjEditPanel().setVisible(true); 054 } 055 }; 056 projectForm.add(newButton); 057 058 /** 059 * Action button attached to the project in the current row in list. 060 * @author Randy Cox 061 */ 062 final class EditButton extends Button { 063 /** For serialization. */ 064 private static final long serialVersionUID = 1L; 065 /** Stores project attached to this button. */ 066 private Project project; 067 068 /** 069 * Constructor. 070 * 071 * @param id wicket id 072 * @param project to attache to this button 073 */ 074 public EditButton(String id, Project project) { 075 super(id); 076 this.project = project; 077 } 078 079 /** Edit the project with edit form. */ 080 @Override 081 public void onSubmit() { 082 model.setProject(this.project); 083 model.loadPropUriRowsView(); 084 model.setFeedback(""); 085 session.setNewProject(false); 086 session.getProjListPanel().setVisible(false); 087 session.getProjEditPanel().setVisible(true); 088 } 089 090 /** 091 * Turn on only when project has allows the action of this button. 092 * @return true if button is turned on. 093 * */ 094 @Override 095 public boolean isVisible() { 096 ProjectsModel model = new ProjectsModel(this.project); 097 return model.isEditable(); 098 } 099 } 100 101 /** 102 * Action button attached to the project in the current row in list. 103 * @author Randy Cox 104 */ 105 final class RenameButton extends Button { 106 /** For serialization. */ 107 private static final long serialVersionUID = 1L; 108 /** Project to rename. */ 109 private Project project; 110 111 /** 112 * Constructor. 113 * 114 * @param id wicket id 115 * @param project to rename. 116 */ 117 public RenameButton(String id, Project project) { 118 super(id); 119 this.project = project; 120 } 121 122 /** Rename project. */ 123 @Override 124 public void onSubmit() { 125 model.setProject(this.project); 126 model.setFeedback(""); 127 session.getProjListPanel().setVisible(false); 128 session.getProjRenamePanel().setVisible(true); 129 } 130 131 /** 132 * Turn on only when project has allows the action of this button. 133 * @return true if button is turned on. 134 * */ 135 @Override 136 public boolean isVisible() { 137 ProjectsModel model = new ProjectsModel(this.project); 138 return model.isRenameable(); 139 } 140 } 141 142 /** 143 * Action button attached to the project in the current row in list. 144 * @author Randy Cox 145 */ 146 final class DeleteButton extends Button { 147 /** For serialization. */ 148 private static final long serialVersionUID = 1L; 149 /** Project to delete. */ 150 private Project project; 151 152 /** 153 * Constructor. 154 * 155 * @param id wicket id 156 * @param project to delete 157 */ 158 public DeleteButton(String id, Project project) { 159 super(id); 160 this.project = project; 161 } 162 163 /** Delete project. */ 164 @Override 165 public void onSubmit() { 166 model.setProject(this.project); 167 model.setFeedback(""); 168 session.getProjListPanel().setVisible(false); 169 session.getProjDeletePanel().setVisible(true); 170 } 171 172 /** 173 * Turn on only when project has allows the action of this button. 174 * @return true if button is turned on. 175 * */ 176 @Override 177 public boolean isVisible() { 178 ProjectsModel model = new ProjectsModel(this.project); 179 return model.isDeletable(); 180 } 181 } 182 183 /** 184 * Action button attached to the project in the current row in list. 185 * @author Randy Cox 186 */ 187 final class LeaveButton extends Button { 188 /** For serialization. */ 189 private static final long serialVersionUID = 1L; 190 /** Project to leave. */ 191 private Project project; 192 193 /** 194 * Constructor. 195 * 196 * @param id wicket id 197 * @param project to leave. 198 */ 199 public LeaveButton(String id, Project project) { 200 super(id); 201 this.project = project; 202 } 203 204 /** Leave project. */ 205 @Override 206 public void onSubmit() { 207 model.setProject(this.project); 208 model.setFeedback(""); 209 session.getProjListPanel().setVisible(false); 210 session.getProjLeavePanel().setVisible(true); 211 } 212 213 /** 214 * Turn on only when project has allows the action of this button. 215 * @return true if button is turned on. 216 * */ 217 @Override 218 public boolean isVisible() { 219 ProjectsModel model = new ProjectsModel(this.project); 220 return model.isLeavable(); 221 } 222 } 223 224 /** 225 * Action button attached to the project in the current row in list. 226 * @author Randy Cox 227 */ 228 final class ReplyButton extends Button { 229 /** For serialization. */ 230 private static final long serialVersionUID = 1L; 231 /** Project to reply about. */ 232 private Project project; 233 234 /** 235 * Constructor. 236 * 237 * @param id wicket id 238 * @param project to reply about. 239 */ 240 public ReplyButton(String id, Project project) { 241 super(id); 242 this.project = project; 243 } 244 245 /** Bring up reply panel to reply to an invitation. */ 246 @Override 247 public void onSubmit() { 248 model.setProject(this.project); 249 model.setFeedback(""); 250 session.getProjListPanel().setVisible(false); 251 session.getProjReplyPanel().setVisible(true); 252 } 253 254 /** 255 * Turn on only when project has allows the action of this button. 256 * @return true if button is turned on. 257 * */ 258 @Override 259 public boolean isVisible() { 260 ProjectsModel model = new ProjectsModel(this.project); 261 return model.isRepliable(); 262 } 263 } 264 265 /** 266 * Action button attached to the project in the current row in list. 267 * @author Randy Cox 268 */ 269 final class ClearCacheButton extends Button { 270 /** For serialization. */ 271 private static final long serialVersionUID = 1L; 272 /** Project to clear cache for. */ 273 private Project project; 274 275 /** 276 * Constructor. 277 * 278 * @param id wicket id 279 * @param project to clear cache for. 280 */ 281 public ClearCacheButton(String id, Project project) { 282 super(id); 283 this.project = project; 284 } 285 286 /** Bring up clear cache panel to confirm action. */ 287 @Override 288 public void onSubmit() { 289 model.setProject(this.project); 290 model.setFeedback(""); 291 session.getProjListPanel().setVisible(false); 292 session.getProjClearCachePanel().setVisible(true); 293 } 294 295 /** 296 * Turn on only when project has allows the action of this button. 297 * @return true if button is turned on. 298 * */ 299 @Override 300 public boolean isVisible() { 301 ProjectsModel model = new ProjectsModel(this.project); 302 return model.isClearCacheable(); 303 } 304 } 305 306 ListView projectTable = new ListView("projectTable", new PropertyModel(model, "projects")) { 307 /** For serialization. */ 308 private static final long serialVersionUID = 1L; 309 310 /** Add line of project info to table. */ 311 @Override 312 public void populateItem(final ListItem item) { 313 final ProjectsModel model = new ProjectsModel((Project) item.getModelObject()); 314 item.add(new EditButton("editButton", model.getProject())); 315 item.add(new RenameButton("renameButton", model.getProject())); 316 item.add(new DeleteButton("deleteButton", model.getProject())); 317 item.add(new LeaveButton("leaveButton", model.getProject())); 318 item.add(new ReplyButton("replyButton", model.getProject())); 319 item.add(new ClearCacheButton("clearCacheButton", model.getProject())); 320 item.add(new Label("projectName", new PropertyModel(model, "projectName"))); 321 322 Label projectOwner = new Label("projectOwner", new PropertyModel(model, 323 "projectOwnerBold")); 324 projectOwner.setEscapeModelStrings(false); 325 item.add(projectOwner); 326 327 item.add(new Label("projectDesc", new PropertyModel(model, "projectDesc"))); 328 item.add(new MultiLineLabel("projectSpan", new PropertyModel(model, "projectSpan"))); 329 330 String maxHeightStr = ((ProjectBrowserApplication) ProjectBrowserApplication.get()) 331 .getProjectBrowserProperty(ProjectBrowserProperties.PROJECTS_TEXTMAXHEIGHT_KEY); 332 final int maxHeight = Integer.parseInt(maxHeightStr); 333 334 ListMultipleChoice projectMembers = new ListMultipleChoice("projectMembers", 335 new PropertyModel(model, "projectConsolidatedMembers")) { 336 /** Support serialization. */ 337 public static final long serialVersionUID = 1L; 338 339 /** Turns this choice box off when no members are present. */ 340 @Override 341 public boolean isVisible() { 342 return ((model.getProjectConsolidatedMembers().size() > maxHeight)); 343 } 344 }; 345 projectMembers.setEnabled(false); 346 projectMembers.setMaxRows(maxHeight); 347 projectMembers.setEscapeModelStrings(false); 348 item.add(projectMembers); 349 350 MultiLineLabel projectMembersLabel = new MultiLineLabel("projectMembersLabel", 351 new PropertyModel(model, "projectConsolidatedMembersStr")) { 352 /** Support serialization. */ 353 public static final long serialVersionUID = 1L; 354 355 /** Turns this choice box off when no members are present. */ 356 @Override 357 public boolean isVisible() { 358 return ((model.getProjectConsolidatedMembers().size() <= maxHeight)); 359 } 360 }; 361 projectMembersLabel.setEscapeModelStrings(false); 362 item.add(projectMembersLabel); 363 364 item.add(new MultiLineLabel("projectUriPatterns", new PropertyModel(model, 365 "projectUriPatternsStr"))); 366 item.add(new MultiLineLabel("projectProperties", new PropertyModel(model, 367 "projectPropertiesStr"))); 368 } 369 }; 370 projectForm.add(projectTable); 371 add(projectForm); 372 } 373 }