2
0
Fork 0

[svn r260] made swing work

This commit is contained in:
willemc 2007-08-02 03:56:02 +02:00
parent 0f55185807
commit 848eb431d6
14 changed files with 825 additions and 127 deletions

View file

@ -10,10 +10,13 @@
<classpathentry kind="lib" path="lib/idcanet-serv5-bin.jar"/>
<classpathentry kind="lib" path="lib/hibernate3.jar"/>
<classpathentry kind="lib" path="lib/jgoodies-binding.jar"/>
<classpathentry kind="con" path="SWT_CONTAINER/JFACE/PLATFORM"/>
<classpathentry kind="lib" path="lib/idcanet-jmx-bin.jar"/>
<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="var" path="ECLIPSE_HOME/plugins/org.eclipse.swt.gtk.linux.x86_3.2.2.v3236.jar"/>
<classpathentry kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.jface_3.2.2.M20061214-1200.jar"/>
<classpathentry kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.jface.databinding_1.0.0.I20060605-1400.jar"/>
<classpathentry kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.jface.text_3.2.2.r322_v20070104.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -201,14 +201,19 @@ public class VascAnnotationParser {
}
if (a.equals(VascDefaultValue.class)) {
VascDefaultValue v = (VascDefaultValue)b;
if (v.defaultValue()==null) {
return null; // error ??
if(v.defaultValueClass().equals(Object.class)==false) {
try {
return v.defaultValueClass().newInstance();
} catch (Exception e) {
logger.log(Level.WARNING,e.getMessage(),e);
throw new NullPointerException("Could not init defaultValueClass");
}
}
try {
return v.defaultValueClass().newInstance();
} catch (Exception e) {
logger.log(Level.WARNING,e.getMessage(),e);
if ("null".equals(v.defaultValue())) {
return "";
}
return v.defaultValue();
}
if (a.equals(VascColumnWidth.class)) {
VascColumnWidth c = (VascColumnWidth)b;

View file

@ -0,0 +1,41 @@
/*
* 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;
/**
*
* @author Willem Cazander
* @version 1.0 Aug 02, 2007
*/
public interface VascEventListener {
public enum VascEventType { DATA_UPDATE,OPTION_UPDATE }
public void vascEvent(VascEventType e,Object o);
}

View file

@ -26,6 +26,8 @@
package com.idcanet.vasc.core;
import com.idcanet.vasc.core.column.VascTableColumn;
/**
*
* @author Willem Cazander
@ -43,6 +45,14 @@ public interface VascTableController {
public Object initEditObject(VascTable table,Object object) throws Exception;
public void initEditObjectColumn(VascTableColumn column,Object object) throws Exception;
public void handleException(Exception e,VascTable table);
public void addEventListener(VascEventListener e);
public void removeEventListener(VascEventListener e);
public void fireVascEvent(VascEventListener.VascEventType type,Object data);
}

View file

@ -40,6 +40,8 @@ public interface VascViewRenderer {
public void renderEdit(VascTable table,Object rowBean) throws Exception;
public void renderDelete(VascTable table,Object rowBean) throws Exception;
public void renderExport(VascTable table,VascDataExporter exporter) throws Exception;
public Object defaultColumnEditor(VascTableColumn column,Object bean,Object gui) throws Exception;

View file

@ -26,10 +26,13 @@
package com.idcanet.vasc.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.idcanet.vasc.annotations.VascAnnotationParser;
import com.idcanet.vasc.core.VascEventListener;
import com.idcanet.vasc.core.VascTable;
import com.idcanet.vasc.core.VascTableController;
import com.idcanet.vasc.core.column.VascAnnotationTableColumn;
@ -45,6 +48,12 @@ import com.idcanet.vasc.impl.column.DefaultVascColumnRenderer;
*/
public class DefaultVascTableController implements VascTableController {
private Logger logger = null;
public DefaultVascTableController() {
logger = Logger.getLogger(DefaultVascTableController.class.getName());
}
/**
* @see com.idcanet.vasc.core.VascTableController#finalizeVascColumns(com.idcanet.vasc.core.VascTable)
*/
@ -120,6 +129,18 @@ public class DefaultVascTableController implements VascTableController {
object = table.getVascRecordCreator().newRecord(table);
return object;
}
public void initEditObjectColumn(VascTableColumn c,Object bean) throws Exception {
Object value = c.getVascColumnValue().getValue(c, bean);
if(value==null & c.getDefaultValue()!=null) {
try {
logger.finer("Setting default value for: "+c.getName()+" def: "+c.getDefaultValue());
c.getVascColumnValue().setValue(c, bean, c.getDefaultValue());
} catch (Exception e) {
logger.log(Level.WARNING,"Error in setting default value: '"+c.getDefaultValue()+"' error: "+e.getMessage(),e);
}
}
}
/**
* @see com.idcanet.vasc.core.VascTableController#refreshData()
@ -131,4 +152,20 @@ public class DefaultVascTableController implements VascTableController {
public void handleException(Exception e,VascTable table) {
Logger.getLogger(DefaultVascTableController.class.getName()).log(Level.WARNING,e.getMessage(),e);
}
List<VascEventListener> eventListeners = new ArrayList<VascEventListener>(2);
public void addEventListener(VascEventListener e) {
eventListeners.add(e);
}
public void removeEventListener(VascEventListener e) {
eventListeners.remove(e);
}
public void fireVascEvent(VascEventListener.VascEventType type,Object data) {
for(VascEventListener e:eventListeners) {
e.vascEvent(type, data);
}
}
}

View file

@ -44,6 +44,6 @@ public class AddRowAction extends AbstractVascAction implements RowVascAction {
}
public void doRowAction(VascTable table,Object rowObject) throws Exception {
table.getVascViewRenderer().renderEdit(table,rowObject);
table.getVascViewRenderer().renderEdit(table,table.getVascRecordCreator().newRecord(table));
}
}

View file

@ -44,6 +44,9 @@ public class DeleteRowAction extends AbstractVascAction implements RowVascAction
}
public void doRowAction(VascTable table,Object rowObject) throws Exception {
table.getVascDataSource().delete(rowObject);
if (rowObject==null) {
return;
}
table.getVascViewRenderer().renderDelete(table,rowObject);
}
}

View file

@ -45,6 +45,9 @@ public class EditRowAction extends AbstractVascAction implements RowVascAction {
public void doRowAction(VascTable table,Object rowObject) throws Exception {
if (rowObject==null) {
return;
}
table.getVascViewRenderer().renderEdit(table,rowObject);
}
}

View file

@ -26,23 +26,51 @@
package com.idcanet.vasc.impl.swing;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.Spring;
import javax.swing.SpringLayout;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import com.idcanet.fff.SwingImageHelper;
import com.idcanet.vasc.core.VascDataExporter;
import com.idcanet.vasc.core.VascEventListener;
import com.idcanet.vasc.core.VascTable;
import com.idcanet.vasc.core.VascUserOption;
import com.idcanet.vasc.core.VascViewRenderer;
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.column.VascTableColumn;
/**
*
@ -61,53 +89,461 @@ public class SwingVascViewRenderer implements VascViewRenderer {
}
/**
* @see com.idcanet.vasc.core.VascViewRenderer#renderView(com.idcanet.vasc.core.VascTable)
* @see com.idcanet.vasc.core.VascViewRenderer#defaultColumnEditor(com.idcanet.vasc.core.column.VascTableColumn, java.lang.Object, java.lang.Object)
*/
public void renderView(VascTable table) {
this.table=table;
try {
table.setTableData(table.getVascDataSource().executeQuery(table.getQuery()));
} catch (Exception e) {
e.printStackTrace();
public Object defaultColumnEditor(VascTableColumn column, Object bean, Object gui) throws Exception {
JTextField def = new JTextField();
def.setText(""+column.getVascColumnValue().getValue(column, bean));
((JComponent)gui).add(def);
def.getDocument().addDocumentListener(new TextListener(column,bean) );
return def;
}
public ImageIcon getImageIcon(String imageResource) {
return SwingImageHelper.getImageIcon(imageResource);
}
class TextListener implements DocumentListener {
private VascTableColumn column = null;
private Object bean = null;
public TextListener(VascTableColumn column,Object bean) {
this.column=column;
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) {
update(e);
}
public void update(DocumentEvent event) {
try {
String value = event.getDocument().getText(0, event.getDocument().getLength());
logger.finer("Setting value: "+value);
column.getVascColumnValue().setValue(column, bean, value);
} catch (Exception ee) {
ee.printStackTrace();
}
}
}
/**
* @see com.idcanet.vasc.core.VascViewRenderer#defaultColumnRenderer(com.idcanet.vasc.core.column.VascTableColumn, java.lang.Object)
*/
public Object defaultColumnRenderer(VascTableColumn column, Object gui) throws Exception {
return null;
}
/**
* @see com.idcanet.vasc.core.VascViewRenderer#renderEdit(com.idcanet.vasc.core.VascTable, java.lang.Object)
*/
public void renderEdit(VascTable table, 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);
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 {
int response = JOptionPane.showOptionDialog(
parent // Center in window.
, "Delete "+rowBean // Message
, "Delete" // Title in titlebar
, JOptionPane.YES_NO_OPTION // Option type
, JOptionPane.PLAIN_MESSAGE // messageType
, null // Icon (none)
, null // Button text as above.
, null // Default button's label
);
if (response==JOptionPane.YES_OPTION) {
table.getVascDataSource().delete(rowBean);
table.getVascTableController().fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, rowBean);
}
}
class SwingEditDialog extends JDialog {
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) {
super();
this.headerText = headerText;
this.title = title;
this.bean = bean;
setTitle(title);
setModal(true);
JPanel pane = new JPanel();
pane.setLayout(new BorderLayout());
JPanel header = new JPanel();
createHeader(header);
pane.add(header,BorderLayout.NORTH);
JPanel body = new JPanel();
createBody(body);
pane.add(body,BorderLayout.CENTER);
JPanel footer = new JPanel();
createFooter(footer);
pane.add(footer,BorderLayout.SOUTH);
add(pane);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
//Ensure the text field always gets the first focus.
//addComponentListener(new ComponentAdapter() {
// public void componentShown(ComponentEvent ce) {
// textField.requestFocusInWindow();
// }
/// });
pack();
setLocationRelativeTo(parent);
}
public Object openDialog() {
setVisible(true);
return result;
}
public void createHeader(JPanel header) {
JLabel l = new JLabel();
l.setText(headerText);
l.setFont(new Font(null,Font.BOLD, 14));
header.add(l);
}
public void createBody(JPanel body) {
body.setLayout(new SpringLayout());
for(VascTableColumn c:table.getTableColumns()) {
JLabel l = new JLabel();
l.setHorizontalAlignment(JLabel.TRAILING);
l.setText(c.getName());
if(c.getToolTip()!=null) {
l.setToolTipText(c.getToolTip());
}
body.add(l);
try {
table.getVascTableController().initEditObjectColumn(c, bean);
if(c.getVascColumnEditor()==null) {
JLabel valueLabel = new JLabel();
valueLabel.setText(""+c.getVascColumnValue().getValue(c, bean));
c.setColumnEditor(valueLabel);
body.add(valueLabel);
} else {
c.setColumnEditor(c.getVascColumnEditor().createColumnEditor(c,bean,body));
}
} catch (Exception e) {
logger.log(Level.WARNING,"Error making column editor: '"+c.getVascColumnValue()+"' error: "+e.getMessage(),e);
}
}
//JComponent, rows, cols, initX, initY ,xPad, yPad
SpringUtilities.makeCompactGrid(body, table.getTableColumns().size(),2, 6,6, 6,6);
}
public void createFooter(JPanel footer) {
JButton saveButton = new JButton();
saveButton.setIcon(getImageIcon("/META-INF/images/silk/png/tick.png"));
saveButton.setText("generic.save");
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
//if(hasRecordError()) {
// return;
//}
result = bean;
setVisible(false);
}
});
footer.add(saveButton);
JButton cancelButton = new JButton();
cancelButton.setIcon(getImageIcon("/META-INF/images/silk/png/cancel.png"));
cancelButton.setText("generic.cancel");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
result = null;
setVisible(false);
}
});
footer.add(cancelButton);
}
}
/**
* @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 {
String fileName = null;
JFileChooser c = new JFileChooser();
// Demonstrate "Save" dialog:
int rVal = c.showSaveDialog(null);
if (rVal == JFileChooser.APPROVE_OPTION) {
fileName = c.getSelectedFile().getAbsolutePath();
// filename.setText(c.getSelectedFile().getName());
//dir.setText(c.getCurrentDirectory().toString());
}
if (rVal == JFileChooser.CANCEL_OPTION) {
return;
}
logger.fine("FileName: "+fileName);
if (fileName == null) {
return;
}
OutputStream out = new FileOutputStream(fileName);
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);
} finally {
if (out!=null) {
out.close();
}
}
}
/**
* @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;
JPanel topPanel = new JPanel();
renderHeader(topPanel);
renderBody(topPanel);
renderFooter(topPanel);
topPanel.setLayout(new BorderLayout());
JPanel n = new JPanel();
topPanel.add(n,BorderLayout.NORTH);
renderHeader(n);
JPanel c = new JPanel();
topPanel.add(c,BorderLayout.CENTER);
renderBody(c);
JPanel f = new JPanel();
topPanel.add(f,BorderLayout.SOUTH);
renderFooter(f);
parent.add(topPanel);
}
private void renderHeader(JComponent parent2) {
}
private void renderBody(JComponent parent2) {
JTable jTable = new JTable(new VascColumnModel());
private void renderHeader(JComponent parent2) {
for(VascTableColumn c:table.getTableColumns()) {
VascJTableColumn t = new VascJTableColumn();
t.setPreferredWidth(c.getWidth());
t.setHeaderValue(c.getName());
jTable.addColumn(t);
if(table.getHeaderName()!=null) {
JLabel l = new JLabel(table.getVascTextValue().getTextValue(table.getHeaderName()));
l.setFont(new Font(null,Font.BOLD, 14));
parent2.add(l);
}
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);
}
// create options
for(VascUserOption option:table.getUserOptions()) {
}
}
private void renderBody(JComponent parent2) {
VascColumnModel model = new VascColumnModel();
table.getVascTableController().addEventListener(model);
JTable jTable = new JTable(model);
// remove auto columns :(
int cols = jTable.getColumnModel().getColumnCount();
for (int i=0;i<cols;i++) {
TableColumn c = jTable.getColumnModel().getColumn(0); // idd, just remove index 0 every time
jTable.removeColumn(c);
}
TableCellRenderer renderer = new JComponentTableCellRenderer();
int counter=0;
for(VascTableColumn c:table.getTableColumns()) {
TableColumn t = new TableColumn();
t.setPreferredWidth(c.getWidth());
t.setHeaderValue(c);
t.setHeaderRenderer(renderer);
t.setModelIndex(counter);
jTable.addColumn(t);
counter++;
}
jTable.getSelectionModel().addListSelectionListener(new TableSectionListener(jTable));
jTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
JScrollPane scrollPane = new JScrollPane(jTable);
parent2.add(scrollPane);
}
class TableSectionListener implements ListSelectionListener {
JTable jTable;
TableSectionListener(JTable table) {
this.jTable = table;
}
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
int rowIndex = jTable.getSelectedRow();
if (rowIndex!=-1) {
Object data = table.getTableData().get(rowIndex);
table.setSelectedObject(data);
} else {
table.setSelectedObject(null);
}
}
}
class JComponentTableCellRenderer extends DefaultTableCellRenderer {
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()));
setToolTipText(c.getVascTable().getVascTextValue().getTextValue(c.getToolTip()));
if(c.getImage()!=null) {
setIcon(getImageIcon(c.getImage()));
} else {
setIcon(null);
}
if (table != null) {
JTableHeader header = table.getTableHeader();
if (header != null) {
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(header.getFont());
}
}
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
return this;
}
}
private void renderFooter(JComponent parent2) {
logger.finest("Creating footer");
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);
}
}
class VascJTableColumn extends TableColumn {
class RowActionListener implements ActionListener {
private RowVascAction action = null;
public RowActionListener(RowVascAction action) {
this.action=action;
}
public void actionPerformed(ActionEvent event) {
logger.info("Row Action");
try {
action.doRowAction(table, table.getSelectedObject());
} catch (Exception e) {
table.getVascTableController().handleException(e, table);
}
}
}
class GlobalActionListener implements ActionListener {
private GlobalVascAction action = null;
public GlobalActionListener(GlobalVascAction action) {
this.action=action;
}
public void actionPerformed(ActionEvent event) {
logger.info("Global Action");
try {
action.doGlobalAction(table);
} catch (Exception e) {
table.getVascTableController().handleException(e, table);
}
}
}
class VascColumnModel extends AbstractTableModel {
class VascColumnModel extends AbstractTableModel implements VascEventListener {
public void vascEvent(VascEventType e,Object o) {
if (e==VascEventType.DATA_UPDATE) {
fireTableDataChanged();
}
}
/**
* @see javax.swing.table.TableModel#getColumnCount()
*/
@ -136,8 +572,204 @@ public class SwingVascViewRenderer implements VascViewRenderer {
//do iets
return "RENDER";
} else {
return ""+vtc.getVascColumnValue().getValue(vtc,bean);
try {
return ""+vtc.getVascColumnValue().getValue(vtc,bean);
} catch (Exception e) {
e.printStackTrace();
return "Error";
}
}
}
}
}
/**
* A 1.4 file that provides utility methods for creating form- or grid-style
* layouts with SpringLayout. These utilities are used by several programs, such
* as SpringBox and SpringCompactGrid.
*/
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
* <code>parent</code> in a grid. Each component is as big as the maximum
* preferred width and height of the components. The parent is made just big
* enough to fit them all.
*
* @param rows
* number of rows
* @param cols
* number of columns
* @param initialX
* x location to start the grid at
* @param initialY
* y location to start the grid at
* @param xPad
* x padding between cells
* @param yPad
* y padding between cells
*/
public static void makeGrid(Container parent, int rows, int cols,
int initialX, int initialY, int xPad, int yPad) {
SpringLayout layout;
try {
layout = (SpringLayout) parent.getLayout();
} catch (ClassCastException exc) {
System.err
.println("The first argument to makeGrid must use SpringLayout.");
return;
}
Spring xPadSpring = Spring.constant(xPad);
Spring yPadSpring = Spring.constant(yPad);
Spring initialXSpring = Spring.constant(initialX);
Spring initialYSpring = Spring.constant(initialY);
int max = rows * cols;
//Calculate Springs that are the max of the width/height so that all
//cells have the same size.
Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0))
.getWidth();
Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0))
.getWidth();
for (int i = 1; i < max; i++) {
SpringLayout.Constraints cons = layout.getConstraints(parent
.getComponent(i));
maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth());
maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight());
}
//Apply the new width/height Spring. This forces all the
//components to have the same size.
for (int i = 0; i < max; i++) {
SpringLayout.Constraints cons = layout.getConstraints(parent
.getComponent(i));
cons.setWidth(maxWidthSpring);
cons.setHeight(maxHeightSpring);
}
//Then adjust the x/y constraints of all the cells so that they
//are aligned in a grid.
SpringLayout.Constraints lastCons = null;
SpringLayout.Constraints lastRowCons = null;
for (int i = 0; i < max; i++) {
SpringLayout.Constraints cons = layout.getConstraints(parent
.getComponent(i));
if (i % cols == 0) { //start of new row
lastRowCons = lastCons;
cons.setX(initialXSpring);
} else { //x position depends on previous component
cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST),
xPadSpring));
}
if (i / cols == 0) { //first row
cons.setY(initialYSpring);
} else { //y position depends on previous row
cons.setY(Spring.sum(lastRowCons
.getConstraint(SpringLayout.SOUTH), yPadSpring));
}
lastCons = cons;
}
//Set the parent's size.
SpringLayout.Constraints pCons = layout.getConstraints(parent);
pCons.setConstraint(SpringLayout.SOUTH, Spring.sum(Spring
.constant(yPad), lastCons.getConstraint(SpringLayout.SOUTH)));
pCons.setConstraint(SpringLayout.EAST, Spring.sum(
Spring.constant(xPad), lastCons
.getConstraint(SpringLayout.EAST)));
}
/* Used by makeCompactGrid. */
private static SpringLayout.Constraints getConstraintsForCell(int row,
int col, Container parent, int cols) {
SpringLayout layout = (SpringLayout) parent.getLayout();
Component c = parent.getComponent(row * cols + col);
return layout.getConstraints(c);
}
/**
* Aligns the first <code>rows</code>*<code>cols</code> components of
* <code>parent</code> in a grid. Each component in a column is as wide as
* the maximum preferred width of the components in that column; height is
* similarly determined for each row. The parent is made just big enough to
* fit them all.
*
* @param rows
* number of rows
* @param cols
* number of columns
* @param initialX
* x location to start the grid at
* @param initialY
* y location to start the grid at
* @param xPad
* x padding between cells
* @param yPad
* y padding between cells
*/
public static void makeCompactGrid(Container parent, int rows, int cols,
int initialX, int initialY, int xPad, int yPad) {
SpringLayout layout;
try {
layout = (SpringLayout) parent.getLayout();
} catch (ClassCastException exc) {
System.err
.println("The first argument to makeCompactGrid must use SpringLayout.");
return;
}
//Align all cells in each column and make them the same width.
Spring x = Spring.constant(initialX);
for (int c = 0; c < cols; c++) {
Spring width = Spring.constant(0);
for (int r = 0; r < rows; r++) {
width = Spring.max(width, getConstraintsForCell(r, c, parent,
cols).getWidth());
}
for (int r = 0; r < rows; r++) {
SpringLayout.Constraints constraints = getConstraintsForCell(r,
c, parent, cols);
constraints.setX(x);
constraints.setWidth(width);
}
x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
}
//Align all cells in each row and make them the same height.
Spring y = Spring.constant(initialY);
for (int r = 0; r < rows; r++) {
Spring height = Spring.constant(0);
for (int c = 0; c < cols; c++) {
height = Spring.max(height, getConstraintsForCell(r, c, parent,
cols).getHeight());
}
for (int c = 0; c < cols; c++) {
SpringLayout.Constraints constraints = getConstraintsForCell(r,
c, parent, cols);
constraints.setY(y);
constraints.setHeight(height);
}
y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
}
//Set the parent's size.
SpringLayout.Constraints pCons = layout.getConstraints(parent);
pCons.setConstraint(SpringLayout.SOUTH, y);
pCons.setConstraint(SpringLayout.EAST, x);
}
}

View file

@ -126,7 +126,7 @@ public class SwtVascViewRenderer implements VascViewRenderer {
logger.info("Rending Edit View");
table.getVascTableController().initEditObject(table, object);
SwtVascEditDialog dialog = new SwtVascEditDialog(Display.getCurrent().getActiveShell(),table,object,"Edit","TOITO");
SwtVascEditDialog dialog = new SwtVascEditDialog(Display.getCurrent().getActiveShell(),table,object,"Vasc Edit","Edit");
Object result = dialog.open();
if(result==null) {
return;
@ -172,6 +172,10 @@ public class SwtVascViewRenderer implements VascViewRenderer {
}
}
public void renderDelete(VascTable table,Object rowBean) throws Exception {
}
public class SwtVascEditDialog extends Dialog {
private Shell shell = null;
@ -246,7 +250,11 @@ public class SwtVascViewRenderer implements VascViewRenderer {
l.setToolTipText(c.getToolTip());
}
try {
table.getVascTableController().initEditObjectColumn(c, bean);
if(c.getVascColumnEditor()==null) {
Label valueLabel = new Label(body, SWT.WRAP);
valueLabel.setText(""+c.getVascColumnValue().getValue(c, bean));
@ -258,15 +266,6 @@ public class SwtVascViewRenderer implements VascViewRenderer {
logger.log(Level.WARNING,"Error making column editor: '"+c.getVascColumnValue()+"' error: "+e.getMessage(),e);
}
// set the default value before creating property
if(c.getVascColumnValue()==null & c.getDefaultValue()!=null) {
try {
logger.finer("Setting default value for: "+c.getName()+" def: "+c.getDefaultValue());
c.getVascColumnValue().setValue(c, bean, c.getDefaultValue());
} catch (Exception e) {
logger.log(Level.WARNING,"Error in setting default value: '"+c.getDefaultValue()+"' error: "+e.getMessage(),e);
}
}
if(c.getColumnEditor() instanceof Control) {
Control editor = (Control)c.getColumnEditor();
GridData gridData = new GridData();

View file

@ -80,15 +80,34 @@ public class SWTTest extends TestCase {
// get GUI
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Hello, world!");
shell.setText("Hello, world!");
// define redering and render
SwtVascViewRenderer render = new SwtVascViewRenderer(shell);
render.renderView(getVascTable());
// view
shell.open();
// Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
// If no more entries in event queue
display.sleep();
}
}
display.dispose();
}
static public VascTable getVascTable() throws Exception {
// define query
XTESParser parser = new XTESParser();
parser.parseResource("/META-INF/xtes/tests.xml");
TemplateStore store = XTESParser.getTemplateStore(parser.getElementContext());
Query query = store.getQuery("testUsers2");
// config table
// config table
VascTable table = new VascTable();
table.setName("Testje");
table.setHeaderName("TableHeader");
@ -118,6 +137,7 @@ public class SWTTest extends TestCase {
column.setToolTip("tooltip");
column.setDefaultValue("DEFFFFFF");
column.setHelpId("helpColumnKey");
column.setImage("/META-INF/images/silk/png/tick.png");
column.setWidth(400);
column.setVascColumnEditor(new DefaultVascColumnEditor());
column.setVascColumnRenderer(new DefaultVascColumnRenderer());
@ -126,21 +146,6 @@ public class SWTTest extends TestCase {
column = new VascAnnotationTableColumn("description");
table.addTableColumns(column);
// define redering and render
SwtVascViewRenderer render = new SwtVascViewRenderer(shell);
render.renderView(table);
// view
shell.open();
// Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
// If no more entries in event queue
display.sleep();
}
}
display.dispose();
return table;
}
}

View file

@ -30,21 +30,9 @@ import java.io.InputStream;
import java.util.logging.LogManager;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import com.idcanet.vasc.core.VascTable;
import com.idcanet.vasc.core.column.VascTableColumn;
import com.idcanet.vasc.impl.BeanVascRecordCreator;
import com.idcanet.vasc.impl.DefaultVascTextValue;
import com.idcanet.vasc.impl.column.BeanPropertyVascColumnValue;
import com.idcanet.vasc.impl.serv5.Serv5HibernateVascDataSource;
import com.idcanet.vasc.impl.swing.SwingVascViewRenderer;
import com.idcanet.vasc.impl.swt.SwtVascViewRenderer;
import com.idcanet.xtes.core.TemplateStore;
import com.idcanet.xtes.core.XTESParser;
import com.idcanet.xtes.xpql.query.Query;
import junit.framework.TestCase;
@ -61,71 +49,38 @@ public class SwingTest extends TestCase {
InputStream loggingProperties = this.getClass().getResourceAsStream("/META-INF/logging.properties");
LogManager.getLogManager().readConfiguration( loggingProperties );
loggingProperties.close();
// load xtes queries
}
public void tearDown() throws Exception {
}
public void testAll() throws Exception {
JFrame.setDefaultLookAndFeelDecorated(false);
// get GUI
JFrame frame = new JFrame();
frame.setTitle("Hello, world!");
frame.setDefaultLookAndFeelDecorated(false);
frame.setTitle("Swing Vasc Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setBounds(150,150,700,500);
frame.setBounds(150,150,900,700);
// define query
XTESParser parser = new XTESParser();
parser.parseResource("/META-INF/xtes/tests.xml");
TemplateStore store = XTESParser.getTemplateStore(parser.getElementContext());
Query query = store.getQuery("testUsers2");
JPanel panel = new JPanel();
frame.add(panel);
// define redering
SwingVascViewRenderer render = new SwingVascViewRenderer(frame.getRootPane());
SwingVascViewRenderer render = new SwingVascViewRenderer(panel);
// config table
VascTable table = new VascTable();
table.setName("Testje");
table.setHeaderName("TableHeader");
table.setToolTip("tooltip text");
table.setDescription("en de omscheiving");
table.setHelpId("someKey");
table.setVascDataSource(new TestModelVascDataSource());
table.setVascTextValue(new DefaultVascTextValue());
table.setVascViewRenderer(render);
table.setQuery(query);
table.setVascRecordCreator(new BeanVascRecordCreator());
VascTableColumn column = new VascTableColumn();
column.setName("test");
column.setToolTip("tooltip");
column.setDefaultValue("DEFFFFFF");
column.setHelpId("helpColumnKey");
column.setWidth(200);
//column.setVascColumnEditor(vascColumnEditor);
//column.setVascColumnRenderer(vascColumnRenderer);
column.setVascColumnValue(new BeanPropertyVascColumnValue("name"));
table.addTableColumns(column);
// render
render.renderView(table);
render.renderView(SWTTest.getVascTable());
// view
frame.getContentPane().validate();
frame.setVisible(true);
frame.repaint();
String test="34";
while (true) {
test+=test+"34566";
if(test.length()>1000000) {
break;
}
while (frame.isVisible()) {
Thread.sleep(1000);
}
}
}

View file

@ -68,13 +68,16 @@ public class TestModelVascDataSource implements VascDataSource {
}
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);
}