View File | Revision Log | Show Annotations | Download File | View Changeset
/hippo/attic/forge/rating-field/trunk/addon/src/main/java/org/onehippo/forge/rating/RatingPlugin.java
Revision: 58810
Committed: Mon Apr 24 09:06:49 2017 UTC (16 months, 3 weeks ago) by jhoffman
File size: 2219 byte(s)
Log Message:
HIPFORGE-99 move rating-field code back from GitHub to SVN attic. Plugin is unmaintained after all.

File Contents

# Content
1 /*
2 * Copyright 2008 Hippo.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.onehippo.forge.rating;
17
18 import org.apache.wicket.markup.html.basic.Label;
19 import org.apache.wicket.model.Model;
20 import org.apache.wicket.model.PropertyModel;
21 import org.hippoecm.frontend.editor.ITemplateEngine;
22 import org.hippoecm.frontend.model.properties.JcrPropertyValueModel;
23 import org.hippoecm.frontend.plugin.IPluginContext;
24 import org.hippoecm.frontend.plugin.config.IPluginConfig;
25 import org.hippoecm.frontend.service.render.RenderPlugin;
26 import org.hippoecm.frontend.widgets.TextFieldWidget;
27 import org.onehippo.forge.rating.model.Rating;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class RatingPlugin extends RenderPlugin {
32 @SuppressWarnings("unused")
33 private final static String SVN_ID = "$Id$";
34
35 private static final long serialVersionUID = 1L;
36
37 static final Logger log = LoggerFactory.getLogger(RatingPlugin.class);
38
39 private Rating rating;
40
41 public RatingPlugin(IPluginContext context, IPluginConfig config) {
42 super(context, config);
43
44 this.rating = new Rating((JcrPropertyValueModel) getModel());
45
46 String mode = config.getString("mode", "view");
47 if (ITemplateEngine.EDIT_MODE.equals(mode)) {
48 TextFieldWidget widget = new TextFieldWidget("value",
49 new PropertyModel(rating, "rating"));
50 if (config.getString("size") != null) {
51 widget.setSize(config.getString("size"));
52 }
53 add(widget);
54 } else {
55 String value = "";
56 for (long i = 0; i < rating.getRating(); i++) {
57 value = value + "*";
58 }
59 add(new Label("value", new Model(value)));
60 }
61 }
62
63 @Override
64 protected void onDetach() {
65 rating.detach();
66 super.onDetach();
67 }
68
69 }

Properties

Name Value
svn:eol-style native
svn:keywords Id