From 4f409296d0744046bf69d0a8103ddbf1e0d01e2a Mon Sep 17 00:00:00 2001 From: "willem.cazander" Date: Thu, 26 Aug 2010 00:51:14 +0200 Subject: [PATCH] splitted the event listeners --- .../vasc/annotations/VascEventListener.java | 7 +- .../java/com/idcanet/vasc/core/VascEntry.java | 28 +++++--- .../idcanet/vasc/core/VascFrontendData.java | 18 ++--- .../idcanet/vasc/core/VascFrontendHelper.java | 4 +- ...va => VascEntryFrontendEventListener.java} | 15 ++-- .../frontends/swing/SwingVascFrontend.java | 19 ++--- .../vasc/frontends/swt/SwtVascFrontend.java | 15 ++-- .../web/jsf/JSFVascEntryEventListener.java | 23 +++--- .../web/jsf/JSFVascEntrySupportBean.java | 27 ++++--- .../frontends/web/jsf/JSFVascUIComponent.java | 31 +++++--- .../web/jsf/JSFVascValidatePhaseListener.java | 14 +++- .../frontends/web/jsf/OldVascUIComponent.java | 39 +++++++---- .../idcanet/vasc/impl/DefaultVascEntry.java | 61 ++++++++-------- .../idcanet/vasc/impl/DefaultVascFactory.java | 10 --- .../vasc/impl/DefaultVascFrontendData.java | 47 ++++++++----- .../vasc/impl/DefaultVascFrontendHelper.java | 42 +++++------ .../vasc/impl/DefaultVascSelectItemModel.java | 38 +++++----- .../vasc/impl/actions/EditRowAction.java | 4 +- .../type/MultiTextVascEntryFieldType.java | 70 ++++++++++++++++++- .../impl/x4o/AnnotationParserElement.java | 25 +++---- src/main/resources/META-INF/fieldtypes.xml | 2 +- src/test/java/com/idcanet/vasc/SwingTest.java | 3 + src/test/resources/vasc/tables.xml | 2 +- 23 files changed, 327 insertions(+), 217 deletions(-) rename src/main/java/com/idcanet/vasc/core/entry/{VascEntryEventListener.java => VascEntryFrontendEventListener.java} (85%) diff --git a/src/main/java/com/idcanet/vasc/annotations/VascEventListener.java b/src/main/java/com/idcanet/vasc/annotations/VascEventListener.java index 8c563d4..9e99e6a 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascEventListener.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascEventListener.java @@ -31,9 +31,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType; - - /** * Event listener annotation * @@ -44,7 +41,5 @@ import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType; @Target(ElementType.TYPE) public @interface VascEventListener { - String[] listeners(); - - VascEventType[] types(); + Class[] listeners(); } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/VascEntry.java b/src/main/java/com/idcanet/vasc/core/VascEntry.java index 04f7582..70cff2d 100644 --- a/src/main/java/com/idcanet/vasc/core/VascEntry.java +++ b/src/main/java/com/idcanet/vasc/core/VascEntry.java @@ -32,8 +32,9 @@ import java.util.List; 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.entry.VascEntryEventListener; +import com.idcanet.vasc.core.entry.VascEntryBackendEventListener; import com.idcanet.vasc.core.entry.VascEntryFieldEventChannel; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; /** * The main vasc entry @@ -379,18 +380,29 @@ public interface VascEntry extends Cloneable,Serializable { public void setVascEntryFieldEventChannel(VascEntryFieldEventChannel vascEntryFieldEventChannel); /** - * Added an VascEntryEventListener - * @param type - * @param listener + * Added an VascEntryBackendEventListener + * @param listener The class of the event listener. */ - public void addVascEntryEventListener(VascEntryEventListener.VascEventType type,VascEntryEventListener listener); + public void addVascEntryBackendEventListener(Class listener); /** - * Returns the list of VascEntryEventListener for a speciec type. - * @param type + * Returns the list of VascEntryBackendEventListener * @return */ - public List getVascEntryEventListeners(VascEntryEventListener.VascEventType type); + public List> getVascEntryBackendEventListeners(); + + /** + * Added an VascEntryFrontendEventListener + * @param listener The class of the event listener. + */ + public void addVascEntryFrontendEventListener(Class listener); + + /** + * Returns the list of VascEntryFrontendEventListener + * @return + */ + public List> getVascEntryFrontendEventListeners(); + public void addListOption(VascEntryField listOption); public List getListOptions(); diff --git a/src/main/java/com/idcanet/vasc/core/VascFrontendData.java b/src/main/java/com/idcanet/vasc/core/VascFrontendData.java index d225dd2..02b5d07 100644 --- a/src/main/java/com/idcanet/vasc/core/VascFrontendData.java +++ b/src/main/java/com/idcanet/vasc/core/VascFrontendData.java @@ -28,8 +28,8 @@ package com.idcanet.vasc.core; import java.util.List; -import com.idcanet.vasc.core.entry.VascEntryEventListener; import com.idcanet.vasc.core.entry.VascEntryFieldValidatorService; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; import com.idcanet.vasc.core.entry.VascEntryResourceImageResolver; import com.idcanet.vasc.core.entry.VascEntryResourceResolver; import com.idcanet.vasc.core.ui.VascUIComponent; @@ -86,17 +86,7 @@ public interface VascFrontendData { public VascUIComponent getFieldVascUIComponent(VascEntryField field); public Object getFieldRealRenderer(VascEntryField field); public void clearFieldRenderObjects(); - - /** - * @return the exceptionListener - */ - public VascEntryEventListener getExceptionListener(); - - /** - * @param exceptionListener the exceptionListener to set - */ - public void setExceptionListener(VascEntryEventListener exceptionListener); - + /** * @return the vascEntryResourceImageResolver */ @@ -112,4 +102,8 @@ public interface VascFrontendData { public VascEntryState getVascEntryState(); public void setVascEntryState(VascEntryState state); + + public void initFrontendListeners(VascEntry entry) throws InstantiationException, IllegalAccessException; + public void addVascEntryFrontendEventListener(VascEntryFrontendEventListener listener); + public List getVascEntryFrontendEventListener(VascEntryFrontendEventListener.VascFrontendEventType type); } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/VascFrontendHelper.java b/src/main/java/com/idcanet/vasc/core/VascFrontendHelper.java index dbed6d7..6dacda2 100644 --- a/src/main/java/com/idcanet/vasc/core/VascFrontendHelper.java +++ b/src/main/java/com/idcanet/vasc/core/VascFrontendHelper.java @@ -30,7 +30,7 @@ import java.util.List; import com.idcanet.vasc.core.actions.GlobalVascAction; import com.idcanet.vasc.core.actions.RowVascAction; -import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType; /** @@ -76,7 +76,7 @@ public interface VascFrontendHelper { public void handleException(VascEntry entry,Exception exception); - public void fireVascEvent(VascEntry entry,VascEventType type,Object data); + public void fireVascEvent(VascEntry entry,VascFrontendEventType type,Object data); public void sortAction(VascEntry entry,VascEntryField field); diff --git a/src/main/java/com/idcanet/vasc/core/entry/VascEntryEventListener.java b/src/main/java/com/idcanet/vasc/core/entry/VascEntryFrontendEventListener.java similarity index 85% rename from src/main/java/com/idcanet/vasc/core/entry/VascEntryEventListener.java rename to src/main/java/com/idcanet/vasc/core/entry/VascEntryFrontendEventListener.java index 7a0c689..63351ce 100644 --- a/src/main/java/com/idcanet/vasc/core/entry/VascEntryEventListener.java +++ b/src/main/java/com/idcanet/vasc/core/entry/VascEntryFrontendEventListener.java @@ -36,9 +36,9 @@ import com.idcanet.vasc.core.VascEntry; * @author Willem Cazander * @version 1.0 Aug 02, 2007 */ -public interface VascEntryEventListener extends Cloneable,Serializable { +public interface VascEntryFrontendEventListener extends Serializable { - public enum VascEventType { + public enum VascFrontendEventType { EXCEPTION, DATA_CREATE, @@ -56,18 +56,13 @@ public interface VascEntryEventListener extends Cloneable,Serializable { OPTION_UPDATE, } + public VascFrontendEventType[] getEventTypes(); + /** * Is executed when the type of event is fired. * @param entry * @param type * @param data */ - public void vascEvent(VascEntry entry,VascEventType type,Object data); - - /** - * Force impl to have public clone methode - * @return - * @throws CloneNotSupportedException - */ - public VascEntryEventListener clone() throws CloneNotSupportedException; + public void vascEvent(VascEntry entry,Object data); } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java b/src/main/java/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java index b0e3980..c414091 100644 --- a/src/main/java/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java +++ b/src/main/java/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java @@ -64,14 +64,13 @@ import javax.swing.table.JTableHeader; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; -import com.idcanet.fff.SwingImageHelper; import com.idcanet.vasc.core.AbstractVascFrontend; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascFrontendData; import com.idcanet.vasc.core.actions.GlobalVascAction; import com.idcanet.vasc.core.actions.RowVascAction; -import com.idcanet.vasc.core.entry.VascEntryEventListener; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; import com.idcanet.vasc.core.entry.VascEntryExporter; import com.idcanet.vasc.core.ui.VascColumnValueModelListener; import com.idcanet.vasc.core.ui.VascUIComponent; @@ -128,7 +127,8 @@ public class SwingVascFrontend extends AbstractVascFrontend { } if (key.indexOf("META-INF")>0 | key.indexOf("resource")>0) { - return SwingImageHelper.getImageIcon(key); + return null; + //return SwingImageHelper.getImageIcon(key); } else { return null; } @@ -592,16 +592,12 @@ public class SwingVascFrontend extends AbstractVascFrontend { } } - class VascColumnModel extends AbstractTableModel implements VascEntryEventListener { + class VascColumnModel extends AbstractTableModel implements VascEntryFrontendEventListener { private static final long serialVersionUID = 10L; - public void vascEvent(VascEntry entry,VascEventType e,Object o) { + public void vascEvent(VascEntry entry,Object o) { fireTableDataChanged(); } - public VascEntryEventListener clone() throws CloneNotSupportedException { - throw new CloneNotSupportedException(); - } - /** * @see javax.swing.entry.entryModel#getColumnCount() @@ -655,6 +651,11 @@ public class SwingVascFrontend extends AbstractVascFrontend { return "Error"; } } + + public VascFrontendEventType[] getEventTypes() { + VascFrontendEventType[] result = {VascFrontendEventType.DATA_LIST_UPDATE}; + return result; + } } } diff --git a/src/main/java/com/idcanet/vasc/frontends/swt/SwtVascFrontend.java b/src/main/java/com/idcanet/vasc/frontends/swt/SwtVascFrontend.java index e1e429d..f441d68 100644 --- a/src/main/java/com/idcanet/vasc/frontends/swt/SwtVascFrontend.java +++ b/src/main/java/com/idcanet/vasc/frontends/swt/SwtVascFrontend.java @@ -74,9 +74,9 @@ import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.VascFrontendData; import com.idcanet.vasc.core.actions.GlobalVascAction; import com.idcanet.vasc.core.actions.RowVascAction; -import com.idcanet.vasc.core.entry.VascEntryEventListener; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; import com.idcanet.vasc.core.entry.VascEntryExporter; -import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType; import com.idcanet.vasc.core.ui.VascOptionValueModelListener; import com.idcanet.vasc.core.ui.VascUIComponent; import com.idcanet.vasc.core.ui.VascValueModel; @@ -440,14 +440,15 @@ public class SwtVascFrontend extends AbstractVascFrontend { } }; - entry.addVascEntryEventListener(VascEventType.DATA_LIST_UPDATE, new VascEntryEventListener() { - public void vascEvent(VascEntry entry,VascEventType type,Object data) { + entry.getVascFrontendData().addVascEntryFrontendEventListener(new VascEntryFrontendEventListener() { + public VascFrontendEventType[] getEventTypes() { + VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.DATA_LIST_UPDATE}; + return result; + } + public void vascEvent(VascEntry entry,Object data) { tableViewer.refresh(); table2.deselectAll(); } - public VascEntryEventListener clone() throws CloneNotSupportedException { - return this; - } }); diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntryEventListener.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntryEventListener.java index 16f3f46..ad3045b 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntryEventListener.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntryEventListener.java @@ -11,14 +11,14 @@ import javax.faces.context.FacesContext; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; -import com.idcanet.vasc.core.entry.VascEntryEventListener; import com.idcanet.vasc.core.entry.VascEntryFieldValue; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; /** * @author willemc * */ -public class JSFVascEntryEventListener implements VascEntryEventListener { +public class JSFVascEntryEventListener implements VascEntryFrontendEventListener { private static final long serialVersionUID = 1765054259934158076L; private String entrySupportVar = null; @@ -26,8 +26,18 @@ public class JSFVascEntryEventListener implements VascEntryEventListener { public JSFVascEntryEventListener(String entrySupportVar) { this.entrySupportVar=entrySupportVar; } - - public void vascEvent(VascEntry entry, VascEventType type,Object dataNotUsed) { + + /** + * @see com.idcanet.vasc.core.entry.VascEntryFrontendEventListener#getEventTypes() + */ + public VascFrontendEventType[] getEventTypes() { + VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.DATA_LIST_UPDATE}; + return result; + } + + + + public void vascEvent(VascEntry entry,Object dataNotUsed) { try { for (VascEntryField field:entry.getVascEntryFields()) { if (field.getVascEntryFieldValue()==null) { @@ -56,9 +66,4 @@ public class JSFVascEntryEventListener implements VascEntryEventListener { ValueExpression ve3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".tablePagesDataModel.wrappedData}", Object.class); ve3.setValue(FacesContext.getCurrentInstance().getELContext(), entry.getVascFrontendData().getVascFrontendHelper().getVascBackendPageNumbers(entry)); } - @Override - public VascEntryEventListener clone() throws CloneNotSupportedException { - return this; - } - } diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java index 02dfed2..1c571bc 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java @@ -295,6 +295,14 @@ public class JSFVascEntrySupportBean implements Serializable { return result; } + public boolean getHasOnlySinglePage() { + int pages = getTablePagesDataModel().getRowCount(); + if (pages==1) { + return true; + } + return false; + } + public boolean getHasExtendedPageMode() { int pages = getTablePagesDataModel().getRowCount(); if (pages>13) { @@ -851,16 +859,17 @@ public class JSFVascEntrySupportBean implements Serializable { JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); VascEntryState state = entry.getVascFrontendData().getVascEntryState(); - if (state.getMultiActionSelection().isEmpty()==false) { - List sels = new ArrayList(5); - for (Integer rowId:state.getMultiActionSelection().keySet()) { - Boolean value = state.getMultiActionSelection().get(rowId); - logger.fine("multiRow delete: "+rowId+" value: "+value); - if (value!=null && value==true) { - Object row = state.getEntryDataList().get(rowId); - sels.add(row); - } + + List sels = new ArrayList(5); + for (Integer rowId:state.getMultiActionSelection().keySet()) { + Boolean value = state.getMultiActionSelection().get(rowId); + logger.fine("multiRow delete: "+rowId+" value: "+value); + if (value!=null && value==true) { + Object row = state.getEntryDataList().get(rowId); + sels.add(row); } + } + if (sels.isEmpty()==false) { for (Object row:sels) { entry.getVascFrontendData().getVascEntryState().setEntryDataObject(row); entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry); diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java index 2ce4751..8493750 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java @@ -45,8 +45,8 @@ import com.idcanet.vasc.core.VascEntryState; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.VascFrontendData; import com.idcanet.vasc.core.VascLinkEntry; -import com.idcanet.vasc.core.entry.VascEntryEventListener; -import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType; import com.idcanet.vasc.frontends.web.jsf.ui.JSFListModel; import com.idcanet.vasc.impl.DefaultVascFactory; @@ -239,7 +239,7 @@ public class JSFVascUIComponent extends UIComponentBase { try { VascEntry entry = supportBean.getVascEntry(); entry.getVascFrontendData().getVascEntryState().setEditCreate(false); - entry.getVascFrontendData().getVascFrontendHelper().fireVascEvent(entry, VascEventType.DATA_SELECT, rowObject); + entry.getVascFrontendData().getVascFrontendHelper().fireVascEvent(entry, VascFrontendEventType.DATA_SELECT, rowObject); entry.getVascFrontendData().getVascEntryState().setEntryDataObject(rowObject); entry.getVascFrontendData().getVascFrontend().renderEdit(); } catch (Exception e) { @@ -326,6 +326,15 @@ public class JSFVascUIComponent extends UIComponentBase { frontendData.setVascController(vascController); entry.setVascFrontendData(frontendData); + try { + frontendData.initFrontendListeners(entry); + } catch (InstantiationException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (IllegalAccessException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry); frontendData.getVascEntryState().setVascBackend(backend); frontendData.getVascEntryState().setVascEntry(entry); @@ -373,7 +382,7 @@ public class JSFVascUIComponent extends UIComponentBase { } // create listener for new objects - entry.addVascEntryEventListener(VascEventType.DATA_CREATE, new CreateEntryFieldValuesListener2(fieldId,selectedValue)); + entry.getVascFrontendData().addVascEntryFrontendEventListener(new CreateEntryFieldValuesListener2(fieldId,selectedValue)); } } catch (Exception e) { e.printStackTrace(); @@ -382,12 +391,12 @@ public class JSFVascUIComponent extends UIComponentBase { String entrySupportVar = (String)getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); - entry.addVascEntryEventListener(VascEntryEventListener.VascEventType.DATA_LIST_UPDATE, new JSFVascEntryEventListener(entrySupportVar)); + entry.getVascFrontendData().addVascEntryFrontendEventListener(new JSFVascEntryEventListener(entrySupportVar)); return entry; } - class CreateEntryFieldValuesListener2 implements VascEntryEventListener { + class CreateEntryFieldValuesListener2 implements VascEntryFrontendEventListener { private static final long serialVersionUID = 1L; private String fieldId = null; private Object value = null; @@ -398,7 +407,11 @@ public class JSFVascUIComponent extends UIComponentBase { this.fieldId=fieldId; this.value=value; } - public void vascEvent(VascEntry entry,VascEventType type, Object data) { + public VascFrontendEventType[] getEventTypes() { + VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.DATA_CREATE}; + return result; + } + public void vascEvent(VascEntry entry,Object data) { VascEntryField field = entry.getVascEntryFieldById(fieldId); try { field.getVascEntryFieldValue().setValue(field, data, value); @@ -406,9 +419,5 @@ public class JSFVascUIComponent extends UIComponentBase { entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); } } - @Override - public VascEntryEventListener clone() throws CloneNotSupportedException { - return this; - } } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascValidatePhaseListener.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascValidatePhaseListener.java index 215a239..4df464b 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascValidatePhaseListener.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascValidatePhaseListener.java @@ -4,6 +4,7 @@ package com.idcanet.vasc.frontends.web.jsf; import java.util.Iterator; +import java.util.Map; import java.util.logging.Logger; import javax.faces.application.FacesMessage; @@ -35,9 +36,20 @@ public class JSFVascValidatePhaseListener implements PhaseListener { logger = Logger.getLogger(JSFVascValidatePhaseListener.class.getName()); } + private static final String SAVE_ACTION_ID_HACK = "VASC_SAVE"; + public void afterPhase(PhaseEvent event) { FacesContext context = event.getFacesContext(); - validateUIInput(context.getViewRoot(),context); + + // we really only want validation this early when saveing. + // this is currently a bit hacky impl; + Map requestMap = context.getExternalContext().getRequestParameterMap(); + for (String key:requestMap.keySet()) { + if (key.contains(SAVE_ACTION_ID_HACK)) { + validateUIInput(context.getViewRoot(),context); + return; + } + } } public void beforePhase(PhaseEvent event) { } diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/OldVascUIComponent.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/OldVascUIComponent.java index 63f58ec..c2a3ead 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/OldVascUIComponent.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/OldVascUIComponent.java @@ -76,10 +76,10 @@ import com.idcanet.vasc.core.VascFrontendData; import com.idcanet.vasc.core.VascLinkEntry; import com.idcanet.vasc.core.actions.GlobalVascAction; import com.idcanet.vasc.core.actions.RowVascAction; -import com.idcanet.vasc.core.entry.VascEntryEventListener; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; import com.idcanet.vasc.core.entry.VascEntryExporter; import com.idcanet.vasc.core.entry.VascEntryFieldValue; -import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType; import com.idcanet.vasc.core.ui.VascOptionValueModelListener; import com.idcanet.vasc.core.ui.VascValueModel; import com.idcanet.vasc.frontends.web.jsf.ui.JSFBoolean; @@ -208,6 +208,15 @@ 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); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } frontendData.setVascController(vascControllerObj); entry.setVascFrontendData(frontendData); @@ -229,9 +238,13 @@ public class OldVascUIComponent extends UIComponentBase { } frontendData.getVascEntryState().setVascBackend(backend); - entry.addVascEntryEventListener(VascEntryEventListener.VascEventType.DATA_LIST_UPDATE, new VascEntryEventListener() { + entry.getVascFrontendData().addVascEntryFrontendEventListener(new VascEntryFrontendEventListener() { private static final long serialVersionUID = 1L; - public void vascEvent(VascEntry entry, VascEventType type,Object dataNotUsed) { + public VascFrontendEventType[] getEventTypes() { + VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.DATA_LIST_UPDATE}; + return result; + } + public void vascEvent(VascEntry entry, Object dataNotUsed) { List data = entry.getVascFrontendData().getVascEntryState().getEntryDataList(); for (VascEntryField field:entry.getVascEntryFields()) { if (field.getVascEntryFieldValue()==null) { @@ -255,10 +268,6 @@ public class OldVascUIComponent extends UIComponentBase { ValueExpression ren4 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['totalResults']}", Integer.class); ren4.setValue(FacesContext.getCurrentInstance().getELContext(), getVascEntry().getVascFrontendData().getVascEntryState().getTotalBackendRecords()); } - @Override - public VascEntryEventListener clone() throws CloneNotSupportedException { - return this; - } }); return entry; @@ -451,7 +460,7 @@ public class OldVascUIComponent extends UIComponentBase { } // create listener for new objects - entry.addVascEntryEventListener(VascEventType.DATA_CREATE, new CreateEntryFieldValuesListener(fieldId,selectedValue)); + entry.getVascFrontendData().addVascEntryFrontendEventListener(new CreateEntryFieldValuesListener(fieldId,selectedValue)); } } @@ -477,7 +486,7 @@ public class OldVascUIComponent extends UIComponentBase { } } - class CreateEntryFieldValuesListener implements VascEntryEventListener { + class CreateEntryFieldValuesListener implements VascEntryFrontendEventListener { private static final long serialVersionUID = 1L; private String fieldId = null; private Object value = null; @@ -488,7 +497,11 @@ public class OldVascUIComponent extends UIComponentBase { this.fieldId=fieldId; this.value=value; } - public void vascEvent(VascEntry entry,VascEventType type, Object data) { + public VascFrontendEventType[] getEventTypes() { + VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.DATA_CREATE}; + return result; + } + public void vascEvent(VascEntry entry,Object data) { VascEntryField field = entry.getVascEntryFieldById(fieldId); try { field.getVascEntryFieldValue().setValue(field, data, value); @@ -496,10 +509,6 @@ public class OldVascUIComponent extends UIComponentBase { entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); } } - @Override - public VascEntryEventListener clone() throws CloneNotSupportedException { - return this; - } } public Object getSelectedTableObject() { diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascEntry.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascEntry.java index 31eb823..c8f9ddb 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascEntry.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascEntry.java @@ -41,8 +41,9 @@ 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.VascEntryEventListener; +import com.idcanet.vasc.core.entry.VascEntryBackendEventListener; import com.idcanet.vasc.core.entry.VascEntryFieldEventChannel; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; /** * VascEntry @@ -86,7 +87,8 @@ public class DefaultVascEntry implements VascEntry { private List vascLinkEntries = null; private Map entryParameters = null; private VascEntryFieldEventChannel vascEntryFieldEventChannel = null; - private Map> eventListeners = null; + private List> eventEntryFrontendEventListeners = null; + private List> eventEntryBackendEventListeners = null; private List listOptions = null; private List backendFilters = null; @@ -107,7 +109,8 @@ public class DefaultVascEntry implements VascEntry { vascLinkEntries = new ArrayList(10); entryParameters = new HashMap(10); - eventListeners = new HashMap>(3); + eventEntryFrontendEventListeners = new ArrayList>(10); + eventEntryBackendEventListeners = new ArrayList>(10); listOptions = new ArrayList(5); backendFilters = new ArrayList(3); } @@ -140,6 +143,8 @@ public class DefaultVascEntry implements VascEntry { result.vascAdminDelete=vascAdminDelete; result.backendId=backendId; result.vascEntryFieldEventChannel=vascEntryFieldEventChannel; + result.eventEntryFrontendEventListeners.addAll(eventEntryFrontendEventListeners); + result.eventEntryBackendEventListeners.addAll(eventEntryBackendEventListeners); // skipping 'vascFrontendData' because it should always be null when cloning happens. for (VascEntryField f:vascFields) { @@ -162,13 +167,6 @@ public class DefaultVascEntry implements VascEntry { for (VascLinkEntry l:vascLinkEntries) { result.vascLinkEntries.add(l.clone()); } - for (VascEntryEventListener.VascEventType type:eventListeners.keySet()) { - List lists = eventListeners.get(type); - for (VascEntryEventListener e:lists) { - VascEntryEventListener listener = e.clone(); - result.addVascEntryEventListener(type, listener); - } - } for (VascEntryField listOption:listOptions) { VascEntryField ff = listOption.clone(); ff.setVascEntry(result); @@ -717,32 +715,37 @@ public class DefaultVascEntry implements VascEntry { public void setVascEntryFieldEventChannel(VascEntryFieldEventChannel vascEntryFieldEventChannel) { this.vascEntryFieldEventChannel = vascEntryFieldEventChannel; } - + /** - * Added an VascEntryEventListener - * @param type - * @param listener + * Added an VascEntryBackendEventListener + * @param listener The class of the event listener. */ - public void addVascEntryEventListener(VascEntryEventListener.VascEventType type,VascEntryEventListener listener) { - List result = eventListeners.get(type); - if (result==null) { - result = new ArrayList(3); - eventListeners.put(type,result); - } - result.add(listener); + public void addVascEntryBackendEventListener(Class listener) { + eventEntryBackendEventListeners.add(listener); } /** - * Returns the list of VascEntryEventListener for a speciec type. - * @param type + * Returns the list of VascEntryBackendEventListener * @return */ - public List getVascEntryEventListeners(VascEntryEventListener.VascEventType type) { - List result = eventListeners.get(type); - if (result!=null) { - return result; - } - return new ArrayList(0); + public List> getVascEntryBackendEventListeners() { + return eventEntryBackendEventListeners; + } + + /** + * Added an VascEntryFrontendEventListener + * @param listener The class of the event listener. + */ + public void addVascEntryFrontendEventListener(Class listener) { + eventEntryFrontendEventListeners.add(listener); + } + + /** + * Returns the list of VascEntryFrontendEventListener + * @return + */ + public List> getVascEntryFrontendEventListeners() { + return eventEntryFrontendEventListeners; } public void addListOption(VascEntryField listOption) { diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascFactory.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascFactory.java index b04c453..f92d266 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascFactory.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascFactory.java @@ -35,7 +35,6 @@ import com.idcanet.vasc.core.VascController; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.VascFrontendData; -import com.idcanet.vasc.core.entry.VascEntryEventListener; import com.idcanet.vasc.impl.entry.DefaultVascEntryResourceResolver; import com.idcanet.vasc.impl.entry.VascValidatorsValidatorService; import com.idcanet.vasc.impl.type.DefaultVascEntryFieldTypeController; @@ -83,15 +82,6 @@ public class DefaultVascFactory { vascFrontendData.getVascEntryState().setVascBackendState(new DefaultVascBackendState()); vascFrontendData.getVascEntryState().getVascBackendState().setPageSize(100); // default page size is zero aka disabled vascFrontendData.getVascEntryState().getVascBackendState().setPageSizeMax(1000); // max 1k records on screen. - vascFrontendData.setExceptionListener(new VascEntryEventListener() { - private static final long serialVersionUID = 1L; - public void vascEvent(VascEntry entry, VascEventType type,Object data) { - throw new RuntimeException(((Exception)data)); // throw to top. - } - public VascEntryEventListener clone() throws CloneNotSupportedException { - return this; - } - }); vascFrontendData.addVascValidatorService(new VascValidatorsValidatorService()); // normal vasc validators return vascFrontendData; } diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendData.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendData.java index b5fa1df..a0d6be7 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendData.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendData.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; import com.idcanet.vasc.core.VascController; +import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascEntryFinalizer; import com.idcanet.vasc.core.VascEntryState; @@ -39,8 +40,8 @@ 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.entry.VascEntryEventListener; import com.idcanet.vasc.core.entry.VascEntryFieldValidatorService; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; import com.idcanet.vasc.core.entry.VascEntryResourceImageResolver; import com.idcanet.vasc.core.entry.VascEntryResourceResolver; import com.idcanet.vasc.core.ui.VascUIComponent; @@ -59,7 +60,7 @@ public class DefaultVascFrontendData implements VascFrontendData { private VascEntryResourceImageResolver vascEntryResourceImageResolver = null; private Map uiComponents = null; private VascController vascController = null; - private VascEntryEventListener exceptionListener = null; + private Map> vascEntryFrontendEventListeners = null; private VascEntryState state = null; @@ -72,6 +73,7 @@ public class DefaultVascFrontendData implements VascFrontendData { fieldComps = new HashMap(8); fieldEditors = new HashMap(8); validatorServices = new ArrayList(4); + vascEntryFrontendEventListeners = new HashMap>(10); } /** @@ -208,20 +210,6 @@ public class DefaultVascFrontendData implements VascFrontendData { return fieldComps.get(field); } - /** - * @return the exceptionListener - */ - public VascEntryEventListener getExceptionListener() { - return exceptionListener; - } - - /** - * @param exceptionListener the exceptionListener to set - */ - public void setExceptionListener(VascEntryEventListener exceptionListener) { - this.exceptionListener = exceptionListener; - } - /** * @return the vascEntryResourceImageResolver */ @@ -257,4 +245,31 @@ public class DefaultVascFrontendData implements VascFrontendData { public void setVascEntryState(VascEntryState state) { this.state=state; } + + + public void initFrontendListeners(VascEntry entry) throws InstantiationException, IllegalAccessException { + for (Class clazz:entry.getVascEntryFrontendEventListeners()) { + VascEntryFrontendEventListener listener = clazz.newInstance(); + addVascEntryFrontendEventListener(listener); + } + } + + public void addVascEntryFrontendEventListener(VascEntryFrontendEventListener listener) { + for (VascEntryFrontendEventListener.VascFrontendEventType type:listener.getEventTypes()) { + List list = vascEntryFrontendEventListeners.get(type); + if (list==null) { + list = new ArrayList(10); + vascEntryFrontendEventListeners.put(type, list); + } + list.add(listener); + } + } + + public List getVascEntryFrontendEventListener(VascEntryFrontendEventListener.VascFrontendEventType type) { + List list = vascEntryFrontendEventListeners.get(type); + if (list==null) { + return new ArrayList(0); + } + return list; + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java index 76d24f7..2466d1d 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java @@ -29,7 +29,6 @@ package com.idcanet.vasc.impl; import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; import com.idcanet.vasc.core.VascBackendFilter; @@ -44,9 +43,9 @@ import com.idcanet.vasc.core.VascLinkEntryType; import com.idcanet.vasc.core.VascUserRoleController; import com.idcanet.vasc.core.actions.GlobalVascAction; import com.idcanet.vasc.core.actions.RowVascAction; -import com.idcanet.vasc.core.entry.VascEntryEventListener; import com.idcanet.vasc.core.entry.VascEntryFieldValidatorService; -import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType; import com.idcanet.vasc.core.ui.VascUIComponent; /** @@ -158,10 +157,10 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { /** * @see com.idcanet.vasc.core.VascFrontendHelper#fireVascEvent(com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType, java.lang.Object) */ - public void fireVascEvent(VascEntry entry,VascEventType type, Object data) { - List list = entry.getVascEntryEventListeners(type); - for (VascEntryEventListener l:list) { - l.vascEvent(entry, type, data); + public void fireVascEvent(VascEntry entry,VascFrontendEventType type, Object data) { + List list = entry.getVascFrontendData().getVascEntryFrontendEventListener(type); + for (VascEntryFrontendEventListener l:list) { + l.vascEvent(entry, data); } } @@ -223,12 +222,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { * @see com.idcanet.vasc.core.VascFrontendHelper#handleException(com.idcanet.vasc.core.VascEntry,java.lang.Exception) */ public void handleException(VascEntry entry,Exception exception) { - VascEntryEventListener listener = entry.getVascFrontendData().getExceptionListener(); - if (listener==null) { - logger.log(Level.WARNING,exception.getMessage(),exception); - throw new RuntimeException("Exception happend: "+exception.getMessage(),exception); - } - listener.vascEvent(entry,VascEventType.EXCEPTION , exception); + fireVascEvent(entry,VascFrontendEventType.EXCEPTION , exception); } /** @@ -258,7 +252,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { logger.finer("Setting default value for: "+field.getName()+" def: "+defaultValue); field.getVascEntryFieldValue().setValue(field, object, defaultValue); } - fireVascEvent(entry,VascEventType.DATA_CREATE, object); + fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.DATA_CREATE, object); return object; } catch (Exception e) { handleException(entry,e); @@ -307,7 +301,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { Object object = entry.getVascFrontendData().getVascEntryState().getEntryDataObject(); Object result = null; try { - fireVascEvent(entry,VascEventType.DATA_PRE_UPDATE,object); + fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.DATA_PRE_UPDATE,object); int index = removeObjectFromDataList(entry,object); // merge object on backend @@ -321,8 +315,8 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { // put object back in list entry.getVascFrontendData().getVascEntryState().getEntryDataList().add(index, result); entry.getVascFrontendData().getVascEntryState().setEntryDataObject(null); - fireVascEvent(entry,VascEventType.DATA_POST_UPDATE,result); - fireVascEvent(entry,VascEventType.DATA_LIST_UPDATE,result); + fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.DATA_POST_UPDATE,result); + fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.DATA_LIST_UPDATE,result); } catch (Exception e) { handleException(entry,e); } @@ -343,8 +337,8 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { } removeObjectFromDataList(entry,object); entry.getVascFrontendData().getVascEntryState().setEntryDataObject(null); - fireVascEvent(entry,VascEventType.DATA_DELETE, object); - fireVascEvent(entry,VascEventType.DATA_LIST_UPDATE, object); + fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.DATA_DELETE, object); + fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.DATA_LIST_UPDATE, object); } /** @@ -370,8 +364,8 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { } catch (Exception e) { handleException(entry, e); } - fireVascEvent(entry,VascEventType.DATA_READ, null); - fireVascEvent(entry,VascEventType.DATA_LIST_UPDATE, null); + fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.DATA_READ, null); + fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.DATA_LIST_UPDATE, null); } public void headerOptionsCreatedFillData(VascEntry entry) { @@ -480,7 +474,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { String sortID = field.getBackendName(); entry.getVascFrontendData().getVascEntryState().getVascBackendState().setSortField(sortID); entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageIndex(0); - fireVascEvent(entry,VascEntryEventListener.VascEventType.DATA_SORT, field); + fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.DATA_SORT, field); refreshData(entry); } @@ -489,7 +483,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { entry.getVascFrontendData().getVascEntryState().getVascBackendState().setSearchString(searchString); entry.getVascFrontendData().getVascEntryState().getVascBackendState().setSortField(null); entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageIndex(0); - fireVascEvent(entry,VascEntryEventListener.VascEventType.DATA_SEARCH, searchString); + fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.DATA_SEARCH, searchString); refreshData(entry); } @@ -504,7 +498,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { } entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageIndex(pageIndex); - fireVascEvent(entry,VascEntryEventListener.VascEventType.DATA_PAGE, pageIndex); + fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.DATA_PAGE, pageIndex); // lets load data; refreshData(entry); diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java index 9784ad8..ff640e1 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java @@ -62,49 +62,49 @@ public class DefaultVascSelectItemModel implements VascSelectItemModel { /** * @see com.idcanet.vasc.core.ui.VascSelectItemModel#getVascSelectItems(com.idcanet.vasc.core.VascEntry) */ - public List getVascSelectItems(VascEntry entry) throws VascException { + public List getVascSelectItems(VascEntry currentEntry) throws VascException { List result = new ArrayList(100); - VascEntry ve = entry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryById(entryId); + VascEntry entry = currentEntry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryById(entryId); if (keyFieldId==null) { - keyFieldId = ve.getPrimaryKeyFieldId(); + keyFieldId = entry.getPrimaryKeyFieldId(); } - VascEntryField key = ve.getVascEntryFieldById(keyFieldId); + VascEntryField key = entry.getVascEntryFieldById(keyFieldId); if (displayFieldId==null) { - displayFieldId = ve.getDisplayNameFieldId(); + displayFieldId = entry.getDisplayNameFieldId(); } - VascEntryField dis = ve.getVascEntryFieldById(displayFieldId); + VascEntryField dis = entry.getVascEntryFieldById(displayFieldId); if (key==null) { - throw new VascException("Could not find: "+keyFieldId+" from: "+ve.getId()); + throw new VascException("Could not find: "+keyFieldId+" from: "+entry.getId()); } if (dis==null) { - throw new VascException("Could not find: "+displayFieldId+" from: "+ve.getId()); + throw new VascException("Could not find: "+displayFieldId+" from: "+entry.getId()); } // set frontend data for new clone, we need te get better lifecycle management for stats/entry/etc - ve.setVascFrontendData(entry.getVascFrontendData()); - VascBackend back = DefaultVascFactory.getProxyVascBackend(ve); + entry.setVascFrontendData(currentEntry.getVascFrontendData()); + VascBackend back = DefaultVascFactory.getProxyVascBackend(entry); try { if (nullLabel!=null) { if (nullKeyValue==null) { nullKeyValue = "null"; } - nullLabel = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(nullLabel); + nullLabel = currentEntry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(nullLabel); VascSelectItem item = new VascSelectItem(nullLabel,null,nullKeyValue); result.add(item); } // set def para VascBackendState state = new DefaultVascBackendState(); - for (String key2:ve.getEntryParameterKeys()) { - Object value = ve.getEntryParameter(key2); + for (String key2:entry.getEntryParameterKeys()) { + Object value = entry.getEntryParameter(key2); //System.out.println("Copy paras name: "+key2+" value: "+value+" class: "+value.getClass().getName()); state.setDataParameter(key2, value); } // set list para - for (VascEntryField vef:ve.getListOptions()) { + for (VascEntryField vef:entry.getListOptions()) { Object def = vef.getDefaultValue(); if (def==null) { continue; @@ -116,12 +116,12 @@ public class DefaultVascSelectItemModel implements VascSelectItemModel { // set para from parent state entry for (String paraName:entryParameterFieldIds.keySet()) { - VascEntry fieldEntry = entry; + VascEntry fieldEntry = currentEntry; if (useParentFields!=null && useParentFields==true) { - if (entry.getVascFrontendData().getVascEntryState().getParent()==null) { + if (currentEntry.getVascFrontendData().getVascEntryState().getParent()==null) { throw new IllegalStateException("Requested to use parent state field values but no parent state found."); } - fieldEntry = entry.getVascFrontendData().getVascEntryState().getParent().getVascEntry(); + fieldEntry = currentEntry.getVascFrontendData().getVascEntryState().getParent().getVascEntry(); } String paraValueId = entryParameterFieldIds.get(paraName); @@ -152,7 +152,7 @@ public class DefaultVascSelectItemModel implements VascSelectItemModel { VascEntryField fieldClone = key.clone(); fieldClone.getVascValidators().clear(); - VascEntryFieldValue v = entry.getVascFrontendData().getVascEntryState().getVascBackend().provideVascEntryFieldValue(fieldClone); + VascEntryFieldValue v = currentEntry.getVascFrontendData().getVascEntryState().getVascBackend().provideVascEntryFieldValue(fieldClone); key.setVascEntryFieldValue(v); } if (dis.getVascEntryFieldValue()==null) { @@ -160,7 +160,7 @@ public class DefaultVascSelectItemModel implements VascSelectItemModel { VascEntryField fieldClone = dis.clone(); fieldClone.getVascValidators().clear(); - VascEntryFieldValue v = entry.getVascFrontendData().getVascEntryState().getVascBackend().provideVascEntryFieldValue(fieldClone); + VascEntryFieldValue v = currentEntry.getVascFrontendData().getVascEntryState().getVascBackend().provideVascEntryFieldValue(fieldClone); dis.setVascEntryFieldValue(v); } diff --git a/src/main/java/com/idcanet/vasc/impl/actions/EditRowAction.java b/src/main/java/com/idcanet/vasc/impl/actions/EditRowAction.java index 2eda9d5..27549f6 100644 --- a/src/main/java/com/idcanet/vasc/impl/actions/EditRowAction.java +++ b/src/main/java/com/idcanet/vasc/impl/actions/EditRowAction.java @@ -29,7 +29,7 @@ package com.idcanet.vasc.impl.actions; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.actions.AbstractVascAction; import com.idcanet.vasc.core.actions.RowVascAction; -import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType; /** * @@ -51,7 +51,7 @@ public class EditRowAction extends AbstractVascAction implements RowVascAction { return; // nothing selected } entry.getVascFrontendData().getVascEntryState().setEditCreate(false); - entry.getVascFrontendData().getVascFrontendHelper().fireVascEvent(entry, VascEventType.DATA_SELECT, rowObject); + entry.getVascFrontendData().getVascFrontendHelper().fireVascEvent(entry, VascFrontendEventType.DATA_SELECT, rowObject); entry.getVascFrontendData().getVascEntryState().setEntryDataObject(rowObject); entry.getVascFrontendData().getVascFrontend().renderEdit(); } diff --git a/src/main/java/com/idcanet/vasc/impl/type/MultiTextVascEntryFieldType.java b/src/main/java/com/idcanet/vasc/impl/type/MultiTextVascEntryFieldType.java index c0600e3..610a1a7 100644 --- a/src/main/java/com/idcanet/vasc/impl/type/MultiTextVascEntryFieldType.java +++ b/src/main/java/com/idcanet/vasc/impl/type/MultiTextVascEntryFieldType.java @@ -43,6 +43,7 @@ import com.idcanet.vasc.core.ui.VascValueModel; public class MultiTextVascEntryFieldType extends DefaultVascEntryFieldType { private static final long serialVersionUID = 1L; + @Override public VascEntryFieldType clone() throws CloneNotSupportedException { MultiTextVascEntryFieldType clone = new MultiTextVascEntryFieldType(); @@ -57,6 +58,8 @@ public class MultiTextVascEntryFieldType extends DefaultVascEntryFieldType { clone.vascValidators.addAll(vascValidators); return clone; } + + /* private Object getIndexValue(VascEntryField entryField,int index) throws VascException { Object record = entryField.getVascEntry().getVascFrontendData().getVascEntryState().getEntryDataObject(); Object value = entryField.getVascEntryFieldValue().getValue(entryField, record); @@ -103,13 +106,15 @@ public class MultiTextVascEntryFieldType extends DefaultVascEntryFieldType { } throw new VascException("Unknown object type: "+value); } + */ /** * @see com.idcanet.vasc.core.AbstractVascEntryFieldType#getUIComponentCount(com.idcanet.vasc.core.VascEntryField) */ @Override public int getUIComponentCount(VascEntryField entryField) throws VascException { - + return 1; + /* Object record = entryField.getVascEntry().getVascFrontendData().getVascEntryState().getEntryDataObject(); Object value = entryField.getVascEntryFieldValue().getValue(entryField, record); @@ -123,6 +128,7 @@ public class MultiTextVascEntryFieldType extends DefaultVascEntryFieldType { return 1+1; } throw new VascException("Unknown object type: "+value); + */ } /** @@ -130,6 +136,10 @@ public class MultiTextVascEntryFieldType extends DefaultVascEntryFieldType { */ @Override public VascValueModel provideEditorVascValueModel(final int index,final VascEntryField entryField) { + MultiVascValueModel model = new MultiVascValueModel(); + return model; + + /* note: not allowed to use inner classes in backend , that breaks remoting !! VascValueModel model = new VascValueModel() { public Object getValue() throws VascException { Object value = getIndexValue(entryField,index); @@ -143,5 +153,63 @@ public class MultiTextVascEntryFieldType extends DefaultVascEntryFieldType { }; return model; + */ + } +} +class MultiVascValueModel extends VascValueModel { + public Object getValue() throws VascException { + Object value = super.getValue(); + //System.out.println("value: "+value+" type: "+value.getClass()); + StringBuffer buf = new StringBuffer(100); + if (value instanceof List) { + for (Object o:((List)value)) { + buf.append(o); + buf.append("\n"); + } + return buf.toString(); + } + if (value instanceof String[]) { + for (Object o:((String[])value)) { + buf.append(o); + buf.append("\n"); + } + return buf.toString(); + } + if (value instanceof String) { + return (String)value; + } + return value; + } + + @SuppressWarnings("unchecked") + public void setValue(Object editValueObj) throws VascException { + + if (super.getValue()==null) { + super.setValue(editValueObj); + return; + } + + if ((editValueObj instanceof String)==false) { + throw new VascException("Can only handle string stuff."); + } + String editValue = (String)editValueObj; + + String[] editList = editValue.split(",|\t|\n"); + + Object value = super.getValue(); + if (value instanceof List) { + ((List)value).clear(); + for (String o:editList) { + ((List)value).add(o); + } + super.setValue(value); + return; + } + if (value instanceof String[]) { + super.setValue(value); + return; + } + // solo String type + super.setValue(value); } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/AnnotationParserElement.java b/src/main/java/com/idcanet/vasc/impl/x4o/AnnotationParserElement.java index aa17018..07cb203 100644 --- a/src/main/java/com/idcanet/vasc/impl/x4o/AnnotationParserElement.java +++ b/src/main/java/com/idcanet/vasc/impl/x4o/AnnotationParserElement.java @@ -45,8 +45,8 @@ import com.idcanet.vasc.core.VascController; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascEntryFieldType; -import com.idcanet.vasc.core.entry.VascEntryEventListener; -import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType; +import com.idcanet.vasc.core.entry.VascEntryBackendEventListener; +import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener; import com.idcanet.vasc.impl.DefaultVascEntryField; import com.idcanet.vasc.validators.VascValidator; import com.idcanet.vasc.validators.VascValidatorClassParser; @@ -104,6 +104,7 @@ public class AnnotationParserElement extends AbstractElement { } } + @SuppressWarnings("unchecked") private void fillEntry(VascEntry entry,Class modelClass,VascAnnotationParser parser) throws ElementException { @@ -111,21 +112,15 @@ public class AnnotationParserElement extends AbstractElement { } - VascEventListener vc = parser.getVascEventListener (modelClass); + VascEventListener vc = parser.getVascEventListener(modelClass); if (vc!=null) { - if (vc.listeners().length!=vc.types().length) { - throw new IllegalArgumentException("Total listeners and types are not equals on: "+modelClass); - } - int i = 0; - for (VascEventType type:vc.types()) { - String listenerClass = vc.listeners()[i]; - VascEntryEventListener listener; - try { - listener = (VascEntryEventListener)X4OParser.loadClass(listenerClass).newInstance(); - entry.addVascEntryEventListener(type, listener); - } catch (Exception e) { - throw new ElementException("Could not create listener: "+listenerClass+" for entryId: "+entry.getId(),e); + for (Class listener:vc.listeners()) { + if (listener.isAssignableFrom(VascEntryFrontendEventListener.class)) { + entry.addVascEntryFrontendEventListener((Class)listener); + } + if (listener.isAssignableFrom(VascEntryBackendEventListener.class)) { + entry.addVascEntryBackendEventListener((Class)listener); } i++; } diff --git a/src/main/resources/META-INF/fieldtypes.xml b/src/main/resources/META-INF/fieldtypes.xml index f1e16ab..5cda54d 100644 --- a/src/main/resources/META-INF/fieldtypes.xml +++ b/src/main/resources/META-INF/fieldtypes.xml @@ -85,7 +85,7 @@ - + diff --git a/src/test/java/com/idcanet/vasc/SwingTest.java b/src/test/java/com/idcanet/vasc/SwingTest.java index 68c01bd..6a7f89e 100644 --- a/src/test/java/com/idcanet/vasc/SwingTest.java +++ b/src/test/java/com/idcanet/vasc/SwingTest.java @@ -115,6 +115,9 @@ public class SwingTest extends TestCase { // render render.initEntry(entry); render.renderView(); + + // get data + entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); // view frame.pack(); diff --git a/src/test/resources/vasc/tables.xml b/src/test/resources/vasc/tables.xml index 46d1c9a..dd4141c 100644 --- a/src/test/resources/vasc/tables.xml +++ b/src/test/resources/vasc/tables.xml @@ -6,7 +6,7 @@