Komponenter
git-svn-id: svn://svn.dsv.su.se/scipro/scipro/trunk@324 73ecded7-942e-4092-bab0-0e58ef0ee984
This commit is contained in:
parent
cc1d0af462
commit
58075c86a7
src/main/java/se/su/dsv/scipro/components
@ -21,6 +21,7 @@ import org.joda.time.MutableDateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.odlabs.wiquery.ui.datepicker.DatePicker;
|
||||
import org.odlabs.wiquery.ui.datepicker.DatePicker.ShowOnEnum;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -79,6 +80,8 @@ public class CustomDateTimeField extends FormComponentPanel<Date> {
|
||||
}
|
||||
};
|
||||
dateField.setDateFormat("yy-mm-dd");
|
||||
dateField.setShowOn(ShowOnEnum.BOTH);
|
||||
dateField.setButtonText("<div class=\"ui-icon ui-icon-calendar\"></div>");
|
||||
add(dateField);
|
||||
|
||||
add(hoursField = new TextField<Integer>("hours", new PropertyModel<Integer>(this, "hours"),
|
||||
|
@ -0,0 +1,3 @@
|
||||
<wicket:panel>
|
||||
<span wicket:id="text"></span> <a href="#" wicket:id="link"><span wicket:id="linkLabel"></span></a>
|
||||
</wicket:panel>
|
@ -0,0 +1,159 @@
|
||||
package se.su.dsv.scipro.components;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
||||
import org.apache.wicket.markup.ComponentTag;
|
||||
import org.apache.wicket.markup.MarkupStream;
|
||||
import org.apache.wicket.markup.html.basic.Label;
|
||||
import org.apache.wicket.markup.html.basic.MultiLineLabel;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
import org.apache.wicket.model.Model;
|
||||
import org.apache.wicket.util.string.AppendingStringBuffer;
|
||||
import org.apache.wicket.util.string.Strings;
|
||||
|
||||
/**
|
||||
* Component that works quite like the MultiLineLabel but initially hides a
|
||||
* part of the text. A link is appended to the end of the text and lets the
|
||||
* user expand the full text. It will only show a link if the string is
|
||||
* longer than the given maxLength.
|
||||
*
|
||||
* Note: If you use this panel in a repeater, you need to call setOutputMarkupId(true) on
|
||||
* the repeater item!
|
||||
*
|
||||
* @author Dan Kjellman <dan-kjel@dsv.su.se>
|
||||
*
|
||||
*/
|
||||
public class ExpandableMultiLineLabel extends Panel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String fullString = "";
|
||||
private String cutString = "";
|
||||
private String stringShowing = "";
|
||||
int fullStringLength = 0;
|
||||
private boolean isCut = false;
|
||||
private boolean needsLink = false;
|
||||
private String linkText = "more";
|
||||
private boolean useLineBreaksWhenLessShown = false;
|
||||
|
||||
public ExpandableMultiLineLabel(String id, final int maxLength, final String str, boolean useLineBreaksWhenLessShown){
|
||||
super(id);
|
||||
setOutputMarkupId(true);
|
||||
this.useLineBreaksWhenLessShown = useLineBreaksWhenLessShown;
|
||||
this.fullString = str;
|
||||
this.fullStringLength = str.length();
|
||||
this.needsLink = fullStringLength > maxLength;
|
||||
if(needsLink){
|
||||
cutString = fullString.substring(0, maxLength - 1) + "...";
|
||||
stringShowing = cutString;
|
||||
} else {
|
||||
stringShowing = fullString;
|
||||
}
|
||||
isCut = needsLink;
|
||||
|
||||
add(new Label("text", new Model<String>(){
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public String getObject(){
|
||||
return stringShowing;
|
||||
}
|
||||
}){
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag)
|
||||
{
|
||||
final CharSequence body = toMultilineMarkup(getDefaultModelObjectAsString());
|
||||
replaceComponentTagBody(markupStream, openTag, body);
|
||||
}
|
||||
});
|
||||
|
||||
AjaxLink<Void> link = new AjaxLink<Void>("link"){
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
if(fullStringLength > maxLength){
|
||||
if(isCut){
|
||||
stringShowing = fullString;
|
||||
linkText = "less";
|
||||
} else {
|
||||
stringShowing = cutString;
|
||||
linkText = "more";
|
||||
}
|
||||
isCut = !isCut;
|
||||
} else {
|
||||
stringShowing = fullString;
|
||||
}
|
||||
target.addComponent(ExpandableMultiLineLabel.this);
|
||||
}
|
||||
};
|
||||
link.setVisible(needsLink);
|
||||
|
||||
link.add(new Label("linkLabel", new Model<String>(){
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public String getObject(){
|
||||
return linkText;
|
||||
}
|
||||
}));
|
||||
add(link);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
// ensure that this component is embedded in a <span> ... </span>
|
||||
protected void onComponentTag(ComponentTag pTag) {
|
||||
super.onComponentTag(pTag);
|
||||
pTag.setName("span");
|
||||
}
|
||||
|
||||
/*
|
||||
* Wrap all paragraphs in a <p>-tag, A display: inline style tag will be
|
||||
* appended to the last <p> so the link will appear directly after the last
|
||||
* char
|
||||
*/
|
||||
public CharSequence toMultilineMarkup(final CharSequence s) {
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ArrayList<CharSequence> lines = new ArrayList<CharSequence>();
|
||||
final AppendingStringBuffer buffer = new AppendingStringBuffer();
|
||||
int numLineBreaks = 0;
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
final char c = s.charAt(i);
|
||||
|
||||
switch (c) {
|
||||
case '\n' :
|
||||
if(isCut && !useLineBreaksWhenLessShown){
|
||||
buffer.append(c);
|
||||
} else {
|
||||
numLineBreaks++;
|
||||
lines.add(buffer.toString());
|
||||
buffer.clear();
|
||||
}
|
||||
break;
|
||||
|
||||
case '\r' :
|
||||
break;
|
||||
|
||||
default :
|
||||
buffer.append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
lines.add(buffer.toString());
|
||||
buffer.clear();
|
||||
CharSequence last = lines.get(numLineBreaks);
|
||||
last = "<p style=\"display:inline;\">" + last + "</p>";
|
||||
lines.remove(numLineBreaks);
|
||||
|
||||
for(int i = 0; i < numLineBreaks; i++){
|
||||
buffer.append("<p>" + lines.get(i) + "</p>");
|
||||
}
|
||||
buffer.append(last);
|
||||
return buffer;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package se.su.dsv.scipro.components;
|
||||
|
||||
import org.apache.wicket.feedback.ComponentFeedbackMessageFilter;
|
||||
import org.apache.wicket.feedback.FeedbackMessage;
|
||||
import org.apache.wicket.markup.html.form.Form;
|
||||
import org.apache.wicket.markup.html.panel.FeedbackPanel;
|
||||
|
||||
/**
|
||||
* If you have several forms on one page and want to filter the feedbackmessages
|
||||
* according to in which form they occurred, use this feedbackpanel.
|
||||
*
|
||||
* @author Dan Kjellman <dan-kjel@dsv.su.se>
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class FormFeedbackPanel<T> extends FeedbackPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public FormFeedbackPanel(String id, final Form<T> form){
|
||||
super(id, new ComponentFeedbackMessageFilter(form){
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public boolean accept(FeedbackMessage message) {
|
||||
return message.getReporter() == form || form.contains(message.getReporter(), true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package se.su.dsv.scipro.components;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.wicket.ajax.IAjaxIndicatorAware;
|
||||
import org.apache.wicket.extensions.ajax.markup.html.AjaxIndicatorAppender;
|
||||
import org.apache.wicket.markup.html.form.DropDownChoice;
|
||||
import org.apache.wicket.markup.html.form.IChoiceRenderer;
|
||||
import org.apache.wicket.model.IModel;
|
||||
|
||||
|
||||
/**
|
||||
* Works just like a normal DropDownChoice but adds a "busy-indicator"
|
||||
*
|
||||
* Use it when you need a component that updates something with ajax when the selection changes.
|
||||
*
|
||||
* @author Dan Kjellman <dan-kjel@dsv.su.se>
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class IndicatingAjaxDropDownChoice<T> extends DropDownChoice<T> implements IAjaxIndicatorAware {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private AjaxIndicatorAppender indicatorAppender = new AjaxIndicatorAppender();
|
||||
|
||||
public IndicatingAjaxDropDownChoice(final String id){
|
||||
super(id);
|
||||
add(indicatorAppender);
|
||||
}
|
||||
|
||||
public IndicatingAjaxDropDownChoice(final String id, final List<? extends T> choices){
|
||||
super(id, choices);
|
||||
add(indicatorAppender);
|
||||
}
|
||||
|
||||
public IndicatingAjaxDropDownChoice(final String id, final List<? extends T> data,
|
||||
final IChoiceRenderer<? super T> renderer) {
|
||||
super(id, data, renderer);
|
||||
add(indicatorAppender);
|
||||
}
|
||||
|
||||
public IndicatingAjaxDropDownChoice(final String id, IModel<T> model, final List<? extends T> choices) {
|
||||
super(id, model, choices);
|
||||
add(indicatorAppender);
|
||||
}
|
||||
|
||||
public IndicatingAjaxDropDownChoice(final String id, IModel<T> model, final List<? extends T> data,
|
||||
final IChoiceRenderer<? super T> renderer){
|
||||
super(id, model, data, renderer);
|
||||
add(indicatorAppender);
|
||||
}
|
||||
|
||||
public IndicatingAjaxDropDownChoice(String id, IModel<? extends List<? extends T>> choices) {
|
||||
super(id, choices);
|
||||
add(indicatorAppender);
|
||||
}
|
||||
|
||||
public IndicatingAjaxDropDownChoice(String id, IModel<T> model, IModel<? extends List<? extends T>> choices){
|
||||
super(id, model, choices);
|
||||
add(indicatorAppender);
|
||||
}
|
||||
|
||||
public IndicatingAjaxDropDownChoice(String id, IModel<? extends List<? extends T>> choices,
|
||||
IChoiceRenderer<? super T> renderer) {
|
||||
super(id, choices, renderer);
|
||||
add(indicatorAppender);
|
||||
}
|
||||
|
||||
public IndicatingAjaxDropDownChoice(String id, IModel<T> model, IModel<? extends List<? extends T>> choices,
|
||||
IChoiceRenderer<? super T> renderer){
|
||||
super(id, model, choices, renderer);
|
||||
add(indicatorAppender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAjaxIndicatorMarkupId() {
|
||||
return indicatorAppender.getMarkupId();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user