/** | /** | ||||
* A simple data object containing one typed value. This class is a | * A simple data object containing one typed value. This class is a | ||||
* straightforward implementation of the the | |||||
* {@link com.vaadin.data.Property} interface. | |||||
* straightforward implementation of the the {@link com.vaadin.data.Property} | |||||
* interface. | |||||
* | * | ||||
* @author IT Mill Ltd. | * @author IT Mill Ltd. | ||||
* @version | * @version |
/** | /** | ||||
* Validator base class for validating strings. See | * Validator base class for validating strings. See | ||||
* {@link com.vaadin.data.validator.AbstractValidator} for more | |||||
* information. | |||||
* {@link com.vaadin.data.validator.AbstractValidator} for more information. | |||||
* | * | ||||
* <p> | * <p> | ||||
* If the validation fails, the exception thrown contains the error message with | * If the validation fails, the exception thrown contains the error message with |
import com.vaadin.data.Validator; | import com.vaadin.data.Validator; | ||||
/** | /** | ||||
* Default Validator base class. See | |||||
* {@link com.vaadin.data.validator.Validator} for more information. | |||||
* Default Validator base class. See {@link com.vaadin.data.validator.Validator} | |||||
* for more information. | |||||
* <p> | * <p> | ||||
* If the validation fails, the exception thrown contains the error message with | * If the validation fails, the exception thrown contains the error message with | ||||
* its argument 0 replaced with the toString() of the object being validated. | * its argument 0 replaced with the toString() of the object being validated. |
* complete according to RFC 822 but handles the vast majority of valid e-mail | * complete according to RFC 822 but handles the vast majority of valid e-mail | ||||
* addresses correctly. | * addresses correctly. | ||||
* | * | ||||
* See {@link com.vaadin.data.validator.AbstractStringValidator} for | |||||
* more information. | |||||
* See {@link com.vaadin.data.validator.AbstractStringValidator} for more | |||||
* information. | |||||
* | * | ||||
* @author IT Mill Ltd. | * @author IT Mill Ltd. | ||||
* @version | * @version |
* class really will send the events, or if it just defines the methods to | * class really will send the events, or if it just defines the methods to | ||||
* be able to implement an interface. | * be able to implement an interface. | ||||
* </p> | * </p> | ||||
* | |||||
* @since 6.2 | * @since 6.2 | ||||
* @see FocusListener | * @see FocusListener | ||||
* @see FocusEvent | * @see FocusEvent | ||||
* class really will send the events, or if it just defines the methods to | * class really will send the events, or if it just defines the methods to | ||||
* be able to implement an interface. | * be able to implement an interface. | ||||
* </p> | * </p> | ||||
* | |||||
* @since 6.2 | * @since 6.2 | ||||
* @see BlurListener | * @see BlurListener | ||||
* @see BlurEvent | * @see BlurEvent |
* | * | ||||
* <p> | * <p> | ||||
* For more information on the inheritable event mechanism see the | * For more information on the inheritable event mechanism see the | ||||
* {@link com.vaadin.event com.vaadin.event package | |||||
* documentation}. | |||||
* {@link com.vaadin.event com.vaadin.event package documentation}. | |||||
* </p> | * </p> | ||||
* | * | ||||
* @author IT Mill Ltd. | * @author IT Mill Ltd. | ||||
* | * | ||||
* <p> | * <p> | ||||
* For more information on the inheritable event mechanism see the | * For more information on the inheritable event mechanism see the | ||||
* {@link com.vaadin.event com.vaadin.event package | |||||
* documentation}. | |||||
* {@link com.vaadin.event com.vaadin.event package documentation}. | |||||
* </p> | * </p> | ||||
* | * | ||||
* @param eventType | * @param eventType | ||||
* | * | ||||
* <p> | * <p> | ||||
* For more information on the inheritable event mechanism see the | * For more information on the inheritable event mechanism see the | ||||
* {@link com.vaadin.event com.vaadin.event package | |||||
* documentation}. | |||||
* {@link com.vaadin.event com.vaadin.event package documentation}. | |||||
* </p> | * </p> | ||||
* | * | ||||
* @param eventType | * @param eventType | ||||
* | * | ||||
* <p> | * <p> | ||||
* For more information on the inheritable event mechanism see the | * For more information on the inheritable event mechanism see the | ||||
* {@link com.vaadin.event com.vaadin.event package | |||||
* documentation}. | |||||
* {@link com.vaadin.event com.vaadin.event package documentation}. | |||||
* </p> | * </p> | ||||
* | * | ||||
* @param eventType | * @param eventType | ||||
* | * | ||||
* <p> | * <p> | ||||
* For more information on the inheritable event mechanism see the | * For more information on the inheritable event mechanism see the | ||||
* {@link com.vaadin.event com.vaadin.event package | |||||
* documentation}. | |||||
* {@link com.vaadin.event com.vaadin.event package documentation}. | |||||
* </p> | * </p> | ||||
* | * | ||||
* @param eventType | * @param eventType | ||||
* | * | ||||
* <p> | * <p> | ||||
* For more information on the inheritable event mechanism see the | * For more information on the inheritable event mechanism see the | ||||
* {@link com.vaadin.event com.vaadin.event package | |||||
* documentation}. | |||||
* {@link com.vaadin.event com.vaadin.event package documentation}. | |||||
* </p> | * </p> | ||||
* | * | ||||
* @param eventType | * @param eventType |
// See if the default browser is Konqueror by resolving the symlink. | // See if the default browser is Konqueror by resolving the symlink. | ||||
boolean isDefaultKonqueror = false; | boolean isDefaultKonqueror = false; | ||||
try { | try { | ||||
// Find out the location of the x-www-browser link from path. | |||||
Process process = runtime.exec("which x-www-browser"); | |||||
BufferedInputStream ins = new BufferedInputStream(process.getInputStream()); | |||||
BufferedReader bufreader = new BufferedReader(new InputStreamReader(ins)); | |||||
String defaultLinkPath = bufreader.readLine(); | |||||
ins.close(); | |||||
// The path is null if the link did not exist. | |||||
if (defaultLinkPath != null) { | |||||
// See if the default browser is Konqueror. | |||||
File file = new File(defaultLinkPath); | |||||
String canonical = file.getCanonicalPath(); | |||||
if (canonical.indexOf("konqueror") != -1) | |||||
isDefaultKonqueror = true; | |||||
} | |||||
// Find out the location of the x-www-browser link from path. | |||||
Process process = runtime.exec("which x-www-browser"); | |||||
BufferedInputStream ins = new BufferedInputStream(process | |||||
.getInputStream()); | |||||
BufferedReader bufreader = new BufferedReader( | |||||
new InputStreamReader(ins)); | |||||
String defaultLinkPath = bufreader.readLine(); | |||||
ins.close(); | |||||
// The path is null if the link did not exist. | |||||
if (defaultLinkPath != null) { | |||||
// See if the default browser is Konqueror. | |||||
File file = new File(defaultLinkPath); | |||||
String canonical = file.getCanonicalPath(); | |||||
if (canonical.indexOf("konqueror") != -1) | |||||
isDefaultKonqueror = true; | |||||
} | |||||
} catch (IOException e1) { | } catch (IOException e1) { | ||||
// The symlink was probably not found, so this is ok. | |||||
// The symlink was probably not found, so this is ok. | |||||
} | } | ||||
// Try x-www-browser, which is symlink to the default browser, | // Try x-www-browser, which is symlink to the default browser, | ||||
// except if we found that it is Konqueror. | // except if we found that it is Konqueror. | ||||
if (!started && !isDefaultKonqueror) { | if (!started && !isDefaultKonqueror) { | ||||
try { | |||||
runtime.exec("x-www-browser " + url); | |||||
started = true; | |||||
} catch (final IOException e) { | |||||
} | |||||
try { | |||||
runtime.exec("x-www-browser " + url); | |||||
started = true; | |||||
} catch (final IOException e) { | |||||
} | |||||
} | } | ||||
// Try firefox | // Try firefox |
* @VERSION@ | * @VERSION@ | ||||
* @since 3.0 | * @since 3.0 | ||||
*/ | */ | ||||
public interface Resource extends Serializable{ | |||||
public interface Resource extends Serializable { | |||||
/** | /** | ||||
* Gets the MIME type of the resource. | * Gets the MIME type of the resource. |
* @VERSION@ | * @VERSION@ | ||||
* @since 3.0 | * @since 3.0 | ||||
*/ | */ | ||||
public interface Sizeable extends Serializable{ | |||||
public interface Sizeable extends Serializable { | |||||
/** | /** | ||||
* Unit code representing pixels. | * Unit code representing pixels. |
/** | /** | ||||
* Terminal error event. | * Terminal error event. | ||||
*/ | */ | ||||
public interface ErrorEvent extends Serializable{ | |||||
public interface ErrorEvent extends Serializable { | |||||
/** | /** | ||||
* Gets the contained throwable. | * Gets the contained throwable. | ||||
/** | /** | ||||
* Terminal error listener interface. | * Terminal error listener interface. | ||||
*/ | */ | ||||
public interface ErrorListener extends Serializable{ | |||||
public interface ErrorListener extends Serializable { | |||||
/** | /** | ||||
* Invoked when terminal error occurs. | * Invoked when terminal error occurs. |
* An interface used by client-side widgets or paintable parts to receive | * An interface used by client-side widgets or paintable parts to receive | ||||
* updates from the corresponding server-side components in the form of | * updates from the corresponding server-side components in the form of | ||||
* {@link UIDL}. | * {@link UIDL}. | ||||
* | |||||
* | |||||
* Updates can be sent back to the server using the | * Updates can be sent back to the server using the | ||||
* {@link ApplicationConnection#updateVariable()} methods. | * {@link ApplicationConnection#updateVariable()} methods. | ||||
*/ | */ |
* <img class='gallery' src='MenuBar.png'/> | * <img class='gallery' src='MenuBar.png'/> | ||||
* </p> | * </p> | ||||
* | * | ||||
* <h3>CSS Style Rules</h3> <ul class='css'> <li>.gwt-MenuBar { the menu bar | |||||
* itself }</li> <li>.gwt-MenuBar .gwt-MenuItem { menu items }</li> <li> | |||||
* .gwt-MenuBar .gwt-MenuItem-selected { selected menu items }</li> </ul> | |||||
* <h3>CSS Style Rules</h3> | |||||
* <ul class='css'> | |||||
* <li>.gwt-MenuBar { the menu bar itself }</li> | |||||
* <li>.gwt-MenuBar .gwt-MenuItem { menu items }</li> | |||||
* <li> | |||||
* .gwt-MenuBar .gwt-MenuItem-selected { selected menu items }</li> | |||||
* </ul> | |||||
* | * | ||||
* <p> | * <p> | ||||
* <h3>Example</h3> | * <h3>Example</h3> |
} | } | ||||
/** | /** | ||||
* | |||||
* | |||||
* @param forceRedraw | * @param forceRedraw | ||||
* Build all from scratch, in case of e.g. locale changes | * Build all from scratch, in case of e.g. locale changes | ||||
*/ | */ | ||||
Object sender = event.getSource(); | Object sender = event.getSource(); | ||||
Cell cell = cal.days.getCellForEvent(event); | Cell cell = cal.days.getCellForEvent(event); | ||||
if (sender != cal.days || cell == null || cell.getRowIndex() < 1 | if (sender != cal.days || cell == null || cell.getRowIndex() < 1 | ||||
|| cell.getRowIndex() > 6 | |||||
|| !cal.datefield.isEnabled() || cal.datefield.isReadonly()) { | |||||
|| cell.getRowIndex() > 6 || !cal.datefield.isEnabled() | |||||
|| cal.datefield.isReadonly()) { | |||||
return; | return; | ||||
} | } | ||||
/** | /** | ||||
* Sets focus to Calendar panel. | * Sets focus to Calendar panel. | ||||
* | |||||
* | |||||
* @param focus | * @param focus | ||||
*/ | */ | ||||
public void setFocus(boolean focus) { | public void setFocus(boolean focus) { |
boolean overflowRight = false; | boolean overflowRight = false; | ||||
if (l + +w + extraSpace > browserWindowWidth) { | if (l + +w + extraSpace > browserWindowWidth) { | ||||
overflowRight = true; | overflowRight = true; | ||||
// Part of the popup is outside the browser window | |||||
// Part of the popup is outside the browser window | |||||
// (to the right) | // (to the right) | ||||
l = browserWindowWidth - w - extraSpace; | l = browserWindowWidth - w - extraSpace; | ||||
} | } |
/** | /** | ||||
* Determines the correct position for a popup and displays the popup at | * Determines the correct position for a popup and displays the popup at | ||||
* that position. | * that position. | ||||
* | |||||
* | |||||
* By default, the popup is shown centered relative to its host component, | * By default, the popup is shown centered relative to its host component, | ||||
* ensuring it is visible on the screen if possible. | * ensuring it is visible on the screen if possible. | ||||
* | |||||
* | |||||
* Can be overridden to customize the popup position. | * Can be overridden to customize the popup position. | ||||
* | |||||
* | |||||
* @param popup | * @param popup | ||||
*/ | */ | ||||
protected void showPopup(final CustomPopup popup) { | protected void showPopup(final CustomPopup popup) { |
/** | /** | ||||
* Client side implementation for UriFragmentUtility. Uses GWT's History object | * Client side implementation for UriFragmentUtility. Uses GWT's History object | ||||
* as an implementation. | * as an implementation. | ||||
* | |||||
* | |||||
*/ | */ | ||||
public class VUriFragmentUtility extends Widget implements Paintable, | public class VUriFragmentUtility extends Widget implements Paintable, | ||||
ValueChangeHandler<String> { | ValueChangeHandler<String> { |
private int captionHeight = 0; | private int captionHeight = 0; | ||||
/** | /** | ||||
* | |||||
* | |||||
* Padding added to the container when it is larger than the component. | * Padding added to the container when it is larger than the component. | ||||
*/ | */ | ||||
private Size containerExpansion = new Size(0, 0); | private Size containerExpansion = new Size(0, 0); | ||||
/* | /* | ||||
* Must remove width specification from container before rendering to | * Must remove width specification from container before rendering to | ||||
* allow components to grow in horizontal direction. | * allow components to grow in horizontal direction. | ||||
* | |||||
* | |||||
* For fixed width layouts we specify the width directly so that height | * For fixed width layouts we specify the width directly so that height | ||||
* is automatically calculated correctly (e.g. for Labels). | * is automatically calculated correctly (e.g. for Labels). | ||||
*/ | */ | ||||
/* | /* | ||||
* This should no longer be needed (after #2563) as all components are | * This should no longer be needed (after #2563) as all components are | ||||
* such that they can be rendered inside a 0x0 DIV. | * such that they can be rendered inside a 0x0 DIV. | ||||
* | |||||
* | |||||
* The exception seems to be complex components (Tree and Table) on | * The exception seems to be complex components (Tree and Table) on | ||||
* Opera (#3444). | * Opera (#3444). | ||||
*/ | */ | ||||
/** | /** | ||||
* Return true if the size of the widget has been specified in the selected | * Return true if the size of the widget has been specified in the selected | ||||
* orientation. | * orientation. | ||||
* | |||||
* | |||||
* @return | * @return | ||||
*/ | */ | ||||
public boolean widgetHasSizeSpecified(int orientation) { | public boolean widgetHasSizeSpecified(int orientation) { | ||||
/** | /** | ||||
* Sets the normalized expand ratio of this slot. The fraction that this | * Sets the normalized expand ratio of this slot. The fraction that this | ||||
* slot will use of "excess space". | * slot will use of "excess space". | ||||
* | |||||
* | |||||
* @param expandRatio | * @param expandRatio | ||||
*/ | */ | ||||
public void setNormalizedExpandRatio(double expandRatio) { | public void setNormalizedExpandRatio(double expandRatio) { |
/** | /** | ||||
* Creates a new toolbar that drives the given rich text area. | * Creates a new toolbar that drives the given rich text area. | ||||
* | |||||
* | |||||
* @param richText | * @param richText | ||||
* the rich text area to be controlled | * the rich text area to be controlled | ||||
*/ | */ |
/** | /** | ||||
* TODO Document me! | * TODO Document me! | ||||
* | |||||
* | |||||
* @author peholmst | * @author peholmst | ||||
*/ | */ | ||||
public abstract class AbstractApplicationPortlet extends GenericPortlet | public abstract class AbstractApplicationPortlet extends GenericPortlet | ||||
/** | /** | ||||
* Gets an application property value. | * Gets an application property value. | ||||
* | |||||
* | |||||
* @param parameterName | * @param parameterName | ||||
* the Name or the parameter. | * the Name or the parameter. | ||||
* @return String value or null if not found | * @return String value or null if not found | ||||
/** | /** | ||||
* Gets an system property value. | * Gets an system property value. | ||||
* | |||||
* | |||||
* @param parameterName | * @param parameterName | ||||
* the Name or the parameter. | * the Name or the parameter. | ||||
* @return String value or null if not found | * @return String value or null if not found | ||||
/** | /** | ||||
* Gets an application or system property value. | * Gets an application or system property value. | ||||
* | |||||
* | |||||
* @param parameterName | * @param parameterName | ||||
* the Name or the parameter. | * the Name or the parameter. | ||||
* @param defaultValue | * @param defaultValue | ||||
* Return the URL from where static files, e.g. the widgetset and the theme, | * Return the URL from where static files, e.g. the widgetset and the theme, | ||||
* are served. In a standard configuration the VAADIN folder inside the | * are served. In a standard configuration the VAADIN folder inside the | ||||
* returned folder is what is used for widgetsets and themes. | * returned folder is what is used for widgetsets and themes. | ||||
* | |||||
* | |||||
* @param request | * @param request | ||||
* @return The location of static resources (inside which there should be a | * @return The location of static resources (inside which there should be a | ||||
* VAADIN directory). Does not end with a slash (/). | * VAADIN directory). Does not end with a slash (/). | ||||
/** | /** | ||||
* Returns true if the servlet is running in production mode. Production | * Returns true if the servlet is running in production mode. Production | ||||
* mode disables all debug facilities. | * mode disables all debug facilities. | ||||
* | |||||
* | |||||
* @return true if in production mode, false if in debug mode | * @return true if in production mode, false if in debug mode | ||||
*/ | */ | ||||
public boolean isProductionMode() { | public boolean isProductionMode() { | ||||
* application with window names identical to the portlet mode names. | * application with window names identical to the portlet mode names. | ||||
* Alternatively, a PortletListener can change the application main window | * Alternatively, a PortletListener can change the application main window | ||||
* contents. | * contents. | ||||
* | |||||
* | |||||
* To implement custom portlet modes, subclass the portlet class and | * To implement custom portlet modes, subclass the portlet class and | ||||
* implement a method annotated with {@link RenderMode} for the custom mode, | * implement a method annotated with {@link RenderMode} for the custom mode, | ||||
* calling {@link #handleRequest(PortletRequest, PortletResponse)} directly | * calling {@link #handleRequest(PortletRequest, PortletResponse)} directly | ||||
* from it. | * from it. | ||||
* | |||||
* | |||||
* Note that the portlet class in the portlet configuration needs to be | * Note that the portlet class in the portlet configuration needs to be | ||||
* changed when overriding methods of this class. | * changed when overriding methods of this class. | ||||
* | |||||
* | |||||
* @param request | * @param request | ||||
* @param response | * @param response | ||||
* @throws PortletException | * @throws PortletException | ||||
/** | /** | ||||
* Handle a request for the "edit" portlet mode. | * Handle a request for the "edit" portlet mode. | ||||
* | |||||
* | |||||
* @see #doView(RenderRequest, RenderResponse) | * @see #doView(RenderRequest, RenderResponse) | ||||
*/ | */ | ||||
@Override | @Override | ||||
/** | /** | ||||
* Handle a request for the "help" portlet mode. | * Handle a request for the "help" portlet mode. | ||||
* | |||||
* | |||||
* @see #doView(RenderRequest, RenderResponse) | * @see #doView(RenderRequest, RenderResponse) | ||||
*/ | */ | ||||
@Override | @Override | ||||
/** | /** | ||||
* Returns the theme for given request/window | * Returns the theme for given request/window | ||||
* | |||||
* | |||||
* @param request | * @param request | ||||
* @param window | * @param window | ||||
* @return | * @return | ||||
/** | /** | ||||
* Get system messages from the current application class | * Get system messages from the current application class | ||||
* | |||||
* | |||||
* @return | * @return | ||||
*/ | */ | ||||
protected SystemMessages getSystemMessages() { | protected SystemMessages getSystemMessages() { | ||||
* Send notification to client's application. Used to notify client of | * Send notification to client's application. Used to notify client of | ||||
* critical errors and session expiration due to long inactivity. Server has | * critical errors and session expiration due to long inactivity. Server has | ||||
* no knowledge of what application client refers to. | * no knowledge of what application client refers to. | ||||
* | |||||
* | |||||
* @param request | * @param request | ||||
* the Portlet request instance. | * the Portlet request instance. | ||||
* @param response | * @param response |
/** | /** | ||||
* Sends a notification that a transaction is starting. | * Sends a notification that a transaction is starting. | ||||
* | |||||
* | |||||
* @param application | * @param application | ||||
* The application associated with the transaction. | * The application associated with the transaction. | ||||
* @param request | * @param request | ||||
/** | /** | ||||
* Sends a notification that a transaction has ended. | * Sends a notification that a transaction has ended. | ||||
* | |||||
* | |||||
* @param application | * @param application | ||||
* The application associated with the transaction. | * The application associated with the transaction. | ||||
* @param request | * @param request | ||||
/** | /** | ||||
* Get the web browser associated with this application context. | * Get the web browser associated with this application context. | ||||
* | |||||
* | |||||
* Because application context is related to the http session and server | * Because application context is related to the http session and server | ||||
* maintains one session per browser-instance, each context has exactly one | * maintains one session per browser-instance, each context has exactly one | ||||
* web browser associated with it. | * web browser associated with it. | ||||
* | |||||
* | |||||
* @return | * @return | ||||
*/ | */ | ||||
public WebBrowser getBrowser() { | public WebBrowser getBrowser() { | ||||
applicationToAjaxAppMgrMap.remove(application); | applicationToAjaxAppMgrMap.remove(application); | ||||
} | } | ||||
public String generateApplicationResourceURL( | |||||
ApplicationResource resource, String mapKey) { | |||||
public String generateApplicationResourceURL(ApplicationResource resource, | |||||
String mapKey) { | |||||
final String filename = resource.getFilename(); | final String filename = resource.getFilename(); | ||||
if (filename == null) { | if (filename == null) { |
* servlet to extend the session lifetime after each Vaadin | * servlet to extend the session lifetime after each Vaadin | ||||
* request. This hack can be removed when supporting portlet | * request. This hack can be removed when supporting portlet | ||||
* 2.0 and resourceRequests. | * 2.0 and resourceRequests. | ||||
* | |||||
* | |||||
* TODO make this configurable, this is not necessary with | * TODO make this configurable, this is not necessary with | ||||
* some custom session configurations. | * some custom session configurations. | ||||
*/ | */ |
/** | /** | ||||
* Parses application runner URIs. | * Parses application runner URIs. | ||||
* | |||||
* | |||||
* If request URL is e.g. | * If request URL is e.g. | ||||
* http://localhost:8080/vaadin/run/com.vaadin.demo.Calc then | * http://localhost:8080/vaadin/run/com.vaadin.demo.Calc then | ||||
* <ul> | * <ul> | ||||
* <li>Runner servlet=run</li> | * <li>Runner servlet=run</li> | ||||
* <li>Vaadin application=com.vaadin.demo.Calc</li> | * <li>Vaadin application=com.vaadin.demo.Calc</li> | ||||
* </ul> | * </ul> | ||||
* | |||||
* | |||||
* @param request | * @param request | ||||
* @return string array containing widgetset URI, application URI and | * @return string array containing widgetset URI, application URI and | ||||
* context, runner, application classname | * context, runner, application classname |
/** | /** | ||||
* TODO Document me! | * TODO Document me! | ||||
* | |||||
* | |||||
* @author peholmst | * @author peholmst | ||||
* | |||||
* | |||||
*/ | */ | ||||
public interface Constants { | public interface Constants { | ||||
* <p> | * <p> | ||||
* Alternatives for implementing similar features are are Servlet {@link Filter} | * Alternatives for implementing similar features are are Servlet {@link Filter} | ||||
* s and {@link TransactionListener}s in Vaadin. | * s and {@link TransactionListener}s in Vaadin. | ||||
* | |||||
* | |||||
* @since 6.2 | * @since 6.2 | ||||
* @see PortletRequestListener | * @see PortletRequestListener | ||||
*/ | */ | ||||
/** | /** | ||||
* This method is called before {@link Terminal} applies the request to | * This method is called before {@link Terminal} applies the request to | ||||
* Application. | * Application. | ||||
* | |||||
* | |||||
* @param request | * @param request | ||||
* @param response | * @param response | ||||
*/ | */ | ||||
/** | /** | ||||
* This method is called at the end of each request. | * This method is called at the end of each request. | ||||
* | |||||
* | |||||
* @param request | * @param request | ||||
* @param response | * @param response | ||||
*/ | */ |
* @since 5.0 | * @since 5.0 | ||||
*/ | */ | ||||
@SuppressWarnings("serial") | @SuppressWarnings("serial") | ||||
public class HttpUploadStream implements | |||||
com.vaadin.terminal.UploadStream { | |||||
public class HttpUploadStream implements com.vaadin.terminal.UploadStream { | |||||
/** | /** | ||||
* Holds value of property variableName. | * Holds value of property variableName. |
/** | /** | ||||
* TODO Write documentation, fix JavaDoc tags. | * TODO Write documentation, fix JavaDoc tags. | ||||
* | |||||
* | |||||
* This is automatically registered as a {@link HttpSessionBindingListener} when | * This is automatically registered as a {@link HttpSessionBindingListener} when | ||||
* {@link PortletSession#setAttribute()} is called with the context as value. | * {@link PortletSession#setAttribute()} is called with the context as value. | ||||
* | |||||
* | |||||
* @author peholmst | * @author peholmst | ||||
*/ | */ | ||||
@SuppressWarnings("serial") | @SuppressWarnings("serial") | ||||
Set<PortletListener> listeners = portletListeners.get(app); | Set<PortletListener> listeners = portletListeners.get(app); | ||||
if (listeners != null) { | if (listeners != null) { | ||||
for (PortletListener l : listeners) { | for (PortletListener l : listeners) { | ||||
l.handleRenderRequest(request, new RestrictedRenderResponse(response)); | |||||
l.handleRenderRequest(request, new RestrictedRenderResponse( | |||||
response)); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
String key = request.getParameter(ActionRequest.ACTION_NAME); | String key = request.getParameter(ActionRequest.ACTION_NAME); | ||||
if (eventActionDestinationMap.containsKey(key)) { | if (eventActionDestinationMap.containsKey(key)) { | ||||
// this action request is only to send queued portlet events | // this action request is only to send queued portlet events | ||||
response.setEvent(eventActionDestinationMap.get(key), eventActionValueMap | |||||
.get(key)); | |||||
response.setEvent(eventActionDestinationMap.get(key), | |||||
eventActionValueMap.get(key)); | |||||
// cleanup | // cleanup | ||||
eventActionDestinationMap.remove(key); | eventActionDestinationMap.remove(key); | ||||
eventActionValueMap.remove(key); | eventActionValueMap.remove(key); | ||||
/** | /** | ||||
* This is for use by {@link AbstractApplicationPortlet} only. | * This is for use by {@link AbstractApplicationPortlet} only. | ||||
* | |||||
* | |||||
* TODO cleaner implementation, now "semi-static"! | * TODO cleaner implementation, now "semi-static"! | ||||
* | |||||
* | |||||
* @param mimeResponse | * @param mimeResponse | ||||
*/ | */ | ||||
void setResponse(PortletResponse response) { | void setResponse(PortletResponse response) { | ||||
} | } | ||||
@Override | @Override | ||||
public String generateApplicationResourceURL( | |||||
ApplicationResource resource, | |||||
public String generateApplicationResourceURL(ApplicationResource resource, | |||||
String mapKey) { | String mapKey) { | ||||
if (response instanceof MimeResponse) { | if (response instanceof MimeResponse) { | ||||
ResourceURL resourceURL = ((MimeResponse) response) | ResourceURL resourceURL = ((MimeResponse) response) | ||||
/** | /** | ||||
* Creates a new action URL. | * Creates a new action URL. | ||||
* | |||||
* | |||||
* @param action | * @param action | ||||
* @return action URL or null if called outside a MimeRequest (outside a | * @return action URL or null if called outside a MimeRequest (outside a | ||||
* UIDL request or similar) | * UIDL request or similar) | ||||
/** | /** | ||||
* Sends a portlet event to the indicated destination. | * Sends a portlet event to the indicated destination. | ||||
* | |||||
* | |||||
* Internally, an action may be created and opened, as an event cannot be | * Internally, an action may be created and opened, as an event cannot be | ||||
* sent directly from all types of requests. | * sent directly from all types of requests. | ||||
* | |||||
* | |||||
* The event destinations and values need to be kept in the context until | * The event destinations and values need to be kept in the context until | ||||
* sent. Any memory leaks if the action fails are limited to the session. | * sent. Any memory leaks if the action fails are limited to the session. | ||||
* | |||||
* | |||||
* Event names for events sent and received by a portlet need to be declared | * Event names for events sent and received by a portlet need to be declared | ||||
* in portlet.xml . | * in portlet.xml . | ||||
* | |||||
* | |||||
* @param window | * @param window | ||||
* a window in which a temporary action URL can be opened if | * a window in which a temporary action URL can be opened if | ||||
* necessary | * necessary | ||||
/** | /** | ||||
* Sets a shared portlet parameter. | * Sets a shared portlet parameter. | ||||
* | |||||
* | |||||
* Internally, an action may be created and opened, as shared parameters | * Internally, an action may be created and opened, as shared parameters | ||||
* cannot be set directly from all types of requests. | * cannot be set directly from all types of requests. | ||||
* | |||||
* | |||||
* The parameters and values need to be kept in the context until sent. Any | * The parameters and values need to be kept in the context until sent. Any | ||||
* memory leaks if the action fails are limited to the session. | * memory leaks if the action fails are limited to the session. | ||||
* | |||||
* | |||||
* Shared parameters set or read by a portlet need to be declared in | * Shared parameters set or read by a portlet need to be declared in | ||||
* portlet.xml . | * portlet.xml . | ||||
* | |||||
* | |||||
* @param window | * @param window | ||||
* a window in which a temporary action URL can be opened if | * a window in which a temporary action URL can be opened if | ||||
* necessary | * necessary | ||||
/** | /** | ||||
* Sets the portlet mode. This may trigger a new render request. | * Sets the portlet mode. This may trigger a new render request. | ||||
* | |||||
* | |||||
* Portlet modes used by a portlet need to be declared in portlet.xml . | * Portlet modes used by a portlet need to be declared in portlet.xml . | ||||
* | |||||
* | |||||
* @param window | * @param window | ||||
* a window in which the render URL can be opened if necessary | * a window in which the render URL can be opened if necessary | ||||
* @param portletMode | * @param portletMode |
/** | /** | ||||
* TODO document me! | * TODO document me! | ||||
* | |||||
* | |||||
* @author peholmst | * @author peholmst | ||||
* | |||||
* | |||||
*/ | */ | ||||
@SuppressWarnings("serial") | @SuppressWarnings("serial") | ||||
public class PortletCommunicationManager extends AbstractCommunicationManager { | public class PortletCommunicationManager extends AbstractCommunicationManager { | ||||
/** | /** | ||||
* Find the application window to use based on the portlet mode. For | * Find the application window to use based on the portlet mode. For | ||||
* internal use only, not in the {@link Callback} interface. | * internal use only, not in the {@link Callback} interface. | ||||
* | |||||
* | |||||
* @param request | * @param request | ||||
* @param application | * @param application | ||||
* @return | * @return |
/** | /** | ||||
* Read-only wrapper for a {@link RenderResponse}. | * Read-only wrapper for a {@link RenderResponse}. | ||||
* | |||||
* | |||||
* Only for use by {@link PortletApplicationContext} and | * Only for use by {@link PortletApplicationContext} and | ||||
* {@link PortletApplicationContext2}. | * {@link PortletApplicationContext2}. | ||||
*/ | */ | ||||
class RestrictedRenderResponse implements RenderResponse, | |||||
Serializable { | |||||
class RestrictedRenderResponse implements RenderResponse, Serializable { | |||||
private RenderResponse response; | private RenderResponse response; | ||||
response.setTitle(title); | response.setTitle(title); | ||||
} | } | ||||
public void setNextPossiblePortletModes( | |||||
Collection<PortletMode> portletModes) { | |||||
public void setNextPossiblePortletModes(Collection<PortletMode> portletModes) { | |||||
// NOP | // NOP | ||||
// TODO throw? | // TODO throw? | ||||
} | } |
/** | /** | ||||
* There is no default-theme for this terminal type. | * There is no default-theme for this terminal type. | ||||
* | |||||
* | |||||
* @return Allways returns null. | * @return Allways returns null. | ||||
*/ | */ | ||||
public String getDefaultTheme() { | public String getDefaultTheme() { | ||||
/** | /** | ||||
* Get the height of the users display in pixels. | * Get the height of the users display in pixels. | ||||
* | |||||
* | |||||
*/ | */ | ||||
public int getScreenHeight() { | public int getScreenHeight() { | ||||
return screenHeight; | return screenHeight; | ||||
/** | /** | ||||
* Get the width of the users display in pixels. | * Get the width of the users display in pixels. | ||||
* | |||||
* | |||||
*/ | */ | ||||
public int getScreenWidth() { | public int getScreenWidth() { | ||||
return screenWidth; | return screenWidth; | ||||
/** | /** | ||||
* Get the browser user-agent string. | * Get the browser user-agent string. | ||||
* | |||||
* | |||||
* @return | * @return | ||||
*/ | */ | ||||
public String getBrowserApplication() { | public String getBrowserApplication() { | ||||
/** | /** | ||||
* Get the IP-address of the web browser. If the application is running | * Get the IP-address of the web browser. If the application is running | ||||
* inside a portlet, this method will return null. | * inside a portlet, this method will return null. | ||||
* | |||||
* | |||||
* @return IP-address in 1.12.123.123 -format | * @return IP-address in 1.12.123.123 -format | ||||
*/ | */ | ||||
public String getAddress() { | public String getAddress() { |
/** | /** | ||||
* Helper class to update widgetsets GWT module configuration file. Can be used | * Helper class to update widgetsets GWT module configuration file. Can be used | ||||
* command line or via IDE tools. | * command line or via IDE tools. | ||||
* | |||||
* | |||||
* <p> | * <p> | ||||
* If module definition file contains text "WS Compiler: manually edited", tool | * If module definition file contains text "WS Compiler: manually edited", tool | ||||
* will skip editing file. | * will skip editing file. | ||||
* | |||||
* | |||||
*/ | */ | ||||
public class WidgetSetBuilder { | public class WidgetSetBuilder { | ||||
/** | /** | ||||
* Default implementation of the the following Field types are used by default: | * Default implementation of the the following Field types are used by default: | ||||
* <p> | * <p> | ||||
* <b>Boolean</b>: Button(switchMode:true).<br/> <b>Date</b>: | |||||
* DateField(resolution: day).<br/> <b>Item</b>: Form. <br/> <b>default field | |||||
* type</b>: TextField. | |||||
* <b>Boolean</b>: Button(switchMode:true).<br/> | |||||
* <b>Date</b>: DateField(resolution: day).<br/> | |||||
* <b>Item</b>: Form. <br/> | |||||
* <b>default field type</b>: TextField. | |||||
* <p> | * <p> | ||||
* | * | ||||
* @author IT Mill Ltd. | * @author IT Mill Ltd. |
null); | null); | ||||
table.addContainerProperty("quantity", Double.class, null, | table.addContainerProperty("quantity", Double.class, null, | ||||
"Quantity (l)", null, null); | "Quantity (l)", null, null); | ||||
table.addContainerProperty("price", Double.class, null, "Price (€/l)", | |||||
null, null); | |||||
table.addContainerProperty("price", Double.class, null, | |||||
"Price (€/l)", null, null); | |||||
table.addContainerProperty("total", Double.class, null, "Total (€)", | table.addContainerProperty("total", Double.class, null, "Total (€)", | ||||
null, null); | null, null); | ||||
table.addContainerProperty("consumption", Double.class, null, | table.addContainerProperty("consumption", Double.class, null, |
import com.vaadin.ui.Window; | import com.vaadin.ui.Window; | ||||
import com.vaadin.ui.Button.ClickEvent; | import com.vaadin.ui.Button.ClickEvent; | ||||
public abstract class Robustness extends com.vaadin.Application | |||||
implements Button.ClickListener { | |||||
public abstract class Robustness extends com.vaadin.Application implements | |||||
Button.ClickListener { | |||||
static int totalCount = 0; | static int totalCount = 0; | ||||
* | * | ||||
* @since 3.1.1 | * @since 3.1.1 | ||||
*/ | */ | ||||
public class Parameters extends com.vaadin.Application implements | |||||
URIHandler, ParameterHandler { | |||||
public class Parameters extends com.vaadin.Application implements URIHandler, | |||||
ParameterHandler { | |||||
private final Label context = new Label(); | private final Label context = new Label(); | ||||
* | * | ||||
*/ | */ | ||||
public class TestBench extends com.vaadin.Application implements | public class TestBench extends com.vaadin.Application implements | ||||
Property.ValueChangeListener { | |||||
// Add here packages which are used for finding testable classes | |||||
String[] testablePackages = { "com.vaadin.tests", | |||||
"com.vaadin.demo", "com.vaadin.demo.colorpicker", | |||||
"com.vaadin.demo.reservation", | |||||
"com.vaadin.demo.features", | |||||
"com.vaadin.tests.tickets", "com.vaadin.tests.book" }; | |||||
HierarchicalContainer testables = new HierarchicalContainer(); | |||||
Window mainWindow = new Window("TestBench window"); | |||||
// Main layout consists of tree menu and body layout | |||||
SplitPanel mainLayout = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); | |||||
Tree menu; | |||||
Panel bodyLayout = new Panel(); | |||||
HashMap itemCaptions = new HashMap(); | |||||
@Override | |||||
public void init() { | |||||
// Add testable classes to hierarchical container | |||||
for (int p = 0; p < testablePackages.length; p++) { | |||||
testables.addItem(testablePackages[p]); | |||||
try { | |||||
final List testableClasses = getTestableClassesForPackage(testablePackages[p]); | |||||
for (final Iterator it = testableClasses.iterator(); it | |||||
.hasNext();) { | |||||
final Class t = (Class) it.next(); | |||||
// ignore TestBench itself | |||||
if (t.equals(TestBench.class)) { | |||||
continue; | |||||
} | |||||
try { | |||||
testables.addItem(t); | |||||
itemCaptions.put(t, t.getName()); | |||||
testables.setParent(t, testablePackages[p]); | |||||
testables.setChildrenAllowed(t, false); | |||||
continue; | |||||
} catch (final Exception e) { | |||||
try { | |||||
testables.addItem(t); | |||||
itemCaptions.put(t, t.getName()); | |||||
testables.setParent(t, testablePackages[p]); | |||||
testables.setChildrenAllowed(t, false); | |||||
continue; | |||||
} catch (final Exception e1) { | |||||
e1.printStackTrace(); | |||||
} | |||||
} | |||||
} | |||||
} catch (final Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
menu = new Tree("Testables", testables); | |||||
for (final Iterator i = itemCaptions.keySet().iterator(); i.hasNext();) { | |||||
final Class testable = (Class) i.next(); | |||||
// simplify captions | |||||
final String name = testable.getName().substring( | |||||
testable.getName().lastIndexOf('.') + 1); | |||||
menu.setItemCaption(testable, name); | |||||
} | |||||
// expand all root items | |||||
for (final Iterator i = menu.rootItemIds().iterator(); i.hasNext();) { | |||||
menu.expandItemsRecursively(i.next()); | |||||
} | |||||
menu.addListener(this); | |||||
menu.setImmediate(true); | |||||
menu.setNullSelectionAllowed(false); | |||||
VerticalLayout lo = new VerticalLayout(); | |||||
lo.addComponent(menu); | |||||
UriFragmentUtility uri = new UriFragmentUtility(); | |||||
lo.addComponent(uri); | |||||
uri.addListener(new UriFragmentUtility.FragmentChangedListener() { | |||||
public void fragmentChanged(FragmentChangedEvent source) { | |||||
String fragment = source.getUriFragmentUtility().getFragment(); | |||||
if (fragment != null && !"".equals(fragment)) { | |||||
// try to find a proper test class | |||||
// exact match | |||||
Iterator iterator = menu.getItemIds().iterator(); | |||||
while (iterator.hasNext()) { | |||||
Object next = iterator.next(); | |||||
if (next instanceof Class) { | |||||
Class c = (Class) next; | |||||
String string = c.getName(); | |||||
if (string.equals(fragment)) { | |||||
menu.setValue(c); | |||||
mainLayout.setSplitPosition(0); | |||||
return; | |||||
} | |||||
} | |||||
} | |||||
// simple name match | |||||
iterator = menu.getItemIds().iterator(); | |||||
while (iterator.hasNext()) { | |||||
Object next = iterator.next(); | |||||
if (next instanceof Class) { | |||||
Class c = (Class) next; | |||||
String string = c.getSimpleName(); | |||||
if (string.equals(fragment)) { | |||||
menu.setValue(c); | |||||
mainLayout.setSplitPosition(0); | |||||
return; | |||||
} | |||||
} | |||||
} | |||||
// ticket match | |||||
iterator = menu.getItemIds().iterator(); | |||||
while (iterator.hasNext()) { | |||||
Object next = iterator.next(); | |||||
if (next instanceof Class) { | |||||
Class c = (Class) next; | |||||
String string = c.getSimpleName(); | |||||
if (string.startsWith("Ticket" + fragment)) { | |||||
menu.setValue(c); | |||||
mainLayout.setSplitPosition(0); | |||||
return; | |||||
} | |||||
} | |||||
} | |||||
// just partly mach lowercase | |||||
iterator = menu.getItemIds().iterator(); | |||||
while (iterator.hasNext()) { | |||||
Object next = iterator.next(); | |||||
if (next instanceof Class) { | |||||
Class c = (Class) next; | |||||
String string = c.getSimpleName(); | |||||
if (string.toLowerCase().contains( | |||||
fragment.toLowerCase())) { | |||||
menu.setValue(c); | |||||
mainLayout.setSplitPosition(0); | |||||
return; | |||||
} | |||||
} | |||||
} | |||||
getMainWindow().showNotification( | |||||
"No potential matc for #" + fragment); | |||||
} | |||||
} | |||||
}); | |||||
mainLayout.addComponent(lo); | |||||
bodyLayout.addStyleName("light"); | |||||
bodyLayout.setSizeFull(); | |||||
bodyLayout.setLayout(new ExpandLayout()); | |||||
mainLayout.addComponent(bodyLayout); | |||||
mainLayout.setSplitPosition(30); | |||||
mainWindow.setLayout(mainLayout); | |||||
setMainWindow(mainWindow); | |||||
} | |||||
private Component createTestable(Class c) { | |||||
try { | |||||
final Application app = (Application) c.newInstance(); | |||||
app.init(); | |||||
Layout lo = app.getMainWindow().getLayout(); | |||||
lo.setParent(null); | |||||
return lo; | |||||
} catch (final Exception e) { | |||||
try { | |||||
final CustomComponent cc = (CustomComponent) c.newInstance(); | |||||
cc.setSizeFull(); | |||||
return cc; | |||||
} catch (final Exception e1) { | |||||
e1.printStackTrace(); | |||||
VerticalLayout lo = new VerticalLayout(); | |||||
lo.addComponent(new Label( | |||||
"Cannot create application / custom component: " | |||||
+ e1.toString())); | |||||
Link l = new Link("Try opening via app runner", | |||||
new ExternalResource("../run/" + c.getName())); | |||||
lo.addComponent(l); | |||||
return lo; | |||||
} | |||||
} | |||||
} | |||||
// Handle menu selection and update body | |||||
public void valueChange(Property.ValueChangeEvent event) { | |||||
bodyLayout.removeAllComponents(); | |||||
bodyLayout.setCaption(null); | |||||
final Object o = menu.getValue(); | |||||
if (o != null && o instanceof Class) { | |||||
final Class c = (Class) o; | |||||
final String title = c.getName(); | |||||
bodyLayout.setCaption(title); | |||||
bodyLayout.addComponent(createTestable(c)); | |||||
} else { | |||||
// NOP node selected or deselected tree item | |||||
} | |||||
} | |||||
/** | |||||
* Return all testable classes within given package. Class is considered | |||||
* testable if it's superclass is Application or CustomComponent. | |||||
* | |||||
* @param packageName | |||||
* @return | |||||
* @throws ClassNotFoundException | |||||
*/ | |||||
public static List getTestableClassesForPackage(String packageName) | |||||
throws Exception { | |||||
final ArrayList directories = new ArrayList(); | |||||
try { | |||||
final ClassLoader cld = Thread.currentThread() | |||||
.getContextClassLoader(); | |||||
if (cld == null) { | |||||
throw new ClassNotFoundException("Can't get class loader."); | |||||
} | |||||
final String path = packageName.replace('.', '/'); | |||||
// Ask for all resources for the path | |||||
final Enumeration resources = cld.getResources(path); | |||||
while (resources.hasMoreElements()) { | |||||
final URL url = (URL) resources.nextElement(); | |||||
directories.add(new File(url.getFile())); | |||||
} | |||||
} catch (final Exception x) { | |||||
throw new Exception(packageName | |||||
+ " does not appear to be a valid package."); | |||||
} | |||||
final ArrayList classes = new ArrayList(); | |||||
// For every directory identified capture all the .class files | |||||
for (final Iterator it = directories.iterator(); it.hasNext();) { | |||||
final File directory = (File) it.next(); | |||||
if (directory.exists()) { | |||||
// Get the list of the files contained in the package | |||||
final String[] files = directory.list(); | |||||
for (int j = 0; j < files.length; j++) { | |||||
// we are only interested in .class files | |||||
if (files[j].endsWith(".class")) { | |||||
// removes the .class extension | |||||
final String p = packageName + '.' | |||||
+ files[j].substring(0, files[j].length() - 6); | |||||
final Class c = Class.forName(p); | |||||
if (c.getSuperclass() != null) { | |||||
if ((c.getSuperclass() | |||||
.equals(com.vaadin.Application.class))) { | |||||
classes.add(c); | |||||
} else if ((c.getSuperclass() | |||||
.equals(com.vaadin.ui.CustomComponent.class))) { | |||||
classes.add(c); | |||||
} | |||||
} | |||||
// for (int i = 0; i < c.getInterfaces().length; i++) { | |||||
// Class cc = c.getInterfaces()[i]; | |||||
// if (c.getInterfaces()[i].equals(Testable.class)) { | |||||
// // Class is testable | |||||
// classes.add(c); | |||||
// } | |||||
// } | |||||
} | |||||
} | |||||
} else { | |||||
throw new ClassNotFoundException(packageName + " (" | |||||
+ directory.getPath() | |||||
+ ") does not appear to be a valid package"); | |||||
} | |||||
} | |||||
return classes; | |||||
} | |||||
Property.ValueChangeListener { | |||||
// Add here packages which are used for finding testable classes | |||||
String[] testablePackages = { "com.vaadin.tests", "com.vaadin.demo", | |||||
"com.vaadin.demo.colorpicker", "com.vaadin.demo.reservation", | |||||
"com.vaadin.demo.features", "com.vaadin.tests.tickets", | |||||
"com.vaadin.tests.book" }; | |||||
HierarchicalContainer testables = new HierarchicalContainer(); | |||||
Window mainWindow = new Window("TestBench window"); | |||||
// Main layout consists of tree menu and body layout | |||||
SplitPanel mainLayout = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); | |||||
Tree menu; | |||||
Panel bodyLayout = new Panel(); | |||||
HashMap itemCaptions = new HashMap(); | |||||
@Override | |||||
public void init() { | |||||
// Add testable classes to hierarchical container | |||||
for (int p = 0; p < testablePackages.length; p++) { | |||||
testables.addItem(testablePackages[p]); | |||||
try { | |||||
final List testableClasses = getTestableClassesForPackage(testablePackages[p]); | |||||
for (final Iterator it = testableClasses.iterator(); it | |||||
.hasNext();) { | |||||
final Class t = (Class) it.next(); | |||||
// ignore TestBench itself | |||||
if (t.equals(TestBench.class)) { | |||||
continue; | |||||
} | |||||
try { | |||||
testables.addItem(t); | |||||
itemCaptions.put(t, t.getName()); | |||||
testables.setParent(t, testablePackages[p]); | |||||
testables.setChildrenAllowed(t, false); | |||||
continue; | |||||
} catch (final Exception e) { | |||||
try { | |||||
testables.addItem(t); | |||||
itemCaptions.put(t, t.getName()); | |||||
testables.setParent(t, testablePackages[p]); | |||||
testables.setChildrenAllowed(t, false); | |||||
continue; | |||||
} catch (final Exception e1) { | |||||
e1.printStackTrace(); | |||||
} | |||||
} | |||||
} | |||||
} catch (final Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
menu = new Tree("Testables", testables); | |||||
for (final Iterator i = itemCaptions.keySet().iterator(); i.hasNext();) { | |||||
final Class testable = (Class) i.next(); | |||||
// simplify captions | |||||
final String name = testable.getName().substring( | |||||
testable.getName().lastIndexOf('.') + 1); | |||||
menu.setItemCaption(testable, name); | |||||
} | |||||
// expand all root items | |||||
for (final Iterator i = menu.rootItemIds().iterator(); i.hasNext();) { | |||||
menu.expandItemsRecursively(i.next()); | |||||
} | |||||
menu.addListener(this); | |||||
menu.setImmediate(true); | |||||
menu.setNullSelectionAllowed(false); | |||||
VerticalLayout lo = new VerticalLayout(); | |||||
lo.addComponent(menu); | |||||
UriFragmentUtility uri = new UriFragmentUtility(); | |||||
lo.addComponent(uri); | |||||
uri.addListener(new UriFragmentUtility.FragmentChangedListener() { | |||||
public void fragmentChanged(FragmentChangedEvent source) { | |||||
String fragment = source.getUriFragmentUtility().getFragment(); | |||||
if (fragment != null && !"".equals(fragment)) { | |||||
// try to find a proper test class | |||||
// exact match | |||||
Iterator iterator = menu.getItemIds().iterator(); | |||||
while (iterator.hasNext()) { | |||||
Object next = iterator.next(); | |||||
if (next instanceof Class) { | |||||
Class c = (Class) next; | |||||
String string = c.getName(); | |||||
if (string.equals(fragment)) { | |||||
menu.setValue(c); | |||||
mainLayout.setSplitPosition(0); | |||||
return; | |||||
} | |||||
} | |||||
} | |||||
// simple name match | |||||
iterator = menu.getItemIds().iterator(); | |||||
while (iterator.hasNext()) { | |||||
Object next = iterator.next(); | |||||
if (next instanceof Class) { | |||||
Class c = (Class) next; | |||||
String string = c.getSimpleName(); | |||||
if (string.equals(fragment)) { | |||||
menu.setValue(c); | |||||
mainLayout.setSplitPosition(0); | |||||
return; | |||||
} | |||||
} | |||||
} | |||||
// ticket match | |||||
iterator = menu.getItemIds().iterator(); | |||||
while (iterator.hasNext()) { | |||||
Object next = iterator.next(); | |||||
if (next instanceof Class) { | |||||
Class c = (Class) next; | |||||
String string = c.getSimpleName(); | |||||
if (string.startsWith("Ticket" + fragment)) { | |||||
menu.setValue(c); | |||||
mainLayout.setSplitPosition(0); | |||||
return; | |||||
} | |||||
} | |||||
} | |||||
// just partly mach lowercase | |||||
iterator = menu.getItemIds().iterator(); | |||||
while (iterator.hasNext()) { | |||||
Object next = iterator.next(); | |||||
if (next instanceof Class) { | |||||
Class c = (Class) next; | |||||
String string = c.getSimpleName(); | |||||
if (string.toLowerCase().contains( | |||||
fragment.toLowerCase())) { | |||||
menu.setValue(c); | |||||
mainLayout.setSplitPosition(0); | |||||
return; | |||||
} | |||||
} | |||||
} | |||||
getMainWindow().showNotification( | |||||
"No potential matc for #" + fragment); | |||||
} | |||||
} | |||||
}); | |||||
mainLayout.addComponent(lo); | |||||
bodyLayout.addStyleName("light"); | |||||
bodyLayout.setSizeFull(); | |||||
bodyLayout.setLayout(new ExpandLayout()); | |||||
mainLayout.addComponent(bodyLayout); | |||||
mainLayout.setSplitPosition(30); | |||||
mainWindow.setLayout(mainLayout); | |||||
setMainWindow(mainWindow); | |||||
} | |||||
private Component createTestable(Class c) { | |||||
try { | |||||
final Application app = (Application) c.newInstance(); | |||||
app.init(); | |||||
Layout lo = app.getMainWindow().getLayout(); | |||||
lo.setParent(null); | |||||
return lo; | |||||
} catch (final Exception e) { | |||||
try { | |||||
final CustomComponent cc = (CustomComponent) c.newInstance(); | |||||
cc.setSizeFull(); | |||||
return cc; | |||||
} catch (final Exception e1) { | |||||
e1.printStackTrace(); | |||||
VerticalLayout lo = new VerticalLayout(); | |||||
lo.addComponent(new Label( | |||||
"Cannot create application / custom component: " | |||||
+ e1.toString())); | |||||
Link l = new Link("Try opening via app runner", | |||||
new ExternalResource("../run/" + c.getName())); | |||||
lo.addComponent(l); | |||||
return lo; | |||||
} | |||||
} | |||||
} | |||||
// Handle menu selection and update body | |||||
public void valueChange(Property.ValueChangeEvent event) { | |||||
bodyLayout.removeAllComponents(); | |||||
bodyLayout.setCaption(null); | |||||
final Object o = menu.getValue(); | |||||
if (o != null && o instanceof Class) { | |||||
final Class c = (Class) o; | |||||
final String title = c.getName(); | |||||
bodyLayout.setCaption(title); | |||||
bodyLayout.addComponent(createTestable(c)); | |||||
} else { | |||||
// NOP node selected or deselected tree item | |||||
} | |||||
} | |||||
/** | |||||
* Return all testable classes within given package. Class is considered | |||||
* testable if it's superclass is Application or CustomComponent. | |||||
* | |||||
* @param packageName | |||||
* @return | |||||
* @throws ClassNotFoundException | |||||
*/ | |||||
public static List getTestableClassesForPackage(String packageName) | |||||
throws Exception { | |||||
final ArrayList directories = new ArrayList(); | |||||
try { | |||||
final ClassLoader cld = Thread.currentThread() | |||||
.getContextClassLoader(); | |||||
if (cld == null) { | |||||
throw new ClassNotFoundException("Can't get class loader."); | |||||
} | |||||
final String path = packageName.replace('.', '/'); | |||||
// Ask for all resources for the path | |||||
final Enumeration resources = cld.getResources(path); | |||||
while (resources.hasMoreElements()) { | |||||
final URL url = (URL) resources.nextElement(); | |||||
directories.add(new File(url.getFile())); | |||||
} | |||||
} catch (final Exception x) { | |||||
throw new Exception(packageName | |||||
+ " does not appear to be a valid package."); | |||||
} | |||||
final ArrayList classes = new ArrayList(); | |||||
// For every directory identified capture all the .class files | |||||
for (final Iterator it = directories.iterator(); it.hasNext();) { | |||||
final File directory = (File) it.next(); | |||||
if (directory.exists()) { | |||||
// Get the list of the files contained in the package | |||||
final String[] files = directory.list(); | |||||
for (int j = 0; j < files.length; j++) { | |||||
// we are only interested in .class files | |||||
if (files[j].endsWith(".class")) { | |||||
// removes the .class extension | |||||
final String p = packageName + '.' | |||||
+ files[j].substring(0, files[j].length() - 6); | |||||
final Class c = Class.forName(p); | |||||
if (c.getSuperclass() != null) { | |||||
if ((c.getSuperclass() | |||||
.equals(com.vaadin.Application.class))) { | |||||
classes.add(c); | |||||
} else if ((c.getSuperclass() | |||||
.equals(com.vaadin.ui.CustomComponent.class))) { | |||||
classes.add(c); | |||||
} | |||||
} | |||||
// for (int i = 0; i < c.getInterfaces().length; i++) { | |||||
// Class cc = c.getInterfaces()[i]; | |||||
// if (c.getInterfaces()[i].equals(Testable.class)) { | |||||
// // Class is testable | |||||
// classes.add(c); | |||||
// } | |||||
// } | |||||
} | |||||
} | |||||
} else { | |||||
throw new ClassNotFoundException(packageName + " (" | |||||
+ directory.getPath() | |||||
+ ") does not appear to be a valid package"); | |||||
} | |||||
} | |||||
return classes; | |||||
} | |||||
} | } |
import com.vaadin.ui.TextField; | import com.vaadin.ui.TextField; | ||||
public class DefaultButtonExample extends CustomComponent implements Handler { | public class DefaultButtonExample extends CustomComponent implements Handler { | ||||
// Define and create user interface components | |||||
Panel panel = new Panel("Login"); | |||||
FormLayout formlayout = new FormLayout(); | |||||
TextField username = new TextField("Username"); | |||||
TextField password = new TextField("Password"); | |||||
HorizontalLayout buttons = new HorizontalLayout(); | |||||
// Define and create user interface components | |||||
Panel panel = new Panel("Login"); | |||||
FormLayout formlayout = new FormLayout(); | |||||
TextField username = new TextField("Username"); | |||||
TextField password = new TextField("Password"); | |||||
HorizontalLayout buttons = new HorizontalLayout(); | |||||
// Create buttons and define their listener methods. | |||||
Button ok = new Button("OK", this, "okHandler"); | |||||
Button cancel = new Button("Cancel", this, "cancelHandler"); | |||||
// Create buttons and define their listener methods. | |||||
Button ok = new Button("OK", this, "okHandler"); | |||||
Button cancel = new Button("Cancel", this, "cancelHandler"); | |||||
// Have the unmodified Enter key cause an event | |||||
Action action_ok = new ShortcutAction("Default key", | |||||
ShortcutAction.KeyCode.ENTER, null); | |||||
// Have the unmodified Enter key cause an event | |||||
Action action_ok = new ShortcutAction("Default key", | |||||
ShortcutAction.KeyCode.ENTER, null); | |||||
// Have the C key modified with Alt cause an event | |||||
Action action_cancel = new ShortcutAction("Alt+C", | |||||
ShortcutAction.KeyCode.C, | |||||
new int[] { ShortcutAction.ModifierKey.ALT }); | |||||
// Have the C key modified with Alt cause an event | |||||
Action action_cancel = new ShortcutAction("Alt+C", | |||||
ShortcutAction.KeyCode.C, | |||||
new int[] { ShortcutAction.ModifierKey.ALT }); | |||||
public DefaultButtonExample() { | |||||
// Set up the user interface | |||||
setCompositionRoot(panel); | |||||
panel.addComponent(formlayout); | |||||
formlayout.addComponent(username); | |||||
formlayout.addComponent(password); | |||||
formlayout.addComponent(buttons); | |||||
buttons.addComponent(ok); | |||||
buttons.addComponent(cancel); | |||||
public DefaultButtonExample() { | |||||
// Set up the user interface | |||||
setCompositionRoot(panel); | |||||
panel.addComponent(formlayout); | |||||
formlayout.addComponent(username); | |||||
formlayout.addComponent(password); | |||||
formlayout.addComponent(buttons); | |||||
buttons.addComponent(ok); | |||||
buttons.addComponent(cancel); | |||||
// Set focus to username | |||||
username.focus(); | |||||
// Set focus to username | |||||
username.focus(); | |||||
// Set this object as the action handler | |||||
System.out.println("adding ah"); | |||||
panel.addActionHandler(this); | |||||
// Set this object as the action handler | |||||
System.out.println("adding ah"); | |||||
panel.addActionHandler(this); | |||||
System.out.println("start done."); | |||||
} | |||||
System.out.println("start done."); | |||||
} | |||||
/** | |||||
* Retrieve actions for a specific component. This method will be called for | |||||
* each object that has a handler; in this example just for login panel. The | |||||
* returned action list might as well be static list. | |||||
*/ | |||||
public Action[] getActions(Object target, Object sender) { | |||||
System.out.println("getActions()"); | |||||
return new Action[] { action_ok, action_cancel }; | |||||
} | |||||
/** | |||||
* Retrieve actions for a specific component. This method will be called for | |||||
* each object that has a handler; in this example just for login panel. The | |||||
* returned action list might as well be static list. | |||||
*/ | |||||
public Action[] getActions(Object target, Object sender) { | |||||
System.out.println("getActions()"); | |||||
return new Action[] { action_ok, action_cancel }; | |||||
} | |||||
/** | |||||
* Handle actions received from keyboard. This simply directs the actions to | |||||
* the same listener methods that are called with ButtonClick events. | |||||
*/ | |||||
public void handleAction(Action action, Object sender, Object target) { | |||||
if (action == action_ok) { | |||||
okHandler(); | |||||
} | |||||
if (action == action_cancel) { | |||||
cancelHandler(); | |||||
} | |||||
} | |||||
/** | |||||
* Handle actions received from keyboard. This simply directs the actions to | |||||
* the same listener methods that are called with ButtonClick events. | |||||
*/ | |||||
public void handleAction(Action action, Object sender, Object target) { | |||||
if (action == action_ok) { | |||||
okHandler(); | |||||
} | |||||
if (action == action_cancel) { | |||||
cancelHandler(); | |||||
} | |||||
} | |||||
public void okHandler() { | |||||
// Do something: report the click | |||||
formlayout.addComponent(new Label("OK clicked. " + "User=" | |||||
+ username.getValue() + ", password=" + password.getValue())); | |||||
// | |||||
} | |||||
public void okHandler() { | |||||
// Do something: report the click | |||||
formlayout.addComponent(new Label("OK clicked. " + "User=" | |||||
+ username.getValue() + ", password=" + password.getValue())); | |||||
// | |||||
} | |||||
public void cancelHandler() { | |||||
// Do something: report the click | |||||
formlayout.addComponent(new Label("Cancel clicked. User=" | |||||
+ username.getValue() + ", password=" + password.getValue())); | |||||
} | |||||
public void cancelHandler() { | |||||
// Do something: report the click | |||||
formlayout.addComponent(new Label("Cancel clicked. User=" | |||||
+ username.getValue() + ", password=" + password.getValue())); | |||||
} | |||||
} | } |
// First tab contains a button, for which we | // First tab contains a button, for which we | ||||
// listen button click events. | // listen button click events. | ||||
tab1.addListener(this); | tab1.addListener(this); | ||||
// This will cause a selectedTabChange() call. | // This will cause a selectedTabChange() call. | ||||
tabsheet.addTab(tab1, "First Tab", null); | tabsheet.addTab(tab1, "First Tab", null); | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
// Enable the invisible and disabled tabs. | // Enable the invisible and disabled tabs. | ||||
tabsheet.getTab(tab2).setVisible(true); | |||||
tabsheet.getTab(tab3).setEnabled(true); | |||||
tabsheet.getTab(tab2).setVisible(true); | |||||
tabsheet.getTab(tab3).setEnabled(true); | |||||
// Change selection automatically to second tab. | // Change selection automatically to second tab. | ||||
tabsheet.setSelectedTab(tab2); | tabsheet.setSelectedTab(tab2); | ||||
public void selectedTabChange(SelectedTabChangeEvent event) { | public void selectedTabChange(SelectedTabChangeEvent event) { | ||||
// Cast to a TabSheet. This isn't really necessary in | // Cast to a TabSheet. This isn't really necessary in | ||||
// this example, as we have only one TabSheet component, | |||||
// but would be useful if there were multiple TabSheets. | |||||
// this example, as we have only one TabSheet component, | |||||
// but would be useful if there were multiple TabSheets. | |||||
final TabSheet source = (TabSheet) event.getSource(); | final TabSheet source = (TabSheet) event.getSource(); | ||||
if (source == tabsheet) { | if (source == tabsheet) { | ||||
// If the first tab was selected. | // If the first tab was selected. | ||||
if (source.getSelectedTab() == tab1) { | if (source.getSelectedTab() == tab1) { | ||||
// The 2. and 3. tabs may not have been set yet. | |||||
if (tabsheet.getTab(tab2) != null | |||||
&& tabsheet.getTab(tab3) != null) { | |||||
tabsheet.getTab(tab2).setVisible(false); | |||||
tabsheet.getTab(tab3).setEnabled(false); | |||||
} | |||||
// The 2. and 3. tabs may not have been set yet. | |||||
if (tabsheet.getTab(tab2) != null | |||||
&& tabsheet.getTab(tab3) != null) { | |||||
tabsheet.getTab(tab2).setVisible(false); | |||||
tabsheet.getTab(tab3).setEnabled(false); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } |
// of the container are integers so we can determine the column number | // of the container are integers so we can determine the column number | ||||
// easily. | // easily. | ||||
table.addContainerProperty("0", String.class, null, "", null, null); // Row | table.addContainerProperty("0", String.class, null, "", null, null); // Row | ||||
// header | |||||
// header | |||||
for (int i = 0; i < 8; i++) { | for (int i = 0; i < 8; i++) { | ||||
table.addContainerProperty("" + (i + 1), String.class, null, String | table.addContainerProperty("" + (i + 1), String.class, null, String | ||||
.valueOf((char) (65 + i)), null, null); | .valueOf((char) (65 + i)), null, null); |
// Create the table row. | // Create the table row. | ||||
table.addItem(new Object[] { calendar.getTime(), | table.addItem(new Object[] { calendar.getTime(), | ||||
new Boolean(false), "" }, new Integer(i)); // Item | new Boolean(false), "" }, new Integer(i)); // Item | ||||
// identifier | |||||
// identifier | |||||
} | } | ||||
table.setPageLength(8); | table.setPageLength(8); |
public class ReplaceComponentNPE extends TestBase { | public class ReplaceComponentNPE extends TestBase { | ||||
@Override | |||||
protected String getDescription() { | |||||
return "Clicking 'ReplaceComponent' should replace the 'Button' button with a VericalLayout, and move the button inside the verticalLayout. Visually this can be seen by the added margins of the VerticalLayout."; | |||||
} | |||||
@Override | |||||
protected Integer getTicketNumber() { | |||||
return 3195; | |||||
} | |||||
final Button button = new Button("Button"); | |||||
final VerticalLayout outer = new VerticalLayout(); | |||||
@Override | |||||
protected void setup() { | |||||
outer.setMargin(true); | |||||
Button changer = new Button("ReplaceComponent"); | |||||
changer.addListener(new Button.ClickListener() { | |||||
public void buttonClick(ClickEvent event) { | |||||
getLayout().replaceComponent(button, outer); | |||||
outer.addComponent(button); | |||||
} | |||||
}); | |||||
getLayout().addComponent(button); | |||||
getLayout().addComponent(changer); | |||||
} | |||||
@Override | |||||
protected String getDescription() { | |||||
return "Clicking 'ReplaceComponent' should replace the 'Button' button with a VericalLayout, and move the button inside the verticalLayout. Visually this can be seen by the added margins of the VerticalLayout."; | |||||
} | |||||
@Override | |||||
protected Integer getTicketNumber() { | |||||
return 3195; | |||||
} | |||||
final Button button = new Button("Button"); | |||||
final VerticalLayout outer = new VerticalLayout(); | |||||
@Override | |||||
protected void setup() { | |||||
outer.setMargin(true); | |||||
Button changer = new Button("ReplaceComponent"); | |||||
changer.addListener(new Button.ClickListener() { | |||||
public void buttonClick(ClickEvent event) { | |||||
getLayout().replaceComponent(button, outer); | |||||
outer.addComponent(button); | |||||
} | |||||
}); | |||||
getLayout().addComponent(button); | |||||
getLayout().addComponent(changer); | |||||
} | |||||
} | } |
package com.vaadin.tests.components.splitpanel; | package com.vaadin.tests.components.splitpanel; | ||||
import com.vaadin.terminal.Sizeable; | import com.vaadin.terminal.Sizeable; | ||||
import com.vaadin.tests.components.AbstractTestCase; | import com.vaadin.tests.components.AbstractTestCase; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; |
package com.vaadin.tests.components.textfield; | package com.vaadin.tests.components.textfield; | ||||
import com.vaadin.tests.components.TestBase; | import com.vaadin.tests.components.TestBase; | ||||
import com.vaadin.ui.TextField; | import com.vaadin.ui.TextField; | ||||
package com.vaadin.tests.components.textfield; | package com.vaadin.tests.components.textfield; | ||||
import com.vaadin.Application; | import com.vaadin.Application; | ||||
import com.vaadin.ui.Component; | import com.vaadin.ui.Component; | ||||
import com.vaadin.ui.Panel; | import com.vaadin.ui.Panel; |
} | } | ||||
/** | /** | ||||
* @see com.vaadin.ui.Upload.Receiver#receiveUpload(String, | |||||
* String) | |||||
* @see com.vaadin.ui.Upload.Receiver#receiveUpload(String, String) | |||||
*/ | */ | ||||
public OutputStream receiveUpload(String filename, String MIMEType) { | public OutputStream receiveUpload(String filename, String MIMEType) { | ||||
fileName = filename; | fileName = filename; |
import com.vaadin.ui.Window; | import com.vaadin.ui.Window; | ||||
import com.vaadin.ui.Button.ClickEvent; | import com.vaadin.ui.Button.ClickEvent; | ||||
public abstract class Robustness extends com.vaadin.Application | |||||
implements Button.ClickListener { | |||||
public abstract class Robustness extends com.vaadin.Application implements | |||||
Button.ClickListener { | |||||
static int totalCount = 0; | static int totalCount = 0; | ||||
* transaction is then started for each application. Some semi-random delays | * transaction is then started for each application. Some semi-random delays | ||||
* are included so that calls to addTransactionListener and | * are included so that calls to addTransactionListener and | ||||
* WebApplicationContext.startTransaction are mixed. | * WebApplicationContext.startTransaction are mixed. | ||||
* | |||||
* | |||||
*/ | */ | ||||
public void testTransactionListeners() throws Exception { | public void testTransactionListeners() throws Exception { | ||||
final List<Throwable> exceptions = new ArrayList<Throwable>(); | final List<Throwable> exceptions = new ArrayList<Throwable>(); | ||||
/** | /** | ||||
* Creates a HttpSession mock | * Creates a HttpSession mock | ||||
* | |||||
* | |||||
*/ | */ | ||||
private static HttpSession createSession() { | private static HttpSession createSession() { | ||||
HttpSession session = createMock(HttpSession.class); | HttpSession session = createMock(HttpSession.class); | ||||
/** | /** | ||||
* A transaction listener that just sleeps for the given amount of time in | * A transaction listener that just sleeps for the given amount of time in | ||||
* transactionStart and transactionEnd. | * transactionStart and transactionEnd. | ||||
* | |||||
* | |||||
*/ | */ | ||||
public static class DelayTransactionListener implements TransactionListener { | public static class DelayTransactionListener implements TransactionListener { | ||||
import com.vaadin.ui.TextField; | import com.vaadin.ui.TextField; | ||||
import com.vaadin.ui.Window; | import com.vaadin.ui.Window; | ||||
public class Ticket1365 extends com.vaadin.Application implements | |||||
Handler { | |||||
public class Ticket1365 extends com.vaadin.Application implements Handler { | |||||
TextField f = new TextField(); | TextField f = new TextField(); | ||||