Просмотр исходного кода

User agent is now showed on first request. Added also system status reporting (memory resources) which is used to track demo application healthiness on production site.

svn changeset:882/svn branch:trunk
tags/6.7.0.beta1
Jani Laakso 17 лет назад
Родитель
Сommit
9585067b8a

+ 19
- 4
src/com/itmill/toolkit/demo/features/Feature.java Просмотреть файл

@@ -52,6 +52,8 @@ public abstract class Feature extends CustomComponent {
protected PropertyPanel propertyPanel;

private Label javadoc;
private Label description;

/** Constuctor for the feature component */
public Feature() {
@@ -94,9 +96,8 @@ public abstract class Feature extends CustomComponent {
ts = new TabSheet();

// Description tab
String desc = getDescriptionXHTML();
String title = getTitle();
if (desc != null) {
if (getDescriptionXHTML() != null) {
OrderedLayout mainLayout = new OrderedLayout(
OrderedLayout.ORIENTATION_VERTICAL);
OrderedLayout layout = new OrderedLayout(
@@ -106,14 +107,15 @@ public abstract class Feature extends CustomComponent {
layout.addComponent(new Embedded("", new ClassResource(
getImage(), this.getApplication())));
String label = "";
label += desc;
label += getDescriptionXHTML();
if (propsReminder)
label += PROP_REMINDER_TEXT;
if (title != null) {
layout.addComponent(new Label("<h3>" + title + "</h3>",
Label.CONTENT_XHTML));
}
mainLayout.addComponent(new Label(label, Label.CONTENT_XHTML));
description = new Label(label, Label.CONTENT_XHTML);
mainLayout.addComponent(description);

ts.addTab(mainLayout, "Description", null);
}
@@ -181,5 +183,18 @@ public abstract class Feature extends CustomComponent {
public void setPropsReminder(boolean propsReminder) {
this.propsReminder = propsReminder;
}
public void updateDescription() {
String label = "";
label += getDescriptionXHTML();
if (propsReminder)
label += PROP_REMINDER_TEXT;
description.setValue(label);
}

// Fix for #512
public Label getDescription() {
return description;
}

}

+ 89
- 15
src/com/itmill/toolkit/demo/features/IntroWelcome.java Просмотреть файл

@@ -28,16 +28,33 @@

package com.itmill.toolkit.demo.features;

import java.net.URL;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;

import com.itmill.toolkit.terminal.DownloadStream;
import com.itmill.toolkit.terminal.ExternalResource;
import com.itmill.toolkit.terminal.PaintException;
import com.itmill.toolkit.terminal.PaintTarget;
import com.itmill.toolkit.terminal.ParameterHandler;
import com.itmill.toolkit.terminal.URIHandler;
import com.itmill.toolkit.terminal.web.ApplicationServlet;
import com.itmill.toolkit.terminal.web.WebBrowser;
import com.itmill.toolkit.ui.Component;
import com.itmill.toolkit.ui.Form;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.Link;
import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.Panel;
import com.itmill.toolkit.ui.Select;

public class IntroWelcome extends Feature {
public class IntroWelcome extends Feature implements URIHandler,
ParameterHandler {

private WebBrowser webBrowser = null;

Panel panel = new Panel();

private static final String WELCOME_TEXT_UPPER = ""
+ "This application lets you view and play with some features of "
@@ -60,13 +77,15 @@ public class IntroWelcome extends Feature {

private static final String WELCOME_TEXT_LOWER = ""
+ "This area contains the selected component's description, list of properties, javadoc"
+ " and optional code sample."
+ "<br /><br />To see how simple it is to create IT Mill Toolkit application,"
+ " click <em>Code Sample</em> tab."
+ "<br /><br />Start your tour now by selecting features from the list"
+ " and optional code sample. "
+ "Start your tour now by selecting features from the list"
+ " on the left and remember to experiment with the <b>Properties panel</b>"
+ " located at the top right corner area.";

private String description = WELCOME_TEXT_LOWER
+ "<br /><br />IT Mill Toolkit version: "
+ ApplicationServlet.VERSION;

public IntroWelcome() {
super();
}
@@ -75,7 +94,6 @@ public class IntroWelcome extends Feature {

OrderedLayout l = new OrderedLayout();

Panel panel = new Panel();
panel.setCaption("Welcome to the IT Mill Toolkit feature tour!");
l.addComponent(panel);

@@ -85,8 +103,6 @@ public class IntroWelcome extends Feature {
label.setContentMode(Label.CONTENT_XHTML);
label.setValue(WELCOME_TEXT_UPPER);

// Propertiesversion.setValue("IT Mill Toolkit version:
// "+ApplicationServlet.VERSION);
propertyPanel = new PropertyPanel(panel);
Form ap = propertyPanel.createBeanPropertySet(new String[] { "width",
"height" });
@@ -116,14 +132,22 @@ public class IntroWelcome extends Feature {
+ " }\n" + "}\n";
}

/**
* @see com.itmill.toolkit.demo.features.Feature#getDescriptionXHTML()
*/
// not ready yet to give description, see paint instead
protected String getDescriptionXHTML() {
WebBrowser wb = (WebBrowser) getWindow().getTerminal();
return WELCOME_TEXT_LOWER + "<br /><br />IT Mill Toolkit version: "
+ ApplicationServlet.VERSION +
(wb != null ? "<br />Browser: " + wb.getBrowserApplication(): "");
return description;
}

// Hack for #512: set description right (WebBrowser now exists)
public void paint(PaintTarget target) throws PaintException {
if (webBrowser == null) {
webBrowser = (WebBrowser) getWindow().getTerminal();
if (webBrowser != null) {
super.getDescription().setValue(
description + "<br />Browser: "
+ webBrowser.getBrowserApplication());
}
}
super.paint(target);
}

protected String getImage() {
@@ -134,4 +158,54 @@ public class IntroWelcome extends Feature {
return "Welcome";
}

/**
* Add URI and parametes handlers to window.
*
* @see com.itmill.toolkit.ui.Component#attach()
*/
public void attach() {
super.attach();
getWindow().addURIHandler(this);
getWindow().addParameterHandler(this);
}

/**
* Remove all handlers from window
*
* @see com.itmill.toolkit.ui.Component#detach()
*/
public void detach() {
super.detach();
getWindow().removeURIHandler(this);
getWindow().removeParameterHandler(this);
}

/**
* Update URI
*
* @see com.itmill.toolkit.terminal.URIHandler#handleURI(URL, String)
*/
public DownloadStream handleURI(URL context, String relativeUri) {
return null;
}

/**
* Show system status if systemStatus is given on URL
*
* @see com.itmill.toolkit.terminal.ParameterHandler#handleParameters(Map)
*/
public void handleParameters(Map parameters) {
for (Iterator i = parameters.keySet().iterator(); i.hasNext();) {
String name = (String) i.next();
if (name.equals("systemStatus")) {
String status = "";
status += "timestamp=" + new Date() + " ";
status += "free=" + Runtime.getRuntime().freeMemory() + ", ";
status += "total=" + Runtime.getRuntime().totalMemory() + ", ";
status += "max=" + Runtime.getRuntime().maxMemory() + "\n";
System.out.println(status);
}
}
}

}

Загрузка…
Отмена
Сохранить