From d88cb263309a5a9a881b0bbe9210bd50f2608423 Mon Sep 17 00:00:00 2001 From: willemc Date: Sat, 28 Apr 2007 17:59:11 +0200 Subject: [PATCH] [svn r249] fixed annotation support , added talbecontroller --- .../annotations/VascAnnotationParser.java | 31 ++++- .../vasc/annotations/VascColumnWidth.java | 46 +++++++ src/com/idcanet/vasc/core/VascTable.java | 30 ++--- .../vasc/core/VascTableController.java | 46 +++++++ .../idcanet/vasc/core/VascViewRenderer.java | 4 +- .../vasc/core/actions/AbstractVascAction.java | 27 +++++ .../vasc/core/actions/ColumnVascAction.java | 2 +- .../vasc/core/actions/GlobalVascAction.java | 2 +- .../vasc/core/actions/RowVascAction.java | 2 +- .../idcanet/vasc/core/actions/VascAction.java | 6 +- .../vasc/core/column/VascTableColumn.java | 5 +- .../vasc/impl/DefaultVascTableController.java | 113 ++++++++++++++++++ .../vasc/impl/actions/AddRowAction.java | 2 +- .../vasc/impl/actions/DeleteRowAction.java | 8 +- .../vasc/impl/actions/EditRowAction.java | 2 +- .../impl/actions/RefreshDataGlobalAction.java | 50 ++++++++ .../impl/actions/XMLExportGlobalAction.java | 1 + .../vasc/impl/swt/SwtVascViewRenderer.java | 73 +++++++---- tests/com/idcanet/vasc/tests/SWTTest.java | 9 +- .../idcanet/vasc/tests/models/TestModel.java | 2 + 20 files changed, 403 insertions(+), 58 deletions(-) create mode 100644 src/com/idcanet/vasc/annotations/VascColumnWidth.java create mode 100644 src/com/idcanet/vasc/core/VascTableController.java create mode 100644 src/com/idcanet/vasc/impl/DefaultVascTableController.java create mode 100644 src/com/idcanet/vasc/impl/actions/RefreshDataGlobalAction.java diff --git a/src/com/idcanet/vasc/annotations/VascAnnotationParser.java b/src/com/idcanet/vasc/annotations/VascAnnotationParser.java index 8e1361b..bcc2e82 100644 --- a/src/com/idcanet/vasc/annotations/VascAnnotationParser.java +++ b/src/com/idcanet/vasc/annotations/VascAnnotationParser.java @@ -89,6 +89,31 @@ public class VascAnnotationParser { return (String)getValue(beanClass,VascName.class,null); } + + public Object getVascColumnWidth(Class beanClass,String property) { + return getValue(beanClass,VascColumnWidth.class,property); + } + + public Object getVascColumnWidth(Class beanClass) { + return getValue(beanClass,VascColumnWidth.class,null); + } + + public String getVascHelpId(Class beanClass,String property) { + return (String)getValue(beanClass,VascHelpId.class,property); + } + + public String getVascHelpId(Class beanClass) { + return (String)getValue(beanClass,VascHelpId.class,null); + } + + public Object getVascDefaultValue(Class beanClass,String property) { + return getValue(beanClass,VascDefaultValue.class,property); + } + + public Object getVascDefaultValue(Class beanClass) { + return getValue(beanClass,VascDefaultValue.class,null); + } + /** * No oop code here...refactor at some point in time * @@ -179,11 +204,15 @@ public class VascAnnotationParser { return null; // error ?? } try { - return v.defaultValue().newInstance(); + return v.defaultValueClass().newInstance(); } catch (Exception e) { logger.log(Level.WARNING,e.getMessage(),e); } } + if (a.equals(VascColumnWidth.class)) { + VascColumnWidth c = (VascColumnWidth)a; + return c.width(); + } return null; } diff --git a/src/com/idcanet/vasc/annotations/VascColumnWidth.java b/src/com/idcanet/vasc/annotations/VascColumnWidth.java new file mode 100644 index 0000000..a495433 --- /dev/null +++ b/src/com/idcanet/vasc/annotations/VascColumnWidth.java @@ -0,0 +1,46 @@ +/* + * Copyright 2004-2006 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.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +/** + * The default column width + * + * @author Willem Cazander + * @version 1.0 Apr 28, 2007 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD,ElementType.TYPE}) +public @interface VascColumnWidth { + + int width() default 150; +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/VascTable.java b/src/com/idcanet/vasc/core/VascTable.java index 0bb8fbe..5f3ffda 100644 --- a/src/com/idcanet/vasc/core/VascTable.java +++ b/src/com/idcanet/vasc/core/VascTable.java @@ -28,7 +28,6 @@ package com.idcanet.vasc.core; import java.util.ArrayList; import java.util.List; -import java.util.logging.Logger; import com.idcanet.vasc.core.actions.ColumnVascAction; import com.idcanet.vasc.core.actions.GlobalVascAction; @@ -36,8 +35,6 @@ import com.idcanet.vasc.core.actions.RowVascAction; import com.idcanet.vasc.core.column.VascTableColumn; import com.idcanet.xtes.xpql.query.Query; - - /** * * @author Willem Cazander @@ -62,6 +59,7 @@ public class VascTable { private VascTextValue vascTextValue = null; private List userOptions = null; private String helpId = null; + private VascTableController vascTableController = null; public VascTable() { tableColumns = new ArrayList(6); @@ -310,17 +308,19 @@ public class VascTable { this.helpId = helpId; } - static public Integer getTotalColumnSize(VascTable table) { - int result = 0; - for(VascTableColumn c:table.getTableColumns()) { - if(c.getWidth()==null) { - Logger.getLogger(VascTable.class.getName()).finer("Column no size: "+c.getName()); - return null; - } - result=+c.getWidth(); - } - return result; - } + /** + * @return the vascTableController + */ + public VascTableController getVascTableController() { + return vascTableController; + } + + /** + * @param vascTableController the vascTableController to set + */ + public void setVascTableController(VascTableController vascTableController) { + this.vascTableController = vascTableController; + } + } - diff --git a/src/com/idcanet/vasc/core/VascTableController.java b/src/com/idcanet/vasc/core/VascTableController.java new file mode 100644 index 0000000..923723a --- /dev/null +++ b/src/com/idcanet/vasc/core/VascTableController.java @@ -0,0 +1,46 @@ +/* + * Copyright 2004-2007 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.core; + +/** + * + * @author Willem Cazander + * @version 1.0 Apr 28, 2007 + */ +public interface VascTableController { + + public void finalizeVascTable(VascTable table) throws Exception; + + public void finalizeVascColumns(VascTable table) throws Exception; + + public Integer getTotalColumnsWidth(VascTable table); + + public void refreshData(VascTable table) throws Exception; + + public void handleException(Exception e,VascTable table); + +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/VascViewRenderer.java b/src/com/idcanet/vasc/core/VascViewRenderer.java index 71092f4..e12a90f 100644 --- a/src/com/idcanet/vasc/core/VascViewRenderer.java +++ b/src/com/idcanet/vasc/core/VascViewRenderer.java @@ -34,7 +34,7 @@ package com.idcanet.vasc.core; */ public interface VascViewRenderer { - public void renderView(VascTable table); + public void renderView(VascTable table) throws Exception; - public void renderEdit(VascTable table,Object rowBean); + public void renderEdit(VascTable table,Object rowBean) throws Exception; } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/actions/AbstractVascAction.java b/src/com/idcanet/vasc/core/actions/AbstractVascAction.java index f3cda51..8655a71 100644 --- a/src/com/idcanet/vasc/core/actions/AbstractVascAction.java +++ b/src/com/idcanet/vasc/core/actions/AbstractVascAction.java @@ -37,6 +37,8 @@ abstract public class AbstractVascAction implements VascAction { private String name = null; private String toolTip = null; + private String image = null; + private String helpId = null; /** * @return the name @@ -63,6 +65,31 @@ abstract public class AbstractVascAction implements VascAction { this.toolTip = toolTip; } + /** + * @return the helpId + */ + public String getHelpId() { + return helpId; + } + /** + * @param helpId the helpId to set + */ + public void setHelpId(String helpId) { + this.helpId = helpId; + } + /** + * @return the image + */ + public String getImage() { + return image; + } + + /** + * @param image the image to set + */ + public void setImage(String image) { + this.image = image; + } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/actions/ColumnVascAction.java b/src/com/idcanet/vasc/core/actions/ColumnVascAction.java index 3429d6a..5c0e9a6 100644 --- a/src/com/idcanet/vasc/core/actions/ColumnVascAction.java +++ b/src/com/idcanet/vasc/core/actions/ColumnVascAction.java @@ -36,5 +36,5 @@ import com.idcanet.vasc.core.column.VascTableColumn; */ public interface ColumnVascAction extends VascAction { - public void doColumnAction(VascTable table,VascTableColumn column); + public void doColumnAction(VascTable table,VascTableColumn column) throws Exception; } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/actions/GlobalVascAction.java b/src/com/idcanet/vasc/core/actions/GlobalVascAction.java index 8c57c0e..24e1900 100644 --- a/src/com/idcanet/vasc/core/actions/GlobalVascAction.java +++ b/src/com/idcanet/vasc/core/actions/GlobalVascAction.java @@ -35,5 +35,5 @@ import com.idcanet.vasc.core.VascTable; */ public interface GlobalVascAction extends VascAction { - public void doGlobalAction(VascTable table); + public void doGlobalAction(VascTable table) throws Exception; } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/actions/RowVascAction.java b/src/com/idcanet/vasc/core/actions/RowVascAction.java index 6d15f82..0d79934 100644 --- a/src/com/idcanet/vasc/core/actions/RowVascAction.java +++ b/src/com/idcanet/vasc/core/actions/RowVascAction.java @@ -35,5 +35,5 @@ import com.idcanet.vasc.core.VascTable; */ public interface RowVascAction extends VascAction { - public void doRowAction(VascTable table,Object rowObject); + public void doRowAction(VascTable table,Object rowObject) throws Exception; } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/actions/VascAction.java b/src/com/idcanet/vasc/core/actions/VascAction.java index dc3ba7a..dde2163 100644 --- a/src/com/idcanet/vasc/core/actions/VascAction.java +++ b/src/com/idcanet/vasc/core/actions/VascAction.java @@ -26,8 +26,6 @@ package com.idcanet.vasc.core.actions; -import com.idcanet.vasc.core.VascTable; - /** * * @author Willem Cazander @@ -39,6 +37,10 @@ public interface VascAction { public void setName(String name); public String getToolTip(); public void setToolTip(String toolTip); + public String getImage(); + public void setImage(String image); + public String getHelpId(); + public void setHelpId(String helpId); //public Object createActionObject(VascTable table); } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/column/VascTableColumn.java b/src/com/idcanet/vasc/core/column/VascTableColumn.java index a2c7ca8..8aa0ffc 100644 --- a/src/com/idcanet/vasc/core/column/VascTableColumn.java +++ b/src/com/idcanet/vasc/core/column/VascTableColumn.java @@ -26,6 +26,8 @@ package com.idcanet.vasc.core.column; +import com.idcanet.vasc.core.VascTable; + /** * @@ -172,7 +174,4 @@ public class VascTableColumn { public void setHelpId(String helpId) { this.helpId = helpId; } - - - } \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/DefaultVascTableController.java b/src/com/idcanet/vasc/impl/DefaultVascTableController.java new file mode 100644 index 0000000..87d9a3d --- /dev/null +++ b/src/com/idcanet/vasc/impl/DefaultVascTableController.java @@ -0,0 +1,113 @@ +/* + * Copyright 2004-2007 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; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.idcanet.vasc.annotations.VascAnnotationParser; +import com.idcanet.vasc.core.VascTable; +import com.idcanet.vasc.core.VascTableController; +import com.idcanet.vasc.core.column.VascAnnotationTableColumn; +import com.idcanet.vasc.core.column.VascTableColumn; +import com.idcanet.vasc.impl.column.BeanPropertyVascColumnValue; + +/** + * + * @author Willem Cazander + * @version 1.0 Apr 28, 2007 + */ +public class DefaultVascTableController implements VascTableController { + + /** + * @see com.idcanet.vasc.core.VascTableController#finalizeVascColumns(com.idcanet.vasc.core.VascTable) + */ + public void finalizeVascColumns(VascTable table) throws Exception { + VascAnnotationParser vap = new VascAnnotationParser(); + + for(VascTableColumn c:table.getTableColumns()) { + if (c instanceof VascAnnotationTableColumn) { + VascAnnotationTableColumn column = (VascAnnotationTableColumn)c; + + if (c.getName()==null) { + c.setName(vap.getVascNameKey(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty())); + } + if (c.getToolTip()==null) { + c.setToolTip(vap.getVascToolTipKey(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty())); + } + if (c.getDefaultValue()==null) { + c.setDefaultValue(vap.getVascDefaultValue(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty())); + } + if (c.getWidth()==null) { + Object obj = vap.getVascColumnWidth(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty()); + if (obj instanceof Integer) { + c.setWidth((Integer)obj); + } + // get KEY + } + if (c.getHelpId()==null) { + c.setHelpId(vap.getVascHelpId(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty())); + } + if (c.getVascColumnValue()==null) { + c.setVascColumnValue(new BeanPropertyVascColumnValue(column.getBeanProperty())); + } + } + } + } + + /** + * @see com.idcanet.vasc.core.VascTableController#finalizeVascTable(com.idcanet.vasc.core.VascTable) + */ + public void finalizeVascTable(VascTable table) throws Exception { + } + + /** + * @see com.idcanet.vasc.core.VascTableController#getTotalColumnsWidth(com.idcanet.vasc.core.VascTable) + */ + public Integer getTotalColumnsWidth(VascTable table) { + int result = 0; + for(VascTableColumn c:table.getTableColumns()) { + if(c.getWidth()==null) { + Logger.getLogger(VascTable.class.getName()).finer("Column no size: "+c.getName()); + return null; + } + result=+c.getWidth(); + } + return result; + } + + /** + * @see com.idcanet.vasc.core.VascTableController#refreshData() + */ + public void refreshData(VascTable table) throws Exception { + table.setTableData(table.getVascDataSource().executeQuery(table.getQuery())); + } + + public void handleException(Exception e,VascTable table) { + Logger.getLogger(DefaultVascTableController.class.getName()).log(Level.WARNING,e.getMessage(),e); + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/actions/AddRowAction.java b/src/com/idcanet/vasc/impl/actions/AddRowAction.java index b8638f1..824d4ac 100644 --- a/src/com/idcanet/vasc/impl/actions/AddRowAction.java +++ b/src/com/idcanet/vasc/impl/actions/AddRowAction.java @@ -42,7 +42,7 @@ public class AddRowAction extends AbstractVascAction implements RowVascAction { setToolTip("generic.toolTip"); } - public void doRowAction(VascTable table,Object rowObject) { + public void doRowAction(VascTable table,Object rowObject) throws Exception { table.getVascViewRenderer().renderEdit(table,rowObject); } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/actions/DeleteRowAction.java b/src/com/idcanet/vasc/impl/actions/DeleteRowAction.java index 7bd6c23..287035f 100644 --- a/src/com/idcanet/vasc/impl/actions/DeleteRowAction.java +++ b/src/com/idcanet/vasc/impl/actions/DeleteRowAction.java @@ -42,11 +42,7 @@ public class DeleteRowAction extends AbstractVascAction implements RowVascAction setToolTip("generic.toolTip"); } - public void doRowAction(VascTable table,Object rowObject) { - try { - table.getVascDataSource().delete(rowObject); - } catch (Exception e) { - e.printStackTrace(); - } + public void doRowAction(VascTable table,Object rowObject) throws Exception { + table.getVascDataSource().delete(rowObject); } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/actions/EditRowAction.java b/src/com/idcanet/vasc/impl/actions/EditRowAction.java index a69cb98..f2c93c5 100644 --- a/src/com/idcanet/vasc/impl/actions/EditRowAction.java +++ b/src/com/idcanet/vasc/impl/actions/EditRowAction.java @@ -43,7 +43,7 @@ public class EditRowAction extends AbstractVascAction implements RowVascAction { } - public void doRowAction(VascTable table,Object rowObject) { + public void doRowAction(VascTable table,Object rowObject) throws Exception { table.getVascViewRenderer().renderEdit(table,rowObject); } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/actions/RefreshDataGlobalAction.java b/src/com/idcanet/vasc/impl/actions/RefreshDataGlobalAction.java new file mode 100644 index 0000000..e604751 --- /dev/null +++ b/src/com/idcanet/vasc/impl/actions/RefreshDataGlobalAction.java @@ -0,0 +1,50 @@ +/* + * Copyright 2004-2007 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.actions; + +import com.idcanet.vasc.core.VascTable; +import com.idcanet.vasc.core.actions.AbstractVascAction; +import com.idcanet.vasc.core.actions.GlobalVascAction; + +/** + * + * @author Willem Cazander + * @version 1.0 Apr 28, 2007 + */ +public class RefreshDataGlobalAction extends AbstractVascAction implements GlobalVascAction { + + public RefreshDataGlobalAction() { + setName("generic.refresh"); + setToolTip("generic.crud.refresh.tooltip"); + setImage("icons/fam/table_refresh.png"); + } + + + public void doGlobalAction(VascTable table) { + //table.getVascViewRenderer().render + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/actions/XMLExportGlobalAction.java b/src/com/idcanet/vasc/impl/actions/XMLExportGlobalAction.java index 44de566..3193b2b 100644 --- a/src/com/idcanet/vasc/impl/actions/XMLExportGlobalAction.java +++ b/src/com/idcanet/vasc/impl/actions/XMLExportGlobalAction.java @@ -40,6 +40,7 @@ public class XMLExportGlobalAction extends AbstractVascAction implements GlobalV public XMLExportGlobalAction() { setName("generic.crud.export.xml.name"); setToolTip("generic.crud.export.xml.tooltip"); + setImage("icons/fam/page_white_excel.png"); } diff --git a/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java b/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java index da9d102..57e3516 100644 --- a/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java +++ b/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java @@ -26,14 +26,10 @@ package com.idcanet.vasc.impl.swt; -import java.util.ArrayList; -import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import javax.swing.text.TabExpander; - -import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.ITableLabelProvider; @@ -85,7 +81,7 @@ public class SwtVascViewRenderer implements VascViewRenderer { this.parent=parent; } - public void renderEdit(VascTable table,Object object) { + public void renderEdit(VascTable table,Object object) throws Exception { logger.info("Rending Edit View"); @@ -111,13 +107,41 @@ public class SwtVascViewRenderer implements VascViewRenderer { result = table.getVascDataSource().merge(object); //FlowstatsPlugin.getDefault().fireModelUpdateListeners(result); - } catch (Exception e) { - logger.log(Level.WARNING,"EJB Error: "+e.getMessage(),e); } finally { //crudTable.getCrudTableDataSource().fillCrudDataList(crudTable); } } + public ImageDescriptor getImageDescriptor(String path) { + try { + logger.info("Loading image: "+path); + //System.out.println("==== 1"); + ImageDescriptor result = ImageDescriptor.createFromFile(path.getClass(), path); + if(result==null) { + // try load fff + //.out.println("==== 2"); + //result = ImageDescriptor.createFromURL(SwingImageHelper.class.getClass().getResource(path)); + } + //System.out.println("==== 3"); + if(result==null) { + throw new NullPointerException("Can't load resource: "+path); + } + //System.out.println("==== 4 "+result.getImageData().height+" w:"+result.getImageData().width); + return result; + } catch (Exception e) { + logger.warning("Could not load image from path: '"+path+"'"); + try { + ImageDescriptor result = null; //ImageDescriptor.createFromURL(SwingImageHelper.class.getClass().getResource("/META-INF/images/silk/png/bomb.png")); + if(result==null) { + throw new NullPointerException("Can't load resource: "+path); + } + return result; + } catch (Exception e2) { + return ImageDescriptor.getMissingImageDescriptor(); // default swt missing image fall back + } + } + } + public class SwtVascEditDialog extends Dialog { private Shell shell = null; @@ -232,7 +256,7 @@ public class SwtVascViewRenderer implements VascViewRenderer { new Label(body, SWT.WRAP); Button saveButton = new Button(body, SWT.NONE); - //saveButton.setImage(crudTable.getImageDescriptor("icons/fam/tick.png").createImage()); + saveButton.setImage(getImageDescriptor("icons/fam/tick.png").createImage()); saveButton.setText("generic.save"); saveButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { @@ -244,7 +268,7 @@ public class SwtVascViewRenderer implements VascViewRenderer { } }); Button cancelButton = new Button(body, SWT.NONE); - //cancelButton.setImage(crudTable.getImageDescriptor("icons/fam/cancel.png").createImage()); + cancelButton.setImage(getImageDescriptor("icons/fam/cancel.png").createImage()); cancelButton.setText("generic.cancel"); cancelButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { @@ -256,14 +280,11 @@ public class SwtVascViewRenderer implements VascViewRenderer { } - public void renderView(VascTable table) { - - try { - table.setTableData(table.getVascDataSource().executeQuery(table.getQuery())); - } catch (Exception e) { - e.printStackTrace(); - } - + public void renderView(VascTable table) throws Exception { + + table.getVascTableController().finalizeVascColumns(table); + table.getVascTableController().finalizeVascTable(table); + table.getVascTableController().refreshData(table); this.table=table; GridLayout layout = new GridLayout(); @@ -378,7 +399,11 @@ public class SwtVascViewRenderer implements VascViewRenderer { @Override public void widgetSelected(SelectionEvent event) { logger.info("Global Action"); - action.doGlobalAction(table); + try { + action.doGlobalAction(table); + } catch (Exception e) { + table.getVascTableController().handleException(e, table); + } } } @@ -461,7 +486,7 @@ public class SwtVascViewRenderer implements VascViewRenderer { } }; - Integer totalSize = VascTable.getTotalColumnSize(table); + Integer totalSize = table.getVascTableController().getTotalColumnsWidth(table); logger.finer("Total size: "+totalSize); TableColumn[] columns = table2.getColumns(); for (int i = 0; i < columns.length; i++) { @@ -494,7 +519,7 @@ public class SwtVascViewRenderer implements VascViewRenderer { Button actionButton = new Button(footer, SWT.NONE); actionButton.setText(action.getName()); actionButton.setToolTipText(action.getToolTip()); - //actionButton.setImage(crudTable.getImageDescriptor("icons/fam/table_add.png").createImage()); + actionButton.setImage(getImageDescriptor(action.getImage()).createImage()); actionButton.addSelectionListener(new ActionListener(action)); } @@ -512,7 +537,11 @@ public class SwtVascViewRenderer implements VascViewRenderer { @Override public void widgetSelected(SelectionEvent event) { logger.info("Row Action"); - action.doRowAction(table, table.getSelectedObject()); + try { + action.doRowAction(table, table.getSelectedObject()); + } catch (Exception e) { + table.getVascTableController().handleException(e, table); + } } } diff --git a/tests/com/idcanet/vasc/tests/SWTTest.java b/tests/com/idcanet/vasc/tests/SWTTest.java index fabba05..4172284 100644 --- a/tests/com/idcanet/vasc/tests/SWTTest.java +++ b/tests/com/idcanet/vasc/tests/SWTTest.java @@ -33,8 +33,10 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import com.idcanet.vasc.core.VascTable; +import com.idcanet.vasc.core.column.VascAnnotationTableColumn; import com.idcanet.vasc.core.column.VascTableColumn; import com.idcanet.vasc.impl.BeanVascRecordCreator; +import com.idcanet.vasc.impl.DefaultVascTableController; import com.idcanet.vasc.impl.DefaultVascTextValue; import com.idcanet.vasc.impl.actions.AddRowAction; import com.idcanet.vasc.impl.actions.DeleteRowAction; @@ -93,6 +95,7 @@ public class SWTTest extends TestCase { table.setToolTip("tooltip text"); table.setDescription("en de omscheiving"); table.setHelpId("someKey"); + table.setVascTableController(new DefaultVascTableController()); table.setVascDataSource(new TestModelVascDataSource()); table.setVascTextValue(new DefaultVascTextValue()); table.setVascViewRenderer(render); @@ -122,16 +125,18 @@ public class SWTTest extends TestCase { column.setVascColumnValue(new BeanPropertyVascColumnValue("name")); table.addTableColumns(column); + column = new VascAnnotationTableColumn("description"); + table.addTableColumns(column); + /* column = new VascTableColumn(); column.setName("test2"); column.setToolTip("tooltip2"); column.setDefaultValue("DEFF2FFFF"); column.setHelpId("helpColum2nKey"); column.setWidth(200); - //column.setVascColumnEditor(vascColumnEditor); - //column.setVascColumnRenderer(vascColumnRenderer); column.setVascColumnValue(new BeanPropertyVascColumnValue("description")); table.addTableColumns(column); + */ // render render.renderView(table); diff --git a/tests/com/idcanet/vasc/tests/models/TestModel.java b/tests/com/idcanet/vasc/tests/models/TestModel.java index bd1fd0d..65e98d1 100644 --- a/tests/com/idcanet/vasc/tests/models/TestModel.java +++ b/tests/com/idcanet/vasc/tests/models/TestModel.java @@ -29,6 +29,7 @@ package com.idcanet.vasc.tests.models; import java.util.Date; +import com.idcanet.vasc.annotations.VascColumnWidth; import com.idcanet.vasc.annotations.VascDefaultValue; import com.idcanet.vasc.annotations.VascHelpId; import com.idcanet.vasc.annotations.VascName; @@ -69,6 +70,7 @@ public class TestModel { @VascToolTip(key="De omscheiving") @VascHelpId(helpId="help.id") @VascDefaultValue(defaultValue="xxxxx") + @VascColumnWidth(width=200) public String getDescription() { return description; }