[svn r289] implemented annotation validators, and removed all info logging
This commit is contained in:
parent
78a76fa12e
commit
fdd0af9597
40
src/com/idcanet/vasc/core/VascExceptionListener.java
Normal file
40
src/com/idcanet/vasc/core/VascExceptionListener.java
Normal file
|
@ -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);
|
||||
}
|
|
@ -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<VascUserOption> userOptions = null;
|
||||
private String helpId = null;
|
||||
private VascTableController vascTableController = null;
|
||||
private Map<Class,Class> uiComponents = null;
|
||||
private Map<Class<?>,Class<?>> uiComponents = null;
|
||||
private VascTableColumn UIIdentifierVascTableColomn = null;
|
||||
|
||||
public VascTable() {
|
||||
tableColumns = new ArrayList<VascTableColumn>(6);
|
||||
|
@ -71,7 +71,7 @@ public class VascTable {
|
|||
globalActions = new ArrayList<GlobalVascAction>(6);
|
||||
tableData = new ArrayList<Object>(6);
|
||||
userOptions = new ArrayList<VascUserOption>(6);
|
||||
uiComponents = new HashMap<Class,Class>(6);
|
||||
uiComponents = new HashMap<Class<?>,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<VascValueModelListener> listeners = null;
|
||||
private VascTable table = null;
|
||||
|
||||
public VascValueModel() {
|
||||
public VascValueModel(VascTable table) {
|
||||
listeners = new ArrayList<VascValueModelListener>(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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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<VascEventListener> eventListeners = null;
|
||||
private List<VascExceptionListener> exceptionListeners = null;
|
||||
|
||||
public DefaultVascTableController() {
|
||||
logger = Logger.getLogger(DefaultVascTableController.class.getName());
|
||||
eventListeners = new ArrayList<VascEventListener>(2);
|
||||
exceptionListeners = new ArrayList<VascExceptionListener>(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<VascEventListener> eventListeners = new ArrayList<VascEventListener>(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);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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 <code>rows</code>*<code>cols</code> components of
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;i<def.getModel().getSize();i++) {
|
||||
Object o = def.getModel().getElementAt(i);
|
||||
VascSelectItem i2 = (VascSelectItem)o;
|
||||
if ( model.getValue().equals(i2.getValue()) ) {
|
||||
def.setSelectedItem(i2);
|
||||
return def;
|
||||
if (model.getValue()!=null) {
|
||||
for (int i=0;i<comboBox.getModel().getSize();i++) {
|
||||
Object o = comboBox.getModel().getElementAt(i);
|
||||
VascSelectItem i2 = (VascSelectItem)o;
|
||||
if ( model.getValue().equals(i2.getValue()) ) {
|
||||
comboBox.setSelectedItem(i2);
|
||||
return comboBox;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return def;
|
||||
if (comboBox.getModel().getSize()>0) {
|
||||
// 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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue