removed deprecated panel and lots of old stuff, including the resource code

This commit is contained in:
Fredrik Friis 2012-02-29 14:31:00 +09:00
parent 7d294432c0
commit 903c10e066
28 changed files with 0 additions and 3109 deletions

@ -42,7 +42,6 @@ import se.su.dsv.scipro.admin.pages.settings.AdminGeneralSettingsPage;
import se.su.dsv.scipro.admin.pages.settings.AdminPeerSettingsPage;
import se.su.dsv.scipro.admin.pages.settings.AdminServerEnvironmentSettingsPage;
import se.su.dsv.scipro.basepages.DemoPage;
import se.su.dsv.scipro.basepages.Inte;
import se.su.dsv.scipro.basepages.errorpages.AccessDeniedPage;
import se.su.dsv.scipro.basepages.errorpages.CustomErrorPageFactory;
import se.su.dsv.scipro.basepages.errorpages.InternalErrorPage;
@ -62,10 +61,6 @@ import se.su.dsv.scipro.json.pages.JsonSentMessagePage;
import se.su.dsv.scipro.json.pages.JsonSetReadPage;
import se.su.dsv.scipro.json.pages.JsonSetStatusPage;
import se.su.dsv.scipro.json.pages.JsonStatusPage;
import se.su.dsv.scipro.knol.resource.page.BookmarkableCategoryResourcePage;
import se.su.dsv.scipro.knol.resource.page.BookmarkableResourcePage;
import se.su.dsv.scipro.knol.resource.page.BookmarkableTagResourcePage;
import se.su.dsv.scipro.knol.resource.page.ResourcePage;
import se.su.dsv.scipro.log.pages.ProjectLogPage;
import se.su.dsv.scipro.log.pages.SupervisorLogPage;
import se.su.dsv.scipro.loginlogout.pages.LoginPage;
@ -172,7 +167,6 @@ public class SciProApplication extends RepositoryApplication implements IThemabl
mountBookmarkablePage("login", LoginPage.class);
mountBookmarkablePage("logout", LogoutPage.class);
mountBookmarkablePage("demo", DemoPage.class);
mountBookmarkablePage("inte", Inte.class);
/*
* Pop-up pages
@ -194,14 +188,6 @@ public class SciProApplication extends RepositoryApplication implements IThemabl
mountBookmarkablePage("json/status", JsonStatusPage.class);
mountBookmarkablePage("json/setstatus", JsonSetStatusPage.class);
/*
* Resource pages
*/
mountBookmarkablePage("resource", ResourcePage.class);
mountBookmarkablePage("resource/category", BookmarkableCategoryResourcePage.class);
mountBookmarkablePage("resource/resource", BookmarkableResourcePage.class);
mountBookmarkablePage("resource/tag", BookmarkableTagResourcePage.class);
/*
* Admin pages
*/

@ -1,29 +0,0 @@
package se.su.dsv.scipro.basepages;
import org.apache.wicket.PageParameters;
import org.apache.wicket.model.Model;
import se.su.dsv.scipro.knol.resource.page.StaticImage;
public class Inte extends PublicPage {
private StaticImage firstImage, secondImage;
public Inte(final PageParameters pp){
super(pp);
firstImage = new StaticImage("firstImage", new Model<String>(
"images/icons/bullet_ball_glass_green.png"));
secondImage = new StaticImage("secondImage", new Model<String>(
"images/icons/bullet_ball_glass_yellow.png"));
add(firstImage);
add(secondImage);
secondImage.setVisible(false);
}
}

@ -1,37 +0,0 @@
/**
*
*/
package se.su.dsv.scipro.knol.resource.model;
import java.util.Collection;
import org.apache.wicket.IClusterable;
import se.su.dsv.scipro.data.dataobjects.Category;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class CategoryModel implements IClusterable {
private String categoryName;
private Category selectedCategory;
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public Category getCategory() {
return selectedCategory;
}
public void setCategory(Category category) {
this.selectedCategory = category;
}
}

@ -1,75 +0,0 @@
/**
*
*/
package se.su.dsv.scipro.knol.resource.model;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.wicket.IClusterable;
import se.su.dsv.scipro.data.dataobjects.Category;
import se.su.dsv.scipro.data.dataobjects.Tag;
import se.su.dsv.scipro.data.dataobjects.User;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class ResourceModel implements IClusterable {
private String info;
private String link;
private String linkName;
private String embedCode;
private String tags;
private Collection<Category> selectedCategoryCollection;
public String getEmbedCode() {
return embedCode;
}
public void setEmbedCode(String embedCode) {
this.embedCode = embedCode;
}
public String getInfo() {
return info;
}
public String getLink() {
return link;
}
public String getLinkName() {
return linkName;
}
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags;
}
public void setInfo(String info) {
this.info = info;
}
public void setLink(String link) {
this.link = link;
}
public void setLinkName(String linkName) {
this.linkName = linkName;
}
public Collection<Category> getSelectedCategoryCollection() {
return selectedCategoryCollection;
}
public void setSelectedCategoryCollection(
Collection<Category> selectedCategoryCollection) {
this.selectedCategoryCollection = selectedCategoryCollection;
}
}

@ -1,12 +0,0 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<body>
<wicket:extend>
<div wicket:id="bookMarkTagPanel"></div>
</wicket:extend>
</body>
</html>

@ -1,46 +0,0 @@
/**
*
*/
package se.su.dsv.scipro.knol.resource.page;
import java.util.List;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import se.su.dsv.scipro.basepages.MenuPage;
import se.su.dsv.scipro.data.dataobjects.Category;
import se.su.dsv.scipro.data.dataobjects.Tag;
import se.su.dsv.scipro.knol.resource.panels.ResourceBookmarkableCategoryPanel;
import se.su.dsv.scipro.knol.resource.panels.ResourceBookmarkableTagPanel;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class BookmarkableCategoryResourcePage extends MenuPage {
public BookmarkableCategoryResourcePage(PageParameters pp) {
super(pp);
add(new ResourceBookmarkableCategoryPanel("bookMarkTagPanel", pp));
}
public static BookmarkablePageLink<Void> getBookmarkablePageLink(String id,
List<Category> categoryList) {
String category = "";
boolean first = true;
for (Category t : categoryList) {
if (first) {
category += t.getId();
first = false;
} else{
category += "+" + t.getId();
}
}
PageParameters pp = new PageParameters();
pp.add("c", category);
return new BookmarkablePageLink<Void>(id,
BookmarkableCategoryResourcePage.class, pp);
}
}

@ -1,12 +0,0 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<body>
<wicket:extend>
<div wicket:id="bookMarkPanel"></div>
</wicket:extend>
</body>
</html>

@ -1,29 +0,0 @@
/**
*
*/
package se.su.dsv.scipro.knol.resource.page;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import se.su.dsv.scipro.basepages.MenuPage;
import se.su.dsv.scipro.data.dataobjects.Resource;
import se.su.dsv.scipro.knol.resource.panels.ResourceBookmarkablePanel;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class BookmarkableResourcePage extends MenuPage{
public BookmarkableResourcePage(PageParameters pp) {
super(pp);
add(new ResourceBookmarkablePanel("bookMarkPanel", pp));
}
public static BookmarkablePageLink<Void> getBookmarkablePageLink(String id, Resource resource){
PageParameters pp = new PageParameters();
pp.put("r", resource.getId());
return new BookmarkablePageLink<Void>(id, BookmarkableResourcePage.class, pp);
}
}

@ -1,12 +0,0 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<body>
<wicket:extend>
<div wicket:id="bookMarkTagPanel"></div>
</wicket:extend>
</body>
</html>

@ -1,43 +0,0 @@
/**
*
*/
package se.su.dsv.scipro.knol.resource.page;
import java.util.List;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import se.su.dsv.scipro.basepages.MenuPage;
import se.su.dsv.scipro.data.dataobjects.Tag;
import se.su.dsv.scipro.knol.resource.panels.ResourceBookmarkableTagPanel;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class BookmarkableTagResourcePage extends MenuPage {
public BookmarkableTagResourcePage(PageParameters pp) {
super(pp);
add(new ResourceBookmarkableTagPanel("bookMarkTagPanel", pp));
}
public static BookmarkablePageLink<Void> getBookmarkablePageLink(String id,
List<Tag> tagList) {
String tag = "";
boolean first = true;
for (Tag t : tagList) {
if (first) {
tag += t.getId();
first = false;
} else{
tag += "+" + t.getId();
}
}
PageParameters pp = new PageParameters();
pp.add("t", tag);
return new BookmarkablePageLink<Void>(id,
BookmarkableTagResourcePage.class, pp);
}
}

@ -1,42 +0,0 @@
/**
*
*/
package se.su.dsv.scipro.knol.resource.page;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.html.WebMarkupContainer;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class HtmlWebMarkupContainer extends WebMarkupContainer {
private String html;
public HtmlWebMarkupContainer(String id, String html) {
super(id);
this.html = html;
}
public String getHtml() {
return html;
}
public void setHtml(String html) {
this.html = html;
}
@Override
protected void onComponentTagBody(MarkupStream markupStream,
ComponentTag openTag) {
replaceComponentTagBody(markupStream, openTag, html);
}
}

@ -1,8 +0,0 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<body>
<wicket:extend>
<div wicket:id="resourcesPanel"></div>
</wicket:extend>
</body>
</html>

@ -1,27 +0,0 @@
/**
*
*/
package se.su.dsv.scipro.knol.resource.page;
import org.apache.wicket.PageParameters;
import se.su.dsv.scipro.basepages.MenuPage;
import se.su.dsv.scipro.knol.resource.panels.ResourcesPanel;
import se.su.dsv.scipro.security.auth.Authorization;
import se.su.dsv.scipro.security.auth.roles.Roles;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
@Authorization(authorizedRoles={Roles.SYSADMIN}) //TODO Hidden for initial deployment
public class ResourcePage extends MenuPage {
public static final String MAIN_MENU_LABEL = "Resources";
public ResourcePage(PageParameters pp) {
super(pp);
add(new ResourcesPanel("resourcesPanel"));
}
}

@ -1,27 +0,0 @@
/**
*
*/
package se.su.dsv.scipro.knol.resource.page;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebComponent;
import org.apache.wicket.model.IModel;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class StaticImage extends WebComponent {
public StaticImage(String id, IModel model) {
super(id, model);
}
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
checkComponentTag(tag, "img");
tag.put("src", getDefaultModelObjectAsString());
// since Wicket 1.4 you need to use getDefaultModelObjectAsString() instead of getModelObjectAsString()
}
}

@ -1,26 +0,0 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<body>
<wicket:panel>
<div><span wicket:id="feedbackPanel">[Feedback goes here]</span></div>
<form wicket:id="uploadForm">
<div><input wicket:id="fileInput" id="fileInput" type="file" /></div>
<div><input type="submit" value="Upload!" name="upload" /></div>
<span wicket:id="progress">[[ajax upload progressbar]]</span>
</form>
<table wicket:id="listFiles">
<tr wicket:id="content">
<!-- <td><a href="delete" wicket:id="delete"><span-->
<!-- wicket:id="deleteIcon" /></a></td>-->
<td><span wicket:id="name">name</span></td>
<td><a href="#" wicket:id="open">Open</a></td>
<td><a href="#" wicket:id="download">Download</a></td>
</tr>
</table>
</wicket:panel>
</body>
</html>

@ -1,124 +0,0 @@
package se.su.dsv.scipro.knol.resource.panels;
import java.util.List;
import org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadProgressBar;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.upload.FileUpload;
import org.apache.wicket.markup.html.form.upload.FileUploadField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.util.lang.Bytes;
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
import se.su.dsv.scipro.data.dataobjects.FileDescription;
import se.su.dsv.scipro.data.dataobjects.Resource;
import se.su.dsv.scipro.repository.FileRepository;
import se.su.dsv.scipro.repository.SortOrder;
import se.su.dsv.scipro.repository.components.FileDownloadLink;
import se.su.dsv.scipro.repository.components.FileOpenLink;
public class FileResourcePanel extends Panel{
private static final long serialVersionUID = 5500371345065598841L;
protected Bytes maxFileSize = Bytes.megabytes(100);
@SpringBean
protected FileRepository fileRepository;
@SpringBean
protected UserDao userDao;
protected FileUploadForm fuf;
protected Resource resource;
protected WebMarkupContainer listFiles;
protected WebMarkupContainer tableHead;
public FileResourcePanel(String id, Resource resource) {
super(id);
add(new FeedbackPanel("feedbackPanel"));
this.resource = resource;
listFiles = new WebMarkupContainer("listFiles");
add(listFiles);
reloadFiles();
fuf = new FileUploadForm("uploadForm");
add(fuf);
fuf.add(new UploadProgressBar("progress", fuf)); //TODO seems to be broken in some browsers like Chrome
if(resource == null || resource.getId() == null)
fuf.setVisible(false);
}
private void reloadFiles() {
listFiles.removeAll();
List<FileDescription> items = fileRepository.searchFiles(fileRepository.getResourcePath(resource.getId()),false);
if(items.isEmpty())
listFiles.setVisible(false);
else
listFiles.setVisible(true);
fileRepository.sortFileDescriptions(items, SortOrder.Name);
RepeatingView contents = new RepeatingView("content");
listFiles.add(contents);
for (final FileDescription desc : items) {
WebMarkupContainer inner = new WebMarkupContainer(contents.newChildId());
inner.add(new Label("name", desc.getName()));
inner.add(new FileDownloadLink("download", desc ));
inner.add(new FileOpenLink("open", desc));
contents.add(inner);
}//for
}//reloadFiles
private class FileUploadForm extends Form<Void> {
private static final long serialVersionUID = 1L;
private FileUploadField fileUploadField;
public FileUploadForm(String id) {
super(id);
setMultiPart(true);
// Add one file input field
add(fileUploadField = new FileUploadField("fileInput"));
setMaxSize(maxFileSize);
}
@Override
protected void onSubmit() {
final FileUpload upload = fileUploadField.getFileUpload();
if(resource == null){
error("File resource was null, this was not meant to happen!");
} else {
if(resource.getId() == null){
error("File resource id was null, this was not meant to happen!");
}
else {
String absolutePath = fileRepository.getResourcePath(resource.getId());
fileRepository.storeFile(upload, absolutePath);
}
}
setRedirect(true);
reloadFiles();
//This might have to be changed into something better using page parameters etc.
setResponsePage(getPage());
}
}
}

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<body>
<wicket:panel>
<h2>Resources</h2>
<div wicket:id="tagHeader" class="larger"></div>
<a href="#" wicket:id="showAll">Show All</a>
<div wicket:id="resourceListPanel"></div>
</wicket:panel>
</body>
</html>

@ -1,101 +0,0 @@
/**
*
*/
package se.su.dsv.scipro.knol.resource.panels;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import org.apache.wicket.PageParameters;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import se.su.dsv.scipro.SciProApplication;
import se.su.dsv.scipro.data.dao.interfaces.CategoryDao;
import se.su.dsv.scipro.data.dao.interfaces.ResourceDao;
import se.su.dsv.scipro.data.dao.interfaces.TagDao;
import se.su.dsv.scipro.data.dataobjects.Category;
import se.su.dsv.scipro.data.dataobjects.Resource;
import se.su.dsv.scipro.data.dataobjects.Tag;
import se.su.dsv.scipro.data.enums.ResourceType;
import se.su.dsv.scipro.knol.resource.page.ResourcePage;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class ResourceBookmarkableCategoryPanel extends Panel {
private static final long serialVersionUID = 1L;
@SpringBean
private ResourceDao resourceDao;
@SpringBean
private CategoryDao categoryDao;
public ResourceBookmarkableCategoryPanel(String id, PageParameters pp) {
super(id);
add(new AjaxLink<Tag>("showAll") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
setResponsePage(ResourcePage.class);
}
});
List<Category> categoryList = new ArrayList<Category>();
String categories = pp.getString("c");
String tagHeader = "Filtered by categories: ";
boolean first = true;
if (categories == null) {
failAndRedirect();
} else {
StringTokenizer stringTokenizer = new StringTokenizer(categories,
"+");
while (stringTokenizer.hasMoreTokens()) {
String tagString = stringTokenizer.nextToken().trim();
Category category = categoryDao.load(Long.valueOf(tagString));
if (category != null) {
if (!categoryList.contains(category)) {
categoryList.add(category);
if (first) {
tagHeader += category.getCategoryName();
first = false;
} else
tagHeader += ", " + category.getCategoryName();
}
} else {
failAndRedirect();
}
}
}
add(new Label("tagHeader", tagHeader));
Set<Resource> resourceList = new HashSet<Resource>();
for (Category category : categoryList) {
resourceList.addAll(resourceDao.findResourcesByCategory(category));
}
add(new ResourceListPanel("resourceListPanel", new ArrayList<Resource>(
resourceList), ResourceType.TAGVIEW));
}
private void failAndRedirect() {
throw new RestartResponseException(SciProApplication.get()
.getApplicationSettings().getAccessDeniedPage());
}
}

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<body>
<wicket:panel>
<h2>Resource</h2>
<div wicket:id="resourceListPanel"></div>
</wicket:panel>
</body>
</html>

@ -1,59 +0,0 @@
/**
*
*/
package se.su.dsv.scipro.knol.resource.panels;
import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.PageParameters;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import se.su.dsv.scipro.SciProApplication;
import se.su.dsv.scipro.data.dao.interfaces.ResourceDao;
import se.su.dsv.scipro.data.dataobjects.Resource;
import se.su.dsv.scipro.data.enums.ResourceType;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class ResourceBookmarkablePanel extends Panel {
private static final long serialVersionUID = 1L;
@SpringBean
private ResourceDao resourceDao;
private Resource resource;
public ResourceBookmarkablePanel(String id, PageParameters pp) {
super(id);
Long resId = pp.getAsLong("r");
if (resId == null) {
failAndRedirect();
} else {
resource = resourceDao.load(resId);
if (resource == null)
failAndRedirect();
}
List<Resource> resourceList = new ArrayList<Resource>();
resourceList.add(resource);
add(new ResourceListPanel("resourceListPanel", resourceList, ResourceType.PERMALINK));
}
private void failAndRedirect() {
throw new RestartResponseException(SciProApplication.get()
.getApplicationSettings().getAccessDeniedPage());
}
}

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<body>
<wicket:panel>
<h2>Resources</h2>
<div wicket:id="tagHeader" class="larger"></div>
<a href="#" wicket:id="showAll">Show All</a>
<div wicket:id="resourceListPanel"></div>
</wicket:panel>
</body>
</html>

@ -1,97 +0,0 @@
/**
*
*/
package se.su.dsv.scipro.knol.resource.panels;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import org.apache.wicket.PageParameters;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import se.su.dsv.scipro.SciProApplication;
import se.su.dsv.scipro.data.dao.interfaces.ResourceDao;
import se.su.dsv.scipro.data.dao.interfaces.TagDao;
import se.su.dsv.scipro.data.dataobjects.Resource;
import se.su.dsv.scipro.data.dataobjects.Tag;
import se.su.dsv.scipro.data.enums.ResourceType;
import se.su.dsv.scipro.knol.resource.page.ResourcePage;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class ResourceBookmarkableTagPanel extends Panel {
private static final long serialVersionUID = 1L;
@SpringBean
private ResourceDao resourceDao;
@SpringBean
private TagDao tagDao;
public ResourceBookmarkableTagPanel(String id, PageParameters pp) {
super(id);
add(new AjaxLink<Tag>("showAll") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
setResponsePage(ResourcePage.class);
}
});
List<Tag> tagList = new ArrayList<Tag>();
String tags = pp.getString("t");
String tagHeader = "Filtered by tags: ";
boolean first = true;
if (tags == null) {
failAndRedirect();
} else {
StringTokenizer stringTokenizer = new StringTokenizer(tags, "+");
while (stringTokenizer.hasMoreTokens()) {
String tagString = stringTokenizer.nextToken().trim();
Tag tag = tagDao.load(Long.valueOf(tagString));
if (null != tag) {
if (!tagList.contains(tag)) {
tagList.add(tag);
if (first) {
tagHeader += tag.getTag();
first = false;
} else
tagHeader += ", " + tag.getTag();
}
} else {
failAndRedirect();
}
}
}
add(new Label("tagHeader", tagHeader));
Set<Resource> resourceList = new HashSet<Resource>();
for (Tag tag : tagList) {
resourceList.addAll(resourceDao.findResourcesByTag(tag));
}
add(new ResourceListPanel("resourceListPanel", new ArrayList<Resource>(resourceList), ResourceType.TAGVIEW));
}
private void failAndRedirect() {
throw new RestartResponseException(SciProApplication.get()
.getApplicationSettings().getAccessDeniedPage());
}
}

@ -1,177 +0,0 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<body>
<wicket:panel>
<div wicket:id="listContainer">
<table wicket:id = "link-item" class = "link-resource-border">
<tr>
<td class="rating-cell">
<div class = "centered" ><a href="#" wicket:id="upLink"><img wicket:id="upLinkIcon"/></a></div>
<div class = "centered larger-rate-number" wicket:id="rate"></div>
<div class = "centered" ><a href="#" wicket:id="downLink"><img wicket:id="downLinkIcon" /></a></div>
</td>
<td>
<a href="#" target="new" wicket:id="link" class="larger"></a>
<span wicket:id="heading" class="larger"></span>
<div class = "right-corner-resource">
<div class = "resource-icon">
<a href="#" wicket:id="editResource"><img src="images/icons/edit_16x16.png" " alt="Edit" title="Edit"/></a>
<a href="#" wicket:id="deleteResource"><img src="images/icons/delete_16x16.png" alt="Delete" title="Delete"/></a>
</div>
<div class = "smaller">
<strong>Created: </strong> <span wicket:id="date"></span>
<br/>
<strong>Created by: </strong> <span wicket:id="user"></span>
</div>
</div>
<div><a href="#" target="new" wicket:id="linkAddress"></a></div>
<div wicket:id="embedCode"></div>
<div wicket:id="info" class = "info-resource"></div>
<div><strong>Categories: </strong> <span wicket:id="category-item"><a href="#" wicket:id="tag"><span wicket:id="tagName"></span></a> </span></div>
<strong>Tags: </strong> <span wicket:id="tag-item"><a href="#" wicket:id="tag"><span wicket:id="tagName"></span></a> </span>
<div ><a href="#" wicket:id="bookmark">Permalink</a></div>
<div><a href="#" wicket:id="showComments"><span wicket:id="commentNumber"></span></a></div>
</td>
</tr>
<tr>
<td class="rating-cell"></td>
<td colspan ="2"><div wicket:id="container"><div wicket:id="commentThread"></div></div></td>
</tr>
</table>
<div wicket:id ="navigator"></div>
</div>
<div wicket:id="editLinkDialog">
<div wicket:id="editLinkDialogContainer">
<form wicket:id="editLinkResourceForm">
<div wicket:id="feedbackContainer" class ="span-8 last">
<div wicket:id="feedbackPanel">
</div>
</div>
<div class ="span-6 last">
<strong>Link Name:</strong>
</div>
<div class ="span-6 last">
<input type="text" wicket:id="linkName" class ="span-6"/>
</div>
<div class ="span-6 last">
<strong>Link Address:</strong>
</div>
<div class ="span-6 last">
<input type="text" wicket:id="link" class ="span-6" />
</div>
<div class ="span-6 last">
<strong>Info:</strong>
</div>
<div class ="span-6 last">
<textarea wicket:id="info" ></textarea>
</div>
<div class ="span-6 last">
<strong>Categories:</strong>
</div>
<div class ="span-6 last">
<select wicket:id="selectedCategoryCollection" class ="span-8 last"></select>
</div>
<div class ="span-6 last">
<strong>Tags:</strong>
</div>
<div class ="span-6 last">
Separate by comma.
</div>
<div class ="span-6 last">
<input type="text" wicket:id="tags" class ="span-6" />
</div>
<div class ="span-6 last">
<strong>Delete tags:</strong>
</div>
<div wicket:id="tagListContainer" class ="span-6 last">
<span wicket:id="tag-item">
<span wicket:id="tagContainer">
<span wicket:id="tag"></span>
<a href="#" wicket:id="deleteTag"><img src="images/icons/delete_16x16.png" alt="Delete" title="Delete"/></a>
</span>
</span>
</div>
<div class ="span-6 last edit-button"><input type="submit" wicket:id="submitButton" /> </div>
</form>
</div>
</div>
<div wicket:id="editEmbedDialog">
<div wicket:id="editEmbedDialogContainer">
<form wicket:id="editEmbedResourceForm">
<div wicket:id="feedbackContainer" class ="span-8 last">
<div wicket:id="feedbackPanel">
</div>
</div>
<div class ="span-6 last">
<strong>Heading:</strong>
</div>
<div class ="span-6 last">
<input type="text" wicket:id="linkName" class ="span-6"/>
</div>
<div class ="span-6 last">
<strong>Embed Code:</strong>
</div>
<div class ="span-8 last">
Disclaimer: no security checks at the moment.
</div>
<div class ="span-6 last">
<textarea wicket:id="embedCode" ></textarea>
</div>
<div class ="span-6 last">
<strong>Info:</strong>
</div>
<div class ="span-6 last">
<textarea wicket:id="info" ></textarea>
</div>
<div class ="span-6 last">
<strong>Categories:</strong>
</div>
<div class ="span-6 last">
<select wicket:id="selectedCategoryCollection" class ="span-8 last"></select>
</div>
<div class ="span-6 last">
<strong>Add tags:</strong>
</div>
<div class ="span-6 last">
Separate by comma.
</div>
<div class ="span-6 last">
<input type="text" wicket:id="tags" class ="span-6" />
</div>
<div class ="span-6 last">
<strong>Delete tags:</strong>
</div>
<div wicket:id="tagListContainerEmbed" class ="span-8 last">
<span wicket:id="tag-embed-item">
<span wicket:id="tagEmbedContainer">
<span wicket:id="tagEmbed"></span>
<a href="#" wicket:id="deleteTagEmbed"><img src="images/icons/delete_16x16.png" alt="Delete" title="Delete"/></a>
</span>
</span>
</div>
<div class ="span-6 last edit-button"><input type="submit" wicket:id="submitButton" /> </div>
</form>
</div>
</div>
</wicket:panel>
</body>
</html>

@ -1,11 +0,0 @@
editLinkDialog.editLinkDialogContainer.editLinkResourceForm.link=Link Address
editLinkDialog.editLinkDialogContainer.editLinkResourceForm.linkName=Link Name
editLinkDialog.editLinkDialogContainer.editLinkResourceForm.info=Info
editLinkDialog.editLinkDialogContainer.editLinkResourceForm.tags=Tags
editLinkDialog.editLinkDialogContainer.editLinkResourceForm.selectedCategoryCollection=Categories
editEmbedDialog.editEmbedDialogContainer.editEmbedResourceForm.linkName=Heading
editEmbedDialog.editEmbedDialogContainer.editEmbedResourceForm.embedCode=Embed Code
editEmbedDialog.editEmbedDialogContainer.editEmbedResourceForm.info=Info
editEmbedDialog.editEmbedDialogContainer.editEmbedResourceForm.tags=Tags
editEmbedDialog.editEmbedDialogContainer.editEmbedResourceForm.selectedCategoryCollection=Categories
Required='${label}' is required

@ -1,170 +0,0 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<body>
<wicket:panel>
<h2>Resources</h2>
<div><a href="#" wicket:id="addLinkResource">Add Link Resource</a></div>
<div><a href="#" wicket:id="addEmbedResource">Add Embed Resource</a></div>
<div><a href="#" wicket:id="addCategories">Add Categories</a></div>
<div><a href="#" wicket:id="adminCategories">Edit Categories</a></div>
<div wicket:id="container">
<div wicket:id="resourceListPanel"></div>
</div>
<div wicket:id="dialog">
<div wicket:id="dialogContainer">
<form wicket:id="resourceForm">
<div wicket:id="feedbackContainer" class ="span-8 last">
<div wicket:id="feedbackPanel">
</div>
</div>
<div class ="span-6 last">
<strong>Link Name:</strong>
</div>
<div class ="span-6 last">
<input type="text" wicket:id="linkName" class ="span-6"/>
</div>
<div class ="span-6 last">
<strong>Link Address:</strong>
</div>
<div class ="span-6 last">
<input type="text" wicket:id="link" class ="span-6" />
</div>
<div class ="span-6 last">
<strong>Info:</strong>
</div>
<div class ="span-6 last">
<textarea wicket:id="info" ></textarea>
</div>
<div class ="span-6 last">
<strong>Categories:</strong>
</div>
<div class ="span-6 last">
<select wicket:id="selectedCategoryCollection" class ="span-8 last"></select>
</div>
<div class ="span-6 last">
<strong>Tags:</strong>
</div>
<div class ="span-6 last">
Separate by comma.
</div>
<div class ="span-6 last">
<input type="text" wicket:id="tags" class ="span-6" />
</div>
<div class ="span-6 last"><input type="submit" wicket:id="submitButton" /> </div>
</form>
</div>
</div>
<div wicket:id="embedDialog">
<div wicket:id="embedDialogContainer">
<form wicket:id="embedResourceForm">
<div wicket:id="feedbackContainer" class ="span-8 last">
<div wicket:id="feedbackPanel"></div>
</div>
<div class ="span-6 last">
<strong>Heading:</strong>
</div>
<div class ="span-6 last">
<input type="text" wicket:id="linkName" class ="span-6"/>
</div>
<div class ="span-6 last">
<strong>Embed Code:</strong>
</div>
<div class ="span-8 last">
Disclaimer: no security checks at the moment.
</div>
<div class ="span-6 last">
<textarea wicket:id="embedCode" ></textarea>
</div>
<div class ="span-6 last">
<strong>Info:</strong>
</div>
<div class ="span-6 last">
<textarea wicket:id="info" ></textarea>
</div>
<div class ="span-6 last">
<strong>Categories:</strong>
</div>
<div class ="span-6 last">
<select wicket:id="selectedCategoryCollection" class ="span-8 last"></select>
</div>
<div class ="span-6 last">
<strong>Tags:</strong>
</div>
<div class ="span-6 last">
Separate by comma.
</div>
<div class ="span-6 last">
<input type="text" wicket:id="tags" class ="span-6" />
</div>
<div class ="span-6 last"><input type="submit" wicket:id="submitButton" /> </div>
</form>
</div>
</div>
<div wicket:id="adminCategoriesDialog">
<div wicket:id="adminCategoriesContainer">
<form wicket:id="adminCategoriesForm">
<div wicket:id="feedbackContainer" class ="span-8 last">
<div wicket:id="feedbackPanel"></div>
</div>
<div class ="span-6 last">
<strong>Categories:</strong>
</div>
<div class ="span-8 last">
<select wicket:id="selectedCategory" class ="span-8 last"></select>
</div>
<div class ="span-6 last">
<strong>Category Name:</strong>
</div>
<div class ="span-6 last">
<input type="text" wicket:id="categoryName" class ="span-6" />
</div>
<div>
</div>
<div class ="span-6 last">
<input type="submit" wicket:id="editButton" />
<input type="submit" wicket:id="deleteCategory" />
</div>
<div class ="span-6 last">
<input type="submit" wicket:id="closeButton" />
</div>
</form>
</div>
</div>
<div wicket:id="addCategoriesDialog">
<div wicket:id="addCategoriesContainer">
<form wicket:id="addCategoriesForm">
<div wicket:id="feedbackContainer" class ="span-8 last">
<div wicket:id="feedbackPanel"></div>
</div>
<div class ="span-6 last">
<strong>Categories:</strong>
</div>
<div class ="span-8 last">
<select wicket:id="selectedCategory" class ="span-8 last"></select>
</div>
<div class ="span-6 last">
<strong>Category Name:</strong>
</div>
<div class ="span-6 last">
<input type="text" wicket:id="categoryName" class ="span-6" />
</div>
<div class ="span-6 last"><input type="submit" wicket:id="addButton" />
</div>
<div class ="span-6 last">
<input type="submit" wicket:id="closeButton" />
</div>
</form>
</div>
</div>
</wicket:panel>
</body>
</html>

@ -1,749 +0,0 @@
/**
*
*/
package se.su.dsv.scipro.knol.resource.panels;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.IAjaxCallDecorator;
import org.apache.wicket.ajax.calldecorator.AjaxCallDecorator;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.form.ListChoice;
import org.apache.wicket.markup.html.form.ListMultipleChoice;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.util.ListModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.validation.validator.UrlValidator;
import org.odlabs.wiquery.core.javascript.JsScopeContext;
import org.odlabs.wiquery.ui.core.JsScopeUiEvent;
import org.odlabs.wiquery.ui.dialog.Dialog;
import se.su.dsv.scipro.SciProSession;
import se.su.dsv.scipro.components.FormFeedbackPanel;
import se.su.dsv.scipro.data.dao.interfaces.CategoryDao;
import se.su.dsv.scipro.data.dao.interfaces.ResourceDao;
import se.su.dsv.scipro.data.dao.interfaces.TagDao;
import se.su.dsv.scipro.data.dataobjects.Category;
import se.su.dsv.scipro.data.dataobjects.Resource;
import se.su.dsv.scipro.data.dataobjects.Tag;
import se.su.dsv.scipro.data.enums.ResourceType;
import se.su.dsv.scipro.knol.resource.model.CategoryModel;
import se.su.dsv.scipro.knol.resource.model.ResourceModel;
import se.su.dsv.scipro.knol.resource.page.ResourcePage;
import se.su.dsv.scipro.security.auth.MetaDataActionStrategy;
import se.su.dsv.scipro.security.auth.roles.Roles;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class ResourcesPanel extends Panel {
private static final long serialVersionUID = 1L;
@SpringBean
private TagDao tagDao;
@SpringBean
private ResourceDao resourceDao;
@SpringBean
private CategoryDao categoryDao;
private WebMarkupContainer linkDialogContainer, embedDialogContainer,
editCategoriesContainer, container, addCategoriesContainer;
private Dialog linkDialog, embedDialog, editCategoriesDialog,
addCategoriesDialog;
private TextField<String> linkNameEmbed;
private ResourceListPanel resourceListPanel;
public ResourcesPanel(String id) {
super(id);
container = new WebMarkupContainer("container");
container.setOutputMarkupId(true);
container
.add(resourceListPanel = new ResourceListPanel(
"resourceListPanel", resourceDao.findAll(),
ResourceType.NORMAL));
add(container);
resourceListPanel.setOutputMarkupId(true);
linkDialogContainer = new WebMarkupContainer("dialogContainer");
linkDialog = new Dialog("dialog");
linkDialog.setModal(true);
linkDialog.setAutoOpen(false);
linkDialog.setWidth(470);
linkDialog.add(linkDialogContainer);
add(linkDialog);
linkDialogContainer.setOutputMarkupId(true);
linkDialogContainer.add(new AddLinkResourceForm("resourceForm"));
embedDialogContainer = new WebMarkupContainer("embedDialogContainer");
embedDialog = new Dialog("embedDialog");
embedDialog.setModal(true);
embedDialog.setAutoOpen(false);
embedDialog.setWidth(470);
embedDialog.add(embedDialogContainer);
add(embedDialog);
embedDialogContainer.setOutputMarkupId(true);
embedDialogContainer.add(new AddEmbedResourceForm("embedResourceForm"));
editCategoriesContainer = new WebMarkupContainer(
"adminCategoriesContainer");
editCategoriesDialog = new Dialog("adminCategoriesDialog");
editCategoriesDialog.setModal(true);
editCategoriesDialog.setAutoOpen(false);
editCategoriesDialog.setWidth(470);
// editCategoriesDialog.setHeight(340);
editCategoriesDialog.setCloseEvent(new JsScopeUiEvent() {
private static final long serialVersionUID = 1L;
@Override
protected void execute(JsScopeContext scopeContext) {
scopeContext.append("window.location.reload()");
}
});
editCategoriesDialog.add(editCategoriesContainer);
add(editCategoriesDialog);
editCategoriesContainer.setOutputMarkupId(true);
editCategoriesContainer.add(new EditCategoriesForm(
"adminCategoriesForm"));
addCategoriesContainer = new WebMarkupContainer(
"addCategoriesContainer");
addCategoriesDialog = new Dialog("addCategoriesDialog");
addCategoriesDialog.setModal(true);
addCategoriesDialog.setAutoOpen(false);
addCategoriesDialog.setWidth(470);
// addCategoriesDialog.setHeight(340);
addCategoriesDialog.setCloseEvent(new JsScopeUiEvent() {
private static final long serialVersionUID = 1L;
@Override
protected void execute(JsScopeContext scopeContext) {
scopeContext.append("window.location.reload()");
}
});
addCategoriesDialog.add(addCategoriesContainer);
add(addCategoriesDialog);
addCategoriesContainer.setOutputMarkupId(true);
addCategoriesContainer.add(new AddCategoriesForm("addCategoriesForm"));
add(new AjaxLink<String>("addLinkResource", new Model<String>(
"Add Link Resource")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
target.addComponent(linkDialog);
linkDialog.open(target);
}
});
add(new AjaxLink<String>("addEmbedResource", new Model<String>(
"Add Link Resource")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
target.addComponent(embedDialog);
embedDialog.open(target);
}
@Override
public boolean isVisible(){
return false; //TODO Made invisible for initial deployment because it allows dangerous code to be pasted
}
});
AjaxLink<String> editCategories, addCategories;
add(editCategories = new AjaxLink<String>("adminCategories") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
target.addComponent(editCategoriesDialog);
editCategoriesDialog.open(target);
}
});
add(addCategories = new AjaxLink<String>("addCategories") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
target.addComponent(addCategoriesDialog);
addCategoriesDialog.open(target);
}
});
MetaDataActionStrategy.authorize(editCategories, Roles.ADMIN, true);
MetaDataActionStrategy.authorize(addCategories, Roles.ADMIN, true);
}
private class AddLinkResourceForm extends Form<ResourceModel> {
private static final long serialVersionUID = 1L;
public AddLinkResourceForm(String name) {
super(name, new CompoundPropertyModel<ResourceModel>(
new ResourceModel()));
final WebMarkupContainer feedbackContainer = new WebMarkupContainer(
"feedbackContainer");
feedbackContainer.setOutputMarkupId(true);
WebMarkupContainer feedbackPanel = new FormFeedbackPanel<ResourceModel>(
"feedbackPanel", this);
feedbackContainer.add(feedbackPanel);
add(feedbackContainer);
linkDialog.setTitle("Add Link Resource");
final TextArea<String> info;
final TextField<String> linkName;
UrlValidator urlValidator = new UrlValidator();
final TextField<String> linkAddress = new TextField<String>("link");
linkAddress.add(urlValidator);
final TextField<String> tags = new TextField<String>("tags");
tags.setRequired(true);
linkAddress.setRequired(true);
add(linkName = new TextField<String>("linkName"));
add(linkAddress);
add(info = new TextArea<String>("info"));
info.setRequired(true);
IChoiceRenderer<Category> choiceRenderer = new IChoiceRenderer<Category>() {
private static final long serialVersionUID = 1L;
// Implement dispay here
public Object getDisplayValue(Category category) {
return category.getCategoryName();
}
@Override
public String getIdValue(Category category, int arg1) {
return category.getId().toString();
}
};
final ListMultipleChoice<Category> categorySelectList = new ListMultipleChoice<Category>(
"selectedCategoryCollection", new ListModel<Category>(
categoryDao.findAll()), choiceRenderer) {
private static final long serialVersionUID = -7117603450416845711L;
};
categorySelectList.setRequired(true);
categorySelectList.setOutputMarkupId(true);
add(categorySelectList);
add(tags);
linkName.setRequired(true);
add(new AjaxButton("submitButton", new Model<String>(
"Save Resource")) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
Resource link = new Resource();
ResourceModel resourceModel = ((ResourceModel) form
.getModelObject());
String tags = resourceModel.getTags();
List<Tag> tagList = new ArrayList<Tag>();
if (tags != null) {
StringTokenizer stringTokenizer = new StringTokenizer(
tags, ",");
while (stringTokenizer.hasMoreTokens()) {
String tagString = stringTokenizer.nextToken()
.trim();
if (null != tagDao.findExactTagQuery(tagString)) {
tagList.add(tagDao.findExactTagQuery(tagString));
} else if (!tagString.equals("")) {
Tag tag = new Tag();
tagString = tagString.toLowerCase();
tag.setTag(tagString);
tag = tagDao.save(tag);
tagList.add(tag);
}
}
}
link.setCategoryList(new ArrayList<Category>(resourceModel
.getSelectedCategoryCollection()));
link.setInfo(resourceModel.getInfo());
link.setLink(resourceModel.getLink());
link.setCreator(SciProSession.get().getUser());
link.setTagList(tagList);
if (resourceModel.getLinkName() != null) {
link.setHeading(resourceModel.getLinkName());
}
resourceDao.save(link);
resourceModel.setLink("");
resourceModel.setLinkName("");
resourceModel.setTags("");
resourceModel.setInfo("");
linkDialog.close(target);
setResponsePage(ResourcePage.class);
}
@Override
protected void onError(final AjaxRequestTarget target,
final Form<?> form) {
target.addComponent(feedbackContainer);
}
});
}
}
private class AddEmbedResourceForm extends Form<ResourceModel> {
private static final long serialVersionUID = 1L;
public AddEmbedResourceForm(String name) {
super(name, new CompoundPropertyModel<ResourceModel>(
new ResourceModel()));
final WebMarkupContainer feedbackContainer = new WebMarkupContainer(
"feedbackContainer");
feedbackContainer.setOutputMarkupId(true);
WebMarkupContainer feedbackPanel = new FormFeedbackPanel<ResourceModel>(
"feedbackPanel", this);
feedbackContainer.add(feedbackPanel);
add(feedbackContainer);
embedDialog.setTitle("Add Embed Resource");
add(linkNameEmbed = new TextField<String>("linkName"));
linkNameEmbed.setRequired(true);
final TextArea<String> embedTextArea;
add(embedTextArea = new TextArea<String>("embedCode"));
embedTextArea.setRequired(true);
final TextArea<String> info;
add(info = new TextArea<String>("info"));
info.setRequired(true);
final TextField<String> tags = new TextField<String>("tags");
tags.setRequired(true);
IChoiceRenderer<Category> choiceRenderer = new IChoiceRenderer<Category>() {
private static final long serialVersionUID = 1L;
// Implement dispay here
public Object getDisplayValue(Category category) {
return category.getCategoryName();
}
@Override
public String getIdValue(Category category, int arg1) {
return category.getId().toString();
}
};
final ListMultipleChoice<Category> categorySelectList = new ListMultipleChoice<Category>(
"selectedCategoryCollection", new ListModel<Category>(
categoryDao.findAll()), choiceRenderer) {
private static final long serialVersionUID = -7117603450416845711L;
};
categorySelectList.setRequired(true);
categorySelectList.setOutputMarkupId(true);
add(categorySelectList);
add(tags);
add(new AjaxButton("submitButton", new Model<String>(
"Save Resource")) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
Resource link;
link = new Resource();
ResourceModel resourceModel = ((ResourceModel) form
.getModelObject());
String tags = resourceModel.getTags();
List<Tag> tagList = new ArrayList<Tag>();
if (tags != null) {
StringTokenizer stringTokenizer = new StringTokenizer(
tags, ",");
while (stringTokenizer.hasMoreTokens()) {
String tagString = stringTokenizer.nextToken()
.trim();
if (null != tagDao.findExactTagQuery(tagString)) {
tagList.add(tagDao.findExactTagQuery(tagString));
} else if (!tagString.equals("")) {
Tag tag = new Tag();
tagString = tagString.toLowerCase();
tag.setTag(tagString);
tag = tagDao.save(tag);
tagList.add(tag);
}
}
}
link.setHeading(resourceModel.getLinkName());
link.setEmbedCode(resourceModel.getEmbedCode());
link.setInfo(resourceModel.getInfo());
link.setCategoryList(new ArrayList<Category>(resourceModel
.getSelectedCategoryCollection()));
link.setCreator(SciProSession.get().getUser());
link.setTagList(tagList);
if (resourceModel.getLinkName() != null) {
link.setHeading(resourceModel.getLinkName());
}
resourceDao.save(link);
resourceModel.setLink("");
resourceModel.setLinkName("");
resourceModel.setTags("");
resourceModel.setInfo("");
embedDialog.close(target);
setResponsePage(ResourcePage.class);
}
@Override
protected void onError(final AjaxRequestTarget target,
final Form<?> form) {
target.addComponent(feedbackContainer);
}
});
}
}
private class EditCategoriesForm extends Form<CategoryModel> {
private static final long serialVersionUID = 1L;
private Category category;
public EditCategoriesForm(String name) {
super(name, new CompoundPropertyModel<CategoryModel>(
new CategoryModel()));
final WebMarkupContainer feedbackContainer = new WebMarkupContainer(
"feedbackContainer");
feedbackContainer.setOutputMarkupId(true);
WebMarkupContainer feedbackPanel = new FormFeedbackPanel<CategoryModel>(
"feedbackPanel", this);
feedbackContainer.add(feedbackPanel);
add(feedbackContainer);
editCategoriesDialog.setTitle("Edit Categories");
final TextField<String> categoryName = new TextField<String>(
"categoryName");
add(categoryName);
IChoiceRenderer<Category> choiceRenderer = new IChoiceRenderer<Category>() {
private static final long serialVersionUID = 1L;
// Implement dispay here
public Object getDisplayValue(Category category) {
return category.getCategoryName();
}
@Override
public String getIdValue(Category category, int arg1) {
return category.getId().toString();
}
};
final ListChoice<Category> categorySelectList = new ListChoice<Category>(
"selectedCategory", new ListModel<Category>(
categoryDao.findAll()), choiceRenderer) {
private static final long serialVersionUID = 1L;
@Override
protected CharSequence getDefaultChoice(Object selected) {
return "";
}
};
categorySelectList.setOutputMarkupId(true);
OnChangeAjaxBehavior userSelectBehaviour = new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 3412906970812300312L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
category = categoryDao.reLoad(getModelObject()
.getCategory());
if (category != null) {
getModelObject().setCategoryName(
category.getCategoryName());
target.addComponent(editCategoriesContainer);
}
}
};
add(new AjaxButton("deleteCategory", new Model<String>(
"Delete Category")) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
if (category != null) {
category = categoryDao.reLoad(category);
for (Resource resource : resourceDao
.findResourcesByCategory(category)) {
List<Category> categoryList = resource
.getCategoryList();
categoryList.remove(category);
resource.setCategoryList(categoryList);
resourceDao.save(resource);
}
categoryDao.delete(category);
categorySelectList.setChoices(categoryDao.findAll());
EditCategoriesForm.this.getModelObject()
.setCategoryName("");
target.addComponent(editCategoriesContainer);
info("Category deleted");
} else {
error("No category selected");
}
}
@Override
protected IAjaxCallDecorator getAjaxCallDecorator() {
return new AjaxCallDecorator() {
private static final long serialVersionUID = 8989126586010432130L;
/*
* (non-Javadoc)
*
* @see
* org.apache.wicket.ajax.calldecorator.AjaxCallDecorator
* #decorateScript(java.lang.CharSequence)
*/
@Override
public CharSequence decorateScript(CharSequence script) {
String ret = "if(!confirm('Do you really want to delete?')) return false; "
+ script;
return ret;
}
};
}
@Override
protected void onError(final AjaxRequestTarget target,
final Form<?> form) {
target.addComponent(feedbackContainer);
}
});
categorySelectList.add(userSelectBehaviour);
add(categorySelectList);
add(new AjaxButton("editButton", new Model<String>("Save Edit")) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
if (category == null) {
error("No category selected");
} else if (EditCategoriesForm.this.getModelObject()
.getCategoryName() == null) {
error("Category must have a name");
} else if (categoryDao
.reLoad(category)
.getCategoryName()
.equals(EditCategoriesForm.this.getModelObject()
.getCategoryName())) {
error("No change");
} else {
category = categoryDao.reLoad(category);
category.setCategoryName(EditCategoriesForm.this
.getModelObject().getCategoryName());
categoryDao.save(category);
info("Category changed");
categorySelectList.setChoices(categoryDao.findAll());
target.addComponent(editCategoriesContainer);
}
}
@Override
protected void onError(final AjaxRequestTarget target,
final Form<?> form) {
target.addComponent(feedbackContainer);
}
});
add(new AjaxButton("closeButton", new Model<String>("Close")) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
editCategoriesDialog.close(target);
setResponsePage(ResourcePage.class);
}
@Override
protected void onError(final AjaxRequestTarget target,
final Form<?> form) {
target.addComponent(feedbackContainer);
}
});
}
}
private class AddCategoriesForm extends Form<CategoryModel> {
private static final long serialVersionUID = 1L;
public AddCategoriesForm(String name) {
super(name, new CompoundPropertyModel<CategoryModel>(
new CategoryModel()));
final WebMarkupContainer feedbackContainer = new WebMarkupContainer(
"feedbackContainer");
feedbackContainer.setOutputMarkupId(true);
WebMarkupContainer feedbackPanel = new FormFeedbackPanel<CategoryModel>(
"feedbackPanel", this);
feedbackContainer.add(feedbackPanel);
add(feedbackContainer);
addCategoriesDialog.setTitle("Add Categories");
final TextField<String> categoryName = new TextField<String>(
"categoryName");
add(categoryName);
IChoiceRenderer<Category> choiceRenderer = new IChoiceRenderer<Category>() {
private static final long serialVersionUID = 1L;
// Implement dispay here
public Object getDisplayValue(Category category) {
return category.getCategoryName();
}
@Override
public String getIdValue(Category category, int arg1) {
return category.getId().toString();
}
};
final ListChoice<Category> categorySelectList = new ListChoice<Category>(
"selectedCategory", new ListModel<Category>(
categoryDao.findAll()), choiceRenderer) {
private static final long serialVersionUID = 1L;
@Override
protected CharSequence getDefaultChoice(Object selected) {
return "";
}
};
categorySelectList.setOutputMarkupId(true);
add(categorySelectList);
add(new AjaxButton("addButton", new Model<String>("Add Category")) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
CategoryModel categoryModel = (CategoryModel) form
.getModelObject();
if (categoryModel.getCategoryName() == null) {
error("Category must have a name");
} else {
Category category = categoryDao
.findExactCategoryQuery(categoryModel
.getCategoryName());
if (category == null) {
Category cat = new Category();
cat.setCategoryName(categoryModel.getCategoryName());
categoryDao.save(cat);
categorySelectList
.setChoices(categoryDao.findAll());
AddCategoriesForm.this.getModelObject()
.setCategoryName("");
target.addComponent(addCategoriesContainer);
info("Category added");
} else {
error("Category already exists");
}
}
}
@Override
protected void onError(final AjaxRequestTarget target,
final Form<?> form) {
target.addComponent(feedbackContainer);
}
});
add(new AjaxButton("closeButton", new Model<String>("Close")) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
addCategoriesDialog.close(target);
setResponsePage(ResourcePage.class);
}
@Override
protected void onError(final AjaxRequestTarget target,
final Form<?> form) {
target.addComponent(feedbackContainer);
}
});
}
}
}

@ -1,11 +0,0 @@
dialog.dialogContainer.resourceForm.link=Link Address
dialog.dialogContainer.resourceForm.linkName=Link Name
dialog.dialogContainer.resourceForm.info=Info
dialog.dialogContainer.resourceForm.tags=Tags
dialog.dialogContainer.resourceForm.selectedCategoryCollection = Categories
embedDialog.embedDialogContainer.embedResourceForm.linkName=Heading
embedDialog.embedDialogContainer.embedResourceForm.embedCode=Embed Code
embedDialog.embedDialogContainer.embedResourceForm.info=Info
embedDialog.embedDialogContainer.embedResourceForm.tags=Tags
embedDialog.embedDialogContainer.embedResourceForm.selectedCategoryCollection=Categories
Required='${label}' is required