diff --git a/src/com/idcanet/vasc/core/VascExceptionListener.java b/src/com/idcanet/vasc/core/VascExceptionListener.java new file mode 100644 index 0000000..3794f18 --- /dev/null +++ b/src/com/idcanet/vasc/core/VascExceptionListener.java @@ -0,0 +1,40 @@ +/* + * 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; + +import java.util.EventListener; + + +/** + * + * @author Willem Cazander + * @version 1.0 Aug 12, 2007 + */ +public interface VascExceptionListener extends EventListener { + + public void handleException(Exception e,VascTable table); +} \ 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 1d168a5..5e24a77 100644 --- a/src/com/idcanet/vasc/core/VascTable.java +++ b/src/com/idcanet/vasc/core/VascTable.java @@ -35,7 +35,6 @@ 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.column.VascTableColumn; -import com.idcanet.vasc.core.ui.VascUIComponent; /** * @@ -62,7 +61,8 @@ public class VascTable { private List userOptions = null; private String helpId = null; private VascTableController vascTableController = null; - private Map uiComponents = null; + private Map,Class> uiComponents = null; + private VascTableColumn UIIdentifierVascTableColomn = null; public VascTable() { tableColumns = new ArrayList(6); @@ -71,7 +71,7 @@ public class VascTable { globalActions = new ArrayList(6); tableData = new ArrayList(6); userOptions = new ArrayList(6); - uiComponents = new HashMap(6); + uiComponents = new HashMap,Class>(6); } /** @@ -321,10 +321,24 @@ public class VascTable { } - public Class getUIComponent(Class classType) { + public Class getUIComponent(Class classType) { return uiComponents.get(classType); } - public void putUIComponent(Class classType,Class comp) { + public void putUIComponent(Class classType,Class comp) { uiComponents.put(classType, comp); } + + /** + * @return the uiIdentifierVascTableColomn + */ + public VascTableColumn getUIIdentifierVascTableColomn() { + return UIIdentifierVascTableColomn; + } + + /** + * @param uiIdentifierVascTableColomn the uiIdentifierVascTableColomn to set + */ + public void setUIIdentifierVascTableColomn(VascTableColumn UIIdentifierVascTableColomn) { + this.UIIdentifierVascTableColomn = UIIdentifierVascTableColomn; + } } diff --git a/src/com/idcanet/vasc/core/VascTableController.java b/src/com/idcanet/vasc/core/VascTableController.java index 9ff79c0..8c5b228 100644 --- a/src/com/idcanet/vasc/core/VascTableController.java +++ b/src/com/idcanet/vasc/core/VascTableController.java @@ -55,4 +55,9 @@ public interface VascTableController { public void fireVascEvent(VascEventListener.VascEventType type,Object data); + public boolean setUIComponentsBeanErrors(VascTable table,Object bean); + + public void addExceptionListener(VascExceptionListener listener); + + public void removeExceptionListener(VascExceptionListener listener); } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/ui/VascColumnValueModelListener.java b/src/com/idcanet/vasc/core/ui/VascColumnValueModelListener.java index e117c14..a0de417 100644 --- a/src/com/idcanet/vasc/core/ui/VascColumnValueModelListener.java +++ b/src/com/idcanet/vasc/core/ui/VascColumnValueModelListener.java @@ -46,13 +46,8 @@ public class VascColumnValueModelListener implements VascValueModelListener { setBean(bean); } - public void valueUpdate(VascValueModel model) { - try { - System.out.println("model bean updating: "+bean); - vascTableColumn.getVascColumnValue().setValue(vascTableColumn, bean, model.getValue()); - } catch (Exception e) { - e.printStackTrace(); - } + public void valueUpdate(VascValueModel model) throws Exception { + vascTableColumn.getVascColumnValue().setValue(vascTableColumn, bean, model.getValue()); } diff --git a/src/com/idcanet/vasc/core/ui/VascUIComponent.java b/src/com/idcanet/vasc/core/ui/VascUIComponent.java index 92dfa88..b63ffaf 100644 --- a/src/com/idcanet/vasc/core/ui/VascUIComponent.java +++ b/src/com/idcanet/vasc/core/ui/VascUIComponent.java @@ -40,4 +40,6 @@ public interface VascUIComponent { public Object createComponent(VascTable table,VascValueModel model,Object gui) throws Exception; + public void setErrorText(String text); + public String getErrorText(); } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/ui/VascUIComponentImplLoader.java b/src/com/idcanet/vasc/core/ui/VascUIComponentImplLoader.java index 464b6b4..a60c636 100644 --- a/src/com/idcanet/vasc/core/ui/VascUIComponentImplLoader.java +++ b/src/com/idcanet/vasc/core/ui/VascUIComponentImplLoader.java @@ -34,10 +34,33 @@ import com.idcanet.vasc.core.VascTable; * @version 1.0 Aug 12, 2007 */ abstract public class VascUIComponentImplLoader extends AbstractVascUIComponent { - + + private VascUIComponent realComponent = null; + public Object loadAndCreateComponent(VascUIComponent wrapper,VascTable table,VascValueModel model,Object gui) throws Exception { - VascUIComponent comp = (VascUIComponent)table.getUIComponent(wrapper.getClass()).newInstance(); - comp.setWrapper(wrapper); - return comp.createComponent(table, model, gui); + realComponent = (VascUIComponent)table.getUIComponent(wrapper.getClass()).newInstance(); + realComponent.setWrapper(wrapper); + return realComponent.createComponent(table, model, gui); + } + + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText() + */ + public String getErrorText() { + if (realComponent==null) { + return null; + } + return realComponent.getErrorText(); + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String) + */ + public void setErrorText(String text) { + if (realComponent==null) { + return; + } + realComponent.setErrorText(text); } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/ui/VascValueModel.java b/src/com/idcanet/vasc/core/ui/VascValueModel.java index cdc1571..ff52121 100644 --- a/src/com/idcanet/vasc/core/ui/VascValueModel.java +++ b/src/com/idcanet/vasc/core/ui/VascValueModel.java @@ -29,6 +29,8 @@ package com.idcanet.vasc.core.ui; import java.util.ArrayList; import java.util.List; +import com.idcanet.vasc.core.VascTable; + /** * @@ -39,9 +41,11 @@ public class VascValueModel { private Object value = null; private List listeners = null; + private VascTable table = null; - public VascValueModel() { + public VascValueModel(VascTable table) { listeners = new ArrayList(2); + this.table=table; } public Object getValue() { @@ -50,7 +54,11 @@ public class VascValueModel { public void setValue(Object value) { this.value = value; - fireListeners(); + try { + fireListeners(); + } catch (Exception e) { + table.getVascTableController().handleException(e, table); + } } public void addListener(VascValueModelListener l) { @@ -59,7 +67,7 @@ public class VascValueModel { public void removeListener(VascValueModelListener l) { listeners.remove(l); } - private void fireListeners() { + private void fireListeners() throws Exception { for (VascValueModelListener l:listeners) { l.valueUpdate(this); } diff --git a/src/com/idcanet/vasc/core/ui/VascValueModelListener.java b/src/com/idcanet/vasc/core/ui/VascValueModelListener.java index f90a275..9daa6ca 100644 --- a/src/com/idcanet/vasc/core/ui/VascValueModelListener.java +++ b/src/com/idcanet/vasc/core/ui/VascValueModelListener.java @@ -26,14 +26,15 @@ package com.idcanet.vasc.core.ui; +import java.util.EventListener; + /** * * @author Willem Cazander * @version 1.0 Aug 12, 2007 */ -public interface VascValueModelListener { +public interface VascValueModelListener extends EventListener { - - public void valueUpdate(VascValueModel model); + public void valueUpdate(VascValueModel model) throws Exception; } \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/DefaultVascTableController.java b/src/com/idcanet/vasc/impl/DefaultVascTableController.java index c0eaba2..006a7b3 100644 --- a/src/com/idcanet/vasc/impl/DefaultVascTableController.java +++ b/src/com/idcanet/vasc/impl/DefaultVascTableController.java @@ -32,8 +32,12 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import org.hibernate.validator.ClassValidator; +import org.hibernate.validator.InvalidValue; + import com.idcanet.vasc.annotations.VascAnnotationParser; import com.idcanet.vasc.core.VascEventListener; +import com.idcanet.vasc.core.VascExceptionListener; import com.idcanet.vasc.core.VascTable; import com.idcanet.vasc.core.VascTableController; import com.idcanet.vasc.core.column.VascAnnotationTableColumn; @@ -51,9 +55,13 @@ import com.idcanet.vasc.impl.column.BeanPropertyVascColumnValue; public class DefaultVascTableController implements VascTableController { private Logger logger = null; + private List eventListeners = null; + private List exceptionListeners = null; public DefaultVascTableController() { logger = Logger.getLogger(DefaultVascTableController.class.getName()); + eventListeners = new ArrayList(2); + exceptionListeners = new ArrayList(2); } /** @@ -164,12 +172,19 @@ public class DefaultVascTableController implements VascTableController { } public void handleException(Exception e,VascTable table) { - Logger.getLogger(DefaultVascTableController.class.getName()).log(Level.WARNING,e.getMessage(),e); + if (exceptionListeners.isEmpty()) { + Logger.getLogger(DefaultVascTableController.class.getName()).log(Level.WARNING,e.getMessage(),e); + return; + } + for(VascExceptionListener ee:exceptionListeners) { + try { + ee.handleException(e, table); + } catch (Exception eee) { + Logger.getLogger(DefaultVascTableController.class.getName()).log(Level.WARNING,"Error in ExceptionListener: "+eee.getMessage(),eee); + } + } } - - List eventListeners = new ArrayList(2); - public void addEventListener(VascEventListener e) { eventListeners.add(e); } @@ -182,4 +197,52 @@ public class DefaultVascTableController implements VascTableController { e.vascEvent(type, data); } } + + @SuppressWarnings("unchecked") + public boolean setUIComponentsBeanErrors(VascTable table,Object bean) { + boolean error = false; + if(bean==null) { + logger.finest("No bean to check."); + return true; // nothing to check + } + + ClassValidator val = new ClassValidator(bean.getClass()); + InvalidValue[] ival = val.getInvalidValues(bean); + logger.fine("Got invaliled value: "+ival.length); + + for(VascTableColumn col:table.getTableColumns()) { + if(col.getVascUIComponent()==null) { + continue; // we only DISPLAY user input errors !! + } + if (col instanceof VascAnnotationTableColumn) { + VascAnnotationTableColumn column = (VascAnnotationTableColumn)col; + + InvalidValue iv = findInvalidValueByProperty(ival,column.getBeanProperty()); + if(iv==null) { + column.getVascUIComponent().setErrorText(null); + continue; // no error on this property + } + error = true; + column.getVascUIComponent().setErrorText(iv.getMessage()); + } + } + logger.finest("Checked for errors: "+error); + return error; + } + private InvalidValue findInvalidValueByProperty(InvalidValue[] ival,String property) { + for(InvalidValue iv:ival) { + if(iv.getPropertyName().equals(property)) { + return iv; + } + } + return null; + } + + public void addExceptionListener(VascExceptionListener listener) { + exceptionListeners.add(listener); + } + + public void removeExceptionListener(VascExceptionListener listener) { + exceptionListeners.remove(listener); + } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/serv5/Serv5HibernateVascDataSource.java b/src/com/idcanet/vasc/impl/serv5/Serv5HibernateVascDataSource.java index dd69a30..142bb42 100644 --- a/src/com/idcanet/vasc/impl/serv5/Serv5HibernateVascDataSource.java +++ b/src/com/idcanet/vasc/impl/serv5/Serv5HibernateVascDataSource.java @@ -67,7 +67,7 @@ public class Serv5HibernateVascDataSource extends AbstractVascDataSource { i++; } List data = q.list(); - //logger.info("Query returned: "+data.size()+" of: "+crudTable.getQueryName()); + //logger.fine("Query returned: "+data.size()+" of: "+crudTable.getQueryName()); return data; } finally { Hibernate3Factory.getSession("flowstats").close(); // close session in threads diff --git a/src/com/idcanet/vasc/impl/swing/SwingVascViewRenderer.java b/src/com/idcanet/vasc/impl/swing/SwingVascViewRenderer.java index e3992bb..68ee086 100644 --- a/src/com/idcanet/vasc/impl/swing/SwingVascViewRenderer.java +++ b/src/com/idcanet/vasc/impl/swing/SwingVascViewRenderer.java @@ -39,7 +39,6 @@ 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; import javax.swing.BorderFactory; @@ -126,7 +125,7 @@ public class SwingVascViewRenderer implements VascViewRenderer { public ImageIcon getImageIcon(String imageResource) { /// TODO hack beter String key = table.getVascTextValue().getTextValue(imageResource); - //logger.info("KEY======================="+key); + //logger.fine("KEY======================="+key); if (key.indexOf("META-INF")>0 | key.indexOf("resource")>0) { return SwingImageHelper.getImageIcon(key); @@ -141,10 +140,21 @@ public class SwingVascViewRenderer implements VascViewRenderer { * @see com.idcanet.vasc.core.VascViewRenderer#renderEdit(com.idcanet.vasc.core.VascTable, java.lang.Object) */ public void renderEdit(Object rowBean) throws Exception { - logger.info("Rending Edit View"); + logger.fine("Rending Edit View"); table.getVascTableController().initEditObject(table, rowBean); - - SwingEditDialog dialog = new SwingEditDialog(parent,table,rowBean,"Vasc Edit","Edit"); + String beanValue = rowBean.toString(); + if (table.getUIIdentifierVascTableColomn()!=null) { + Object vv = table.getUIIdentifierVascTableColomn().getVascColumnValue().getValue(table.getUIIdentifierVascTableColomn(), rowBean); + if (vv==null) { + beanValue=""; + } else { + beanValue=""+vv; + } + if (beanValue.length()>30) { + beanValue=beanValue.substring(0, 30); + } + } + SwingEditDialog dialog = new SwingEditDialog(parent,table,rowBean,table.getVascTextValue().getTextValue("vasc.dialog.edit.title"),table.getVascTextValue().getTextValue("vasc.dialog.edit.message",beanValue)); Object result = dialog.openDialog(); logger.finest("OPEN closed : "+result); if(result==null) { @@ -163,10 +173,17 @@ public class SwingVascViewRenderer implements VascViewRenderer { } public void renderDelete(Object rowBean) throws Exception { + String beanValue = rowBean.toString(); + if (table.getUIIdentifierVascTableColomn()!=null) { + beanValue = ""+table.getUIIdentifierVascTableColomn().getVascColumnValue().getValue(table.getUIIdentifierVascTableColomn(), rowBean); + if (beanValue.length()>30) { + beanValue=beanValue.substring(0, 30); + } + } int response = JOptionPane.showOptionDialog( parent // Center in window. - , "Delete "+rowBean // Message - , "Delete" // Title in titlebar + , table.getVascTextValue().getTextValue("vasc.dialog.delete.message",beanValue) // Message + , table.getVascTextValue().getTextValue("vasc.dialog.delete.title") // Title in titlebar , JOptionPane.YES_NO_OPTION // Option type , JOptionPane.PLAIN_MESSAGE // messageType , null // Icon (none) @@ -184,18 +201,16 @@ public class SwingVascViewRenderer implements VascViewRenderer { class SwingEditDialog extends JDialog { + private static final long serialVersionUID = 10L; 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) throws Exception { super(); this.headerText = headerText; - this.title = title; this.bean = bean; - setTitle(table.getVascTextValue().getTextValue(title)); setModal(true); @@ -276,7 +291,7 @@ public class SwingVascViewRenderer implements VascViewRenderer { body.add(valueLabel); } else { VascUIComponent comp = c.getVascUIComponent(); - VascValueModel model = new VascValueModel(); + VascValueModel model = new VascValueModel(table); model.setValue(c.getVascColumnValue().getValue(c, bean)); model.addListener(new VascColumnValueModelListener(c,bean)); comp.createComponent(table, model, body); @@ -295,9 +310,9 @@ public class SwingVascViewRenderer implements VascViewRenderer { saveButton.setToolTipText(table.getVascTextValue().getTextValue("vasc.dialog.save.tooltip")); saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { - //if(hasRecordError()) { - // return; - //} + if(table.getVascTableController().setUIComponentsBeanErrors(table, bean)) { + return; + } result = bean; setVisible(false); } @@ -347,8 +362,7 @@ public class SwingVascViewRenderer implements VascViewRenderer { 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); + table.getVascTableController().handleException(e, table); } finally { if (out!=null) { out.close(); @@ -427,7 +441,7 @@ public class SwingVascViewRenderer implements VascViewRenderer { JPanel optionPanel = new JPanel(); //top.setBackground(Color.GREEN); for(VascUserOption option:table.getUserOptions()) { - Object obj = option.createUserOptionRenderer(table); + option.createUserOptionRenderer(table); } //top.add(header,BorderLayout.NORTH); @@ -489,6 +503,7 @@ public class SwingVascViewRenderer implements VascViewRenderer { } } class JComponentTableCellRenderer extends DefaultTableCellRenderer { + private static final long serialVersionUID = 10L; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,boolean hasFocus, int row, int column) { VascTableColumn c = (VascTableColumn)value; setText(c.getVascTable().getVascTextValue().getTextValue(c.getName())); @@ -508,7 +523,6 @@ public class SwingVascViewRenderer implements VascViewRenderer { setFont(header.getFont()); } } - //setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); setBorder(UIManager.getBorder("TableHeader.cellBorder")); return this; } @@ -540,7 +554,7 @@ public class SwingVascViewRenderer implements VascViewRenderer { } public void actionPerformed(ActionEvent event) { - logger.info("Row Action"); + logger.fine("Row Action"); try { action.doRowAction(table, table.getSelectedObject()); } catch (Exception e) { @@ -558,7 +572,7 @@ public class SwingVascViewRenderer implements VascViewRenderer { } public void actionPerformed(ActionEvent event) { - logger.info("Global Action"); + logger.fine("Global Action"); try { action.doGlobalAction(table); } catch (Exception e) { @@ -568,6 +582,7 @@ public class SwingVascViewRenderer implements VascViewRenderer { } class VascColumnModel extends AbstractTableModel implements VascEventListener { + private static final long serialVersionUID = 10L; public void vascEvent(VascEventType e,Object o) { if (e==VascEventType.DATA_UPDATE) { @@ -623,7 +638,6 @@ public class SwingVascViewRenderer implements VascViewRenderer { return ""+vtc.getVascColumnValue().getValue(vtc,bean); } } catch (Exception e) { - e.printStackTrace(); return "Error"; } } @@ -637,15 +651,6 @@ public class SwingVascViewRenderer implements VascViewRenderer { */ class SpringUtilities { - /** - * A debugging utility that prints to stdout the component's minimum, - * preferred, and maximum sizes. - */ - public static void printSizes(Component c) { - System.out.println("minimumSize = " + c.getMinimumSize()); - System.out.println("preferredSize = " + c.getPreferredSize()); - System.out.println("maximumSize = " + c.getMaximumSize()); - } /** * Aligns the first rows*cols components of diff --git a/src/com/idcanet/vasc/impl/swing/ui/SwingDate.java b/src/com/idcanet/vasc/impl/swing/ui/SwingDate.java index 8ad232a..43ab3fc 100644 --- a/src/com/idcanet/vasc/impl/swing/ui/SwingDate.java +++ b/src/com/idcanet/vasc/impl/swing/ui/SwingDate.java @@ -26,6 +26,7 @@ package com.idcanet.vasc.impl.swing.ui; +import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Date; @@ -46,12 +47,41 @@ import com.michaelbaranov.microba.calendar.DatePicker; */ public class SwingDate extends AbstractVascUIComponent { + private DatePicker datePicker = null; + private Color orgBackgroundColor = null; + public Object createComponent(VascTable table,VascValueModel model,Object gui) throws Exception { - DatePicker def = new DatePicker(); - def.setDate((Date)model.getValue()); - ((JComponent)gui).add(def); - def.addActionListener(new SelectActionListener2(model)); - return def; + datePicker = new DatePicker(); + orgBackgroundColor = datePicker.getBackground(); + datePicker.setDate((Date)model.getValue()); + ((JComponent)gui).add(datePicker); + datePicker.addActionListener(new SelectActionListener2(model)); + return datePicker; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText() + */ + public String getErrorText() { + if (datePicker==null) { + return null; + } + return datePicker.getToolTipText(); + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String) + */ + public void setErrorText(String text) { + if (datePicker==null) { + return; + } + datePicker.setToolTipText(text); + if (text==null) { + datePicker.setBackground(orgBackgroundColor); + } else { + datePicker.setBackground(Color.RED); + } } } class SelectActionListener2 implements ActionListener { diff --git a/src/com/idcanet/vasc/impl/swing/ui/SwingList.java b/src/com/idcanet/vasc/impl/swing/ui/SwingList.java index bca7ce1..2a09a5e 100644 --- a/src/com/idcanet/vasc/impl/swing/ui/SwingList.java +++ b/src/com/idcanet/vasc/impl/swing/ui/SwingList.java @@ -26,6 +26,7 @@ package com.idcanet.vasc.impl.swing.ui; +import java.awt.Color; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -50,44 +51,75 @@ import com.idcanet.vasc.core.ui.VascValueModel; */ public class SwingList extends AbstractVascUIComponent { - public Object createComponent(VascTable table,final VascValueModel model,Object gui) throws Exception { - + private JComboBox comboBox = null; + private Color orgBackgroundColor = null; + + public Object createComponent(VascTable table,final VascValueModel model,Object gui) throws Exception { VascList l = (VascList)getWrapper(); - JComboBox def; if (l.getVascSelectItemModel()==null) { - def = new JComboBox(); + comboBox = new JComboBox(); } else { - def = new JComboBox(l.getVascSelectItemModel().getVascSelectItems().toArray()); + comboBox = new JComboBox(l.getVascSelectItemModel().getVascSelectItems().toArray()); } - ((JComponent)gui).add(def); - def.setRenderer(new MyCellRenderer()); - def.addActionListener(new ActionListener() { + orgBackgroundColor = comboBox.getBackground(); + ((JComponent)gui).add(comboBox); + comboBox.setRenderer(new MyCellRenderer()); + comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VascSelectItem i = (VascSelectItem)((JComboBox)e.getSource()).getSelectedItem(); model.setValue(i.getValue()); } }); - if (model.getValue()==null) { - return def; - } // set default !! - for (int i=0;i0) { + // else select the top one. + comboBox.setSelectedIndex(0); + } + return comboBox; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText() + */ + public String getErrorText() { + if (comboBox==null) { + return null; + } + return comboBox.getToolTipText(); + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String) + */ + public void setErrorText(String text) { + if (comboBox==null) { + return; + } + comboBox.setToolTipText(text); + if (text==null) { + comboBox.setBackground(orgBackgroundColor); + } else { + comboBox.setBackground(Color.RED); + } } } class MyCellRenderer extends JLabel implements ListCellRenderer { + private static final long serialVersionUID = 10L; + public MyCellRenderer() { setOpaque(true); } diff --git a/src/com/idcanet/vasc/impl/swing/ui/SwingTextField.java b/src/com/idcanet/vasc/impl/swing/ui/SwingTextField.java index f2e0684..57a6d8b 100644 --- a/src/com/idcanet/vasc/impl/swing/ui/SwingTextField.java +++ b/src/com/idcanet/vasc/impl/swing/ui/SwingTextField.java @@ -26,6 +26,8 @@ package com.idcanet.vasc.impl.swing.ui; +import java.awt.Color; + import javax.swing.JComponent; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; @@ -33,7 +35,6 @@ import javax.swing.event.DocumentListener; import com.idcanet.vasc.core.VascTable; import com.idcanet.vasc.core.ui.AbstractVascUIComponent; -import com.idcanet.vasc.core.ui.VascUIComponent; import com.idcanet.vasc.core.ui.VascValueModel; @@ -44,22 +45,52 @@ import com.idcanet.vasc.core.ui.VascValueModel; */ public class SwingTextField extends AbstractVascUIComponent { - public Object createComponent(VascTable table,VascValueModel model,Object gui) throws Exception { - JTextField def = new JTextField(); - def.setText(""+model.getValue()); - ((JComponent)gui).add(def); - def.getDocument().addDocumentListener(new TextListener(model) ); - return def; - } + private JTextField textField = null; + private Color orgBackgroundColor = null; + public Object createComponent(VascTable table,VascValueModel model,Object gui) throws Exception { + textField = new JTextField(); + orgBackgroundColor = textField.getBackground(); + textField.setText(""+model.getValue()); + ((JComponent)gui).add(textField); + textField.getDocument().addDocumentListener(new TextListener(model,table)); + return textField; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText() + */ + public String getErrorText() { + if (textField==null) { + return null; + } + return textField.getToolTipText(); + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String) + */ + public void setErrorText(String text) { + if (textField==null) { + return; + } + textField.setToolTipText(text); + if (text==null) { + textField.setBackground(orgBackgroundColor); + } else { + textField.setBackground(Color.RED); + } + } } class TextListener implements DocumentListener { private VascValueModel model = null; + private VascTable table = null; - public TextListener(VascValueModel model) { + public TextListener(VascValueModel model,VascTable table) { this.model=model; + this.table=table; } /** @@ -86,10 +117,9 @@ class TextListener implements DocumentListener { public void update(DocumentEvent event) { try { String value = event.getDocument().getText(0, event.getDocument().getLength()); - System.out.println("Setting value: "+value); model.setValue(value); } catch (Exception ee) { - ee.printStackTrace(); + table.getVascTableController().handleException(ee, table); } } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/swing/ui/SwingToggle.java b/src/com/idcanet/vasc/impl/swing/ui/SwingToggle.java index 5f8614d..cf46f0d 100644 --- a/src/com/idcanet/vasc/impl/swing/ui/SwingToggle.java +++ b/src/com/idcanet/vasc/impl/swing/ui/SwingToggle.java @@ -26,6 +26,7 @@ package com.idcanet.vasc.impl.swing.ui; +import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -45,12 +46,41 @@ import com.idcanet.vasc.core.ui.VascValueModel; */ public class SwingToggle extends AbstractVascUIComponent { + private JCheckBox checkBox = null; + private Color orgBackgroundColor = null; + public Object createComponent(VascTable table,VascValueModel model,Object gui) throws Exception { - JCheckBox def = new JCheckBox(); - def.setSelected((Boolean)model.getValue()); - ((JComponent)gui).add(def); - def.addActionListener(new SelectActionListener(model)); - return def; + checkBox = new JCheckBox(); + orgBackgroundColor = checkBox.getBackground(); + checkBox.setSelected((Boolean)model.getValue()); + ((JComponent)gui).add(checkBox); + checkBox.addActionListener(new SelectActionListener(model)); + return checkBox; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText() + */ + public String getErrorText() { + if (checkBox==null) { + return null; + } + return checkBox.getToolTipText(); + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String) + */ + public void setErrorText(String text) { + if (checkBox==null) { + return; + } + checkBox.setToolTipText(text); + if (text==null) { + checkBox.setBackground(orgBackgroundColor); + } else { + checkBox.setBackground(Color.RED); + } } } class SelectActionListener implements ActionListener { diff --git a/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java b/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java index 7cde7ba..66f2b98 100644 --- a/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java +++ b/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java @@ -26,13 +26,11 @@ package com.idcanet.vasc.impl.swt; -import java.awt.TextField; import java.io.FileOutputStream; import java.io.OutputStream; import java.util.logging.Level; import java.util.logging.Logger; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.jface.viewers.IStructuredContentProvider; @@ -137,7 +135,7 @@ public class SwtVascViewRenderer implements VascViewRenderer { public void renderEdit(Object object) throws Exception { - logger.info("Rending Edit View"); + logger.fine("Rending Edit View"); table.getVascTableController().initEditObject(table, object); SwtVascEditDialog dialog = new SwtVascEditDialog(Display.getCurrent().getActiveShell(),table,object,"Vasc Edit","Edit"); @@ -159,21 +157,16 @@ public class SwtVascViewRenderer implements VascViewRenderer { path = table.getVascTextValue().getTextValue(path); - logger.info("Loading image: "+path); - //System.out.println("==== 1"); + logger.fine("Loading image: "+path); ImageDescriptor result = ImageDescriptor.createFromFile(path.getClass(), path); result = ImageDescriptor.createFromFile(SwingImageHelper.class, 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+"'"); @@ -482,7 +475,7 @@ public class SwtVascViewRenderer implements VascViewRenderer { */ @Override public void widgetSelected(SelectionEvent event) { - logger.info("Global Action"); + logger.fine("Global Action"); try { action.doGlobalAction(table); } catch (Exception e) { @@ -521,7 +514,7 @@ public class SwtVascViewRenderer implements VascViewRenderer { */ public void widgetSelected(SelectionEvent e) { Object data = e.item.getData(); - logger.info("Slecting data: "+data); + logger.fine("Slecting data: "+data); table.setSelectedObject(data); } @@ -625,7 +618,7 @@ public class SwtVascViewRenderer implements VascViewRenderer { */ @Override public void widgetSelected(SelectionEvent event) { - logger.info("Row Action"); + logger.fine("Row Action"); try { action.doRowAction(table, table.getSelectedObject()); } catch (Exception e) {