diff --git a/.classpath b/.classpath index fa68597..94b3dde 100644 --- a/.classpath +++ b/.classpath @@ -10,10 +10,13 @@ - + + + + diff --git a/src/com/idcanet/vasc/annotations/VascAnnotationParser.java b/src/com/idcanet/vasc/annotations/VascAnnotationParser.java index 62e6f89..103c1af 100644 --- a/src/com/idcanet/vasc/annotations/VascAnnotationParser.java +++ b/src/com/idcanet/vasc/annotations/VascAnnotationParser.java @@ -201,14 +201,19 @@ public class VascAnnotationParser { } if (a.equals(VascDefaultValue.class)) { VascDefaultValue v = (VascDefaultValue)b; - if (v.defaultValue()==null) { - return null; // error ?? + + if(v.defaultValueClass().equals(Object.class)==false) { + try { + return v.defaultValueClass().newInstance(); + } catch (Exception e) { + logger.log(Level.WARNING,e.getMessage(),e); + throw new NullPointerException("Could not init defaultValueClass"); + } } - try { - return v.defaultValueClass().newInstance(); - } catch (Exception e) { - logger.log(Level.WARNING,e.getMessage(),e); + if ("null".equals(v.defaultValue())) { + return ""; } + return v.defaultValue(); } if (a.equals(VascColumnWidth.class)) { VascColumnWidth c = (VascColumnWidth)b; diff --git a/src/com/idcanet/vasc/core/VascEventListener.java b/src/com/idcanet/vasc/core/VascEventListener.java new file mode 100644 index 0000000..3c5cbfa --- /dev/null +++ b/src/com/idcanet/vasc/core/VascEventListener.java @@ -0,0 +1,41 @@ +/* + * 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 Aug 02, 2007 + */ +public interface VascEventListener { + + public enum VascEventType { DATA_UPDATE,OPTION_UPDATE } + + public void vascEvent(VascEventType e,Object o); + +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/VascTableController.java b/src/com/idcanet/vasc/core/VascTableController.java index a41cee6..9ff79c0 100644 --- a/src/com/idcanet/vasc/core/VascTableController.java +++ b/src/com/idcanet/vasc/core/VascTableController.java @@ -26,6 +26,8 @@ package com.idcanet.vasc.core; +import com.idcanet.vasc.core.column.VascTableColumn; + /** * * @author Willem Cazander @@ -43,6 +45,14 @@ public interface VascTableController { public Object initEditObject(VascTable table,Object object) throws Exception; + public void initEditObjectColumn(VascTableColumn column,Object object) throws Exception; + public void handleException(Exception e,VascTable table); + + public void addEventListener(VascEventListener e); + + public void removeEventListener(VascEventListener e); + + public void fireVascEvent(VascEventListener.VascEventType type,Object data); } \ 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 c1cc2b0..aaf8f4b 100644 --- a/src/com/idcanet/vasc/core/VascViewRenderer.java +++ b/src/com/idcanet/vasc/core/VascViewRenderer.java @@ -40,6 +40,8 @@ public interface VascViewRenderer { public void renderEdit(VascTable table,Object rowBean) throws Exception; + public void renderDelete(VascTable table,Object rowBean) throws Exception; + public void renderExport(VascTable table,VascDataExporter exporter) throws Exception; public Object defaultColumnEditor(VascTableColumn column,Object bean,Object gui) throws Exception; diff --git a/src/com/idcanet/vasc/impl/DefaultVascTableController.java b/src/com/idcanet/vasc/impl/DefaultVascTableController.java index 6753b55..c07d777 100644 --- a/src/com/idcanet/vasc/impl/DefaultVascTableController.java +++ b/src/com/idcanet/vasc/impl/DefaultVascTableController.java @@ -26,10 +26,13 @@ package com.idcanet.vasc.impl; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import com.idcanet.vasc.annotations.VascAnnotationParser; +import com.idcanet.vasc.core.VascEventListener; import com.idcanet.vasc.core.VascTable; import com.idcanet.vasc.core.VascTableController; import com.idcanet.vasc.core.column.VascAnnotationTableColumn; @@ -45,6 +48,12 @@ import com.idcanet.vasc.impl.column.DefaultVascColumnRenderer; */ public class DefaultVascTableController implements VascTableController { + private Logger logger = null; + + public DefaultVascTableController() { + logger = Logger.getLogger(DefaultVascTableController.class.getName()); + } + /** * @see com.idcanet.vasc.core.VascTableController#finalizeVascColumns(com.idcanet.vasc.core.VascTable) */ @@ -120,6 +129,18 @@ public class DefaultVascTableController implements VascTableController { object = table.getVascRecordCreator().newRecord(table); return object; } + + public void initEditObjectColumn(VascTableColumn c,Object bean) throws Exception { + Object value = c.getVascColumnValue().getValue(c, bean); + if(value==null & c.getDefaultValue()!=null) { + try { + logger.finer("Setting default value for: "+c.getName()+" def: "+c.getDefaultValue()); + c.getVascColumnValue().setValue(c, bean, c.getDefaultValue()); + } catch (Exception e) { + logger.log(Level.WARNING,"Error in setting default value: '"+c.getDefaultValue()+"' error: "+e.getMessage(),e); + } + } + } /** * @see com.idcanet.vasc.core.VascTableController#refreshData() @@ -131,4 +152,20 @@ public class DefaultVascTableController implements VascTableController { public void handleException(Exception e,VascTable table) { Logger.getLogger(DefaultVascTableController.class.getName()).log(Level.WARNING,e.getMessage(),e); } + + + List eventListeners = new ArrayList(2); + + public void addEventListener(VascEventListener e) { + eventListeners.add(e); + } + public void removeEventListener(VascEventListener e) { + eventListeners.remove(e); + } + + public void fireVascEvent(VascEventListener.VascEventType type,Object data) { + for(VascEventListener e:eventListeners) { + e.vascEvent(type, data); + } + } } \ 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 e3db712..cb73692 100644 --- a/src/com/idcanet/vasc/impl/actions/AddRowAction.java +++ b/src/com/idcanet/vasc/impl/actions/AddRowAction.java @@ -44,6 +44,6 @@ public class AddRowAction extends AbstractVascAction implements RowVascAction { } public void doRowAction(VascTable table,Object rowObject) throws Exception { - table.getVascViewRenderer().renderEdit(table,rowObject); + table.getVascViewRenderer().renderEdit(table,table.getVascRecordCreator().newRecord(table)); } } \ 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 09d4f48..c0824b0 100644 --- a/src/com/idcanet/vasc/impl/actions/DeleteRowAction.java +++ b/src/com/idcanet/vasc/impl/actions/DeleteRowAction.java @@ -44,6 +44,9 @@ public class DeleteRowAction extends AbstractVascAction implements RowVascAction } public void doRowAction(VascTable table,Object rowObject) throws Exception { - table.getVascDataSource().delete(rowObject); + if (rowObject==null) { + return; + } + table.getVascViewRenderer().renderDelete(table,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 2f02720..6e45213 100644 --- a/src/com/idcanet/vasc/impl/actions/EditRowAction.java +++ b/src/com/idcanet/vasc/impl/actions/EditRowAction.java @@ -45,6 +45,9 @@ public class EditRowAction extends AbstractVascAction implements RowVascAction { public void doRowAction(VascTable table,Object rowObject) throws Exception { + if (rowObject==null) { + return; + } table.getVascViewRenderer().renderEdit(table,rowObject); } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/swing/SwingVascViewRenderer.java b/src/com/idcanet/vasc/impl/swing/SwingVascViewRenderer.java index 2247521..402717b 100644 --- a/src/com/idcanet/vasc/impl/swing/SwingVascViewRenderer.java +++ b/src/com/idcanet/vasc/impl/swing/SwingVascViewRenderer.java @@ -26,23 +26,51 @@ package com.idcanet.vasc.impl.swing; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Container; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.ImageIcon; +import javax.swing.JButton; import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.ListSelectionModel; +import javax.swing.Spring; +import javax.swing.SpringLayout; +import javax.swing.UIManager; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableCellRenderer; +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.VascDataExporter; +import com.idcanet.vasc.core.VascEventListener; import com.idcanet.vasc.core.VascTable; import com.idcanet.vasc.core.VascUserOption; import com.idcanet.vasc.core.VascViewRenderer; +import com.idcanet.vasc.core.actions.GlobalVascAction; import com.idcanet.vasc.core.actions.RowVascAction; -import com.idcanet.vasc.core.column.VascTableColumn;; +import com.idcanet.vasc.core.column.VascTableColumn; /** * @@ -61,53 +89,461 @@ public class SwingVascViewRenderer implements VascViewRenderer { } /** - * @see com.idcanet.vasc.core.VascViewRenderer#renderView(com.idcanet.vasc.core.VascTable) + * @see com.idcanet.vasc.core.VascViewRenderer#defaultColumnEditor(com.idcanet.vasc.core.column.VascTableColumn, java.lang.Object, java.lang.Object) */ - public void renderView(VascTable table) { - this.table=table; - try { - table.setTableData(table.getVascDataSource().executeQuery(table.getQuery())); - } catch (Exception e) { - e.printStackTrace(); + public Object defaultColumnEditor(VascTableColumn column, Object bean, Object gui) throws Exception { + JTextField def = new JTextField(); + def.setText(""+column.getVascColumnValue().getValue(column, bean)); + ((JComponent)gui).add(def); + def.getDocument().addDocumentListener(new TextListener(column,bean) ); + return def; + } + + public ImageIcon getImageIcon(String imageResource) { + return SwingImageHelper.getImageIcon(imageResource); + } + + class TextListener implements DocumentListener { + + private VascTableColumn column = null; + private Object bean = null; + + public TextListener(VascTableColumn column,Object bean) { + this.column=column; + this.bean=bean; + } + + /* (non-Javadoc) + * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent) + */ + public void changedUpdate(DocumentEvent e) { + update(e); + } + + /* (non-Javadoc) + * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent) + */ + public void insertUpdate(DocumentEvent e) { + update(e); + } + + /* (non-Javadoc) + * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent) + */ + public void removeUpdate(DocumentEvent e) { + update(e); + } + + public void update(DocumentEvent event) { + try { + String value = event.getDocument().getText(0, event.getDocument().getLength()); + logger.finer("Setting value: "+value); + column.getVascColumnValue().setValue(column, bean, value); + } catch (Exception ee) { + ee.printStackTrace(); + } + } + } + + + + /** + * @see com.idcanet.vasc.core.VascViewRenderer#defaultColumnRenderer(com.idcanet.vasc.core.column.VascTableColumn, java.lang.Object) + */ + public Object defaultColumnRenderer(VascTableColumn column, Object gui) throws Exception { + return null; + } + + + + + /** + * @see com.idcanet.vasc.core.VascViewRenderer#renderEdit(com.idcanet.vasc.core.VascTable, java.lang.Object) + */ + public void renderEdit(VascTable table, Object rowBean) throws Exception { + logger.info("Rending Edit View"); + table.getVascTableController().initEditObject(table, rowBean); + + SwingEditDialog dialog = new SwingEditDialog(parent,table,rowBean,"Vasc Edit","Edit"); + Object result = dialog.openDialog(); + System.out.println("---------------- OPEN closed : "+result); + if(result==null) { + return; + } + try { + result = table.getVascDataSource().merge(rowBean); + table.getVascTableController().fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, result); + } finally { + //TODO: or merge into table == faster + table.getVascTableController().refreshData(table); + } + } + + public void renderDelete(VascTable table,Object rowBean) throws Exception { + int response = JOptionPane.showOptionDialog( + parent // Center in window. + , "Delete "+rowBean // Message + , "Delete" // Title in titlebar + , JOptionPane.YES_NO_OPTION // Option type + , JOptionPane.PLAIN_MESSAGE // messageType + , null // Icon (none) + , null // Button text as above. + , null // Default button's label + ); + if (response==JOptionPane.YES_OPTION) { + table.getVascDataSource().delete(rowBean); + table.getVascTableController().fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, rowBean); + } + } + + + class SwingEditDialog extends JDialog { + + private String headerText = null; + private String title = null; + private Object result = null; + private Object bean = null; + + public SwingEditDialog(JComponent parent,VascTable table,Object bean,String title,String headerText) { + super(); + this.headerText = headerText; + this.title = title; + this.bean = bean; + + + setTitle(title); + setModal(true); + + JPanel pane = new JPanel(); + pane.setLayout(new BorderLayout()); + + JPanel header = new JPanel(); + createHeader(header); + pane.add(header,BorderLayout.NORTH); + + JPanel body = new JPanel(); + createBody(body); + pane.add(body,BorderLayout.CENTER); + + JPanel footer = new JPanel(); + createFooter(footer); + pane.add(footer,BorderLayout.SOUTH); + + add(pane); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + + //Ensure the text field always gets the first focus. + //addComponentListener(new ComponentAdapter() { + // public void componentShown(ComponentEvent ce) { + // textField.requestFocusInWindow(); + // } + /// }); + + pack(); + setLocationRelativeTo(parent); } + public Object openDialog() { + setVisible(true); + return result; + } + + public void createHeader(JPanel header) { + JLabel l = new JLabel(); + l.setText(headerText); + l.setFont(new Font(null,Font.BOLD, 14)); + header.add(l); + } + + public void createBody(JPanel body) { + body.setLayout(new SpringLayout()); + for(VascTableColumn c:table.getTableColumns()) { + JLabel l = new JLabel(); + l.setHorizontalAlignment(JLabel.TRAILING); + + l.setText(c.getName()); + if(c.getToolTip()!=null) { + l.setToolTipText(c.getToolTip()); + } + body.add(l); + + try { + table.getVascTableController().initEditObjectColumn(c, bean); + + if(c.getVascColumnEditor()==null) { + JLabel valueLabel = new JLabel(); + valueLabel.setText(""+c.getVascColumnValue().getValue(c, bean)); + c.setColumnEditor(valueLabel); + body.add(valueLabel); + } else { + c.setColumnEditor(c.getVascColumnEditor().createColumnEditor(c,bean,body)); + } + } catch (Exception e) { + logger.log(Level.WARNING,"Error making column editor: '"+c.getVascColumnValue()+"' error: "+e.getMessage(),e); + } + } + //JComponent, rows, cols, initX, initY ,xPad, yPad + SpringUtilities.makeCompactGrid(body, table.getTableColumns().size(),2, 6,6, 6,6); + + } + public void createFooter(JPanel footer) { + + JButton saveButton = new JButton(); + saveButton.setIcon(getImageIcon("/META-INF/images/silk/png/tick.png")); + saveButton.setText("generic.save"); + saveButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + //if(hasRecordError()) { + // return; + //} + result = bean; + setVisible(false); + } + }); + footer.add(saveButton); + + JButton cancelButton = new JButton(); + cancelButton.setIcon(getImageIcon("/META-INF/images/silk/png/cancel.png")); + cancelButton.setText("generic.cancel"); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + result = null; + setVisible(false); + } + }); + footer.add(cancelButton); + } + } + + + + + /** + * @see com.idcanet.vasc.core.VascViewRenderer#renderExport(com.idcanet.vasc.core.VascTable, com.idcanet.vasc.core.VascDataExporter) + */ + public void renderExport(VascTable table, VascDataExporter exporter) throws Exception { + + String fileName = null; + JFileChooser c = new JFileChooser(); + // Demonstrate "Save" dialog: + int rVal = c.showSaveDialog(null); + if (rVal == JFileChooser.APPROVE_OPTION) { + fileName = c.getSelectedFile().getAbsolutePath(); + // filename.setText(c.getSelectedFile().getName()); + //dir.setText(c.getCurrentDirectory().toString()); + } + if (rVal == JFileChooser.CANCEL_OPTION) { + return; + } + + logger.fine("FileName: "+fileName); + if (fileName == null) { + return; + } + OutputStream out = new FileOutputStream(fileName); + try { + exporter.doExport(out, table); + } catch (Exception e) { + //MessageDialog.openError(Display.getCurrent().getActiveShell(),crudTable.i18n("crud.event.export.error.title"),crudTable.i18n("crud.event.export.error.message")); + logger.log(Level.WARNING,"Error: "+e.getMessage(),e); + } finally { + if (out!=null) { + out.close(); + } + } + } + + + /** + * @see com.idcanet.vasc.core.VascViewRenderer#renderView(com.idcanet.vasc.core.VascTable) + */ + public void renderView(VascTable table) throws Exception { + + if (table.getVascViewRenderer()==null) { + table.setVascViewRenderer(this); + } else { + if (table.getVascViewRenderer()!=this) { + throw new IllegalArgumentException("VascTable has already a differtent VascViewRenderer attected"); + } + } + table.getVascTableController().finalizeVascColumns(table); + table.getVascTableController().finalizeVascTable(table); + table.getVascTableController().refreshData(table); + this.table=table; + JPanel topPanel = new JPanel(); - renderHeader(topPanel); - renderBody(topPanel); - renderFooter(topPanel); + topPanel.setLayout(new BorderLayout()); + + JPanel n = new JPanel(); + topPanel.add(n,BorderLayout.NORTH); + renderHeader(n); + + JPanel c = new JPanel(); + topPanel.add(c,BorderLayout.CENTER); + renderBody(c); + + JPanel f = new JPanel(); + topPanel.add(f,BorderLayout.SOUTH); + renderFooter(f); + parent.add(topPanel); } - private void renderHeader(JComponent parent2) { - } - - private void renderBody(JComponent parent2) { - JTable jTable = new JTable(new VascColumnModel()); + private void renderHeader(JComponent parent2) { - - for(VascTableColumn c:table.getTableColumns()) { - VascJTableColumn t = new VascJTableColumn(); - t.setPreferredWidth(c.getWidth()); - t.setHeaderValue(c.getName()); - - jTable.addColumn(t); + if(table.getHeaderName()!=null) { + JLabel l = new JLabel(table.getVascTextValue().getTextValue(table.getHeaderName())); + l.setFont(new Font(null,Font.BOLD, 14)); + parent2.add(l); } + for (GlobalVascAction action:table.getGlobalActions()) { + JButton but = new JButton(); + but.setText(table.getVascTextValue().getTextValue(action.getName())); + but.setToolTipText(table.getVascTextValue().getTextValue(action.getToolTip())); + but.addActionListener(new GlobalActionListener(action)); + but.setIcon(getImageIcon(action.getImage())); + parent2.add(but); + } + // create options + for(VascUserOption option:table.getUserOptions()) { + + } + } + + private void renderBody(JComponent parent2) { + + VascColumnModel model = new VascColumnModel(); + table.getVascTableController().addEventListener(model); + JTable jTable = new JTable(model); + + // remove auto columns :( + int cols = jTable.getColumnModel().getColumnCount(); + for (int i=0;irows*cols components of + * parent in a grid. Each component in a column is as wide as + * the maximum preferred width of the components in that column; height is + * similarly determined for each row. The parent is made just big enough to + * fit them all. + * + * @param rows + * number of rows + * @param cols + * number of columns + * @param initialX + * x location to start the grid at + * @param initialY + * y location to start the grid at + * @param xPad + * x padding between cells + * @param yPad + * y padding between cells + */ + 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; + } + + //Align all cells in each column and make them the same width. + Spring x = Spring.constant(initialX); + for (int c = 0; c < cols; c++) { + Spring width = Spring.constant(0); + for (int r = 0; r < rows; r++) { + width = Spring.max(width, getConstraintsForCell(r, c, parent, + cols).getWidth()); + } + for (int r = 0; r < rows; r++) { + SpringLayout.Constraints constraints = getConstraintsForCell(r, + c, parent, cols); + constraints.setX(x); + constraints.setWidth(width); + } + x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad))); + } + + //Align all cells in each row and make them the same height. + Spring y = Spring.constant(initialY); + for (int r = 0; r < rows; r++) { + Spring height = Spring.constant(0); + for (int c = 0; c < cols; c++) { + height = Spring.max(height, getConstraintsForCell(r, c, parent, + cols).getHeight()); + } + for (int c = 0; c < cols; c++) { + SpringLayout.Constraints constraints = getConstraintsForCell(r, + c, parent, cols); + constraints.setY(y); + constraints.setHeight(height); + } + y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad))); + } + + //Set the parent's size. + SpringLayout.Constraints pCons = layout.getConstraints(parent); + pCons.setConstraint(SpringLayout.SOUTH, y); + pCons.setConstraint(SpringLayout.EAST, x); + } +} + diff --git a/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java b/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java index ee29541..81fa326 100644 --- a/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java +++ b/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java @@ -126,7 +126,7 @@ public class SwtVascViewRenderer implements VascViewRenderer { logger.info("Rending Edit View"); table.getVascTableController().initEditObject(table, object); - SwtVascEditDialog dialog = new SwtVascEditDialog(Display.getCurrent().getActiveShell(),table,object,"Edit","TOITO"); + SwtVascEditDialog dialog = new SwtVascEditDialog(Display.getCurrent().getActiveShell(),table,object,"Vasc Edit","Edit"); Object result = dialog.open(); if(result==null) { return; @@ -172,6 +172,10 @@ public class SwtVascViewRenderer implements VascViewRenderer { } } + public void renderDelete(VascTable table,Object rowBean) throws Exception { + + } + public class SwtVascEditDialog extends Dialog { private Shell shell = null; @@ -246,7 +250,11 @@ public class SwtVascViewRenderer implements VascViewRenderer { l.setToolTipText(c.getToolTip()); } + + try { + table.getVascTableController().initEditObjectColumn(c, bean); + if(c.getVascColumnEditor()==null) { Label valueLabel = new Label(body, SWT.WRAP); valueLabel.setText(""+c.getVascColumnValue().getValue(c, bean)); @@ -258,15 +266,6 @@ public class SwtVascViewRenderer implements VascViewRenderer { logger.log(Level.WARNING,"Error making column editor: '"+c.getVascColumnValue()+"' error: "+e.getMessage(),e); } - // set the default value before creating property - if(c.getVascColumnValue()==null & c.getDefaultValue()!=null) { - try { - logger.finer("Setting default value for: "+c.getName()+" def: "+c.getDefaultValue()); - c.getVascColumnValue().setValue(c, bean, c.getDefaultValue()); - } catch (Exception e) { - logger.log(Level.WARNING,"Error in setting default value: '"+c.getDefaultValue()+"' error: "+e.getMessage(),e); - } - } if(c.getColumnEditor() instanceof Control) { Control editor = (Control)c.getColumnEditor(); GridData gridData = new GridData(); diff --git a/tests/com/idcanet/vasc/SWTTest.java b/tests/com/idcanet/vasc/SWTTest.java index f80033a..07f165d 100644 --- a/tests/com/idcanet/vasc/SWTTest.java +++ b/tests/com/idcanet/vasc/SWTTest.java @@ -80,15 +80,34 @@ public class SWTTest extends TestCase { // get GUI Display display = new Display(); Shell shell = new Shell(display); - shell.setText("Hello, world!"); - + shell.setText("Hello, world!"); + + // define redering and render + SwtVascViewRenderer render = new SwtVascViewRenderer(shell); + render.renderView(getVascTable()); + + // view + shell.open(); + // Set up the event loop. + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + // If no more entries in event queue + display.sleep(); + } + } + display.dispose(); + } + + + static public VascTable getVascTable() throws Exception { + // define query XTESParser parser = new XTESParser(); parser.parseResource("/META-INF/xtes/tests.xml"); TemplateStore store = XTESParser.getTemplateStore(parser.getElementContext()); Query query = store.getQuery("testUsers2"); - - // config table + + // config table VascTable table = new VascTable(); table.setName("Testje"); table.setHeaderName("TableHeader"); @@ -118,6 +137,7 @@ public class SWTTest extends TestCase { column.setToolTip("tooltip"); column.setDefaultValue("DEFFFFFF"); column.setHelpId("helpColumnKey"); + column.setImage("/META-INF/images/silk/png/tick.png"); column.setWidth(400); column.setVascColumnEditor(new DefaultVascColumnEditor()); column.setVascColumnRenderer(new DefaultVascColumnRenderer()); @@ -126,21 +146,6 @@ public class SWTTest extends TestCase { column = new VascAnnotationTableColumn("description"); table.addTableColumns(column); - - - // define redering and render - SwtVascViewRenderer render = new SwtVascViewRenderer(shell); - render.renderView(table); - - // view - shell.open(); - // Set up the event loop. - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - // If no more entries in event queue - display.sleep(); - } - } - display.dispose(); + return table; } } \ No newline at end of file diff --git a/tests/com/idcanet/vasc/SwingTest.java b/tests/com/idcanet/vasc/SwingTest.java index 9958453..cdcf1b9 100644 --- a/tests/com/idcanet/vasc/SwingTest.java +++ b/tests/com/idcanet/vasc/SwingTest.java @@ -30,21 +30,9 @@ import java.io.InputStream; import java.util.logging.LogManager; import javax.swing.JFrame; +import javax.swing.JPanel; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -import com.idcanet.vasc.core.VascTable; -import com.idcanet.vasc.core.column.VascTableColumn; -import com.idcanet.vasc.impl.BeanVascRecordCreator; -import com.idcanet.vasc.impl.DefaultVascTextValue; -import com.idcanet.vasc.impl.column.BeanPropertyVascColumnValue; -import com.idcanet.vasc.impl.serv5.Serv5HibernateVascDataSource; import com.idcanet.vasc.impl.swing.SwingVascViewRenderer; -import com.idcanet.vasc.impl.swt.SwtVascViewRenderer; -import com.idcanet.xtes.core.TemplateStore; -import com.idcanet.xtes.core.XTESParser; -import com.idcanet.xtes.xpql.query.Query; import junit.framework.TestCase; @@ -61,71 +49,38 @@ public class SwingTest extends TestCase { InputStream loggingProperties = this.getClass().getResourceAsStream("/META-INF/logging.properties"); LogManager.getLogManager().readConfiguration( loggingProperties ); loggingProperties.close(); - - // load xtes queries } public void tearDown() throws Exception { } public void testAll() throws Exception { + JFrame.setDefaultLookAndFeelDecorated(false); // get GUI JFrame frame = new JFrame(); - frame.setTitle("Hello, world!"); - frame.setDefaultLookAndFeelDecorated(false); + frame.setTitle("Swing Vasc Test"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); - frame.setBounds(150,150,700,500); + frame.setBounds(150,150,900,700); - // define query - XTESParser parser = new XTESParser(); - parser.parseResource("/META-INF/xtes/tests.xml"); - TemplateStore store = XTESParser.getTemplateStore(parser.getElementContext()); - Query query = store.getQuery("testUsers2"); - + JPanel panel = new JPanel(); + frame.add(panel); // define redering - SwingVascViewRenderer render = new SwingVascViewRenderer(frame.getRootPane()); + SwingVascViewRenderer render = new SwingVascViewRenderer(panel); - // config table - VascTable table = new VascTable(); - table.setName("Testje"); - table.setHeaderName("TableHeader"); - table.setToolTip("tooltip text"); - table.setDescription("en de omscheiving"); - table.setHelpId("someKey"); - table.setVascDataSource(new TestModelVascDataSource()); - table.setVascTextValue(new DefaultVascTextValue()); - table.setVascViewRenderer(render); - table.setQuery(query); - table.setVascRecordCreator(new BeanVascRecordCreator()); - - VascTableColumn column = new VascTableColumn(); - column.setName("test"); - column.setToolTip("tooltip"); - column.setDefaultValue("DEFFFFFF"); - column.setHelpId("helpColumnKey"); - column.setWidth(200); - //column.setVascColumnEditor(vascColumnEditor); - //column.setVascColumnRenderer(vascColumnRenderer); - column.setVascColumnValue(new BeanPropertyVascColumnValue("name")); - table.addTableColumns(column); - // render - render.renderView(table); + render.renderView(SWTTest.getVascTable()); // view frame.getContentPane().validate(); frame.setVisible(true); + frame.repaint(); - String test="34"; - while (true) { - test+=test+"34566"; - if(test.length()>1000000) { - break; - } + while (frame.isVisible()) { + Thread.sleep(1000); } } } \ No newline at end of file diff --git a/tests/com/idcanet/vasc/TestModelVascDataSource.java b/tests/com/idcanet/vasc/TestModelVascDataSource.java index 890ac22..e2f98ac 100644 --- a/tests/com/idcanet/vasc/TestModelVascDataSource.java +++ b/tests/com/idcanet/vasc/TestModelVascDataSource.java @@ -68,13 +68,16 @@ public class TestModelVascDataSource implements VascDataSource { } public void persist(Object object) throws Exception { - + testModels.add(object); } public Object merge(Object object) throws Exception { + if(testModels.contains(object)==false) { + testModels.add(object); + } return object; } public void delete(Object object) throws Exception { - + testModels.remove(object); }