diff --git a/src/com/idcanet/vasc/annotations/VascAnnotationParser.java b/src/com/idcanet/vasc/annotations/VascAnnotationParser.java index c158b24..a22a7c7 100644 --- a/src/com/idcanet/vasc/annotations/VascAnnotationParser.java +++ b/src/com/idcanet/vasc/annotations/VascAnnotationParser.java @@ -184,7 +184,13 @@ public class VascAnnotationParser { // recursif function: return getValue(typeClass,annotationType,propRest); } - result = doAnnotation(method.getAnnotation(annotationType)); + + Annotation anno = method.getAnnotation(annotationType); + // no annotation == no default + if (anno==null && annotationType.equals(VascDefaultValue.class)) { + return null; + } + result = doAnnotation(anno); if(result!=null) { return result; } diff --git a/src/com/idcanet/vasc/core/column/VascColumnRenderer.java b/src/com/idcanet/vasc/core/column/VascColumnRenderer.java index 6351544..54c6b9b 100644 --- a/src/com/idcanet/vasc/core/column/VascColumnRenderer.java +++ b/src/com/idcanet/vasc/core/column/VascColumnRenderer.java @@ -33,5 +33,5 @@ package com.idcanet.vasc.core.column; */ public interface VascColumnRenderer { - public Object createColumnRenderer(VascTableColumn column,Object gui) throws Exception; + public String rendererColumn(VascTableColumn column,Object record) throws Exception; } \ 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 a1da074..987a4f8 100644 --- a/src/com/idcanet/vasc/core/column/VascTableColumn.java +++ b/src/com/idcanet/vasc/core/column/VascTableColumn.java @@ -50,11 +50,14 @@ public class VascTableColumn { private VascColumnRenderer vascColumnRenderer = null; private VascUIComponent vascUIComponent = null; - private Object columnRenderer = null; private Object columnEditor = null; private VascTable vascTable = null; + private boolean editDisplay = true; + private boolean editReadonly = false; + private boolean listDisplay = true; + /** * @return the defaultValue */ @@ -153,20 +156,6 @@ public class VascTableColumn { public void setColumnEditor(Object columnEditor) { this.columnEditor = columnEditor; } - - /** - * @return the columnRenderer - */ - public Object getColumnRenderer() { - return columnRenderer; - } - - /** - * @param columnRenderer the columnRenderer to set - */ - public void setColumnRenderer(Object columnRenderer) { - this.columnRenderer = columnRenderer; - } /** * @return the helpId @@ -209,4 +198,46 @@ public class VascTableColumn { public void setVascTable(VascTable vascTable) { this.vascTable = vascTable; } + + /** + * @return the editDisplay + */ + public boolean isEditDisplay() { + return editDisplay; + } + + /** + * @param editDisplay the editDisplay to set + */ + public void setEditDisplay(boolean editDisplay) { + this.editDisplay = editDisplay; + } + + /** + * @return the editReadonly + */ + public boolean isEditReadonly() { + return editReadonly; + } + + /** + * @param editReadonly the editReadonly to set + */ + public void setEditReadonly(boolean editReadonly) { + this.editReadonly = editReadonly; + } + + /** + * @return the listDisplay + */ + public boolean isListDisplay() { + return listDisplay; + } + + /** + * @param listDisplay the listDisplay to set + */ + public void setListDisplay(boolean listDisplay) { + this.listDisplay = listDisplay; + } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/column/VascColumnEditor.java b/src/com/idcanet/vasc/impl/column/BeanPropertyVascColumnRenderer.java similarity index 68% rename from src/com/idcanet/vasc/core/column/VascColumnEditor.java rename to src/com/idcanet/vasc/impl/column/BeanPropertyVascColumnRenderer.java index 994e740..001f918 100644 --- a/src/com/idcanet/vasc/core/column/VascColumnEditor.java +++ b/src/com/idcanet/vasc/impl/column/BeanPropertyVascColumnRenderer.java @@ -24,14 +24,34 @@ * should not be interpreted as representing official policies, either expressed or implied, of IDCA. */ -package com.idcanet.vasc.core.column; +package com.idcanet.vasc.impl.column; + +import com.idcanet.vasc.core.column.VascColumnRenderer; +import com.idcanet.vasc.core.column.VascTableColumn; /** * * @author Willem Cazander * @version 1.0 Mar 21, 2007 */ -public interface VascColumnEditor { +public class BeanPropertyVascColumnRenderer extends BeanPropertyVascColumnValue implements VascColumnRenderer { + - public Object createColumnEditor(VascTableColumn column,Object bean,Object gui) throws Exception; + public BeanPropertyVascColumnRenderer() { + super(); + } + public BeanPropertyVascColumnRenderer(String property) { + super(property); + } + + /** + * @see com.idcanet.vasc.core.column.VascColumnRenderer#rendererColumn(com.idcanet.vasc.core.column.VascTableColumn, java.lang.Object) + */ + public String rendererColumn(VascTableColumn column, Object record) throws Exception { + Object o = getValue(column,record); + if (o==null) { + return ""; + } + return o.toString(); + } } \ 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 89292e7..8074dd5 100644 --- a/src/com/idcanet/vasc/impl/swing/SwingVascViewRenderer.java +++ b/src/com/idcanet/vasc/impl/swing/SwingVascViewRenderer.java @@ -37,6 +37,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileOutputStream; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -51,13 +53,10 @@ 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; @@ -232,7 +231,14 @@ public class SwingVascViewRenderer implements VascViewRenderer { public void createBody(JPanel body) throws Exception { body.setLayout(new SpringLayout()); - for(VascTableColumn c:table.getTableColumns()) { + int column = 0; + for(VascTableColumn c:table.getTableColumns()) { + table.getVascTableController().initEditObjectColumn(c, bean); + if (c.isEditDisplay()==false) { + continue; + } + column++; + JLabel l = new JLabel(); l.setHorizontalAlignment(JLabel.TRAILING); @@ -242,15 +248,20 @@ public class SwingVascViewRenderer implements VascViewRenderer { } body.add(l); - table.getVascTableController().initEditObjectColumn(c, bean); - + if (c.isEditReadonly()==true) { + JLabel valueLabel = new JLabel(); + valueLabel.setText(""+c.getVascColumnValue().getValue(c, bean)); + c.setColumnEditor(valueLabel); + body.add(valueLabel); + continue; + } + if(c.getVascUIComponent()==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)); VascUIComponent comp = c.getVascUIComponent(); VascValueModel model = new VascValueModel(); model.setValue(c.getVascColumnValue().getValue(c, bean)); @@ -258,9 +269,9 @@ public class SwingVascViewRenderer implements VascViewRenderer { comp.createComponent(table, model, body); c.setColumnEditor(comp); } - } + } //JComponent, rows, cols, initX, initY ,xPad, yPad - SpringUtilities.makeCompactGrid(body, table.getTableColumns().size(),2, 6,6, 6,6); + SpringUtilities.makeCompactGrid(body, column,2, 6,6, 6,6); } public void createFooter(JPanel footer) { @@ -370,10 +381,11 @@ public class SwingVascViewRenderer implements VascViewRenderer { if(table.getHeaderImage()!=null) { JLabel l = new JLabel(); - // TODO: hack images working l.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(table.getHeaderImage())).getScaledInstance(32, 32, Image.SCALE_SMOOTH))); - l.setToolTipText(table.getVascTextValue().getTextValue(table.getHeaderToolTip())); + if (table.getHeaderToolTip()!=null) { + l.setToolTipText(table.getVascTextValue().getTextValue(table.getHeaderToolTip())); + } header.add(l,BorderLayout.WEST); } @@ -381,7 +393,9 @@ public class SwingVascViewRenderer implements VascViewRenderer { JLabel l = new JLabel(table.getVascTextValue().getTextValue(table.getHeaderName())); l.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); l.setFont(new Font(null,Font.BOLD, 18)); - l.setToolTipText(table.getVascTextValue().getTextValue(table.getHeaderToolTip())); + if (table.getHeaderToolTip()!=null) { + l.setToolTipText(table.getVascTextValue().getTextValue(table.getHeaderToolTip())); + } header.add(l,BorderLayout.CENTER); } @@ -422,10 +436,14 @@ public class SwingVascViewRenderer implements VascViewRenderer { TableColumn c = jTable.getColumnModel().getColumn(0); // idd, just remove index 0 every time jTable.removeColumn(c); } + jTable.revalidate(); TableCellRenderer renderer = new JComponentTableCellRenderer(); int counter=0; for(VascTableColumn c:table.getTableColumns()) { + if (c.isListDisplay()==false) { + continue; + } TableColumn t = new TableColumn(); t.setPreferredWidth(c.getWidth()); t.setHeaderValue(c); @@ -548,7 +566,14 @@ public class SwingVascViewRenderer implements VascViewRenderer { * @see javax.swing.table.TableModel#getColumnCount() */ public int getColumnCount() { - return table.getTableColumns().size(); + int result = 0; + for(VascTableColumn c:table.getTableColumns()) { + if (c.isListDisplay()==false) { + continue; + } + result++; + } + return result; } /** @@ -567,17 +592,26 @@ public class SwingVascViewRenderer implements VascViewRenderer { public Object getValueAt(int rowIndex, int columnIndex) { Object bean = table.getTableData().get(rowIndex); logger.finer("Rending column; "+columnIndex+" bean: "+bean); - VascTableColumn vtc = table.getTableColumns().get(columnIndex); - if (vtc.getColumnRenderer()!=null) { - //do iets - return "RENDER"; - } else { - try { - return ""+vtc.getVascColumnValue().getValue(vtc,bean); - } catch (Exception e) { - e.printStackTrace(); - return "Error"; + + List list = new ArrayList(); + for(VascTableColumn c:table.getTableColumns()) { + if (c.isListDisplay()==false) { + continue; + } + list.add(c); + } + + VascTableColumn vtc = list.get(columnIndex); + try { + if (vtc.getVascColumnRenderer()!=null) { + return vtc.getVascColumnRenderer().rendererColumn(vtc,bean); + } else { + return ""+vtc.getVascColumnValue().getValue(vtc,bean); + } + } catch (Exception e) { + e.printStackTrace(); + return "Error"; } } } diff --git a/src/com/idcanet/vasc/impl/swing/ui/SwingList.java b/src/com/idcanet/vasc/impl/swing/ui/SwingList.java index 9bdbc2d..7f2e1ac 100644 --- a/src/com/idcanet/vasc/impl/swing/ui/SwingList.java +++ b/src/com/idcanet/vasc/impl/swing/ui/SwingList.java @@ -56,7 +56,7 @@ import com.idcanet.vasc.core.ui.VascValueModel; public class SwingList extends AbstractVascUIComponent { public Object createComponent(VascTable table,final VascValueModel model,Object gui) throws Exception { - + VascList l = (VascList)getWrapper(); JComboBox def; if (l.getVascSelectItemModel()==null) { @@ -85,7 +85,11 @@ class MyCellRenderer extends JLabel implements ListCellRenderer { public Component getListCellRendererComponent(JList list,Object value,int index,boolean isSelected,boolean cellHasFocus) { VascSelectItem i = (VascSelectItem)value; - setText(i.getLabel()); + if (i!=null) { + setText(i.getLabel()); + } else { + setText("Error"); + } return this; } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java b/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java index cf058f4..7cde7ba 100644 --- a/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java +++ b/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java @@ -661,7 +661,7 @@ public class SwtVascViewRenderer implements VascViewRenderer { */ public String getColumnText(Object bean, int columnNumber) { VascTableColumn vtc = table.getTableColumns().get(columnNumber); - if (vtc.getColumnRenderer()==null) { + if (vtc.getVascColumnRenderer()==null) { try { return ""+vtc.getVascColumnValue().getValue(vtc,bean); } catch (Exception e) {