API Overview API Index Package Overview Direct link to this page
JavaOnTracks 0.1.2
  net.jot.web.widget. JOTExampleWidget View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

/*
 * JavaOnTrack/Jotwiki
 * Thibaut Colar.
 * tcolar-jot AT colar  DOT net
 */

package net.jot.web.widget;

import java.util.Hashtable;
import net.jot.web.JOTFlowRequest;
import net.jot.web.ajax.JOTAjaxHelper;

/**
 * Example widget that shows the ammount of memory available on the server
 * Uses ajax to autorefresh
 * @author thibautc
 */
public class JOTExampleWidget extends JOTWidgetBase
{
    /*
     * <jot:widget class="net.jot.web.widget.JOTExampleWidget" width="28" style="7" refreshEvery="5"/> ...
    */
    
    public String renderWidget(Hashtable options)
    {
        int refreshEvery=properties.getRefreshEvery();
        String color=properties.getPropertyDefaultValue(JOTWidgetBaseProperties.PROP_BG_COLOR, options, "#ff0000");
        String ftSize=properties.getPropertyDefaultValue("fontSize", options, "12");
        
        String html="";
        html+="<span style='background-color:"+color+";font-size:"+ftSize+"' id='example_widget_"+uniqueId+"'>Mem: N/A %</span>";
        if(refreshEvery==-1)
        {
            // manual refresh button
            html+="<button onclick=\""+getJscriptFuncName()+"('');\">Update</button>";
        }
        html+="<br/><br/>";
        return html;
    }

    public boolean validatePermissions()
    {
        // no permissions needed.
        return true;
    }

    
    public String getAjaxCallbackJavascript()
    {
        String  js=JOTAjaxHelper.setJscriptVarValueFromAjaxVar("mem","mem",uniqueId);
        js +=      "mem = 'Mem: '+mem+'%';\n"; 
        js+=       JOTAjaxHelper.setElementInnerValue("example_widget",uniqueId,"mem");
        
        return JOTAjaxHelper.buildStandardCallbackJscript(js, uniqueId);
    }

    public String getAjaxAction()
    {
        return "examplewidget.do";
    }

    public Hashtable widgetAjaxCall(JOTFlowRequest request)
    {
        Runtime r = Runtime.getRuntime();
        float freemem=r.freeMemory();
        float totalmem= r.totalMemory();
        long memPct = (long)(freemem*100/totalmem);
        
        Hashtable hash=new Hashtable();
        hash.put("mem",""+memPct);
        
        return hash;
    }

    public JOTWidgetBaseProperties getWidgetProperties()
    {
        return new JOTWidgetBaseProperties();
    }

    public void customizeProperties()
    {
        properties.removeProperty(JOTWidgetBaseProperties.PROP_BORDER_TYPE);
        properties.removeProperty(JOTWidgetBaseProperties.PROP_BORDER_WIDTH);
        properties.addProperty("fontSize",new JOTWidgetProperty(JOTWidgetProperty.TYPE_SELECT, new String[]{"5","6","7","8","12","15","20","30"},"12"));
    }

    public String getShortName()
    {
        return "JOT Example widget";
    }
}

Generated By: JavaOnTracks Doclet 0.1.5     ©Thibaut Colar