2
0
Fork 0

[svn r283] added date and boolean editors to swing

This commit is contained in:
willemc 2007-09-21 02:42:04 +02:00
parent 9218ea6c8e
commit 78a5744a2a
10 changed files with 204 additions and 5 deletions

View file

@ -15,5 +15,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="lib/idcanet-fff-bin.jar"/>
<classpathentry kind="lib" path="lib/hibernate-annotations.jar"/>
<classpathentry kind="lib" path="lib/microba-0.4.2-bin.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

BIN
lib/microba-0.4.2-bin.jar Normal file

Binary file not shown.

View file

@ -34,7 +34,7 @@ package com.idcanet.vasc.core;
*/
public interface VascEventListener {
public enum VascEventType { DATA_UPDATE,OPTION_UPDATE }
public enum VascEventType { DATA_UPDATE,OPTION_UPDATE,CLOSE_WINDOW }
public void vascEvent(VascEventType e,Object o);

View file

@ -27,6 +27,7 @@
package com.idcanet.vasc.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -37,7 +38,9 @@ import com.idcanet.vasc.core.VascTable;
import com.idcanet.vasc.core.VascTableController;
import com.idcanet.vasc.core.column.VascAnnotationTableColumn;
import com.idcanet.vasc.core.column.VascTableColumn;
import com.idcanet.vasc.core.ui.VascDate;
import com.idcanet.vasc.core.ui.VascTextField;
import com.idcanet.vasc.core.ui.VascToggle;
import com.idcanet.vasc.impl.column.BeanPropertyVascColumnValue;
/**
@ -91,7 +94,13 @@ public class DefaultVascTableController implements VascTableController {
}
}
if (c.getVascUIComponent()==null) {
c.setVascUIComponent(new VascTextField());
if (c.getDefaultValue() instanceof Boolean) {
c.setVascUIComponent(new VascToggle());
} else if (c.getDefaultValue() instanceof Date) {
c.setVascUIComponent(new VascDate());
} else {
c.setVascUIComponent(new VascTextField());
}
}
if (c.getVascColumnRenderer()==null) {
//c.setVascColumnRenderer(new DefaultVascColumnRenderer());

View file

@ -75,12 +75,16 @@ 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.VascColumnValueModelListener;
import com.idcanet.vasc.core.ui.VascDate;
import com.idcanet.vasc.core.ui.VascList;
import com.idcanet.vasc.core.ui.VascTextField;
import com.idcanet.vasc.core.ui.VascToggle;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
import com.idcanet.vasc.impl.swing.ui.SwingDate;
import com.idcanet.vasc.impl.swing.ui.SwingList;
import com.idcanet.vasc.impl.swing.ui.SwingTextField;
import com.idcanet.vasc.impl.swing.ui.SwingToggle;
/**
*
@ -112,7 +116,9 @@ public class SwingVascViewRenderer implements VascViewRenderer {
table.getVascTableController().refreshData(table);
table.putUIComponent(VascTextField.class, SwingTextField.class);
table.putUIComponent(VascList.class, SwingList.class);
table.putUIComponent(VascToggle.class, SwingToggle.class);
table.putUIComponent(VascDate.class, SwingDate.class);
this.table=table;
}

View file

@ -0,0 +1,71 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.impl.swing.ui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import javax.swing.JComponent;
import com.idcanet.vasc.core.VascTable;
import com.idcanet.vasc.core.ui.AbstractVascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
import com.michaelbaranov.microba.calendar.DatePicker;
/**
*
*
* @author Willem Cazander
* @version 1.0 Sep 21, 2007
*/
public class SwingDate extends AbstractVascUIComponent {
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;
}
}
class SelectActionListener2 implements ActionListener {
private VascValueModel model;
public SelectActionListener2(VascValueModel model) {
this.model=model;
}
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
Date value = ((DatePicker)e.getSource()).getDate();
model.setValue(value);
}
}

View file

@ -59,8 +59,7 @@ public class SwingList extends AbstractVascUIComponent {
} else {
def = new JComboBox(l.getVascSelectItemModel().getVascSelectItems().toArray());
}
((JComponent)gui).add(def);
((JComponent)gui).add(def);
def.setRenderer(new MyCellRenderer());
def.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@ -68,6 +67,21 @@ public class SwingList extends AbstractVascUIComponent {
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;
}
}
return def;
}
}

View file

@ -0,0 +1,70 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.impl.swing.ui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import com.idcanet.vasc.core.VascTable;
import com.idcanet.vasc.core.ui.AbstractVascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
/**
*
*
* @author Willem Cazander
* @version 1.0 Sep 21, 2007
*/
public class SwingToggle extends AbstractVascUIComponent {
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;
}
}
class SelectActionListener implements ActionListener {
private VascValueModel model;
public SelectActionListener(VascValueModel model) {
this.model=model;
}
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
boolean value = ((JCheckBox)e.getSource()).isSelected();
model.setValue(value);
}
}

View file

@ -26,6 +26,8 @@
package com.idcanet.vasc;
import java.util.Date;
import com.idcanet.vasc.core.VascTable;
import com.idcanet.vasc.core.column.VascAnnotationTableColumn;
import com.idcanet.vasc.core.column.VascTableColumn;
@ -108,6 +110,14 @@ public class TestTable {
column = new VascAnnotationTableColumn("description");
table.addTableColumns(column);
column = new VascAnnotationTableColumn("active");
column.setDefaultValue(true);
table.addTableColumns(column);
column = new VascAnnotationTableColumn("date");
column.setDefaultValue(new Date());
table.addTableColumns(column);
column = new VascAnnotationTableColumn("testModel");
VascList list = new VascList();
list.setVascSelectItemModel(data);

View file

@ -53,6 +53,7 @@ public class TestModel {
private String name = null;
private String description = null;
private Float price = null;
private Boolean active = null;
private Date date = null;
private TestModel testModel = null;
@ -131,4 +132,21 @@ public class TestModel {
public void setTestModel(TestModel testModel) {
this.testModel = testModel;
}
/**
* @return the active
*/
public Boolean getActive() {
return active;
}
/**
* @param active the active to set
*/
public void setActive(Boolean active) {
this.active = active;
}
}