2
0
Fork 0

[svn r262] made i18n work, added some images, made preperments for the user options

This commit is contained in:
willemc 2007-08-03 04:09:01 +02:00
parent cb8d6bc334
commit 0d5312462c
27 changed files with 468 additions and 163 deletions

View file

@ -114,6 +114,14 @@ public class VascAnnotationParser {
return getValue(beanClass,VascDefaultValue.class,null);
}
public String getVascImage(Class beanClass,String property) {
return (String)getValue(beanClass,VascImage.class,property);
}
public String getVascImage(Class beanClass) {
return (String)getValue(beanClass,VascImage.class,null);
}
/**
* No oop code here...refactor at some point in time
*
@ -129,7 +137,11 @@ public class VascAnnotationParser {
Object result = null;
if(property==null) {
result = doAnnotation(beanClass.getAnnotation(annotationType));
Annotation anno = beanClass.getAnnotation(annotationType);
if (anno==null) {
return null; // no annotion avaible
}
result = doAnnotation(anno);
if(result!=null) {
return result;
}
@ -219,6 +231,13 @@ public class VascAnnotationParser {
VascColumnWidth c = (VascColumnWidth)b;
return c.width();
}
if (a.equals(VascImage.class)) {
VascImage c = (VascImage)b;
if("".equals(c.image()) | "null".equals(c.image())) {
return null;
}
return c.image();
}
return null;
}

View file

@ -0,0 +1,51 @@
/*
* Copyright 2004-2006 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.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Sets the VascImage property
*
* @author Willem Cazander
* @version 1.0 May 27, 2006
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface VascImage {
/**
* The resource or key of the Image, default to "null"
* @see com.idcanet.i18n.I18nAnnotationParser#getI18nLabelKey(Class, String)
* @return The key of the ToolTip
*/
String image() default "null";
}

View file

@ -0,0 +1,57 @@
/*
* 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.HashMap;
import java.util.Map;
import java.util.Set;
/**
*
* @author Willem Cazander
* @version 1.0 Aug 2, 2007
*/
abstract public class AbstractVascDataSource implements VascDataSource {
Map<String,Object> parameters = null;
public AbstractVascDataSource() {
parameters = new HashMap<String,Object>(10);
}
public void setDataParameter(String key,Object data) {
parameters.put(key,data);
}
public Object getDataParameter(String key) {
return parameters.get(key);
}
public Set<String> getDataParameterKeys() {
return parameters.keySet();
}
}

View file

@ -27,8 +27,7 @@
package com.idcanet.vasc.core;
import java.util.List;
import com.idcanet.xtes.xpql.query.Query;
import java.util.Set;
/**
@ -38,7 +37,11 @@ import com.idcanet.xtes.xpql.query.Query;
*/
public interface VascDataSource {
public List<Object> executeQuery(Query query) throws Exception;
public void setDataParameter(String key,Object data);
public Object getDataParameter(String key);
public Set<String> getDataParameterKeys();
public List<Object> execute() throws Exception;
public void persist(Object object) throws Exception;

View file

@ -33,7 +33,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.xtes.xpql.query.Query;
/**
*
@ -44,14 +43,13 @@ public class VascTable {
private String name = null;
private String headerName = null;
private String description = null;
private String toolTip = null;
private String headerImage = null;
private String headerToolTip = null;
private List<VascTableColumn> tableColumns = null;
private List<RowVascAction> rowActions = null;
private List<ColumnVascAction> columnActions = null;
private List<GlobalVascAction> globalActions = null;
private VascDataSource vascDataSource = null;
private Query query = null;
private List<Object> tableData = null;
private Object selectedObject = null;
private VascRecordCreator vascRecordCreator = null;
@ -84,19 +82,6 @@ public class VascTable {
columnActions.add(columnAction);
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @return the globalActions
@ -140,20 +125,6 @@ public class VascTable {
this.name = name;
}
/**
* @return the query
*/
public Query getQuery() {
return query;
}
/**
* @param query the query to set
*/
public void setQuery(Query query) {
this.query = query;
}
/**
* @return the rowActions
*/
@ -216,19 +187,6 @@ public class VascTable {
this.tableData = tableData;
}
/**
* @return the toolTip
*/
public String getToolTip() {
return toolTip;
}
/**
* @param toolTip the toolTip to set
*/
public void setToolTip(String toolTip) {
this.toolTip = toolTip;
}
/**
* @return the userOptions
@ -327,6 +285,32 @@ public class VascTable {
public void setVascTableController(VascTableController vascTableController) {
this.vascTableController = vascTableController;
}
/**
* @return the headerImage
*/
public String getHeaderImage() {
return headerImage;
}
/**
* @param headerImage the headerImage to set
*/
public void setHeaderImage(String headerImage) {
this.headerImage = headerImage;
}
/**
* @return the headerToolTip
*/
public String getHeaderToolTip() {
return headerToolTip;
}
/**
* @param headerToolTip the headerToolTip to set
*/
public void setHeaderToolTip(String headerToolTip) {
this.headerToolTip = headerToolTip;
}
}

View file

@ -33,7 +33,7 @@ package com.idcanet.vasc.core;
* @version 1.0 Mar 21, 2007
*/
public interface VascTextValue {
public String getTextValue(String text);
public String getTextValue(String key,Object...params);
}

View file

@ -36,13 +36,15 @@ import com.idcanet.vasc.core.column.VascTableColumn;
*/
public interface VascViewRenderer {
public void renderView(VascTable table) throws Exception;
public void initTable(VascTable table) throws Exception;
public void renderView() throws Exception;
public void renderEdit(VascTable table,Object rowBean) throws Exception;
public void renderEdit(Object rowBean) throws Exception;
public void renderDelete(VascTable table,Object rowBean) throws Exception;
public void renderDelete(Object rowBean) throws Exception;
public void renderExport(VascTable table,VascDataExporter exporter) throws Exception;
public void renderExport(VascDataExporter exporter) throws Exception;
public Object defaultColumnEditor(VascTableColumn column,Object bean,Object gui) throws Exception;

View file

@ -86,6 +86,9 @@ public class DefaultVascTableController implements VascTableController {
if (c.getVascColumnValue()==null) {
c.setVascColumnValue(new BeanPropertyVascColumnValue(column.getBeanProperty()));
}
if (c.getImage()==null) {
c.setImage(vap.getVascImage(table.getVascRecordCreator().getObjectClass(),column.getBeanProperty()));
}
}
if (c.getVascColumnEditor()==null) {
c.setVascColumnEditor(new DefaultVascColumnEditor());
@ -146,7 +149,8 @@ public class DefaultVascTableController implements VascTableController {
* @see com.idcanet.vasc.core.VascTableController#refreshData()
*/
public void refreshData(VascTable table) throws Exception {
table.setTableData(table.getVascDataSource().executeQuery(table.getQuery()));
table.setTableData(table.getVascDataSource().execute());
fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, null);
}
public void handleException(Exception e,VascTable table) {

View file

@ -35,7 +35,11 @@ import com.idcanet.vasc.core.VascTextValue;
*/
public class DefaultVascTextValue implements VascTextValue {
public String getTextValue(String text) {
public String getKeyMapping(String key) {
return key;
}
public String getTextValue(String text,Object...params) {
return text;
}
}

View file

@ -38,12 +38,12 @@ import com.idcanet.vasc.core.actions.RowVascAction;
public class AddRowAction extends AbstractVascAction implements RowVascAction {
public AddRowAction() {
setName("generic.crud.add");
setToolTip("generic.toolTip");
setImage("/META-INF/images/silk/png/table_add.png");
setName("vasc.action.add.name");
setToolTip("vasc.action.add.tooltip");
setImage("vasc.action.add.image");
}
public void doRowAction(VascTable table,Object rowObject) throws Exception {
table.getVascViewRenderer().renderEdit(table,table.getVascRecordCreator().newRecord(table));
table.getVascViewRenderer().renderEdit(table.getVascRecordCreator().newRecord(table));
}
}

View file

@ -43,18 +43,18 @@ import com.idcanet.vasc.core.column.VascTableColumn;
public class CSVExportGlobalAction extends AbstractVascAction implements GlobalVascAction,VascDataExporter {
public CSVExportGlobalAction() {
setName("generic.crud.export.csv.name");
setToolTip("generic.crud.export.csv.tooltip");
setImage("/META-INF/images/silk/png/page_white_excel.png");
setName("vasc.action.csv.name");
setToolTip("vasc.action.csv.tooltip");
setImage("vasc.action.csv.image");
}
public void doGlobalAction(VascTable table) throws Exception {
table.getVascViewRenderer().renderExport(table,this);
table.getVascViewRenderer().renderExport(this);
}
public void doExport(OutputStream out,VascTable table) throws Exception {
PrintWriter p = new PrintWriter(out);
p.write("# csv file\n");
p.write("# csv\n");
for (VascTableColumn c:table.getTableColumns()) {
p.write(c.getName()+"\t");
}

View file

@ -38,15 +38,15 @@ import com.idcanet.vasc.core.actions.RowVascAction;
public class DeleteRowAction extends AbstractVascAction implements RowVascAction {
public DeleteRowAction() {
setName("generic.crud.delete.name");
setToolTip("generic.crud.delete.tooltip");
setImage("/META-INF/images/silk/png/table_delete.png");
setName("vasc.action.del.name");
setToolTip("vasc.action.del.tooltip");
setImage("vasc.action.del.image");
}
public void doRowAction(VascTable table,Object rowObject) throws Exception {
if (rowObject==null) {
return;
}
table.getVascViewRenderer().renderDelete(table,rowObject);
table.getVascViewRenderer().renderDelete(rowObject);
}
}

View file

@ -38,9 +38,9 @@ import com.idcanet.vasc.core.actions.RowVascAction;
public class EditRowAction extends AbstractVascAction implements RowVascAction {
public EditRowAction() {
setName("generic.crud.edit");
setToolTip("generic.crud.edit.toolTip");
setImage("/META-INF/images/silk/png/table_edit.png");
setName("vasc.action.edit.name");
setToolTip("vasc.action.edit.tooltip");
setImage("vasc.action.edit.image");
}
@ -48,6 +48,6 @@ public class EditRowAction extends AbstractVascAction implements RowVascAction {
if (rowObject==null) {
return;
}
table.getVascViewRenderer().renderEdit(table,rowObject);
table.getVascViewRenderer().renderEdit(rowObject);
}
}

View file

@ -38,13 +38,13 @@ import com.idcanet.vasc.core.actions.GlobalVascAction;
public class RefreshDataGlobalAction extends AbstractVascAction implements GlobalVascAction {
public RefreshDataGlobalAction() {
setName("generic.refresh");
setToolTip("generic.crud.refresh.tooltip");
setImage("/META-INF/images/silk/png/table_refresh.png");
setName("vasc.action.refresh.name");
setToolTip("vasc.action.refresh.tooltip");
setImage("vasc.action.refresh.image");
}
public void doGlobalAction(VascTable table) throws Exception {
table.getVascTableController().refreshData(table);
table.getVascTableController().refreshData(table); // this wil also fire the event
}
}

View file

@ -43,13 +43,13 @@ import com.idcanet.vasc.core.column.VascTableColumn;
public class XMLExportGlobalAction extends AbstractVascAction implements GlobalVascAction,VascDataExporter {
public XMLExportGlobalAction() {
setName("generic.crud.export.xml.name");
setToolTip("generic.crud.export.xml.tooltip");
setImage("/META-INF/images/silk/png/page_white_excel.png");
setName("vasc.action.xml.name");
setToolTip("vasc.action.xml.tooltip");
setImage("vasc.action.xml.image");
}
public void doGlobalAction(VascTable table) throws Exception {
table.getVascViewRenderer().renderExport(table,this);
table.getVascViewRenderer().renderExport(this);
}
public void doExport(OutputStream out,VascTable table) throws Exception {

View file

@ -32,6 +32,7 @@ import java.util.logging.Level;
import org.hibernate.Query;
import com.idcanet.serv5.services.hibernate3.Hibernate3Factory;
import com.idcanet.vasc.core.AbstractVascDataSource;
import com.idcanet.vasc.core.VascDataSource;
import com.idcanet.xtes.xpql.query.QueryParameterValue;
@ -40,18 +41,21 @@ import com.idcanet.xtes.xpql.query.QueryParameterValue;
* @author Willem Cazander
* @version 1.0 Mar 21, 2007
*/
public class Serv5HibernateVascDataSource implements VascDataSource {
public class Serv5HibernateVascDataSource extends AbstractVascDataSource {
private String session = null;
private com.idcanet.xtes.xpql.query.Query query = null;
public Serv5HibernateVascDataSource() {
}
public Serv5HibernateVascDataSource(String session) {
public Serv5HibernateVascDataSource(String session,com.idcanet.xtes.xpql.query.Query query) {
setSession(session);
setQuery(query);
}
public List<Object> executeQuery(com.idcanet.xtes.xpql.query.Query query) throws Exception {
public List<Object> execute() throws Exception {
try {
Query q = Hibernate3Factory.getSession(getSession()).createQuery(query.toPreparedSQL(query));
@ -101,6 +105,7 @@ public class Serv5HibernateVascDataSource implements VascDataSource {
public String getSession() {
return session;
}
/**
* @param session the session to set
*/
@ -108,6 +113,17 @@ public class Serv5HibernateVascDataSource implements VascDataSource {
this.session = session;
}
/**
* @return the query
*/
public com.idcanet.xtes.xpql.query.Query getQuery() {
return query;
}
/**
* @param query the query to set
*/
public void setQuery(com.idcanet.xtes.xpql.query.Query query) {
this.query = query;
}
}

View file

@ -31,6 +31,8 @@ import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileOutputStream;
@ -38,6 +40,7 @@ import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
@ -89,6 +92,21 @@ public class SwingVascViewRenderer implements VascViewRenderer {
this.parent=parent;
}
public void initTable(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;
}
/**
* @see com.idcanet.vasc.core.VascViewRenderer#defaultColumnEditor(com.idcanet.vasc.core.column.VascTableColumn, java.lang.Object, java.lang.Object)
*/
@ -101,7 +119,10 @@ public class SwingVascViewRenderer implements VascViewRenderer {
}
public ImageIcon getImageIcon(String imageResource) {
return SwingImageHelper.getImageIcon(imageResource);
/// TODO hack beter
String key = table.getVascTextValue().getTextValue(imageResource);
return SwingImageHelper.getImageIcon(key);
}
class TextListener implements DocumentListener {
@ -114,21 +135,21 @@ public class SwingVascViewRenderer implements VascViewRenderer {
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) {
@ -161,26 +182,24 @@ public class SwingVascViewRenderer implements VascViewRenderer {
/**
* @see com.idcanet.vasc.core.VascViewRenderer#renderEdit(com.idcanet.vasc.core.VascTable, java.lang.Object)
*/
public void renderEdit(VascTable table, Object rowBean) throws Exception {
public void renderEdit(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);
logger.finest("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 {
public void renderDelete(Object rowBean) throws Exception {
int response = JOptionPane.showOptionDialog(
parent // Center in window.
, "Delete "+rowBean // Message
@ -212,7 +231,7 @@ public class SwingVascViewRenderer implements VascViewRenderer {
this.bean = bean;
setTitle(title);
setTitle(table.getVascTextValue().getTextValue(title));
setModal(true);
JPanel pane = new JPanel();
@ -252,8 +271,9 @@ public class SwingVascViewRenderer implements VascViewRenderer {
public void createHeader(JPanel header) {
JLabel l = new JLabel();
l.setText(headerText);
l.setText(table.getVascTextValue().getTextValue(headerText));
l.setFont(new Font(null,Font.BOLD, 14));
//l.setToolTipText(table.getVascTextValue().getTextValue(headerText));
header.add(l);
}
@ -291,8 +311,9 @@ public class SwingVascViewRenderer implements VascViewRenderer {
public void createFooter(JPanel footer) {
JButton saveButton = new JButton();
saveButton.setIcon(getImageIcon("/META-INF/images/silk/png/tick.png"));
saveButton.setText("generic.save");
saveButton.setIcon(getImageIcon("vasc.dialog.save.image"));
saveButton.setText(table.getVascTextValue().getTextValue("vasc.dialog.save.name"));
saveButton.setToolTipText(table.getVascTextValue().getTextValue("vasc.dialog.save.tooltip"));
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
//if(hasRecordError()) {
@ -305,8 +326,9 @@ public class SwingVascViewRenderer implements VascViewRenderer {
footer.add(saveButton);
JButton cancelButton = new JButton();
cancelButton.setIcon(getImageIcon("/META-INF/images/silk/png/cancel.png"));
cancelButton.setText("generic.cancel");
cancelButton.setIcon(getImageIcon("vasc.dialog.cancel.image"));
cancelButton.setText(table.getVascTextValue().getTextValue("vasc.dialog.cancel.name"));
cancelButton.setToolTipText(table.getVascTextValue().getTextValue("vasc.dialog.cancel.tooltip"));
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
result = null;
@ -323,7 +345,7 @@ public class SwingVascViewRenderer implements VascViewRenderer {
/**
* @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 {
public void renderExport(VascDataExporter exporter) throws Exception {
String fileName = null;
JFileChooser c = new JFileChooser();
@ -359,20 +381,8 @@ public class SwingVascViewRenderer implements VascViewRenderer {
/**
* @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;
public void renderView() throws Exception {
JPanel topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
//topPanel.setBackground(Color.PINK);
@ -397,27 +407,52 @@ public class SwingVascViewRenderer implements VascViewRenderer {
}
private void renderHeader(JComponent parent2) {
JPanel header = new JPanel();
header.setLayout(new BorderLayout());
header.setBackground(Color.WHITE);
header.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
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()));
header.add(l,BorderLayout.WEST);
}
if(table.getHeaderName()!=null) {
JLabel l = new JLabel(table.getVascTextValue().getTextValue(table.getHeaderName()));
l.setFont(new Font(null,Font.BOLD, 14));
parent2.add(l);
l.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
l.setFont(new Font(null,Font.BOLD, 18));
l.setToolTipText(table.getVascTextValue().getTextValue(table.getHeaderToolTip()));
header.add(l,BorderLayout.CENTER);
}
JPanel top = new JPanel();
//top.setBackground(Color.BLUE);
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);
top.add(but);
}
// create options
JPanel optionPanel = new JPanel();
//top.setBackground(Color.GREEN);
for(VascUserOption option:table.getUserOptions()) {
Object obj = option.createUserOptionRenderer(table);
}
//top.add(header,BorderLayout.NORTH);
parent2.setLayout(new BorderLayout());
parent2.add(header,BorderLayout.NORTH);
parent2.add(optionPanel,BorderLayout.CENTER);
parent2.add(top,BorderLayout.EAST);
}
private void renderBody(JComponent parent2) {
@ -487,6 +522,7 @@ public class SwingVascViewRenderer implements VascViewRenderer {
setFont(header.getFont());
}
}
//setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
return this;
}
@ -495,14 +531,17 @@ public class SwingVascViewRenderer implements VascViewRenderer {
private void renderFooter(JComponent parent2) {
logger.finest("Creating footer");
JPanel panel = new JPanel();
for(RowVascAction action:table.getRowActions()) {
JButton but = new JButton();
but.setText(table.getVascTextValue().getTextValue(action.getName()));
but.setToolTipText(table.getVascTextValue().getTextValue(action.getToolTip()));
but.setIcon(getImageIcon(action.getImage()));
but.addActionListener(new RowActionListener(action));
parent2.add(but);
panel.add(but);
}
parent2.setLayout(new BorderLayout());
parent2.add(panel,BorderLayout.WEST);
}
@ -572,7 +611,7 @@ public class SwingVascViewRenderer implements VascViewRenderer {
*/
public Object getValueAt(int rowIndex, int columnIndex) {
Object bean = table.getTableData().get(rowIndex);
System.out.println("Rending column; "+columnIndex+" bean: "+bean);
logger.finer("Rending column; "+columnIndex+" bean: "+bean);
VascTableColumn vtc = table.getTableColumns().get(columnIndex);
if (vtc.getColumnRenderer()!=null) {
//do iets

View file

@ -90,6 +90,20 @@ public class SwtVascViewRenderer implements VascViewRenderer {
this.parent=parent;
}
public void initTable(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;
}
private static final String[] FILTER_NAMES = {
"All Files (*.*)",
"Comma Separated Values Files (*.csv)",
@ -98,7 +112,7 @@ public class SwtVascViewRenderer implements VascViewRenderer {
/** These filter extensions are used to filter which files are displayed. */
private static final String[] FILTER_EXTS = { "*.*","*.csv","*.xls" };
public void renderExport(VascTable table,VascDataExporter exporter) throws Exception {
public void renderExport(VascDataExporter exporter) throws Exception {
FileDialog dlg = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
dlg.setFilterNames(FILTER_NAMES);
dlg.setFilterExtensions(FILTER_EXTS);
@ -121,7 +135,7 @@ public class SwtVascViewRenderer implements VascViewRenderer {
}
}
public void renderEdit(VascTable table,Object object) throws Exception {
public void renderEdit(Object object) throws Exception {
logger.info("Rending Edit View");
table.getVascTableController().initEditObject(table, object);
@ -142,6 +156,9 @@ public class SwtVascViewRenderer implements VascViewRenderer {
public ImageDescriptor getImageDescriptor(String path) {
try {
path = table.getVascTextValue().getTextValue(path);
logger.info("Loading image: "+path);
//System.out.println("==== 1");
ImageDescriptor result = ImageDescriptor.createFromFile(path.getClass(), path);
@ -172,7 +189,7 @@ public class SwtVascViewRenderer implements VascViewRenderer {
}
}
public void renderDelete(VascTable table,Object rowBean) throws Exception {
public void renderDelete(Object rowBean) throws Exception {
}
@ -282,8 +299,9 @@ public class SwtVascViewRenderer implements VascViewRenderer {
new Label(body, SWT.WRAP);
Button saveButton = new Button(body, SWT.NONE);
saveButton.setImage(getImageDescriptor("/META-INF/images/silk/png/tick.png").createImage());
saveButton.setText("generic.save");
saveButton.setImage(getImageDescriptor("vasc.dialog.save.image").createImage());
saveButton.setText(table.getVascTextValue().getTextValue("vasc.dialog.save.name"));
saveButton.setToolTipText(table.getVascTextValue().getTextValue("vasc.dialog.save.tooltip"));
saveButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
//if(hasRecordError()) {
@ -294,8 +312,9 @@ public class SwtVascViewRenderer implements VascViewRenderer {
}
});
Button cancelButton = new Button(body, SWT.NONE);
cancelButton.setImage(getImageDescriptor("/META-INF/images/silk/png/cancel.png").createImage());
cancelButton.setText("generic.cancel");
cancelButton.setImage(getImageDescriptor("vasc.dialog.cancel.image").createImage());
cancelButton.setText(table.getVascTextValue().getTextValue("vasc.dialog.cancel.name"));
cancelButton.setToolTipText(table.getVascTextValue().getTextValue("vasc.dialog.cancel.tooltip"));
cancelButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
result = null;
@ -345,21 +364,7 @@ public class SwtVascViewRenderer implements VascViewRenderer {
}
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;
public void renderView() throws Exception {
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
@ -424,8 +429,8 @@ public class SwtVascViewRenderer implements VascViewRenderer {
ToolBar toolBar = new ToolBar(headerBar, SWT.NONE);
for (GlobalVascAction action:table.getGlobalActions()) {
ToolItem item = new ToolItem(toolBar, SWT.PUSH);
item.setText(action.getName());
item.setToolTipText(action.getToolTip());
item.setText(table.getVascTextValue().getTextValue(action.getName()));
item.setToolTipText(table.getVascTextValue().getTextValue(action.getToolTip()));
if (action.getImage()!=null) {
item.setImage(getImageDescriptor(action.getImage()).createImage());
}
@ -438,6 +443,7 @@ public class SwtVascViewRenderer implements VascViewRenderer {
if(table.getHeaderName()!=null) {
Font headerFont = new Font(header.getDisplay(), "verdana", 16, SWT.BOLD);
Label l = new Label(headerName, SWT.CENTER);
l.setImage(getImageDescriptor(table.getHeaderImage()).createImage());
l.setFont(headerFont);
l.setText(table.getVascTextValue().getTextValue(table.getHeaderName()));
l.setBackground(c);
@ -596,8 +602,8 @@ public class SwtVascViewRenderer implements VascViewRenderer {
logger.finest("Creating footer");
for(RowVascAction action:table.getRowActions()) {
Button actionButton = new Button(footer, SWT.NONE);
actionButton.setText(action.getName());
actionButton.setToolTipText(action.getToolTip());
actionButton.setText(table.getVascTextValue().getTextValue(action.getName()));
actionButton.setToolTipText(table.getVascTextValue().getTextValue(action.getToolTip()));
if (action.getImage()!=null) {
actionButton.setImage(getImageDescriptor(action.getImage()).createImage());
}

View file

@ -65,7 +65,8 @@ public class SWTTest extends TestCase {
// define redering and render
SwtVascViewRenderer render = new SwtVascViewRenderer(shell);
render.renderView(TestTable.getVascTable());
render.initTable(TestTable.getVascTable());
render.renderView();
// view
shell.open();

View file

@ -32,6 +32,7 @@ import java.util.logging.LogManager;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.idcanet.vasc.core.VascTable;
import com.idcanet.vasc.impl.swing.SwingVascViewRenderer;
import junit.framework.TestCase;
@ -63,13 +64,19 @@ public class SwingTest extends TestCase {
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLocationRelativeTo(null);
// get table
VascTable table = TestTable.getVascTable();
// define redering
JPanel panel = new JPanel();
SwingVascViewRenderer render = new SwingVascViewRenderer(panel);
frame.add(panel);
// render
render.renderView(TestTable.getVascTable());
render.initTable(table);
//render.renderEdit(table.getTableData().get(0));
render.renderView();
// view
frame.pack();

View file

@ -30,7 +30,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.idcanet.vasc.core.VascDataSource;
import com.idcanet.vasc.core.AbstractVascDataSource;
import com.idcanet.vasc.models.TestModel;
/**
@ -38,7 +38,7 @@ import com.idcanet.vasc.models.TestModel;
* @author Willem Cazander
* @version 1.0 Mar 21, 2007
*/
public class TestModelVascDataSource implements VascDataSource {
public class TestModelVascDataSource extends AbstractVascDataSource {
private List<Object> testModels = null;
@ -63,22 +63,22 @@ public class TestModelVascDataSource implements VascDataSource {
this.testModels=testModels;
}
public List<Object> executeQuery(com.idcanet.xtes.xpql.query.Query query) throws Exception {
public List<Object> execute() throws Exception {
return testModels;
}
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);
}
}

View file

@ -57,22 +57,25 @@ public class TestTable {
static public VascTable getVascTable() throws Exception {
// define query
/*
XTESParser parser = new XTESParser();
parser.parseResource("/META-INF/xtes/tests.xml");
parser.parseResource("/resources/xtes/tests.xml");
TemplateStore store = XTESParser.getTemplateStore(parser.getElementContext());
Query query = store.getQuery("testUsers2");
*/
// config table
VascTable table = new VascTable();
table.setName("Testje");
table.setHeaderName("TableHeader");
table.setToolTip("tooltip text");
table.setDescription("en de omscheiving");
table.setHeaderName("Test Table enzo");
table.setHeaderToolTip("Met een hele coole tooltip");
table.setHeaderImage("/resources/images/gabelfresser.gif");
table.setHelpId("someKey");
table.setVascTableController(new DefaultVascTableController());
table.setVascDataSource(new TestModelVascDataSource());
table.setVascTextValue(new DefaultVascTextValue());
table.setQuery(query);
//table.setVascTextValue(new DefaultVascTextValue());
table.setVascTextValue(new VascI18nTextValue());
table.setVascRecordCreator(new BeanVascRecordCreator(TestModel.class));
table.addRowActions(new AddRowAction());
table.addRowActions(new EditRowAction());

View file

@ -0,0 +1,66 @@
/*
* 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;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.logging.Logger;
import com.idcanet.vasc.core.VascTextValue;
/**
*
* @author Willem Cazander
* @version 1.0 Aug 2, 2007
*/
public class VascI18nTextValue implements VascTextValue {
private String getKeyMapping(String key) {
return key;
}
public String getTextValue(String key,Object...params) {
return i18n(getKeyMapping(key),params);
}
static private String i18n(String key,Object...params) {
if (key==null) { throw new NullPointerException("key may not be null"); }
try {
String text = ResourceBundle.getBundle("resources.i18n.vasc").getString(key);
if (params != null) {
MessageFormat mf = new MessageFormat(text);
text = mf.format(params, new StringBuffer(), null).toString();
}
return text;
} catch(MissingResourceException e){
Logger.getAnonymousLogger().finer("Missing i18n or non i18n key: "+key);
return key;
}
}
}

View file

@ -35,6 +35,7 @@ import org.hibernate.validator.Max;
import com.idcanet.vasc.annotations.VascColumnWidth;
import com.idcanet.vasc.annotations.VascDefaultValue;
import com.idcanet.vasc.annotations.VascHelpId;
import com.idcanet.vasc.annotations.VascImage;
import com.idcanet.vasc.annotations.VascName;
import com.idcanet.vasc.annotations.VascToolTip;
@ -74,6 +75,7 @@ public class TestModel {
@VascHelpId(helpId="help.id")
@VascDefaultValue(defaultValue="xxxxx")
@VascColumnWidth(width=200)
@VascImage(image="/resources/images/gabelfresser.gif")
@NotNull
@Max(value=10)
public String getDescription() {

View file

@ -0,0 +1,41 @@
test = Dit is een test
vasc.dialog.save.name = Opslaan
vasc.dialog.save.tooltip = Het opslaan van de waardes.
vasc.dialog.save.image = /META-INF/images/silk/png/tick.png
vasc.dialog.cancel.name = Annuleren
vasc.dialog.cancel.tooltip = Niet opslaan van de waardes.
vasc.dialog.cancel.image = /META-INF/images/silk/png/cancel.png
vasc.action.add.name = Toevoegen
vasc.action.add.tooltip = Voegt een nieuw rij toe.
vasc.action.add.image = /META-INF/images/silk/png/table_add.png
vasc.action.edit.name = Aanpassen
vasc.action.edit.tooltip = Pas een waarde aan van de geselecteerde rij in de table.
vasc.action.edit.image = /META-INF/images/silk/png/table_edit.png
vasc.action.del.name = Verwijderen
vasc.action.del.tooltip = Verwijdert de geselecteerde rij uit de table.
vasc.action.del.image = /META-INF/images/silk/png/table_delete.png
vasc.action.csv.name = CSV
vasc.action.csv.tooltip = Exporteren naar Excel.
vasc.action.csv.image = /META-INF/images/silk/png/page_white_excel.png
vasc.action.xml.name = XML
vasc.action.xml.tooltip = Exporteren naar Xml.
vasc.action.xml.image = /META-INF/images/silk/png/page_white_excel.png
vasc.action.refresh.name = Vernieuwen
vasc.action.refresh.tooltip = Ververst de waardes in de table.
vasc.action.refresh.image = /META-INF/images/silk/png/table_refresh.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB