Cleanup performed Organized imports Format svn changeset:3162/svn branch:trunktags/6.7.0.beta1
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit; | package com.itmill.toolkit; | ||||
/** | /** | ||||
* Mapping from window name to window instance. | * Mapping from window name to window instance. | ||||
*/ | */ | ||||
private Hashtable windows = new Hashtable(); | |||||
private final Hashtable windows = new Hashtable(); | |||||
/** | /** | ||||
* Main window of the application. | * Main window of the application. | ||||
/** | /** | ||||
* Application resource mapping: key <-> resource. | * Application resource mapping: key <-> resource. | ||||
*/ | */ | ||||
private Hashtable resourceKeyMap = new Hashtable(); | |||||
private final Hashtable resourceKeyMap = new Hashtable(); | |||||
private Hashtable keyResourceMap = new Hashtable(); | |||||
private final Hashtable keyResourceMap = new Hashtable(); | |||||
private long lastResourceKeyNumber = 0; | private long lastResourceKeyNumber = 0; | ||||
} | } | ||||
// Gets the window by name | // Gets the window by name | ||||
Window window = (Window) windows.get(name); | |||||
final Window window = (Window) windows.get(name); | |||||
return window; | return window; | ||||
} | } | ||||
private void fireWindowAttachEvent(Window window) { | private void fireWindowAttachEvent(Window window) { | ||||
// Fires the window attach event | // Fires the window attach event | ||||
if (windowAttachListeners != null) { | if (windowAttachListeners != null) { | ||||
Object[] listeners = windowAttachListeners.toArray(); | |||||
WindowAttachEvent event = new WindowAttachEvent(window); | |||||
final Object[] listeners = windowAttachListeners.toArray(); | |||||
final WindowAttachEvent event = new WindowAttachEvent(window); | |||||
for (int i = 0; i < listeners.length; i++) { | for (int i = 0; i < listeners.length; i++) { | ||||
((WindowAttachListener) listeners[i]).windowAttached(event); | ((WindowAttachListener) listeners[i]).windowAttached(event); | ||||
} | } | ||||
private void fireWindowDetachEvent(Window window) { | private void fireWindowDetachEvent(Window window) { | ||||
// Fires the window detach event | // Fires the window detach event | ||||
if (windowDetachListeners != null) { | if (windowDetachListeners != null) { | ||||
Object[] listeners = windowDetachListeners.toArray(); | |||||
WindowDetachEvent event = new WindowDetachEvent(window); | |||||
final Object[] listeners = windowDetachListeners.toArray(); | |||||
final WindowDetachEvent event = new WindowDetachEvent(window); | |||||
for (int i = 0; i < listeners.length; i++) { | for (int i = 0; i < listeners.length; i++) { | ||||
((WindowDetachListener) listeners[i]).windowDetached(event); | ((WindowDetachListener) listeners[i]).windowDetached(event); | ||||
} | } | ||||
* the new user. | * the new user. | ||||
*/ | */ | ||||
public void setUser(Object user) { | public void setUser(Object user) { | ||||
Object prevUser = this.user; | |||||
final Object prevUser = this.user; | |||||
if (user != prevUser && (user == null || !user.equals(prevUser))) { | if (user != prevUser && (user == null || !user.equals(prevUser))) { | ||||
this.user = user; | this.user = user; | ||||
if (userChangeListeners != null) { | if (userChangeListeners != null) { | ||||
Object[] listeners = userChangeListeners.toArray(); | |||||
UserChangeEvent event = new UserChangeEvent(this, user, | |||||
final Object[] listeners = userChangeListeners.toArray(); | |||||
final UserChangeEvent event = new UserChangeEvent(this, user, | |||||
prevUser); | prevUser); | ||||
for (int i = 0; i < listeners.length; i++) { | for (int i = 0; i < listeners.length; i++) { | ||||
((UserChangeListener) listeners[i]) | ((UserChangeListener) listeners[i]) | ||||
public void setTheme(String theme) { | public void setTheme(String theme) { | ||||
// Collect list of windows not having the current or future theme | // Collect list of windows not having the current or future theme | ||||
LinkedList toBeUpdated = new LinkedList(); | |||||
String myTheme = getTheme(); | |||||
for (Iterator i = getWindows().iterator(); i.hasNext();) { | |||||
Window w = (Window) i.next(); | |||||
String windowTheme = w.getTheme(); | |||||
final LinkedList toBeUpdated = new LinkedList(); | |||||
final String myTheme = getTheme(); | |||||
for (final Iterator i = getWindows().iterator(); i.hasNext();) { | |||||
final Window w = (Window) i.next(); | |||||
final String windowTheme = w.getTheme(); | |||||
if ((windowTheme == null) | if ((windowTheme == null) | ||||
|| (!theme.equals(windowTheme) && windowTheme | || (!theme.equals(windowTheme) && windowTheme | ||||
.equals(myTheme))) { | .equals(myTheme))) { | ||||
this.theme = theme; | this.theme = theme; | ||||
// Ask windows to update themselves | // Ask windows to update themselves | ||||
for (Iterator i = toBeUpdated.iterator(); i.hasNext();) { | |||||
for (final Iterator i = toBeUpdated.iterator(); i.hasNext();) { | |||||
((Window) i.next()).requestRepaint(); | ((Window) i.next()).requestRepaint(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Generate key | // Generate key | ||||
String key = String.valueOf(++lastResourceKeyNumber); | |||||
final String key = String.valueOf(++lastResourceKeyNumber); | |||||
// Add the resource to mappings | // Add the resource to mappings | ||||
resourceKeyMap.put(resource, key); | resourceKeyMap.put(resource, key); | ||||
* the resource to remove. | * the resource to remove. | ||||
*/ | */ | ||||
public void removeResource(ApplicationResource resource) { | public void removeResource(ApplicationResource resource) { | ||||
Object key = resourceKeyMap.get(resource); | |||||
final Object key = resourceKeyMap.get(resource); | |||||
if (key != null) { | if (key != null) { | ||||
resourceKeyMap.remove(resource); | resourceKeyMap.remove(resource); | ||||
keyResourceMap.remove(key); | keyResourceMap.remove(key); | ||||
public String getRelativeLocation(ApplicationResource resource) { | public String getRelativeLocation(ApplicationResource resource) { | ||||
// Gets the key | // Gets the key | ||||
String key = (String) resourceKeyMap.get(resource); | |||||
final String key = (String) resourceKeyMap.get(resource); | |||||
// If the resource is not registered, return null | // If the resource is not registered, return null | ||||
if (key == null) { | if (key == null) { | ||||
return null; | return null; | ||||
} | } | ||||
String filename = resource.getFilename(); | |||||
final String filename = resource.getFilename(); | |||||
if (filename == null) { | if (filename == null) { | ||||
return "APP/" + key + "/"; | return "APP/" + key + "/"; | ||||
} else { | } else { | ||||
// Resolves the prefix | // Resolves the prefix | ||||
String prefix = relativeUri; | String prefix = relativeUri; | ||||
int index = relativeUri.indexOf('/'); | |||||
final int index = relativeUri.indexOf('/'); | |||||
if (index >= 0) { | if (index >= 0) { | ||||
prefix = relativeUri.substring(0, index); | prefix = relativeUri.substring(0, index); | ||||
} | } | ||||
if (prefix.equals("APP")) { | if (prefix.equals("APP")) { | ||||
// Handles the resource request | // Handles the resource request | ||||
int next = relativeUri.indexOf('/', index + 1); | |||||
final int next = relativeUri.indexOf('/', index + 1); | |||||
if (next < 0) { | if (next < 0) { | ||||
return null; | return null; | ||||
} | } | ||||
String key = relativeUri.substring(index + 1, next); | |||||
ApplicationResource resource = (ApplicationResource) keyResourceMap | |||||
final String key = relativeUri.substring(index + 1, next); | |||||
final ApplicationResource resource = (ApplicationResource) keyResourceMap | |||||
.get(key); | .get(key); | ||||
if (resource != null) { | if (resource != null) { | ||||
return resource.getStream(); | return resource.getStream(); | ||||
URL windowContext; | URL windowContext; | ||||
try { | try { | ||||
windowContext = new URL(context, prefix + "/"); | windowContext = new URL(context, prefix + "/"); | ||||
String windowUri = relativeUri.length() > prefix.length() + 1 ? relativeUri | |||||
final String windowUri = relativeUri.length() > prefix.length() + 1 ? relativeUri | |||||
.substring(prefix.length() + 1) | .substring(prefix.length() + 1) | ||||
: ""; | : ""; | ||||
return window.handleURI(windowContext, windowUri); | return window.handleURI(windowContext, windowUri); | ||||
} catch (MalformedURLException e) { | |||||
} catch (final MalformedURLException e) { | |||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* New user of the application. | * New user of the application. | ||||
*/ | */ | ||||
private Object newUser; | |||||
private final Object newUser; | |||||
/** | /** | ||||
* Previous user of the application. | * Previous user of the application. | ||||
*/ | */ | ||||
private Object prevUser; | |||||
private final Object prevUser; | |||||
/** | /** | ||||
* Constructor for user change event. | * Constructor for user change event. | ||||
*/ | */ | ||||
private static final long serialVersionUID = 3544669568644691769L; | private static final long serialVersionUID = 3544669568644691769L; | ||||
private Window window; | |||||
private final Window window; | |||||
/** | /** | ||||
* Creates a event. | * Creates a event. | ||||
*/ | */ | ||||
private static final long serialVersionUID = 3977578104367822392L; | private static final long serialVersionUID = 3977578104367822392L; | ||||
private Window window; | |||||
private final Window window; | |||||
/** | /** | ||||
* Creates a event. | * Creates a event. | ||||
// Shows the error in AbstractComponent | // Shows the error in AbstractComponent | ||||
if (owner instanceof AbstractComponent) { | if (owner instanceof AbstractComponent) { | ||||
Throwable e = event.getThrowable(); | |||||
final Throwable e = event.getThrowable(); | |||||
if (e instanceof ErrorMessage) { | if (e instanceof ErrorMessage) { | ||||
((AbstractComponent) owner).setComponentError((ErrorMessage) e); | ((AbstractComponent) owner).setComponentError((ErrorMessage) e); | ||||
} else { | } else { | ||||
* @return Focused component or null if none is focused. | * @return Focused component or null if none is focused. | ||||
*/ | */ | ||||
public Component.Focusable consumeFocus() { | public Component.Focusable consumeFocus() { | ||||
Component.Focusable f = pendingFocus; | |||||
final Component.Focusable f = pendingFocus; | |||||
pendingFocus = null; | pendingFocus = null; | ||||
return f; | return f; | ||||
} | } |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data; | package com.itmill.toolkit.data; | ||||
private static final long serialVersionUID = 3256720671781630518L; | private static final long serialVersionUID = 3256720671781630518L; | ||||
/** Source class implementing the buffered interface */ | /** Source class implementing the buffered interface */ | ||||
private Buffered source; | |||||
private final Buffered source; | |||||
/** Original cause of the source exception */ | /** Original cause of the source exception */ | ||||
private Throwable[] causes = {}; | private Throwable[] causes = {}; | ||||
int level = Integer.MIN_VALUE; | int level = Integer.MIN_VALUE; | ||||
for (int i = 0; i < causes.length; i++) { | for (int i = 0; i < causes.length; i++) { | ||||
int causeLevel = (causes[i] instanceof ErrorMessage) ? ((ErrorMessage) causes[i]) | |||||
final int causeLevel = (causes[i] instanceof ErrorMessage) ? ((ErrorMessage) causes[i]) | |||||
.getErrorLevel() | .getErrorLevel() | ||||
: ErrorMessage.ERROR; | : ErrorMessage.ERROR; | ||||
if (causeLevel > level) { | if (causeLevel > level) { | ||||
/* Documented in super interface */ | /* Documented in super interface */ | ||||
public void paint(PaintTarget target) throws PaintException { | public void paint(PaintTarget target) throws PaintException { | ||||
target.startTag("error"); | target.startTag("error"); | ||||
int level = getErrorLevel(); | |||||
final int level = getErrorLevel(); | |||||
if (level > 0 && level <= ErrorMessage.INFORMATION) { | if (level > 0 && level <= ErrorMessage.INFORMATION) { | ||||
target.addAttribute("level", "info"); | target.addAttribute("level", "info"); | ||||
} else if (level <= ErrorMessage.WARNING) { | } else if (level <= ErrorMessage.WARNING) { |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data; | package com.itmill.toolkit.data; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data; | package com.itmill.toolkit.data; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data; | package com.itmill.toolkit.data; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data; | package com.itmill.toolkit.data; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data; | package com.itmill.toolkit.data; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data; | package com.itmill.toolkit.data; | ||||
target.addAttribute("level", "error"); | target.addAttribute("level", "error"); | ||||
// Error message | // Error message | ||||
String message = getLocalizedMessage(); | |||||
final String message = getLocalizedMessage(); | |||||
if (message != null) { | if (message != null) { | ||||
target.addText(message); | target.addText(message); | ||||
} | } |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data.util; | package com.itmill.toolkit.data.util; | ||||
/** | /** | ||||
* The bean which this Item is based on. | * The bean which this Item is based on. | ||||
*/ | */ | ||||
private Object bean; | |||||
private final Object bean; | |||||
/** | /** | ||||
* <p> | * <p> | ||||
// Try to introspect, if it fails, we just have an empty Item | // Try to introspect, if it fails, we just have an empty Item | ||||
try { | try { | ||||
// Create bean information | // Create bean information | ||||
BeanInfo info = Introspector.getBeanInfo(bean.getClass()); | |||||
PropertyDescriptor[] pd = info.getPropertyDescriptors(); | |||||
final BeanInfo info = Introspector.getBeanInfo(bean.getClass()); | |||||
final PropertyDescriptor[] pd = info.getPropertyDescriptors(); | |||||
// Add all the bean properties as MethodProperties to this Item | // Add all the bean properties as MethodProperties to this Item | ||||
for (int i = 0; i < pd.length; i++) { | for (int i = 0; i < pd.length; i++) { | ||||
Method getMethod = pd[i].getReadMethod(); | |||||
Method setMethod = pd[i].getWriteMethod(); | |||||
Class type = pd[i].getPropertyType(); | |||||
String name = pd[i].getName(); | |||||
final Method getMethod = pd[i].getReadMethod(); | |||||
final Method setMethod = pd[i].getWriteMethod(); | |||||
final Class type = pd[i].getPropertyType(); | |||||
final String name = pd[i].getName(); | |||||
if ((getMethod != null) && (setMethod != null)) { | if ((getMethod != null) && (setMethod != null)) { | ||||
Property p = new MethodProperty(type, bean, getMethod, | |||||
setMethod); | |||||
final Property p = new MethodProperty(type, bean, | |||||
getMethod, setMethod); | |||||
addItemProperty(name, p); | addItemProperty(name, p); | ||||
} | } | ||||
} | } | ||||
} catch (java.beans.IntrospectionException ignored) { | |||||
} catch (final java.beans.IntrospectionException ignored) { | |||||
} | } | ||||
} | } | ||||
// Try to introspect, if it fails, we just have an empty Item | // Try to introspect, if it fails, we just have an empty Item | ||||
try { | try { | ||||
// Create bean information | // Create bean information | ||||
BeanInfo info = Introspector.getBeanInfo(bean.getClass()); | |||||
PropertyDescriptor[] pd = info.getPropertyDescriptors(); | |||||
final BeanInfo info = Introspector.getBeanInfo(bean.getClass()); | |||||
final PropertyDescriptor[] pd = info.getPropertyDescriptors(); | |||||
// Add all the bean properties as MethodProperties to this Item | // Add all the bean properties as MethodProperties to this Item | ||||
for (Iterator iter = propertyIds.iterator(); iter.hasNext();) { | |||||
Object id = iter.next(); | |||||
for (final Iterator iter = propertyIds.iterator(); iter.hasNext();) { | |||||
final Object id = iter.next(); | |||||
for (int i = 0; i < pd.length; i++) { | for (int i = 0; i < pd.length; i++) { | ||||
String name = pd[i].getName(); | |||||
final String name = pd[i].getName(); | |||||
if (name.equals(id)) { | if (name.equals(id)) { | ||||
Method getMethod = pd[i].getReadMethod(); | |||||
Method setMethod = pd[i].getWriteMethod(); | |||||
Class type = pd[i].getPropertyType(); | |||||
final Method getMethod = pd[i].getReadMethod(); | |||||
final Method setMethod = pd[i].getWriteMethod(); | |||||
final Class type = pd[i].getPropertyType(); | |||||
Property p = new MethodProperty(type, bean, getMethod, | |||||
setMethod); | |||||
final Property p = new MethodProperty(type, bean, | |||||
getMethod, setMethod); | |||||
addItemProperty(name, p); | addItemProperty(name, p); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} catch (java.beans.IntrospectionException ignored) { | |||||
} catch (final java.beans.IntrospectionException ignored) { | |||||
} | } | ||||
} | } |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data.util; | package com.itmill.toolkit.data.util; | ||||
Container.ItemSetChangeNotifier, Container.PropertySetChangeNotifier { | Container.ItemSetChangeNotifier, Container.PropertySetChangeNotifier { | ||||
/** The wrapped container */ | /** The wrapped container */ | ||||
private Container container; | |||||
private final Container container; | |||||
/** Set of IDs of those contained Items that can't have children. */ | /** Set of IDs of those contained Items that can't have children. */ | ||||
private HashSet noChildrenAllowed = null; | private HashSet noChildrenAllowed = null; | ||||
else { | else { | ||||
// Calculate the set of all items in the hierarchy | // Calculate the set of all items in the hierarchy | ||||
HashSet s = new HashSet(); | |||||
final HashSet s = new HashSet(); | |||||
s.add(parent.keySet()); | s.add(parent.keySet()); | ||||
s.add(children.keySet()); | s.add(children.keySet()); | ||||
s.addAll(roots); | s.addAll(roots); | ||||
// Remove unnecessary items | // Remove unnecessary items | ||||
for (Iterator i = s.iterator(); i.hasNext();) { | |||||
Object id = i.next(); | |||||
for (final Iterator i = s.iterator(); i.hasNext();) { | |||||
final Object id = i.next(); | |||||
if (!container.containsId(id)) { | if (!container.containsId(id)) { | ||||
removeFromHierarchyWrapper(id); | removeFromHierarchyWrapper(id); | ||||
} | } | ||||
} | } | ||||
// Add all the missing items | // Add all the missing items | ||||
Collection ids = container.getItemIds(); | |||||
for (Iterator i = ids.iterator(); i.hasNext();) { | |||||
Object id = i.next(); | |||||
final Collection ids = container.getItemIds(); | |||||
for (final Iterator i = ids.iterator(); i.hasNext();) { | |||||
final Object id = i.next(); | |||||
if (!s.contains(id)) { | if (!s.contains(id)) { | ||||
addToHierarchyWrapper(id); | addToHierarchyWrapper(id); | ||||
s.add(id); | s.add(id); | ||||
if (isRoot(itemId)) { | if (isRoot(itemId)) { | ||||
roots.remove(itemId); | roots.remove(itemId); | ||||
} | } | ||||
Object p = parent.get(itemId); | |||||
final Object p = parent.get(itemId); | |||||
if (p != null) { | if (p != null) { | ||||
LinkedList c = (LinkedList) children.get(p); | |||||
final LinkedList c = (LinkedList) children.get(p); | |||||
if (c != null) { | if (c != null) { | ||||
c.remove(itemId); | c.remove(itemId); | ||||
} | } | ||||
return ((Container.Hierarchical) container).getChildren(itemId); | return ((Container.Hierarchical) container).getChildren(itemId); | ||||
} | } | ||||
Collection c = (Collection) children.get(itemId); | |||||
final Collection c = (Collection) children.get(itemId); | |||||
if (c == null) { | if (c == null) { | ||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
// Get the old parent | // Get the old parent | ||||
Object oldParentId = parent.get(itemId); | |||||
final Object oldParentId = parent.get(itemId); | |||||
// Check if no change is necessary | // Check if no change is necessary | ||||
if ((newParentId == null && oldParentId == null) | if ((newParentId == null && oldParentId == null) | ||||
if (newParentId == null) { | if (newParentId == null) { | ||||
// Remove from old parents children list | // Remove from old parents children list | ||||
LinkedList l = (LinkedList) children.get(itemId); | |||||
final LinkedList l = (LinkedList) children.get(itemId); | |||||
if (l != null) { | if (l != null) { | ||||
l.remove(itemId); | l.remove(itemId); | ||||
if (l.isEmpty()) { | if (l.isEmpty()) { | ||||
if (oldParentId == null) { | if (oldParentId == null) { | ||||
roots.remove(itemId); | roots.remove(itemId); | ||||
} else { | } else { | ||||
LinkedList l = (LinkedList) children.get(oldParentId); | |||||
final LinkedList l = (LinkedList) children.get(oldParentId); | |||||
if (l != null) { | if (l != null) { | ||||
l.remove(itemId); | l.remove(itemId); | ||||
if (l.isEmpty()) { | if (l.isEmpty()) { | ||||
*/ | */ | ||||
public Object addItem() throws UnsupportedOperationException { | public Object addItem() throws UnsupportedOperationException { | ||||
Object id = container.addItem(); | |||||
final Object id = container.addItem(); | |||||
if (id != null) { | if (id != null) { | ||||
addToHierarchyWrapper(id); | addToHierarchyWrapper(id); | ||||
} | } | ||||
*/ | */ | ||||
public Item addItem(Object itemId) throws UnsupportedOperationException { | public Item addItem(Object itemId) throws UnsupportedOperationException { | ||||
Item item = container.addItem(itemId); | |||||
final Item item = container.addItem(itemId); | |||||
if (item != null) { | if (item != null) { | ||||
addToHierarchyWrapper(itemId); | addToHierarchyWrapper(itemId); | ||||
} | } | ||||
*/ | */ | ||||
public boolean removeAllItems() throws UnsupportedOperationException { | public boolean removeAllItems() throws UnsupportedOperationException { | ||||
boolean success = container.removeAllItems(); | |||||
final boolean success = container.removeAllItems(); | |||||
if (success) { | if (success) { | ||||
roots.clear(); | roots.clear(); | ||||
public boolean removeItem(Object itemId) | public boolean removeItem(Object itemId) | ||||
throws UnsupportedOperationException { | throws UnsupportedOperationException { | ||||
boolean success = container.removeItem(itemId); | |||||
final boolean success = container.removeItem(itemId); | |||||
if (success) { | if (success) { | ||||
removeFromHierarchyWrapper(itemId); | removeFromHierarchyWrapper(itemId); |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data.util; | package com.itmill.toolkit.data.util; | ||||
/** | /** | ||||
* The wrapped container | * The wrapped container | ||||
*/ | */ | ||||
private Container container; | |||||
private final Container container; | |||||
/** | /** | ||||
* Ordering information, ie. the mapping from Item ID to the next item ID | * Ordering information, ie. the mapping from Item ID to the next item ID | ||||
*/ | */ | ||||
private void removeFromOrderWrapper(Object id) { | private void removeFromOrderWrapper(Object id) { | ||||
if (id != null) { | if (id != null) { | ||||
Object pid = prev.get(id); | |||||
Object nid = next.get(id); | |||||
final Object pid = prev.get(id); | |||||
final Object nid = next.get(id); | |||||
if (first.equals(id)) { | if (first.equals(id)) { | ||||
first = nid; | first = nid; | ||||
} | } | ||||
if (!ordered) { | if (!ordered) { | ||||
Collection ids = container.getItemIds(); | |||||
final Collection ids = container.getItemIds(); | |||||
// Recreates ordering if some parts of it are missing | // Recreates ordering if some parts of it are missing | ||||
if (next == null || first == null || last == null || prev != null) { | if (next == null || first == null || last == null || prev != null) { | ||||
} | } | ||||
// Filter out all the missing items | // Filter out all the missing items | ||||
LinkedList l = new LinkedList(next.keySet()); | |||||
for (Iterator i = l.iterator(); i.hasNext();) { | |||||
Object id = i.next(); | |||||
final LinkedList l = new LinkedList(next.keySet()); | |||||
for (final Iterator i = l.iterator(); i.hasNext();) { | |||||
final Object id = i.next(); | |||||
if (!container.containsId(id)) { | if (!container.containsId(id)) { | ||||
removeFromOrderWrapper(id); | removeFromOrderWrapper(id); | ||||
} | } | ||||
} | } | ||||
// Adds missing items | // Adds missing items | ||||
for (Iterator i = ids.iterator(); i.hasNext();) { | |||||
Object id = i.next(); | |||||
for (final Iterator i = ids.iterator(); i.hasNext();) { | |||||
final Object id = i.next(); | |||||
if (!next.containsKey(id)) { | if (!next.containsKey(id)) { | ||||
addToOrderWrapper(id); | addToOrderWrapper(id); | ||||
} | } | ||||
*/ | */ | ||||
public Object addItem() throws UnsupportedOperationException { | public Object addItem() throws UnsupportedOperationException { | ||||
Object id = container.addItem(); | |||||
final Object id = container.addItem(); | |||||
if (id != null) { | if (id != null) { | ||||
addToOrderWrapper(id); | addToOrderWrapper(id); | ||||
} | } | ||||
* if the addItem is not supported. | * if the addItem is not supported. | ||||
*/ | */ | ||||
public Item addItem(Object itemId) throws UnsupportedOperationException { | public Item addItem(Object itemId) throws UnsupportedOperationException { | ||||
Item item = container.addItem(itemId); | |||||
final Item item = container.addItem(itemId); | |||||
if (item != null) { | if (item != null) { | ||||
addToOrderWrapper(itemId); | addToOrderWrapper(itemId); | ||||
} | } | ||||
* if the removeAllItems is not supported. | * if the removeAllItems is not supported. | ||||
*/ | */ | ||||
public boolean removeAllItems() throws UnsupportedOperationException { | public boolean removeAllItems() throws UnsupportedOperationException { | ||||
boolean success = container.removeAllItems(); | |||||
final boolean success = container.removeAllItems(); | |||||
if (success) { | if (success) { | ||||
first = last = null; | first = last = null; | ||||
next.clear(); | next.clear(); | ||||
public boolean removeItem(Object itemId) | public boolean removeItem(Object itemId) | ||||
throws UnsupportedOperationException { | throws UnsupportedOperationException { | ||||
boolean success = container.removeItem(itemId); | |||||
final boolean success = container.removeItem(itemId); | |||||
if (success) { | if (success) { | ||||
removeFromOrderWrapper(itemId); | removeFromOrderWrapper(itemId); | ||||
} | } | ||||
} | } | ||||
// Adds the item to container | // Adds the item to container | ||||
Item item = container.addItem(newItemId); | |||||
final Item item = container.addItem(newItemId); | |||||
// Puts the new item to its correct place | // Puts the new item to its correct place | ||||
if (item != null) { | if (item != null) { | ||||
} | } | ||||
// Adds the item to container | // Adds the item to container | ||||
Object id = container.addItem(); | |||||
final Object id = container.addItem(); | |||||
// Puts the new item to its correct place | // Puts the new item to its correct place | ||||
if (id != null) { | if (id != null) { |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data.util; | package com.itmill.toolkit.data.util; | ||||
FILEITEM_NAME = FileItem.class.getMethod("getName", new Class[] {}); | FILEITEM_NAME = FileItem.class.getMethod("getName", new Class[] {}); | ||||
FILEITEM_ICON = FileItem.class.getMethod("getIcon", new Class[] {}); | FILEITEM_ICON = FileItem.class.getMethod("getIcon", new Class[] {}); | ||||
FILEITEM_SIZE = FileItem.class.getMethod("getSize", new Class[] {}); | FILEITEM_SIZE = FileItem.class.getMethod("getSize", new Class[] {}); | ||||
} catch (NoSuchMethodException e) { | |||||
} catch (final NoSuchMethodException e) { | |||||
} | } | ||||
} | } | ||||
*/ | */ | ||||
public void addRoot(File root) { | public void addRoot(File root) { | ||||
if (root != null) { | if (root != null) { | ||||
File[] newRoots = new File[roots.length + 1]; | |||||
final File[] newRoots = new File[roots.length + 1]; | |||||
for (int i = 0; i < roots.length; i++) { | for (int i = 0; i < roots.length; i++) { | ||||
newRoots[i] = roots[i]; | newRoots[i] = roots[i]; | ||||
} | } | ||||
return Collections.unmodifiableCollection(new LinkedList()); | return Collections.unmodifiableCollection(new LinkedList()); | ||||
} | } | ||||
List l = Arrays.asList(f); | |||||
final List l = Arrays.asList(f); | |||||
Collections.sort(l); | Collections.sort(l); | ||||
return Collections.unmodifiableCollection(l); | return Collections.unmodifiableCollection(l); | ||||
return Collections.unmodifiableCollection(new LinkedList()); | return Collections.unmodifiableCollection(new LinkedList()); | ||||
} | } | ||||
List l = Arrays.asList(f); | |||||
final List l = Arrays.asList(f); | |||||
Collections.sort(l); | Collections.sort(l); | ||||
return Collections.unmodifiableCollection(l); | return Collections.unmodifiableCollection(l); | ||||
try { | try { | ||||
val |= ((File) itemId).getCanonicalPath().startsWith( | val |= ((File) itemId).getCanonicalPath().startsWith( | ||||
roots[i].getCanonicalPath()); | roots[i].getCanonicalPath()); | ||||
} catch (IOException e) { | |||||
} catch (final IOException e) { | |||||
// Exception ignored | // Exception ignored | ||||
} | } | ||||
} else { | } else { | ||||
l = f.listFiles(); | l = f.listFiles(); | ||||
} | } | ||||
List ll = Arrays.asList(l); | |||||
final List ll = Arrays.asList(l); | |||||
Collections.sort(ll); | Collections.sort(ll); | ||||
for (Iterator i = ll.iterator(); i.hasNext();) { | |||||
File lf = (File) i.next(); | |||||
for (final Iterator i = ll.iterator(); i.hasNext();) { | |||||
final File lf = (File) i.next(); | |||||
if (lf.isDirectory()) { | if (lf.isDirectory()) { | ||||
addItemIds(col, lf); | addItemIds(col, lf); | ||||
} else { | } else { | ||||
public Collection getItemIds() { | public Collection getItemIds() { | ||||
if (recursive) { | if (recursive) { | ||||
Collection col = new ArrayList(); | |||||
final Collection col = new ArrayList(); | |||||
for (int i = 0; i < roots.length; i++) { | for (int i = 0; i < roots.length; i++) { | ||||
addItemIds(col, roots[i]); | addItemIds(col, roots[i]); | ||||
} | } | ||||
return Collections.unmodifiableCollection(new LinkedList()); | return Collections.unmodifiableCollection(new LinkedList()); | ||||
} | } | ||||
List l = Arrays.asList(f); | |||||
final List l = Arrays.asList(f); | |||||
Collections.sort(l); | Collections.sort(l); | ||||
return Collections.unmodifiableCollection(l); | return Collections.unmodifiableCollection(l); | ||||
} | } | ||||
/** | /** | ||||
* The wrapped file. | * The wrapped file. | ||||
*/ | */ | ||||
private File file; | |||||
private final File file; | |||||
/** | /** | ||||
* Constructs a FileItem from a existing file. | * Constructs a FileItem from a existing file. | ||||
if (obj == null || !(obj instanceof FileItem)) { | if (obj == null || !(obj instanceof FileItem)) { | ||||
return false; | return false; | ||||
} | } | ||||
FileItem fi = (FileItem) obj; | |||||
final FileItem fi = (FileItem) obj; | |||||
return fi.getHost() == getHost() && fi.file.equals(file); | return fi.getHost() == getHost() && fi.file.equals(file); | ||||
} | } | ||||
*/ | */ | ||||
public class FileExtensionFilter implements FilenameFilter { | public class FileExtensionFilter implements FilenameFilter { | ||||
private String filter; | |||||
private final String filter; | |||||
/** | /** | ||||
* Constructs a new FileExtensionFilter using given extension. | * Constructs a new FileExtensionFilter using given extension. |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data.util; | package com.itmill.toolkit.data.util; | ||||
/** | /** | ||||
* Set of IDs of those contained Items that can't have children. | * Set of IDs of those contained Items that can't have children. | ||||
*/ | */ | ||||
private HashSet noChildrenAllowed = new HashSet(); | |||||
private final HashSet noChildrenAllowed = new HashSet(); | |||||
/** | /** | ||||
* Mapping from Item ID to parent Item. | * Mapping from Item ID to parent Item. | ||||
*/ | */ | ||||
private Hashtable parent = new Hashtable(); | |||||
private final Hashtable parent = new Hashtable(); | |||||
/** | /** | ||||
* Mapping from Item ID to a list of child IDs. | * Mapping from Item ID to a list of child IDs. | ||||
*/ | */ | ||||
private Hashtable children = new Hashtable(); | |||||
private final Hashtable children = new Hashtable(); | |||||
/** | /** | ||||
* List that contains all root elements of the container. | * List that contains all root elements of the container. | ||||
*/ | */ | ||||
private LinkedList roots = new LinkedList(); | |||||
private final LinkedList roots = new LinkedList(); | |||||
/* | /* | ||||
* Can the specified Item have any children? Don't add a JavaDoc comment | * Can the specified Item have any children? Don't add a JavaDoc comment | ||||
* interface. | * interface. | ||||
*/ | */ | ||||
public Collection getChildren(Object itemId) { | public Collection getChildren(Object itemId) { | ||||
Collection c = (Collection) children.get(itemId); | |||||
final Collection c = (Collection) children.get(itemId); | |||||
if (c == null) { | if (c == null) { | ||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
// Gets the old parent | // Gets the old parent | ||||
Object oldParentId = parent.get(itemId); | |||||
final Object oldParentId = parent.get(itemId); | |||||
// Checks if no change is necessary | // Checks if no change is necessary | ||||
if ((newParentId == null && oldParentId == null) | if ((newParentId == null && oldParentId == null) | ||||
if (newParentId == null) { | if (newParentId == null) { | ||||
// Removes from old parents children list | // Removes from old parents children list | ||||
LinkedList l = (LinkedList) children.get(itemId); | |||||
final LinkedList l = (LinkedList) children.get(itemId); | |||||
if (l != null) { | if (l != null) { | ||||
l.remove(itemId); | l.remove(itemId); | ||||
if (l.isEmpty()) { | if (l.isEmpty()) { | ||||
if (oldParentId == null) { | if (oldParentId == null) { | ||||
roots.remove(itemId); | roots.remove(itemId); | ||||
} else { | } else { | ||||
LinkedList l = (LinkedList) children.get(oldParentId); | |||||
final LinkedList l = (LinkedList) children.get(oldParentId); | |||||
if (l != null) { | if (l != null) { | ||||
l.remove(itemId); | l.remove(itemId); | ||||
if (l.isEmpty()) { | if (l.isEmpty()) { | ||||
* @see com.itmill.toolkit.data.Container#addItem() | * @see com.itmill.toolkit.data.Container#addItem() | ||||
*/ | */ | ||||
public Object addItem() { | public Object addItem() { | ||||
Object id = super.addItem(); | |||||
final Object id = super.addItem(); | |||||
if (id != null && !roots.contains(id)) { | if (id != null && !roots.contains(id)) { | ||||
roots.add(id); | roots.add(id); | ||||
} | } | ||||
* @see com.itmill.toolkit.data.Container#addItem(Object) | * @see com.itmill.toolkit.data.Container#addItem(Object) | ||||
*/ | */ | ||||
public Item addItem(Object itemId) { | public Item addItem(Object itemId) { | ||||
Item item = super.addItem(itemId); | |||||
final Item item = super.addItem(itemId); | |||||
if (item != null) { | if (item != null) { | ||||
roots.add(itemId); | roots.add(itemId); | ||||
} | } | ||||
* @see com.itmill.toolkit.data.Container#removeAllItems() | * @see com.itmill.toolkit.data.Container#removeAllItems() | ||||
*/ | */ | ||||
public boolean removeAllItems() { | public boolean removeAllItems() { | ||||
boolean success = super.removeAllItems(); | |||||
final boolean success = super.removeAllItems(); | |||||
if (success) { | if (success) { | ||||
roots.clear(); | roots.clear(); | ||||
* @see com.itmill.toolkit.data.Container#removeItem(Object) | * @see com.itmill.toolkit.data.Container#removeItem(Object) | ||||
*/ | */ | ||||
public boolean removeItem(Object itemId) { | public boolean removeItem(Object itemId) { | ||||
boolean success = super.removeItem(itemId); | |||||
final boolean success = super.removeItem(itemId); | |||||
if (success) { | if (success) { | ||||
if (isRoot(itemId)) { | if (isRoot(itemId)) { | ||||
roots.remove(itemId); | roots.remove(itemId); | ||||
} | } | ||||
children.remove(itemId); | children.remove(itemId); | ||||
Object p = parent.get(itemId); | |||||
final Object p = parent.get(itemId); | |||||
if (p != null) { | if (p != null) { | ||||
LinkedList c = (LinkedList) children.get(p); | |||||
final LinkedList c = (LinkedList) children.get(p); | |||||
if (c != null) { | if (c != null) { | ||||
c.remove(itemId); | c.remove(itemId); | ||||
} | } |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data.util; | package com.itmill.toolkit.data.util; | ||||
public IndexedContainer(Collection itemIds) { | public IndexedContainer(Collection itemIds) { | ||||
if (items != null) { | if (items != null) { | ||||
for (Iterator i = itemIds.iterator(); i.hasNext();) { | |||||
for (final Iterator i = itemIds.iterator(); i.hasNext();) { | |||||
this.addItem(i.next()); | this.addItem(i.next()); | ||||
} | } | ||||
} | } | ||||
// If default value is given, set it | // If default value is given, set it | ||||
if (defaultValue != null) { | if (defaultValue != null) { | ||||
for (Iterator i = itemIds.iterator(); i.hasNext();) { | |||||
for (final Iterator i = itemIds.iterator(); i.hasNext();) { | |||||
getItem(i.next()).getItemProperty(propertyId).setValue( | getItem(i.next()).getItemProperty(propertyId).setValue( | ||||
defaultValue); | defaultValue); | ||||
} | } | ||||
public Object addItem() { | public Object addItem() { | ||||
// Creates a new id | // Creates a new id | ||||
Object id = new Object(); | |||||
final Object id = new Object(); | |||||
// Adds the Item into container | // Adds the Item into container | ||||
addItem(id); | addItem(id); | ||||
// Adds the Item to container | // Adds the Item to container | ||||
itemIds.add(itemId); | itemIds.add(itemId); | ||||
items.put(itemId, new Hashtable()); | items.put(itemId, new Hashtable()); | ||||
Item item = getItem(itemId); | |||||
final Item item = getItem(itemId); | |||||
if (filteredItemIds != null) { | if (filteredItemIds != null) { | ||||
if (passesFilters(item)) { | if (passesFilters(item)) { | ||||
filteredItemIds.add(itemId); | filteredItemIds.add(itemId); | ||||
types.remove(propertyId); | types.remove(propertyId); | ||||
// If remove the Property from all Items | // If remove the Property from all Items | ||||
for (Iterator i = itemIds.iterator(); i.hasNext();) { | |||||
for (final Iterator i = itemIds.iterator(); i.hasNext();) { | |||||
((Hashtable) items.get(i.next())).remove(propertyId); | ((Hashtable) items.get(i.next())).remove(propertyId); | ||||
} | } | ||||
return filteredItemIds.iterator().next(); | return filteredItemIds.iterator().next(); | ||||
} | } | ||||
return itemIds.get(0); | return itemIds.get(0); | ||||
} catch (IndexOutOfBoundsException e) { | |||||
} catch (NoSuchElementException e) { | |||||
} catch (final IndexOutOfBoundsException e) { | |||||
} catch (final NoSuchElementException e) { | |||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public Object lastItemId() { | public Object lastItemId() { | ||||
try { | try { | ||||
if (filteredItemIds != null) { | if (filteredItemIds != null) { | ||||
Iterator i = filteredItemIds.iterator(); | |||||
final Iterator i = filteredItemIds.iterator(); | |||||
Object last = null; | Object last = null; | ||||
while (i.hasNext()) { | while (i.hasNext()) { | ||||
last = i.next(); | last = i.next(); | ||||
return last; | return last; | ||||
} | } | ||||
return itemIds.get(itemIds.size() - 1); | return itemIds.get(itemIds.size() - 1); | ||||
} catch (IndexOutOfBoundsException e) { | |||||
} catch (final IndexOutOfBoundsException e) { | |||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
if (!filteredItemIds.contains(itemId)) { | if (!filteredItemIds.contains(itemId)) { | ||||
return null; | return null; | ||||
} | } | ||||
Iterator i = filteredItemIds.iterator(); | |||||
final Iterator i = filteredItemIds.iterator(); | |||||
if (itemId == null) { | if (itemId == null) { | ||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
try { | try { | ||||
return itemIds.get(itemIds.indexOf(itemId) + 1); | return itemIds.get(itemIds.indexOf(itemId) + 1); | ||||
} catch (IndexOutOfBoundsException e) { | |||||
} catch (final IndexOutOfBoundsException e) { | |||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
if (!filteredItemIds.contains(itemId)) { | if (!filteredItemIds.contains(itemId)) { | ||||
return null; | return null; | ||||
} | } | ||||
Iterator i = filteredItemIds.iterator(); | |||||
final Iterator i = filteredItemIds.iterator(); | |||||
if (itemId == null) { | if (itemId == null) { | ||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
try { | try { | ||||
return itemIds.get(itemIds.indexOf(itemId) - 1); | return itemIds.get(itemIds.indexOf(itemId) - 1); | ||||
} catch (IndexOutOfBoundsException e) { | |||||
} catch (final IndexOutOfBoundsException e) { | |||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
public boolean isFirstId(Object itemId) { | public boolean isFirstId(Object itemId) { | ||||
if (filteredItemIds != null) { | if (filteredItemIds != null) { | ||||
try { | try { | ||||
Object first = filteredItemIds.iterator().next(); | |||||
final Object first = filteredItemIds.iterator().next(); | |||||
return (itemId != null && itemId.equals(first)); | return (itemId != null && itemId.equals(first)); | ||||
} catch (NoSuchElementException e) { | |||||
} catch (final NoSuchElementException e) { | |||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
if (filteredItemIds != null) { | if (filteredItemIds != null) { | ||||
try { | try { | ||||
Object last = null; | Object last = null; | ||||
for (Iterator i = filteredItemIds.iterator(); i.hasNext();) { | |||||
for (final Iterator i = filteredItemIds.iterator(); i.hasNext();) { | |||||
last = i.next(); | last = i.next(); | ||||
} | } | ||||
return (itemId != null && itemId.equals(last)); | return (itemId != null && itemId.equals(last)); | ||||
} catch (NoSuchElementException e) { | |||||
} catch (final NoSuchElementException e) { | |||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
int s = size(); | |||||
final int s = size(); | |||||
return (s >= 1 && itemIds.get(s - 1).equals(itemId)); | return (s >= 1 && itemIds.get(s - 1).equals(itemId)); | ||||
} | } | ||||
throw new IndexOutOfBoundsException(); | throw new IndexOutOfBoundsException(); | ||||
} | } | ||||
try { | try { | ||||
Iterator i = filteredItemIds.iterator(); | |||||
final Iterator i = filteredItemIds.iterator(); | |||||
while (index-- > 0) { | while (index-- > 0) { | ||||
i.next(); | i.next(); | ||||
} | } | ||||
return i.next(); | return i.next(); | ||||
} catch (NoSuchElementException e) { | |||||
} catch (final NoSuchElementException e) { | |||||
throw new IndexOutOfBoundsException(); | throw new IndexOutOfBoundsException(); | ||||
} | } | ||||
} | } | ||||
return -1; | return -1; | ||||
} | } | ||||
try { | try { | ||||
for (Iterator i = filteredItemIds.iterator(); itemId.equals(i | |||||
.next());) { | |||||
for (final Iterator i = filteredItemIds.iterator(); itemId | |||||
.equals(i.next());) { | |||||
index++; | index++; | ||||
} | } | ||||
return index; | return index; | ||||
} catch (NoSuchElementException e) { | |||||
} catch (final NoSuchElementException e) { | |||||
return -1; | return -1; | ||||
} | } | ||||
} | } | ||||
public Object addItemAt(int index) { | public Object addItemAt(int index) { | ||||
// Creates a new id | // Creates a new id | ||||
Object id = new Object(); | |||||
final Object id = new Object(); | |||||
// Adds the Item into container | // Adds the Item into container | ||||
addItemAt(index, id); | addItemAt(index, id); | ||||
// Sends event to listeners listening all value changes | // Sends event to listeners listening all value changes | ||||
if (propertyValueChangeListeners != null) { | if (propertyValueChangeListeners != null) { | ||||
Object[] l = propertyValueChangeListeners.toArray(); | |||||
Property.ValueChangeEvent event = new IndexedContainer.PropertyValueChangeEvent( | |||||
final Object[] l = propertyValueChangeListeners.toArray(); | |||||
final Property.ValueChangeEvent event = new IndexedContainer.PropertyValueChangeEvent( | |||||
source); | source); | ||||
for (int i = 0; i < l.length; i++) { | for (int i = 0; i < l.length; i++) { | ||||
((Property.ValueChangeListener) l[i]).valueChange(event); | ((Property.ValueChangeListener) l[i]).valueChange(event); | ||||
// Sends event to single property value change listeners | // Sends event to single property value change listeners | ||||
if (singlePropertyValueChangeListeners != null) { | if (singlePropertyValueChangeListeners != null) { | ||||
Hashtable propertySetToListenerListMap = (Hashtable) singlePropertyValueChangeListeners | |||||
final Hashtable propertySetToListenerListMap = (Hashtable) singlePropertyValueChangeListeners | |||||
.get(source.propertyId); | .get(source.propertyId); | ||||
if (propertySetToListenerListMap != null) { | if (propertySetToListenerListMap != null) { | ||||
LinkedList listenerList = (LinkedList) propertySetToListenerListMap | |||||
final LinkedList listenerList = (LinkedList) propertySetToListenerListMap | |||||
.get(source.itemId); | .get(source.itemId); | ||||
if (listenerList != null) { | if (listenerList != null) { | ||||
Property.ValueChangeEvent event = new IndexedContainer.PropertyValueChangeEvent( | |||||
final Property.ValueChangeEvent event = new IndexedContainer.PropertyValueChangeEvent( | |||||
source); | source); | ||||
for (Iterator i = listenerList.iterator(); i.hasNext();) { | |||||
for (final Iterator i = listenerList.iterator(); i | |||||
.hasNext();) { | |||||
((Property.ValueChangeListener) i.next()) | ((Property.ValueChangeListener) i.next()) | ||||
.valueChange(event); | .valueChange(event); | ||||
} | } | ||||
*/ | */ | ||||
private void fireContainerPropertySetChange() { | private void fireContainerPropertySetChange() { | ||||
if (propertySetChangeListeners != null) { | if (propertySetChangeListeners != null) { | ||||
Object[] l = propertySetChangeListeners.toArray(); | |||||
Container.PropertySetChangeEvent event = new IndexedContainer.PropertySetChangeEvent( | |||||
final Object[] l = propertySetChangeListeners.toArray(); | |||||
final Container.PropertySetChangeEvent event = new IndexedContainer.PropertySetChangeEvent( | |||||
this); | this); | ||||
for (int i = 0; i < l.length; i++) { | for (int i = 0; i < l.length; i++) { | ||||
((Container.PropertySetChangeListener) l[i]) | ((Container.PropertySetChangeListener) l[i]) | ||||
*/ | */ | ||||
private void fireContentsChange() { | private void fireContentsChange() { | ||||
if (itemSetChangeListeners != null) { | if (itemSetChangeListeners != null) { | ||||
Object[] l = itemSetChangeListeners.toArray(); | |||||
Container.ItemSetChangeEvent event = new IndexedContainer.ItemSetChangeEvent( | |||||
final Object[] l = itemSetChangeListeners.toArray(); | |||||
final Container.ItemSetChangeEvent event = new IndexedContainer.ItemSetChangeEvent( | |||||
this); | this); | ||||
for (int i = 0; i < l.length; i++) { | for (int i = 0; i < l.length; i++) { | ||||
((Container.ItemSetChangeListener) l[i]) | ((Container.ItemSetChangeListener) l[i]) | ||||
private void removeSinglePropertyChangeListener(Object propertyId, | private void removeSinglePropertyChangeListener(Object propertyId, | ||||
Object itemId, Property.ValueChangeListener listener) { | Object itemId, Property.ValueChangeListener listener) { | ||||
if (listener != null && singlePropertyValueChangeListeners != null) { | if (listener != null && singlePropertyValueChangeListeners != null) { | ||||
Hashtable propertySetToListenerListMap = (Hashtable) singlePropertyValueChangeListeners | |||||
final Hashtable propertySetToListenerListMap = (Hashtable) singlePropertyValueChangeListeners | |||||
.get(propertyId); | .get(propertyId); | ||||
if (propertySetToListenerListMap != null) { | if (propertySetToListenerListMap != null) { | ||||
LinkedList listenerList = (LinkedList) propertySetToListenerListMap | |||||
final LinkedList listenerList = (LinkedList) propertySetToListenerListMap | |||||
.get(itemId); | .get(itemId); | ||||
if (listenerList != null) { | if (listenerList != null) { | ||||
listenerList.remove(listener); | listenerList.remove(listener); | ||||
/** | /** | ||||
* Item ID in the host container for this Item. | * Item ID in the host container for this Item. | ||||
*/ | */ | ||||
private Object itemId; | |||||
private final Object itemId; | |||||
/** | /** | ||||
* Constructs a new ListItem instance and connects it to a host | * Constructs a new ListItem instance and connects it to a host | ||||
public String toString() { | public String toString() { | ||||
String retValue = ""; | String retValue = ""; | ||||
for (Iterator i = propertyIds.iterator(); i.hasNext();) { | |||||
Object propertyId = i.next(); | |||||
for (final Iterator i = propertyIds.iterator(); i.hasNext();) { | |||||
final Object propertyId = i.next(); | |||||
retValue += getItemProperty(propertyId).toString(); | retValue += getItemProperty(propertyId).toString(); | ||||
if (i.hasNext()) { | if (i.hasNext()) { | ||||
retValue += " "; | retValue += " "; | ||||
|| !obj.getClass().equals(IndexedContainerItem.class)) { | || !obj.getClass().equals(IndexedContainerItem.class)) { | ||||
return false; | return false; | ||||
} | } | ||||
IndexedContainerItem li = (IndexedContainerItem) obj; | |||||
final IndexedContainerItem li = (IndexedContainerItem) obj; | |||||
return getHost() == li.getHost() && itemId.equals(li.itemId); | return getHost() == li.getHost() && itemId.equals(li.itemId); | ||||
} | } | ||||
/** | /** | ||||
* ID of the Item, where the Property resides. | * ID of the Item, where the Property resides. | ||||
*/ | */ | ||||
private Object itemId; | |||||
private final Object itemId; | |||||
/** | /** | ||||
* Id of the Property. | * Id of the Property. | ||||
*/ | */ | ||||
private Object propertyId; | |||||
private final Object propertyId; | |||||
/** | /** | ||||
* Constructs a new ListProperty object and connect it to a ListItem and | * Constructs a new ListProperty object and connect it to a ListItem and | ||||
throws Property.ReadOnlyException, Property.ConversionException { | throws Property.ReadOnlyException, Property.ConversionException { | ||||
// Gets the Property set | // Gets the Property set | ||||
Hashtable propertySet = (Hashtable) items.get(itemId); | |||||
final Hashtable propertySet = (Hashtable) items.get(itemId); | |||||
// Support null values on all types | // Support null values on all types | ||||
if (newValue == null) { | if (newValue == null) { | ||||
try { | try { | ||||
// Gets the string constructor | // Gets the string constructor | ||||
Constructor constr = getType().getConstructor( | |||||
final Constructor constr = getType().getConstructor( | |||||
new Class[] { String.class }); | new Class[] { String.class }); | ||||
// Creates new object from the string | // Creates new object from the string | ||||
propertySet.put(propertyId, constr | propertySet.put(propertyId, constr | ||||
.newInstance(new Object[] { newValue.toString() })); | .newInstance(new Object[] { newValue.toString() })); | ||||
} catch (java.lang.Exception e) { | |||||
} catch (final java.lang.Exception e) { | |||||
throw new Property.ConversionException( | throw new Property.ConversionException( | ||||
"Conversion for value '" + newValue + "' of class " | "Conversion for value '" + newValue + "' of class " | ||||
+ newValue.getClass().getName() + " to " | + newValue.getClass().getName() + " to " | ||||
* the Property | * the Property | ||||
*/ | */ | ||||
public String toString() { | public String toString() { | ||||
Object value = getValue(); | |||||
final Object value = getValue(); | |||||
if (value == null) { | if (value == null) { | ||||
return null; | return null; | ||||
} | } | ||||
|| !obj.getClass().equals(IndexedContainerProperty.class)) { | || !obj.getClass().equals(IndexedContainerProperty.class)) { | ||||
return false; | return false; | ||||
} | } | ||||
IndexedContainerProperty lp = (IndexedContainerProperty) obj; | |||||
final IndexedContainerProperty lp = (IndexedContainerProperty) obj; | |||||
return lp.getHost() == getHost() | return lp.getHost() == getHost() | ||||
&& lp.propertyId.equals(propertyId) | && lp.propertyId.equals(propertyId) | ||||
&& lp.itemId.equals(itemId); | && lp.itemId.equals(itemId); | ||||
public synchronized void sort(Object[] propertyId, boolean[] ascending) { | public synchronized void sort(Object[] propertyId, boolean[] ascending) { | ||||
// Removes any non-sortable property ids | // Removes any non-sortable property ids | ||||
ArrayList ids = new ArrayList(); | |||||
ArrayList orders = new ArrayList(); | |||||
Collection sortable = getSortableContainerPropertyIds(); | |||||
final ArrayList ids = new ArrayList(); | |||||
final ArrayList orders = new ArrayList(); | |||||
final Collection sortable = getSortableContainerPropertyIds(); | |||||
for (int i = 0; i < propertyId.length; i++) { | for (int i = 0; i < propertyId.length; i++) { | ||||
if (sortable.contains(propertyId[i])) { | if (sortable.contains(propertyId[i])) { | ||||
ids.add(propertyId[i]); | ids.add(propertyId[i]); | ||||
*/ | */ | ||||
public Collection getSortableContainerPropertyIds() { | public Collection getSortableContainerPropertyIds() { | ||||
LinkedList list = new LinkedList(); | |||||
for (Iterator i = propertyIds.iterator(); i.hasNext();) { | |||||
Object id = i.next(); | |||||
Class type = getType(id); | |||||
final LinkedList list = new LinkedList(); | |||||
for (final Iterator i = propertyIds.iterator(); i.hasNext();) { | |||||
final Object id = i.next(); | |||||
final Class type = getType(id); | |||||
if (type != null && Comparable.class.isAssignableFrom(type)) { | if (type != null && Comparable.class.isAssignableFrom(type)) { | ||||
list.add(id); | list.add(id); | ||||
} | } | ||||
for (int i = 0; i < sortPropertyId.length; i++) { | for (int i = 0; i < sortPropertyId.length; i++) { | ||||
// Get the compared properties | // Get the compared properties | ||||
Property pp1 = getContainerProperty(o1, sortPropertyId[i]); | |||||
Property pp2 = getContainerProperty(o2, sortPropertyId[i]); | |||||
final Property pp1 = getContainerProperty(o1, sortPropertyId[i]); | |||||
final Property pp2 = getContainerProperty(o2, sortPropertyId[i]); | |||||
// Get the compared values | // Get the compared values | ||||
Object p1 = pp1 == null ? null : pp1.getValue(); | |||||
Object p2 = pp2 == null ? null : pp2.getValue(); | |||||
final Object p1 = pp1 == null ? null : pp1.getValue(); | |||||
final Object p2 = pp2 == null ? null : pp2.getValue(); | |||||
// Result of the comparison | // Result of the comparison | ||||
int r = 0; | int r = 0; | ||||
public Object clone() throws CloneNotSupportedException { | public Object clone() throws CloneNotSupportedException { | ||||
// Creates the clone | // Creates the clone | ||||
IndexedContainer nc = new IndexedContainer(); | |||||
final IndexedContainer nc = new IndexedContainer(); | |||||
// Clone the shallow properties | // Clone the shallow properties | ||||
nc.itemIds = itemIds != null ? (ArrayList) itemIds.clone() : null; | nc.itemIds = itemIds != null ? (ArrayList) itemIds.clone() : null; | ||||
nc.items = null; | nc.items = null; | ||||
} else { | } else { | ||||
nc.items = new Hashtable(); | nc.items = new Hashtable(); | ||||
for (Iterator i = items.keySet().iterator(); i.hasNext();) { | |||||
Object id = i.next(); | |||||
Hashtable it = (Hashtable) items.get(id); | |||||
for (final Iterator i = items.keySet().iterator(); i.hasNext();) { | |||||
final Object id = i.next(); | |||||
final Hashtable it = (Hashtable) items.get(id); | |||||
nc.items.put(id, it.clone()); | nc.items.put(id, it.clone()); | ||||
} | } | ||||
} | } | ||||
if (!(obj instanceof IndexedContainer)) { | if (!(obj instanceof IndexedContainer)) { | ||||
return false; | return false; | ||||
} | } | ||||
IndexedContainer o = (IndexedContainer) obj; | |||||
final IndexedContainer o = (IndexedContainer) obj; | |||||
// Checks the properties one by one | // Checks the properties one by one | ||||
if (itemIds != o.itemIds && o.itemIds != null | if (itemIds != o.itemIds && o.itemIds != null | ||||
if (!(obj instanceof Filter)) { | if (!(obj instanceof Filter)) { | ||||
return false; | return false; | ||||
} | } | ||||
Filter o = (Filter) obj; | |||||
final Filter o = (Filter) obj; | |||||
// Checks the properties one by one | // Checks the properties one by one | ||||
if (propertyId != o.propertyId && o.propertyId != null | if (propertyId != o.propertyId && o.propertyId != null | ||||
if (filters == null || propertyId == null) { | if (filters == null || propertyId == null) { | ||||
return; | return; | ||||
} | } | ||||
for (Iterator i = filters.iterator(); i.hasNext();) { | |||||
Filter f = (Filter) i.next(); | |||||
for (final Iterator i = filters.iterator(); i.hasNext();) { | |||||
final Filter f = (Filter) i.next(); | |||||
if (propertyId.equals(f.propertyId)) { | if (propertyId.equals(f.propertyId)) { | ||||
i.remove(); | i.remove(); | ||||
} | } | ||||
} | } | ||||
// Filter | // Filter | ||||
for (Iterator i = itemIds.iterator(); i.hasNext();) { | |||||
Object id = i.next(); | |||||
for (final Iterator i = itemIds.iterator(); i.hasNext();) { | |||||
final Object id = i.next(); | |||||
if (passesFilters(new IndexedContainerItem(id))) { | if (passesFilters(new IndexedContainerItem(id))) { | ||||
filteredItemIds.add(id); | filteredItemIds.add(id); | ||||
} | } | ||||
if (item == null) { | if (item == null) { | ||||
return false; | return false; | ||||
} | } | ||||
for (Iterator i = filters.iterator(); i.hasNext();) { | |||||
Filter f = (Filter) i.next(); | |||||
String s1 = f.ignoreCase ? f.filterString.toLowerCase() | |||||
for (final Iterator i = filters.iterator(); i.hasNext();) { | |||||
final Filter f = (Filter) i.next(); | |||||
final String s1 = f.ignoreCase ? f.filterString.toLowerCase() | |||||
: f.filterString; | : f.filterString; | ||||
Property p = item.getItemProperty(f.propertyId); | |||||
final Property p = item.getItemProperty(f.propertyId); | |||||
if (p == null || p.toString() == null) { | if (p == null || p.toString() == null) { | ||||
return false; | return false; | ||||
} | } | ||||
String s2 = f.ignoreCase ? p.toString().toLowerCase() : p | |||||
final String s2 = f.ignoreCase ? p.toString().toLowerCase() : p | |||||
.toString(); | .toString(); | ||||
if (f.onlyMatchPrefix) { | if (f.onlyMatchPrefix) { | ||||
if (s2.indexOf(s1) != 0) { | if (s2.indexOf(s1) != 0) { |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data.util; | package com.itmill.toolkit.data.util; | ||||
/** | /** | ||||
* The object that includes the property the MethodProperty is bound to. | * The object that includes the property the MethodProperty is bound to. | ||||
*/ | */ | ||||
private Object instance; | |||||
private final Object instance; | |||||
/** | /** | ||||
* Argument arrays for the getter and setter methods. | * Argument arrays for the getter and setter methods. | ||||
*/ | */ | ||||
public MethodProperty(Object instance, String beanPropertyName) { | public MethodProperty(Object instance, String beanPropertyName) { | ||||
Class beanClass = instance.getClass(); | |||||
final Class beanClass = instance.getClass(); | |||||
// Assure that the first letter is upper cased (it is a common | // Assure that the first letter is upper cased (it is a common | ||||
// mistake to write firstName, not FirstName). | // mistake to write firstName, not FirstName). | ||||
if (Character.isLowerCase(beanPropertyName.charAt(0))) { | if (Character.isLowerCase(beanPropertyName.charAt(0))) { | ||||
char[] buf = beanPropertyName.toCharArray(); | |||||
final char[] buf = beanPropertyName.toCharArray(); | |||||
buf[0] = Character.toUpperCase(buf[0]); | buf[0] = Character.toUpperCase(buf[0]); | ||||
beanPropertyName = new String(buf); | beanPropertyName = new String(buf); | ||||
} | } | ||||
try { | try { | ||||
getMethod = beanClass.getMethod("get" + beanPropertyName, | getMethod = beanClass.getMethod("get" + beanPropertyName, | ||||
new Class[] {}); | new Class[] {}); | ||||
} catch (java.lang.NoSuchMethodException ignored) { | |||||
} catch (final java.lang.NoSuchMethodException ignored) { | |||||
try { | try { | ||||
getMethod = beanClass.getMethod("is" + beanPropertyName, | getMethod = beanClass.getMethod("is" + beanPropertyName, | ||||
new Class[] {}); | new Class[] {}); | ||||
} catch (java.lang.NoSuchMethodException ignoredAsWell) { | |||||
} catch (final java.lang.NoSuchMethodException ignoredAsWell) { | |||||
try { | try { | ||||
getMethod = beanClass.getMethod("are" + beanPropertyName, | getMethod = beanClass.getMethod("are" + beanPropertyName, | ||||
new Class[] {}); | new Class[] {}); | ||||
} catch (java.lang.NoSuchMethodException e) { | |||||
} catch (final java.lang.NoSuchMethodException e) { | |||||
throw new MethodProperty.MethodException("Bean property " | throw new MethodProperty.MethodException("Bean property " | ||||
+ beanPropertyName + " can not be found"); | + beanPropertyName + " can not be found"); | ||||
} | } | ||||
try { | try { | ||||
setMethod = beanClass.getMethod("set" + beanPropertyName, | setMethod = beanClass.getMethod("set" + beanPropertyName, | ||||
new Class[] { type }); | new Class[] { type }); | ||||
} catch (java.lang.NoSuchMethodException skipped) { | |||||
} catch (final java.lang.NoSuchMethodException skipped) { | |||||
} | } | ||||
// Gets the return type from get method | // Gets the return type from get method | ||||
this.type = type; | this.type = type; | ||||
// Find set and get -methods | // Find set and get -methods | ||||
Method[] m = instance.getClass().getMethods(); | |||||
final Method[] m = instance.getClass().getMethods(); | |||||
// Finds get method | // Finds get method | ||||
boolean found = false; | boolean found = false; | ||||
} | } | ||||
// Tests the parameter types | // Tests the parameter types | ||||
Class[] c = m[i].getParameterTypes(); | |||||
final Class[] c = m[i].getParameterTypes(); | |||||
if (c.length != getArgs.length) { | if (c.length != getArgs.length) { | ||||
// not the right amount of parameters, try next method | // not the right amount of parameters, try next method | ||||
} | } | ||||
// Checks parameter compatibility | // Checks parameter compatibility | ||||
Class[] c = m[i].getParameterTypes(); | |||||
final Class[] c = m[i].getParameterTypes(); | |||||
if (c.length != setArgs.length) { | if (c.length != setArgs.length) { | ||||
// not the right amount of parameters, try next method | // not the right amount of parameters, try next method | ||||
public Object getValue() { | public Object getValue() { | ||||
try { | try { | ||||
return getMethod.invoke(instance, getArgs); | return getMethod.invoke(instance, getArgs); | ||||
} catch (Throwable e) { | |||||
} catch (final Throwable e) { | |||||
throw new MethodProperty.MethodException(e); | throw new MethodProperty.MethodException(e); | ||||
} | } | ||||
} | } | ||||
* @return String representation of the value stored in the Property | * @return String representation of the value stored in the Property | ||||
*/ | */ | ||||
public String toString() { | public String toString() { | ||||
Object value = getValue(); | |||||
final Object value = getValue(); | |||||
if (value == null) { | if (value == null) { | ||||
return null; | return null; | ||||
} | } | ||||
try { | try { | ||||
// Gets the string constructor | // Gets the string constructor | ||||
Constructor constr = getType().getConstructor( | |||||
final Constructor constr = getType().getConstructor( | |||||
new Class[] { String.class }); | new Class[] { String.class }); | ||||
value = constr | value = constr | ||||
.newInstance(new Object[] { newValue.toString() }); | .newInstance(new Object[] { newValue.toString() }); | ||||
} catch (java.lang.Exception e) { | |||||
} catch (final java.lang.Exception e) { | |||||
throw new Property.ConversionException(e); | throw new Property.ConversionException(e); | ||||
} | } | ||||
} else { | } else { | ||||
// Sets the value to argument array | // Sets the value to argument array | ||||
Object[] args = new Object[setArgs.length]; | |||||
final Object[] args = new Object[setArgs.length]; | |||||
for (int i = 0; i < setArgs.length; i++) { | for (int i = 0; i < setArgs.length; i++) { | ||||
args[i] = (i == setArgumentIndex) ? value : setArgs[i]; | args[i] = (i == setArgumentIndex) ? value : setArgs[i]; | ||||
} | } | ||||
setMethod.invoke(instance, args); | setMethod.invoke(instance, args); | ||||
} | } | ||||
} catch (InvocationTargetException e) { | |||||
Throwable targetException = e.getTargetException(); | |||||
} catch (final InvocationTargetException e) { | |||||
final Throwable targetException = e.getTargetException(); | |||||
throw new MethodProperty.MethodException(targetException); | throw new MethodProperty.MethodException(targetException); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
throw new MethodProperty.MethodException(e); | throw new MethodProperty.MethodException(e); | ||||
} | } | ||||
} | } | ||||
* the new read-only status of the Property. | * the new read-only status of the Property. | ||||
*/ | */ | ||||
public void setReadOnly(boolean newStatus) { | public void setReadOnly(boolean newStatus) { | ||||
boolean prevStatus = readOnly; | |||||
final boolean prevStatus = readOnly; | |||||
if (newStatus) { | if (newStatus) { | ||||
readOnly = true; | readOnly = true; | ||||
} else { | } else { | ||||
*/ | */ | ||||
private void fireReadOnlyStatusChange() { | private void fireReadOnlyStatusChange() { | ||||
if (readOnlyStatusChangeListeners != null) { | if (readOnlyStatusChangeListeners != null) { | ||||
Object[] l = readOnlyStatusChangeListeners.toArray(); | |||||
Property.ReadOnlyStatusChangeEvent event = new MethodProperty.ReadOnlyStatusChangeEvent( | |||||
final Object[] l = readOnlyStatusChangeListeners.toArray(); | |||||
final Property.ReadOnlyStatusChangeEvent event = new MethodProperty.ReadOnlyStatusChangeEvent( | |||||
this); | this); | ||||
for (int i = 0; i < l.length; i++) { | for (int i = 0; i < l.length; i++) { | ||||
((Property.ReadOnlyStatusChangeListener) l[i]) | ((Property.ReadOnlyStatusChangeListener) l[i]) |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data.util; | package com.itmill.toolkit.data.util; | ||||
/** | /** | ||||
* Data type of the Property's value. | * Data type of the Property's value. | ||||
*/ | */ | ||||
private Class type; | |||||
private final Class type; | |||||
/** | /** | ||||
* Internal list of registered value change listeners. | * Internal list of registered value change listeners. | ||||
* ObjectProperty | * ObjectProperty | ||||
*/ | */ | ||||
public String toString() { | public String toString() { | ||||
Object value = getValue(); | |||||
final Object value = getValue(); | |||||
if (value != null) { | if (value != null) { | ||||
return value.toString(); | return value.toString(); | ||||
} else { | } else { | ||||
try { | try { | ||||
// Gets the string constructor | // Gets the string constructor | ||||
Constructor constr = getType().getConstructor( | |||||
final Constructor constr = getType().getConstructor( | |||||
new Class[] { String.class }); | new Class[] { String.class }); | ||||
// Creates new object from the string | // Creates new object from the string | ||||
value = constr | value = constr | ||||
.newInstance(new Object[] { newValue.toString() }); | .newInstance(new Object[] { newValue.toString() }); | ||||
} catch (java.lang.Exception e) { | |||||
} catch (final java.lang.Exception e) { | |||||
throw new Property.ConversionException(e); | throw new Property.ConversionException(e); | ||||
} | } | ||||
} | } | ||||
*/ | */ | ||||
private void fireValueChange() { | private void fireValueChange() { | ||||
if (valueChangeListeners != null) { | if (valueChangeListeners != null) { | ||||
Object[] l = valueChangeListeners.toArray(); | |||||
Property.ValueChangeEvent event = new ObjectProperty.ValueChangeEvent( | |||||
final Object[] l = valueChangeListeners.toArray(); | |||||
final Property.ValueChangeEvent event = new ObjectProperty.ValueChangeEvent( | |||||
this); | this); | ||||
for (int i = 0; i < l.length; i++) { | for (int i = 0; i < l.length; i++) { | ||||
((Property.ValueChangeListener) l[i]).valueChange(event); | ((Property.ValueChangeListener) l[i]).valueChange(event); | ||||
*/ | */ | ||||
private void fireReadOnlyStatusChange() { | private void fireReadOnlyStatusChange() { | ||||
if (readOnlyStatusChangeListeners != null) { | if (readOnlyStatusChangeListeners != null) { | ||||
Object[] l = readOnlyStatusChangeListeners.toArray(); | |||||
Property.ReadOnlyStatusChangeEvent event = new ObjectProperty.ReadOnlyStatusChangeEvent( | |||||
final Object[] l = readOnlyStatusChangeListeners.toArray(); | |||||
final Property.ReadOnlyStatusChangeEvent event = new ObjectProperty.ReadOnlyStatusChangeEvent( | |||||
this); | this); | ||||
for (int i = 0; i < l.length; i++) { | for (int i = 0; i < l.length; i++) { | ||||
((Property.ReadOnlyStatusChangeListener) l[i]) | ((Property.ReadOnlyStatusChangeListener) l[i]) |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data.util; | package com.itmill.toolkit.data.util; | ||||
public String toString() { | public String toString() { | ||||
String retValue = ""; | String retValue = ""; | ||||
for (Iterator i = getItemPropertyIds().iterator(); i.hasNext();) { | |||||
Object propertyId = i.next(); | |||||
for (final Iterator i = getItemPropertyIds().iterator(); i.hasNext();) { | |||||
final Object propertyId = i.next(); | |||||
retValue += getItemProperty(propertyId).toString(); | retValue += getItemProperty(propertyId).toString(); | ||||
if (i.hasNext()) { | if (i.hasNext()) { | ||||
retValue += " "; | retValue += " "; | ||||
*/ | */ | ||||
private void fireItemPropertySetChange() { | private void fireItemPropertySetChange() { | ||||
if (propertySetChangeListeners != null) { | if (propertySetChangeListeners != null) { | ||||
Object[] l = propertySetChangeListeners.toArray(); | |||||
Item.PropertySetChangeEvent event = new PropertysetItem.PropertySetChangeEvent( | |||||
final Object[] l = propertySetChangeListeners.toArray(); | |||||
final Item.PropertySetChangeEvent event = new PropertysetItem.PropertySetChangeEvent( | |||||
this); | this); | ||||
for (int i = 0; i < l.length; i++) { | for (int i = 0; i < l.length; i++) { | ||||
((Item.PropertySetChangeListener) l[i]) | ((Item.PropertySetChangeListener) l[i]) | ||||
*/ | */ | ||||
public Object clone() throws CloneNotSupportedException { | public Object clone() throws CloneNotSupportedException { | ||||
PropertysetItem npsi = new PropertysetItem(); | |||||
final PropertysetItem npsi = new PropertysetItem(); | |||||
npsi.list = list != null ? (LinkedList) list.clone() : null; | npsi.list = list != null ? (LinkedList) list.clone() : null; | ||||
npsi.propertySetChangeListeners = propertySetChangeListeners != null ? (LinkedList) propertySetChangeListeners | npsi.propertySetChangeListeners = propertySetChangeListeners != null ? (LinkedList) propertySetChangeListeners | ||||
return false; | return false; | ||||
} | } | ||||
PropertysetItem other = (PropertysetItem) obj; | |||||
final PropertysetItem other = (PropertysetItem) obj; | |||||
if (other.list != list) { | if (other.list != list) { | ||||
if (other.list == null) { | if (other.list == null) { |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data.util; | package com.itmill.toolkit.data.util; | ||||
private int resultSetConcurrency = DEFAULT_RESULTSET_CONCURRENCY; | private int resultSetConcurrency = DEFAULT_RESULTSET_CONCURRENCY; | ||||
private String queryStatement; | |||||
private final String queryStatement; | |||||
private Connection connection; | |||||
private final Connection connection; | |||||
private ResultSet result; | private ResultSet result; | ||||
private Collection propertyIds; | private Collection propertyIds; | ||||
private HashMap propertyTypes = new HashMap(); | |||||
private final HashMap propertyTypes = new HashMap(); | |||||
private int size = -1; | private int size = -1; | ||||
refresh(); | refresh(); | ||||
ResultSetMetaData metadata; | ResultSetMetaData metadata; | ||||
metadata = result.getMetaData(); | metadata = result.getMetaData(); | ||||
int count = metadata.getColumnCount(); | |||||
ArrayList list = new ArrayList(count); | |||||
final int count = metadata.getColumnCount(); | |||||
final ArrayList list = new ArrayList(count); | |||||
for (int i = 1; i <= count; i++) { | for (int i = 1; i <= count; i++) { | ||||
String columnName = metadata.getColumnName(i); | |||||
final String columnName = metadata.getColumnName(i); | |||||
list.add(columnName); | list.add(columnName); | ||||
Property p = getContainerProperty(new Integer(1), columnName); | |||||
final Property p = getContainerProperty(new Integer(1), columnName); | |||||
propertyTypes.put(columnName, p == null ? Object.class : p | propertyTypes.put(columnName, p == null ? Object.class : p | ||||
.getType()); | .getType()); | ||||
} | } | ||||
* @return collection of Item IDs | * @return collection of Item IDs | ||||
*/ | */ | ||||
public Collection getItemIds() { | public Collection getItemIds() { | ||||
Collection c = new ArrayList(size); | |||||
final Collection c = new ArrayList(size); | |||||
for (int i = 1; i <= size; i++) { | for (int i = 1; i <= size; i++) { | ||||
c.add(new Integer(i)); | c.add(new Integer(i)); | ||||
} | } | ||||
try { | try { | ||||
result.absolute(((Integer) itemId).intValue()); | result.absolute(((Integer) itemId).intValue()); | ||||
value = result.getObject((String) propertyId); | value = result.getObject((String) propertyId); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
return null; | return null; | ||||
} | } | ||||
if (!(id instanceof Integer)) { | if (!(id instanceof Integer)) { | ||||
return false; | return false; | ||||
} | } | ||||
int i = ((Integer) id).intValue(); | |||||
final int i = ((Integer) id).intValue(); | |||||
if (i < 1) { | if (i < 1) { | ||||
return false; | return false; | ||||
} | } | ||||
if (size < 1 || !(id instanceof Integer)) { | if (size < 1 || !(id instanceof Integer)) { | ||||
return null; | return null; | ||||
} | } | ||||
int i = ((Integer) id).intValue(); | |||||
final int i = ((Integer) id).intValue(); | |||||
if (i >= size) { | if (i >= size) { | ||||
return null; | return null; | ||||
} | } | ||||
if (size < 1 || !(id instanceof Integer)) { | if (size < 1 || !(id instanceof Integer)) { | ||||
return null; | return null; | ||||
} | } | ||||
int i = ((Integer) id).intValue(); | |||||
final int i = ((Integer) id).intValue(); | |||||
if (i <= 1) { | if (i <= 1) { | ||||
return null; | return null; | ||||
} | } | ||||
public void finalize() { | public void finalize() { | ||||
try { | try { | ||||
close(); | close(); | ||||
} catch (SQLException ignored) { | |||||
} catch (final SQLException ignored) { | |||||
} | } | ||||
} | } | ||||
if (size < 1 || !(id instanceof Integer)) { | if (size < 1 || !(id instanceof Integer)) { | ||||
return -1; | return -1; | ||||
} | } | ||||
int i = ((Integer) id).intValue(); | |||||
final int i = ((Integer) id).intValue(); | |||||
if (i >= size || i < 1) { | if (i >= size || i < 1) { | ||||
return -1; | return -1; | ||||
} | } |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data.validator; | package com.itmill.toolkit.data.validator; | ||||
/** | /** | ||||
* List of contained validators. | * List of contained validators. | ||||
*/ | */ | ||||
private LinkedList validators = new LinkedList(); | |||||
private final LinkedList validators = new LinkedList(); | |||||
/** | /** | ||||
* Error message. | * Error message. | ||||
public void validate(Object value) throws Validator.InvalidValueException { | public void validate(Object value) throws Validator.InvalidValueException { | ||||
switch (mode) { | switch (mode) { | ||||
case MODE_AND: | case MODE_AND: | ||||
for (Iterator i = validators.iterator(); i.hasNext();) { | |||||
for (final Iterator i = validators.iterator(); i.hasNext();) { | |||||
((Validator) i.next()).validate(value); | ((Validator) i.next()).validate(value); | ||||
} | } | ||||
return; | return; | ||||
case MODE_OR: | case MODE_OR: | ||||
Validator.InvalidValueException first = null; | Validator.InvalidValueException first = null; | ||||
for (Iterator i = validators.iterator(); i.hasNext();) { | |||||
for (final Iterator i = validators.iterator(); i.hasNext();) { | |||||
try { | try { | ||||
((Validator) i.next()).validate(value); | ((Validator) i.next()).validate(value); | ||||
return; | return; | ||||
} catch (Validator.InvalidValueException e) { | |||||
} catch (final Validator.InvalidValueException e) { | |||||
if (first == null) { | if (first == null) { | ||||
first = e; | first = e; | ||||
} | } | ||||
if (first == null) { | if (first == null) { | ||||
return; | return; | ||||
} | } | ||||
String em = getErrorMessage(); | |||||
final String em = getErrorMessage(); | |||||
if (em != null) { | if (em != null) { | ||||
throw new Validator.InvalidValueException(em); | throw new Validator.InvalidValueException(em); | ||||
} else { | } else { | ||||
public boolean isValid(Object value) { | public boolean isValid(Object value) { | ||||
switch (mode) { | switch (mode) { | ||||
case MODE_AND: | case MODE_AND: | ||||
for (Iterator i = validators.iterator(); i.hasNext();) { | |||||
Validator v = (Validator) i.next(); | |||||
for (final Iterator i = validators.iterator(); i.hasNext();) { | |||||
final Validator v = (Validator) i.next(); | |||||
if (!v.isValid(value)) { | if (!v.isValid(value)) { | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
case MODE_OR: | case MODE_OR: | ||||
for (Iterator i = validators.iterator(); i.hasNext();) { | |||||
Validator v = (Validator) i.next(); | |||||
for (final Iterator i = validators.iterator(); i.hasNext();) { | |||||
final Validator v = (Validator) i.next(); | |||||
if (v.isValid(value)) { | if (v.isValid(value)) { | ||||
return true; | return true; | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
HashSet found = new HashSet(); | |||||
for (Iterator i = validators.iterator(); i.hasNext();) { | |||||
Validator v = (Validator) i.next(); | |||||
final HashSet found = new HashSet(); | |||||
for (final Iterator i = validators.iterator(); i.hasNext();) { | |||||
final Validator v = (Validator) i.next(); | |||||
if (validatorType.isAssignableFrom(v.getClass())) { | if (validatorType.isAssignableFrom(v.getClass())) { | ||||
found.add(v); | found.add(v); | ||||
} | } | ||||
if (v instanceof CompositeValidator | if (v instanceof CompositeValidator | ||||
&& ((CompositeValidator) v).getMode() == MODE_AND) { | && ((CompositeValidator) v).getMode() == MODE_AND) { | ||||
Collection c = ((CompositeValidator) v) | |||||
final Collection c = ((CompositeValidator) v) | |||||
.getSubValidators(validatorType); | .getSubValidators(validatorType); | ||||
if (c != null) { | if (c != null) { | ||||
found.addAll(c); | found.addAll(c); |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data.validator; | package com.itmill.toolkit.data.validator; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.data.validator; | package com.itmill.toolkit.data.validator; | ||||
if (value == null && !allowNull) { | if (value == null && !allowNull) { | ||||
throw new Validator.InvalidValueException(errorMessage); | throw new Validator.InvalidValueException(errorMessage); | ||||
} | } | ||||
String s = value.toString(); | |||||
final String s = value.toString(); | |||||
if (s == null && !allowNull) { | if (s == null && !allowNull) { | ||||
throw new Validator.InvalidValueException(errorMessage); | throw new Validator.InvalidValueException(errorMessage); | ||||
} | } | ||||
int len = s.length(); | |||||
final int len = s.length(); | |||||
if ((minLength >= 0 && len < minLength) | if ((minLength >= 0 && len < minLength) | ||||
|| (maxLength >= 0 && len > maxLength)) { | || (maxLength >= 0 && len > maxLength)) { | ||||
throw new Validator.InvalidValueException(errorMessage); | throw new Validator.InvalidValueException(errorMessage); | ||||
if (value == null && !allowNull) { | if (value == null && !allowNull) { | ||||
return true; | return true; | ||||
} | } | ||||
String s = value.toString(); | |||||
final String s = value.toString(); | |||||
if (s == null && !allowNull) { | if (s == null && !allowNull) { | ||||
return true; | return true; | ||||
} | } | ||||
int len = s.length(); | |||||
final int len = s.length(); | |||||
if ((minLength >= 0 && len < minLength) | if ((minLength >= 0 && len < minLength) | ||||
|| (maxLength >= 0 && len > maxLength)) { | || (maxLength >= 0 && len > maxLength)) { | ||||
return false; | return false; |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import com.itmill.toolkit.data.Property.ValueChangeEvent; | import com.itmill.toolkit.data.Property.ValueChangeEvent; | ||||
public void init() { | public void init() { | ||||
// Create and set main window | // Create and set main window | ||||
Window browser = new Window("IT Mill Browser"); | |||||
final Window browser = new Window("IT Mill Browser"); | |||||
setMainWindow(browser); | setMainWindow(browser); | ||||
// Use the expand layout to allow one component to use as much | // Use the expand layout to allow one component to use as much | ||||
// space as | // space as | ||||
// possible. | // possible. | ||||
ExpandLayout exl = new ExpandLayout(); | |||||
final ExpandLayout exl = new ExpandLayout(); | |||||
browser.setLayout(exl); | browser.setLayout(exl); | ||||
exl.setSizeFull(); | exl.setSizeFull(); | ||||
// create the address combobox | // create the address combobox | ||||
Select select = new Select(); | |||||
final Select select = new Select(); | |||||
// allow input | // allow input | ||||
select.setNewItemsAllowed(true); | select.setNewItemsAllowed(true); | ||||
// no empty selection | // no empty selection | ||||
} | } | ||||
public void valueChange(ValueChangeEvent event) { | public void valueChange(ValueChangeEvent event) { | ||||
String url = (String) event.getProperty().getValue(); | |||||
final String url = (String) event.getProperty().getValue(); | |||||
if (url != null) { | if (url != null) { | ||||
// the selected url has changed, let's go there | // the selected url has changed, let's go there | ||||
emb.setSource(new ExternalResource(url)); | emb.setSource(new ExternalResource(url)); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import com.itmill.toolkit.Application; | import com.itmill.toolkit.Application; | ||||
public void init() { | public void init() { | ||||
Window w = new Window("Buffered UI components demo"); | |||||
final Window w = new Window("Buffered UI components demo"); | |||||
addWindow(w); | addWindow(w); | ||||
// Create property | // Create property | ||||
Float floatValue = new Float(1.0f); | |||||
final Float floatValue = new Float(1.0f); | |||||
property = new ObjectProperty(floatValue); | property = new ObjectProperty(floatValue); | ||||
// Textfield | // Textfield | ||||
w.addComponent(text); | w.addComponent(text); | ||||
// Property state | // Property state | ||||
Label propertyState = new Label(property); | |||||
final Label propertyState = new Label(property); | |||||
propertyState.setCaption("Property (data source) state"); | propertyState.setCaption("Property (data source) state"); | ||||
w.addComponent(propertyState); | w.addComponent(propertyState); | ||||
// Button state | // Button state | ||||
Label textState = new Label(text); | |||||
final Label textState = new Label(text); | |||||
textState.setCaption("TextField state"); | textState.setCaption("TextField state"); | ||||
w.addComponent(textState); | w.addComponent(textState); | ||||
w.addComponent(new Button("increase property value", | w.addComponent(new Button("increase property value", | ||||
new Button.ClickListener() { | new Button.ClickListener() { | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
Float currentValue = (Float) property.getValue(); | |||||
final Float currentValue = (Float) property.getValue(); | |||||
property.setValue(new Float( | property.setValue(new Float( | ||||
currentValue.floatValue() + 1.0)); | currentValue.floatValue() + 1.0)); | ||||
} | } | ||||
// (easier debugging when you dont have to restart the server to | // (easier debugging when you dont have to restart the server to | ||||
// make | // make | ||||
// code changes) | // code changes) | ||||
Button restart = new Button("restart", this, "close"); | |||||
final Button restart = new Button("restart", this, "close"); | |||||
restart.addStyleName(Button.STYLE_LINK); | restart.addStyleName(Button.STYLE_LINK); | ||||
w.addComponent(restart); | w.addComponent(restart); | ||||
} | } |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import com.itmill.toolkit.terminal.PaintException; | import com.itmill.toolkit.terminal.PaintException; | ||||
public void init() { | public void init() { | ||||
Window main = new Window("Client-side caching example"); | |||||
final Window main = new Window("Client-side caching example"); | |||||
setMainWindow(main); | setMainWindow(main); | ||||
setTheme("example"); | setTheme("example"); | ||||
TabSheet ts = new TabSheet(); | |||||
final TabSheet ts = new TabSheet(); | |||||
main.addComponent(ts); | main.addComponent(ts); | ||||
Layout layout = new OrderedLayout(); | Layout layout = new OrderedLayout(); | ||||
public void paintContent(PaintTarget target) throws PaintException { | public void paintContent(PaintTarget target) throws PaintException { | ||||
try { | try { | ||||
Thread.sleep(3000); | Thread.sleep(3000); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
// IGNORED | // IGNORED | ||||
} | } | ||||
super.paintContent(target); | super.paintContent(target); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import com.itmill.toolkit.ui.Button; | import com.itmill.toolkit.ui.Button; | ||||
public void init() { | public void init() { | ||||
// Create a new layout for the components used by the calculator | // Create a new layout for the components used by the calculator | ||||
GridLayout layout = new GridLayout(4, 5); | |||||
final GridLayout layout = new GridLayout(4, 5); | |||||
// Create a new label component for displaying the result | // Create a new label component for displaying the result | ||||
display = new Label(Double.toString(current)); | display = new Label(Double.toString(current)); | ||||
// Create the buttons and place them in the grid | // Create the buttons and place them in the grid | ||||
for (int i = 0; i < captions.length; i++) { | for (int i = 0; i < captions.length; i++) { | ||||
Button button = new Button(captions[i], this); | |||||
final Button button = new Button(captions[i], this); | |||||
layout.addComponent(button); | layout.addComponent(button); | ||||
} | } | ||||
current = current * 10 | current = current * 10 | ||||
+ Double.parseDouble(event.getButton().getCaption()); | + Double.parseDouble(event.getButton().getCaption()); | ||||
display.setValue(Double.toString(current)); | display.setValue(Double.toString(current)); | ||||
} catch (java.lang.NumberFormatException e) { | |||||
} catch (final java.lang.NumberFormatException e) { | |||||
// Operation button pressed | // Operation button pressed | ||||
if (operation.equals("+")) { | if (operation.equals("+")) { |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import com.itmill.toolkit.ui.Button; | import com.itmill.toolkit.ui.Button; | ||||
private CustomLayout mainLayout = null; | private CustomLayout mainLayout = null; | ||||
private Panel bodyPanel = new Panel(); | |||||
private final Panel bodyPanel = new Panel(); | |||||
private TextField username = new TextField("Username"); | |||||
private final TextField username = new TextField("Username"); | |||||
private TextField loginPwd = new TextField("Password"); | |||||
private final TextField loginPwd = new TextField("Password"); | |||||
private Button loginButton = new Button("Login", this, "loginClicked"); | |||||
private final Button loginButton = new Button("Login", this, "loginClicked"); | |||||
private Tree menu = new Tree(); | |||||
private final Tree menu = new Tree(); | |||||
/** | /** | ||||
* Initialize Application. Demo components are added to main window. | * Initialize Application. Demo components are added to main window. | ||||
*/ | */ | ||||
public void init() { | public void init() { | ||||
Window mainWindow = new Window("CustomLayout demo"); | |||||
final Window mainWindow = new Window("CustomLayout demo"); | |||||
setMainWindow(mainWindow); | setMainWindow(mainWindow); | ||||
// set the application to use example -theme | // set the application to use example -theme | ||||
// Create custom layout, themes/example/layout/mainLayout.html | // Create custom layout, themes/example/layout/mainLayout.html | ||||
mainLayout = new CustomLayout("mainLayout"); | mainLayout = new CustomLayout("mainLayout"); | ||||
// wrap custom layout inside a panel | // wrap custom layout inside a panel | ||||
Panel customLayoutPanel = new Panel( | |||||
final Panel customLayoutPanel = new Panel( | |||||
"Panel containing custom layout (mainLayout.html)"); | "Panel containing custom layout (mainLayout.html)"); | ||||
customLayoutPanel.addComponent(mainLayout); | customLayoutPanel.addComponent(mainLayout); | ||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import com.itmill.toolkit.ui.OrderedLayout; | import com.itmill.toolkit.ui.OrderedLayout; | ||||
* - Create new window for the application - Give the window a visible | * - Create new window for the application - Give the window a visible | ||||
* title - Set the window to be the main window of the application | * title - Set the window to be the main window of the application | ||||
*/ | */ | ||||
Window main = new Window("Filter select demo"); | |||||
final Window main = new Window("Filter select demo"); | |||||
setMainWindow(main); | setMainWindow(main); | ||||
// default filterin (Starts with) | // default filterin (Starts with) | ||||
Select s1 = new Select(); | |||||
final Select s1 = new Select(); | |||||
for (int i = 0; i < 105; i++) { | for (int i = 0; i < 105; i++) { | ||||
s1 | s1 | ||||
.addItem(firstnames[(int) (Math.random() * (firstnames.length - 1))] | .addItem(firstnames[(int) (Math.random() * (firstnames.length - 1))] | ||||
s1.setImmediate(true); | s1.setImmediate(true); | ||||
// contains filter | // contains filter | ||||
Select s2 = new Select(); | |||||
final Select s2 = new Select(); | |||||
for (int i = 0; i < 500; i++) { | for (int i = 0; i < 500; i++) { | ||||
s2 | s2 | ||||
.addItem(firstnames[(int) (Math.random() * (firstnames.length - 1))] | .addItem(firstnames[(int) (Math.random() * (firstnames.length - 1))] | ||||
s2.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS); | s2.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS); | ||||
// Add selects to UI using ordered layout and panels | // Add selects to UI using ordered layout and panels | ||||
OrderedLayout orderedLayout = new OrderedLayout( | |||||
final OrderedLayout orderedLayout = new OrderedLayout( | |||||
OrderedLayout.ORIENTATION_HORIZONTAL); | OrderedLayout.ORIENTATION_HORIZONTAL); | ||||
Panel panel1 = new Panel("Select with default filter"); | |||||
Panel panel2 = new Panel("Select with contains filter"); | |||||
final Panel panel1 = new Panel("Select with default filter"); | |||||
final Panel panel2 = new Panel("Select with contains filter"); | |||||
panel1.addComponent(s1); | panel1.addComponent(s1); | ||||
panel2.addComponent(s2); | panel2.addComponent(s2); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import com.itmill.toolkit.ui.Label; | import com.itmill.toolkit.ui.Label; | ||||
* - Create new window for the application - Give the window a visible | * - Create new window for the application - Give the window a visible | ||||
* title - Set the window to be the main window of the application | * title - Set the window to be the main window of the application | ||||
*/ | */ | ||||
Window main = new Window("Hello window"); | |||||
final Window main = new Window("Hello window"); | |||||
setMainWindow(main); | setMainWindow(main); | ||||
/* | /* |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import java.util.Date; | import java.util.Date; | ||||
private final Action ACTION_RESTART = new ShortcutAction("Restart ", | private final Action ACTION_RESTART = new ShortcutAction("Restart ", | ||||
ShortcutAction.KeyCode.ESCAPE, null); | ShortcutAction.KeyCode.ESCAPE, null); | ||||
private Action[] actions = new Action[] { ACTION_A, ACTION_Z, ACTION_X, | |||||
ACTION_RESTART }; | |||||
private final Action[] actions = new Action[] { ACTION_A, ACTION_Z, | |||||
ACTION_X, ACTION_RESTART }; | |||||
private TextField f; | private TextField f; | ||||
public void init() { | public void init() { | ||||
Window w = new Window("Keyboard shortcuts demo"); | |||||
ExpandLayout main = new ExpandLayout(); | |||||
final Window w = new Window("Keyboard shortcuts demo"); | |||||
final ExpandLayout main = new ExpandLayout(); | |||||
main.setMargin(true); | main.setMargin(true); | ||||
main.setSpacing(true); | main.setSpacing(true); | ||||
setMainWindow(w); | setMainWindow(w); | ||||
w.setLayout(main); | w.setLayout(main); | ||||
Panel p = new Panel("Test application for shortcut actions"); | |||||
final Panel p = new Panel("Test application for shortcut actions"); | |||||
p.addComponent(instructions); | p.addComponent(instructions); | ||||
OrderedLayout buttons = new OrderedLayout( | |||||
final OrderedLayout buttons = new OrderedLayout( | |||||
OrderedLayout.ORIENTATION_HORIZONTAL); | OrderedLayout.ORIENTATION_HORIZONTAL); | ||||
// Restart button | // Restart button | ||||
Button close = new Button("restart", this, "close"); | |||||
Button a = new Button("Button A", this, "actionAHandler"); | |||||
Button z = new Button("Button Z", this, "actionZHandler"); | |||||
Button x = new Button("Button X", this, "actionXHandler"); | |||||
final Button close = new Button("restart", this, "close"); | |||||
final Button a = new Button("Button A", this, "actionAHandler"); | |||||
final Button z = new Button("Button Z", this, "actionZHandler"); | |||||
final Button x = new Button("Button X", this, "actionXHandler"); | |||||
f = new TextField(); | f = new TextField(); | ||||
buttons.addComponent(close); | buttons.addComponent(close); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import com.itmill.toolkit.terminal.ClassResource; | import com.itmill.toolkit.terminal.ClassResource; | ||||
* Initialize Application. Demo components are added to main window. | * Initialize Application. Demo components are added to main window. | ||||
*/ | */ | ||||
public void init() { | public void init() { | ||||
Window mainWindow = new Window("Layout demo"); | |||||
final Window mainWindow = new Window("Layout demo"); | |||||
setMainWindow(mainWindow); | setMainWindow(mainWindow); | ||||
// | // | ||||
// Create horizontal ordered layout | // Create horizontal ordered layout | ||||
// | // | ||||
OrderedLayout layoutA = new OrderedLayout( | |||||
final OrderedLayout layoutA = new OrderedLayout( | |||||
OrderedLayout.ORIENTATION_HORIZONTAL); | OrderedLayout.ORIENTATION_HORIZONTAL); | ||||
// Add 4 panels | // Add 4 panels | ||||
fillLayout(layoutA, 4); | fillLayout(layoutA, 4); | ||||
// | // | ||||
// Create vertical ordered layout | // Create vertical ordered layout | ||||
// | // | ||||
OrderedLayout layoutB = new OrderedLayout( | |||||
final OrderedLayout layoutB = new OrderedLayout( | |||||
OrderedLayout.ORIENTATION_VERTICAL); | OrderedLayout.ORIENTATION_VERTICAL); | ||||
// Add 4 panels | // Add 4 panels | ||||
fillLayout(layoutB, 4); | fillLayout(layoutB, 4); | ||||
// | // | ||||
// Create grid layout | // Create grid layout | ||||
// | // | ||||
GridLayout layoutG = new GridLayout(4, 4); | |||||
final GridLayout layoutG = new GridLayout(4, 4); | |||||
// Add 16 panels components | // Add 16 panels components | ||||
fillLayout(layoutG, 16); | fillLayout(layoutG, 16); | ||||
// | // | ||||
// Create grid layout | // Create grid layout | ||||
// | // | ||||
GridLayout layoutG2 = new GridLayout(4, 4); | |||||
final GridLayout layoutG2 = new GridLayout(4, 4); | |||||
// Add 4 panels with absolute coordinates (diagonally) | // Add 4 panels with absolute coordinates (diagonally) | ||||
layoutG2.addComponent(getExampleComponent("x=0, y=0"), 0, 0); | layoutG2.addComponent(getExampleComponent("x=0, y=0"), 0, 0); | ||||
layoutG2.addComponent(getExampleComponent("x=1, y=1"), 1, 1); | layoutG2.addComponent(getExampleComponent("x=1, y=1"), 1, 1); | ||||
// | // | ||||
// Create TabSheet | // Create TabSheet | ||||
// | // | ||||
TabSheet tabsheet = new TabSheet(); | |||||
final TabSheet tabsheet = new TabSheet(); | |||||
tabsheet | tabsheet | ||||
.setCaption("Tabsheet, above layouts are added to this component"); | .setCaption("Tabsheet, above layouts are added to this component"); | ||||
tabsheet.addTab(layoutA, "Horizontal ordered layout", null); | tabsheet.addTab(layoutA, "Horizontal ordered layout", null); | ||||
} | } | ||||
private Component getExamplePicture(String caption) { | private Component getExamplePicture(String caption) { | ||||
ClassResource cr = new ClassResource("features/m-bullet-blue.gif", this); | |||||
Embedded em = new Embedded("Embedded " + caption, cr); | |||||
final ClassResource cr = new ClassResource( | |||||
"features/m-bullet-blue.gif", this); | |||||
final Embedded em = new Embedded("Embedded " + caption, cr); | |||||
em.setWidth(170); | em.setWidth(170); | ||||
return em; | return em; | ||||
} | } | ||||
private Component getExampleComponent(String caption) { | private Component getExampleComponent(String caption) { | ||||
Panel panel = new Panel(); | |||||
final Panel panel = new Panel(); | |||||
panel.setCaption("Panel component " + caption); | panel.setCaption("Panel component " + caption); | ||||
panel | panel | ||||
.addComponent(new Label( | .addComponent(new Label( |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import com.itmill.toolkit.ui.Button; | import com.itmill.toolkit.ui.Button; | ||||
public void init() { | public void init() { | ||||
// Create main window | // Create main window | ||||
Window main = new Window("ModalWindow demo"); | |||||
final Window main = new Window("ModalWindow demo"); | |||||
setMainWindow(main); | setMainWindow(main); | ||||
main.addComponent(new Label("ModalWindow demo")); | main.addComponent(new Label("ModalWindow demo")); | ||||
// Main window textfield | // Main window textfield | ||||
TextField f = new TextField(); | |||||
final TextField f = new TextField(); | |||||
f.setTabIndex(1); | f.setTabIndex(1); | ||||
main.addComponent(f); | main.addComponent(f); | ||||
// Main window button | // Main window button | ||||
Button b = new Button("Test Button in main window"); | |||||
final Button b = new Button("Test Button in main window"); | |||||
b.addListener(this); | b.addListener(this); | ||||
b.setTabIndex(2); | b.setTabIndex(2); | ||||
main.addComponent(b); | main.addComponent(b); | ||||
"You have to close this window before accessing others.")); | "You have to close this window before accessing others.")); | ||||
// Textfield for modal window | // Textfield for modal window | ||||
TextField f = new TextField(); | |||||
final TextField f = new TextField(); | |||||
f.setTabIndex(4); | f.setTabIndex(4); | ||||
test.addComponent(f); | test.addComponent(f); | ||||
f.focus(); | f.focus(); | ||||
// Modal window button | // Modal window button | ||||
Button b = new Button("Test Button in modal window"); | |||||
final Button b = new Button("Test Button in modal window"); | |||||
b.setTabIndex(5); | b.setTabIndex(5); | ||||
b.addListener(this); | b.addListener(this); | ||||
test.addComponent(b); | test.addComponent(b); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import java.net.MalformedURLException; | import java.net.MalformedURLException; | ||||
w.setWidth(100); | w.setWidth(100); | ||||
w.setHeight(400); | w.setHeight(400); | ||||
Button closebutton = new Button("Close " | |||||
final Button closebutton = new Button("Close " | |||||
+ w.getCaption(), new Button.ClickListener() { | + w.getCaption(), new Button.ClickListener() { | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
main.removeWindow(w); | main.removeWindow(w); | ||||
.currentTimeMillis() | .currentTimeMillis() | ||||
+ "/")), | + "/")), | ||||
null); | null); | ||||
} catch (MalformedURLException e) { | |||||
} catch (final MalformedURLException e) { | |||||
} | } | ||||
} | } | ||||
})); | })); | ||||
public Window getWindow(String name) { | public Window getWindow(String name) { | ||||
Window w = super.getWindow(name); | |||||
final Window w = super.getWindow(name); | |||||
if (w != null) { | if (w != null) { | ||||
return w; | return w; | ||||
} | } | ||||
if (name != null && name.startsWith("mainwin-")) { | if (name != null && name.startsWith("mainwin-")) { | ||||
String postfix = name.substring("mainwin-".length()); | |||||
final String postfix = name.substring("mainwin-".length()); | |||||
final Window ww = new Window("Window: " + postfix); | final Window ww = new Window("Window: " + postfix); | ||||
ww.setName(name); | ww.setName(name); | ||||
ww.addComponent(new Label( | ww.addComponent(new Label( |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import com.itmill.toolkit.data.Item; | import com.itmill.toolkit.data.Item; | ||||
public void init() { | public void init() { | ||||
// Create new window for the application and give the window a visible. | // Create new window for the application and give the window a visible. | ||||
Window main = new Window("Notification demo"); | |||||
final Window main = new Window("Notification demo"); | |||||
// set as main window | // set as main window | ||||
setMainWindow(main); | setMainWindow(main); | ||||
main.addComponent(message); // add to layout | main.addComponent(message); // add to layout | ||||
// Button to show the notification | // Button to show the notification | ||||
Button b = new Button("Show notification", new ClickListener() { | |||||
final Button b = new Button("Show notification", new ClickListener() { | |||||
// this is an inline ClickListener | // this is an inline ClickListener | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
// show the notification | // show the notification |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import java.net.URL; | import java.net.URL; | ||||
import com.itmill.toolkit.terminal.DownloadStream; | import com.itmill.toolkit.terminal.DownloadStream; | ||||
import com.itmill.toolkit.terminal.ExternalResource; | import com.itmill.toolkit.terminal.ExternalResource; | ||||
import com.itmill.toolkit.terminal.ParameterHandler; | import com.itmill.toolkit.terminal.ParameterHandler; | ||||
import com.itmill.toolkit.terminal.Sizeable; | |||||
import com.itmill.toolkit.terminal.URIHandler; | import com.itmill.toolkit.terminal.URIHandler; | ||||
import com.itmill.toolkit.ui.ExpandLayout; | import com.itmill.toolkit.ui.ExpandLayout; | ||||
import com.itmill.toolkit.ui.Label; | import com.itmill.toolkit.ui.Label; | ||||
public class Parameters extends com.itmill.toolkit.Application implements | public class Parameters extends com.itmill.toolkit.Application implements | ||||
URIHandler, ParameterHandler { | URIHandler, ParameterHandler { | ||||
private Label context = new Label(); | |||||
private final Label context = new Label(); | |||||
private Label relative = new Label(); | |||||
private final Label relative = new Label(); | |||||
private Table params = new Table(); | |||||
private final Table params = new Table(); | |||||
public void init() { | public void init() { | ||||
Window main = new Window("Parameters demo"); | |||||
final Window main = new Window("Parameters demo"); | |||||
setMainWindow(main); | setMainWindow(main); | ||||
// This class acts both as URI handler and parameter handler | // This class acts both as URI handler and parameter handler | ||||
main.addURIHandler(this); | main.addURIHandler(this); | ||||
main.addParameterHandler(this); | main.addParameterHandler(this); | ||||
ExpandLayout layout = new ExpandLayout(); | |||||
Label info = new Label("To test URI and Parameter Handlers, " | |||||
final ExpandLayout layout = new ExpandLayout(); | |||||
final Label info = new Label("To test URI and Parameter Handlers, " | |||||
+ "add get parameters to URL. For example try examples below: "); | + "add get parameters to URL. For example try examples below: "); | ||||
info.setCaption("Usage info"); | info.setCaption("Usage info"); | ||||
layout.addComponent(info); | layout.addComponent(info); | ||||
try { | try { | ||||
URL u1 = new URL(getURL(), "test/uri?test=1&test=2"); | |||||
URL u2 = new URL(getURL(), "foo/bar?mary=john&count=3"); | |||||
final URL u1 = new URL(getURL(), "test/uri?test=1&test=2"); | |||||
final URL u2 = new URL(getURL(), "foo/bar?mary=john&count=3"); | |||||
layout.addComponent(new Link(u1.toString(), | layout.addComponent(new Link(u1.toString(), | ||||
new ExternalResource(u1))); | new ExternalResource(u1))); | ||||
layout.addComponent(new Label("Or this: ")); | layout.addComponent(new Label("Or this: ")); | ||||
layout.addComponent(new Link(u2.toString(), | layout.addComponent(new Link(u2.toString(), | ||||
new ExternalResource(u2))); | new ExternalResource(u2))); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
System.out.println("Couldn't get hostname for this machine: " | System.out.println("Couldn't get hostname for this machine: " | ||||
+ e.toString()); | + e.toString()); | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
// URI | // URI | ||||
Panel panel1 = new Panel("URI Handler"); | |||||
final Panel panel1 = new Panel("URI Handler"); | |||||
context.setCaption("Last URI handler context"); | context.setCaption("Last URI handler context"); | ||||
panel1.addComponent(context); | panel1.addComponent(context); | ||||
relative.setCaption("Last relative URI"); | relative.setCaption("Last relative URI"); | ||||
params.addContainerProperty("Key", String.class, ""); | params.addContainerProperty("Key", String.class, ""); | ||||
params.addContainerProperty("Value", String.class, ""); | params.addContainerProperty("Value", String.class, ""); | ||||
Panel panel2 = new Panel("Parameter Handler"); | |||||
final Panel panel2 = new Panel("Parameter Handler"); | |||||
params.setHeight(100); | params.setHeight(100); | ||||
params.setHeightUnits(Table.UNITS_PERCENTAGE); | |||||
params.setHeightUnits(Sizeable.UNITS_PERCENTAGE); | |||||
panel2.setHeight(100); | panel2.setHeight(100); | ||||
panel2.setHeightUnits(Panel.UNITS_PERCENTAGE); | |||||
panel2.setHeightUnits(Sizeable.UNITS_PERCENTAGE); | |||||
panel2.setLayout(new ExpandLayout()); | panel2.setLayout(new ExpandLayout()); | ||||
panel2.getLayout().setMargin(true); | panel2.getLayout().setMargin(true); | ||||
*/ | */ | ||||
public void handleParameters(Map parameters) { | public void handleParameters(Map parameters) { | ||||
params.removeAllItems(); | params.removeAllItems(); | ||||
for (Iterator i = parameters.keySet().iterator(); i.hasNext();) { | |||||
String name = (String) i.next(); | |||||
String[] values = (String[]) parameters.get(name); | |||||
for (final Iterator i = parameters.keySet().iterator(); i.hasNext();) { | |||||
final String name = (String) i.next(); | |||||
final String[] values = (String[]) parameters.get(name); | |||||
String v = ""; | String v = ""; | ||||
for (int j = 0; j < values.length; j++) { | for (int j = 0; j < values.length; j++) { | ||||
if (v.length() > 0) { | if (v.length() > 0) { |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import java.sql.SQLException; | import java.sql.SQLException; | ||||
+ " dynamically loaded rows from example SQL table"; | + " dynamically loaded rows from example SQL table"; | ||||
// Table component where SQL rows are attached (using QueryContainer) | // Table component where SQL rows are attached (using QueryContainer) | ||||
private Table table = new Table(); | |||||
private final Table table = new Table(); | |||||
private Label tableLastAction = new Label("No action selected for table."); | |||||
private final Label tableLastAction = new Label( | |||||
"No action selected for table."); | |||||
// Select component where SQL rows are attached (using QueryContainer) | // Select component where SQL rows are attached (using QueryContainer) | ||||
private Select select = new Select(); | |||||
private final Select select = new Select(); | |||||
// Tree component that uses select as datasource | // Tree component that uses select as datasource | ||||
private Tree tree = new Tree(); | |||||
private final Tree tree = new Tree(); | |||||
private Label treeLastAction = new Label("No action selected for tree."); | |||||
private final Label treeLastAction = new Label( | |||||
"No action selected for tree."); | |||||
// Database provided with sample data | // Database provided with sample data | ||||
private SampleDatabase sampleDatabase; | private SampleDatabase sampleDatabase; | ||||
// Example Actions for table | // Example Actions for table | ||||
private Action ACTION1 = new Action("Upload"); | |||||
private final Action ACTION1 = new Action("Upload"); | |||||
private Action ACTION2 = new Action("Download"); | |||||
private final Action ACTION2 = new Action("Download"); | |||||
private Action ACTION3 = new Action("Show history"); | |||||
private final Action ACTION3 = new Action("Show history"); | |||||
private Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 }; | |||||
private final Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 }; | |||||
/** | /** | ||||
* Initialize Application. Demo components are added to main window. | * Initialize Application. Demo components are added to main window. | ||||
*/ | */ | ||||
public void init() { | public void init() { | ||||
Window main = new Window("QueryContainer demo"); | |||||
final Window main = new Window("QueryContainer demo"); | |||||
setMainWindow(main); | setMainWindow(main); | ||||
// Main window contains heading, table, select and tree | // Main window contains heading, table, select and tree | ||||
// populate Toolkit table component with test SQL table rows | // populate Toolkit table component with test SQL table rows | ||||
try { | try { | ||||
QueryContainer qc = new QueryContainer("SELECT * FROM employee", | |||||
sampleDatabase.getConnection()); | |||||
final QueryContainer qc = new QueryContainer( | |||||
"SELECT * FROM employee", sampleDatabase.getConnection()); | |||||
table.setContainerDataSource(qc); | table.setContainerDataSource(qc); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
// define which columns should be visible on Table component | // define which columns should be visible on Table component | ||||
// populate Toolkit select component with test SQL table rows | // populate Toolkit select component with test SQL table rows | ||||
try { | try { | ||||
QueryContainer qc = new QueryContainer( | |||||
final QueryContainer qc = new QueryContainer( | |||||
"SELECT DISTINCT UNIT FROM employee", sampleDatabase | "SELECT DISTINCT UNIT FROM employee", sampleDatabase | ||||
.getConnection()); | .getConnection()); | ||||
select.setContainerDataSource(qc); | select.setContainerDataSource(qc); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
} | } |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import java.sql.SQLException; | import java.sql.SQLException; | ||||
* Initialize Application. Demo components are added to main window. | * Initialize Application. Demo components are added to main window. | ||||
*/ | */ | ||||
public void init() { | public void init() { | ||||
Window main = new Window("Select demo"); | |||||
final Window main = new Window("Select demo"); | |||||
setMainWindow(main); | setMainWindow(main); | ||||
// Main window contains heading, table, select and tree | // Main window contains heading, table, select and tree | ||||
Panel panel = new Panel("Select demo (a.k.a Google Suggests)"); | |||||
final Panel panel = new Panel("Select demo (a.k.a Google Suggests)"); | |||||
panel.addComponent(lazySelect); | panel.addComponent(lazySelect); | ||||
panel.addComponent(new Label("<hr />", Label.CONTENT_XHTML)); | panel.addComponent(new Label("<hr />", Label.CONTENT_XHTML)); | ||||
panel.addComponent(select); | panel.addComponent(select); | ||||
select.setItemCaptionPropertyId("WORKER"); | select.setItemCaptionPropertyId("WORKER"); | ||||
// populate Toolkit select component with test SQL table rows | // populate Toolkit select component with test SQL table rows | ||||
try { | try { | ||||
QueryContainer qc = new QueryContainer( | |||||
final QueryContainer qc = new QueryContainer( | |||||
"SELECT ID, UNIT||', '||LASTNAME||' '||FIRSTNAME" | "SELECT ID, UNIT||', '||LASTNAME||' '||FIRSTNAME" | ||||
+ " AS WORKER FROM employee ORDER BY WORKER", | + " AS WORKER FROM employee ORDER BY WORKER", | ||||
sampleDatabase.getConnection()); | sampleDatabase.getConnection()); | ||||
select.setContainerDataSource(qc); | select.setContainerDataSource(qc); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import java.sql.SQLException; | import java.sql.SQLException; | ||||
+ " dynamically loaded rows from example SQL table"; | + " dynamically loaded rows from example SQL table"; | ||||
// Table component where SQL rows are attached (using QueryContainer) | // Table component where SQL rows are attached (using QueryContainer) | ||||
private Table table = new Table(); | |||||
private final Table table = new Table(); | |||||
// Label which displays last performed action against table row | // Label which displays last performed action against table row | ||||
private Label tableLastAction = new Label("No action selected for table."); | |||||
private final Label tableLastAction = new Label( | |||||
"No action selected for table."); | |||||
// Database provided with sample data | // Database provided with sample data | ||||
private SampleDatabase sampleDatabase; | private SampleDatabase sampleDatabase; | ||||
// Example Actions for table | // Example Actions for table | ||||
private Action ACTION1 = new Action("Upload"); | |||||
private final Action ACTION1 = new Action("Upload"); | |||||
private Action ACTION2 = new Action("Download"); | |||||
private final Action ACTION2 = new Action("Download"); | |||||
private Action ACTION3 = new Action("Show history"); | |||||
private final Action ACTION3 = new Action("Show history"); | |||||
private Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 }; | |||||
private final Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 }; | |||||
// Button which is used to disable or enable table | // Button which is used to disable or enable table | ||||
// note: when button click event occurs, tableEnabler() method is called | // note: when button click event occurs, tableEnabler() method is called | ||||
private Button tableEnabler = new Button("Disable table", this, | |||||
private final Button tableEnabler = new Button("Disable table", this, | |||||
"tableEnabler"); | "tableEnabler"); | ||||
// Button which is used to hide or show table | // Button which is used to hide or show table | ||||
// note: when button click event occurs, tableVisibility() method is called | // note: when button click event occurs, tableVisibility() method is called | ||||
private Button tableVisibility = new Button("Hide table", this, | |||||
private final Button tableVisibility = new Button("Hide table", this, | |||||
"tableVisibility"); | "tableVisibility"); | ||||
// Button which is used to hide or show table | // Button which is used to hide or show table | ||||
// note: when button click event occurs, tableVisibility() method is called | // note: when button click event occurs, tableVisibility() method is called | ||||
private Button tableCaption = new Button("Hide caption", this, | |||||
private final Button tableCaption = new Button("Hide caption", this, | |||||
"tableCaption"); | "tableCaption"); | ||||
/** | /** | ||||
* Initialize Application. Demo components are added to main window. | * Initialize Application. Demo components are added to main window. | ||||
*/ | */ | ||||
public void init() { | public void init() { | ||||
Window main = new Window("Table demo"); | |||||
final Window main = new Window("Table demo"); | |||||
setMainWindow(main); | setMainWindow(main); | ||||
// create demo database | // create demo database | ||||
+ "<b>Rows are loaded from the server as they are needed.<br />" | + "<b>Rows are loaded from the server as they are needed.<br />" | ||||
+ "Try scrolling the table to see it in action.</b><br />" | + "Try scrolling the table to see it in action.</b><br />" | ||||
+ ACTION_DESCRIPTION, Label.CONTENT_XHTML)); | + ACTION_DESCRIPTION, Label.CONTENT_XHTML)); | ||||
OrderedLayout layout = new OrderedLayout( | |||||
final OrderedLayout layout = new OrderedLayout( | |||||
OrderedLayout.ORIENTATION_HORIZONTAL); | OrderedLayout.ORIENTATION_HORIZONTAL); | ||||
// TODO: disabled until #655 fixed | // TODO: disabled until #655 fixed | ||||
// layout.addComponent(tableVisibility); | // layout.addComponent(tableVisibility); | ||||
// populate Toolkit table component with test SQL table rows | // populate Toolkit table component with test SQL table rows | ||||
try { | try { | ||||
QueryContainer qc = new QueryContainer("SELECT * FROM employee", | |||||
sampleDatabase.getConnection()); | |||||
final QueryContainer qc = new QueryContainer( | |||||
"SELECT * FROM employee", sampleDatabase.getConnection()); | |||||
table.setContainerDataSource(qc); | table.setContainerDataSource(qc); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
// define which columns should be visible on Table component | // define which columns should be visible on Table component |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import java.io.File; | import java.io.File; | ||||
Tree.ExpandListener { | Tree.ExpandListener { | ||||
// Filesystem explorer panel and it's components | // Filesystem explorer panel and it's components | ||||
private Panel explorerPanel = new Panel("Filesystem explorer"); | |||||
private final Panel explorerPanel = new Panel("Filesystem explorer"); | |||||
private Tree tree = new Tree(); | |||||
private final Tree tree = new Tree(); | |||||
public void init() { | public void init() { | ||||
Window main = new Window("Tree filesystem demo"); | |||||
final Window main = new Window("Tree filesystem demo"); | |||||
setMainWindow(main); | setMainWindow(main); | ||||
// Main window contains heading and panel | // Main window contains heading and panel | ||||
tree.addListener(this); | tree.addListener(this); | ||||
// Get sample directory | // Get sample directory | ||||
File sampleDir = SampleDirectory.getDirectory(this); | |||||
final File sampleDir = SampleDirectory.getDirectory(this); | |||||
// populate tree's root node with example directory | // populate tree's root node with example directory | ||||
if (sampleDir != null) { | if (sampleDir != null) { | ||||
populateNode(sampleDir.getAbsolutePath(), null); | populateNode(sampleDir.getAbsolutePath(), null); | ||||
* and directories. | * and directories. | ||||
*/ | */ | ||||
public void nodeExpand(ExpandEvent event) { | public void nodeExpand(ExpandEvent event) { | ||||
Item i = tree.getItem(event.getItemId()); | |||||
final Item i = tree.getItem(event.getItemId()); | |||||
if (!tree.hasChildren(i)) { | if (!tree.hasChildren(i)) { | ||||
// populate tree's node which was expanded | // populate tree's node which was expanded | ||||
populateNode(event.getItemId().toString(), event.getItemId()); | populateNode(event.getItemId().toString(), event.getItemId()); | ||||
* node | * node | ||||
*/ | */ | ||||
private void populateNode(String file, Object parent) { | private void populateNode(String file, Object parent) { | ||||
File subdir = new File(file); | |||||
File[] files = subdir.listFiles(); | |||||
final File subdir = new File(file); | |||||
final File[] files = subdir.listFiles(); | |||||
for (int x = 0; x < files.length; x++) { | for (int x = 0; x < files.length; x++) { | ||||
try { | try { | ||||
// add new item (String) to tree | // add new item (String) to tree | ||||
String path = files[x].getCanonicalPath().toString(); | |||||
final String path = files[x].getCanonicalPath().toString(); | |||||
tree.addItem(path); | tree.addItem(path); | ||||
// set parent if this item has one | // set parent if this item has one | ||||
if (parent != null) { | if (parent != null) { | ||||
// no, childrens therefore do not exists | // no, childrens therefore do not exists | ||||
tree.setChildrenAllowed(path, false); | tree.setChildrenAllowed(path, false); | ||||
} | } | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
} | } |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import java.io.File; | import java.io.File; | ||||
import com.itmill.toolkit.data.util.FilesystemContainer; | import com.itmill.toolkit.data.util.FilesystemContainer; | ||||
import com.itmill.toolkit.data.util.FilesystemContainer.FileItem; | import com.itmill.toolkit.data.util.FilesystemContainer.FileItem; | ||||
import com.itmill.toolkit.demo.util.SampleDirectory; | import com.itmill.toolkit.demo.util.SampleDirectory; | ||||
import com.itmill.toolkit.terminal.Sizeable; | |||||
import com.itmill.toolkit.ui.ExpandLayout; | import com.itmill.toolkit.ui.ExpandLayout; | ||||
import com.itmill.toolkit.ui.Field; | import com.itmill.toolkit.ui.Field; | ||||
import com.itmill.toolkit.ui.Label; | import com.itmill.toolkit.ui.Label; | ||||
implements Listener { | implements Listener { | ||||
// Filesystem explorer panel and it's components | // Filesystem explorer panel and it's components | ||||
private Panel explorerPanel = new Panel("Filesystem explorer"); | |||||
private final Panel explorerPanel = new Panel("Filesystem explorer"); | |||||
private Tree filesystem = new Tree(); | |||||
private final Tree filesystem = new Tree(); | |||||
// File properties panel and it's components | // File properties panel and it's components | ||||
private Panel propertyPanel = new Panel("File properties"); | |||||
private final Panel propertyPanel = new Panel("File properties"); | |||||
private Label fileProperties = new Label(); | |||||
private final Label fileProperties = new Label(); | |||||
public void init() { | public void init() { | ||||
Window w = new Window("Tree FilesystemContainer demo"); | |||||
final Window w = new Window("Tree FilesystemContainer demo"); | |||||
setMainWindow(w); | setMainWindow(w); | ||||
ExpandLayout main = new ExpandLayout(); | |||||
final ExpandLayout main = new ExpandLayout(); | |||||
w.setLayout(main); | w.setLayout(main); | ||||
main.setMargin(true); | main.setMargin(true); | ||||
main.setSpacing(true); | main.setSpacing(true); | ||||
propertyPanel.setHeight(120); | propertyPanel.setHeight(120); | ||||
main.addComponent(propertyPanel); | main.addComponent(propertyPanel); | ||||
explorerPanel.setHeight(100); | explorerPanel.setHeight(100); | ||||
explorerPanel.setHeightUnits(Panel.UNITS_PERCENTAGE); | |||||
explorerPanel.setHeightUnits(Sizeable.UNITS_PERCENTAGE); | |||||
main.addComponent(explorerPanel); | main.addComponent(explorerPanel); | ||||
main.expand(explorerPanel); | main.expand(explorerPanel); | ||||
propertyPanel.setEnabled(false); | propertyPanel.setEnabled(false); | ||||
// Get sample directory | // Get sample directory | ||||
File sampleDir = SampleDirectory.getDirectory(this); | |||||
final File sampleDir = SampleDirectory.getDirectory(this); | |||||
// Populate tree with FilesystemContainer | // Populate tree with FilesystemContainer | ||||
FilesystemContainer fsc = new FilesystemContainer(sampleDir, true); | |||||
final FilesystemContainer fsc = new FilesystemContainer(sampleDir, true); | |||||
filesystem.setContainerDataSource(fsc); | filesystem.setContainerDataSource(fsc); | ||||
// "this" handles all filesystem events | // "this" handles all filesystem events | ||||
// e.g. node clicked, expanded etc. | // e.g. node clicked, expanded etc. | ||||
// Check if event is about changing value | // Check if event is about changing value | ||||
if (event.getClass() == Field.ValueChangeEvent.class) { | if (event.getClass() == Field.ValueChangeEvent.class) { | ||||
// Update property panel contents | // Update property panel contents | ||||
FileItem fileItem = (FileItem) filesystem.getItem(filesystem | |||||
.getValue()); | |||||
final FileItem fileItem = (FileItem) filesystem | |||||
.getItem(filesystem.getValue()); | |||||
fileProperties.setIcon(fileItem.getIcon()); | fileProperties.setIcon(fileItem.getIcon()); | ||||
fileProperties.setCaption(fileItem.getName() + ", size " | fileProperties.setCaption(fileItem.getName() + ", size " | ||||
+ fileItem.getSize() + " bytes."); | + fileItem.getSize() + " bytes."); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
// | // | ||||
Property.ValueChangeListener { | Property.ValueChangeListener { | ||||
/* Menu for navigating inside the application. */ | /* Menu for navigating inside the application. */ | ||||
private Tree menu = new Tree(); | |||||
private final Tree menu = new Tree(); | |||||
/* Contents of the website */ | /* Contents of the website */ | ||||
private String[][] pages = { { "Welcome", "Welcome to our website..." }, | |||||
private final String[][] pages = { | |||||
{ "Welcome", "Welcome to our website..." }, | |||||
{ "Products", "Public product information." }, | { "Products", "Public product information." }, | ||||
{ "Contact", "Public contact information." }, | { "Contact", "Public contact information." }, | ||||
{ "CRM", "CRM Database requiring login." }, | { "CRM", "CRM Database requiring login." }, | ||||
{ "Intranet", "Internal information database." } }; | { "Intranet", "Internal information database." } }; | ||||
/* Application layout */ | /* Application layout */ | ||||
private GridLayout layout = new GridLayout(2, 1); | |||||
private final GridLayout layout = new GridLayout(2, 1); | |||||
/* Initialize the application */ | /* Initialize the application */ | ||||
public void init() { | public void init() { | ||||
// Create the main window of the application | // Create the main window of the application | ||||
Window main = new Window("Login example", layout); | |||||
final Window main = new Window("Login example", layout); | |||||
setMainWindow(main); | setMainWindow(main); | ||||
// Add menu and loginbox to the application | // Add menu and loginbox to the application | ||||
OrderedLayout l = new OrderedLayout(); | |||||
final OrderedLayout l = new OrderedLayout(); | |||||
layout.addComponent(l, 0, 0); | layout.addComponent(l, 0, 0); | ||||
l.addComponent(menu); | l.addComponent(menu); | ||||
l.addComponent(new LoginBox()); | l.addComponent(new LoginBox()); | ||||
// Handle menu selection and update visible page | // Handle menu selection and update visible page | ||||
public void valueChange(Property.ValueChangeEvent event) { | public void valueChange(Property.ValueChangeEvent event) { | ||||
layout.removeComponent(1, 0); | layout.removeComponent(1, 0); | ||||
String title = (String) menu.getValue(); | |||||
final String title = (String) menu.getValue(); | |||||
for (int i = 0; i < pages.length; i++) { | for (int i = 0; i < pages.length; i++) { | ||||
if (pages[i][0].equals(title)) { | if (pages[i][0].equals(title)) { | ||||
Panel p = new Panel(pages[i][0]); | |||||
final Panel p = new Panel(pages[i][0]); | |||||
p.addComponent(new Label(pages[i][1])); | p.addComponent(new Label(pages[i][1])); | ||||
p.setStyle("strong"); | p.setStyle("strong"); | ||||
layout.addComponent(p, 1, 0); | layout.addComponent(p, 1, 0); | ||||
Application.UserChangeListener { | Application.UserChangeListener { | ||||
// The components this loginbox is composed of | // The components this loginbox is composed of | ||||
private TextField loginName = new TextField("Name"); | |||||
private final TextField loginName = new TextField("Name"); | |||||
private Button loginButton = new Button("Enter", this, "login"); | |||||
private final Button loginButton = new Button("Enter", this, "login"); | |||||
private Panel loginPanel = new Panel("Login"); | |||||
private final Panel loginPanel = new Panel("Login"); | |||||
private Panel statusPanel = new Panel(); | |||||
private final Panel statusPanel = new Panel(); | |||||
private Button logoutButton = new Button("Logout", | |||||
private final Button logoutButton = new Button("Logout", | |||||
UpgradingSample.this, "close"); | UpgradingSample.this, "close"); | ||||
private Label statusLabel = new Label(); | |||||
private final Label statusLabel = new Label(); | |||||
// Initialize login component | // Initialize login component | ||||
public LoginBox() { | public LoginBox() { | ||||
// Login into application | // Login into application | ||||
public void login() { | public void login() { | ||||
String name = (String) loginName.getValue(); | |||||
final String name = (String) loginName.getValue(); | |||||
if (name != null && name.length() > 0) { | if (name != null && name.length() > 0) { | ||||
setUser(name); | setUser(name); | ||||
} | } |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo; | package com.itmill.toolkit.demo; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
public void init() { | public void init() { | ||||
// Create new window for the application and give the window a visible. | // Create new window for the application and give the window a visible. | ||||
Window main = new Window("IT Mill Toolkit 5 Windowed Demos"); | |||||
final Window main = new Window("IT Mill Toolkit 5 Windowed Demos"); | |||||
// set as main window | // set as main window | ||||
setMainWindow(main); | setMainWindow(main); | ||||
// Create menu window. | // Create menu window. | ||||
Window menu = new Window("Select demo"); | |||||
final Window menu = new Window("Select demo"); | |||||
menu.setWidth(200); | menu.setWidth(200); | ||||
menu.setHeight(400); | menu.setHeight(400); | ||||
main.addWindow(menu); // add to layout | main.addWindow(menu); // add to layout | ||||
// Create a menu button for each demo | // Create a menu button for each demo | ||||
for (Iterator it = servlets.keySet().iterator(); it.hasNext();) { | |||||
String name = (String) it.next(); | |||||
Button b = new Button(name, new Button.ClickListener() { | |||||
for (final Iterator it = servlets.keySet().iterator(); it.hasNext();) { | |||||
final String name = (String) it.next(); | |||||
final Button b = new Button(name, new Button.ClickListener() { | |||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
show(event.getButton().getCaption()); | show(event.getButton().getCaption()); | ||||
} | } |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.colorpicker; | package com.itmill.toolkit.demo.colorpicker; | ||||
import java.util.Map; | import java.util.Map; | ||||
public void changeVariables(Object source, Map variables) { | public void changeVariables(Object source, Map variables) { | ||||
// Sets the currently selected color | // Sets the currently selected color | ||||
if (variables.containsKey("colorname") && !isReadOnly()) { | if (variables.containsKey("colorname") && !isReadOnly()) { | ||||
String newValue = (String) variables.get("colorname"); | |||||
final String newValue = (String) variables.get("colorname"); | |||||
// Changing the property of the component will | // Changing the property of the component will | ||||
// trigger a ValueChangeEvent | // trigger a ValueChangeEvent | ||||
setValue(newValue, true); | setValue(newValue, true); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.colorpicker; | package com.itmill.toolkit.demo.colorpicker; | ||||
import com.itmill.toolkit.data.Property.ValueChangeEvent; | import com.itmill.toolkit.data.Property.ValueChangeEvent; | ||||
main.addComponent(colorname); | main.addComponent(colorname); | ||||
// Server-side manipulation of the component state | // Server-side manipulation of the component state | ||||
Button button = new Button("Set to white"); | |||||
final Button button = new Button("Set to white"); | |||||
button.addListener(new Button.ClickListener() { | button.addListener(new Button.ClickListener() { | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
colorselector.setColor("white"); | colorselector.setColor("white"); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.colorpicker.gwt.client; | package com.itmill.toolkit.demo.colorpicker.gwt.client; | ||||
import com.google.gwt.user.client.ui.Widget; | import com.google.gwt.user.client.ui.Widget; | ||||
public class ColorPickerWidgetSet extends DefaultWidgetSet { | public class ColorPickerWidgetSet extends DefaultWidgetSet { | ||||
/** Creates a widget according to its class name. */ | /** Creates a widget according to its class name. */ | ||||
public Widget createWidget(UIDL uidl) { | public Widget createWidget(UIDL uidl) { | ||||
String className = resolveWidgetTypeName(uidl); | |||||
final String className = resolveWidgetTypeName(uidl); | |||||
if ("com.itmill.toolkit.demo.colorpicker.gwt.client.ui.IColorPicker" | if ("com.itmill.toolkit.demo.colorpicker.gwt.client.ui.IColorPicker" | ||||
.equals(className)) { | .equals(className)) { | ||||
return new IColorPicker(); | return new IColorPicker(); | ||||
/** Resolves UIDL tag name to class name. */ | /** Resolves UIDL tag name to class name. */ | ||||
protected String resolveWidgetTypeName(UIDL uidl) { | protected String resolveWidgetTypeName(UIDL uidl) { | ||||
String tag = uidl.getTag(); | |||||
final String tag = uidl.getTag(); | |||||
if ("colorpicker".equals(tag)) { | if ("colorpicker".equals(tag)) { | ||||
return "com.itmill.toolkit.demo.colorpicker.gwt.client.ui.IColorPicker"; | return "com.itmill.toolkit.demo.colorpicker.gwt.client.ui.IColorPicker"; | ||||
} | } |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.colorpicker.gwt.client.ui; | package com.itmill.toolkit.demo.colorpicker.gwt.client.ui; | ||||
import com.google.gwt.user.client.DOM; | import com.google.gwt.user.client.DOM; | ||||
public GwtColorPicker() { | public GwtColorPicker() { | ||||
// Create a 4x4 grid of buttons with names for 16 colors | // Create a 4x4 grid of buttons with names for 16 colors | ||||
Grid grid = new Grid(4, 4); | |||||
String[] colors = new String[] { "aqua", "black", "blue", "fuchsia", | |||||
"gray", "green", "lime", "maroon", "navy", "olive", "purple", | |||||
"red", "silver", "teal", "white", "yellow" }; | |||||
final Grid grid = new Grid(4, 4); | |||||
final String[] colors = new String[] { "aqua", "black", "blue", | |||||
"fuchsia", "gray", "green", "lime", "maroon", "navy", "olive", | |||||
"purple", "red", "silver", "teal", "white", "yellow" }; | |||||
int colornum = 0; | int colornum = 0; | ||||
for (int i = 0; i < 4; i++) { | for (int i = 0; i < 4; i++) { | ||||
for (int j = 0; j < 4; j++, colornum++) { | for (int j = 0; j < 4; j++, colornum++) { | ||||
// Create a button for each color | // Create a button for each color | ||||
Button button = new Button(colors[colornum]); | |||||
final Button button = new Button(colors[colornum]); | |||||
button.addClickListener(this); | button.addClickListener(this); | ||||
// Put the button in the Grid layout | // Put the button in the Grid layout | ||||
// Create a panel with the color grid and currently selected color | // Create a panel with the color grid and currently selected color | ||||
// indicator | // indicator | ||||
HorizontalPanel panel = new HorizontalPanel(); | |||||
final HorizontalPanel panel = new HorizontalPanel(); | |||||
panel.add(grid); | panel.add(grid); | ||||
panel.add(currentcolor); | panel.add(currentcolor); | ||||
// the parent of the label element. Notice that the element has no | // the parent of the label element. Notice that the element has no | ||||
// parent | // parent | ||||
// before the widget has been added to the horizontal panel. | // before the widget has been added to the horizontal panel. | ||||
Element panelcell = DOM.getParent(currentcolor.getElement()); | |||||
final Element panelcell = DOM.getParent(currentcolor.getElement()); | |||||
DOM.setElementProperty(panelcell, "className", | DOM.setElementProperty(panelcell, "className", | ||||
"colorpicker-currentcolorbox"); | "colorpicker-currentcolorbox"); | ||||
// Obtain the DOM elements. This assumes that the <td> element | // Obtain the DOM elements. This assumes that the <td> element | ||||
// of the HorizontalPanel is the parent of the label element. | // of the HorizontalPanel is the parent of the label element. | ||||
Element nameelement = currentcolor.getElement(); | |||||
Element cell = DOM.getParent(nameelement); | |||||
final Element nameelement = currentcolor.getElement(); | |||||
final Element cell = DOM.getParent(nameelement); | |||||
// Give feedback by changing the background color | // Give feedback by changing the background color | ||||
DOM.setStyleAttribute(cell, "background", newcolor); | DOM.setStyleAttribute(cell, "background", newcolor); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.colorpicker.gwt.client.ui; | package com.itmill.toolkit.demo.colorpicker.gwt.client.ui; | ||||
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; | import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import com.itmill.toolkit.terminal.ExternalResource; | import com.itmill.toolkit.terminal.ExternalResource; | ||||
public ButtonExample() { | public ButtonExample() { | ||||
OrderedLayout main = new OrderedLayout(); | |||||
final OrderedLayout main = new OrderedLayout(); | |||||
main.setMargin(true); | main.setMargin(true); | ||||
setCompositionRoot(main); | setCompositionRoot(main); | ||||
OrderedLayout horiz = new OrderedLayout( | |||||
final OrderedLayout horiz = new OrderedLayout( | |||||
OrderedLayout.ORIENTATION_HORIZONTAL); | OrderedLayout.ORIENTATION_HORIZONTAL); | ||||
main.addComponent(horiz); | main.addComponent(horiz); | ||||
Panel basic = new Panel("Basic buttons"); | |||||
final Panel basic = new Panel("Basic buttons"); | |||||
basic.setStyleName(Panel.STYLE_LIGHT); | basic.setStyleName(Panel.STYLE_LIGHT); | ||||
horiz.addComponent(basic); | horiz.addComponent(basic); | ||||
Panel bells = new Panel("w/ bells & whistles"); | |||||
final Panel bells = new Panel("w/ bells & whistles"); | |||||
bells.setStyleName(Panel.STYLE_LIGHT); | bells.setStyleName(Panel.STYLE_LIGHT); | ||||
horiz.addComponent(bells); | horiz.addComponent(bells); | ||||
b.setDescription("Link-style, icon+tootip, no caption"); | b.setDescription("Link-style, icon+tootip, no caption"); | ||||
basic.addComponent(b); | basic.addComponent(b); | ||||
Panel links = new Panel("Links"); | |||||
final Panel links = new Panel("Links"); | |||||
links.setStyleName(Panel.STYLE_LIGHT); | links.setStyleName(Panel.STYLE_LIGHT); | ||||
main.addComponent(links); | main.addComponent(links); | ||||
Label desc = new Label( | |||||
final Label desc = new Label( | |||||
"The main difference between a Link and" | "The main difference between a Link and" | ||||
+ " a link-styled Button is that the Link works client-" | + " a link-styled Button is that the Link works client-" | ||||
+ " side, whereas the Button works server side.<br/> This means" | + " side, whereas the Button works server side.<br/> This means" | ||||
} | } | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
Button b = event.getButton(); | |||||
final Button b = event.getButton(); | |||||
getWindow().showNotification( | getWindow().showNotification( | ||||
"Clicked" | "Clicked" | ||||
+ (b instanceof CheckBox ? ", value: " | + (b instanceof CheckBox ? ", value: " |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import com.itmill.toolkit.terminal.PaintException; | import com.itmill.toolkit.terminal.PaintException; | ||||
public ClientCachingExample() { | public ClientCachingExample() { | ||||
OrderedLayout main = new OrderedLayout(); | |||||
final OrderedLayout main = new OrderedLayout(); | |||||
main.setMargin(true); | main.setMargin(true); | ||||
setCompositionRoot(main); | setCompositionRoot(main); | ||||
main.addComponent(new Label(msg)); | main.addComponent(new Label(msg)); | ||||
TabSheet ts = new TabSheet(); | |||||
final TabSheet ts = new TabSheet(); | |||||
main.addComponent(ts); | main.addComponent(ts); | ||||
Layout layout = new OrderedLayout(); | Layout layout = new OrderedLayout(); | ||||
public void paintContent(PaintTarget target) throws PaintException { | public void paintContent(PaintTarget target) throws PaintException { | ||||
try { | try { | ||||
Thread.sleep(3000); | Thread.sleep(3000); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
// IGNORED | // IGNORED | ||||
} | } | ||||
super.paintContent(target); | super.paintContent(target); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import com.itmill.toolkit.ui.ComboBox; | import com.itmill.toolkit.ui.ComboBox; | ||||
"Fielding", "Einstein" }; | "Fielding", "Einstein" }; | ||||
public ComboBoxExample() { | public ComboBoxExample() { | ||||
OrderedLayout main = new OrderedLayout(); | |||||
final OrderedLayout main = new OrderedLayout(); | |||||
main.setMargin(true); | main.setMargin(true); | ||||
setCompositionRoot(main); | setCompositionRoot(main); | ||||
// starts-with filter | // starts-with filter | ||||
ComboBox s1 = new ComboBox("Select with starts-with filter"); | |||||
final ComboBox s1 = new ComboBox("Select with starts-with filter"); | |||||
s1.setFilteringMode(Filtering.FILTERINGMODE_STARTSWITH); | s1.setFilteringMode(Filtering.FILTERINGMODE_STARTSWITH); | ||||
s1.setColumns(20); | s1.setColumns(20); | ||||
for (int i = 0; i < 105; i++) { | for (int i = 0; i < 105; i++) { | ||||
main.addComponent(s1); | main.addComponent(s1); | ||||
// contains filter | // contains filter | ||||
ComboBox s2 = new ComboBox("Select with contains filter"); | |||||
final ComboBox s2 = new ComboBox("Select with contains filter"); | |||||
s2.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS); | s2.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS); | ||||
s2.setColumns(20); | s2.setColumns(20); | ||||
for (int i = 0; i < 500; i++) { | for (int i = 0; i < 500; i++) { | ||||
main.addComponent(s2); | main.addComponent(s2); | ||||
// initially empty | // initially empty | ||||
ComboBox s3 = new ComboBox("Initially empty; enter your own"); | |||||
final ComboBox s3 = new ComboBox("Initially empty; enter your own"); | |||||
s3.setColumns(20); | s3.setColumns(20); | ||||
s3.setImmediate(true); | s3.setImmediate(true); | ||||
main.addComponent(s3); | main.addComponent(s3); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import com.itmill.toolkit.data.Property.ValueChangeEvent; | import com.itmill.toolkit.data.Property.ValueChangeEvent; | ||||
setSizeFull(); | setSizeFull(); | ||||
// create the address combobox | // create the address combobox | ||||
Select select = new Select(); | |||||
final Select select = new Select(); | |||||
// allow input | // allow input | ||||
select.setNewItemsAllowed(true); | select.setNewItemsAllowed(true); | ||||
// no empty selection | // no empty selection | ||||
} | } | ||||
public void valueChange(ValueChangeEvent event) { | public void valueChange(ValueChangeEvent event) { | ||||
String url = (String) event.getProperty().getValue(); | |||||
final String url = (String) event.getProperty().getValue(); | |||||
if (url != null) { | if (url != null) { | ||||
// the selected url has changed, let's go there | // the selected url has changed, let's go there | ||||
emb.setSource(new ExternalResource(url)); | emb.setSource(new ExternalResource(url)); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import com.itmill.toolkit.terminal.ExternalResource; | import com.itmill.toolkit.terminal.ExternalResource; | ||||
import com.itmill.toolkit.terminal.Sizeable; | import com.itmill.toolkit.terminal.Sizeable; | ||||
import com.itmill.toolkit.terminal.ThemeResource; | import com.itmill.toolkit.terminal.ThemeResource; | ||||
import com.itmill.toolkit.ui.AbstractSelect; | |||||
import com.itmill.toolkit.ui.Button; | import com.itmill.toolkit.ui.Button; | ||||
import com.itmill.toolkit.ui.Component; | import com.itmill.toolkit.ui.Component; | ||||
import com.itmill.toolkit.ui.Embedded; | import com.itmill.toolkit.ui.Embedded; | ||||
private TabSheet ts; | private TabSheet ts; | ||||
// Example "cache" | // Example "cache" | ||||
private HashMap exampleInstances = new HashMap(); | |||||
private final HashMap exampleInstances = new HashMap(); | |||||
// List of examples | // List of examples | ||||
private static final Object[][] demos = new Object[][] { | private static final Object[][] demos = new Object[][] { | ||||
setTheme("example"); | setTheme("example"); | ||||
// Create new window for the application and give the window a visible. | // Create new window for the application and give the window a visible. | ||||
Window main = new Window("IT Mill Toolkit 5"); | |||||
final Window main = new Window("IT Mill Toolkit 5"); | |||||
// set as main window | // set as main window | ||||
setMainWindow(main); | setMainWindow(main); | ||||
SplitPanel split = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); | |||||
final SplitPanel split = new SplitPanel( | |||||
SplitPanel.ORIENTATION_HORIZONTAL); | |||||
split.setSplitPosition(200, Sizeable.UNITS_PIXELS); | split.setSplitPosition(200, Sizeable.UNITS_PIXELS); | ||||
main.setLayout(split); | main.setLayout(split); | ||||
HashMap sectionIds = new HashMap(); | |||||
HierarchicalContainer container = createContainer(); | |||||
Object rootId = container.addItem(); | |||||
final HashMap sectionIds = new HashMap(); | |||||
final HierarchicalContainer container = createContainer(); | |||||
final Object rootId = container.addItem(); | |||||
Item item = container.getItem(rootId); | Item item = container.getItem(rootId); | ||||
Property p = item.getItemProperty(PROPERTY_ID_NAME); | Property p = item.getItemProperty(PROPERTY_ID_NAME); | ||||
p.setValue("All examples"); | p.setValue("All examples"); | ||||
for (int i = 0; i < demos.length; i++) { | for (int i = 0; i < demos.length; i++) { | ||||
Object[] demo = demos[i]; | |||||
String section = (String) demo[0]; | |||||
final Object[] demo = demos[i]; | |||||
final String section = (String) demo[0]; | |||||
Object sectionId; | Object sectionId; | ||||
if (sectionIds.containsKey(section)) { | if (sectionIds.containsKey(section)) { | ||||
sectionId = sectionIds.get(section); | sectionId = sectionIds.get(section); | ||||
p = item.getItemProperty(PROPERTY_ID_NAME); | p = item.getItemProperty(PROPERTY_ID_NAME); | ||||
p.setValue(section); | p.setValue(section); | ||||
} | } | ||||
Object id = container.addItem(); | |||||
final Object id = container.addItem(); | |||||
container.setParent(id, sectionId); | container.setParent(id, sectionId); | ||||
initItem(container.getItem(id), demo); | initItem(container.getItem(id), demo); | ||||
tree.setMultiSelect(false); | tree.setMultiSelect(false); | ||||
tree.setNullSelectionAllowed(false); | tree.setNullSelectionAllowed(false); | ||||
tree.setContainerDataSource(container); | tree.setContainerDataSource(container); | ||||
tree.setItemCaptionMode(Tree.ITEM_CAPTION_MODE_PROPERTY); | |||||
tree.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY); | |||||
tree.setItemCaptionPropertyId(PROPERTY_ID_NAME); | tree.setItemCaptionPropertyId(PROPERTY_ID_NAME); | ||||
tree.addListener(this); | tree.addListener(this); | ||||
tree.setImmediate(true); | tree.setImmediate(true); | ||||
split.addComponent(tree); | split.addComponent(tree); | ||||
SplitPanel split2 = new SplitPanel(); | |||||
final SplitPanel split2 = new SplitPanel(); | |||||
split2.setSplitPosition(200, Sizeable.UNITS_PIXELS); | split2.setSplitPosition(200, Sizeable.UNITS_PIXELS); | ||||
split.addComponent(split2); | split.addComponent(split2); | ||||
table.setNullSelectionAllowed(false); | table.setNullSelectionAllowed(false); | ||||
try { | try { | ||||
table.setContainerDataSource((IndexedContainer) container.clone()); | table.setContainerDataSource((IndexedContainer) container.clone()); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); | ||||
} | } | ||||
// Hide some columns | // Hide some columns | ||||
table.setImmediate(true); | table.setImmediate(true); | ||||
split2.addComponent(table); | split2.addComponent(table); | ||||
ExpandLayout exp = new ExpandLayout(); | |||||
final ExpandLayout exp = new ExpandLayout(); | |||||
exp.setMargin(true); | exp.setMargin(true); | ||||
split2.addComponent(exp); | split2.addComponent(exp); | ||||
OrderedLayout wbLayout = new OrderedLayout( | |||||
final OrderedLayout wbLayout = new OrderedLayout( | |||||
OrderedLayout.ORIENTATION_HORIZONTAL); | OrderedLayout.ORIENTATION_HORIZONTAL); | ||||
Button b = new Button("Open in sub-window", new Button.ClickListener() { | Button b = new Button("Open in sub-window", new Button.ClickListener() { | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
Component component = (Component) ts.getComponentIterator() | Component component = (Component) ts.getComponentIterator() | ||||
.next(); | .next(); | ||||
String caption = ts.getTabCaption(component); | |||||
final String caption = ts.getTabCaption(component); | |||||
Window w = getWindow(caption); | Window w = getWindow(caption); | ||||
if (w == null) { | if (w == null) { | ||||
try { | try { | ||||
component = (Component) component.getClass() | component = (Component) component.getClass() | ||||
.newInstance(); | .newInstance(); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
// Could not create | // Could not create | ||||
return; | return; | ||||
} | } | ||||
wbLayout.addComponent(b); | wbLayout.addComponent(b); | ||||
exp.addComponent(wbLayout); | exp.addComponent(wbLayout); | ||||
exp.setComponentAlignment(wbLayout, ExpandLayout.ALIGNMENT_RIGHT, | |||||
ExpandLayout.ALIGNMENT_TOP); | |||||
exp.setComponentAlignment(wbLayout, OrderedLayout.ALIGNMENT_RIGHT, | |||||
OrderedLayout.ALIGNMENT_TOP); | |||||
ts = new TabSheet(); | ts = new TabSheet(); | ||||
ts.setSizeFull(); | ts.setSizeFull(); | ||||
exp.addComponent(ts); | exp.addComponent(ts); | ||||
exp.expand(ts); | exp.expand(ts); | ||||
Label status = new Label( | |||||
final Label status = new Label( | |||||
"<a href=\"http://www.itmill.com/index_developers.htm\">Developer Area</a>" | "<a href=\"http://www.itmill.com/index_developers.htm\">Developer Area</a>" | ||||
+ " | <a href=\"http://www.itmill.com/developers_documentation.htm\">Documentation</a>"); | + " | <a href=\"http://www.itmill.com/developers_documentation.htm\">Documentation</a>"); | ||||
status.setContentMode(Label.CONTENT_XHTML); | status.setContentMode(Label.CONTENT_XHTML); | ||||
exp.addComponent(status); | exp.addComponent(status); | ||||
exp.setComponentAlignment(status, ExpandLayout.ALIGNMENT_RIGHT, | |||||
ExpandLayout.ALIGNMENT_VERTICAL_CENTER); | |||||
exp.setComponentAlignment(status, OrderedLayout.ALIGNMENT_RIGHT, | |||||
OrderedLayout.ALIGNMENT_VERTICAL_CENTER); | |||||
// select initial section ("All") | // select initial section ("All") | ||||
tree.setValue(rootId); | tree.setValue(rootId); | ||||
} | } | ||||
private HierarchicalContainer createContainer() { | private HierarchicalContainer createContainer() { | ||||
HierarchicalContainer c = new HierarchicalContainer(); | |||||
final HierarchicalContainer c = new HierarchicalContainer(); | |||||
c.addContainerProperty(PROPERTY_ID_CATEGORY, String.class, null); | c.addContainerProperty(PROPERTY_ID_CATEGORY, String.class, null); | ||||
c.addContainerProperty(PROPERTY_ID_NAME, String.class, ""); | c.addContainerProperty(PROPERTY_ID_NAME, String.class, ""); | ||||
c.addContainerProperty(PROPERTY_ID_DESC, String.class, ""); | c.addContainerProperty(PROPERTY_ID_DESC, String.class, ""); | ||||
public void valueChange(ValueChangeEvent event) { | public void valueChange(ValueChangeEvent event) { | ||||
if (event.getProperty() == tree) { | if (event.getProperty() == tree) { | ||||
Object id = tree.getValue(); | |||||
Item item = tree.getItem(id); | |||||
final Object id = tree.getValue(); | |||||
final Item item = tree.getItem(id); | |||||
// | // | ||||
String section; | String section; | ||||
if (tree.isRoot(id)) { | if (tree.isRoot(id)) { | ||||
} | } | ||||
table.setValue(null); | table.setValue(null); | ||||
IndexedContainer c = (IndexedContainer) table | |||||
final IndexedContainer c = (IndexedContainer) table | |||||
.getContainerDataSource(); | .getContainerDataSource(); | ||||
c.removeAllContainerFilters(); | c.removeAllContainerFilters(); | ||||
if (section != null) { | if (section != null) { | ||||
table.removeListener(this); | table.removeListener(this); | ||||
tree.setValue(table.getValue()); | tree.setValue(table.getValue()); | ||||
table.addListener(this); | table.addListener(this); | ||||
Item item = table.getItem(table.getValue()); | |||||
Class c = (Class) item.getItemProperty(PROPERTY_ID_CLASS) | |||||
final Item item = table.getItem(table.getValue()); | |||||
final Class c = (Class) item.getItemProperty(PROPERTY_ID_CLASS) | |||||
.getValue(); | .getValue(); | ||||
Component component = getComponent(c); | |||||
final Component component = getComponent(c); | |||||
if (component != null) { | if (component != null) { | ||||
String caption = (String) item.getItemProperty( | |||||
final String caption = (String) item.getItemProperty( | |||||
PROPERTY_ID_NAME).getValue(); | PROPERTY_ID_NAME).getValue(); | ||||
ts.removeAllComponents(); | ts.removeAllComponents(); | ||||
ts.addTab(component, caption, null); | ts.addTab(component, caption, null); | ||||
} | } | ||||
// update "viewed" state | // update "viewed" state | ||||
Property p = item.getItemProperty(PROPERTY_ID_VIEWED); | |||||
final Property p = item.getItemProperty(PROPERTY_ID_VIEWED); | |||||
if (p.getValue() == null) { | if (p.getValue() == null) { | ||||
p.setValue(new Embedded("", new ThemeResource( | p.setValue(new Embedded("", new ThemeResource( | ||||
"icons/ok.png"))); | "icons/ok.png"))); | ||||
private Component getComponent(Class componentClass) { | private Component getComponent(Class componentClass) { | ||||
if (!exampleInstances.containsKey(componentClass)) { | if (!exampleInstances.containsKey(componentClass)) { | ||||
try { | try { | ||||
Component c = (Component) componentClass.newInstance(); | |||||
final Component c = (Component) componentClass.newInstance(); | |||||
exampleInstances.put(componentClass, c); | exampleInstances.put(componentClass, c); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
return null; | return null; | ||||
} | } | ||||
} | } |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import com.itmill.toolkit.ui.CustomComponent; | import com.itmill.toolkit.ui.CustomComponent; | ||||
public LabelExample() { | public LabelExample() { | ||||
OrderedLayout main = new OrderedLayout(); | |||||
final OrderedLayout main = new OrderedLayout(); | |||||
main.setMargin(true); | main.setMargin(true); | ||||
setCompositionRoot(main); | setCompositionRoot(main); | ||||
GridLayout g = new GridLayout(2, 4); | |||||
final GridLayout g = new GridLayout(2, 4); | |||||
main.addComponent(g); | main.addComponent(g); | ||||
// plain w/o caption | // plain w/o caption |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import com.itmill.toolkit.ui.CustomComponent; | import com.itmill.toolkit.ui.CustomComponent; | ||||
public LayoutExample() { | public LayoutExample() { | ||||
OrderedLayout main = new OrderedLayout(); | |||||
final OrderedLayout main = new OrderedLayout(); | |||||
main.setMargin(true); | main.setMargin(true); | ||||
setCompositionRoot(main); | setCompositionRoot(main); | ||||
GridLayout g = new GridLayout(2, 5); | |||||
final GridLayout g = new GridLayout(2, 5); | |||||
main.addComponent(g); | main.addComponent(g); | ||||
// panel | // panel | ||||
ol.addComponent(new Label("Component 3")); | ol.addComponent(new Label("Component 3")); | ||||
ts.addTab(ol, "Horizontal OrderedLayout", null); | ts.addTab(ol, "Horizontal OrderedLayout", null); | ||||
GridLayout gl = new GridLayout(3, 3); | |||||
final GridLayout gl = new GridLayout(3, 3); | |||||
gl.setMargin(true); | gl.setMargin(true); | ||||
gl.addComponent(new Label("Component 1.1")); | gl.addComponent(new Label("Component 1.1")); | ||||
gl.addComponent(new Label("Component 1.2")); | gl.addComponent(new Label("Component 1.2")); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import java.util.Date; | import java.util.Date; | ||||
*/ | */ | ||||
public NotificationExample() { | public NotificationExample() { | ||||
// Main layout | // Main layout | ||||
OrderedLayout main = new OrderedLayout(); | |||||
final OrderedLayout main = new OrderedLayout(); | |||||
main.setMargin(true); // use theme-specific margin | main.setMargin(true); // use theme-specific margin | ||||
setCompositionRoot(main); | setCompositionRoot(main); | ||||
message.setValue("A quick one jumped over the lazy dog."); | message.setValue("A quick one jumped over the lazy dog."); | ||||
// Button to show the notification | // Button to show the notification | ||||
Button b = new Button("Show notification", new ClickListener() { | |||||
final Button b = new Button("Show notification", new ClickListener() { | |||||
// this is an inline ClickListener | // this is an inline ClickListener | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
// show the notification | // show the notification |
/** | |||||
* | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | */ | ||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import com.itmill.toolkit.ui.Button; | import com.itmill.toolkit.ui.Button; | ||||
+ "See the <A href=\"http://www.itmill.com/manual/\">manual</a> " | + "See the <A href=\"http://www.itmill.com/manual/\">manual</a> " | ||||
+ "for more information."; | + "for more information."; | ||||
private OrderedLayout main; | |||||
private Label l; | |||||
private RichTextArea editor = new RichTextArea(); | |||||
private Button b; | |||||
private final OrderedLayout main; | |||||
private final Label l; | |||||
private final RichTextArea editor = new RichTextArea(); | |||||
private final Button b; | |||||
public RichTextExample() { | public RichTextExample() { | ||||
// main layout | // main layout |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import com.itmill.toolkit.data.Property.ValueChangeEvent; | import com.itmill.toolkit.data.Property.ValueChangeEvent; | ||||
public class SelectExample extends CustomComponent { | public class SelectExample extends CustomComponent { | ||||
// listener that shows a value change notification | // listener that shows a value change notification | ||||
private Field.ValueChangeListener listener = new Field.ValueChangeListener() { | |||||
private final Field.ValueChangeListener listener = new Field.ValueChangeListener() { | |||||
public void valueChange(ValueChangeEvent event) { | public void valueChange(ValueChangeEvent event) { | ||||
getWindow().showNotification("" + event.getProperty().getValue()); | getWindow().showNotification("" + event.getProperty().getValue()); | ||||
} | } | ||||
}; | }; | ||||
public SelectExample() { | public SelectExample() { | ||||
OrderedLayout main = new OrderedLayout(); | |||||
final OrderedLayout main = new OrderedLayout(); | |||||
main.setMargin(true); | main.setMargin(true); | ||||
setCompositionRoot(main); | setCompositionRoot(main); | ||||
OrderedLayout horiz = new OrderedLayout( | |||||
final OrderedLayout horiz = new OrderedLayout( | |||||
OrderedLayout.ORIENTATION_HORIZONTAL); | OrderedLayout.ORIENTATION_HORIZONTAL); | ||||
main.addComponent(horiz); | main.addComponent(horiz); | ||||
Panel single = new Panel("Single selects"); | |||||
final Panel single = new Panel("Single selects"); | |||||
single.setStyleName(Panel.STYLE_LIGHT); | single.setStyleName(Panel.STYLE_LIGHT); | ||||
horiz.addComponent(single); | horiz.addComponent(single); | ||||
Panel multi = new Panel("Multi selects"); | |||||
final Panel multi = new Panel("Multi selects"); | |||||
multi.setStyleName(Panel.STYLE_LIGHT); | multi.setStyleName(Panel.STYLE_LIGHT); | ||||
horiz.addComponent(multi); | horiz.addComponent(multi); | ||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
public TableExample() { | public TableExample() { | ||||
// main layout | // main layout | ||||
OrderedLayout main = new OrderedLayout(); | |||||
final OrderedLayout main = new OrderedLayout(); | |||||
main.setMargin(true); | main.setMargin(true); | ||||
setCompositionRoot(main); | setCompositionRoot(main); | ||||
main.addComponent(source); | main.addComponent(source); | ||||
// x-selected button row | // x-selected button row | ||||
OrderedLayout horiz = new OrderedLayout( | |||||
final OrderedLayout horiz = new OrderedLayout( | |||||
OrderedLayout.ORIENTATION_HORIZONTAL); | OrderedLayout.ORIENTATION_HORIZONTAL); | ||||
horiz.setMargin(false, false, true, false); | horiz.setMargin(false, false, true, false); | ||||
main.addComponent(horiz); | main.addComponent(horiz); | ||||
saved.addActionHandler(this); | saved.addActionHandler(this); | ||||
main.addComponent(saved); | main.addComponent(saved); | ||||
CheckBox b = new CheckBox("Modify saved creatures"); | |||||
final CheckBox b = new CheckBox("Modify saved creatures"); | |||||
b.addListener(new CheckBox.ClickListener() { | b.addListener(new CheckBox.ClickListener() { | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
saved.setEditable(((Boolean) event.getButton().getValue()) | saved.setEditable(((Boolean) event.getButton().getValue()) | ||||
private void fillTable(Table table) { | private void fillTable(Table table) { | ||||
initProperties(table); | initProperties(table); | ||||
String[] sp = new String[] { "Fox", "Dog", "Cat", "Moose", "Penguin", | |||||
"Cow" }; | |||||
String[] ty = new String[] { "Quick", "Lazy", "Sleepy", "Fidgety", | |||||
"Crazy", "Kewl" }; | |||||
String[] ki = new String[] { "Jumping", "Walking", "Sleeping", | |||||
final String[] sp = new String[] { "Fox", "Dog", "Cat", "Moose", | |||||
"Penguin", "Cow" }; | |||||
final String[] ty = new String[] { "Quick", "Lazy", "Sleepy", | |||||
"Fidgety", "Crazy", "Kewl" }; | |||||
final String[] ki = new String[] { "Jumping", "Walking", "Sleeping", | |||||
"Skipping", "Dancing" }; | "Skipping", "Dancing" }; | ||||
for (int i = 0; i < 100; i++) { | for (int i = 0; i < 100; i++) { | ||||
String s = sp[(int) (Math.random() * sp.length)]; | |||||
String t = ty[(int) (Math.random() * ty.length)]; | |||||
String k = ki[(int) (Math.random() * ki.length)]; | |||||
final String s = sp[(int) (Math.random() * sp.length)]; | |||||
final String t = ty[(int) (Math.random() * ty.length)]; | |||||
final String k = ki[(int) (Math.random() * ki.length)]; | |||||
table.addItem(new Object[] { s, t, k, Boolean.FALSE }, new Integer( | table.addItem(new Object[] { s, t, k, Boolean.FALSE }, new Integer( | ||||
i)); | i)); | ||||
} | } | ||||
// Called for each item (row), returns valid actions for that item | // Called for each item (row), returns valid actions for that item | ||||
public Action[] getActions(Object target, Object sender) { | public Action[] getActions(Object target, Object sender) { | ||||
if (sender == source) { | if (sender == source) { | ||||
Item item = source.getItem(target); | |||||
final Item item = source.getItem(target); | |||||
// save, delete, and hire if not already hired | // save, delete, and hire if not already hired | ||||
if (item != null | if (item != null | ||||
&& item.getItemProperty(PROPERTY_HIRED).getValue() == Boolean.FALSE) { | && item.getItemProperty(PROPERTY_HIRED).getValue() == Boolean.FALSE) { | ||||
return; | return; | ||||
} | } | ||||
// "manual" copy of the item properties we want | // "manual" copy of the item properties we want | ||||
Item added = saved.addItem(target); | |||||
final Item added = saved.addItem(target); | |||||
Property p = added.getItemProperty(PROPERTY_SPECIES); | Property p = added.getItemProperty(PROPERTY_SPECIES); | ||||
p.setValue(item.getItemProperty(PROPERTY_SPECIES).getValue()); | p.setValue(item.getItemProperty(PROPERTY_SPECIES).getValue()); | ||||
p = added.getItemProperty(PROPERTY_TYPE); | p = added.getItemProperty(PROPERTY_TYPE); | ||||
} else { | } else { | ||||
// sender==saved | // sender==saved | ||||
if (action == ACTION_DELETE) { | if (action == ACTION_DELETE) { | ||||
Item item = saved.getItem(target); | |||||
final Item item = saved.getItem(target); | |||||
getWindow().showNotification("Deleted", "" + item); | getWindow().showNotification("Deleted", "" + item); | ||||
saved.removeItem(target); | saved.removeItem(target); | ||||
} | } | ||||
} | } | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
Button b = event.getButton(); | |||||
final Button b = event.getButton(); | |||||
if (b == deselect) { | if (b == deselect) { | ||||
source.setValue(null); | source.setValue(null); | ||||
} else if (b == saveSelected) { | } else if (b == saveSelected) { | ||||
// loop each selected and copy to "saved" table | // loop each selected and copy to "saved" table | ||||
Set selected = (Set) source.getValue(); | |||||
final Set selected = (Set) source.getValue(); | |||||
int s = 0; | int s = 0; | ||||
for (Iterator it = selected.iterator(); it.hasNext();) { | |||||
Object id = it.next(); | |||||
for (final Iterator it = selected.iterator(); it.hasNext();) { | |||||
final Object id = it.next(); | |||||
if (!saved.containsId(id)) { | if (!saved.containsId(id)) { | ||||
Item item = source.getItem(id); | |||||
Item added = saved.addItem(id); | |||||
final Item item = source.getItem(id); | |||||
final Item added = saved.addItem(id); | |||||
// "manual" copy of the properties we want | // "manual" copy of the properties we want | ||||
Property p = added.getItemProperty(PROPERTY_SPECIES); | Property p = added.getItemProperty(PROPERTY_SPECIES); | ||||
p.setValue(item.getItemProperty(PROPERTY_SPECIES) | p.setValue(item.getItemProperty(PROPERTY_SPECIES) | ||||
} else if (b == hireSelected) { | } else if (b == hireSelected) { | ||||
// loop each selected and set property HIRED to true | // loop each selected and set property HIRED to true | ||||
int s = 0; | int s = 0; | ||||
Set selected = (Set) source.getValue(); | |||||
for (Iterator it = selected.iterator(); it.hasNext();) { | |||||
Object id = it.next(); | |||||
final Set selected = (Set) source.getValue(); | |||||
for (final Iterator it = selected.iterator(); it.hasNext();) { | |||||
final Object id = it.next(); | |||||
Item item = source.getItem(id); | Item item = source.getItem(id); | ||||
Property p = item.getItemProperty(PROPERTY_HIRED); | |||||
final Property p = item.getItemProperty(PROPERTY_HIRED); | |||||
if (p.getValue() == Boolean.FALSE) { | if (p.getValue() == Boolean.FALSE) { | ||||
p.setValue(Boolean.TRUE); | p.setValue(Boolean.TRUE); | ||||
source.requestRepaint(); | source.requestRepaint(); | ||||
} else { | } else { | ||||
// loop trough selected and delete | // loop trough selected and delete | ||||
int s = 0; | int s = 0; | ||||
Set selected = (Set) source.getValue(); | |||||
for (Iterator it = selected.iterator(); it.hasNext();) { | |||||
Object id = it.next(); | |||||
final Set selected = (Set) source.getValue(); | |||||
for (final Iterator it = selected.iterator(); it.hasNext();) { | |||||
final Object id = it.next(); | |||||
if (source.containsId(id)) { | if (source.containsId(id)) { | ||||
s++; | s++; | ||||
source.removeItem(id); | source.removeItem(id); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import com.itmill.toolkit.data.Item; | import com.itmill.toolkit.data.Item; | ||||
import com.itmill.toolkit.data.Property; | import com.itmill.toolkit.data.Property; | ||||
import com.itmill.toolkit.data.Property.ValueChangeEvent; | import com.itmill.toolkit.data.Property.ValueChangeEvent; | ||||
import com.itmill.toolkit.event.Action; | import com.itmill.toolkit.event.Action; | ||||
import com.itmill.toolkit.ui.AbstractSelect; | |||||
import com.itmill.toolkit.ui.CustomComponent; | import com.itmill.toolkit.ui.CustomComponent; | ||||
import com.itmill.toolkit.ui.Label; | import com.itmill.toolkit.ui.Label; | ||||
import com.itmill.toolkit.ui.OrderedLayout; | import com.itmill.toolkit.ui.OrderedLayout; | ||||
TextField editor; | TextField editor; | ||||
public TreeExample() { | public TreeExample() { | ||||
OrderedLayout main = new OrderedLayout( | |||||
final OrderedLayout main = new OrderedLayout( | |||||
OrderedLayout.ORIENTATION_HORIZONTAL); | OrderedLayout.ORIENTATION_HORIZONTAL); | ||||
main.setMargin(true); | main.setMargin(true); | ||||
setCompositionRoot(main); | setCompositionRoot(main); | ||||
// we'll use a property for caption instead of the item id ("value"), | // we'll use a property for caption instead of the item id ("value"), | ||||
// so that multiple items can have the same caption | // so that multiple items can have the same caption | ||||
tree.addContainerProperty(CAPTION_PROPERTY, String.class, ""); | tree.addContainerProperty(CAPTION_PROPERTY, String.class, ""); | ||||
tree.setItemCaptionMode(Tree.ITEM_CAPTION_MODE_PROPERTY); | |||||
tree.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY); | |||||
tree.setItemCaptionPropertyId(CAPTION_PROPERTY); | tree.setItemCaptionPropertyId(CAPTION_PROPERTY); | ||||
for (int i = 1; i <= 3; i++) { | for (int i = 1; i <= 3; i++) { | ||||
Object id = addCaptionedItem("Section " + i, null); | |||||
final Object id = addCaptionedItem("Section " + i, null); | |||||
tree.expandItem(id); | tree.expandItem(id); | ||||
addCaptionedItem("Team A", id); | addCaptionedItem("Team A", id); | ||||
addCaptionedItem("Team B", id); | addCaptionedItem("Team B", id); | ||||
tree.removeItem(target); | tree.removeItem(target); | ||||
} else { | } else { | ||||
// Add | // Add | ||||
Object id = addCaptionedItem("New Item", target); | |||||
final Object id = addCaptionedItem("New Item", target); | |||||
tree.expandItem(target); | tree.expandItem(target); | ||||
tree.setValue(id); | tree.setValue(id); | ||||
editor.focus(); | editor.focus(); | ||||
} | } | ||||
public void valueChange(ValueChangeEvent event) { | public void valueChange(ValueChangeEvent event) { | ||||
Object id = tree.getValue(); // selected item id | |||||
final Object id = tree.getValue(); // selected item id | |||||
if (event.getProperty() == tree) { | if (event.getProperty() == tree) { | ||||
// a Tree item was (un) selected | // a Tree item was (un) selected | ||||
if (id == null) { | if (id == null) { | ||||
editor.removeListener(this); | editor.removeListener(this); | ||||
// enable TextField and update value | // enable TextField and update value | ||||
editor.setEnabled(true); | editor.setEnabled(true); | ||||
Item item = tree.getItem(id); | |||||
final Item item = tree.getItem(id); | |||||
editor.setValue(item.getItemProperty(CAPTION_PROPERTY) | editor.setValue(item.getItemProperty(CAPTION_PROPERTY) | ||||
.getValue()); | .getValue()); | ||||
// listen for TextField changes | // listen for TextField changes | ||||
} else { | } else { | ||||
// TextField | // TextField | ||||
if (id != null) { | if (id != null) { | ||||
Item item = tree.getItem(id); | |||||
Property p = item.getItemProperty(CAPTION_PROPERTY); | |||||
final Item item = tree.getItem(id); | |||||
final Property p = item.getItemProperty(CAPTION_PROPERTY); | |||||
p.setValue(editor.getValue()); | p.setValue(editor.getValue()); | ||||
tree.requestRepaint(); | tree.requestRepaint(); | ||||
} | } | ||||
*/ | */ | ||||
private Object addCaptionedItem(String caption, Object parent) { | private Object addCaptionedItem(String caption, Object parent) { | ||||
// add item, let tree decide id | // add item, let tree decide id | ||||
Object id = tree.addItem(); | |||||
final Object id = tree.addItem(); | |||||
// get the created item | // get the created item | ||||
Item item = tree.getItem(id); | |||||
final Item item = tree.getItem(id); | |||||
// set our "caption" property | // set our "caption" property | ||||
Property p = item.getItemProperty(CAPTION_PROPERTY); | |||||
final Property p = item.getItemProperty(CAPTION_PROPERTY); | |||||
p.setValue(caption); | p.setValue(caption); | ||||
if (parent != null) { | if (parent != null) { | ||||
tree.setParent(id, parent); | tree.setParent(id, parent); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import com.itmill.toolkit.data.Property.ValueChangeEvent; | import com.itmill.toolkit.data.Property.ValueChangeEvent; | ||||
public class ValueInputExample extends CustomComponent { | public class ValueInputExample extends CustomComponent { | ||||
public ValueInputExample() { | public ValueInputExample() { | ||||
OrderedLayout main = new OrderedLayout(); | |||||
final OrderedLayout main = new OrderedLayout(); | |||||
main.setMargin(true); | main.setMargin(true); | ||||
setCompositionRoot(main); | setCompositionRoot(main); | ||||
// listener that shows a value change notification | // listener that shows a value change notification | ||||
Field.ValueChangeListener listener = new Field.ValueChangeListener() { | |||||
final Field.ValueChangeListener listener = new Field.ValueChangeListener() { | |||||
public void valueChange(ValueChangeEvent event) { | public void valueChange(ValueChangeEvent event) { | ||||
getWindow().showNotification("Received", | getWindow().showNotification("Received", | ||||
"<pre>" + event.getProperty().getValue() + "</pre>", | "<pre>" + event.getProperty().getValue() + "</pre>", | ||||
slider.addListener(new Slider.ValueChangeListener() { | slider.addListener(new Slider.ValueChangeListener() { | ||||
public void valueChange(ValueChangeEvent event) { | public void valueChange(ValueChangeEvent event) { | ||||
// update caption when value changes | // update caption when value changes | ||||
Slider s = (Slider) event.getProperty(); | |||||
final Slider s = (Slider) event.getProperty(); | |||||
s.setCaption("Value: " + s.getValue()); | s.setCaption("Value: " + s.getValue()); | ||||
} | } | ||||
}); | }); | ||||
try { | try { | ||||
slider.setValue(20); | slider.setValue(20); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); | ||||
} | } | ||||
left.addComponent(slider); | left.addComponent(slider); | ||||
slider.addListener(new Slider.ValueChangeListener() { | slider.addListener(new Slider.ValueChangeListener() { | ||||
public void valueChange(ValueChangeEvent event) { | public void valueChange(ValueChangeEvent event) { | ||||
// update caption when value changes | // update caption when value changes | ||||
Slider s = (Slider) event.getProperty(); | |||||
final Slider s = (Slider) event.getProperty(); | |||||
s.setCaption("Value: " + s.getValue()); | s.setCaption("Value: " + s.getValue()); | ||||
} | } | ||||
}); | }); | ||||
try { | try { | ||||
slider.setValue(0.5); | slider.setValue(0.5); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); | ||||
} | } | ||||
left.addComponent(slider); | left.addComponent(slider); |
/** | |||||
* | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | */ | ||||
package com.itmill.toolkit.demo.featurebrowser; | package com.itmill.toolkit.demo.featurebrowser; | ||||
import java.net.URL; | import java.net.URL; | ||||
private URL windowUrl = null; | private URL windowUrl = null; | ||||
public WindowingExample() { | public WindowingExample() { | ||||
OrderedLayout main = new OrderedLayout(); | |||||
final OrderedLayout main = new OrderedLayout(); | |||||
main.setMargin(true); | main.setMargin(true); | ||||
setCompositionRoot(main); | setCompositionRoot(main); | ||||
Label l = new Label(txt); | |||||
final Label l = new Label(txt); | |||||
l.setContentMode(Label.CONTENT_XHTML); | l.setContentMode(Label.CONTENT_XHTML); | ||||
main.addComponent(l); | main.addComponent(l); | ||||
main.addComponent(new Button("Create a new subwindow", | main.addComponent(new Button("Create a new subwindow", | ||||
new Button.ClickListener() { | new Button.ClickListener() { | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
Window w = new Window("Subwindow"); | |||||
Label l = new Label(txt); | |||||
final Window w = new Window("Subwindow"); | |||||
final Label l = new Label(txt); | |||||
l.setContentMode(Label.CONTENT_XHTML); | l.setContentMode(Label.CONTENT_XHTML); | ||||
w.addComponent(l); | w.addComponent(l); | ||||
getApplication().getMainWindow().addWindow(w); | getApplication().getMainWindow().addWindow(w); | ||||
main.addComponent(new Button("Create a new modal window", | main.addComponent(new Button("Create a new modal window", | ||||
new Button.ClickListener() { | new Button.ClickListener() { | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
Window w = new Window("Modal window"); | |||||
final Window w = new Window("Modal window"); | |||||
w.setModal(true); | w.setModal(true); | ||||
Label l = new Label(txt); | |||||
final Label l = new Label(txt); | |||||
l.setContentMode(Label.CONTENT_XHTML); | l.setContentMode(Label.CONTENT_XHTML); | ||||
w.addComponent(l); | w.addComponent(l); | ||||
getApplication().getMainWindow().addWindow(w); | getApplication().getMainWindow().addWindow(w); | ||||
new Button.ClickListener() { | new Button.ClickListener() { | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
if (windowUrl == null) { | if (windowUrl == null) { | ||||
Window w = new Window("Subwindow"); | |||||
Label l = new Label(txt); | |||||
final Window w = new Window("Subwindow"); | |||||
final Label l = new Label(txt); | |||||
l.setContentMode(Label.CONTENT_XHTML); | l.setContentMode(Label.CONTENT_XHTML); | ||||
w.addComponent(l); | w.addComponent(l); | ||||
getApplication().addWindow(w); | getApplication().addWindow(w); | ||||
"Create a new application-level window, with it's own state", | "Create a new application-level window, with it's own state", | ||||
new Button.ClickListener() { | new Button.ClickListener() { | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
Window w = new Window("Subwindow"); | |||||
final Window w = new Window("Subwindow"); | |||||
getApplication().addWindow(w); | getApplication().addWindow(w); | ||||
Label l = new Label("Each opened window has its own" | |||||
+ " name, and is accessed trough its own uri."); | |||||
final Label l = new Label( | |||||
"Each opened window has its own" | |||||
+ " name, and is accessed trough its own uri."); | |||||
l.setCaption("Window " + w.getName()); | l.setCaption("Window " + w.getName()); | ||||
w.addComponent(l); | w.addComponent(l); | ||||
getApplication().getMainWindow().open( | getApplication().getMainWindow().open( |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.reservation; | package com.itmill.toolkit.demo.reservation; | ||||
import java.sql.SQLException; | import java.sql.SQLException; | ||||
* Initialize Application. Demo components are added to main window. | * Initialize Application. Demo components are added to main window. | ||||
*/ | */ | ||||
public void init() { | public void init() { | ||||
Window main = new Window("Calendar demo"); | |||||
final Window main = new Window("Calendar demo"); | |||||
setMainWindow(main); | setMainWindow(main); | ||||
main.setLayout(new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL)); | main.setLayout(new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL)); | ||||
from.addListener(new ValueChangeListener() { | from.addListener(new ValueChangeListener() { | ||||
public void valueChange(ValueChangeEvent event) { | public void valueChange(ValueChangeEvent event) { | ||||
Date fd = (Date) from.getValue(); | |||||
Date td = (Date) to.getValue(); | |||||
final Date fd = (Date) from.getValue(); | |||||
final Date td = (Date) to.getValue(); | |||||
if (fd == null) { | if (fd == null) { | ||||
to.setValue(null); | to.setValue(null); | ||||
to.setEnabled(false); | to.setEnabled(false); | ||||
*/ | */ | ||||
private void initCalendars() { | private void initCalendars() { | ||||
try { | try { | ||||
QueryContainer qc = new QueryContainer("SELECT * FROM " | |||||
final QueryContainer qc = new QueryContainer("SELECT * FROM " | |||||
+ SampleCalendarDatabase.DB_TABLE_NAME, sampleDatabase | + SampleCalendarDatabase.DB_TABLE_NAME, sampleDatabase | ||||
.getConnection()); | .getConnection()); | ||||
from.setContainerDataSource(qc); | from.setContainerDataSource(qc); | ||||
to.setContainerDataSource(qc); | to.setContainerDataSource(qc); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
/* | /* |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.reservation; | package com.itmill.toolkit.demo.reservation; | ||||
import java.util.Collection; | import java.util.Collection; | ||||
// Check old propertyIds | // Check old propertyIds | ||||
if (itemEndPropertyId != null) { | if (itemEndPropertyId != null) { | ||||
Class c = dataSource.getType(itemEndPropertyId); | |||||
final Class c = dataSource.getType(itemEndPropertyId); | |||||
if (!Date.class.isAssignableFrom(c)) { | if (!Date.class.isAssignableFrom(c)) { | ||||
itemEndPropertyId = null; | itemEndPropertyId = null; | ||||
} | } | ||||
} | } | ||||
if (itemNotimePropertyId != null) { | if (itemNotimePropertyId != null) { | ||||
Class c = dataSource.getType(itemNotimePropertyId); | |||||
final Class c = dataSource.getType(itemNotimePropertyId); | |||||
if (!Boolean.class.isAssignableFrom(c)) { | if (!Boolean.class.isAssignableFrom(c)) { | ||||
itemNotimePropertyId = null; | itemNotimePropertyId = null; | ||||
} | } | ||||
} | } | ||||
if (itemStartPropertyId != null) { | if (itemStartPropertyId != null) { | ||||
Class c = dataSource.getType(itemStartPropertyId); | |||||
final Class c = dataSource.getType(itemStartPropertyId); | |||||
if (Date.class.isAssignableFrom(c)) { | if (Date.class.isAssignableFrom(c)) { | ||||
// All we _really_ need is one date | // All we _really_ need is one date | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
// We need at least one Date | // We need at least one Date | ||||
Collection ids = dataSource.getContainerPropertyIds(); | |||||
for (Iterator it = ids.iterator(); it.hasNext();) { | |||||
Object id = it.next(); | |||||
Class c = dataSource.getType(id); | |||||
final Collection ids = dataSource.getContainerPropertyIds(); | |||||
for (final Iterator it = ids.iterator(); it.hasNext();) { | |||||
final Object id = it.next(); | |||||
final Class c = dataSource.getType(id); | |||||
if (Date.class.isAssignableFrom(c)) { | if (Date.class.isAssignableFrom(c)) { | ||||
itemStartPropertyId = id; | itemStartPropertyId = id; | ||||
return true; | return true; | ||||
// TODO send one month now, the rest via lazyloading | // TODO send one month now, the rest via lazyloading | ||||
int month = new Date().getMonth(); | int month = new Date().getMonth(); | ||||
Object value = getValue(); | |||||
final Object value = getValue(); | |||||
if (value != null && value instanceof Date) { | if (value != null && value instanceof Date) { | ||||
month = ((Date) value).getMonth(); | month = ((Date) value).getMonth(); | ||||
} | } | ||||
for (Iterator it = dataSource.getItemIds().iterator(); it.hasNext();) { | |||||
Object itemId = it.next(); | |||||
Item item = dataSource.getItem(itemId); | |||||
for (final Iterator it = dataSource.getItemIds().iterator(); it | |||||
.hasNext();) { | |||||
final Object itemId = it.next(); | |||||
final Item item = dataSource.getItem(itemId); | |||||
Property p = item.getItemProperty(itemStartPropertyId); | Property p = item.getItemProperty(itemStartPropertyId); | ||||
Date start = (Date) p.getValue(); | Date start = (Date) p.getValue(); | ||||
Date end = start; // assume same day | Date end = start; // assume same day | ||||
if (end == null) { | if (end == null) { | ||||
end = start; | end = start; | ||||
} else if (end.before(start)) { | } else if (end.before(start)) { | ||||
Date tmp = start; | |||||
final Date tmp = start; | |||||
start = end; | start = end; | ||||
end = tmp; | end = tmp; | ||||
} | } | ||||
target.addAttribute("id", itemId.hashCode()); | target.addAttribute("id", itemId.hashCode()); | ||||
if (itemStyleNamePropertyId != null) { | if (itemStyleNamePropertyId != null) { | ||||
p = item.getItemProperty(itemStyleNamePropertyId); | p = item.getItemProperty(itemStyleNamePropertyId); | ||||
String styleName = (String) p.getValue(); | |||||
final String styleName = (String) p.getValue(); | |||||
target.addAttribute("styleName", styleName); | target.addAttribute("styleName", styleName); | ||||
} | } | ||||
target.addAttribute("start", "" + start.getTime()); | target.addAttribute("start", "" + start.getTime()); | ||||
} | } | ||||
if (itemTitlePropertyId != null) { | if (itemTitlePropertyId != null) { | ||||
p = item.getItemProperty(itemTitlePropertyId); | p = item.getItemProperty(itemTitlePropertyId); | ||||
Object val = p.getValue(); | |||||
final Object val = p.getValue(); | |||||
if (val != null) { | if (val != null) { | ||||
target.addAttribute("title", val.toString()); | target.addAttribute("title", val.toString()); | ||||
} | } | ||||
} | } | ||||
if (itemDescriptionPropertyId != null) { | if (itemDescriptionPropertyId != null) { | ||||
p = item.getItemProperty(itemDescriptionPropertyId); | p = item.getItemProperty(itemDescriptionPropertyId); | ||||
Object val = p.getValue(); | |||||
final Object val = p.getValue(); | |||||
if (val != null) { | if (val != null) { | ||||
target.addAttribute("description", val | target.addAttribute("description", val | ||||
.toString()); | .toString()); | ||||
} | } | ||||
if (itemNotimePropertyId != null) { | if (itemNotimePropertyId != null) { | ||||
p = item.getItemProperty(itemNotimePropertyId); | p = item.getItemProperty(itemNotimePropertyId); | ||||
Object val = p.getValue(); | |||||
final Object val = p.getValue(); | |||||
if (val != null) { | if (val != null) { | ||||
target.addAttribute("notime", ((Boolean) val) | target.addAttribute("notime", ((Boolean) val) | ||||
.booleanValue()); | .booleanValue()); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.reservation; | package com.itmill.toolkit.demo.reservation; | ||||
import java.awt.geom.Point2D; | import java.awt.geom.Point2D; | ||||
public class GoogleMap extends AbstractComponent implements Sizeable, | public class GoogleMap extends AbstractComponent implements Sizeable, | ||||
Container.Viewer { | Container.Viewer { | ||||
private String TAG_MARKERS = "markers"; | |||||
private String TAG_MARKER = "marker"; | |||||
private final String TAG_MARKERS = "markers"; | |||||
private final String TAG_MARKER = "marker"; | |||||
private int width = 400; | private int width = 400; | ||||
private int height = 300; | private int height = 300; | ||||
private int zoomLevel = 15; | private int zoomLevel = 15; | ||||
if (dataSource != null) { | if (dataSource != null) { | ||||
target.startTag(TAG_MARKERS); | target.startTag(TAG_MARKERS); | ||||
Collection itemIds = dataSource.getItemIds(); | |||||
for (Iterator it = itemIds.iterator(); it.hasNext();) { | |||||
Object itemId = it.next(); | |||||
Item item = dataSource.getItem(itemId); | |||||
final Collection itemIds = dataSource.getItemIds(); | |||||
for (final Iterator it = itemIds.iterator(); it.hasNext();) { | |||||
final Object itemId = it.next(); | |||||
final Item item = dataSource.getItem(itemId); | |||||
Property p = item.getItemProperty(getItemMarkerXPropertyId()); | Property p = item.getItemProperty(getItemMarkerXPropertyId()); | ||||
Double x = (Double) (p != null ? p.getValue() : null); | |||||
final Double x = (Double) (p != null ? p.getValue() : null); | |||||
p = item.getItemProperty(getItemMarkerYPropertyId()); | p = item.getItemProperty(getItemMarkerYPropertyId()); | ||||
Double y = (Double) (p != null ? p.getValue() : null); | |||||
final Double y = (Double) (p != null ? p.getValue() : null); | |||||
if (x == null || y == null) { | if (x == null || y == null) { | ||||
continue; | continue; | ||||
} | } | ||||
target.addAttribute("x", x.doubleValue()); | target.addAttribute("x", x.doubleValue()); | ||||
target.addAttribute("y", y.doubleValue()); | target.addAttribute("y", y.doubleValue()); | ||||
p = item.getItemProperty(getItemMarkerHtmlPropertyId()); | p = item.getItemProperty(getItemMarkerHtmlPropertyId()); | ||||
String h = (String) (p != null ? p.getValue() : null); | |||||
final String h = (String) (p != null ? p.getValue() : null); | |||||
target.addAttribute("html", h); | target.addAttribute("html", h); | ||||
target.endTag(TAG_MARKER); | target.endTag(TAG_MARKER); | ||||
} | } | ||||
if (dataSource == null) { | if (dataSource == null) { | ||||
initDataSource(); | initDataSource(); | ||||
} | } | ||||
Object markerId = dataSource.addItem(); | |||||
final Object markerId = dataSource.addItem(); | |||||
if (markerId == null) { | if (markerId == null) { | ||||
return null; | return null; | ||||
} | } | ||||
Item marker = dataSource.getItem(markerId); | |||||
final Item marker = dataSource.getItem(markerId); | |||||
Property p = marker.getItemProperty(getItemMarkerXPropertyId()); | Property p = marker.getItemProperty(getItemMarkerXPropertyId()); | ||||
p.setValue(new Double(location.x)); | p.setValue(new Double(location.x)); | ||||
p = marker.getItemProperty(getItemMarkerYPropertyId()); | p = marker.getItemProperty(getItemMarkerYPropertyId()); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.reservation; | package com.itmill.toolkit.demo.reservation; | ||||
import java.awt.geom.Point2D; | import java.awt.geom.Point2D; | ||||
db.generateDemoUser(); | db.generateDemoUser(); | ||||
db.generateReservations(); | db.generateReservations(); | ||||
Window mainWindow = new Window("Reservr"); | |||||
final Window mainWindow = new Window("Reservr"); | |||||
setMainWindow(mainWindow); | setMainWindow(mainWindow); | ||||
setTheme("reservr"); | setTheme("reservr"); | ||||
TabSheet mainTabs = new TabSheet(); | |||||
final TabSheet mainTabs = new TabSheet(); | |||||
mainWindow.addComponent(mainTabs); | mainWindow.addComponent(mainTabs); | ||||
OrderedLayout reservationTab = new OrderedLayout(); | |||||
final OrderedLayout reservationTab = new OrderedLayout(); | |||||
mainTabs.addTab(reservationTab, "Make reservation", null); | mainTabs.addTab(reservationTab, "Make reservation", null); | ||||
resourcePanel = new ResourceSelectorPanel("Resources"); | resourcePanel = new ResourceSelectorPanel("Resources"); | ||||
this, "selectedResourcesChanged"); | this, "selectedResourcesChanged"); | ||||
reservationTab.addComponent(resourcePanel); | reservationTab.addComponent(resourcePanel); | ||||
Panel reservationPanel = new Panel("Reservation", new OrderedLayout( | |||||
OrderedLayout.ORIENTATION_HORIZONTAL)); | |||||
final Panel reservationPanel = new Panel("Reservation", | |||||
new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL)); | |||||
reservationPanel.addStyleName(Panel.STYLE_LIGHT); | reservationPanel.addStyleName(Panel.STYLE_LIGHT); | ||||
reservationPanel.getLayout().setMargin(true); | reservationPanel.getLayout().setMargin(true); | ||||
reservationTab.addComponent(reservationPanel); | reservationTab.addComponent(reservationPanel); | ||||
OrderedLayout infoLayout = new OrderedLayout(); | |||||
final OrderedLayout infoLayout = new OrderedLayout(); | |||||
infoLayout.setMargin(false, true, false, false); | infoLayout.setMargin(false, true, false, false); | ||||
reservationPanel.addComponent(infoLayout); | reservationPanel.addComponent(infoLayout); | ||||
resourceName = new Label("From the list above"); | resourceName = new Label("From the list above"); | ||||
map.setContainerDataSource(db.getResources(null)); | map.setContainerDataSource(db.getResources(null)); | ||||
infoLayout.addComponent(map); | infoLayout.addComponent(map); | ||||
Calendar from = Calendar.getInstance(); | |||||
final Calendar from = Calendar.getInstance(); | |||||
from.add(Calendar.HOUR, 1); | from.add(Calendar.HOUR, 1); | ||||
from.set(Calendar.MINUTE, 0); | from.set(Calendar.MINUTE, 0); | ||||
from.set(Calendar.SECOND, 0); | from.set(Calendar.SECOND, 0); | ||||
initCalendarFieldPropertyIds(reservedFrom); | initCalendarFieldPropertyIds(reservedFrom); | ||||
reservationPanel.addComponent(reservedFrom); | reservationPanel.addComponent(reservedFrom); | ||||
Label arrowLabel = new Label("»"); | |||||
final Label arrowLabel = new Label("»"); | |||||
arrowLabel.setContentMode(Label.CONTENT_XHTML); | arrowLabel.setContentMode(Label.CONTENT_XHTML); | ||||
arrowLabel.setStyleName("arrow"); | arrowLabel.setStyleName("arrow"); | ||||
reservationPanel.addComponent(arrowLabel); | reservationPanel.addComponent(arrowLabel); | ||||
Calendar to = Calendar.getInstance(); | |||||
final Calendar to = Calendar.getInstance(); | |||||
to.setTime(from.getTime()); | to.setTime(from.getTime()); | ||||
to.add(Calendar.MILLISECOND, (int) DEFAULT_GAP_MILLIS); | to.add(Calendar.MILLISECOND, (int) DEFAULT_GAP_MILLIS); | ||||
reservedTo = new CalendarField("To"); | reservedTo = new CalendarField("To"); | ||||
reservedFrom.addListener(new ValueChangeListener() { | reservedFrom.addListener(new ValueChangeListener() { | ||||
public void valueChange(ValueChangeEvent event) { | public void valueChange(ValueChangeEvent event) { | ||||
Date fd = (Date) reservedFrom.getValue(); | |||||
final Date fd = (Date) reservedFrom.getValue(); | |||||
if (fd == null) { | if (fd == null) { | ||||
reservedTo.setValue(null); | reservedTo.setValue(null); | ||||
reservedTo.setEnabled(false); | reservedTo.setEnabled(false); | ||||
} | } | ||||
reservedTo.setMinimumDate(new Date(fd.getTime() | reservedTo.setMinimumDate(new Date(fd.getTime() | ||||
+ DEFAULT_GAP_MILLIS)); | + DEFAULT_GAP_MILLIS)); | ||||
Calendar to = Calendar.getInstance(); | |||||
final Calendar to = Calendar.getInstance(); | |||||
to.setTime(fd); | to.setTime(fd); | ||||
to.add(Calendar.MILLISECOND, (int) currentGapMillis); | to.add(Calendar.MILLISECOND, (int) currentGapMillis); | ||||
reservedTo.setValue(to.getTime()); | reservedTo.setValue(to.getTime()); | ||||
}); | }); | ||||
reservedTo.addListener(new ValueChangeListener() { | reservedTo.addListener(new ValueChangeListener() { | ||||
public void valueChange(ValueChangeEvent event) { | public void valueChange(ValueChangeEvent event) { | ||||
Date from = (Date) reservedFrom.getValue(); | |||||
Date to = (Date) reservedTo.getValue(); | |||||
final Date from = (Date) reservedFrom.getValue(); | |||||
final Date to = (Date) reservedTo.getValue(); | |||||
currentGapMillis = to.getTime() - from.getTime(); | currentGapMillis = to.getTime() - from.getTime(); | ||||
if (currentGapMillis <= 0) { | if (currentGapMillis <= 0) { | ||||
Calendar t = Calendar.getInstance(); | |||||
final Calendar t = Calendar.getInstance(); | |||||
t.setTime(from); | t.setTime(from); | ||||
t.add(Calendar.MILLISECOND, (int) DEFAULT_GAP_MILLIS); | t.add(Calendar.MILLISECOND, (int) DEFAULT_GAP_MILLIS); | ||||
reservedTo.setValue(t.getTime()); | reservedTo.setValue(t.getTime()); | ||||
} | } | ||||
}); | }); | ||||
OrderedLayout allLayout = new OrderedLayout( | |||||
final OrderedLayout allLayout = new OrderedLayout( | |||||
OrderedLayout.ORIENTATION_HORIZONTAL); | OrderedLayout.ORIENTATION_HORIZONTAL); | ||||
allLayout.addStyleName(Panel.STYLE_LIGHT); | allLayout.addStyleName(Panel.STYLE_LIGHT); | ||||
allLayout.setMargin(true); | allLayout.setMargin(true); | ||||
public void makeReservation() { | public void makeReservation() { | ||||
try { | try { | ||||
Item resource = getActiveResource(); | |||||
final Item resource = getActiveResource(); | |||||
if (resource != null) { | if (resource != null) { | ||||
db.addReservation(resource, 0, (Date) reservedFrom.getValue(), | db.addReservation(resource, 0, (Date) reservedFrom.getValue(), | ||||
(Date) reservedTo.getValue(), (String) description | (Date) reservedTo.getValue(), (String) description | ||||
"Please select a resource (or category) to reserve.", | "Please select a resource (or category) to reserve.", | ||||
Notification.TYPE_WARNING_MESSAGE); | Notification.TYPE_WARNING_MESSAGE); | ||||
} | } | ||||
} catch (ResourceNotAvailableException e) { | |||||
} catch (final ResourceNotAvailableException e) { | |||||
getMainWindow() | getMainWindow() | ||||
.showNotification( | .showNotification( | ||||
"Not available!", | "Not available!", | ||||
} | } | ||||
private Item getActiveResource() throws ResourceNotAvailableException { | private Item getActiveResource() throws ResourceNotAvailableException { | ||||
List rids = resourcePanel.getSelectedResources(); | |||||
final List rids = resourcePanel.getSelectedResources(); | |||||
if (rids != null && rids.size() > 0) { | if (rids != null && rids.size() > 0) { | ||||
for (Iterator it = rids.iterator(); it.hasNext();) { | |||||
Item resource = (Item) it.next(); | |||||
int id = ((Integer) resource.getItemProperty( | |||||
for (final Iterator it = rids.iterator(); it.hasNext();) { | |||||
final Item resource = (Item) it.next(); | |||||
final int id = ((Integer) resource.getItemProperty( | |||||
SampleDB.Resource.PROPERTY_ID_ID).getValue()) | SampleDB.Resource.PROPERTY_ID_ID).getValue()) | ||||
.intValue(); | .intValue(); | ||||
if (db.isAvailableResource(id, (Date) reservedFrom.getValue(), | if (db.isAvailableResource(id, (Date) reservedFrom.getValue(), | ||||
} | } | ||||
private void refreshReservations(boolean alsoResources) { | private void refreshReservations(boolean alsoResources) { | ||||
Container reservations = db.getReservations(resourcePanel | |||||
final Container reservations = db.getReservations(resourcePanel | |||||
.getSelectedResources()); | .getSelectedResources()); | ||||
reservedFrom.setContainerDataSource(reservations); | reservedFrom.setContainerDataSource(reservations); | ||||
reservedTo.setContainerDataSource(reservations); | reservedTo.setContainerDataSource(reservations); | ||||
if (alsoResources) { | if (alsoResources) { | ||||
refreshSelectedResources(); | refreshSelectedResources(); | ||||
} | } | ||||
Container allReservations = db.getReservations(null); | |||||
final Container allReservations = db.getReservations(null); | |||||
allTable.setContainerDataSource(allReservations); | allTable.setContainerDataSource(allReservations); | ||||
if (allReservations != null && allReservations.size() > 0) { | if (allReservations != null && allReservations.size() > 0) { | ||||
allTable.setVisibleColumns(new Object[] { | allTable.setVisibleColumns(new Object[] { | ||||
Item resource = null; | Item resource = null; | ||||
try { | try { | ||||
resource = getActiveResource(); | resource = getActiveResource(); | ||||
} catch (ResourceNotAvailableException e) { | |||||
} catch (final ResourceNotAvailableException e) { | |||||
getMainWindow().showNotification("Not available", | getMainWindow().showNotification("Not available", | ||||
"Please choose another resource or time period.", | "Please choose another resource or time period.", | ||||
Notification.TYPE_HUMANIZED_MESSAGE); | Notification.TYPE_HUMANIZED_MESSAGE); | ||||
resourceName.setCaption(name); | resourceName.setCaption(name); | ||||
resourceName.setValue(desc); | resourceName.setValue(desc); | ||||
// Put all resources on map (may be many if category was selected) | // Put all resources on map (may be many if category was selected) | ||||
LinkedList srs = resourcePanel.getSelectedResources(); | |||||
for (Iterator it = srs.iterator(); it.hasNext();) { | |||||
final LinkedList srs = resourcePanel.getSelectedResources(); | |||||
for (final Iterator it = srs.iterator(); it.hasNext();) { | |||||
resource = (Item) it.next(); | resource = (Item) it.next(); | ||||
name = (String) resource.getItemProperty( | name = (String) resource.getItemProperty( | ||||
SampleDB.Resource.PROPERTY_ID_NAME).getValue(); | SampleDB.Resource.PROPERTY_ID_NAME).getValue(); | ||||
desc = (String) resource.getItemProperty( | desc = (String) resource.getItemProperty( | ||||
SampleDB.Resource.PROPERTY_ID_DESCRIPTION).getValue(); | SampleDB.Resource.PROPERTY_ID_DESCRIPTION).getValue(); | ||||
Double x = (Double) resource.getItemProperty( | |||||
final Double x = (Double) resource.getItemProperty( | |||||
SampleDB.Resource.PROPERTY_ID_LOCATIONX).getValue(); | SampleDB.Resource.PROPERTY_ID_LOCATIONX).getValue(); | ||||
Double y = (Double) resource.getItemProperty( | |||||
final Double y = (Double) resource.getItemProperty( | |||||
SampleDB.Resource.PROPERTY_ID_LOCATIONY).getValue(); | SampleDB.Resource.PROPERTY_ID_LOCATIONY).getValue(); | ||||
if (x != null && y != null) { | if (x != null && y != null) { | ||||
map.addMarker(name + "<br/>" + desc, new Point2D.Double(x | map.addMarker(name + "<br/>" + desc, new Point2D.Double(x |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.reservation; | package com.itmill.toolkit.demo.reservation; | ||||
public class ResourceNotAvailableException extends Exception { | public class ResourceNotAvailableException extends Exception { |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.reservation; | package com.itmill.toolkit.demo.reservation; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
public class ResourceSelectorPanel extends Panel implements | public class ResourceSelectorPanel extends Panel implements | ||||
Button.ClickListener { | Button.ClickListener { | ||||
private HashMap categoryLayouts = new HashMap(); | |||||
private HashMap categoryResources = new HashMap(); | |||||
private final HashMap categoryLayouts = new HashMap(); | |||||
private final HashMap categoryResources = new HashMap(); | |||||
private Container allResources; | private Container allResources; | ||||
private LinkedList selectedResources = null; | private LinkedList selectedResources = null; | ||||
categoryLayouts.clear(); | categoryLayouts.clear(); | ||||
categoryResources.clear(); | categoryResources.clear(); | ||||
if (resources != null && resources.size() > 0) { | if (resources != null && resources.size() > 0) { | ||||
for (Iterator it = resources.getItemIds().iterator(); it.hasNext();) { | |||||
Item resource = resources.getItem(it.next()); | |||||
Integer id = (Integer) resource.getItemProperty( | |||||
for (final Iterator it = resources.getItemIds().iterator(); it | |||||
.hasNext();) { | |||||
final Item resource = resources.getItem(it.next()); | |||||
final Integer id = (Integer) resource.getItemProperty( | |||||
SampleDB.Resource.PROPERTY_ID_ID).getValue(); | SampleDB.Resource.PROPERTY_ID_ID).getValue(); | ||||
String category = (String) resource.getItemProperty( | |||||
final String category = (String) resource.getItemProperty( | |||||
SampleDB.Resource.PROPERTY_ID_CATEGORY).getValue(); | SampleDB.Resource.PROPERTY_ID_CATEGORY).getValue(); | ||||
String name = (String) resource.getItemProperty( | |||||
final String name = (String) resource.getItemProperty( | |||||
SampleDB.Resource.PROPERTY_ID_NAME).getValue(); | SampleDB.Resource.PROPERTY_ID_NAME).getValue(); | ||||
String description = (String) resource.getItemProperty( | |||||
final String description = (String) resource.getItemProperty( | |||||
SampleDB.Resource.PROPERTY_ID_DESCRIPTION).getValue(); | SampleDB.Resource.PROPERTY_ID_DESCRIPTION).getValue(); | ||||
Button rButton = new Button(name, this); | |||||
final Button rButton = new Button(name, this); | |||||
rButton.setStyleName("link"); | rButton.setStyleName("link"); | ||||
rButton.setDescription(description); | rButton.setDescription(description); | ||||
rButton.setData(resource); | rButton.setData(resource); | ||||
categoryLayouts.put(category, resourceLayout); | categoryLayouts.put(category, resourceLayout); | ||||
resourceList = new LinkedList(); | resourceList = new LinkedList(); | ||||
categoryResources.put(category, resourceList); | categoryResources.put(category, resourceList); | ||||
Button cButton = new Button(category + " (any)", this); | |||||
final Button cButton = new Button(category + " (any)", this); | |||||
cButton.setStyleName("important-link"); | cButton.setStyleName("important-link"); | ||||
cButton.setData(category); | cButton.setData(category); | ||||
resourceLayout.addComponent(cButton); | resourceLayout.addComponent(cButton); | ||||
// Selects one initial categore, inpractice randomly | // Selects one initial categore, inpractice randomly | ||||
public void selectFirstCategory() { | public void selectFirstCategory() { | ||||
try { | try { | ||||
Object catId = categoryResources.keySet().iterator().next(); | |||||
LinkedList res = (LinkedList) categoryResources.get(catId); | |||||
Layout l = (Layout) categoryLayouts.get(catId); | |||||
Button catB = (Button) l.getComponentIterator().next(); | |||||
final Object catId = categoryResources.keySet().iterator().next(); | |||||
final LinkedList res = (LinkedList) categoryResources.get(catId); | |||||
final Layout l = (Layout) categoryLayouts.get(catId); | |||||
final Button catB = (Button) l.getComponentIterator().next(); | |||||
setSelectedResources(res); | setSelectedResources(res); | ||||
catB.setStyleName("selected-link"); | catB.setStyleName("selected-link"); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
e.printStackTrace(System.err); | e.printStackTrace(System.err); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
Object source = event.getSource(); | |||||
final Object source = event.getSource(); | |||||
if (source instanceof Button) { | if (source instanceof Button) { | ||||
Object data = ((Button) source).getData(); | |||||
String name = ((Button) source).getCaption(); | |||||
final Object data = ((Button) source).getData(); | |||||
final String name = ((Button) source).getCaption(); | |||||
resetStyles(); | resetStyles(); | ||||
if (data instanceof Item) { | if (data instanceof Item) { | ||||
LinkedList rlist = new LinkedList(); | |||||
final LinkedList rlist = new LinkedList(); | |||||
rlist.add(data); | rlist.add(data); | ||||
setSelectedResources(rlist); | setSelectedResources(rlist); | ||||
} else { | } else { | ||||
String category = (String) data; | |||||
LinkedList resources = (LinkedList) categoryResources | |||||
final String category = (String) data; | |||||
final LinkedList resources = (LinkedList) categoryResources | |||||
.get(category); | .get(category); | ||||
setSelectedResources(resources); | setSelectedResources(resources); | ||||
} | } | ||||
} | } | ||||
private void resetStyles() { | private void resetStyles() { | ||||
for (Iterator it = categoryLayouts.values().iterator(); it.hasNext();) { | |||||
Layout lo = (Layout) it.next(); | |||||
for (Iterator bit = lo.getComponentIterator(); bit.hasNext();) { | |||||
Button b = (Button) bit.next(); | |||||
for (final Iterator it = categoryLayouts.values().iterator(); it | |||||
.hasNext();) { | |||||
final Layout lo = (Layout) it.next(); | |||||
for (final Iterator bit = lo.getComponentIterator(); bit.hasNext();) { | |||||
final Button b = (Button) bit.next(); | |||||
if (b.getData() instanceof Item) { | if (b.getData() instanceof Item) { | ||||
b.setStyleName("link"); | b.setStyleName("link"); | ||||
} else { | } else { |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.reservation; | package com.itmill.toolkit.demo.reservation; | ||||
import java.sql.Connection; | import java.sql.Connection; | ||||
private void dropTables() { | private void dropTables() { | ||||
try { | try { | ||||
update("DROP TABLE " + Reservation.TABLE); | update("DROP TABLE " + Reservation.TABLE); | ||||
} catch (SQLException IGNORED) { | |||||
} catch (final SQLException IGNORED) { | |||||
// IGNORED, assuming it was not there | // IGNORED, assuming it was not there | ||||
} | } | ||||
try { | try { | ||||
update("DROP TABLE " + Resource.TABLE); | update("DROP TABLE " + Resource.TABLE); | ||||
} catch (SQLException IGNORED) { | |||||
} catch (final SQLException IGNORED) { | |||||
// IGNORED, assuming it was not there | // IGNORED, assuming it was not there | ||||
} | } | ||||
try { | try { | ||||
update("DROP TABLE " + User.TABLE); | update("DROP TABLE " + User.TABLE); | ||||
} catch (SQLException IGNORED) { | |||||
} catch (final SQLException IGNORED) { | |||||
// IGNORED, assuming it was not there | // IGNORED, assuming it was not there | ||||
} | } | ||||
} | } | ||||
try { | try { | ||||
Class.forName("org.hsqldb.jdbcDriver").newInstance(); | Class.forName("org.hsqldb.jdbcDriver").newInstance(); | ||||
connection = DriverManager.getConnection(DB_URL); | connection = DriverManager.getConnection(DB_URL); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
} | } | ||||
private void update(String expression) throws SQLException { | private void update(String expression) throws SQLException { | ||||
Statement st = null; | Statement st = null; | ||||
st = connection.createStatement(); | st = connection.createStatement(); | ||||
int i = st.executeUpdate(expression); | |||||
final int i = st.executeUpdate(expression); | |||||
if (i == -1) { | if (i == -1) { | ||||
System.out.println("SampleDatabase error : " + expression); | System.out.println("SampleDatabase error : " + expression); | ||||
} | } | ||||
String stmt = null; | String stmt = null; | ||||
stmt = CREATE_TABLE_RESOURCE; | stmt = CREATE_TABLE_RESOURCE; | ||||
update(stmt); | update(stmt); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
if (e.toString().indexOf("Table already exists") == -1) { | if (e.toString().indexOf("Table already exists") == -1) { | ||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
String stmt = null; | String stmt = null; | ||||
stmt = CREATE_TABLE_USER; | stmt = CREATE_TABLE_USER; | ||||
update(stmt); | update(stmt); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
if (e.toString().indexOf("Table already exists") == -1) { | if (e.toString().indexOf("Table already exists") == -1) { | ||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
String stmt = null; | String stmt = null; | ||||
stmt = CREATE_TABLE_RESERVATION; | stmt = CREATE_TABLE_RESERVATION; | ||||
update(stmt); | update(stmt); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
if (e.toString().indexOf("Table already exists") == -1) { | if (e.toString().indexOf("Table already exists") == -1) { | ||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
private String testDatabase() { | private String testDatabase() { | ||||
String result = null; | String result = null; | ||||
try { | try { | ||||
Statement stmt = connection.createStatement( | |||||
final Statement stmt = connection.createStatement( | |||||
ResultSet.TYPE_SCROLL_INSENSITIVE, | ResultSet.TYPE_SCROLL_INSENSITIVE, | ||||
ResultSet.CONCUR_UPDATABLE); | ResultSet.CONCUR_UPDATABLE); | ||||
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM " | |||||
final ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM " | |||||
+ Resource.TABLE); | + Resource.TABLE); | ||||
rs.next(); | rs.next(); | ||||
result = "rowcount for table test is " + rs.getObject(1).toString(); | result = "rowcount for table test is " + rs.getObject(1).toString(); | ||||
stmt.close(); | stmt.close(); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
return result; | return result; | ||||
public Container getCategories() { | public Container getCategories() { | ||||
// TODO where deleted=? | // TODO where deleted=? | ||||
String q = "SELECT DISTINCT(" + Resource.PROPERTY_ID_CATEGORY | |||||
final String q = "SELECT DISTINCT(" + Resource.PROPERTY_ID_CATEGORY | |||||
+ ") FROM " + Resource.TABLE + " ORDER BY " | + ") FROM " + Resource.TABLE + " ORDER BY " | ||||
+ Resource.PROPERTY_ID_CATEGORY; | + Resource.PROPERTY_ID_CATEGORY; | ||||
try { | try { | ||||
return new QueryContainer(q, connection, | return new QueryContainer(q, connection, | ||||
ResultSet.TYPE_SCROLL_INSENSITIVE, | ResultSet.TYPE_SCROLL_INSENSITIVE, | ||||
ResultSet.CONCUR_READ_ONLY); | ResultSet.CONCUR_READ_ONLY); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
return new QueryContainer(q, connection, | return new QueryContainer(q, connection, | ||||
ResultSet.TYPE_SCROLL_INSENSITIVE, | ResultSet.TYPE_SCROLL_INSENSITIVE, | ||||
ResultSet.CONCUR_READ_ONLY); | ResultSet.CONCUR_READ_ONLY); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
q += " WHERE " + Reservation.PROPERTY_ID_RESOURCE_ID + "=" | q += " WHERE " + Reservation.PROPERTY_ID_RESOURCE_ID + "=" | ||||
+ Resource.PROPERTY_ID_ID; | + Resource.PROPERTY_ID_ID; | ||||
if (resources != null && resources.size() > 0) { | if (resources != null && resources.size() > 0) { | ||||
StringBuffer s = new StringBuffer(); | |||||
for (Iterator it = resources.iterator(); it.hasNext();) { | |||||
final StringBuffer s = new StringBuffer(); | |||||
for (final Iterator it = resources.iterator(); it.hasNext();) { | |||||
if (s.length() > 0) { | if (s.length() > 0) { | ||||
s.append(","); | s.append(","); | ||||
} | } | ||||
} | } | ||||
q += " ORDER BY " + Reservation.PROPERTY_ID_RESERVED_FROM; | q += " ORDER BY " + Reservation.PROPERTY_ID_RESERVED_FROM; | ||||
try { | try { | ||||
QueryContainer qc = new QueryContainer(q, connection, | |||||
final QueryContainer qc = new QueryContainer(q, connection, | |||||
ResultSet.TYPE_SCROLL_INSENSITIVE, | ResultSet.TYPE_SCROLL_INSENSITIVE, | ||||
ResultSet.CONCUR_READ_ONLY); | ResultSet.CONCUR_READ_ONLY); | ||||
if (qc.size() < 1) { | if (qc.size() < 1) { | ||||
} else { | } else { | ||||
return qc; | return qc; | ||||
} | } | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
} | } | ||||
public void addReservation(Item resource, int reservedById, | public void addReservation(Item resource, int reservedById, | ||||
Date reservedFrom, Date reservedTo, String description) { | Date reservedFrom, Date reservedTo, String description) { | ||||
if (reservedFrom.after(reservedTo)) { | if (reservedFrom.after(reservedTo)) { | ||||
Date tmp = reservedTo; | |||||
final Date tmp = reservedTo; | |||||
reservedTo = reservedFrom; | reservedTo = reservedFrom; | ||||
reservedFrom = tmp; | reservedFrom = tmp; | ||||
} | } | ||||
int resourceId = ((Integer) resource.getItemProperty( | |||||
final int resourceId = ((Integer) resource.getItemProperty( | |||||
Resource.PROPERTY_ID_ID).getValue()).intValue(); | Resource.PROPERTY_ID_ID).getValue()).intValue(); | ||||
String q = "INSERT INTO " + Reservation.TABLE + " (" | |||||
final String q = "INSERT INTO " + Reservation.TABLE + " (" | |||||
+ Reservation.PROPERTY_ID_RESOURCE_ID + "," | + Reservation.PROPERTY_ID_RESOURCE_ID + "," | ||||
+ Reservation.PROPERTY_ID_RESERVED_BY_ID + "," | + Reservation.PROPERTY_ID_RESERVED_BY_ID + "," | ||||
+ Reservation.PROPERTY_ID_RESERVED_FROM + "," | + Reservation.PROPERTY_ID_RESERVED_FROM + "," | ||||
throw new ResourceNotAvailableException( | throw new ResourceNotAvailableException( | ||||
"The resource is not available at that time."); | "The resource is not available at that time."); | ||||
} | } | ||||
PreparedStatement p = connection.prepareStatement(q); | |||||
final PreparedStatement p = connection.prepareStatement(q); | |||||
p.setInt(1, resourceId); | p.setInt(1, resourceId); | ||||
p.setInt(2, reservedById); | p.setInt(2, reservedById); | ||||
p.setTimestamp(3, | p.setTimestamp(3, | ||||
p.setTimestamp(4, new java.sql.Timestamp(reservedTo.getTime())); | p.setTimestamp(4, new java.sql.Timestamp(reservedTo.getTime())); | ||||
p.setString(5, description); | p.setString(5, description); | ||||
p.execute(); | p.execute(); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
} | } | ||||
Date reservedTo) { | Date reservedTo) { | ||||
// TODO where deleted=? | // TODO where deleted=? | ||||
if (reservedFrom.after(reservedTo)) { | if (reservedFrom.after(reservedTo)) { | ||||
Date tmp = reservedTo; | |||||
final Date tmp = reservedTo; | |||||
reservedTo = reservedFrom; | reservedTo = reservedFrom; | ||||
reservedFrom = tmp; | reservedFrom = tmp; | ||||
} | } | ||||
String checkQ = "SELECT count(*) FROM " + Reservation.TABLE + " WHERE " | |||||
+ Reservation.PROPERTY_ID_RESOURCE_ID + "=? AND ((" | |||||
final String checkQ = "SELECT count(*) FROM " + Reservation.TABLE | |||||
+ " WHERE " + Reservation.PROPERTY_ID_RESOURCE_ID + "=? AND ((" | |||||
+ Reservation.PROPERTY_ID_RESERVED_FROM + ">=? AND " | + Reservation.PROPERTY_ID_RESERVED_FROM + ">=? AND " | ||||
+ Reservation.PROPERTY_ID_RESERVED_FROM + "<?) OR (" | + Reservation.PROPERTY_ID_RESERVED_FROM + "<?) OR (" | ||||
+ Reservation.PROPERTY_ID_RESERVED_TO + ">? AND " | + Reservation.PROPERTY_ID_RESERVED_TO + ">? AND " | ||||
+ Reservation.PROPERTY_ID_RESERVED_FROM + "<=? AND " | + Reservation.PROPERTY_ID_RESERVED_FROM + "<=? AND " | ||||
+ Reservation.PROPERTY_ID_RESERVED_TO + ">=?)" + ")"; | + Reservation.PROPERTY_ID_RESERVED_TO + ">=?)" + ")"; | ||||
try { | try { | ||||
PreparedStatement p = connection.prepareStatement(checkQ); | |||||
final PreparedStatement p = connection.prepareStatement(checkQ); | |||||
p.setInt(1, resourceId); | p.setInt(1, resourceId); | ||||
p.setTimestamp(2, new java.sql.Timestamp(reservedFrom.getTime())); | p.setTimestamp(2, new java.sql.Timestamp(reservedFrom.getTime())); | ||||
p.setTimestamp(3, new java.sql.Timestamp(reservedTo.getTime())); | p.setTimestamp(3, new java.sql.Timestamp(reservedTo.getTime())); | ||||
p.setTimestamp(6, new java.sql.Timestamp(reservedFrom.getTime())); | p.setTimestamp(6, new java.sql.Timestamp(reservedFrom.getTime())); | ||||
p.setTimestamp(7, new java.sql.Timestamp(reservedTo.getTime())); | p.setTimestamp(7, new java.sql.Timestamp(reservedTo.getTime())); | ||||
p.execute(); | p.execute(); | ||||
ResultSet rs = p.getResultSet(); | |||||
final ResultSet rs = p.getResultSet(); | |||||
if (rs.next() && rs.getInt(1) > 0) { | if (rs.next() && rs.getInt(1) > 0) { | ||||
return false; | return false; | ||||
} | } | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
return true; | return true; | ||||
public Container getUsers() { | public Container getUsers() { | ||||
// TODO where deleted=? | // TODO where deleted=? | ||||
String q = "SELECT * FROM " + User.TABLE + " ORDER BY " | |||||
final String q = "SELECT * FROM " + User.TABLE + " ORDER BY " | |||||
+ User.PROPERTY_ID_FULLNAME; | + User.PROPERTY_ID_FULLNAME; | ||||
try { | try { | ||||
QueryContainer qc = new QueryContainer(q, connection, | |||||
final QueryContainer qc = new QueryContainer(q, connection, | |||||
ResultSet.TYPE_SCROLL_INSENSITIVE, | ResultSet.TYPE_SCROLL_INSENSITIVE, | ||||
ResultSet.CONCUR_READ_ONLY); | ResultSet.CONCUR_READ_ONLY); | ||||
return qc; | return qc; | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
} | } | ||||
public void generateReservations() { | public void generateReservations() { | ||||
int days = 30; | |||||
String descriptions[] = { "Picking up guests from airport", | |||||
final int days = 30; | |||||
final String descriptions[] = { "Picking up guests from airport", | |||||
"Sightseeing with the guests", | "Sightseeing with the guests", | ||||
"Moving new servers from A to B", "Shopping", | "Moving new servers from A to B", "Shopping", | ||||
"Customer meeting", "Guests arriving at harbour", | "Customer meeting", "Guests arriving at harbour", | ||||
"Moving furniture", "Taking guests to see town" }; | "Moving furniture", "Taking guests to see town" }; | ||||
Container cat = getCategories(); | |||||
Collection cIds = cat.getItemIds(); | |||||
for (Iterator it = cIds.iterator(); it.hasNext();) { | |||||
Object id = it.next(); | |||||
Item ci = cat.getItem(id); | |||||
String c = (String) ci.getItemProperty( | |||||
final Container cat = getCategories(); | |||||
final Collection cIds = cat.getItemIds(); | |||||
for (final Iterator it = cIds.iterator(); it.hasNext();) { | |||||
final Object id = it.next(); | |||||
final Item ci = cat.getItem(id); | |||||
final String c = (String) ci.getItemProperty( | |||||
Resource.PROPERTY_ID_CATEGORY).getValue(); | Resource.PROPERTY_ID_CATEGORY).getValue(); | ||||
Container resources = getResources(c); | |||||
Collection rIds = resources.getItemIds(); | |||||
Calendar cal = Calendar.getInstance(); | |||||
final Container resources = getResources(c); | |||||
final Collection rIds = resources.getItemIds(); | |||||
final Calendar cal = Calendar.getInstance(); | |||||
cal.set(Calendar.MINUTE, 0); | cal.set(Calendar.MINUTE, 0); | ||||
cal.set(Calendar.SECOND, 0); | cal.set(Calendar.SECOND, 0); | ||||
cal.set(Calendar.MILLISECOND, 0); | cal.set(Calendar.MILLISECOND, 0); | ||||
int hourNow = new Date().getHours(); | |||||
final int hourNow = new Date().getHours(); | |||||
// cal.add(Calendar.DAY_OF_MONTH, -days); | // cal.add(Calendar.DAY_OF_MONTH, -days); | ||||
for (int i = 0; i < days; i++) { | for (int i = 0; i < days; i++) { | ||||
int r = 3; | int r = 3; | ||||
for (Iterator rit = rIds.iterator(); rit.hasNext() && r > 0; r--) { | |||||
Object rid = rit.next(); | |||||
Item resource = resources.getItem(rid); | |||||
int s = hourNow - 6 + (int) Math.round(Math.random() * 6.0); | |||||
int e = s + 1 + (int) Math.round(Math.random() * 4.0); | |||||
Date start = new Date(cal.getTimeInMillis()); | |||||
for (final Iterator rit = rIds.iterator(); rit.hasNext() | |||||
&& r > 0; r--) { | |||||
final Object rid = rit.next(); | |||||
final Item resource = resources.getItem(rid); | |||||
final int s = hourNow - 6 | |||||
+ (int) Math.round(Math.random() * 6.0); | |||||
final int e = s + 1 + (int) Math.round(Math.random() * 4.0); | |||||
final Date start = new Date(cal.getTimeInMillis()); | |||||
start.setHours(s); | start.setHours(s); | ||||
Date end = new Date(cal.getTimeInMillis()); | |||||
final Date end = new Date(cal.getTimeInMillis()); | |||||
end.setHours(e); | end.setHours(e); | ||||
addReservation(resource, 0, start, end, | addReservation(resource, 0, start, end, | ||||
descriptions[(int) Math.floor(Math.random() | descriptions[(int) Math.floor(Math.random() | ||||
public void generateResources() { | public void generateResources() { | ||||
Object[][] resources = { | |||||
final Object[][] resources = { | |||||
// Turku | // Turku | ||||
{ "01", "01 Ford Mondeo", "w/ company logo", "Turku", | { "01", "01 Ford Mondeo", "w/ company logo", "Turku", | ||||
new Double(60.510857), new Double(22.275424) }, | new Double(60.510857), new Double(22.275424) }, | ||||
}; | }; | ||||
String q = "INSERT INTO " + Resource.TABLE + "(" | |||||
final String q = "INSERT INTO " + Resource.TABLE + "(" | |||||
+ Resource.PROPERTY_ID_STYLENAME + "," | + Resource.PROPERTY_ID_STYLENAME + "," | ||||
+ Resource.PROPERTY_ID_NAME + "," | + Resource.PROPERTY_ID_NAME + "," | ||||
+ Resource.PROPERTY_ID_DESCRIPTION + "," | + Resource.PROPERTY_ID_DESCRIPTION + "," | ||||
+ Resource.PROPERTY_ID_LOCATIONY + ")" | + Resource.PROPERTY_ID_LOCATIONY + ")" | ||||
+ " VALUES (?,?,?,?,?,?)"; | + " VALUES (?,?,?,?,?,?)"; | ||||
try { | try { | ||||
PreparedStatement stmt = connection.prepareStatement(q); | |||||
final PreparedStatement stmt = connection.prepareStatement(q); | |||||
for (int i = 0; i < resources.length; i++) { | for (int i = 0; i < resources.length; i++) { | ||||
int j = 0; | int j = 0; | ||||
stmt.setString(j + 1, (String) resources[i][j++]); | stmt.setString(j + 1, (String) resources[i][j++]); | ||||
.doubleValue()); | .doubleValue()); | ||||
stmt.execute(); | stmt.execute(); | ||||
} | } | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
} | } | ||||
public void generateDemoUser() { | public void generateDemoUser() { | ||||
String q = "INSERT INTO USER (" + User.PROPERTY_ID_FULLNAME + "," | |||||
final String q = "INSERT INTO USER (" + User.PROPERTY_ID_FULLNAME + "," | |||||
+ User.PROPERTY_ID_EMAIL + "," + User.PROPERTY_ID_PASSWORD | + User.PROPERTY_ID_EMAIL + "," + User.PROPERTY_ID_PASSWORD | ||||
+ ") VALUES (?,?,?)"; | + ") VALUES (?,?,?)"; | ||||
try { | try { | ||||
PreparedStatement stmt = connection.prepareStatement(q); | |||||
final PreparedStatement stmt = connection.prepareStatement(q); | |||||
stmt.setString(1, "Demo User"); | stmt.setString(1, "Demo User"); | ||||
stmt.setString(2, "demo.user@itmill.com"); | stmt.setString(2, "demo.user@itmill.com"); | ||||
stmt.setString(3, "demo"); | stmt.setString(3, "demo"); | ||||
stmt.execute(); | stmt.execute(); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.reservation.gwt.client; | package com.itmill.toolkit.demo.reservation.gwt.client; | ||||
import com.google.gwt.core.client.GWT; | import com.google.gwt.core.client.GWT; | ||||
public class ReservationWidgetSet extends DefaultWidgetSet { | public class ReservationWidgetSet extends DefaultWidgetSet { | ||||
public Widget createWidget(UIDL uidl) { | public Widget createWidget(UIDL uidl) { | ||||
String className = resolveWidgetTypeName(uidl); | |||||
final String className = resolveWidgetTypeName(uidl); | |||||
if ("com.itmill.toolkit.terminal.gwt.client.ui.IGoogleMap" | if ("com.itmill.toolkit.terminal.gwt.client.ui.IGoogleMap" | ||||
.equals(className)) { | .equals(className)) { | ||||
return new IGoogleMap(); | return new IGoogleMap(); | ||||
protected String resolveWidgetTypeName(UIDL uidl) { | protected String resolveWidgetTypeName(UIDL uidl) { | ||||
String tag = uidl.getTag(); | |||||
final String tag = uidl.getTag(); | |||||
if ("googlemap".equals(tag)) { | if ("googlemap".equals(tag)) { | ||||
return "com.itmill.toolkit.terminal.gwt.client.ui.IGoogleMap"; | return "com.itmill.toolkit.terminal.gwt.client.ui.IGoogleMap"; | ||||
} else if ("calendarfield".equals(tag)) { | } else if ("calendarfield".equals(tag)) { |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.reservation.gwt.client.ui; | package com.itmill.toolkit.demo.reservation.gwt.client.ui; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
public class ICalendarField extends IDateField { | public class ICalendarField extends IDateField { | ||||
private CalendarPanel calPanel; | |||||
private final CalendarPanel calPanel; | |||||
private SimplePanel hourPanel; | private SimplePanel hourPanel; | ||||
private FlexTable hourTable; | private FlexTable hourTable; | ||||
private EntrySource entrySource; | |||||
private final EntrySource entrySource; | |||||
private TableListener ftListener = new HourTableListener(); | |||||
private final TableListener ftListener = new HourTableListener(); | |||||
private int realResolution = RESOLUTION_DAY; | private int realResolution = RESOLUTION_DAY; | ||||
realResolution = currentResolution; | realResolution = currentResolution; | ||||
currentResolution = RESOLUTION_DAY; | currentResolution = RESOLUTION_DAY; | ||||
if (uidl.hasAttribute("min")) { | if (uidl.hasAttribute("min")) { | ||||
String mins = uidl.getStringAttribute("min"); | |||||
long min = (mins != null ? Long.parseLong(mins) : 0); | |||||
String maxs = uidl.getStringAttribute("max"); | |||||
long max = (maxs != null ? Long.parseLong(maxs) : 0); | |||||
Date minDate = (min > 0 ? new Date(min) : null); | |||||
Date maxDate = (max > 0 ? new Date(max) : null); | |||||
final String mins = uidl.getStringAttribute("min"); | |||||
final long min = (mins != null ? Long.parseLong(mins) : 0); | |||||
final String maxs = uidl.getStringAttribute("max"); | |||||
final long max = (maxs != null ? Long.parseLong(maxs) : 0); | |||||
final Date minDate = (min > 0 ? new Date(min) : null); | |||||
final Date maxDate = (max > 0 ? new Date(max) : null); | |||||
calPanel.setLimits(minDate, maxDate); | calPanel.setLimits(minDate, maxDate); | ||||
} | } | ||||
entrySource.clear(); | entrySource.clear(); | ||||
for (Iterator cit = uidl.getChildIterator(); cit.hasNext();) { | |||||
UIDL child = (UIDL) cit.next(); | |||||
for (final Iterator cit = uidl.getChildIterator(); cit.hasNext();) { | |||||
final UIDL child = (UIDL) cit.next(); | |||||
if (child.getTag().equals("items")) { | if (child.getTag().equals("items")) { | ||||
for (Iterator iit = child.getChildIterator(); iit.hasNext();) { | |||||
UIDL item = (UIDL) iit.next(); | |||||
for (final Iterator iit = child.getChildIterator(); iit | |||||
.hasNext();) { | |||||
final UIDL item = (UIDL) iit.next(); | |||||
entrySource.addItem(item); | entrySource.addItem(item); | ||||
} | } | ||||
break; | break; | ||||
CLASSNAME + "-row-" + style); | CLASSNAME + "-row-" + style); | ||||
String hstr = (i < 10 ? "0" : "") + i + ":00"; | String hstr = (i < 10 ? "0" : "") + i + ":00"; | ||||
if (dts.isTwelveHourClock()) { | if (dts.isTwelveHourClock()) { | ||||
String ampm = (i < 12 ? "am" : "pm"); | |||||
final String ampm = (i < 12 ? "am" : "pm"); | |||||
hstr = (i <= 12 ? i : i - 12) + ":00 " + ampm; | hstr = (i <= 12 ? i : i - 12) + ":00 " + ampm; | ||||
} | } | ||||
hourTable.setHTML(i, 0, "<span>" + hstr + "</span>"); | hourTable.setHTML(i, 0, "<span>" + hstr + "</span>"); | ||||
.setStyleName(i, 0, CLASSNAME + "-time"); | .setStyleName(i, 0, CLASSNAME + "-time"); | ||||
} | } | ||||
List entries = entrySource.getEntries(date, | |||||
final List entries = entrySource.getEntries(date, | |||||
DateTimeService.RESOLUTION_DAY); | DateTimeService.RESOLUTION_DAY); | ||||
int currentCol = 1; | int currentCol = 1; | ||||
for (Iterator it = entries.iterator(); it.hasNext();) { | |||||
CalendarEntry entry = (CalendarEntry) it.next(); | |||||
for (final Iterator it = entries.iterator(); it.hasNext();) { | |||||
final CalendarEntry entry = (CalendarEntry) it.next(); | |||||
int start = 0; | int start = 0; | ||||
int hours = 24; | int hours = 24; | ||||
if (!entry.isNotime()) { | if (!entry.isNotime()) { | ||||
hourTable.getFlexCellFormatter().setRowSpan(start, col, hours); | hourTable.getFlexCellFormatter().setRowSpan(start, col, hours); | ||||
hourTable.getFlexCellFormatter().setStyleName(start, col, | hourTable.getFlexCellFormatter().setStyleName(start, col, | ||||
CLASSNAME + "-entry"); | CLASSNAME + "-entry"); | ||||
String sn = entry.getStyleName(); | |||||
final String sn = entry.getStyleName(); | |||||
if (sn != null && !sn.equals("")) { | if (sn != null && !sn.equals("")) { | ||||
hourTable.getFlexCellFormatter().addStyleName(start, col, | hourTable.getFlexCellFormatter().addStyleName(start, col, | ||||
CLASSNAME + "-" + entry.getStyleName()); | CLASSNAME + "-" + entry.getStyleName()); | ||||
} | } | ||||
Element el = hourTable.getFlexCellFormatter() | |||||
.getElement(start, col); | |||||
final Element el = hourTable.getFlexCellFormatter().getElement( | |||||
start, col); | |||||
String tooltip; | String tooltip; | ||||
if (DateTimeService.isSameDay(entry.getStart(), entry.getEnd())) { | if (DateTimeService.isSameDay(entry.getStart(), entry.getEnd())) { | ||||
tooltip = (start < 10 ? "0" : "") + start + ":00"; | tooltip = (start < 10 ? "0" : "") + start + ":00"; | ||||
if (dts.isTwelveHourClock()) { | if (dts.isTwelveHourClock()) { | ||||
String ampm = (start < 12 ? "am" : "pm"); | |||||
final String ampm = (start < 12 ? "am" : "pm"); | |||||
tooltip = (start <= 12 ? start : start - 12) + ":00 " | tooltip = (start <= 12 ? start : start - 12) + ":00 " | ||||
+ ampm; | + ampm; | ||||
} | } | ||||
// int hour = new Date().getHours()+1; // scroll to current hour | // int hour = new Date().getHours()+1; // scroll to current hour | ||||
int hour = this.date.getHours() + 1; // scroll to selected | |||||
final int hour = this.date.getHours() + 1; // scroll to selected | |||||
// hour | // hour | ||||
int h1 = hourPanel.getOffsetHeight() / 2; | |||||
int oh = hourTable.getOffsetHeight(); | |||||
int h2 = (int) (hour / 24.0 * oh); | |||||
int scrollTop = h2 - h1; | |||||
Element el = hourPanel.getElement(); | |||||
final int h1 = hourPanel.getOffsetHeight() / 2; | |||||
final int oh = hourTable.getOffsetHeight(); | |||||
final int h2 = (int) (hour / 24.0 * oh); | |||||
final int scrollTop = h2 - h1; | |||||
final Element el = hourPanel.getElement(); | |||||
setScrollTop(el, scrollTop); | setScrollTop(el, scrollTop); | ||||
} | } | ||||
private native void setScrollTop(Element el, int scrollTop) /*-{ | private native void setScrollTop(Element el, int scrollTop) /*-{ | ||||
el.scrollTop = scrollTop; | |||||
}-*/; | |||||
el.scrollTop = scrollTop; | |||||
}-*/; | |||||
private class HourTableListener implements TableListener { | private class HourTableListener implements TableListener { | ||||
private class EntrySource implements CalendarPanel.CalendarEntrySource { | private class EntrySource implements CalendarPanel.CalendarEntrySource { | ||||
private HashMap dates = new HashMap(); | |||||
private final HashMap dates = new HashMap(); | |||||
public void addItem(UIDL item) { | public void addItem(UIDL item) { | ||||
String styleName = item.getStringAttribute("styleName"); | |||||
Integer id = new Integer(item.getIntAttribute("id")); | |||||
long start = Long.parseLong(item.getStringAttribute("start")); | |||||
Date startDate = new Date(start); | |||||
final String styleName = item.getStringAttribute("styleName"); | |||||
final Integer id = new Integer(item.getIntAttribute("id")); | |||||
final long start = Long.parseLong(item.getStringAttribute("start")); | |||||
final Date startDate = new Date(start); | |||||
long end = -1; | long end = -1; | ||||
try { | try { | ||||
end = Long.parseLong(item.getStringAttribute("end")); | end = Long.parseLong(item.getStringAttribute("end")); | ||||
} catch (Exception IGNORED) { | |||||
} catch (final Exception IGNORED) { | |||||
// IGNORED attribute not required | // IGNORED attribute not required | ||||
} | } | ||||
Date endDate = (end > 0 && end != start ? new Date(end) : new Date( | |||||
start)); | |||||
String title = item.getStringAttribute("title"); | |||||
String desc = item.getStringAttribute("description"); | |||||
boolean notime = item.getBooleanAttribute("notime"); | |||||
CalendarEntry entry = new CalendarEntry(styleName, startDate, | |||||
final Date endDate = (end > 0 && end != start ? new Date(end) | |||||
: new Date(start)); | |||||
final String title = item.getStringAttribute("title"); | |||||
final String desc = item.getStringAttribute("description"); | |||||
final boolean notime = item.getBooleanAttribute("notime"); | |||||
final CalendarEntry entry = new CalendarEntry(styleName, startDate, | |||||
endDate, title, desc, notime); | endDate, title, desc, notime); | ||||
// TODO should remove+readd if the same entry (id) is | // TODO should remove+readd if the same entry (id) is | ||||
// added again | // added again | ||||
for (Date d = entry.getStart(); d.getYear() <= entry.getEnd() | |||||
for (final Date d = entry.getStart(); d.getYear() <= entry.getEnd() | |||||
.getYear() | .getYear() | ||||
&& d.getMonth() <= entry.getEnd().getYear() | && d.getMonth() <= entry.getEnd().getYear() | ||||
&& d.getDate() <= entry.getEnd().getDate(); d.setTime(d | && d.getDate() <= entry.getEnd().getDate(); d.setTime(d | ||||
.getTime() + 86400000)) { | .getTime() + 86400000)) { | ||||
String key = d.getYear() + "" + d.getMonth() + "" + d.getDate(); | |||||
final String key = d.getYear() + "" + d.getMonth() + "" | |||||
+ d.getDate(); | |||||
ArrayList l = (ArrayList) dates.get(key); | ArrayList l = (ArrayList) dates.get(key); | ||||
if (l == null) { | if (l == null) { | ||||
l = new ArrayList(); | l = new ArrayList(); | ||||
} | } | ||||
public List getEntries(Date date, int resolution) { | public List getEntries(Date date, int resolution) { | ||||
List entries = (List) dates.get(date.getYear() + "" | |||||
final List entries = (List) dates.get(date.getYear() + "" | |||||
+ date.getMonth() + "" + date.getDate()); | + date.getMonth() + "" + date.getDate()); | ||||
ArrayList res = new ArrayList(); | |||||
final ArrayList res = new ArrayList(); | |||||
if (entries == null) { | if (entries == null) { | ||||
return res; | return res; | ||||
} | } | ||||
for (Iterator it = entries.iterator(); it.hasNext();) { | |||||
CalendarEntry item = (CalendarEntry) it.next(); | |||||
for (final Iterator it = entries.iterator(); it.hasNext();) { | |||||
final CalendarEntry item = (CalendarEntry) it.next(); | |||||
if (DateTimeService.isInRange(date, item.getStart(), item | if (DateTimeService.isInRange(date, item.getStart(), item | ||||
.getEnd(), resolution)) { | .getEnd(), resolution)) { | ||||
res.add(item); | res.add(item); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.reservation.gwt.client.ui; | package com.itmill.toolkit.demo.reservation.gwt.client.ui; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { | public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { | ||||
map.clearOverlays(); | map.clearOverlays(); | ||||
GLatLng pos = null; | GLatLng pos = null; | ||||
for (Iterator it = uidl.getChildIterator(); it.hasNext();) { | |||||
UIDL u = (UIDL) it.next(); | |||||
for (final Iterator it = uidl.getChildIterator(); it.hasNext();) { | |||||
final UIDL u = (UIDL) it.next(); | |||||
if (u.getTag().equals("markers")) { | if (u.getTag().equals("markers")) { | ||||
for (Iterator m = u.getChildIterator(); m.hasNext();) { | |||||
UIDL umarker = (UIDL) m.next(); | |||||
String html = "<span>" + umarker.getStringAttribute("html") | |||||
+ "</span>"; | |||||
double x = umarker.getDoubleAttribute("x"); | |||||
double y = umarker.getDoubleAttribute("y"); | |||||
for (final Iterator m = u.getChildIterator(); m.hasNext();) { | |||||
final UIDL umarker = (UIDL) m.next(); | |||||
final String html = "<span>" | |||||
+ umarker.getStringAttribute("html") + "</span>"; | |||||
final double x = umarker.getDoubleAttribute("x"); | |||||
final double y = umarker.getDoubleAttribute("y"); | |||||
pos = new GLatLng(x, y); | pos = new GLatLng(x, y); | ||||
GMarker marker = new GMarker(pos); | |||||
final GMarker marker = new GMarker(pos); | |||||
map.addOverlay(marker); | map.addOverlay(marker); | ||||
if (html != null) { | if (html != null) { | ||||
addMarkerPopup(marker, html); | addMarkerPopup(marker, html); | ||||
map.setZoom(uidl.getIntAttribute("zoom")); | map.setZoom(uidl.getIntAttribute("zoom")); | ||||
} | } | ||||
if (uidl.hasAttribute("centerX") && uidl.hasAttribute("centerY")) { | if (uidl.hasAttribute("centerX") && uidl.hasAttribute("centerY")) { | ||||
GLatLng center = new GLatLng(uidl.getDoubleAttribute("centerX"), | |||||
uidl.getDoubleAttribute("centerY")); | |||||
final GLatLng center = new GLatLng(uidl | |||||
.getDoubleAttribute("centerX"), uidl | |||||
.getDoubleAttribute("centerY")); | |||||
map.setCenter(center); | map.setCenter(center); | ||||
} else if (pos != null) { | } else if (pos != null) { | ||||
// use last marker position | // use last marker position |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.util; | package com.itmill.toolkit.demo.util; | ||||
import java.sql.Connection; | import java.sql.Connection; | ||||
*/ | */ | ||||
private void connect() { | private void connect() { | ||||
// use memory-Only Database | // use memory-Only Database | ||||
String url = "jdbc:hsqldb:mem:toolkit"; | |||||
final String url = "jdbc:hsqldb:mem:toolkit"; | |||||
try { | try { | ||||
Class.forName("org.hsqldb.jdbcDriver").newInstance(); | Class.forName("org.hsqldb.jdbcDriver").newInstance(); | ||||
connection = DriverManager.getConnection(url, "sa", ""); | connection = DriverManager.getConnection(url, "sa", ""); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
} | } | ||||
public void update(String expression) throws SQLException { | public void update(String expression) throws SQLException { | ||||
Statement st = null; | Statement st = null; | ||||
st = connection.createStatement(); | st = connection.createStatement(); | ||||
int i = st.executeUpdate(expression); | |||||
final int i = st.executeUpdate(expression); | |||||
if (i == -1) { | if (i == -1) { | ||||
System.out.println("SampleDatabase error : " + expression); | System.out.println("SampleDatabase error : " + expression); | ||||
} | } | ||||
+ "EVENTSTART DATETIME, EVENTEND DATETIME, NOTIME BOOLEAN )"; | + "EVENTSTART DATETIME, EVENTEND DATETIME, NOTIME BOOLEAN )"; | ||||
update(stmt); | update(stmt); | ||||
for (int j = 0; j < ENTRYCOUNT; j++) { | for (int j = 0; j < ENTRYCOUNT; j++) { | ||||
Timestamp start = new Timestamp(new java.util.Date().getTime()); | |||||
final Timestamp start = new Timestamp(new java.util.Date() | |||||
.getTime()); | |||||
start.setDate((int) ((Math.random() - 0.4) * 200)); | start.setDate((int) ((Math.random() - 0.4) * 200)); | ||||
start.setMinutes(0); | start.setMinutes(0); | ||||
start.setHours(8 + (int) Math.random() * 12); | start.setHours(8 + (int) Math.random() * 12); | ||||
Timestamp end = new Timestamp(start.getTime()); | |||||
final Timestamp end = new Timestamp(start.getTime()); | |||||
if (Math.random() < 0.7) { | if (Math.random() < 0.7) { | ||||
long t = end.getTime(); | long t = end.getTime(); | ||||
long hour = 60 * 60 * 1000; | |||||
final long hour = 60 * 60 * 1000; | |||||
t = t + hour + (Math.round(Math.random() * 3 * hour)); | t = t + hour + (Math.round(Math.random() * 3 * hour)); | ||||
end.setTime(t); | end.setTime(t); | ||||
} | } | ||||
+ "','" + end + "'," + (Math.random() > 0.7) + ")"; | + "','" + end + "'," + (Math.random() > 0.7) + ")"; | ||||
update(stmt); | update(stmt); | ||||
} | } | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
if (e.toString().indexOf("Table already exists") == -1) { | if (e.toString().indexOf("Table already exists") == -1) { | ||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
private String testDatabase() { | private String testDatabase() { | ||||
String result = null; | String result = null; | ||||
try { | try { | ||||
Statement stmt = connection.createStatement( | |||||
final Statement stmt = connection.createStatement( | |||||
ResultSet.TYPE_SCROLL_INSENSITIVE, | ResultSet.TYPE_SCROLL_INSENSITIVE, | ||||
ResultSet.CONCUR_UPDATABLE); | ResultSet.CONCUR_UPDATABLE); | ||||
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM " | |||||
final ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM " | |||||
+ DB_TABLE_NAME); | + DB_TABLE_NAME); | ||||
rs.next(); | rs.next(); | ||||
result = "rowcount for table test is " + rs.getObject(1).toString(); | result = "rowcount for table test is " + rs.getObject(1).toString(); | ||||
stmt.close(); | stmt.close(); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
return result; | return result; |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.util; | package com.itmill.toolkit.demo.util; | ||||
import java.sql.Connection; | import java.sql.Connection; | ||||
*/ | */ | ||||
private void connect() { | private void connect() { | ||||
// use memory-Only Database | // use memory-Only Database | ||||
String url = "jdbc:hsqldb:mem:toolkit"; | |||||
final String url = "jdbc:hsqldb:mem:toolkit"; | |||||
try { | try { | ||||
Class.forName("org.hsqldb.jdbcDriver").newInstance(); | Class.forName("org.hsqldb.jdbcDriver").newInstance(); | ||||
connection = DriverManager.getConnection(url, "sa", ""); | connection = DriverManager.getConnection(url, "sa", ""); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
} | } | ||||
public void update(String expression) throws SQLException { | public void update(String expression) throws SQLException { | ||||
Statement st = null; | Statement st = null; | ||||
st = connection.createStatement(); | st = connection.createStatement(); | ||||
int i = st.executeUpdate(expression); | |||||
final int i = st.executeUpdate(expression); | |||||
if (i == -1) { | if (i == -1) { | ||||
throw new SQLException("Database error : " + expression); | throw new SQLException("Database error : " + expression); | ||||
} | } | ||||
+ "'" + ")"; | + "'" + ")"; | ||||
update(stmt); | update(stmt); | ||||
} | } | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
if (e.toString().indexOf("Table already exists") == -1) { | if (e.toString().indexOf("Table already exists") == -1) { | ||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
private String testDatabase() { | private String testDatabase() { | ||||
String result = null; | String result = null; | ||||
try { | try { | ||||
Statement stmt = connection.createStatement( | |||||
final Statement stmt = connection.createStatement( | |||||
ResultSet.TYPE_SCROLL_INSENSITIVE, | ResultSet.TYPE_SCROLL_INSENSITIVE, | ||||
ResultSet.CONCUR_UPDATABLE); | ResultSet.CONCUR_UPDATABLE); | ||||
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM employee"); | |||||
final ResultSet rs = stmt | |||||
.executeQuery("SELECT COUNT(*) FROM employee"); | |||||
rs.next(); | rs.next(); | ||||
result = "rowcount for table test is " + rs.getObject(1).toString(); | result = "rowcount for table test is " + rs.getObject(1).toString(); | ||||
stmt.close(); | stmt.close(); | ||||
} catch (SQLException e) { | |||||
} catch (final SQLException e) { | |||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
return result; | return result; |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.demo.util; | package com.itmill.toolkit.demo.util; | ||||
import java.io.File; | import java.io.File; | ||||
return file; | return file; | ||||
} | } | ||||
// Add failure notification as an Panel to main window | // Add failure notification as an Panel to main window | ||||
Panel errorPanel = new Panel("Demo application error"); | |||||
final Panel errorPanel = new Panel("Demo application error"); | |||||
errorPanel.setStyle("strong"); | errorPanel.setStyle("strong"); | ||||
errorPanel.setComponentError(new SystemError( | errorPanel.setComponentError(new SystemError( | ||||
"Cannot provide sample directory")); | "Cannot provide sample directory")); |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.event; | package com.itmill.toolkit.event; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.event; | package com.itmill.toolkit.event; | ||||
public void removeListener(Class eventType, Object target) { | public void removeListener(Class eventType, Object target) { | ||||
if (listenerList != null) { | if (listenerList != null) { | ||||
Iterator i = listenerList.iterator(); | |||||
final Iterator i = listenerList.iterator(); | |||||
while (i.hasNext()) { | while (i.hasNext()) { | ||||
try { | try { | ||||
ListenerMethod lm = (ListenerMethod) i.next(); | |||||
final ListenerMethod lm = (ListenerMethod) i.next(); | |||||
if (lm.matches(eventType, target)) { | if (lm.matches(eventType, target)) { | ||||
i.remove(); | i.remove(); | ||||
} | } | ||||
} catch (java.lang.ClassCastException e) { | |||||
} catch (final java.lang.ClassCastException e) { | |||||
// Class cast exceptions are ignored | // Class cast exceptions are ignored | ||||
} | } | ||||
} | } | ||||
public void removeListener(Class eventType, Object target, Method method) { | public void removeListener(Class eventType, Object target, Method method) { | ||||
if (listenerList != null) { | if (listenerList != null) { | ||||
Iterator i = listenerList.iterator(); | |||||
final Iterator i = listenerList.iterator(); | |||||
while (i.hasNext()) { | while (i.hasNext()) { | ||||
try { | try { | ||||
ListenerMethod lm = (ListenerMethod) i.next(); | |||||
final ListenerMethod lm = (ListenerMethod) i.next(); | |||||
if (lm.matches(eventType, target, method)) { | if (lm.matches(eventType, target, method)) { | ||||
i.remove(); | i.remove(); | ||||
} | } | ||||
} catch (java.lang.ClassCastException e) { | |||||
} catch (final java.lang.ClassCastException e) { | |||||
// Class cast exceptions are ignored | // Class cast exceptions are ignored | ||||
} | } | ||||
} | } | ||||
public void removeListener(Class eventType, Object target, String methodName) { | public void removeListener(Class eventType, Object target, String methodName) { | ||||
// Find the correct method | // Find the correct method | ||||
Method[] methods = target.getClass().getMethods(); | |||||
final Method[] methods = target.getClass().getMethods(); | |||||
Method method = null; | Method method = null; | ||||
for (int i = 0; i < methods.length; i++) { | for (int i = 0; i < methods.length; i++) { | ||||
if (methods[i].getName().equals(methodName)) { | if (methods[i].getName().equals(methodName)) { | ||||
// Remove the listeners | // Remove the listeners | ||||
if (listenerList != null) { | if (listenerList != null) { | ||||
Iterator i = listenerList.iterator(); | |||||
final Iterator i = listenerList.iterator(); | |||||
while (i.hasNext()) { | while (i.hasNext()) { | ||||
try { | try { | ||||
ListenerMethod lm = (ListenerMethod) i.next(); | |||||
final ListenerMethod lm = (ListenerMethod) i.next(); | |||||
if (lm.matches(eventType, target, method)) { | if (lm.matches(eventType, target, method)) { | ||||
i.remove(); | i.remove(); | ||||
} | } | ||||
} catch (java.lang.ClassCastException e) { | |||||
} catch (final java.lang.ClassCastException e) { | |||||
// Class cast exceptions are ignored | // Class cast exceptions are ignored | ||||
} | } | ||||
} | } | ||||
// Send the event to all listeners. The listeners themselves | // Send the event to all listeners. The listeners themselves | ||||
// will filter out unwanted events. | // will filter out unwanted events. | ||||
Iterator i = new LinkedList(listenerList).iterator(); | |||||
final Iterator i = new LinkedList(listenerList).iterator(); | |||||
while (i.hasNext()) { | while (i.hasNext()) { | ||||
((ListenerMethod) i.next()).receiveEvent(event); | ((ListenerMethod) i.next()).receiveEvent(event); | ||||
} | } |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.event; | package com.itmill.toolkit.event; | ||||
* Type of the event that should trigger this listener. Also the subclasses | * Type of the event that should trigger this listener. Also the subclasses | ||||
* of this class are accepted to trigger the listener. | * of this class are accepted to trigger the listener. | ||||
*/ | */ | ||||
private Class eventType; | |||||
private final Class eventType; | |||||
/** | /** | ||||
* The object containing the trigger method. | * The object containing the trigger method. | ||||
*/ | */ | ||||
private Object object; | |||||
private final Object object; | |||||
/** | /** | ||||
* The trigger method to call when an event passing the given criteria | * The trigger method to call when an event passing the given criteria | ||||
* fires. | * fires. | ||||
*/ | */ | ||||
private Method method; | |||||
private final Method method; | |||||
/** | /** | ||||
* Optional argument set to pass to the trigger method. | * Optional argument set to pass to the trigger method. | ||||
throws java.lang.IllegalArgumentException { | throws java.lang.IllegalArgumentException { | ||||
// Finds the correct method | // Finds the correct method | ||||
Method[] methods = object.getClass().getMethods(); | |||||
final Method[] methods = object.getClass().getMethods(); | |||||
Method method = null; | Method method = null; | ||||
for (int i = 0; i < methods.length; i++) { | for (int i = 0; i < methods.length; i++) { | ||||
if (methods[i].getName().equals(methodName)) { | if (methods[i].getName().equals(methodName)) { | ||||
Object[] arguments) throws java.lang.IllegalArgumentException { | Object[] arguments) throws java.lang.IllegalArgumentException { | ||||
// Find the correct method | // Find the correct method | ||||
Method[] methods = object.getClass().getMethods(); | |||||
final Method[] methods = object.getClass().getMethods(); | |||||
Method method = null; | Method method = null; | ||||
for (int i = 0; i < methods.length; i++) { | for (int i = 0; i < methods.length; i++) { | ||||
if (methods[i].getName().equals(methodName)) { | if (methods[i].getName().equals(methodName)) { | ||||
this.method = method; | this.method = method; | ||||
eventArgumentIndex = -1; | eventArgumentIndex = -1; | ||||
Class[] params = method.getParameterTypes(); | |||||
final Class[] params = method.getParameterTypes(); | |||||
if (params.length == 0) { | if (params.length == 0) { | ||||
arguments = new Object[0]; | arguments = new Object[0]; | ||||
throws java.lang.IllegalArgumentException { | throws java.lang.IllegalArgumentException { | ||||
// Finds the correct method | // Finds the correct method | ||||
Method[] methods = object.getClass().getMethods(); | |||||
final Method[] methods = object.getClass().getMethods(); | |||||
Method method = null; | Method method = null; | ||||
for (int i = 0; i < methods.length; i++) { | for (int i = 0; i < methods.length; i++) { | ||||
if (methods[i].getName().equals(methodName)) { | if (methods[i].getName().equals(methodName)) { | ||||
this.method = method; | this.method = method; | ||||
eventArgumentIndex = -1; | eventArgumentIndex = -1; | ||||
Class[] params = method.getParameterTypes(); | |||||
final Class[] params = method.getParameterTypes(); | |||||
if (params.length == 0) { | if (params.length == 0) { | ||||
arguments = new Object[0]; | arguments = new Object[0]; | ||||
if (eventArgumentIndex == 0 && arguments.length == 1) { | if (eventArgumentIndex == 0 && arguments.length == 1) { | ||||
method.invoke(object, new Object[] { event }); | method.invoke(object, new Object[] { event }); | ||||
} else { | } else { | ||||
Object[] arg = new Object[arguments.length]; | |||||
final Object[] arg = new Object[arguments.length]; | |||||
for (int i = 0; i < arg.length; i++) { | for (int i = 0; i < arg.length; i++) { | ||||
arg[i] = arguments[i]; | arg[i] = arguments[i]; | ||||
} | } | ||||
method.invoke(object, arguments); | method.invoke(object, arguments); | ||||
} | } | ||||
} catch (java.lang.IllegalAccessException e) { | |||||
} catch (final java.lang.IllegalAccessException e) { | |||||
// This should never happen | // This should never happen | ||||
throw new java.lang.RuntimeException( | throw new java.lang.RuntimeException( | ||||
"Internal error - please report: " + e.toString()); | "Internal error - please report: " + e.toString()); | ||||
} catch (java.lang.reflect.InvocationTargetException e) { | |||||
} catch (final java.lang.reflect.InvocationTargetException e) { | |||||
// This should never happen | // This should never happen | ||||
throw new MethodException("Invocation if method " + method | throw new MethodException("Invocation if method " + method | ||||
+ " failed.", e.getTargetException()); | + " failed.", e.getTargetException()); | ||||
*/ | */ | ||||
private static final long serialVersionUID = 3257005445242894135L; | private static final long serialVersionUID = 3257005445242894135L; | ||||
private Throwable cause; | |||||
private final Throwable cause; | |||||
private String message; | private String message; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.event; | package com.itmill.toolkit.event; | ||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.event; | package com.itmill.toolkit.event; | ||||
import com.itmill.toolkit.terminal.Resource; | import com.itmill.toolkit.terminal.Resource; | ||||
*/ | */ | ||||
public class ShortcutAction extends Action { | public class ShortcutAction extends Action { | ||||
private int keyCode; | |||||
private final int keyCode; | |||||
private int[] modifiers; | |||||
private final int[] modifiers; | |||||
public ShortcutAction(String caption, int kc, int[] m) { | public ShortcutAction(String caption, int kc, int[] m) { | ||||
super(caption); | super(caption); |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.launcher; | package com.itmill.toolkit.launcher; | ||||
import java.awt.FlowLayout; | import java.awt.FlowLayout; | ||||
public static void main(String[] args) { | public static void main(String[] args) { | ||||
Map serverArgs = ITMillToolkitWebMode.parseArguments(args); | |||||
final Map serverArgs = ITMillToolkitWebMode.parseArguments(args); | |||||
boolean deployed = false; | boolean deployed = false; | ||||
try { | try { | ||||
// Default deployment: embedded.war | // Default deployment: embedded.war | ||||
deployed = deployEmbeddedWarfile(serverArgs); | deployed = deployEmbeddedWarfile(serverArgs); | ||||
} catch (IOException e1) { | |||||
} catch (final IOException e1) { | |||||
e1.printStackTrace(); | e1.printStackTrace(); | ||||
deployed = false; | deployed = false; | ||||
} | } | ||||
} | } | ||||
// Start the Winstone servlet container | // Start the Winstone servlet container | ||||
String url = ITMillToolkitWebMode.runServer(serverArgs, "Desktop Mode"); | |||||
final String url = ITMillToolkitWebMode.runServer(serverArgs, | |||||
"Desktop Mode"); | |||||
// Open browser into application URL | // Open browser into application URL | ||||
if (url != null) { | if (url != null) { | ||||
final JButton cancelButton = new JButton("Cancel"); | final JButton cancelButton = new JButton("Cancel"); | ||||
// List for close verify buttons | // List for close verify buttons | ||||
ActionListener buttonListener = new ActionListener() { | |||||
final ActionListener buttonListener = new ActionListener() { | |||||
public void actionPerformed(ActionEvent e) { | public void actionPerformed(ActionEvent e) { | ||||
if (e.getSource() == okButton) { | if (e.getSource() == okButton) { | ||||
System.exit(0); | System.exit(0); | ||||
frame.addWindowListener(new WindowAdapter() { | frame.addWindowListener(new WindowAdapter() { | ||||
public void windowClosing(WindowEvent e) { | public void windowClosing(WindowEvent e) { | ||||
Rectangle bounds = frame.getBounds(); | |||||
final Rectangle bounds = frame.getBounds(); | |||||
frame.setTitle("Confirm close"); | frame.setTitle("Confirm close"); | ||||
contentPane.removeAll(); | contentPane.removeAll(); | ||||
contentPane.add(question); | contentPane.add(question); | ||||
}); | }); | ||||
// Position the window nicely | // Position the window nicely | ||||
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit() | |||||
.getScreenSize(); | |||||
int w = 270; | |||||
int h = 95; | |||||
int margin = 20; | |||||
final java.awt.Dimension screenSize = java.awt.Toolkit | |||||
.getDefaultToolkit().getScreenSize(); | |||||
final int w = 270; | |||||
final int h = 95; | |||||
final int margin = 20; | |||||
frame.setBounds(new Rectangle(screenSize.width - w - margin, | frame.setBounds(new Rectangle(screenSize.width - w - margin, | ||||
screenSize.height - h - margin * 2, w, h)); | screenSize.height - h - margin * 2, w, h)); | ||||
frame.toFront(); | frame.toFront(); | ||||
* @throws IOException | * @throws IOException | ||||
*/ | */ | ||||
protected static boolean deployEmbeddedWarfile(Map args) throws IOException { | protected static boolean deployEmbeddedWarfile(Map args) throws IOException { | ||||
String embeddedWarfileName = "/embedded.war"; | |||||
InputStream embeddedWarfile = ITMillToolkitDesktopMode.class | |||||
final String embeddedWarfileName = "/embedded.war"; | |||||
final InputStream embeddedWarfile = ITMillToolkitDesktopMode.class | |||||
.getResourceAsStream(embeddedWarfileName); | .getResourceAsStream(embeddedWarfileName); | ||||
if (embeddedWarfile != null) { | if (embeddedWarfile != null) { | ||||
File tempWarfile = File.createTempFile("embedded", ".war") | |||||
final File tempWarfile = File.createTempFile("embedded", ".war") | |||||
.getAbsoluteFile(); | .getAbsoluteFile(); | ||||
tempWarfile.getParentFile().mkdirs(); | tempWarfile.getParentFile().mkdirs(); | ||||
tempWarfile.deleteOnExit(); | tempWarfile.deleteOnExit(); | ||||
String embeddedWebroot = "winstoneEmbeddedWAR"; | |||||
File tempWebroot = new File(tempWarfile.getParentFile(), | |||||
final String embeddedWebroot = "winstoneEmbeddedWAR"; | |||||
final File tempWebroot = new File(tempWarfile.getParentFile(), | |||||
embeddedWebroot); | embeddedWebroot); | ||||
tempWebroot.mkdirs(); | tempWebroot.mkdirs(); | ||||
OutputStream out = new FileOutputStream(tempWarfile, true); | |||||
final OutputStream out = new FileOutputStream(tempWarfile, true); | |||||
int read = 0; | int read = 0; | ||||
byte buffer[] = new byte[2048]; | |||||
final byte buffer[] = new byte[2048]; | |||||
while ((read = embeddedWarfile.read(buffer)) != -1) { | while ((read = embeddedWarfile.read(buffer)) != -1) { | ||||
out.write(buffer, 0, read); | out.write(buffer, 0, read); | ||||
} | } |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.launcher; | package com.itmill.toolkit.launcher; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
public static void main(String[] args) { | public static void main(String[] args) { | ||||
// Pass-through of arguments for Jetty | // Pass-through of arguments for Jetty | ||||
Map serverArgs = parseArguments(args); | |||||
final Map serverArgs = parseArguments(args); | |||||
// Start Jetty | // Start Jetty | ||||
System.out.println("Starting Jetty servlet container."); | System.out.println("Starting Jetty servlet container."); | ||||
String url = runServer(serverArgs, "Web Mode"); | |||||
final String url = runServer(serverArgs, "Web Mode"); | |||||
// Start Browser | // Start Browser | ||||
System.out.println("Starting Web Browser."); | System.out.println("Starting Web Browser."); | ||||
assignDefault(serverArgs, "httpPort", serverPort); | assignDefault(serverArgs, "httpPort", serverPort); | ||||
try { | try { | ||||
long started = System.currentTimeMillis(); | |||||
final long started = System.currentTimeMillis(); | |||||
Server server = new Server(); | |||||
final Server server = new Server(); | |||||
// String threadPoolName = | // String threadPoolName = | ||||
// System.getProperty("jetty.threadpool.name", | // System.getProperty("jetty.threadpool.name", | ||||
// threadPool.setLowThreads(lowThreads); | // threadPool.setLowThreads(lowThreads); | ||||
// server.setThreadPool(threadPool); | // server.setThreadPool(threadPool); | ||||
Connector connector = new SelectChannelConnector(); | |||||
final Connector connector = new SelectChannelConnector(); | |||||
// FIXME httpPort hardcoded to 8888 | // FIXME httpPort hardcoded to 8888 | ||||
// connector.setPort(Integer.valueOf(serverArgs.get("httpPort") | // connector.setPort(Integer.valueOf(serverArgs.get("httpPort") | ||||
// .toString())); | // .toString())); | ||||
connector.setPort(8888); | connector.setPort(8888); | ||||
server.setConnectors(new Connector[] { connector }); | server.setConnectors(new Connector[] { connector }); | ||||
WebAppContext webappcontext = new WebAppContext(); | |||||
final WebAppContext webappcontext = new WebAppContext(); | |||||
webappcontext.setContextPath(""); | webappcontext.setContextPath(""); | ||||
webappcontext.setWar(serverArgs.get("webroot").toString()); | webappcontext.setWar(serverArgs.get("webroot").toString()); | ||||
// enable hot code replace | // enable hot code replace | ||||
server.start(); | server.start(); | ||||
// System.err.println("Started Jetty in " | // System.err.println("Started Jetty in " | ||||
// + (System.currentTimeMillis() - started) + "ms."); | // + (System.currentTimeMillis() - started) + "ms."); | ||||
} catch (Exception e) { | |||||
} catch (final Exception e) { | |||||
e.printStackTrace(); | e.printStackTrace(); | ||||
return null; | return null; | ||||
} | } | ||||
* @return map of arguments key value pairs. | * @return map of arguments key value pairs. | ||||
*/ | */ | ||||
protected static Map parseArguments(String[] args) { | protected static Map parseArguments(String[] args) { | ||||
Map map = new HashMap(); | |||||
final Map map = new HashMap(); | |||||
for (int i = 0; i < args.length; i++) { | for (int i = 0; i < args.length; i++) { | ||||
int d = args[i].indexOf("="); | |||||
final int d = args[i].indexOf("="); | |||||
if (d > 0 && d < args[i].length() && args[i].startsWith("--")) { | if (d > 0 && d < args[i].length() && args[i].startsWith("--")) { | ||||
String name = args[i].substring(2, d); | |||||
String value = args[i].substring(d + 1); | |||||
final String name = args[i].substring(2, d); | |||||
final String value = args[i].substring(d + 1); | |||||
map.put(name, value); | map.put(name, value); | ||||
} | } | ||||
} | } |
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.launcher.util; | package com.itmill.toolkit.launcher.util; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
*/ | */ | ||||
public static void openBrowser(String url) { | public static void openBrowser(String url) { | ||||
Runtime runtime = Runtime.getRuntime(); | |||||
final Runtime runtime = Runtime.getRuntime(); | |||||
boolean started = false; | boolean started = false; | ||||
String os = System.getProperty("os.name", "windows").toLowerCase(); | |||||
final String os = System.getProperty("os.name", "windows") | |||||
.toLowerCase(); | |||||
// Linux | // Linux | ||||
if (os.indexOf("linux") >= 0) { | if (os.indexOf("linux") >= 0) { | ||||
try { | try { | ||||
runtime.exec("x-www-browser " + url); | runtime.exec("x-www-browser " + url); | ||||
started = true; | started = true; | ||||
} catch (IOException e) { | |||||
} catch (final IOException e) { | |||||
} | } | ||||
} | } | ||||
try { | try { | ||||
runtime.exec("firefox " + url); | runtime.exec("firefox " + url); | ||||
started = true; | started = true; | ||||
} catch (IOException e) { | |||||
} catch (final IOException e) { | |||||
} | } | ||||
} | } | ||||
try { | try { | ||||
runtime.exec("mozilla " + url); | runtime.exec("mozilla " + url); | ||||
started = true; | started = true; | ||||
} catch (IOException e) { | |||||
} catch (final IOException e) { | |||||
} | } | ||||
} | } | ||||
try { | try { | ||||
runtime.exec("konqueror " + url); | runtime.exec("konqueror " + url); | ||||
started = true; | started = true; | ||||
} catch (IOException e) { | |||||
} catch (final IOException e) { | |||||
} | } | ||||
} | } | ||||
} | } | ||||
try { | try { | ||||
runtime.exec("open " + url); | runtime.exec("open " + url); | ||||
started = true; | started = true; | ||||
} catch (IOException e) { | |||||
} catch (final IOException e) { | |||||
} | } | ||||
} | } | ||||
} | } | ||||
try { | try { | ||||
runtime.exec("cmd /c start " + url); | runtime.exec("cmd /c start " + url); | ||||
started = true; | started = true; | ||||
} catch (IOException e) { | |||||
} catch (final IOException e) { | |||||
} | } | ||||
} | } | ||||
} | } |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.service; | package com.itmill.toolkit.service; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.service; | package com.itmill.toolkit.service; | ||||
static { | static { | ||||
// Initialize extension to MIME map | // Initialize extension to MIME map | ||||
StringTokenizer lines = new StringTokenizer(initialExtToMIMEMap, ","); | |||||
final StringTokenizer lines = new StringTokenizer(initialExtToMIMEMap, | |||||
","); | |||||
while (lines.hasMoreTokens()) { | while (lines.hasMoreTokens()) { | ||||
String line = lines.nextToken(); | |||||
StringTokenizer exts = new StringTokenizer(line); | |||||
String type = exts.nextToken(); | |||||
final String line = lines.nextToken(); | |||||
final StringTokenizer exts = new StringTokenizer(line); | |||||
final String type = exts.nextToken(); | |||||
while (exts.hasMoreTokens()) { | while (exts.hasMoreTokens()) { | ||||
String ext = exts.nextToken(); | |||||
final String ext = exts.nextToken(); | |||||
addExtension(ext, type); | addExtension(ext, type); | ||||
} | } | ||||
} | } | ||||
dotIndex++; | dotIndex++; | ||||
if (fileName.length() > dotIndex) { | if (fileName.length() > dotIndex) { | ||||
String ext = fileName.substring(dotIndex); | |||||
final String ext = fileName.substring(dotIndex); | |||||
// Return type from extension map, if found | // Return type from extension map, if found | ||||
String type = (String) extToMIMEMap.get(ext); | |||||
final String type = (String) extToMIMEMap.get(ext); | |||||
if (type != null) { | if (type != null) { | ||||
return type; | return type; | ||||
} | } | ||||
*/ | */ | ||||
public static Resource getIcon(String fileName) { | public static Resource getIcon(String fileName) { | ||||
String mimeType = getMIMEType(fileName); | |||||
Resource icon = (Resource) MIMEToIconMap.get(mimeType); | |||||
final String mimeType = getMIMEType(fileName); | |||||
final Resource icon = (Resource) MIMEToIconMap.get(mimeType); | |||||
if (icon != null) { | if (icon != null) { | ||||
return icon; | return icon; | ||||
} | } | ||||
*/ | */ | ||||
public static Resource getIcon(File file) { | public static Resource getIcon(File file) { | ||||
String mimeType = getMIMEType(file); | |||||
Resource icon = (Resource) MIMEToIconMap.get(mimeType); | |||||
final String mimeType = getMIMEType(file); | |||||
final Resource icon = (Resource) MIMEToIconMap.get(mimeType); | |||||
if (icon != null) { | if (icon != null) { | ||||
return icon; | return icon; | ||||
} | } |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/** | /** | ||||
* Associated class used for indetifying the source of the resource. | * Associated class used for indetifying the source of the resource. | ||||
*/ | */ | ||||
private Class associatedClass; | |||||
private final Class associatedClass; | |||||
/** | /** | ||||
* Name of the resource is relative to the associated class. | * Name of the resource is relative to the associated class. | ||||
*/ | */ | ||||
private String resourceName; | |||||
private final String resourceName; | |||||
/** | /** | ||||
* Application used for serving the class. | * Application used for serving the class. | ||||
*/ | */ | ||||
private Application application; | |||||
private final Application application; | |||||
/** | /** | ||||
* Creates a new application resource instance. The resource id is relative | * Creates a new application resource instance. The resource id is relative | ||||
* @see com.itmill.toolkit.terminal.ApplicationResource#getStream() | * @see com.itmill.toolkit.terminal.ApplicationResource#getStream() | ||||
*/ | */ | ||||
public DownloadStream getStream() { | public DownloadStream getStream() { | ||||
DownloadStream ds = new DownloadStream(associatedClass | |||||
final DownloadStream ds = new DownloadStream(associatedClass | |||||
.getResourceAsStream(resourceName), getMIMEType(), | .getResourceAsStream(resourceName), getMIMEType(), | ||||
getFilename()); | getFilename()); | ||||
ds.setBufferSize(getBufferSize()); | ds.setBufferSize(getBufferSize()); |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/** | /** | ||||
* Array of all the errors. | * Array of all the errors. | ||||
*/ | */ | ||||
private List errors; | |||||
private final List errors; | |||||
/** | /** | ||||
* Level of the error. | * Level of the error. | ||||
errors = new ArrayList(errorMessages.size()); | errors = new ArrayList(errorMessages.size()); | ||||
level = Integer.MIN_VALUE; | level = Integer.MIN_VALUE; | ||||
for (Iterator i = errorMessages.iterator(); i.hasNext();) { | |||||
for (final Iterator i = errorMessages.iterator(); i.hasNext();) { | |||||
addErrorMessage((ErrorMessage) i.next()); | addErrorMessage((ErrorMessage) i.next()); | ||||
} | } | ||||
private void addErrorMessage(ErrorMessage error) { | private void addErrorMessage(ErrorMessage error) { | ||||
if (error != null && !errors.contains(error)) { | if (error != null && !errors.contains(error)) { | ||||
errors.add(error); | errors.add(error); | ||||
int l = error.getErrorLevel(); | |||||
final int l = error.getErrorLevel(); | |||||
if (l > level) { | if (l > level) { | ||||
level = l; | level = l; | ||||
} | } | ||||
} | } | ||||
// Paint all the exceptions | // Paint all the exceptions | ||||
for (Iterator i = errors.iterator(); i.hasNext();) { | |||||
for (final Iterator i = errors.iterator(); i.hasNext();) { | |||||
((ErrorMessage) i.next()).paint(target); | ((ErrorMessage) i.next()).paint(target); | ||||
} | } | ||||
public String toString() { | public String toString() { | ||||
String retval = "["; | String retval = "["; | ||||
int pos = 0; | int pos = 0; | ||||
for (Iterator i = errors.iterator(); i.hasNext();) { | |||||
for (final Iterator i = errors.iterator(); i.hasNext();) { | |||||
if (pos > 0) { | if (pos > 0) { | ||||
retval += ","; | retval += ","; | ||||
} | } |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/** | /** | ||||
* Application. | * Application. | ||||
*/ | */ | ||||
private Application application; | |||||
private final Application application; | |||||
/** | /** | ||||
* Default cache time for this stream resource. | * Default cache time for this stream resource. | ||||
*/ | */ | ||||
public DownloadStream getStream() { | public DownloadStream getStream() { | ||||
try { | try { | ||||
DownloadStream ds = new DownloadStream(new FileInputStream( | |||||
final DownloadStream ds = new DownloadStream(new FileInputStream( | |||||
sourceFile), getMIMEType(), getFilename()); | sourceFile), getMIMEType(), getFilename()); | ||||
ds.setCacheTime(cacheTime); | ds.setCacheTime(cacheTime); | ||||
return ds; | return ds; | ||||
} catch (FileNotFoundException e) { | |||||
} catch (final FileNotFoundException e) { | |||||
// No logging for non-existing files at this level. | // No logging for non-existing files at this level. | ||||
return null; | return null; | ||||
} | } |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
private int lastKey = 0; | private int lastKey = 0; | ||||
private Hashtable objectKeyMap = new Hashtable(); | |||||
private final Hashtable objectKeyMap = new Hashtable(); | |||||
private Hashtable keyObjectMap = new Hashtable(); | |||||
private final Hashtable keyObjectMap = new Hashtable(); | |||||
/** | /** | ||||
* Gets key for an object. | * Gets key for an object. | ||||
* the object to be removed. | * the object to be removed. | ||||
*/ | */ | ||||
public void remove(Object removeobj) { | public void remove(Object removeobj) { | ||||
String key = (String) objectKeyMap.get(removeobj); | |||||
final String key = (String) objectKeyMap.get(removeobj); | |||||
if (key != null) { | if (key != null) { | ||||
objectKeyMap.remove(key); | objectKeyMap.remove(key); |
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2007 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/* ************************************************************************* | |||||
IT Mill Toolkit | |||||
Development of Browser User Interfaces Made Easy | |||||
Copyright (C) 2000-2006 IT Mill Ltd | |||||
************************************************************************* | |||||
This product is distributed under commercial license that can be found | |||||
from the product package on license.pdf. Use of this product might | |||||
require purchasing a commercial license from IT Mill Ltd. For guidelines | |||||
on usage, see licensing-guidelines.html | |||||
************************************************************************* | |||||
For more information, contact: | |||||
IT Mill Ltd phone: +358 2 4802 7180 | |||||
Ruukinkatu 2-4 fax: +358 2 4802 7181 | |||||
20540, Turku email: info@itmill.com | |||||
Finland company www: www.itmill.com | |||||
Primary source for information and releases: www.itmill.com | |||||
********************************************************************** */ | |||||
/* | |||||
@ITMillApache2LicenseForJavaFiles@ | |||||
*/ | |||||
package com.itmill.toolkit.terminal; | package com.itmill.toolkit.terminal; | ||||
/** | /** | ||||
* Application. | * Application. | ||||
*/ | */ | ||||
private Application application; | |||||
private final Application application; | |||||
/** | /** | ||||
* Default buffer size for this stream resource. | * Default buffer size for this stream resource. | ||||
* @see com.itmill.toolkit.terminal.ApplicationResource#getStream() | * @see com.itmill.toolkit.terminal.ApplicationResource#getStream() | ||||
*/ | */ | ||||
public DownloadStream getStream() { | public DownloadStream getStream() { | ||||
StreamSource ss = getStreamSource(); | |||||
final StreamSource ss = getStreamSource(); | |||||
if (ss == null) { | if (ss == null) { | ||||
return null; | return null; | ||||
} | } | ||||
DownloadStream ds = new DownloadStream(ss.getStream(), getMIMEType(), | |||||
getFilename()); | |||||
final DownloadStream ds = new DownloadStream(ss.getStream(), | |||||
getMIMEType(), getFilename()); | |||||
ds.setBufferSize(getBufferSize()); | ds.setBufferSize(getBufferSize()); | ||||
ds.setCacheTime(cacheTime); | ds.setCacheTime(cacheTime); | ||||
return ds; | return ds; |