From a51eeeb254b134990515094581a453338f6c9a45 Mon Sep 17 00:00:00 2001 From: "willem.cazander" Date: Tue, 19 Oct 2010 15:44:57 +0200 Subject: [PATCH] split event listeners and made xml elements for event en actions on back/frontend --- .../vasc/annotations/VascEventListener.java | 4 +- .../backends/jdbc/JdbcXpqlVascBackend.java | 42 +----- .../vasc/core/AbstractVascFrontend.java | 6 +- .../java/com/idcanet/vasc/core/VascEntry.java | 7 +- .../com/idcanet/vasc/core/VascFrontend.java | 2 + .../idcanet/vasc/core/VascFrontendData.java | 2 +- .../entry/VascEntryBackendEventListener.java | 2 +- .../idcanet/vasc/impl/DefaultVascEntry.java | 95 ++++++++++-- .../idcanet/vasc/impl/DefaultVascFactory.java | 5 +- .../vasc/impl/DefaultVascFrontendData.java | 46 +++++- .../impl/VascBackendProxyEventExecutor.java | 20 ++- .../entry/SetParameterBackendListener.java | 137 ++++++++++++++++++ .../impl/x4o/AnnotationParserElement.java | 2 +- .../vasc/impl/x4o/SetParameterElement.java | 18 +-- .../vasc/impl/x4o/VascEntryActionElement.java | 87 +++++++++++ .../impl/x4o/VascEventListenerElement.java | 68 +++++++++ .../resources/META-INF/vasc/vasc-lang.eld | 2 + .../vasc/ejb3/VascServiceManagerImpl.java | 24 +-- .../frontends/swing/SwingVascFrontend.java | 21 +-- .../vasc/frontends/swt/SwtVascFrontend.java | 7 + .../jsf/AbstractJSFVascFacesController.java | 35 ++++- .../web/jsf/JSFVascEntrySupportBean.java | 17 +-- .../web/jsf/JSFVascFrontendRenderer.java | 10 +- .../frontends/web/jsf/JSFVascUIComponent.java | 9 +- .../web/jsf/JSFVascUIComponentRenderer.java | 5 +- .../frontends/web/jsf/OldVascUIComponent.java | 9 +- 26 files changed, 559 insertions(+), 123 deletions(-) create mode 100644 vasc-core/src/main/java/com/idcanet/vasc/impl/entry/SetParameterBackendListener.java create mode 100644 vasc-core/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryActionElement.java create mode 100644 vasc-core/src/main/java/com/idcanet/vasc/impl/x4o/VascEventListenerElement.java diff --git a/vasc-core/src/main/java/com/idcanet/vasc/annotations/VascEventListener.java b/vasc-core/src/main/java/com/idcanet/vasc/annotations/VascEventListener.java index 1d8646c..c12168c 100644 --- a/vasc-core/src/main/java/com/idcanet/vasc/annotations/VascEventListener.java +++ b/vasc-core/src/main/java/com/idcanet/vasc/annotations/VascEventListener.java @@ -41,6 +41,6 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) public @interface VascEventListener { - String[] backendEventListeners(); - String[] frontendEventListeners(); + String[] backendEventListeners() default {}; + String[] frontendEventListeners() default {}; } \ No newline at end of file diff --git a/vasc-core/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcXpqlVascBackend.java b/vasc-core/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcXpqlVascBackend.java index 53b364b..4815af7 100644 --- a/vasc-core/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcXpqlVascBackend.java +++ b/vasc-core/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcXpqlVascBackend.java @@ -34,6 +34,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.idcanet.vasc.backends.MapVascEntryFieldValue; +import com.idcanet.vasc.backends.MapVascEntryRecordCreator; import com.idcanet.vasc.core.AbstractVascBackend; import com.idcanet.vasc.core.VascBackendState; import com.idcanet.vasc.core.VascEntry; @@ -151,49 +153,13 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend { * @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField) */ public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { - VascEntryFieldValue result = new VascEntryFieldValue() { - /** - * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) - */ - @SuppressWarnings("unchecked") - public Object getValue(VascEntryField field, Object record) throws VascException { - Map map = (Map)record; - Object o = map.get(field.getBackendName()); - return o; - } - - /** - * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) - */ - public String getDisplayValue(VascEntryField field, Object record) throws VascException { - return ""+getValue(field,record); // not supported - } - - /** - * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object) - */ - @SuppressWarnings("unchecked") - public void setValue(VascEntryField field, Object record,Object value) throws VascException { - Map map = (Map)record; - map.put(field.getBackendName(), value); - } - }; - return result; + return new MapVascEntryFieldValue(); } /** * @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry) */ public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { - return new VascEntryRecordCreator() { - - public Class getObjectClass() { - return Map.class; - } - - public Object newRecord(VascEntry entry) throws Exception { - return new HashMap(10); - } - }; + return new MapVascEntryRecordCreator(); } } \ No newline at end of file diff --git a/vasc-core/src/main/java/com/idcanet/vasc/core/AbstractVascFrontend.java b/vasc-core/src/main/java/com/idcanet/vasc/core/AbstractVascFrontend.java index ca2ea20..a454753 100644 --- a/vasc-core/src/main/java/com/idcanet/vasc/core/AbstractVascFrontend.java +++ b/vasc-core/src/main/java/com/idcanet/vasc/core/AbstractVascFrontend.java @@ -26,6 +26,9 @@ package com.idcanet.vasc.core; +import java.util.logging.Logger; + + /** * * @author Willem Cazander @@ -56,10 +59,11 @@ abstract public class AbstractVascFrontend implements VascFrontend { */ public void initEntry(VascEntry entry) throws Exception { if (entry.getVascFrontendData().getVascFrontend()==null) { + Logger.getLogger(AbstractVascFrontend.class.getName()).fine("Bind frontend: "+this+" to: "+entry.getVascFrontendData()+" entry: "+entry.getId()); entry.getVascFrontendData().setVascFrontend(this); } else { if (entry.getVascFrontendData().getVascFrontend()!=this) { - throw new IllegalArgumentException("VascEntry has already a differtent VascFrontend attected"); + throw new IllegalArgumentException("VascEntry '"+entry.getId()+"' data: "+entry.getVascFrontendData()+" frontend: "+this+" has already a differtent VascFrontend attected"); } } this.entry=entry; diff --git a/vasc-core/src/main/java/com/idcanet/vasc/core/VascEntry.java b/vasc-core/src/main/java/com/idcanet/vasc/core/VascEntry.java index d7e2b51..1189866 100644 --- a/vasc-core/src/main/java/com/idcanet/vasc/core/VascEntry.java +++ b/vasc-core/src/main/java/com/idcanet/vasc/core/VascEntry.java @@ -393,13 +393,13 @@ public interface VascEntry extends Cloneable,Serializable { * Added an VascEntryFrontendEventListener * @param listener The class of the event listener. */ - public void addVascEntryFrontendEventListener(String listener); + public void addVascEntryFrontendEventListener(String listener,String frontendType); /** * Returns the list of VascEntryFrontendEventListener * @return */ - public List getVascEntryFrontendEventListeners(); + public List getVascEntryFrontendEventListenersByType(String frontendType); public void addListOption(VascEntryField listOption); @@ -409,6 +409,9 @@ public interface VascEntry extends Cloneable,Serializable { public void addVascBackendFilter(VascBackendFilter filter); public List getVascBackendFilters(); + public void addVascEntryFrontendAction(String actionClass,String frontendType); + public List getVascEntryFrontendActionsByType(String frontendType); + /** * Force impl to have public clone methode * @return diff --git a/vasc-core/src/main/java/com/idcanet/vasc/core/VascFrontend.java b/vasc-core/src/main/java/com/idcanet/vasc/core/VascFrontend.java index 562a733..5cf39f8 100644 --- a/vasc-core/src/main/java/com/idcanet/vasc/core/VascFrontend.java +++ b/vasc-core/src/main/java/com/idcanet/vasc/core/VascFrontend.java @@ -40,6 +40,8 @@ public interface VascFrontend { public String getId(); + public String getFrontendType(); + public void initEntry(VascEntry entry) throws Exception; public void renderView() throws Exception; diff --git a/vasc-core/src/main/java/com/idcanet/vasc/core/VascFrontendData.java b/vasc-core/src/main/java/com/idcanet/vasc/core/VascFrontendData.java index 02b5d07..6704322 100644 --- a/vasc-core/src/main/java/com/idcanet/vasc/core/VascFrontendData.java +++ b/vasc-core/src/main/java/com/idcanet/vasc/core/VascFrontendData.java @@ -103,7 +103,7 @@ public interface VascFrontendData { public VascEntryState getVascEntryState(); public void setVascEntryState(VascEntryState state); - public void initFrontendListeners(VascEntry entry) throws InstantiationException, IllegalAccessException; + public void initFrontendListeners(VascEntry entry,String frontendType) throws InstantiationException, IllegalAccessException; public void addVascEntryFrontendEventListener(VascEntryFrontendEventListener listener); public List getVascEntryFrontendEventListener(VascEntryFrontendEventListener.VascFrontendEventType type); } \ No newline at end of file diff --git a/vasc-core/src/main/java/com/idcanet/vasc/core/entry/VascEntryBackendEventListener.java b/vasc-core/src/main/java/com/idcanet/vasc/core/entry/VascEntryBackendEventListener.java index 668346f..bbfc18d 100644 --- a/vasc-core/src/main/java/com/idcanet/vasc/core/entry/VascEntryBackendEventListener.java +++ b/vasc-core/src/main/java/com/idcanet/vasc/core/entry/VascEntryBackendEventListener.java @@ -60,7 +60,7 @@ public interface VascEntryBackendEventListener extends Serializable { POST_MOVE_UP } - public VascBackendEventType[] getEventType(); + public VascBackendEventType[] getEventTypes(); /** * Is executed when the type of event is fired. diff --git a/vasc-core/src/main/java/com/idcanet/vasc/impl/DefaultVascEntry.java b/vasc-core/src/main/java/com/idcanet/vasc/impl/DefaultVascEntry.java index d1566a5..fe2d1b5 100644 --- a/vasc-core/src/main/java/com/idcanet/vasc/impl/DefaultVascEntry.java +++ b/vasc-core/src/main/java/com/idcanet/vasc/impl/DefaultVascEntry.java @@ -41,9 +41,7 @@ import com.idcanet.vasc.core.actions.ColumnVascAction; import com.idcanet.vasc.core.actions.GlobalVascAction; import com.idcanet.vasc.core.actions.RowVascAction; import com.idcanet.vasc.core.actions.VascAction; -import com.idcanet.vasc.core.entry.VascEntryBackendEventListener; import com.idcanet.vasc.core.entry.VascEntryFieldEventChannel; -import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; /** * VascEntry @@ -87,11 +85,12 @@ public class DefaultVascEntry implements VascEntry { private List vascLinkEntries = null; private Map entryParameters = null; private VascEntryFieldEventChannel vascEntryFieldEventChannel = null; - private List eventEntryFrontendEventListeners = null; + private Map> eventEntryFrontendEventListeners = null; private List eventEntryBackendEventListeners = null; private List listOptions = null; private List backendFilters = null; - + private Map> eventEntryFrontendActions = null; + private String backendId = null; private VascFrontendData vascFrontendData = null; @@ -109,7 +108,8 @@ public class DefaultVascEntry implements VascEntry { vascLinkEntries = new ArrayList(10); entryParameters = new HashMap(10); - eventEntryFrontendEventListeners = new ArrayList(10); + eventEntryFrontendActions = new HashMap>(10); + eventEntryFrontendEventListeners = new HashMap>(10); eventEntryBackendEventListeners = new ArrayList(10); listOptions = new ArrayList(5); backendFilters = new ArrayList(3); @@ -143,8 +143,9 @@ public class DefaultVascEntry implements VascEntry { result.vascAdminDelete=vascAdminDelete; result.backendId=backendId; result.vascEntryFieldEventChannel=vascEntryFieldEventChannel; - result.eventEntryFrontendEventListeners.addAll(eventEntryFrontendEventListeners); + result.eventEntryFrontendEventListeners.putAll(eventEntryFrontendEventListeners); result.eventEntryBackendEventListeners.addAll(eventEntryBackendEventListeners); + result.eventEntryFrontendActions.putAll(eventEntryFrontendActions); // skipping 'vascFrontendData' because it should always be null when cloning happens. for (VascEntryField f:vascFields) { @@ -172,10 +173,10 @@ public class DefaultVascEntry implements VascEntry { ff.setVascEntry(result); result.listOptions.add(ff); } - for (VascBackendFilter f:backendFilters) { - VascBackendFilter ff = f.clone(); - result.backendFilters.add(ff); - } + // for (VascBackendFilter f:backendFilters) { + // VascBackendFilter ff = f.clone(); + // result.backendFilters.add(ff); + // } // no cloning of the values here ? @@ -736,18 +737,84 @@ public class DefaultVascEntry implements VascEntry { * Added an VascEntryFrontendEventListener * @param listener The class of the event listener. */ - public void addVascEntryFrontendEventListener(String listener) { - eventEntryFrontendEventListeners.add(listener); + public void addVascEntryFrontendEventListener(String listener,String frontendType) { + if (frontendType==null) { + frontendType = "__ALL__"; + } + if (frontendType.isEmpty() | "all".equalsIgnoreCase(frontendType)) { + frontendType = "__ALL__"; + } + List typeList = eventEntryFrontendEventListeners.get(frontendType); + if (typeList==null) { + typeList = new ArrayList(10); + eventEntryFrontendEventListeners.put(frontendType,typeList); + } + typeList.add(listener); } /** * Returns the list of VascEntryFrontendEventListener * @return */ - public List getVascEntryFrontendEventListeners() { - return eventEntryFrontendEventListeners; + public List getVascEntryFrontendEventListenersByType(String frontendType) { + if (frontendType==null) { + frontendType = "__ALL__"; + } + if (frontendType.isEmpty() | "all".equalsIgnoreCase(frontendType)) { + frontendType = "__ALL__"; + } + List typeList = eventEntryFrontendEventListeners.get(frontendType); + if (typeList==null) { + typeList = new ArrayList(0); + } + if (frontendType.equals("__ALL__")==false) { + // also add all + List typeListAll = eventEntryFrontendEventListeners.get("__ALL__"); + if (typeListAll!=null) { + typeList.addAll(typeListAll); + } + } + return typeList; } + public void addVascEntryFrontendAction(String actionClass,String frontendType) { + if (frontendType==null) { + frontendType = "__ALL__"; + } + if (frontendType.isEmpty() | "all".equalsIgnoreCase(frontendType)) { + frontendType = "__ALL__"; + } + List typeList = eventEntryFrontendActions.get(frontendType); + if (typeList==null) { + typeList = new ArrayList(10); + eventEntryFrontendActions.put(frontendType,typeList); + } + typeList.add(actionClass); + } + + + public List getVascEntryFrontendActionsByType(String frontendType) { + if (frontendType==null) { + frontendType = "__ALL__"; + } + if (frontendType.isEmpty() | "all".equalsIgnoreCase(frontendType)) { + frontendType = "__ALL__"; + } + List typeList = eventEntryFrontendActions.get(frontendType); + if (typeList==null) { + typeList = new ArrayList(0); + } + if (frontendType.equals("__ALL__")==false) { + // also add all + List typeListAll = eventEntryFrontendActions.get("__ALL__"); + if (typeListAll!=null) { + typeList.addAll(typeListAll); + } + } + return typeList; + } + + public void addListOption(VascEntryField listOption) { if (listOption==null) { throw new NullPointerException("can not add null listOption."); diff --git a/vasc-core/src/main/java/com/idcanet/vasc/impl/DefaultVascFactory.java b/vasc-core/src/main/java/com/idcanet/vasc/impl/DefaultVascFactory.java index fb4af8f..5d05d1a 100644 --- a/vasc-core/src/main/java/com/idcanet/vasc/impl/DefaultVascFactory.java +++ b/vasc-core/src/main/java/com/idcanet/vasc/impl/DefaultVascFactory.java @@ -115,10 +115,7 @@ public class DefaultVascFactory { if (backend.isPageable()==false) { backend = new VascBackendProxyPaged(backend,entry); } - - // execute backend event listeners - backend = new VascBackendProxyEventExecutor(backend,entry); - + // return the configed backend. return backend; } diff --git a/vasc-core/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendData.java b/vasc-core/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendData.java index ca30fd8..b552ade 100644 --- a/vasc-core/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendData.java +++ b/vasc-core/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendData.java @@ -40,6 +40,10 @@ import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.VascFrontend; import com.idcanet.vasc.core.VascFrontendData; import com.idcanet.vasc.core.VascFrontendHelper; +import com.idcanet.vasc.core.actions.ColumnVascAction; +import com.idcanet.vasc.core.actions.GlobalVascAction; +import com.idcanet.vasc.core.actions.RowVascAction; +import com.idcanet.vasc.core.actions.VascAction; import com.idcanet.vasc.core.entry.VascEntryFieldValidatorService; import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; import com.idcanet.vasc.core.entry.VascEntryResourceImageResolver; @@ -247,12 +251,12 @@ public class DefaultVascFrontendData implements VascFrontendData { } - public void initFrontendListeners(VascEntry entry) throws InstantiationException, IllegalAccessException { + public void initFrontendListeners(VascEntry entry,String frontendType) throws InstantiationException, IllegalAccessException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl==null) { cl = entry.getClass().getClassLoader(); } - for (String clazz:entry.getVascEntryFrontendEventListeners()) { + for (String clazz:entry.getVascEntryFrontendEventListenersByType(frontendType)) { VascEntryFrontendEventListener listener; try { listener = (VascEntryFrontendEventListener)cl.loadClass(clazz).newInstance(); @@ -261,6 +265,44 @@ public class DefaultVascFrontendData implements VascFrontendData { } addVascEntryFrontendEventListener(listener); } + + for (String clazz:entry.getVascEntryFrontendActionsByType(frontendType)) { + Object obj = null; + try { + obj = cl.loadClass(clazz).newInstance(); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Could not load frontend action of: "+clazz); + } + if (obj instanceof VascAction) { + VascAction action = (VascAction)obj; + String aid = action.getId(); + if (aid==null) { + throw new IllegalArgumentException("Action has no id: "+action+" in entryId: "+entry.getId()); + } + if (action.getName()==null) { + action.setName("vasc.action."+aid+".name"); + } + if (action.getDescription()==null) { + action.setDescription("vasc.action."+aid+".description"); + } + if (action.getImage()==null) { + action.setImage("vasc.action."+aid+".image"); + } + if (action.getHelpId()==null) { + action.setHelpId("vasc.action."+aid+".helpId"); + } + } + + if (obj instanceof RowVascAction) { + entry.addRowAction((RowVascAction)obj); + } + if (obj instanceof ColumnVascAction) { + entry.addColumnAction((ColumnVascAction)obj); + } + if (obj instanceof GlobalVascAction) { + entry.addGlobalAction((GlobalVascAction)obj); + } + } } public void addVascEntryFrontendEventListener(VascEntryFrontendEventListener listener) { diff --git a/vasc-core/src/main/java/com/idcanet/vasc/impl/VascBackendProxyEventExecutor.java b/vasc-core/src/main/java/com/idcanet/vasc/impl/VascBackendProxyEventExecutor.java index 9d68bee..68c44b0 100644 --- a/vasc-core/src/main/java/com/idcanet/vasc/impl/VascBackendProxyEventExecutor.java +++ b/vasc-core/src/main/java/com/idcanet/vasc/impl/VascBackendProxyEventExecutor.java @@ -67,11 +67,29 @@ public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy { listeners.add(listener); } } + + public VascBackendProxyEventExecutor(VascBackend backend,VascEntry entry,List listeners) { + super(backend); + this.entry=entry; + this.listeners=listeners; + } private void fireVascEvent(VascBackendEventType type, Object data) { for (int i=0;i clazz2 = X4OParser.loadClass(clazz); + obj = clazz2.newInstance(); + } catch (Exception e) { + throw new ElementException("Could not load class: "+clazz); + } + if (obj instanceof RowVascAction) { + v.addRowAction((RowVascAction)obj); + } + if (obj instanceof ColumnVascAction) { + v.addColumnAction((ColumnVascAction)obj); + } + if (obj instanceof GlobalVascAction) { + v.addGlobalAction((GlobalVascAction)obj); + } + } else if ("frontend".equalsIgnoreCase(type)) { + v.addVascEntryFrontendAction(clazz, frontendType); + } else { + throw new ElementException("Unsupported type attribute: "+type); + } + } +} \ No newline at end of file diff --git a/vasc-core/src/main/java/com/idcanet/vasc/impl/x4o/VascEventListenerElement.java b/vasc-core/src/main/java/com/idcanet/vasc/impl/x4o/VascEventListenerElement.java new file mode 100644 index 0000000..39c5eb8 --- /dev/null +++ b/vasc-core/src/main/java/com/idcanet/vasc/impl/x4o/VascEventListenerElement.java @@ -0,0 +1,68 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.impl.x4o; + +import com.idcanet.vasc.core.VascEntry; + +import com.idcanet.x4o.element.AbstractElement; +import com.idcanet.x4o.element.ElementException; + +/** + * Handed the eventListener xml tag. + * + * @author Willem Cazander + * @version 1.0 Oct 18, 2010 + */ +public class VascEventListenerElement extends AbstractElement { + + /** + * @see com.idcanet.x4o.element.AbstractElement#doElementRun() + */ + @Override + public void doElementRun() throws ElementException { + String clazz = getAttributes().get("class"); + String type = getAttributes().get("type"); + String frontendType = getAttributes().get("frontendType"); + if (clazz==null) { + throw new ElementException("No class attribute given."); + } + if (clazz.isEmpty()) { + throw new ElementException("class attribute is empty."); + } + if (getParent().getElementObject() instanceof VascEntry==false) { + throw new ElementException("Parent object is not vasc entry."); + } + VascEntry v = (VascEntry)getParent().getElementObject(); + if ("backend".equalsIgnoreCase(type)) { + v.addVascEntryBackendEventListener(clazz); + } else if ("frontend".equalsIgnoreCase(type)) { + v.addVascEntryFrontendEventListener(clazz, frontendType); + } else { + throw new ElementException("Unsupported type attribute: "+type); + } + } +} \ No newline at end of file diff --git a/vasc-core/src/main/resources/META-INF/vasc/vasc-lang.eld b/vasc-core/src/main/resources/META-INF/vasc/vasc-lang.eld index 1b2da16..e5d8b67 100644 --- a/vasc-core/src/main/resources/META-INF/vasc/vasc-lang.eld +++ b/vasc-core/src/main/resources/META-INF/vasc/vasc-lang.eld @@ -22,6 +22,8 @@ + + diff --git a/vasc-ejb3/src/main/java/com/idcanet/vasc/ejb3/VascServiceManagerImpl.java b/vasc-ejb3/src/main/java/com/idcanet/vasc/ejb3/VascServiceManagerImpl.java index 8e2a0e9..3611a60 100644 --- a/vasc-ejb3/src/main/java/com/idcanet/vasc/ejb3/VascServiceManagerImpl.java +++ b/vasc-ejb3/src/main/java/com/idcanet/vasc/ejb3/VascServiceManagerImpl.java @@ -49,11 +49,13 @@ import javax.persistence.EntityManager; import com.idcanet.vasc.backends.jpa.EntityManagerProvider; import com.idcanet.vasc.core.VascBackend; +import com.idcanet.vasc.core.VascBackendControllerLocal; import com.idcanet.vasc.core.VascController; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.impl.DefaultVascBackedEntryFinalizer; import com.idcanet.vasc.impl.DefaultVascEntryController; import com.idcanet.vasc.impl.DefaultVascFactory; +import com.idcanet.vasc.impl.VascBackendProxyEventExecutor; import com.idcanet.vasc.impl.actions.AddRowAction; import com.idcanet.vasc.impl.actions.CSVExportGlobalAction; import com.idcanet.vasc.impl.actions.DeleteRowAction; @@ -91,18 +93,16 @@ public class VascServiceManagerImpl implements VascServiceManager.IRemote,VascSe @PostConstruct public void loadAll() { logger.fine("VascServiceManager created now loading resources..."); - try { - long s = System.currentTimeMillis(); - + try { Map keys = loadKeys(); for (String key:keys.keySet()) { String value = keys.get(key); if ("persistenceUnit".equals(key)) { - logger.info("getting EntityManager: "+value); + logger.fine("getting EntityManager: "+value); entityManager = (EntityManager)new InitialContext().lookup(value); } if ("xpqlController".equals(key)) { - logger.info("getting XpqlQueryManagerLocal: "+value); + logger.fine("getting XpqlQueryManagerLocal: "+value); xpqlController = (XpqlQueryManager)new InitialContext().lookup(value); } if ("i18nBundle".equals(key)) { @@ -119,9 +119,10 @@ public class VascServiceManagerImpl implements VascServiceManager.IRemote,VascSe if (resourceBundle==null) { new NullPointerException("Have no resourceBundle"); } + long s = System.currentTimeMillis(); // get local jvm plugging controller - VascController c = DefaultVascFactory.getDefaultVascController(22l, "test", "login"); + VascController c = DefaultVascFactory.getDefaultVascController(0l, "nobody", "NO_ROLE"); for (String key:keys.keySet()) { String value = keys.get(key); @@ -357,8 +358,8 @@ public class VascServiceManagerImpl implements VascServiceManager.IRemote,VascSe try { // fill stuff in all global entry'ies for (String id:c.getVascEntryController().getVascEntryIds()) { - VascEntry entry = ((DefaultVascEntryController)c.getVascEntryController()).getRealVascEntryById(id); - if (entry.isVascDisplayOnly()==false) { + VascEntry entry = ((DefaultVascEntryController)c.getVascEntryController()).getRealVascEntryById(id); + if (entry.isVascDisplayOnly()==false) { if (entry.isVascAdminCreate()) { entry.addRowAction(new AddRowAction()); } @@ -391,9 +392,14 @@ public class VascServiceManagerImpl implements VascServiceManager.IRemote,VascSe // this is temp untill x4o templaing DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer(); f.finalizeVascEntry(entry, c); + + // execute backend event listeners + VascBackend vb = c.getVascBackendController().getVascBackendById(entry.getBackendId()); + vb = new VascBackendProxyEventExecutor(vb,entry); + ((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(vb); } - logger.info("VASC COMPLEET LETS RETURN."); + logger.finer("Done final config vascController: "+c); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/vasc-frontend-swing/src/main/java/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java b/vasc-frontend-swing/src/main/java/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java index e98bc5b..c2729a5 100644 --- a/vasc-frontend-swing/src/main/java/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java +++ b/vasc-frontend-swing/src/main/java/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java @@ -98,6 +98,13 @@ public class SwingVascFrontend extends AbstractVascFrontend { this.parent=parent; } + /** + * @see com.idcanet.vasc.core.VascFrontend#getFrontendType() + */ + public String getFrontendType() { + return "swing"; + } + /** * Add swing implmented ui components */ @@ -686,15 +693,12 @@ class SpringUtilities { * @param yPad * y padding between cells */ - public static void makeGrid(Container parent, int rows, int cols, - int initialX, int initialY, int xPad, int yPad) { + public static void makeGrid(Container parent, int rows, int cols,int initialX, int initialY, int xPad, int yPad) { SpringLayout layout; try { layout = (SpringLayout) parent.getLayout(); } catch (ClassCastException exc) { - System.err - .println("The first argument to makeGrid must use SpringLayout."); - return; + throw new IllegalArgumentException("parent container has not StringLayout layoutmanager."); } Spring xPadSpring = Spring.constant(xPad); @@ -788,15 +792,12 @@ class SpringUtilities { * @param yPad * y padding between cells */ - public static void makeCompactGrid(Container parent, int rows, int cols, - int initialX, int initialY, int xPad, int yPad) { + public static void makeCompactGrid(Container parent, int rows, int cols,int initialX, int initialY, int xPad, int yPad) { SpringLayout layout; try { layout = (SpringLayout) parent.getLayout(); } catch (ClassCastException exc) { - System.err - .println("The first argument to makeCompactGrid must use SpringLayout."); - return; + throw new IllegalArgumentException("parent container has not StringLayout layoutmanager."); } //Align all cells in each column and make them the same width. diff --git a/vasc-frontend-swt/src/main/java/com/idcanet/vasc/frontends/swt/SwtVascFrontend.java b/vasc-frontend-swt/src/main/java/com/idcanet/vasc/frontends/swt/SwtVascFrontend.java index 8ff9b26..95a2cc9 100644 --- a/vasc-frontend-swt/src/main/java/com/idcanet/vasc/frontends/swt/SwtVascFrontend.java +++ b/vasc-frontend-swt/src/main/java/com/idcanet/vasc/frontends/swt/SwtVascFrontend.java @@ -104,6 +104,13 @@ public class SwtVascFrontend extends AbstractVascFrontend { this.parent=parent; } + /** + * @see com.idcanet.vasc.core.VascFrontend#getFrontendType() + */ + public String getFrontendType() { + return "swt"; + } + /** * Add swt implmented ui components */ diff --git a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/AbstractJSFVascFacesController.java b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/AbstractJSFVascFacesController.java index 0529757..f252891 100644 --- a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/AbstractJSFVascFacesController.java +++ b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/AbstractJSFVascFacesController.java @@ -51,13 +51,17 @@ import com.idcanet.vasc.core.VascEntryControllerLocal; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.VascFrontendData; +import com.idcanet.vasc.core.entry.VascEntryBackendEventListener; import com.idcanet.vasc.core.entry.VascEntryFieldValue; import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; import com.idcanet.vasc.core.entry.VascEntryRecordCreator; import com.idcanet.vasc.ejb3.VascServiceManager; import com.idcanet.vasc.impl.DefaultVascBackedEntryFinalizer; +import com.idcanet.vasc.impl.DefaultVascEntryState; import com.idcanet.vasc.impl.DefaultVascFactory; +import com.idcanet.vasc.impl.VascBackendProxyEventExecutor; import com.idcanet.vasc.impl.entry.DefaultVascEntryResourceResolver; +import com.idcanet.vasc.impl.entry.SetParameterBackendListener; /** * Base faces session object for managing vasc entries. @@ -175,6 +179,9 @@ abstract public class AbstractJSFVascFacesController { VascEntry entry = getVascController().getVascEntryController().getVascEntryById(entryId); entry.setVascFrontendData(getNewVascFrontendData()); entry.getVascFrontendData().setVascController(getVascController()); + VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry); + entry.getVascFrontendData().getVascEntryState().setVascBackend(backend); + entry.getVascFrontendData().getVascEntryState().setVascEntry(entry); // copy para if (para!=null) { @@ -187,8 +194,7 @@ abstract public class AbstractJSFVascFacesController { entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); return entry.getVascFrontendData().getVascEntryState().getEntryDataList(); } catch (Exception e) { - e.printStackTrace(); - return new ArrayList(0); + throw new RuntimeException("Could not execute list: "+e.getMessage(),e); } } @@ -386,6 +392,31 @@ abstract public class AbstractJSFVascFacesController { VascEntry ve = vascManager.getVascEntry(id); String backendId = ve.getBackendId(); VascBackend vb = new RemoteVascBackend(backendId,vascManager); + + for (String key:ve.getEntryParameterKeys()) { + Object value = ve.getEntryParameter(key); + if (value instanceof String==false) { + continue; + } + String paraValue = (String)value; + if (paraValue.startsWith("userPara")==false) { + continue; + } + String[] ps = paraValue.split(":"); + String type = ps[1]; + String paraTypeValue = ps[2]; + + SetParameterBackendListener listener = new SetParameterBackendListener(vui.userId,vui.username); + listener.setName(key); + listener.setType(type); + // listener.setValue(paraTypeValue); + + List listeners=new ArrayList(10); + listeners.add(listener); + vb = new VascBackendProxyEventExecutor(vb,ve,listeners); + } + + localBackendController.addVascBackend(vb); DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer(); diff --git a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java index 1c571bc..77121f8 100644 --- a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java +++ b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java @@ -153,7 +153,7 @@ public class JSFVascEntrySupportBean implements Serializable { try { result = ve.getDisplayValue(v, row); } catch (VascException e) { - e.printStackTrace(); + throw new RuntimeException("Could not get parent name DisplayValue: "+e.getMessage(),e); } return result; } @@ -169,7 +169,7 @@ public class JSFVascEntrySupportBean implements Serializable { try { result = ve.getDisplayValue(v, row); } catch (VascException e) { - e.printStackTrace(); + throw new RuntimeException("Could not get selected name DisplayValue: "+e.getMessage(),e); } return result; } @@ -528,8 +528,7 @@ public class JSFVascEntrySupportBean implements Serializable { } state.getMultiActionSelection().clear(); // after down deselect all options } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + throw new RuntimeException("Could not do multirowaction",e); } finally { vascEntry=null; } @@ -606,15 +605,7 @@ public class JSFVascEntrySupportBean implements Serializable { // select record to edit Object rowObject = entry.getVascFrontendData().getVascEntryState().getParent().getEntryDataObject(); - //String idField = entry.getVascFrontendData().getVascEntryState().getParent().getVascEntry().getPrimaryKeyFieldId(); - // VascEntryField field = entry.getVascFrontendData().getVascEntryState().getParent().getVascEntry().getVascEntryFieldById(idField); -// try { - // Object id = field.getVascEntryFieldValue().getValue(field, rowObject); - comp.initGoto(entry.getVascFrontendData().getVascEntryState().getParent(),rowObject); - // } catch (VascException e1) { - // TODO Auto-generated catch block - // e1.printStackTrace(); - //} + comp.initGoto(entry.getVascFrontendData().getVascEntryState().getParent(),rowObject); } diff --git a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java index 1522e11..a4b02f0 100644 --- a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java +++ b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java @@ -57,7 +57,15 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser logger = Logger.getLogger(JSFVascFrontendRenderer.class.getName()); } - // Frontend Stuff + // Frontend Stuff + + /** + * @see com.idcanet.vasc.core.VascFrontend#getFrontendType() + */ + public String getFrontendType() { + return "jsf"; + } + protected void addUiComponents() { VascFrontendData vfd = getVascEntry().getVascFrontendData(); diff --git a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java index 7a7107b..cb08923 100644 --- a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java +++ b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java @@ -217,7 +217,7 @@ public class JSFVascUIComponent extends UIComponentBase { try { renderer.initEntry(entry); } catch (Exception e) { - entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + throw new RuntimeException("Could not initEntry: "+e.getMessage(),e); } supportBean = new JSFVascEntrySupportBean(entry); // copy search string for preadded search string from application layer @@ -243,7 +243,7 @@ public class JSFVascUIComponent extends UIComponentBase { entry.getVascFrontendData().getVascEntryState().setEntryDataObject(rowObject); entry.getVascFrontendData().getVascFrontend().renderEdit(); } catch (Exception e) { - e.printStackTrace(); + throw new RuntimeException("Could not renderEdit: "+e.getMessage(),e); } } @@ -324,10 +324,11 @@ public class JSFVascUIComponent extends UIComponentBase { throw new NullPointerException("Could not locate '"+entryName+"' from : "+vascController); } + frontendData.setVascFrontend(null); // reset data obj. todo rm this. frontendData.setVascController(vascController); entry.setVascFrontendData(frontendData); try { - frontendData.initFrontendListeners(entry); + frontendData.initFrontendListeners(entry,"jsf"); } catch (InstantiationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); @@ -385,7 +386,7 @@ public class JSFVascUIComponent extends UIComponentBase { entry.getVascFrontendData().addVascEntryFrontendEventListener(new CreateEntryFieldValuesListener2(fieldId,selectedValue)); } } catch (Exception e) { - e.printStackTrace(); + throw new RuntimeException("error: "+e.getMessage(),e); } } diff --git a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java index c06e9b8..319adb5 100644 --- a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java +++ b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java @@ -166,8 +166,11 @@ public class JSFVascUIComponentRenderer extends Renderer { JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(grid); VascEntry entry = comp.getVascEntry(); + if (entry==null) { + throw new NullPointerException("No parent vasc component found."); + } + String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); - int column = 0; for (VascEntryField c:entry.getVascEntryFields()) { if (entry.getVascFrontendData().getVascFrontendHelper().renderEdit(c)==false) { diff --git a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/OldVascUIComponent.java b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/OldVascUIComponent.java index 8dcbfe9..a428813 100644 --- a/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/OldVascUIComponent.java +++ b/vasc-frontend-web-jsf/src/main/java/com/idcanet/vasc/frontends/web/jsf/OldVascUIComponent.java @@ -207,7 +207,7 @@ public class OldVascUIComponent extends UIComponentBase { ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), vascFrontendData.getExpressionString(), VascFrontendData.class); VascFrontendData frontendData = (VascFrontendData)ve2.getValue(FacesContext.getCurrentInstance().getELContext()); try { - frontendData.initFrontendListeners(entry); + frontendData.initFrontendListeners(entry,"jsf"); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -1597,6 +1597,13 @@ class JSFFrontendRenderer extends AbstractVascFrontend implements Serializable { private static final long serialVersionUID = 1L; + /** + * @see com.idcanet.vasc.core.VascFrontend#getFrontendType() + */ + public String getFrontendType() { + return "jsf"; + } + // Frontend Stuff protected void addUiComponents() {