2
0
Fork 0

moved to sub projects

This commit is contained in:
Willem Cazander 2011-12-31 00:32:07 +01:00
parent a523cc9122
commit dff60035cf
182 changed files with 251 additions and 46 deletions

10
vasc-frontends/.classpath Normal file
View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

23
vasc-frontends/.project Normal file
View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>vasc-frontends</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
#Sat Dec 31 00:15:40 CET 2011
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View file

@ -0,0 +1,6 @@
#Sat Dec 31 00:15:40 CET 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5

View file

@ -0,0 +1,5 @@
#Sat Dec 31 00:15:40 CET 2011
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

18
vasc-frontends/pom.xml Normal file
View file

@ -0,0 +1,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vasc</artifactId>
<groupId>net.forwardfire.vasc</groupId>
<version>0.3.5-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>vasc-frontends</artifactId>
<packaging>pom</packaging>
<name>vasc-frontends</name>
<description>vasc-frontends</description>
<modules>
<module>vasc-frontend-swing</module>
<module>vasc-frontend-swt</module>
<module>vasc-frontend-web-jsf</module>
</modules>
</project>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>vasc-frontend-swing</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
#Sun Dec 25 17:29:07 CET 2011
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View file

@ -0,0 +1,6 @@
#Mon Aug 30 21:56:01 CEST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5

View file

@ -0,0 +1,5 @@
#Sun Dec 25 17:29:02 CET 2011
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View file

@ -0,0 +1,9 @@
#Mon Aug 30 21:56:00 CEST 2010
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1

View file

@ -0,0 +1,40 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vasc-frontends</artifactId>
<groupId>net.forwardfire.vasc</groupId>
<version>0.3.5-SNAPSHOT</version>
</parent>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-frontend-swing</artifactId>
<version>0.3.5-SNAPSHOT</version>
<name>vasc-frontend-swing</name>
<description>vasc-frontend-swing</description>
<dependencies>
<dependency>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-core</artifactId>
<version>${project.version}</version>
</dependency>
<!-- FFF depency
<dependency>
<groupId>com.idcanet.fff</groupId>
<artifactId>fff-main</artifactId>
<version>0.8-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
-->
<!-- Swing date editor depency -->
<dependency>
<groupId>com.michaelbaranov</groupId>
<artifactId>microba</artifactId>
<version>0.4.4.1</version>
</dependency>
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel</artifactId>
<version>${juel.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,845 @@
/*
* 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 net.forwardfire.vasc.frontends.swing;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
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.ListSelectionModel;
import javax.swing.Spring;
import javax.swing.SpringLayout;
import javax.swing.UIManager;
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 net.forwardfire.vasc.core.AbstractVascFrontend;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascFrontendData;
import net.forwardfire.vasc.core.actions.GlobalVascAction;
import net.forwardfire.vasc.core.actions.RowVascAction;
import net.forwardfire.vasc.core.entry.VascEntryExporter;
import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener;
import net.forwardfire.vasc.core.ui.VascColumnValueModelListener;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
import net.forwardfire.vasc.frontends.swing.ui.SwingBoolean;
import net.forwardfire.vasc.frontends.swing.ui.SwingButton;
import net.forwardfire.vasc.frontends.swing.ui.SwingColorChooser;
import net.forwardfire.vasc.frontends.swing.ui.SwingLabel;
import net.forwardfire.vasc.frontends.swing.ui.SwingList;
import net.forwardfire.vasc.frontends.swing.ui.SwingText;
import net.forwardfire.vasc.frontends.swing.ui.SwingTextArea;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 21, 2007
*/
public class SwingVascFrontend extends AbstractVascFrontend {
private Logger logger = null;
private JComponent parent = null;
public SwingVascFrontend(JComponent parent) {
logger = Logger.getLogger(SwingVascFrontend.class.getName());
this.parent=parent;
}
/**
* @see net.forwardfire.vasc.core.VascFrontend#getFrontendType()
*/
public String getFrontendType() {
return "swing";
}
/**
* Add swing implmented ui components
*/
protected void addUiComponents() {
VascFrontendData vfd = getVascEntry().getVascFrontendData();
// required UI components
vfd.putVascUIComponent(VascUIComponent.VASC_LABEL,SwingLabel.class.getName());
vfd.putVascUIComponent(VascUIComponent.VASC_TEXT, SwingText.class.getName());
vfd.putVascUIComponent(VascUIComponent.VASC_LIST, SwingList.class.getName());
vfd.putVascUIComponent(VascUIComponent.VASC_BUTTON, SwingButton.class.getName());
// optional UI components
vfd.putVascUIComponent(VascUIComponent.VASC_BOOLEAN , SwingBoolean.class.getName());
//vfd.putVascUIComponent(VascUIComponent.VASC_DATE , SwingDate.class.getName());
vfd.putVascUIComponent(VascUIComponent.VASC_TEXTAREA, SwingTextArea.class.getName());
vfd.putVascUIComponent(VascUIComponent.VASC_COLOR, SwingColorChooser.class.getName());
}
public ImageIcon getImageIcon(String imageResource) {
/// TODO hack beter
String key = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(imageResource);
//logger.fine("KEY======================="+key);
if (key.startsWith("vasc.entry")) {
return null;
}
if (key.indexOf("META-INF")>0 | key.indexOf("resource")>0) {
return null;
//return SwingImageHelper.getImageIcon(key);
} else {
return null;
}
}
/**
* @see net.forwardfire.vasc.core.VascViewRenderer#renderEdit(net.forwardfire.vasc.core.VascEntry, java.lang.Object)
*/
public void renderEdit() throws Exception {
logger.fine("Rending Edit View");
Object rowBean = entry.getVascFrontendData().getVascEntryState().getEntryDataObject();
String beanValue = rowBean.toString();
if (entry.getDisplayNameFieldId()!=null) {
VascEntryField v = entry.getVascEntryFieldById(entry.getDisplayNameFieldId());
Object vv = v.getVascEntryFieldValue().getValue(v, rowBean);
if (vv==null) {
beanValue="";
} else {
beanValue=""+vv;
}
if (beanValue.length()>30) {
beanValue=beanValue.substring(0, 30);
}
}
SwingEditDialog dialog = new SwingEditDialog(parent,entry,rowBean,i18n("vasc.dialog.edit.title"),i18n("vasc.dialog.edit.message",beanValue));
Object result = dialog.openDialog();
logger.finest("OPEN closed : "+result);
if(result==null) {
return;
}
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(result);
entry.getVascFrontendData().getVascFrontendHelper().mergeObject(entry);
}
public void renderDelete() throws Exception {
Object rowBean = entry.getVascFrontendData().getVascEntryState().getEntryDataObject();
String beanValue = rowBean.toString();
VascEntryField v = entry.getVascEntryFieldById(entry.getDisplayNameFieldId());
beanValue = ""+v.getVascEntryFieldValue().getValue(v, rowBean);
if (beanValue.length()>30) {
beanValue=beanValue.substring(0, 30);
}
int response = JOptionPane.showOptionDialog(
parent // Center in window.
, i18n("vasc.dialog.delete.message",beanValue) // Message
, i18n("vasc.dialog.delete.title") // 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) {
entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry);
}
}
class SwingEditDialog extends JDialog {
private static final long serialVersionUID = 10L;
private String headerText = null;
private Object result = null;
private Object bean = null;
public SwingEditDialog(JComponent parent,VascEntry entry,Object bean,String title,String headerText) throws Exception {
super();
this.headerText = headerText;
this.bean = bean;
setTitle(i18n(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(i18n(headerText));
l.setFont(new Font(null,Font.BOLD, 14));
//l.setToolTipText(i18n(headerText));
header.add(l);
}
public void createBody(JPanel body) throws Exception {
body.setLayout(new SpringLayout());
int column = 0;
for (VascEntryField c:entry.getVascEntryFields()) {
if (c.getEdit()==false) {
continue;
}
//if (c.isEditReadOnly()==true) {
for (int i=0;i<c.getVascEntryFieldType().getUIComponentCount(c);i++) {
VascUIComponent label = c.getVascEntryFieldType().provideLabelUIComponent(i,c);
VascValueModel model = new VascValueModel();
model.setValue(i18n(c.getName()));
label.createComponent(entry,c,model,body);
VascUIComponent editor = c.getVascEntryFieldType().provideEditorUIComponent(i,c);
model = new VascValueModel(c.getVascEntryFieldType().provideEditorVascValueModel(i,c));
model.setValue(c.getVascEntryFieldValue().getValue(c, bean));
model.addListener(new VascColumnValueModelListener(c,bean));
Object g = editor.createComponent(entry,c,model,body);
column++;
if (i==0) {
entry.getVascFrontendData().addFieldVascUIComponents(c, editor,g);
}
}
}
//JComponent, rows, cols, initX, initY ,xPad, yPad
SpringUtilities.makeCompactGrid(body, column,2, 6,6, 6,6);
}
public void createFooter(JPanel footer) {
JButton saveButton = new JButton();
saveButton.setIcon(getImageIcon("vasc.dialog.save.image"));
saveButton.setText(i18n("vasc.dialog.save.name"));
saveButton.setToolTipText(i18n("vasc.dialog.save.tooltip"));
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
//if(entry.getVascFrontendData().getVascFrontendHelper().validateObject(entry, bean)) {
// return;
//}
result = bean;
setVisible(false);
}
});
footer.add(saveButton);
JButton cancelButton = new JButton();
cancelButton.setIcon(getImageIcon("vasc.dialog.cancel.image"));
cancelButton.setText(i18n("vasc.dialog.cancel.name"));
cancelButton.setToolTipText(i18n("vasc.dialog.cancel.tooltip"));
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
result = null;
setVisible(false);
}
});
footer.add(cancelButton);
}
}
/**
* @see net.forwardfire.vasc.core.VascViewRenderer#renderExport(net.forwardfire.vasc.core.VascEntry, net.forwardfire.vasc.core.VascDataExporter)
*/
public void renderExport(VascEntryExporter exporter) throws Exception {
String fileName = null;
JFileChooser c = new JFileChooser();
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, entry);
} catch (Exception e) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e);
} finally {
if (out!=null) {
out.close();
}
}
}
/**
* @see net.forwardfire.vasc.core.VascViewRenderer#renderView(net.forwardfire.vasc.core.VascEntry)
*/
public void renderView() throws Exception {
JPanel topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
//topPanel.setBackground(Color.PINK);
JPanel n = new JPanel();
topPanel.add(n,BorderLayout.NORTH);
renderHeader(n);
JPanel c = new JPanel();
c.setLayout(new BorderLayout());
topPanel.add(c,BorderLayout.CENTER);
renderBody(c);
JPanel f = new JPanel();
//f.setBackground(Color.BLUE);
topPanel.add(f,BorderLayout.SOUTH);
renderFooter(f);
//parent.setBackground(Color.CYAN);
parent.setLayout(new BorderLayout());
parent.add(topPanel);
}
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(entry.getListImage()!=null) {
JLabel l = new JLabel();
// TODO: hack images working
//l.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(entry.getHeaderImage())).getScaledInstance(32, 32, Image.SCALE_SMOOTH)));
if (entry.getListDescription()!=null) {
l.setToolTipText(i18n(entry.getListDescription()));
}
header.add(l,BorderLayout.WEST);
}
if(entry.getName()!=null) {
JLabel l = new JLabel(i18n(entry.getName()));
l.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
l.setFont(new Font(null,Font.BOLD, 18));
if (entry.getListDescription()!=null) {
l.setToolTipText(i18n(entry.getListDescription()));
}
header.add(l,BorderLayout.CENTER);
}
JPanel top = new JPanel();
//top.setBackground(Color.BLUE);
for (GlobalVascAction action:entry.getGlobalActions()) {
JButton but = new JButton();
but.setText(i18n(action.getName()));
but.setToolTipText(i18n(action.getDescription()));
but.addActionListener(new GlobalActionListener(action));
but.setIcon(getImageIcon(action.getImage()));
top.add(but);
}
// create options
JPanel optionPanel = new JPanel();
//top.setBackground(Color.GREEN);
//for(VascUserOption option:entry.getUserOptions()) {
// option.createUserOptionRenderer(entry);
//}
//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) {
VascColumnModel model = new VascColumnModel();
//TODO: entry.getVascEntryController().addEventListener(model);
JTable table = new JTable();
// this regs the listeners for the sorting
//tableSorter.setTableHeader(table.getTableHeader());
//tableSorter.setTableModel(model);
table.setModel(model);
table.getTableHeader().setReorderingAllowed(false);
// remove auto columns :(
int cols = table.getColumnModel().getColumnCount();
for (int i=0;i<cols;i++) {
TableColumn c = table.getColumnModel().getColumn(0); // idd, just remove index 0 every time
table.removeColumn(c);
}
table.revalidate();
TableCellRenderer renderer = new JComponentTableHeaderCellRenderer();
int counter=0;
for(VascEntryField c:entry.getVascEntryFields()) {
if (c.getList()==false) {
continue;
}
TableColumn t = new TableColumn();
if (c.getSizeList()!=null) {
t.setPreferredWidth(c.getSizeList());
} else {
t.setPreferredWidth(200);
}
t.setHeaderValue(c);
t.setHeaderRenderer(renderer);
t.setModelIndex(counter);
table.addColumn(t);
counter++;
}
table.getSelectionModel().addListSelectionListener(new EntrySectionListener(table));
table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
table.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 2) {
Object o = entry.getVascFrontendData().getVascEntryState().getEntryDataObject();
if (o==null) {
return;
}
try {
// todo: fix
entry.getVascFrontendData().getVascFrontend().renderEdit();
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, ee);
}
}
}
});
JScrollPane scrollPane = new JScrollPane(table);
parent2.add(scrollPane);
}
class EntrySectionListener implements ListSelectionListener {
JTable table;
EntrySectionListener(JTable table) {
this.table = table;
}
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
int rowIndex = table.getSelectedRow();
if (rowIndex!=-1) {
// temp; gets index by sorter
//rowIndex = tableSorter.modelIndex(rowIndex);
Object data = entry.getVascFrontendData().getVascEntryState().getEntryDataList().get(rowIndex);
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(data);
} else {
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(null);
}
}
}
class JComponentTableHeaderCellRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = 10L;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,boolean hasFocus, int row, int column) {
VascEntryField c = (VascEntryField)value;
setText(i18n(c.getName()));
setToolTipText(i18n(c.getDescription()));
if(c.getImage()!=null) {
setIcon(getImageIcon(c.getImage()));
} else {
setIcon(null);
}
if (entry != 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");
JPanel panel = new JPanel();
for(RowVascAction action:entry.getRowActions()) {
JButton but = new JButton();
but.setText(i18n(action.getName()));
but.setToolTipText(i18n(action.getDescription()));
but.setIcon(getImageIcon(action.getImage()));
but.addActionListener(new RowActionListener(action));
panel.add(but);
}
parent2.setLayout(new BorderLayout());
parent2.add(panel,BorderLayout.WEST);
}
class RowActionListener implements ActionListener {
private RowVascAction action = null;
public RowActionListener(RowVascAction action) {
this.action=action;
}
public void actionPerformed(ActionEvent event) {
logger.fine("Row Action");
try {
action.doRowAction(entry, entry.getVascFrontendData().getVascEntryState().getEntryDataObject());
} catch (Exception e) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
}
}
}
class GlobalActionListener implements ActionListener {
private GlobalVascAction action = null;
public GlobalActionListener(GlobalVascAction action) {
this.action=action;
}
public void actionPerformed(ActionEvent event) {
logger.fine("Global Action");
try {
action.doGlobalAction(entry);
} catch (Exception e) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
}
}
}
class VascColumnModel extends AbstractTableModel implements VascEntryFrontendEventListener {
private static final long serialVersionUID = 10L;
public void vascEvent(VascEntry entry,Object o) {
fireTableDataChanged();
}
/**
* @see javax.swing.entry.entryModel#getColumnCount()
*/
public int getColumnCount() {
int result = 0;
for(VascEntryField c:entry.getVascEntryFields()) {
if (c.getList()==false) {
continue;
}
result++;
}
return result;
}
/**
* @see javax.swing.entry.entryModel#getRowCount()
*/
public int getRowCount() {
if (entry.getVascFrontendData().getVascEntryState().getEntryDataList()==null) {
return 0;
}
return entry.getVascFrontendData().getVascEntryState().getEntryDataList().size();
}
/**
* @see javax.swing.entry.entryModel#getValueAt(int, int)
*/
public Object getValueAt(int rowIndex, int columnIndex) {
Object bean = entry.getVascFrontendData().getVascEntryState().getEntryDataList().get(rowIndex);
logger.finer("Rending column; "+columnIndex+" bean: "+bean);
// TODO: this is slowing....
List<VascEntryField> list = new ArrayList<VascEntryField>();
for(VascEntryField c:entry.getVascEntryFields()) {
if (c.getList()==false) {
continue;
}
list.add(c);
}
VascEntryField vtc = list.get(columnIndex);
try {
//if (vtc.getVascColumnRenderer()!=null) {
// return vtc.getVascColumnRenderer().rendererColumn(vtc,bean);
//} else {
return ""+vtc.getVascEntryFieldValue().getValue(vtc,bean);
// }
} catch (Exception e) {
return "Error";
}
}
public VascFrontendEventType[] getEventTypes() {
VascFrontendEventType[] result = {VascFrontendEventType.POST_UPDATE};
return result;
}
}
}
/**
* 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 {
/**
* 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) {
throw new IllegalArgumentException("parent container has not StringLayout layoutmanager.");
}
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) {
throw new IllegalArgumentException("parent container has not StringLayout layoutmanager.");
}
//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

@ -0,0 +1,138 @@
/*
* 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 net.forwardfire.vasc.frontends.swing.ui;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
/**
*
*
* @author Willem Cazander
* @version 1.0 Sep 21, 2007
*/
public class SwingBoolean implements VascUIComponent {
private JCheckBox checkBox = null;
private Color orgBackgroundColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
checkBox = new JCheckBox();
orgBackgroundColor = checkBox.getBackground();
checkBox.setSelected(new Boolean(model.getValue().toString()));
((JComponent)gui).add(checkBox);
checkBox.addActionListener(new SelectActionListener(model,table));
return checkBox;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (checkBox==null) {
return null;
}
return checkBox.getToolTipText();
}
/**
* @see net.forwardfire.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);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !checkBox.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
checkBox.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return checkBox.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
checkBox.setVisible(rendered);
}
}
class SelectActionListener implements ActionListener {
private VascValueModel model;
private VascEntry entry = null;
public SelectActionListener(VascValueModel model,VascEntry entry) {
this.model=model;
this.entry=entry;
}
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
boolean value = ((JCheckBox)e.getSource()).isSelected();
try {
model.setValue(value);
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
}

View file

@ -0,0 +1,113 @@
/*
* 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 net.forwardfire.vasc.frontends.swing.ui;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JComponent;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
/**
*
*
* @author Willem Cazander
* @version 1.0 Nov 18, 2008
*/
public class SwingButton implements VascUIComponent {
private JButton vascButton = null;
private Color orgBackgroundColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
vascButton = new JButton("Color");
orgBackgroundColor = vascButton.getBackground();
((JComponent)gui).add(vascButton);
//vascButton.addActionListener(new SelectActionListener3(model,true,table));
return vascButton;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (vascButton==null) {
return null;
}
return vascButton.getToolTipText();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String text) {
if (vascButton==null) {
return;
}
vascButton.setToolTipText(text);
if (text==null) {
vascButton.setBackground(orgBackgroundColor);
} else {
vascButton.setBackground(Color.RED);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !vascButton.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
vascButton.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return vascButton.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
vascButton.setVisible(rendered);
}
}

View file

@ -0,0 +1,170 @@
/*
* 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 net.forwardfire.vasc.frontends.swing.ui;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
/**
*
*
* @author Willem Cazander
* @version 1.0 Nov 25, 2007
*/
public class SwingColorChooser implements VascUIComponent {
private JButton colorButton = null;
private Color orgBackgroundColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
JButton colorButton = new JButton("Color");
orgBackgroundColor = colorButton.getBackground();
((JComponent)gui).add(colorButton);
colorButton.addActionListener(new SelectActionListener3(model,true,table));
return colorButton;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (colorButton==null) {
return null;
}
return colorButton.getToolTipText();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String text) {
if (colorButton==null) {
return;
}
colorButton.setToolTipText(text);
if (text==null) {
colorButton.setBackground(orgBackgroundColor);
} else {
colorButton.setBackground(Color.RED);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !colorButton.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
colorButton.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return colorButton.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
colorButton.setVisible(rendered);
}
}
class SelectActionListener3 implements ActionListener {
private VascValueModel model;
private boolean hexEncoding = false;
private VascEntry entry = null;
public SelectActionListener3(VascValueModel model,boolean hexEncoding,VascEntry entry) {
this.model=model;
this.hexEncoding=hexEncoding;
this.entry=entry;
}
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
if (hexEncoding==false) {
Color cur=null;
try {
cur = (Color)model.getValue();
} catch (VascException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (cur==null) {
cur = Color.YELLOW;
}
Color newColor = JColorChooser.showDialog(null,"Choose a color...",cur);
try {
model.setValue(newColor);
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
} else {
String cur=null;
try {
cur = (String)model.getValue();
} catch (VascException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Color c = Color.YELLOW;
try {
if (cur!=null) {
c = Color.decode(cur);
}
Color newColor = JColorChooser.showDialog(null,"Choose a color...",c);
String newColorString = "#"+Integer.toHexString( newColor.getRGB() & 0x00ffffff );
model.setValue(newColorString);
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
}
}

View file

@ -0,0 +1,144 @@
/*
* 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 net.forwardfire.vasc.frontends.swing.ui;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.util.Date;
import javax.swing.JComponent;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
import com.michaelbaranov.microba.calendar.DatePicker;
/**
*
*
* @author Willem Cazander
* @version 1.0 Sep 21, 2007
*/
public class SwingDate implements VascUIComponent {
private DatePicker datePicker = null;
private Color orgBackgroundColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
datePicker = new DatePicker();
orgBackgroundColor = datePicker.getBackground();
try {
datePicker.setDate((Date)model.getValue());
} catch (PropertyVetoException e) {
throw new VascException(new VascException(e));
}
((JComponent)gui).add(datePicker);
datePicker.addActionListener(new SelectActionListener2(model,table));
return datePicker;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (datePicker==null) {
return null;
}
return datePicker.getToolTipText();
}
/**
* @see net.forwardfire.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);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !datePicker.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
datePicker.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return datePicker.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
datePicker.setVisible(rendered);
}
}
class SelectActionListener2 implements ActionListener {
private VascValueModel model;
private VascEntry entry = null;
public SelectActionListener2(VascValueModel model,VascEntry entry) {
this.model=model;
this.entry=entry;
}
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
Date value = ((DatePicker)e.getSource()).getDate();
try {
model.setValue(value);
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
}

View file

@ -0,0 +1,114 @@
/*
* 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 net.forwardfire.vasc.frontends.swing.ui;
import java.awt.Color;
import javax.swing.JComponent;
import javax.swing.JLabel;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
/**
*
* @author Willem Cazander
* @version 1.0 Sep 21, 2008
*/
public class SwingLabel implements VascUIComponent {
private JLabel label = null;
private Color orgBackgroundColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
label = new JLabel();
label.setHorizontalAlignment(JLabel.TRAILING);
orgBackgroundColor = label.getBackground();
label.setText(""+model.getValue());
((JComponent)gui).add(label);
return label;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (label==null) {
return null;
}
return label.getToolTipText();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String text) {
if (label==null) {
return;
}
label.setToolTipText(text);
if (text==null) {
label.setBackground(orgBackgroundColor);
} else {
label.setBackground(Color.RED);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !label.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
label.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return label.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
label.setVisible(rendered);
}
}

View file

@ -0,0 +1,172 @@
/*
* 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 net.forwardfire.vasc.frontends.swing.ui;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascSelectItem;
import net.forwardfire.vasc.core.ui.VascSelectItemModel;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
/**
*
* @author Willem Cazander
* @version 1.0 Aug 12, 2007
*/
public class SwingList implements VascUIComponent {
private JComboBox comboBox = null;
private Color orgBackgroundColor = null;
public Object createComponent(final VascEntry entry,VascEntryField entryField,final VascValueModel model,Object gui) throws VascException {
VascSelectItemModel items = (VascSelectItemModel)entryField.getVascEntryFieldType().getDataObject();
if (items==null) {
comboBox = new JComboBox();
} else {
comboBox = new JComboBox(items.getVascSelectItems(entry).toArray());
}
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();
try {
model.setValue(i.getValue());
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
});
// set default !!
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;
}
}
}
if (comboBox.getModel().getSize()>0) {
// else select the top one.
comboBox.setSelectedIndex(0);
}
return comboBox;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (comboBox==null) {
return null;
}
return comboBox.getToolTipText();
}
/**
* @see net.forwardfire.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);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !comboBox.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
comboBox.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return comboBox.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
comboBox.setVisible(rendered);
}
}
class MyCellRenderer extends JLabel implements ListCellRenderer {
private static final long serialVersionUID = 10L;
public MyCellRenderer() {
setOpaque(true);
}
public Component getListCellRendererComponent(JList list,Object value,int index,boolean isSelected,boolean cellHasFocus) {
VascSelectItem i = (VascSelectItem)value;
if (i!=null) {
setText(i.getLabel());
} else {
setText("Error");
}
return this;
}
}

View file

@ -0,0 +1,161 @@
/*
* 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 net.forwardfire.vasc.frontends.swing.ui;
import java.awt.Color;
import javax.swing.JComponent;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
/**
*
* @author Willem Cazander
* @version 1.0 Aug 12, 2007
*/
public class SwingText implements VascUIComponent {
private JTextField textField = null;
private Color orgBackgroundColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
textField = new JTextField();
orgBackgroundColor = textField.getBackground();
textField.setText(""+model.getValue());
((JComponent)gui).add(textField);
textField.getDocument().addDocumentListener(new TextListener(model,table,this));
return textField;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (textField==null) {
return null;
}
return textField.getToolTipText();
}
/**
* @see net.forwardfire.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);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !textField.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
textField.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return textField.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
textField.setVisible(rendered);
}
}
class TextListener implements DocumentListener {
private VascValueModel model = null;
//private VascTable table = null;
private SwingText textField = null;
public TextListener(VascValueModel model,VascEntry table,SwingText textField) {
this.model=model;
//this.table=table;
this.textField=textField;
}
/**
* @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
*/
public void changedUpdate(DocumentEvent e) {
update(e);
}
/**
* @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
*/
public void insertUpdate(DocumentEvent e) {
update(e);
}
/**
* @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());
model.setValue(value);
textField.setErrorText(null);
} catch (Exception ee) {
textField.setErrorText(ee.getLocalizedMessage());
//table.getVascTableController().handleException(ee, table);
}
}
}

View file

@ -0,0 +1,168 @@
/*
* 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 net.forwardfire.vasc.frontends.swing.ui;
import java.awt.Color;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JTextArea;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
/**
*
* @author Willem Cazander
* @version 1.0 Sep 21, 2008
*/
public class SwingTextArea implements VascUIComponent {
private JTextArea textArea = null;
private Color orgBackgroundColor = null;
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
textArea = new JTextArea();
textArea.setBorder(BorderFactory.createEtchedBorder());
textArea.setRows(8);
//entryField.getVascEntryFieldType().getProperty(name)
//textArea.setRows(rows);
//textArea.setColumns(columns);
orgBackgroundColor = textArea.getBackground();
textArea.setText(""+model.getValue());
((JComponent)gui).add(textArea);
textArea.getDocument().addDocumentListener(new TextAreaListener(model,entry,this));
return textArea;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (textArea==null) {
return null;
}
return textArea.getToolTipText();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String text) {
if (textArea==null) {
return;
}
textArea.setToolTipText(text);
if (text==null) {
textArea.setBackground(orgBackgroundColor);
} else {
textArea.setBackground(Color.RED);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !textArea.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
textArea.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return textArea.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
textArea.setVisible(rendered);
}
}
class TextAreaListener implements DocumentListener {
private VascValueModel model = null;
private SwingTextArea textArea = null;
public TextAreaListener(VascValueModel model,VascEntry entry,SwingTextArea textArea) {
this.model=model;
this.textArea=textArea;
}
/**
* @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
*/
public void changedUpdate(DocumentEvent e) {
update(e);
}
/**
* @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
*/
public void insertUpdate(DocumentEvent e) {
update(e);
}
/**
* @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());
model.setValue(value);
textArea.setErrorText(null);
} catch (Exception ee) {
textArea.setErrorText(ee.getLocalizedMessage());
//table.getVascTableController().handleException(ee, table);
}
}
}

View file

@ -0,0 +1,131 @@
/*
* 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 net.forwardfire.vasc;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.frontends.swing.SwingVascFrontend;
import junit.framework.TestCase;
/**
* Tests a simple x4o xml language.
*
* @author Willem Cazander
* @version 1.0 Jul 24, 2006
*/
public class SwingTest extends TestCase {
public void setUp() throws Exception {
// enable all logs
//InputStream loggingProperties = this.getClass().getResourceAsStream("META-INF/logging.properties");
//LogManager.getLogManager().readConfiguration( loggingProperties );
//loggingProperties.close();
}
public void tearDown() throws Exception {
}
public void testNull() throws Exception {
assertEquals(true, true);
//main(new String[] {});
}
public static void main(String[] argu){
JFrame.setDefaultLookAndFeelDecorated(false);
try {
VascEntry entry = TestTable.getVascTable();
SwingTest s = new SwingTest();
JFrame frame = s.viewEntry(entry);
while (frame.isVisible()) {
Thread.sleep(100000);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public JFrame viewEntry(final VascEntry entry) throws Exception {
// get GUI
JFrame frame = new JFrame();
frame.setTitle("Vasc Test - Swing - "+entry.getName());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLocationRelativeTo(null);
JMenuBar menubar = new JMenuBar();
JMenu vascMenu = new JMenu("Vasc Entries");
for (final String id:entry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryIds()) {
JMenuItem item = new JMenuItem(id);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
VascEntry ee = entry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryById(id);
TestTable.fill(ee,entry.getVascFrontendData().getVascController());
viewEntry(ee);
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
vascMenu.add(item);
}
menubar.add(vascMenu);
frame.setJMenuBar(menubar);
// define redering
JPanel panel = new JPanel();
SwingVascFrontend render = new SwingVascFrontend(panel);
frame.add(panel);
// render
render.initEntry(entry);
render.renderView();
// get data
entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry);
// view
frame.pack();
frame.setVisible(true);
return frame;
}
}

View file

@ -0,0 +1,173 @@
/*
* 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 net.forwardfire.vasc;
import java.util.Date;
import net.forwardfire.vasc.annotations.VascDefaultValue;
import net.forwardfire.vasc.annotations.VascEntry;
import net.forwardfire.vasc.annotations.VascI18n;
import net.forwardfire.vasc.annotations.VascModelReference;
import net.forwardfire.vasc.annotations.VascStyle;
import net.forwardfire.vasc.validators.VascDateFuture;
import net.forwardfire.vasc.validators.VascObjectNotNull;
import net.forwardfire.vasc.validators.VascStringLength;
//import org.hibernate.validator.NotNull;
//import org.hibernate.validator.Max;
/**
* TestModel
*
*
* @author Willem Cazander
* @version 1.0 Mar 28, 2007
*/
@VascEntry(headerName="En een tooltip op het model")
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;
private String hexColor = null;
//private Node nonEditorField = null;
/**
* @return the date
*/
@VascDateFuture
public Date getDate() {
return date;
}
/**
* @param date the date to set
*/
public void setDate(Date date) {
this.date = date;
}
/**
* @return the description
*/
@VascI18n( name="omscheiving",
description="De omscrijving",
image="/resources/images/gabelfresser.gif",
helpId="help.id")
@VascDefaultValue(value="xxxxx")
@VascStyle(sizeList=200)
// @NotNull
// @Max(value=10)
@VascObjectNotNull
@VascStringLength(max=10)
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the price
*/
public Float getPrice() {
return price;
}
/**
* @param price the price to set
*/
public void setPrice(Float price) {
this.price = price;
}
// @NotNull
@VascObjectNotNull
@VascModelReference
@VascI18n(image="/resources/images/gabelfresser.gif")
public TestModel getTestModel() {
return 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;
}
/**
* @return the hexColor
*/
public String getHexColor() {
return hexColor;
}
/**
* @param hexColor the hexColor to set
*/
public void setHexColor(String hexColor) {
this.hexColor = hexColor;
}
}

View file

@ -0,0 +1,149 @@
/*
* 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 net.forwardfire.vasc;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import net.forwardfire.vasc.core.AbstractVascBackend;
import net.forwardfire.vasc.core.VascBackendState;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
import net.forwardfire.vasc.core.ui.VascSelectItem;
import net.forwardfire.vasc.core.ui.VascSelectItemModel;
import net.forwardfire.vasc.impl.entry.BeanPropertyVascEntryFieldValue;
import net.forwardfire.vasc.impl.entry.BeanVascEntryRecordCreator;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 21, 2007
*/
public class TestModelVascDataSource extends AbstractVascBackend implements VascSelectItemModel {
private List<Object> testModels = null;
private String nullLabel = null;
private String nullKeyValue = null;
public TestModelVascDataSource() {
testModels = new ArrayList<Object>(2);
TestModel t = new TestModel();
t.setDate(new Date());
t.setDescription("yoyo test");
t.setName("this Name");
t.setPrice(34.1f);
t.setActive(true);
t.setHexColor("#FF66EE");
testModels.add(t);
t = new TestModel();
t.setDate(new Date());
t.setDescription("Model2 test");
t.setName("BeanSourde");
t.setPrice(19.2f);
t.setActive(false);
t.setTestModel((TestModel)testModels.get(0));
testModels.add(t);
}
public TestModelVascDataSource(List<Object> testModels) {
this.testModels=testModels;
}
public List<Object> execute(VascBackendState state) throws VascException {
return testModels;
}
public void persist(Object object) throws VascException {
testModels.add(object);
}
public Object merge(Object object) throws VascException {
if(testModels.contains(object)==false) {
testModels.add(object);
}
return object;
}
public void delete(Object object) throws VascException {
testModels.remove(object);
}
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
return new BeanPropertyVascEntryFieldValue(field.getBackendName());
}
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return new BeanVascEntryRecordCreator(TestModel.class);
}
// --- VascSelectItemModel interface
public List<VascSelectItem> getVascSelectItems(VascEntry entry) {
List<VascSelectItem> res = new ArrayList<VascSelectItem>(4);
for (Object o:testModels) {
TestModel t = (TestModel)o;
VascSelectItem i = new VascSelectItem(t.getName(),t);
res.add(i);
}
return res;
}
/**
* @return the nullLabel
*/
public String getNullLabel() {
return nullLabel;
}
/**
* @param nullLabel the nullLabel to set
*/
public void setNullLabel(String nullLabel) {
this.nullLabel = nullLabel;
}
/**
* @return the nullKeyValue
*/
public String getNullKeyValue() {
return nullKeyValue;
}
/**
* @param nullKeyValue the nullKeyValue to set
*/
public void setNullKeyValue(String nullKeyValue) {
this.nullKeyValue = nullKeyValue;
}
}

View file

@ -0,0 +1,154 @@
/*
* 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 net.forwardfire.vasc;
import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Method;
import java.util.Locale;
import net.forwardfire.vasc.core.VascBackend;
import net.forwardfire.vasc.core.VascBackendControllerLocal;
import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.VascFrontendData;
import net.forwardfire.vasc.impl.DefaultVascBackedEntryFinalizer;
import net.forwardfire.vasc.impl.DefaultVascFactory;
import net.forwardfire.vasc.impl.DefaultVascFrontendData;
import net.forwardfire.vasc.impl.DefaultVascFrontendHelper;
import net.forwardfire.vasc.impl.VascBackendProxyPaged;
import net.forwardfire.vasc.impl.VascBackendProxySearch;
import net.forwardfire.vasc.impl.VascBackendProxySort;
import net.forwardfire.vasc.impl.actions.AddRowAction;
import net.forwardfire.vasc.impl.actions.CSVExportGlobalAction;
import net.forwardfire.vasc.impl.actions.DeleteRowAction;
import net.forwardfire.vasc.impl.actions.EditRowAction;
import net.forwardfire.vasc.impl.actions.RefreshDataGlobalAction;
import net.forwardfire.vasc.impl.actions.XMLExportGlobalAction;
import net.forwardfire.vasc.impl.x4o.VascParser;
/**
*
* @author Willem Cazander
* @version 1.0 Aug 2, 2007
*/
public class TestTable {
static VascController getDefaultVascController() throws Exception {
VascController c = DefaultVascFactory.getDefaultVascController(2288L,"idca.nl","user","admin");
// for test
TestModelVascDataSource backend = new TestModelVascDataSource();
backend.setId("testBackend1");
((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(backend);
return c;
}
static public void fill(VascEntry entry,VascController vascController) {
VascFrontendData frontendData = DefaultVascFactory.getDefaultVascFrontendData(null); //DefaultVascFactory.getDefaultVascFrontendData("i18n.vasc", Locale.getDefault());
frontendData.setVascController(vascController);
entry.setVascFrontendData(frontendData);
VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry);
frontendData.getVascEntryState().setVascBackend(backend);
frontendData.getVascEntryState().setVascEntry(entry);
entry.addRowAction(new AddRowAction());
entry.addRowAction(new EditRowAction());
entry.addRowAction(new DeleteRowAction());
entry.addGlobalAction(new XMLExportGlobalAction());
entry.addGlobalAction(new CSVExportGlobalAction());
entry.addGlobalAction(new RefreshDataGlobalAction());
// hackje om deze manuale actions van i18n keys te voorzien;
// this is temp untill x4o templaing
DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer();
try {
f.finalizeVascEntry(entry, vascController);
} catch (VascException e) {
e.printStackTrace();
}
}
static public VascEntry getVascTable() throws Exception {
VascController c = getDefaultVascController();
VascParser parser = new VascParser(c);
File f = File.createTempFile("test-vasc", ".xml");
parser.setDebugOutputStream(new FileOutputStream(f));
parser.parseResource("net/forwardfire/vasc/tables.xml");
VascEntry entry = parser.getVascController().getVascEntryController().getVascEntryById("test1");
fill(entry,c);
return entry;
}
static void printEntry(VascEntry e) throws Exception {
System.out.println("");
System.out.println("=== Printing entry ===");
System.out.println("");
for (Method m:e.getClass().getMethods()) {
if (m.getName().startsWith("get")==false) { //a bit dirty
continue;
}
if (m.getParameterTypes().length>0) {
continue;
}
System.out.println("prop: "+m.getName()+" -> "+m.invoke(e));
}
System.out.println("");
System.out.println("=== Fields ===");
for (VascEntryField vef:e.getVascEntryFields()) {
System.out.println("=== Field: "+vef.getId());
for (Method m:vef.getClass().getMethods()) {
if (m.getName().startsWith("get")==false) { //a bit dirty
continue;
}
if (m.getParameterTypes().length>0) {
continue;
}
System.out.println("prop: "+m.getName()+" -> "+m.invoke(vef));
}
}
}
}

View file

@ -0,0 +1,318 @@
<?xml version="1.0" encoding="UTF-8"?>
<x4o:root xmlns:v="http://vasc.idcanet.com/eld/vasc-lang.eld"
xmlns:x4o="http://eld.x4o.org/eld/x4o-lang.eld"
>
<!--
<v:simpleJdbcConnectionProvider
el.id="dbDatafeeds"
driverClassName="org.postgresql.Driver"
dbUrl="jdbc:postgresql://db0.dev.lan.mbuyu.nl/datafeeds_dev"
dbUser="mbuyu"
dbPassword="eephoh2O"
/>
<v:jdbcBackend
id="dbStreams"
jdbcConnectionProvider="${dbDatafeeds}"
idColumnName="id"
sqlList="SELECT * FROM stream LIMIT 100"
sqlDelete="DELETE FROM stream WHERE id = ?0"
sqlPersist="INSERT INTO stream (name,url,importing,etc) VALUES (?0,?1,?2,?3,?4)"
sqlMerge="UPDATE stream (name,url) VALUE (?0,?1)"
/>
<v:entry id="streams" backendId="dbStreams">
<v:field id="id" readOnly="true"/>
<v:field id="name"/>
<v:field id="url"/>
<v:field id="importing" vascEntryFieldType="BooleanField"/>
<v:field id="last_parsed" vascEntryFieldType="DateField" />
<v:field id="last_checked" vascEntryFieldType="DateField"/>
<v:field id="parser_locale" list="false"/>
<v:field id="column_mapping" list="false"/>
</v:entry>
<v:simpleLdapConnectionProvider
el.id="ldapSudoers"
ldapHost="ldap2.lan.mbuyu.nl"
bindUser="uid=admin-sudo,ou=services,dc=m4n,dc=nl"
bindPass="adminSudo"
/>
<v:ldapBackend
id="ldapBackendSudoers"
ldapConnectionProvider="${ldapSudoers}"
baseDN="ou=sudoers,dc=m4n,dc=nl"
keyAttribute="cn"
ldapFilter="(&amp;(objectClass=sudoRole))"
/>
-->
<!--
<v:entry id="sudoers" backendId="ldapBackendSudoers">
<v:field id="user" backendName="cn" readOnly="true"/>
<v:field id="description" rolesEdit="admin" rolesList="all"/>
<v:field id="sudoCommand" vascEntryFieldType="MultiTextField"/>
<v:field id="sudoHost" vascEntryFieldType="MultiTextField"/>
<v:field id="sudoUser" vascEntryFieldType="MultiTextField"/>
<v:ldapNextIdFunction name="nextUidNumber" ldapFilter="(&(objectClass=posixGroup))" ldapAttribute="gidnumber"/>
<v:listeners hook="post_create">
<etc:loginToFtpServer/>
</v:listeners>
<v:link fieldName="user" viewController="ldapUsers" parameterName="user_cn"/>
<v:link fieldName="gidNumber" viewController="ldapGroups" parameterName="group_key,${baseDn}"/>
<v:detail fieldName="gidNumber" detailController="${ldapGroups}"/>
</v:entry>
-->
<!--
<v:simpleLdapConnectionProvider
el.id="ldapUsers"
ldapHost="ldap2.lan.mbuyu.nl"
bindUser="uid=admin-users,ou=services,dc=m4n,dc=nl"
bindPass="superAU"
/>
<v:ldapBackend
id="ldapBackendUsers"
ldapConnectionProvider="${ldapUsers}"
baseDN="ou=users,dc=m4n,dc=nl"
keyAttribute="uid"
ldapFilter="(&amp;(objectClass=posixAccount))"
/>
<v:entry id="users" backendId="ldapBackendUsers">
<v:field id="uid" />
<v:field id="uidNumber" vascEntryFieldType="IntegerField"/>
<v:field id="gidNumber" vascEntryFieldType="IntegerField"/>
<v:field id="loginShell" list="false"/>
<v:field id="homeDirectory" list="false"/>
<v:field id="cn" list="false"/>
<v:field id="givenName" />
<v:field id="sn" />
<v:field id="mailbox" list="false"/>
<v:field id="mail" vascEntryFieldType="EmailField"/>
<v:field id="mailActive" vascEntryFieldType="BooleanField"/>
<v:field id="alias" vascEntryFieldType="MultiTextField" list="false"/>
<v:field id="autoResponseActive" vascEntryFieldType="BooleanField" />
<v:field id="autoresponseMessage" vascEntryFieldType="TextAreaField" list="false"/>
<v:field id="sambaAcctFlags" list="false"/>
<v:field id="sambaPrimaryGroupSID" list="false"/>
<v:field id="sambaSID" list="false"/>
<v:field id="m4nVPNActive" vascEntryFieldType="BooleanField"/>
<v:field id="m4nDateInService" />
<v:field id="m4nDateOutService" />
<v:field id="m4nUserId" vascEntryFieldType="IntegerField"/>
<v:field id="m4nHosts" vascEntryFieldType="MultiTextField"/>
</v:entry>
<v:simpleLdapConnectionProvider
el.id="ldapMachines"
ldapHost="ldap2.lan.mbuyu.nl"
bindUser="uid=samba,ou=services,dc=m4n,dc=nl"
bindPass="superS"
/>
<v:ldapBackend
id="ldapBackendMachines"
ldapConnectionProvider="${ldapMachines}"
baseDN="ou=machines,dc=m4n,dc=nl"
keyAttribute="uid"
ldapFilter="(&amp;(objectClass=sambaSamAccount))"
/>
<v:entry id="machines" backendId="ldapBackendMachines">
<v:field id="uid" />
<v:field id="sambaAcctFlags"/>
<v:field id="sambaSID" />
<v:field id="uidNumber" />
</v:entry>
-->
<v:entry id="test1" backendId="testBackend1">
<v:field id="name" defaultValue=""/>
<v:field id="description" vascEntryFieldType="EmailField" defaultValue="email@address.nl"/>
<v:field id="active" defaultValue="true"/>
<v:field id="date" vascEntryFieldType="DateField" defaultValue=""/>
<v:field id="hexColor" vascEntryFieldType="ColorField" defaultValue="#FF3355"/>
<v:field id="testModel" vascEntryFieldType="ListField" dataObject="$myBean.testBackend1"
vascEntryFieldType.dataObject="#{vascController.vascBackendControllerResolver.vascBackendController.vascBackendById('testBackend1')}"
/>
</v:entry>
<!--
- View
- States
- Tables
- Columns
Master
- Details
-->
<!--
<x4o:bean el.id="dataSource" bean.class="com.id.."/>
<x4o:bean el.id="tableController" bean.class="com.id.."/>
<v:vascView name="test1">
<v:vascTableController>
</v:vascTableController>
<v:vascBackendController>
<v:vascJDBCQueryController>
<x4o:property name="list">select id,name,blog_status_id,description,slug from blog_post</x4o:property>
<x4o:property name="update">update (id,name,blog_status_id,description,slug) values(?,?,?,?,?) from blog_post where id=?</x4o:property>
<x4o:property name="create">instert into (id,name,blog_status_id,description,slug) values(?,?,?,?,?) from blog_post where id=?</x4o:property>
<x4o:property name="delete">delete from blog_post where id=?</x4o:property>
</v:vascJDBCQueryController>
</v:vascBackendController>
<v:vascField name="">
<v:vascFieldOptions/>
<v:vascFieldChoises/>
</v:vascField>
<v:vascField name="">
<v:vascUserRoles list="admin"/>
</v:vascField>
</v:vascView>
<x4o:template el.id="ldapServerTemplate">
<v:ldapConnection name="main">
<x4o:property name="connectionUrl" value="ldaps://ldap.office.mbuyu.nl"/>
</v:ldapConnection>
</x4o:template>
<v:ldapConnection el.id="sudoers" x4o.templates="ldapServerTemplate">
<x4o:property name="user" value="uid=admin-sudo,ou=services,dc=m4n,dc=nl"/>
<x4o:property name="pass" value="adminSudo"/>
<x4o:property name="baseDn" value="ou=sudoers,dc=m4n,dc=nl"/>
</v:ldapConnection>
<x4o:template el.id="sudoTemplate">
<v:field name="user" backendName="cn" readOnly="true"/>
<v:field name="description" backendName="description"/>
<v:field name="sudoCommand" fieldEditor="listField"/>
<v:field name="sudoHost" fieldEditor="listField"/>
<v:field name="sudoUser" fieldEditor="listField"/>
</x4o:template>
<x4o:template el.id="sambaUserSchema">
<v:field name="sambaSID" fieldEditor="textField" edit="false" list="false" view="false" create="false" defaultValue="S-1-5-21-1200182392-965607725-1867741125-514"/>
<v:field name="sambaGroupType" v.defaultValue="2"/>
</x4o:template>
<v:viewController name="ldapUsers" primaryKey="user">
<x4o:templateTag template="${posixUserSchema}"/>
<x4o:templateTag template="${sambaUserSchema}">
<v:field name="sambaGroupType" v.defaultValue="3"/>
</x4o:templateTag>
<v:field name="sambaGroupType" v.defaultValue="4"/>
</v:viewController>
<vasc:fieldType name="EmailField2">
<vasc:fieldHint key="validate" default="true"/>
<vasc:fieldHint key="timeout" default="200"/>
</vasc:fieldType>
<vasc:fieldType name="listField">
<vasc:fieldHint key="validate" default="true"/>
<vasc:fieldHint key="timeout" default="200"/>
</vasc:fieldType>
-->
<v:entry id="test2" backendId="testBackend1">
<v:field id="name"/>
<v:field id="description"/>
<v:field id="active"/>
<v:field id="testModel" vascEntryFieldType="ListField"/>
</v:entry>
<v:entry
id="test3"
helpId="someHelpKey"
image="imsdf"
headerName="sdf"
headerDescription="sdfsdf"
headerImage="sdfsdfsd"
primaryKeyFieldId="name"
displayNameFieldId="name"
vascDisplayOnly="false"
vascAdminList="true"
vascAdminEdit="true"
vascAdminCreate="true"
vascAdminDelete="true"
backendId="testBackend1"
>
<v:field id="name"/>
<v:field
id="active"
backendName="active"
name="active"
description="active"
helpId="active"
image="active"
defaultValue="true"
sizeList="100"
sizeEdit="80"
styleList="styleClass"
styleEdit="styleClass"
choices=""
choicesAsRadio="false"
view="true"
optional="false"
create="true"
edit="true"
editReadOnly="false"
editBlank="false"
list="true"
rolesCreate="admin|manager"
rolesEdit=""
rolesEditReadOnly=""
rolesList=""
vascEntryFieldType=""
vascEntryFieldEventChannel=""
>
<v:intSizeValidator min="20"/>
</v:field>
<v:fieldSet
id="set1"
vascEntryFieldIds="name,active"
name="set1"
description="set1"
helpId="set1"
image="set1"
styleList="styleClass"
styleEdit="styleClass"
collapsed="false"
optional="false"
/>
</v:entry>
</x4o:root>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>vasc-frontend-swt</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
#Sun Dec 25 17:29:07 CET 2011
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View file

@ -0,0 +1,6 @@
#Mon Aug 30 21:56:52 CEST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5

View file

@ -0,0 +1,5 @@
#Sun Dec 25 17:29:02 CET 2011
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View file

@ -0,0 +1,9 @@
#Mon Aug 30 21:56:51 CEST 2010
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1

View file

@ -0,0 +1,147 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vasc-frontends</artifactId>
<groupId>net.forwardfire.vasc</groupId>
<version>0.3.5-SNAPSHOT</version>
</parent>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-frontend-swt</artifactId>
<version>0.3.5-SNAPSHOT</version>
<name>vasc-frontend-swt</name>
<description>vasc-frontend-swt</description>
<dependencies>
<dependency>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-core</artifactId>
<version>${project.version}</version>
</dependency>
<!-- SWT depency TODO: linux only, wait for 3.4 !!
<dependency>
<groupId>org.eclipse.swt.gtk.linux</groupId>
<artifactId>x86</artifactId>
<version>3.3.0-v3346</version>
<scope>compile</scope>
<optional />
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>jface</artifactId>
<version>3.3.0-I20070606-0010</version>
<scope>compile</scope>
<optional />
</dependency>
-->
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>jface</artifactId>
<version>3.2.1-M20060908-1000</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<!-- Eclipse OS-specific dependencies -->
<profiles>
<profile>
<id>linux-x86</id>
<activation>
<os>
<arch>i386</arch>
<family>unix</family>
<name>linux</name>
</os>
</activation>
<dependencies>
<dependency>
<groupId>org.eclipse.swt.gtk.linux</groupId>
<artifactId>x86</artifactId>
<version>[3.2.0,4.0.0)</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>linux-x86_64</id>
<activation>
<os>
<arch>amd64</arch>
<family>unix</family>
<name>linux</name>
</os>
</activation>
<dependencies>
<dependency>
<groupId>org.eclipse.swt.gtk.linux</groupId>
<artifactId>x86_64</artifactId>
<version>[3.2.0,4.0.0)</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>solaris-sparc</id>
<activation>
<os>
<arch>sparc</arch>
<family>unix</family>
<name>SunOS</name>
</os>
</activation>
<dependencies>
<dependency>
<groupId>org.eclipse.swt.gtk.solaris</groupId>
<artifactId>sparc</artifactId>
<version>[3.2.0,4.0.0)</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>macosx</id>
<activation>
<os>
<family>unix</family>
<name>mac os x</name>
</os>
</activation>
<dependencies>
<dependency>
<groupId>org.eclipse.swt.carbon</groupId>
<artifactId>macosx</artifactId>
<version>[3.2.0,4.0.0)</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>win32</id>
<activation>
<os>
<arch>x86</arch>
<family>windows</family>
</os>
</activation>
<dependencies>
<dependency>
<groupId>org.eclipse.swt.win32.win32</groupId>
<artifactId>x86</artifactId>
<version>[3.2.0,4.0.0)</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>win64</id>
<activation>
<os>
<arch>amd64</arch>
<family>windows</family>
</os>
</activation>
<dependencies>
<dependency>
<groupId>org.eclipse.swt.win32.win32</groupId>
<artifactId>x86_64</artifactId>
<version>[3.2.0,4.0.0)</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>

View file

@ -0,0 +1,231 @@
/*
* 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 net.forwardfire.vasc.frontends.swt;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascColumnValueModelListener;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
/**
*
* @author Willem Cazander
* @version 1.0 May 13, 2009
*/
public class SwtVascEditDialog extends Dialog {
private VascEntry entry = null;
private Shell shell = null;
public SwtVascEditDialog (VascEntry entry) {
super (Display.getCurrent().getActiveShell(), 0);
this.entry=entry;
}
protected String i18n(String key,Object...params) {
return entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key,params);
}
protected Object i18nImage(String key) {
if (entry.getVascFrontendData().getVascEntryResourceImageResolver()==null) {
return null;
}
return entry.getVascFrontendData().getVascEntryResourceImageResolver().getImageValue(entry,key);
}
public void open() throws VascException {
shell = new Shell(getParent(), SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
shell.setText(i18n(entry.getName()));
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
shell.setLayout(layout);
Composite header = new Composite(shell, SWT.NONE);
GridLayout headerLayout = new GridLayout();
headerLayout.numColumns = 6;
header.setLayout(headerLayout);
header.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite body = new Composite(shell, SWT.NONE);
GridLayout bodyLayout = new GridLayout();
bodyLayout.numColumns = 1;
body.setLayout(bodyLayout);
body.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite footer = new Composite(shell, SWT.NONE);
GridLayout footerLayout = new GridLayout();
footerLayout.numColumns = 6;
footer.setLayout(footerLayout);
footer.setLayoutData(new GridData(SWT.NONE));
createHeader(header);
createBody(body);
createFooter(footer);
shell.pack();
shell.open();
Display display = shell.getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
public void createHeader(Composite header) {
String displayFieldId = entry.getDisplayNameFieldId();
VascEntryField dis = entry.getVascEntryFieldById(displayFieldId);
if (dis==null) {
throw new RuntimeException("Could not find: "+displayFieldId+" from: "+entry.getId());
}
String name = null;
try {
Object bean = entry.getVascFrontendData().getVascEntryState().getEntryDataObject();
name = dis.getVascEntryFieldValue().getDisplayValue(dis, bean);
} catch (VascException e) {
throw new RuntimeException("Could not display value from "+entry.getId(),e);
}
Color c = new Color(header.getDisplay(),255,255,255);
header.setBackground(c);
Label img = new Label(header, SWT.NONE);
if (entry.getVascFrontendData().getVascEntryState().isEditCreate()) {
img.setImage((Image)i18nImage(entry.getCreateImage()));
} else {
img.setImage((Image)i18nImage(entry.getEditImage()));
}
img.setBackground(c);
Font headerFont = new Font(header.getDisplay(), "verdana", 14, SWT.NONE);
Label l = new Label(header, SWT.CENTER);
if (entry.getVascFrontendData().getVascEntryState().isEditCreate()) {
l.setText(i18n(entry.getCreateDescription(),name));
} else {
l.setText(i18n(entry.getEditDescription(),name));
}
l.setFont(headerFont);
l.setBackground(c);
}
public void createBody(Composite body) throws VascException {
body.setLayout(new GridLayout(2, true));
body.setLayoutData(new GridData(GridData.FILL_BOTH));
Object bean = entry.getVascFrontendData().getVascEntryState().getEntryDataObject();
entry.getVascFrontendData().clearFieldRenderObjects(); // only needed for swt use
for (VascEntryField c:entry.getVascEntryFields()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderEdit(c)==false) {
continue;
}
for (int i=0;i<c.getVascEntryFieldType().getUIComponentCount(c);i++) {
VascUIComponent label = c.getVascEntryFieldType().provideLabelUIComponent(i,c);
VascValueModel model = new VascValueModel();
model.setValue(i18n(c.getName()));
Control realLabel = (Control)label.createComponent(entry,c,model,body);
realLabel.setToolTipText(i18n(c.getDescription()));
VascUIComponent editor = c.getVascEntryFieldType().provideEditorUIComponent(i,c);
model = new VascValueModel(c.getVascEntryFieldType().provideEditorVascValueModel(i,c));
model.setValue(c.getVascEntryFieldValue().getValue(c, bean));
model.addListener(new VascColumnValueModelListener(c,bean));
Control edit = (Control )editor.createComponent(entry,c,model,body);
if (edit.getLayoutData()==null) { // is for textarea which has custum layout data
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.FILL;
edit.setLayoutData(gridData);
}
if (i==0) {
entry.getVascFrontendData().addFieldVascUIComponents(c, editor,edit);
}
}
}
entry.getVascFrontendData().getVascFrontendHelper().editReadOnlyUIComponents(entry);
}
public void createFooter(Composite body) {
Button saveButton = new Button(body, SWT.NONE);
saveButton.setImage((Image)i18nImage("vasc.action.saveAction.image"));
saveButton.setText(i18n("vasc.action.saveAction.name"));
saveButton.setToolTipText(i18n("vasc.action.saveAction.description"));
saveButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
try {
boolean error = entry.getVascFrontendData().getVascFrontendHelper().validateAndSetErrorText(entry);
if (error) {
return;
}
entry.getVascFrontendData().getVascFrontendHelper().mergeObject(entry);
shell.dispose();
} catch (Exception ee) {
ee.printStackTrace();
}
}
});
Button cancelButton = new Button(body, SWT.NONE);
cancelButton.setImage((Image)i18nImage("vasc.action.cancelAction.image"));
cancelButton.setText(i18n("vasc.action.cancelAction.name"));
cancelButton.setToolTipText(i18n("vasc.action.cancelAction.description"));
cancelButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(null);
shell.dispose();
}
});
}
}

View file

@ -0,0 +1,668 @@
/*
* 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 net.forwardfire.vasc.frontends.swt;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.forwardfire.vasc.core.AbstractVascFrontend;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.VascFrontendData;
import net.forwardfire.vasc.core.actions.GlobalVascAction;
import net.forwardfire.vasc.core.actions.RowVascAction;
import net.forwardfire.vasc.core.entry.VascEntryExporter;
import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener;
import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType;
import net.forwardfire.vasc.core.ui.VascOptionValueModelListener;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
import net.forwardfire.vasc.core.ui.VascValueModelListener;
import net.forwardfire.vasc.frontends.swt.ui.SwtBoolean;
import net.forwardfire.vasc.frontends.swt.ui.SwtButton;
import net.forwardfire.vasc.frontends.swt.ui.SwtLabel;
import net.forwardfire.vasc.frontends.swt.ui.SwtList;
import net.forwardfire.vasc.frontends.swt.ui.SwtText;
import net.forwardfire.vasc.frontends.swt.ui.SwtTextArea;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 21, 2007
*/
public class SwtVascFrontend extends AbstractVascFrontend {
private Logger logger = null;
private Composite parent = null;
private boolean renderGlobalActions = true;
public SwtVascFrontend(Composite parent) {
logger = Logger.getLogger(SwtVascFrontend.class.getName());
this.parent=parent;
}
/**
* @see net.forwardfire.vasc.core.VascFrontend#getFrontendType()
*/
public String getFrontendType() {
return "swt";
}
/**
* Add swt implmented ui components
*/
protected void addUiComponents() {
VascFrontendData vfd = getVascEntry().getVascFrontendData();
// required UI components
vfd.putVascUIComponent(VascUIComponent.VASC_LABEL,SwtLabel.class.getName());
vfd.putVascUIComponent(VascUIComponent.VASC_TEXT, SwtText.class.getName());
vfd.putVascUIComponent(VascUIComponent.VASC_BUTTON, SwtButton.class.getName());
vfd.putVascUIComponent(VascUIComponent.VASC_LIST, SwtList.class.getName());
// optional UI components
vfd.putVascUIComponent(VascUIComponent.VASC_BOOLEAN , SwtBoolean.class.getName());
//vfd.putVascUIComponent(VascUIComponent.VASC_DATE , SwtDate.class.getName());
vfd.putVascUIComponent(VascUIComponent.VASC_TEXTAREA, SwtTextArea.class.getName());
//vfd.putVascUIComponent(VascUIComponent.VASC_COLOR, SwtColorChooser.class.getName());
}
/**
* @return the renderGlobalActions
*/
public boolean isRenderGlobalActions() {
return renderGlobalActions;
}
/**
* @param renderGlobalActions the renderGlobalActions to set
*/
public void setRenderGlobalActions(boolean renderGlobalActions) {
this.renderGlobalActions = renderGlobalActions;
}
@Override
protected Object i18nImage(String key) {
if (entry.getVascFrontendData().getVascEntryResourceImageResolver()==null) {
return null;
}
return entry.getVascFrontendData().getVascEntryResourceImageResolver().getImageValue(entry,key);
}
private static final String[] FILTER_NAMES = {
"All Files (*.*)",
"Comma Separated Values Files (*.csv)",
"Microsoft Excel Spreadsheet Files (*.xls)",
};
/** These filter extensions are used to filter which files are displayed. */
private static final String[] FILTER_EXTS = { "*.*","*.csv","*.xls" };
public void renderExport(VascEntryExporter exporter) throws Exception {
FileDialog dlg = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
dlg.setFilterNames(FILTER_NAMES);
dlg.setFilterExtensions(FILTER_EXTS);
dlg.setFileName(entry.getName()+".csv");
String fileName = dlg.open();
logger.fine("FileName: "+fileName);
if (fileName == null) {
return;
}
OutputStream out = new FileOutputStream(fileName);
try {
exporter.doExport(out, entry);
} 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();
}
}
}
public void renderEdit() throws Exception {
logger.fine("Rending Edit View");
SwtVascEditDialog dialog = new SwtVascEditDialog(entry);
dialog.open();
}
public void renderDelete() throws Exception {
boolean del = askDelete( Display.getCurrent().getActiveShell() );
if (del==false) {
return;
}
// yes
entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry);
}
private boolean askDelete(Shell shell) {
logger.finest("Asking for delete");
MessageBox askDelete = new MessageBox(shell,SWT.ICON_QUESTION|SWT.YES|SWT.NO);
askDelete.setText(i18n("crud.event.delete.confim.title"));
askDelete.setMessage(i18n("crud.event.delete.confim.question"));
int state = askDelete.open();
if (state == SWT.YES) {
return true;
}
return false;
}
public void renderView() throws Exception {
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
parent.setLayout(layout);
Composite header = new Composite(parent, SWT.NONE);
GridLayout headerLayout = new GridLayout();
headerLayout.numColumns = 6;
header.setLayout(headerLayout);
header.setLayoutData(new GridData(SWT.NONE));
Composite body = new Composite(parent, SWT.NONE);
GridLayout bodyLayout = new GridLayout();
bodyLayout.numColumns = 1;
body.setLayout(bodyLayout);
body.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite footer = new Composite(parent, SWT.NONE);
GridLayout footerLayout = new GridLayout();
footerLayout.numColumns = 6;
footer.setLayout(footerLayout);
footer.setLayoutData(new GridData(SWT.NONE));
createHeader(header);
createBody(body);
createFooter(footer);
}
public void createHeader(Composite header) {
logger.finest("Creating header");
Color c = header.getDisplay().getSystemColor(SWT.COLOR_WHITE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.marginTop = 0;
header.setLayout(layout);
header.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
header.setBackground(c);
if (isRenderGlobalActions()) {
Composite headerBar = new Composite(header, SWT.NONE);
//GridLayout headerLayout = new GridLayout();
//headerLayout.numColumns = 1;
headerBar.setLayout(new FillLayout());
//headerBar.setLayoutData(new GridData(GridData.FILL_BOTH));
ToolBar toolBar = new ToolBar(headerBar, SWT.NONE);
for (GlobalVascAction action:entry.getGlobalActions()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderGlobalVascAction(action)==false) {
continue;
}
ToolItem item = new ToolItem(toolBar, SWT.PUSH);
item.setText(i18n(action.getName()));
item.setToolTipText(i18n(action.getDescription()));
item.setImage((Image)i18nImage(action.getImage()));
item.addSelectionListener(new GlobalActionListener(action));
}
}
Composite headerName = new Composite(header, SWT.NONE);
GridLayout bodyLayout = new GridLayout();
bodyLayout.numColumns = 2;
headerName.setLayout(bodyLayout);
headerName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
headerName.setBackground(c);
Label l = new Label(headerName, SWT.CENTER);
l.setImage((Image)i18nImage(entry.getListImage()));
l.setBackground(c);
Font headerFont = new Font(header.getDisplay(), "verdana", 16, SWT.BOLD);
l = new Label(headerName, SWT.CENTER);
l.setFont(headerFont);
l.setText(i18n(entry.getName()));
l.setBackground(c);
Composite headerText = new Composite(header, SWT.NONE);
bodyLayout = new GridLayout();
bodyLayout.numColumns = 1;
headerText.setLayout(bodyLayout);
headerText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
headerText.setBackground(c);
l = new Label(headerText, SWT.CENTER);
l.setText(i18n(entry.getListDescription()));
l.setBackground(c);
Composite headerSplit = new Composite(header, SWT.NONE);
GridLayout headerSplitLayout = new GridLayout();
headerSplitLayout.numColumns = 2;
headerSplit.setLayout(headerSplitLayout);
headerSplit.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Composite headerOptions = new Composite(headerSplit, SWT.NONE);
GridLayout headerOptionsLayout = new GridLayout();
headerOptionsLayout.numColumns = 2;
headerOptions.setLayout(headerOptionsLayout);
headerOptions.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
try {
for (VascEntryField option:entry.getListOptions()) {
for (int i=0;i<option.getVascEntryFieldType().getUIComponentCount(option);i++) {
net.forwardfire.vasc.core.ui.VascUIComponent label = option.getVascEntryFieldType().provideLabelUIComponent(i,option);
VascValueModel model = new VascValueModel();
model.setValue(i18n(option.getName()));
label.createComponent(entry,option,model,headerOptions);
net.forwardfire.vasc.core.ui.VascUIComponent editor = option.getVascEntryFieldType().provideEditorUIComponent(i,option);
model = new VascValueModel(option.getVascEntryFieldType().provideEditorVascValueModel(i,option));
model.addListener(new VascOptionValueModelListener(option));
model.setValue(null);
model.addListener(new VascValueModelListener() {
public void valueUpdate(VascValueModel model) throws VascException {
entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry);// mm
}
});
Object edit = editor.createComponent(entry,option,model,headerOptions);
// i==0 is for multi field editor support... which is stell very in progress
if (i==0) {
entry.getVascFrontendData().addFieldVascUIComponents(option, editor,edit);
}
}
}
Composite headerRightOptions = new Composite(headerSplit, SWT.NONE | SWT.RIGHT | SWT.TOP );
GridLayout headerRightOptionsLayout = new GridLayout();
headerRightOptionsLayout.numColumns = 2;
headerRightOptions.setLayout(headerRightOptionsLayout);
headerRightOptions.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label searchLabel = new Label(headerRightOptions, SWT.CENTER);
searchLabel.setText("Zoeken:");
final Text text = new Text(headerRightOptions, SWT.NONE | SWT.BORDER );
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
String value = text.getText();
try {
entry.getVascFrontendData().getVascFrontendHelper().searchAction(entry, value);
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
});
entry.getVascFrontendData().getVascFrontendHelper().headerOptionsCreatedFillData(entry);
} catch (Exception e) {
e.printStackTrace();
}
}
class GlobalActionListener extends SelectionAdapter {
private GlobalVascAction action = null;
public GlobalActionListener(GlobalVascAction action) {
this.action=action;
}
/**
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent event) {
logger.fine("Global Action");
try {
action.doGlobalAction(entry);
} catch (Exception e) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
}
}
}
public void createBody(Composite body) {
logger.finer("Creating body");
// Create the table viewer to display the players
// SWT.CHECK
final TableViewer tableViewer = new TableViewer(body, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
final Table table2 = tableViewer.getTable();
table2.setLayoutData(new GridData(GridData.FILL_BOTH));
table2.setHeaderVisible(true);
table2.setLinesVisible(true);
body.addControlListener(new ResizeTableControlListener(body,table2));
table2.addSelectionListener(new SelectionListener() {
/**
* @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
public void widgetDefaultSelected(SelectionEvent e) {
}
/**
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
public void widgetSelected(SelectionEvent e) {
Object data = e.item.getData();
logger.fine("Slecting data: "+data);
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(data);
}
});
// Set the content and label providers
tableViewer.setContentProvider(new ListConverterContentProvider());
tableViewer.setLabelProvider(new DefaultLabelProvider(entry));
//TODO: add renderer support
//Add sort indicator and sort data when column selected
Listener sortListener = new Listener() {
public void handleEvent(Event e) {
// determine new sort column and direction
TableColumn sortColumn = table2.getSortColumn();
TableColumn currentColumn = (TableColumn) e.widget;
int dir = table2.getSortDirection();
if (sortColumn == currentColumn) {
dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
} else {
table2.setSortColumn(currentColumn);
dir = SWT.UP;
}
table2.setSortDirection(dir);
VascEntryField field = (VascEntryField)currentColumn.getData();
entry.getVascFrontendData().getVascFrontendHelper().sortAction(entry, field);
}
};
entry.getVascFrontendData().addVascEntryFrontendEventListener(new VascEntryFrontendEventListener() {
public VascFrontendEventType[] getEventTypes() {
VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.POST_READ};
return result;
}
public void vascEvent(VascEntry entry,Object data) {
tableViewer.refresh();
table2.deselectAll();
}
});
for (VascEntryField c:entry.getVascEntryFields()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderList(c)==false) {
continue;
}
TableColumn tc = new TableColumn(table2, SWT.LEFT);
tc.setText(i18n(c.getName()));
tc.setData(c);
tc.setToolTipText(i18n(c.getDescription()));
tc.setImage((Image)i18nImage(c.getImage()));
tc.addListener(SWT.Selection, sortListener);
tc.setMoveable(true);
tc.setResizable(true);
}
int totalWidth = entry.getVascFrontendData().getVascFrontendHelper().getTotalColumnsWidth(entry);
logger.finer("Total size: "+totalWidth);
TableColumn[] columns = table2.getColumns();
for (int i = 0; i < columns.length; i++) {
VascEntryField c = (VascEntryField)columns[i].getData();
Integer cWidth = c.getSizeList();
if (cWidth!=null) {
//int w = (int)((double)totalSize/(double)totalSize)*cWidth;
columns[i].setWidth(cWidth);
//logger.finest("Setting column width: "+w+" total: "+totalSize+" c: "+cWidth+" of column: "+i);
} else {
columns[i].pack();
}
}
logger.fine("Table with columns created: "+table2.getColumnCount());
tableViewer.setInput(entry);
tableViewer.refresh();
}
class ResizeTableControlListener implements ControlListener {
Composite comp = null;
Table table = null;
public ResizeTableControlListener(Composite comp,Table table) {
this.comp=comp;
this.table=table;
}
public void controlResized(ControlEvent e) {
Rectangle area = comp.getClientArea();
Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
int width = area.width - 2*table.getBorderWidth();
if (preferredSize.y > area.height + table.getHeaderHeight()) {
// Subtract the scrollbar width from the total column width
// if a vertical scrollbar will be required
Point vBarSize = table.getVerticalBar().getSize();
width -= vBarSize.x;
}
Point oldSize = table.getSize();
if (oldSize.x > area.width) {
// table is getting smaller so make the columns
// smaller first and then resize the table to
// match the client area width
table.setSize(area.width, area.height);
} else {
// table is getting bigger so make the table
// bigger first and then make the columns wider
// to match the client area width
table.setSize(area.width, area.height);
//column1.setWidth(width/3);
//column2.setWidth(width - column1.getWidth());
}
}
public void controlMoved(ControlEvent e) {
}
}
public void createFooter(Composite footer) {
logger.finest("Creating footer");
for( RowVascAction action:entry.getRowActions()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderRowVascAction(action)==false) {
continue;
}
Button actionButton = new Button(footer, SWT.NONE);
actionButton.setText(i18n(action.getName()));
actionButton.setToolTipText(i18n(action.getDescription()));
actionButton.setImage((Image)i18nImage(action.getImage()));
actionButton.addSelectionListener(new ActionListener(action));
}
}
class ActionListener extends SelectionAdapter {
private RowVascAction action = null;
public ActionListener(RowVascAction action) {
this.action=action;
}
/**
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent event) {
logger.fine("Row Action");
try {
action.doRowAction(entry, entry.getVascFrontendData().getVascEntryState().getEntryDataObject());
} catch (Exception e) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
}
}
}
class DefaultLabelProvider implements ITableLabelProvider {
private VascEntry entry = null;
public DefaultLabelProvider(VascEntry entry) {
this.entry=entry;
}
/**
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
*/
public Image getColumnImage(Object arg0, int arg1) {
return null;
}
/**
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
*/
public String getColumnText(Object bean, int columnNumber) {
int col=0;
VascEntryField vtc = null;
for (VascEntryField c:entry.getVascEntryFields()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderList(c)==false) {
continue;
}
if (col==columnNumber) {
vtc = c;
break;
}
col++;
}
if (vtc==null) {
// should not happen
vtc = entry.getVascEntryFields().get(columnNumber);
}
//if (vtc.getVascColumnRenderer()==null) {
try {
return vtc.getVascEntryFieldValue().getDisplayValue(vtc,bean);
} catch (Exception e) {
logger.log(Level.WARNING,"Error in get value: '"+vtc.getVascEntryFieldValue()+"' error: "+e.getMessage(),e);
return "Err";
}
//}
// see custem column renderer, so this code will never be called
//return "CUSTEM_RENDER";
}
/**
* @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
*/
public void addListener(ILabelProviderListener arg0) {
}
/**
* @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
*/
public void dispose() {
}
/**
* @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
*/
public boolean isLabelProperty(Object arg0, String arg1) {
return false;
}
/**
* @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
*/
public void removeListener(ILabelProviderListener arg0) {
}
}
class ListConverterContentProvider implements IStructuredContentProvider {
/**
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object obj) {
return ((VascEntry)obj).getVascFrontendData().getVascEntryState().getEntryDataList().toArray();
}
/**
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
}
/**
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
}
}
}

View file

@ -0,0 +1,133 @@
/*
* 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 net.forwardfire.vasc.frontends.swt.ui;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
/**
*
*
* @author Willem Cazander
* @version 1.0 Jan 13, 2009
*/
public class SwtBoolean implements VascUIComponent {
private Button button = null;
private Color orgBackgroundColor = null;
private Color errorColor = null;
public Object createComponent(final VascEntry entry,VascEntryField entryField,final VascValueModel model,Object gui) throws VascException {
button = new Button((Composite)gui, SWT.CHECK);
orgBackgroundColor = button.getBackground();
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
//button.setImage(getImageDescriptor("vasc.dialog.save.image").createImage());
button.setText("");
Object value = model.getValue();
if (value!=null) {
button.setSelection(new Boolean(model.getValue()+""));
}
//button.setToolTipText(i18n("vasc.dialog.save.tooltip"));
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Boolean value = button.getSelection();
try {
System.out.println("setting value: "+value);
model.setValue(value);
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
});
return button;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (button==null) {
return null;
}
return button.getToolTipText();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String text) {
if (button==null) {
return;
}
button.setToolTipText(text);
if (text==null) {
button.setBackground(orgBackgroundColor);
} else {
button.setBackground(errorColor);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !button.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
button.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return button.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
button.setVisible(rendered);
}
}

View file

@ -0,0 +1,122 @@
/*
* 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 net.forwardfire.vasc.frontends.swt.ui;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
/**
*
*
* @author Willem Cazander
* @version 1.0 Jan 13, 2009
*/
public class SwtButton implements VascUIComponent {
private Button button = null;
private Color orgBackgroundColor = null;
private Color errorColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
button = new Button((Composite)gui, SWT.NONE);
orgBackgroundColor = button.getBackground();
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
//button.setImage(getImageDescriptor("vasc.dialog.save.image").createImage());
button.setText(model.getValue()+"");
//button.setToolTipText(i18n("vasc.dialog.save.tooltip"));
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
}
});
return button;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (button==null) {
return null;
}
return button.getToolTipText();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String text) {
if (button==null) {
return;
}
button.setToolTipText(text);
if (text==null) {
button.setBackground(orgBackgroundColor);
} else {
button.setBackground(errorColor);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !button.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
button.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return button.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
button.setVisible(rendered);
}
}

View file

@ -0,0 +1,113 @@
/*
* 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 net.forwardfire.vasc.frontends.swt.ui;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
/**
*
*
* @author Willem Cazander
* @version 1.0 Jan 13, 2009
*/
public class SwtLabel implements VascUIComponent {
private Label label = null;
private Color orgBackgroundColor = null;
private Color errorColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
label = new Label((Composite)gui, SWT.NONE);
orgBackgroundColor = label.getBackground();
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
label.setText(model.getValue()+"");
return label;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (label==null) {
return null;
}
return label.getToolTipText();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String text) {
if (label==null) {
return;
}
label.setToolTipText(text);
if (text==null) {
label.setBackground(orgBackgroundColor);
} else {
label.setBackground(errorColor);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !label.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
label.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return label.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
label.setVisible(rendered);
}
}

View file

@ -0,0 +1,180 @@
/*
* 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 net.forwardfire.vasc.frontends.swt.ui;
import java.util.List;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascSelectItem;
import net.forwardfire.vasc.core.ui.VascSelectItemModel;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
/**
*
*
* @author Willem Cazander
* @version 1.0 May 10, 2009
*/
public class SwtList implements VascUIComponent {
private Combo combo = null;
private Color orgBackgroundColor = null;
private Color errorColor = null;
private List<VascSelectItem> data = null;
public Object createComponent(final VascEntry entry,VascEntryField entryField,final VascValueModel model,Object gui) throws VascException {
combo = new Combo((Composite)gui,SWT.SINGLE | SWT.BORDER);
combo.setVisibleItemCount(8);
VascSelectItemModel items = (VascSelectItemModel)entryField.getVascEntryFieldType().getDataObject();
if (items!=null) {
data = items.getVascSelectItems(entry);
}
fillCombo();
orgBackgroundColor = combo.getBackground();
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
combo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
VascSelectItem item = findItem(combo.getText());
if (item!=null) {
try {
model.setValue(item.getValue());
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
}
});
// sets default selected
for (VascSelectItem i:data) {
Object iValue = i.getValue();
Object mValue = model.getValue();
if (iValue==null && mValue==null) {
combo.setText(i.getLabel());
break;
}
if (iValue==null) {
continue;
}
if (iValue.equals(mValue)) {
combo.setText(i.getLabel());
break;
}
}
if (combo.getText()==null) {
combo.setText(data.get(0).getLabel()); // select top one.
}
return combo;
}
private void fillCombo() {
if (data==null | combo==null) {
return;
}
for (VascSelectItem i:data) {
if (i.isDisabled()) {
continue;
}
combo.add(i.getLabel());
}
}
private VascSelectItem findItem(String text) {
for (VascSelectItem i:data) {
if (i.getLabel().equals(text)) {
return i;
}
}
return null;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (combo==null) {
return null;
}
return combo.getToolTipText();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String text) {
if (combo==null) {
return;
}
combo.setToolTipText(text);
if (text==null) {
combo.setBackground(orgBackgroundColor);
} else {
combo.setBackground(errorColor);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !combo.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
combo.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return combo.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
combo.setVisible(rendered);
}
}

View file

@ -0,0 +1,139 @@
/*
* 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 net.forwardfire.vasc.frontends.swt.ui;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
/**
* Renders the swt text field.
*
* @author Willem Cazander
* @version 1.0 Jan 13, 2009
*/
public class SwtText implements VascUIComponent {
private Text text = null;
private Color orgBackgroundColor = null;
private Color errorColor = null;
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
text = new Text((Composite)gui, SWT.NONE | SWT.BORDER);
orgBackgroundColor = text.getBackground();
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
Object value = model.getValue();
if (value!=null) {
text.setText(value.toString());
}
text.addModifyListener(new TextListener(model,entry));
return text;
}
class TextListener implements ModifyListener {
private VascValueModel model = null;
private VascEntry entry = null;
public TextListener(VascValueModel model,VascEntry entry) {
this.model=model;
this.entry=entry;
}
public void modifyText(ModifyEvent e) {
Object value = text.getText();
try {
model.setValue(value);
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (text==null) {
return null;
}
return text.getToolTipText();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String textString) {
if (text==null) {
return;
}
text.setToolTipText(textString);
if (textString==null) {
text.setBackground(orgBackgroundColor);
} else {
text.setBackground(errorColor);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !text.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
text.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return text.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
text.setVisible(rendered);
}
}

View file

@ -0,0 +1,163 @@
/*
* 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 net.forwardfire.vasc.frontends.swt.ui;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
/**
*
*
* @author Willem Cazander
* @version 1.0 Jan 13, 2009
*/
public class SwtTextArea implements VascUIComponent {
private Text text = null;
private Color orgBackgroundColor = null;
private Color errorColor = null;
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
text = new Text((Composite)gui, SWT.MULTI | SWT.BORDER);
orgBackgroundColor = text.getBackground();
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
int cols = 25;
int rows = 3;
String colsString = entryField.getVascEntryFieldType().getProperty("editor.columns");
if (colsString!=null && "".equals(colsString)==false) {
cols = new Integer(colsString);
}
String rowsString = entryField.getVascEntryFieldType().getProperty("editor.rows");
if (rowsString!=null && "".equals(rowsString)==false) {
rows = new Integer(rowsString);
}
GC gc = new GC(text);
FontMetrics fm = gc.getFontMetrics ();
gc.dispose ();
int width = cols * fm.getAverageCharWidth();
int height = rows * fm.getHeight();
GridData data = new GridData();
data.widthHint = width;
data.heightHint = height;
text.setLayoutData(data);
Object value = model.getValue();
if (value!=null) {
text.setText(value.toString());
}
text.addModifyListener(new TextListener(model,entry));
return text;
}
class TextListener implements ModifyListener {
private VascValueModel model = null;
private VascEntry entry = null;
public TextListener(VascValueModel model,VascEntry entry) {
this.model=model;
this.entry=entry;
}
public void modifyText(ModifyEvent e) {
Object value = text.getText();
try {
model.setValue(value);
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (text==null) {
return null;
}
return text.getToolTipText();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String textString) {
if (text==null) {
return;
}
text.setToolTipText(textString);
if (textString==null) {
text.setBackground(orgBackgroundColor);
} else {
text.setBackground(errorColor);
}
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !text.isEnabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
text.setEnabled(!disabled);
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return text.isVisible();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
text.setVisible(rendered);
}
}

View file

@ -0,0 +1,619 @@
/*
* 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 net.forwardfire.vasc;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.ColorCellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import junit.framework.TestCase;
/**
* Tests a simple x4o xml language.
*
* @author Willem Cazander
* @version 1.0 Jul 24, 2006
*/
public class SWTTableViewerTest extends TestCase {
public void setUp() throws Exception {
// enable all logs
//InputStream loggingProperties = this.getClass().getResourceAsStream("/META-INF/logging.properties");
//LogManager.getLogManager().readConfiguration( loggingProperties );
//loggingProperties.close();
// load xtes queries
}
public static void main(String[] args) {
new PersonEditor().run();
}
public void tearDown() throws Exception {
}
public void testNull() throws Exception {
assertEquals(true, true);
}
}
class PersonEditor extends ApplicationWindow {
// Table column names/properties
public static final String NAME = "Name";
public static final String MALE = "Male?";
public static final String AGE = "Age Range";
public static final String SHIRT_COLOR = "Shirt Color";
public static final String[] PROPS = { NAME, MALE, AGE, SHIRT_COLOR };
// The data model
private java.util.List people;
/**
* Constructs a PersonEditor
*/
public PersonEditor() {
super(null);
people = new ArrayList();
}
/**
* Runs the application
*/
public void run() {
// Don't return from open() until window closes
setBlockOnOpen(true);
// Open the main window
open();
// Dispose the display
Display.getCurrent().dispose();
}
/**
* Configures the shell
*
* @param shell
* the shell
*/
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setText("Person Editor");
shell.setSize(400, 400);
}
/**
* Creates the main window's contents
*
* @param parent
* the main window
* @return Control
*/
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
// Add a button to create the new person
Button newPerson = new Button(composite, SWT.PUSH);
newPerson.setText("Create New Person");
// Add the TableViewer
final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION);
tv.setContentProvider(new PersonContentProvider());
tv.setLabelProvider(new PersonLabelProvider());
tv.setInput(people);
// Set up the table
Table table = tv.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
new TableColumn(table, SWT.CENTER).setText(NAME);
new TableColumn(table, SWT.CENTER).setText(MALE);
new TableColumn(table, SWT.CENTER).setText(AGE);
new TableColumn(table, SWT.CENTER).setText(SHIRT_COLOR);
for (int i = 0, n = table.getColumnCount(); i < n; i++) {
table.getColumn(i).pack();
}
table.setHeaderVisible(true);
table.setLinesVisible(true);
// Add a new person when the user clicks button
newPerson.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Person p = new Person();
p.setName("Name");
p.setMale(true);
p.setAgeRange(Integer.valueOf("0"));
p.setShirtColor(new RGB(255, 0, 0));
people.add(p);
tv.refresh();
}
});
// Create the cell editors
CellEditor[] editors = new CellEditor[4];
editors[0] = new TextCellEditor(table);
editors[1] = new CheckboxCellEditor(table);
editors[2] = new ComboBoxCellEditor(table, AgeRange.INSTANCES,
SWT.READ_ONLY);
editors[3] = new ColorCellEditor(table);
// Set the editors, cell modifier, and column properties
tv.setColumnProperties(PROPS);
tv.setCellModifier(new PersonCellModifier(tv));
tv.setCellEditors(editors);
return composite;
}
/**
* The application entry point
*
* @param args
* the command line arguments
*/
public static void main(String[] args) {
new PersonEditor().run();
}
}
/**
* This class provides the content for the person table
*/
class PersonContentProvider implements IStructuredContentProvider {
/**
* Returns the Person objects
*/
public Object[] getElements(Object inputElement) {
return ((List) inputElement).toArray();
}
/**
* Disposes any created resources
*/
public void dispose() {
// Do nothing
}
/**
* Called when the input changes
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// Ignore
}
}
/**
* This class provides the content for the FoodList application
*/
class FoodContentProvider implements IStructuredContentProvider {
/**
* Gets the food items for the list
*
* @param arg0
* the data model
* @return Object[]
*/
public Object[] getElements(Object arg0) {
return ((GroceryList) arg0).getFoods().toArray();
}
/**
* Disposes any created resources
*/
public void dispose() {
// Do nothing
}
/**
* Called when the input changes
*
* @param arg0
* the viewer
* @param arg1
* the old input
* @param arg2
* the new input
*/
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
// Do nothing
}
}
/**
* This class represents the cell modifier for the PersonEditor program
*/
class PersonCellModifier implements ICellModifier {
private Viewer viewer;
public PersonCellModifier(Viewer viewer) {
this.viewer = viewer;
}
/**
* Returns whether the property can be modified
*
* @param element
* the element
* @param property
* the property
* @return boolean
*/
public boolean canModify(Object element, String property) {
// Allow editing of all values
return true;
}
/**
* Returns the value for the property
*
* @param element
* the element
* @param property
* the property
* @return Object
*/
public Object getValue(Object element, String property) {
Person p = (Person) element;
if (PersonEditor.NAME.equals(property))
return p.getName();
else if (PersonEditor.MALE.equals(property))
return Boolean.valueOf(p.isMale());
else if (PersonEditor.AGE.equals(property))
return p.getAgeRange();
else if (PersonEditor.SHIRT_COLOR.equals(property))
return p.getShirtColor();
else
return null;
}
/**
* Modifies the element
*
* @param element
* the element
* @param property
* the property
* @param value
* the value
*/
public void modify(Object element, String property, Object value) {
if (element instanceof Item)
element = ((Item) element).getData();
Person p = (Person) element;
if (PersonEditor.NAME.equals(property))
p.setName((String) value);
else if (PersonEditor.MALE.equals(property))
p.setMale(((Boolean) value).booleanValue());
else if (PersonEditor.AGE.equals(property))
p.setAgeRange((Integer) value);
else if (PersonEditor.SHIRT_COLOR.equals(property))
p.setShirtColor((RGB) value);
// Force the viewer to refresh
viewer.refresh();
}
}
/**
* This class represents a person
*/
class Person {
private String name;
private boolean male;
private Integer ageRange;
private RGB shirtColor;
/**
* @return Returns the ageRange.
*/
public Integer getAgeRange() {
return ageRange;
}
/**
* @param ageRange
* The ageRange to set.
*/
public void setAgeRange(Integer ageRange) {
this.ageRange = ageRange;
}
/**
* @return Returns the male.
*/
public boolean isMale() {
return male;
}
/**
* @param male
* The male to set.
*/
public void setMale(boolean male) {
this.male = male;
}
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
/**
* @param name
* The name to set.
*/
public void setName(String name) {
this.name = name;
}
/**
* @return Returns the shirtColor.
*/
public RGB getShirtColor() {
return shirtColor;
}
/**
* @param shirtColor
* The shirtColor to set.
*/
public void setShirtColor(RGB shirtColor) {
this.shirtColor = shirtColor;
}
}
/**
* This class contains all the foods on the "grocery list"
*/
class GroceryList {
// Holds the foods
private List foods;
/**
* Constructs a grocery list
*/
public GroceryList() {
foods = new ArrayList();
// Add some foods
foods.add(new Food("Broccoli", true));
foods.add(new Food("Bundt Cake", false));
foods.add(new Food("Cabbage", true));
foods.add(new Food("Candy Canes", false));
foods.add(new Food("Eggs", true));
foods.add(new Food("Potato Chips", false));
foods.add(new Food("Milk", true));
foods.add(new Food("Soda", false));
foods.add(new Food("Chicken", true));
foods.add(new Food("Cinnamon Rolls", false));
}
/**
* Returns the foods in this grocery list
*
* @return List
*/
public List getFoods() {
return Collections.unmodifiableList(foods);
}
}
/**
* This class represents a type of food
*/
class Food {
// The name of the food
private String name;
// Is it healthy?
private boolean healthy;
/**
* Food constructor
*
* @param name
* the name
* @param healthy
* whether or not it's healthy
*/
public Food(String name, boolean healthy) {
this.name = name;
this.healthy = healthy;
}
/**
* Gets whether this is healthy
*
* @return boolean
*/
public boolean isHealthy() {
return healthy;
}
/**
* Gets the name
*
* @return String
*/
public String getName() {
return name;
}
}
/**
* This class provides the labels for the person table
*/
class PersonLabelProvider implements ITableLabelProvider {
/**
* Returns the image
*
* @param element
* the element
* @param columnIndex
* the column index
* @return Image
*/
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
/**
* Returns the column text
*
* @param element
* the element
* @param columnIndex
* the column index
* @return String
*/
public String getColumnText(Object element, int columnIndex) {
Person person = (Person) element;
switch (columnIndex) {
case 0:
return person.getName();
case 1:
return Boolean.toString(person.isMale());
case 2:
return AgeRange.INSTANCES[person.getAgeRange().intValue()];
case 3:
return person.getShirtColor().toString();
}
return null;
}
/**
* Adds a listener
*
* @param listener
* the listener
*/
public void addListener(ILabelProviderListener listener) {
// Ignore it
}
/**
* Disposes any created resources
*/
public void dispose() {
// Nothing to dispose
}
/**
* Returns whether altering this property on this element will affect the
* label
*
* @param element
* the element
* @param property
* the property
* @return boolean
*/
public boolean isLabelProperty(Object element, String property) {
return false;
}
/**
* Removes a listener
*
* @param listener
* the listener
*/
public void removeListener(ILabelProviderListener listener) {
// Ignore
}
}
/**
* This class encapsulates age ranges
*/
class AgeRange {
public static final String NONE = "";
public static final String BABY = "0 - 3";
public static final String TODDLER = "4 - 7";
public static final String CHILD = "8 - 12";
public static final String TEENAGER = "13 - 19";
public static final String ADULT = "20 - ?";
public static final String[] INSTANCES = { NONE, BABY, TODDLER, CHILD,
TEENAGER, ADULT };
}

View file

@ -0,0 +1,96 @@
/*
* 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 net.forwardfire.vasc;
import java.io.InputStream;
import java.util.logging.LogManager;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.frontends.swt.SwtVascFrontend;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import junit.framework.TestCase;
/**
* Tests a simple x4o xml language.
*
* @author Willem Cazander
* @version 1.0 Jul 24, 2006
*/
public class SWTTest extends TestCase {
public void setUp() throws Exception {
// enable all logs
//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 testNull() throws Exception {
assertEquals(true, true);
}
public static void main(String[] args) throws Exception {
new SWTTest().doSWT();
}
public void doSWT() throws Exception {
// get GUI
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Vasc Test - Swt");
// define redering and render
SwtVascFrontend render = new SwtVascFrontend(shell);
VascEntry entry = TestTable.getVascTable();
entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry);
render.initEntry(entry);
render.renderView();
// 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();
}
}

View file

@ -0,0 +1,172 @@
/*
* 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 net.forwardfire.vasc;
import java.util.Date;
import net.forwardfire.vasc.annotations.VascDefaultValue;
import net.forwardfire.vasc.annotations.VascEntry;
import net.forwardfire.vasc.annotations.VascI18n;
import net.forwardfire.vasc.annotations.VascModelReference;
import net.forwardfire.vasc.annotations.VascStyle;
import net.forwardfire.vasc.validators.VascDateFuture;
import net.forwardfire.vasc.validators.VascObjectNotNull;
import net.forwardfire.vasc.validators.VascStringLength;
//import org.hibernate.validator.NotNull;
//import org.hibernate.validator.Max;
/**
* TestModel
*
*
* @author Willem Cazander
* @version 1.0 Mar 28, 2007
*/
@VascEntry(headerName="En een tooltip op het model")
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;
private String hexColor = null;
//private Node nonEditorField = null;
/**
* @return the date
*/
@VascDateFuture
public Date getDate() {
return date;
}
/**
* @param date the date to set
*/
public void setDate(Date date) {
this.date = date;
}
/**
* @return the description
*/
@VascI18n( name="omscheiving",
description="De omscrijving",
image="/resources/images/gabelfresser.gif",
helpId="help.id")
@VascDefaultValue(value="xxxxx")
@VascStyle(sizeList=200)
// @NotNull
// @Max(value=10)
@VascObjectNotNull
@VascStringLength(max=10)
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the price
*/
public Float getPrice() {
return price;
}
/**
* @param price the price to set
*/
public void setPrice(Float price) {
this.price = price;
}
// @NotNull
@VascObjectNotNull
@VascModelReference
@VascI18n(image="/resources/images/gabelfresser.gif")
public TestModel getTestModel() {
return 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;
}
/**
* @return the hexColor
*/
public String getHexColor() {
return hexColor;
}
/**
* @param hexColor the hexColor to set
*/
public void setHexColor(String hexColor) {
this.hexColor = hexColor;
}
}

View file

@ -0,0 +1,149 @@
/*
* 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 net.forwardfire.vasc;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import net.forwardfire.vasc.core.AbstractVascBackend;
import net.forwardfire.vasc.core.VascBackendState;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
import net.forwardfire.vasc.core.ui.VascSelectItem;
import net.forwardfire.vasc.core.ui.VascSelectItemModel;
import net.forwardfire.vasc.impl.entry.BeanPropertyVascEntryFieldValue;
import net.forwardfire.vasc.impl.entry.BeanVascEntryRecordCreator;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 21, 2007
*/
public class TestModelVascDataSource extends AbstractVascBackend implements VascSelectItemModel {
private List<Object> testModels = null;
private String nullLabel = null;
private String nullKeyValue = null;
public TestModelVascDataSource() {
testModels = new ArrayList<Object>(2);
TestModel t = new TestModel();
t.setDate(new Date());
t.setDescription("yoyo test");
t.setName("this Name");
t.setPrice(34.1f);
t.setActive(true);
t.setHexColor("#FF66EE");
testModels.add(t);
t = new TestModel();
t.setDate(new Date());
t.setDescription("Model2 test");
t.setName("BeanSourde");
t.setPrice(19.2f);
t.setActive(false);
t.setTestModel((TestModel)testModels.get(0));
testModels.add(t);
}
public TestModelVascDataSource(List<Object> testModels) {
this.testModels=testModels;
}
public List<Object> execute(VascBackendState state) throws VascException {
return testModels;
}
public void persist(Object object) throws VascException {
testModels.add(object);
}
public Object merge(Object object) throws VascException {
if(testModels.contains(object)==false) {
testModels.add(object);
}
return object;
}
public void delete(Object object) throws VascException {
testModels.remove(object);
}
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
return new BeanPropertyVascEntryFieldValue(field.getBackendName());
}
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return new BeanVascEntryRecordCreator(TestModel.class);
}
// --- VascSelectItemModel interface
public List<VascSelectItem> getVascSelectItems(VascEntry entry) {
List<VascSelectItem> res = new ArrayList<VascSelectItem>(4);
for (Object o:testModels) {
TestModel t = (TestModel)o;
VascSelectItem i = new VascSelectItem(t.getName(),t);
res.add(i);
}
return res;
}
/**
* @return the nullLabel
*/
public String getNullLabel() {
return nullLabel;
}
/**
* @param nullLabel the nullLabel to set
*/
public void setNullLabel(String nullLabel) {
this.nullLabel = nullLabel;
}
/**
* @return the nullKeyValue
*/
public String getNullKeyValue() {
return nullKeyValue;
}
/**
* @param nullKeyValue the nullKeyValue to set
*/
public void setNullKeyValue(String nullKeyValue) {
this.nullKeyValue = nullKeyValue;
}
}

View file

@ -0,0 +1,154 @@
/*
* 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 net.forwardfire.vasc;
import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Method;
import java.util.Locale;
import net.forwardfire.vasc.core.VascBackend;
import net.forwardfire.vasc.core.VascBackendControllerLocal;
import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.VascFrontendData;
import net.forwardfire.vasc.impl.DefaultVascBackedEntryFinalizer;
import net.forwardfire.vasc.impl.DefaultVascFactory;
import net.forwardfire.vasc.impl.DefaultVascFrontendData;
import net.forwardfire.vasc.impl.DefaultVascFrontendHelper;
import net.forwardfire.vasc.impl.VascBackendProxyPaged;
import net.forwardfire.vasc.impl.VascBackendProxySearch;
import net.forwardfire.vasc.impl.VascBackendProxySort;
import net.forwardfire.vasc.impl.actions.AddRowAction;
import net.forwardfire.vasc.impl.actions.CSVExportGlobalAction;
import net.forwardfire.vasc.impl.actions.DeleteRowAction;
import net.forwardfire.vasc.impl.actions.EditRowAction;
import net.forwardfire.vasc.impl.actions.RefreshDataGlobalAction;
import net.forwardfire.vasc.impl.actions.XMLExportGlobalAction;
import net.forwardfire.vasc.impl.x4o.VascParser;
/**
*
* @author Willem Cazander
* @version 1.0 Aug 2, 2007
*/
public class TestTable {
static VascController getDefaultVascController() throws Exception {
VascController c = DefaultVascFactory.getDefaultVascController(2288L,"idca.nl","user","admin");
// for test
TestModelVascDataSource backend = new TestModelVascDataSource();
backend.setId("testBackend1");
((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(backend);
return c;
}
static public void fill(VascEntry entry,VascController vascController) {
VascFrontendData frontendData = DefaultVascFactory.getDefaultVascFrontendData("i18n.vasc", Locale.getDefault());
frontendData.setVascController(vascController);
entry.setVascFrontendData(frontendData);
VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry);
frontendData.getVascEntryState().setVascBackend(backend);
frontendData.getVascEntryState().setVascEntry(entry);
entry.addRowAction(new AddRowAction());
entry.addRowAction(new EditRowAction());
entry.addRowAction(new DeleteRowAction());
entry.addGlobalAction(new XMLExportGlobalAction());
entry.addGlobalAction(new CSVExportGlobalAction());
entry.addGlobalAction(new RefreshDataGlobalAction());
// hackje om deze manuale actions van i18n keys te voorzien;
// this is temp untill x4o templaing
DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer();
try {
f.finalizeVascEntry(entry, vascController);
} catch (VascException e) {
e.printStackTrace();
}
}
static public VascEntry getVascTable() throws Exception {
VascController c = getDefaultVascController();
VascParser parser = new VascParser(c);
File f = File.createTempFile("test-vasc", ".xml");
parser.setDebugOutputStream(new FileOutputStream(f));
parser.parseResource("vasc/tables.xml");
VascEntry entry = parser.getVascController().getVascEntryController().getVascEntryById("test1");
fill(entry,c);
return entry;
}
static void printEntry(VascEntry e) throws Exception {
System.out.println("");
System.out.println("=== Printing entry ===");
System.out.println("");
for (Method m:e.getClass().getMethods()) {
if (m.getName().startsWith("get")==false) { //a bit dirty
continue;
}
if (m.getParameterTypes().length>0) {
continue;
}
System.out.println("prop: "+m.getName()+" -> "+m.invoke(e));
}
System.out.println("");
System.out.println("=== Fields ===");
for (VascEntryField vef:e.getVascEntryFields()) {
System.out.println("=== Field: "+vef.getId());
for (Method m:vef.getClass().getMethods()) {
if (m.getName().startsWith("get")==false) { //a bit dirty
continue;
}
if (m.getParameterTypes().length>0) {
continue;
}
System.out.println("prop: "+m.getName()+" -> "+m.invoke(vef));
}
}
}
}

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>vasc-frontend-web-jsf</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
#Sun Dec 25 17:29:07 CET 2011
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View file

@ -0,0 +1,6 @@
#Mon Aug 30 21:58:06 CEST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5

View file

@ -0,0 +1,5 @@
#Sun Dec 25 17:29:03 CET 2011
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View file

@ -0,0 +1,9 @@
#Mon Aug 30 21:58:05 CEST 2010
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1

View file

@ -0,0 +1,67 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vasc-frontends</artifactId>
<groupId>net.forwardfire.vasc</groupId>
<version>0.3.5-SNAPSHOT</version>
</parent>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-frontend-web-jsf</artifactId>
<version>0.3.5-SNAPSHOT</version>
<name>vasc-frontend-web-jsf</name>
<description>vasc-frontend-web-jsf</description>
<dependencies>
<dependency>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-ejb3</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>1.2_04</version>
<scope>provided</scope>
</dependency>
<!-- tomahak jsf frontend
<dependency>
<groupId>org.apache.myfaces.tomahawk</groupId>
<artifactId>tomahawk12</artifactId>
<version>1.1.8</version>
<scope>compile</scope>
</dependency>
-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,455 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import javax.faces.context.FacesContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import net.forwardfire.vasc.core.VascBackend;
import net.forwardfire.vasc.core.VascBackendControllerLocal;
import net.forwardfire.vasc.core.VascBackendState;
import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryControllerLocal;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.VascFrontendData;
import net.forwardfire.vasc.core.entry.VascEntryBackendEventListener;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener;
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
import net.forwardfire.vasc.ejb3.VascServiceManager;
import net.forwardfire.vasc.impl.DefaultVascBackedEntryFinalizer;
import net.forwardfire.vasc.impl.DefaultVascFactory;
import net.forwardfire.vasc.impl.VascBackendProxyEventExecutor;
import net.forwardfire.vasc.impl.entry.DefaultVascEntryResourceResolver;
import net.forwardfire.vasc.impl.entry.SetParameterBackendListener;
/**
* Base faces session object for managing vasc entries.
*
* @author Willem Cazander
* @version 1.0 Sep 21, 2010
*/
abstract public class AbstractJSFVascFacesController {
private VascController vascController = null;
abstract public String getVascSericeManagerJNDI();
abstract public String getResourceBundleWEB();
abstract public boolean getDisableI18N();
abstract public VascUserInfo getVascUserInfo();
public class VascUserInfo {
Long userId;
String username;
String[] roles;
public VascUserInfo(Long userId,String username,String[] roles) {
this.userId=userId;
this.username=username;
this.roles=roles;
}
}
/*
class RefreshObjectForLazyPropertiesListener implements VascEntryFrontendEventListener {
public VascFrontendEventType[] getEventTypes() {
VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.POST_UPDATE};
return result;
}
public void vascEvent(VascEntry entry,Object data) {
if (data.getClass().getName().startsWith("some.class.models.jpa")==false) {
return; // only refresh model classes
}
// TODO: mmm rewrite events to change to different object to use ejb3++ solution ?
// Use hiberbate session to attach a detected object again. (note: this is not possible with EJB3, uses merge() which returns a new object)
//((Session)entityManager.getDelegate()).refresh(data);
}
}
*/
class MergedResourceBundle extends ResourceBundle {
Map<String,String> data = new HashMap<String,String>(500);
public void addDateMap(Map<String,String> dataMap) {
data.putAll(dataMap);
}
public void addDataBundle(ResourceBundle bundle) {
for (String key:bundle.keySet()) {
String value = bundle.getString(key);
data.put(key, value);
}
}
public Object handleGetObject(String key) {
return data.get(key);
}
public Enumeration<String> getKeys() {
return Collections.enumeration(data.keySet());
}
}
/**
* Config vasc frontend data object for jsf component to use.
*
* @return
*/
public VascFrontendData getNewVascFrontendData() {
Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
MergedResourceBundle bundle = new MergedResourceBundle();
bundle.addDataBundle(ResourceBundle.getBundle(getResourceBundleWEB(), locale));
try {
Context context = new InitialContext();
VascServiceManager vascManager = (VascServiceManager)context.lookup(getVascSericeManagerJNDI());
Map<String,String> remoteI18n = vascManager.getResourceBundle(locale.toString());
bundle.addDateMap(remoteI18n);
} catch (Exception e) {
throw new RuntimeException("Could not get the ejb resource bundle: "+e.getMessage(),e);
}
VascFrontendData vascFrontendData = DefaultVascFactory.getDefaultVascFrontendData(bundle);
vascFrontendData.addVascEntryFrontendEventListener(new VascEntryFrontendEventListener() {
private static final long serialVersionUID = 1L;
public VascFrontendEventType[] getEventTypes() {
VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.EXCEPTION};
return result;
}
public void vascEvent(VascEntry entry, Object data) {
if (data instanceof Exception) {
((Exception)data).printStackTrace();
}
}
});
// config frontend data for ISF usage
if (getDisableI18N()) {
vascFrontendData.setVascEntryResourceResolver(new DefaultVascEntryResourceResolver());
} else {
vascFrontendData.setVascEntryResourceResolver(new DefaultVascEntryResourceResolver(bundle));
}
return vascFrontendData;
}
/**
*
*/
public List<Object> executeVascList(String entryId,Map<String,Object> para) {
try {
// plug all object
VascEntry entry = getVascController().getVascEntryController().getVascEntryById(entryId);
entry.setVascFrontendData(getNewVascFrontendData());
entry.getVascFrontendData().setVascController(getVascController());
VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry);
entry.getVascFrontendData().getVascEntryState().setVascBackend(backend);
entry.getVascFrontendData().getVascEntryState().setVascEntry(entry);
// set def para
VascBackendState state = entry.getVascFrontendData().getVascEntryState().getVascBackendState();
for (String key2:entry.getEntryParameterKeys()) {
Object value = entry.getEntryParameter(key2);
//System.out.println("Copy paras name: "+key2+" value: "+value+" class: "+value.getClass().getName());
state.setDataParameter(key2, value);
}
// set list para
for (VascEntryField vef:entry.getListOptions()) {
Object def = vef.getDefaultValue();
if (def==null) {
continue;
}
String backendName = vef.getBackendName();
state.setDataParameter(backendName, def);
}
// copy para
if (para!=null) {
for (String key:para.keySet()) {
entry.setEntryParameter(key, para.get(key));
}
}
// done, execute and return data.
entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry);
return entry.getVascFrontendData().getVascEntryState().getEntryDataList();
} catch (Exception e) {
throw new RuntimeException("Could not execute list: "+e.getMessage(),e);
}
}
class RemoteVascBackend implements VascBackend {
private String backendId = null;
private VascServiceManager vascManager = null;
public RemoteVascBackend(String backendId,VascServiceManager vascManager) {
this.backendId=backendId;
this.vascManager=vascManager;
}
public void delete(Object object) throws VascException {
Object[] args = new Object[1];
args[0]=object;
vascManager.invokeBackendMethod(backendId, "delete", args);
}
public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascException {
Object[] args = new Object[2];
args[0]=state;
args[1]=primaryId;
Object result = vascManager.invokeBackendMethod(backendId, "doRecordMoveDownById", args);
return (Long)result;
}
public long doRecordMoveUpById(VascBackendState state, Object primaryId) throws VascException {
Object[] args = new Object[2];
args[0]=state;
args[1]=primaryId;
Object result = vascManager.invokeBackendMethod(backendId, "doRecordMoveUpById", args);
return (Long)result;
}
@SuppressWarnings("unchecked")
public List<Object> execute(VascBackendState state) throws VascException {
Object[] args = new Object[1];
args[0]=state;
Object result = vascManager.invokeBackendMethod(backendId, "execute", args);
return (List<Object>)result;
}
public long fetchTotalExecuteSize(VascBackendState state) {
Object[] args = new Object[1];
args[0]=state;
Object result = vascManager.invokeBackendMethod(backendId, "fetchTotalExecuteSize", args);
return (Long)result;
}
public String getId() {
return backendId;
}
public boolean isPageable() {
Object[] args = new Object[0];
Object result = vascManager.invokeBackendMethod(backendId, "isPageable", args);
return (Boolean)result;
}
public boolean isRecordMoveable() {
Object[] args = new Object[0];
Object result = vascManager.invokeBackendMethod(backendId, "isRecordMoveable", args);
return (Boolean)result;
}
public boolean isSearchable() {
Object[] args = new Object[0];
Object result = vascManager.invokeBackendMethod(backendId, "isSearchable", args);
return (Boolean)result;
}
public boolean isSortable() {
Object[] args = new Object[0];
Object result = vascManager.invokeBackendMethod(backendId, "isSortable", args);
return (Boolean)result;
}
public Object merge(Object object) throws VascException {
Object[] args = new Object[1];
args[0]=object;
Object result = vascManager.invokeBackendMethod(backendId, "merge", args);
return result;
}
public void persist(Object object) throws VascException {
Object[] args = new Object[1];
args[0]=object;
vascManager.invokeBackendMethod(backendId, "delete", args);
}
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
/*
try {
ByteArrayOutputStream dataArray = new ByteArrayOutputStream(256); // it grows when needed
ObjectOutputStream objOutstream = new ObjectOutputStream(dataArray);
objOutstream.writeObject(field);
objOutstream.close();
int objectSize = dataArray.size();
System.out.println("Writing obj to field: "+objectSize);
} catch (IOException e) {
throw new RuntimeException(e);
}
*/
Object[] args = new Object[1];
args[0]=field;
Object result = vascManager.invokeBackendMethod(backendId, "provideVascEntryFieldValue", args);
return (VascEntryFieldValue)result;
}
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
VascEntry clone = null;
try {
clone = vascEntry.clone();
clone.setVascFrontendData(null);
clone.setVascEntryFieldEventChannel(null);
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
ByteArrayOutputStream dataArray = new ByteArrayOutputStream(256); // it grows when needed
ObjectOutputStream objOutstream = new ObjectOutputStream(dataArray);
objOutstream.writeObject(clone);
objOutstream.close();
//int objectSize = dataArray.size();
//System.out.println("Writing obj to entry: "+objectSize);
} catch (IOException e) {
throw new RuntimeException(e);
}
Object[] args = new Object[1];
args[0]=clone;
Object result = vascManager.invokeBackendMethod(backendId, "provideVascEntryRecordCreator", args);
return (VascEntryRecordCreator)result;
}
public void setId(String id) {
// we cant change id
}
public Map<String, Object> executePageSummary() {
return null;
}
public Map<String, Object> executeTotalSummary() {
return null;
}
public boolean isPageSummary() {
Object[] args = new Object[0];
Object result = vascManager.invokeBackendMethod(backendId, "isPageSummary", args);
return (Boolean)result;
}
public boolean isTotalSummary() {
Object[] args = new Object[0];
Object result = vascManager.invokeBackendMethod(backendId, "isTotalSummary", args);
return (Boolean)result;
}
}
/**
* @return the vascController
*/
public VascController getVascController() {
if (vascController!=null) {
return vascController;
}
try {
VascUserInfo vui = getVascUserInfo();
// get local jvm plugging controller
VascController c = DefaultVascFactory.getDefaultVascController(vui.userId, vui.username, vui.roles);
/*
DefaultVascEntryController con = new DefaultVascEntryController() {
public VascEntry getVascEntryById(String id) {
VascEntry ve = super.getVascEntryById(id);
// add global listener to make sure we have all LAZY properties of a bean before we goto edit mode.
ve.addVascEntryEventListener(VascEventType.DATA_SELECT, new RefreshObjectForLazyPropertiesListener());
return ve;
}
};
((DefaultVascController)c).setVascEntryController(con);
*/
Context context = new InitialContext();
VascServiceManager vascManager = (VascServiceManager)context.lookup(getVascSericeManagerJNDI());
List<String> entryIds = vascManager.getVascEntryIds();
VascEntryControllerLocal localEntryController = (VascEntryControllerLocal)c.getVascEntryController();
VascBackendControllerLocal localBackendController = (VascBackendControllerLocal)c.getVascBackendController();
for (String id:entryIds) {
VascEntry ve = vascManager.getVascEntry(id);
String backendId = ve.getBackendId();
VascBackend vb = new RemoteVascBackend(backendId,vascManager);
for (String key:ve.getEntryParameterKeys()) {
Object value = ve.getEntryParameter(key);
if (value instanceof String==false) {
continue;
}
String paraValue = (String)value;
if (paraValue.startsWith("userPara")==false) {
continue;
}
String[] ps = paraValue.split(":");
String type = ps[1];
String paraTypeValue = ps[2];
SetParameterBackendListener listener = new SetParameterBackendListener(vui.userId,vui.username);
listener.setName(key);
listener.setType(type);
listener.setValue(paraTypeValue);
List<VascEntryBackendEventListener> listeners=new ArrayList<VascEntryBackendEventListener>(10);
listeners.add(listener);
vb = new VascBackendProxyEventExecutor(vb,ve,listeners);
}
localBackendController.addVascBackend(vb);
DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer();
ve = f.finalizeVascEntry(ve,c);
localEntryController.addVascEntry(ve, c);
}
vascController = c;
return vascController;
} catch (Exception e) {
throw new RuntimeException("Could not create remote based vasc controller; "+e.getMessage(),e);
}
}
public void setVascController(VascController vascController) {
}
}

View file

@ -0,0 +1,71 @@
/**
*
*/
package net.forwardfire.vasc.frontends.web.jsf;
import java.util.ArrayList;
import java.util.List;
import javax.el.ValueExpression;
import javax.faces.context.FacesContext;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener;
/**
* @author willemc
*
*/
public class JSFVascEntryEventListener implements VascEntryFrontendEventListener {
private static final long serialVersionUID = 1765054259934158076L;
private String entrySupportVar = null;
public JSFVascEntryEventListener(String entrySupportVar) {
this.entrySupportVar=entrySupportVar;
}
/**
* @see net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener#getEventTypes()
*/
public VascFrontendEventType[] getEventTypes() {
VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.POST_READ};
return result;
}
public void vascEvent(VascEntry entry,Object dataNotUsed) {
try {
for (VascEntryField field:entry.getVascEntryFields()) {
if (field.getVascEntryFieldValue()==null) {
// TODO: fix this for better remote support
VascEntryField fieldClone = field.clone();
fieldClone.getVascValidators().clear();
VascEntryFieldValue v = entry.getVascFrontendData().getVascEntryState().getVascBackend().provideVascEntryFieldValue(fieldClone);
field.setVascEntryFieldValue(v);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
List<Object> data = entry.getVascFrontendData().getVascEntryState().getEntryDataList();
List<Object> result = new ArrayList<Object>(data.size());
int index = 0;
for (Object o:data) {
VascDataBackendBean b = new VascDataBackendBean(entry,o,index);
result.add(b);
index++;
}
ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".tableDataModel.wrappedData}", Object.class);
ve2.setValue(FacesContext.getCurrentInstance().getELContext(), result);
ValueExpression ve3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".tablePagesDataModel.wrappedData}", Object.class);
ve3.setValue(FacesContext.getCurrentInstance().getELContext(), entry.getVascFrontendData().getVascFrontendHelper().getVascBackendPageNumbers(entry));
}
}

View file

@ -0,0 +1,146 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf;
import java.io.Serializable;
import java.util.logging.Logger;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import net.forwardfire.vasc.core.AbstractVascFrontend;
import net.forwardfire.vasc.core.VascFrontendData;
import net.forwardfire.vasc.core.entry.VascEntryExporter;
import net.forwardfire.vasc.frontends.web.jsf.ui.JSFBoolean;
import net.forwardfire.vasc.frontends.web.jsf.ui.JSFLabel;
import net.forwardfire.vasc.frontends.web.jsf.ui.JSFList;
import net.forwardfire.vasc.frontends.web.jsf.ui.JSFText;
import net.forwardfire.vasc.frontends.web.jsf.ui.JSFTextArea;
/**
* Given the jsf vasc renderer its own class
*
*
* @author Willem Cazander
* @version 1.0 Nov 12, 2009
*/
public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Serializable {
private static final long serialVersionUID = 1L;
private Logger logger = null;
public JSFVascFrontendRenderer() {
logger = Logger.getLogger(JSFVascFrontendRenderer.class.getName());
}
// Frontend Stuff
/**
* @see net.forwardfire.vasc.core.VascFrontend#getFrontendType()
*/
public String getFrontendType() {
return "jsf";
}
protected void addUiComponents() {
VascFrontendData vfd = getVascEntry().getVascFrontendData();
// required UI components
vfd.putVascUIComponent(net.forwardfire.vasc.core.ui.VascUIComponent.VASC_LABEL,JSFLabel.class.getName());
vfd.putVascUIComponent(net.forwardfire.vasc.core.ui.VascUIComponent.VASC_TEXT, JSFText.class.getName());
vfd.putVascUIComponent(net.forwardfire.vasc.core.ui.VascUIComponent.VASC_LIST, JSFList.class.getName());
//vfd.putVascUIComponent(net.forwardfire.vasc.core.ui.VascUIComponent.VASC_BUTTON, JSFButton.class.getName());
// optional UI components
vfd.putVascUIComponent(net.forwardfire.vasc.core.ui.VascUIComponent.VASC_BOOLEAN , JSFBoolean.class.getName());
//vfd.putVascUIComponent(net.forwardfire.vasc.core.ui.VascUIComponent.VASC_DATE , JSFDate.class.getName());
vfd.putVascUIComponent(net.forwardfire.vasc.core.ui.VascUIComponent.VASC_TEXTAREA , JSFTextArea.class.getName());
//vfd.putVascUIComponent(net.forwardfire.vasc.core.ui.VascUIComponent.VASC_COLOR , JSFColorChooser.class.getName());
}
/**
* @see net.forwardfire.vasc.core.VascFrontend#renderDelete(java.lang.Object)
*/
public void renderDelete() throws Exception {
logger.finer("renderDelete");
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,getVascEntry().getId());
comp.setRenderFacetState("deleteView");
}
/**
* @see net.forwardfire.vasc.core.VascFrontend#renderEdit(java.lang.Object)
*/
public void renderEdit() throws Exception {
logger.finer("renderEdit");
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,getVascEntry().getId());
comp.setRenderFacetState("editView");
entry.getVascFrontendData().getVascFrontendHelper().editReadOnlyUIComponents(entry);
VascDataBackendBean selBean = null;
if (entry.getVascFrontendData().getVascEntryState().isEditCreate()) {
int index = entry.getVascFrontendData().getVascEntryState().getEntryDataList().size()+1;
selBean = new VascDataBackendBean(entry,entry.getVascFrontendData().getVascEntryState().getEntryDataObject(),index);
} else {
selBean = comp.getSupportBean().getSelectedTableRecord();
}
selBean.setRealValue(true);
comp.getSupportBean().setSelected(selBean);
}
/**
* @see net.forwardfire.vasc.core.VascFrontend#renderExport(net.forwardfire.vasc.core.entry.VascEntryExporter)
*/
public void renderExport(VascEntryExporter exporter) throws Exception {
logger.finer("renderExport");
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,getVascEntry().getId());
comp.setRenderFacetState("exportView");
comp.getSupportBean().setSelectedExporter(exporter);
}
/**
* @see net.forwardfire.vasc.core.VascFrontend#renderView()
*/
public void renderView() throws Exception {
logger.finer("renderView");
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,getVascEntry().getId());
comp.setRenderFacetState("listView");
//if (comp.getSupportBean().getSelected()!=null) {
// comp.getSupportBean().getSelected().setRealValue(false);
// comp.getSupportBean().setSelected(null);
//}
}
}

View file

@ -0,0 +1,444 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import net.forwardfire.vasc.core.VascBackend;
import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascEntryState;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.VascFrontendData;
import net.forwardfire.vasc.core.VascLinkEntry;
import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener;
import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType;
import net.forwardfire.vasc.frontends.web.jsf.ui.JSFListModel;
import net.forwardfire.vasc.impl.DefaultVascFactory;
/**
* Renders an JSF vasc entry views.
*
* This is a already less hacky this is second incarnation of this bean
*
* @author Willem Cazander
* @version 1.0 Nov 16, 2008
*/
public class JSFVascUIComponent extends UIComponentBase {
public static final String FAMILY = "vasc.jsf.component.family";
public static final String VASC_CONTROLLER_KEY = "vascController";
public static final String VASC_FRONTEND_DATA_KEY = "vascFrontendData";
public static final String ENTRY_NAME_KEY = "entryName";
public static final String ENTRY_SUPPORT_VAR_KEY = "entrySupportVar";
public static final String TABLE_RECORD_VAR_KEY = "tableRecordVar";
public static final String INJECT_EDIT_FIELDS_ID = "injectEditFieldsId";
public static final String INJECT_TABLE_OPTIONS_ID = "injectTableOptionsId";
public static final String INJECT_TABLE_COLUMNS_ID = "injectTableColumnsId";
public static final String DISABLE_LINK_COLUMNS = "disableLinkColumns";
public static final String INJECT_TABLE_OPTIONS_ON_CHANGE = "injectTableOptionOnChange";
private JSFVascFrontendRenderer renderer = null;
private JSFVascEntrySupportBean supportBean = null;
private String renderFacetState = null;
private VascLinkEntry link = null;
private VascEntryState linkState = null;
private VascEntryState state = null;
private Object stateEditId = null;
private Logger logger = null;
private Boolean initClear = null;
private String injectTableOptionOnChange = null;
public JSFVascUIComponent() {
logger = Logger.getLogger(JSFVascUIComponent.class.getName());
}
public String getFamily() {
return FAMILY;
}
@Override
public Object saveState(FacesContext facesContext) {
logger.fine("Save State");
Object values[] = new Object[8];
values[0] = super.saveState(facesContext);
values[1] = this.getAttributes().get(VASC_CONTROLLER_KEY);
values[2] = this.getAttributes().get(VASC_FRONTEND_DATA_KEY);
values[3] = this.getAttributes().get(ENTRY_NAME_KEY);
values[4] = renderer;
values[5] = supportBean;
values[6] = renderFacetState;
values[7] = this.getAttributes().get(INJECT_TABLE_OPTIONS_ON_CHANGE);
return values;
}
@Override
public void restoreState(FacesContext facesContext, Object state) {
logger.fine("Resotre State");
Object values[] = (Object[])state;
super.restoreState(facesContext, values[0]);
this.getAttributes().put(VASC_CONTROLLER_KEY, values[1]);
this.getAttributes().put(VASC_FRONTEND_DATA_KEY, values[2]);
this.getAttributes().put(ENTRY_NAME_KEY, values[3]);
renderer = (JSFVascFrontendRenderer) values[4];
supportBean = (JSFVascEntrySupportBean) values[5];
renderFacetState = (String) values[6];
injectTableOptionOnChange = (String) values[7];
// TODO: check if we can move this some day...
String entrySupportVar = (String)getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY);
ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+"}", Object.class);
ve2.setValue(FacesContext.getCurrentInstance().getELContext(), getSupportBean());
}
static public JSFVascUIComponent findVascParent(UIComponent comp) {
if (comp==null) {
return null;
}
if (comp instanceof JSFVascUIComponent) {
return (JSFVascUIComponent)comp;
}
return findVascParent(comp.getParent());
}
static public JSFVascUIComponent findVascChild(UIComponent comp,String entryId) {
if (comp==null) {
return null;
}
if (comp instanceof JSFVascUIComponent) {
JSFVascUIComponent ui = (JSFVascUIComponent)comp;
if (entryId==null) {
return ui;
}
if (entryId.equals(ui.getVascEntry().getId())) {
return ui;
}
return null; // this is a other entry on this view
}
for (UIComponent c:comp.getChildren()) {
Object res = findVascChild(c,entryId);
if (res!=null) {
return (JSFVascUIComponent)res; // found
}
}
return null;
}
/**
* Finds component with the given id
*/
static public UIComponent findComponentById(UIComponent c, String id) {
if (id.equals(c.getId())) {
return c;
}
Iterator<UIComponent> kids = c.getFacetsAndChildren();
while (kids.hasNext()) {
UIComponent found = findComponentById(kids.next(), id);
if (found != null) {
return found;
}
}
return null;
}
public VascEntry getVascEntry() {
return renderer.getVascEntry();
}
protected void initGoto(VascLinkEntry link) {
logger.fine("init goto "+link);
this.link=link;
}
protected void initGoto(VascLinkEntry link,VascEntryState state) {
logger.fine("init goto link: "+link);
this.link=link;
this.linkState=state;
}
protected void initGoto(VascEntryState state) {
logger.fine("init goto "+state);
this.state=state;
}
protected void initGoto(VascEntryState state,Object stateEditId) {
logger.fine("init goto "+state);
this.state=state;
this.stateEditId=stateEditId;
}
public Boolean getInitClear() {
return initClear;
}
@Override
public void encodeBegin(FacesContext context) throws IOException {
logger.fine("Comp encodeBegin link: "+link);
// no need to add multiple
if (renderer==null) {
logger.finer("Adding phase listener: JSFVascValidatePhaseListener");
context.getViewRoot().addPhaseListener(new JSFVascValidatePhaseListener());
}
boolean init = false;
if (renderer==null | link!=null | state!=null) {
renderFacetState = "listView";
VascEntry entry = createClonedVascEntry();
renderer = new JSFVascFrontendRenderer();
try {
renderer.initEntry(entry);
} catch (Exception e) {
throw new RuntimeException("Could not initEntry: "+e.getMessage(),e);
}
supportBean = new JSFVascEntrySupportBean(entry);
// copy search string for preadded search string from application layer
supportBean.setSearchString(entry.getVascFrontendData().getVascEntryState().getVascBackendState().getSearchString());
init = true;
}
if (stateEditId!=null) {
Object rowObject = stateEditId;
// setup for renderEdit() of frontend
List<Object> list = new ArrayList<Object>(1);
list.add(new VascDataBackendBean(supportBean.getVascEntry(),rowObject,0));
supportBean.getTableDataModel().setWrappedData(list);
supportBean.getTableDataModel().setRowIndex(0);
// edit action copyed
try {
VascEntry entry = supportBean.getVascEntry();
entry.getVascFrontendData().getVascEntryState().setEditCreate(false);
entry.getVascFrontendData().getVascFrontendHelper().fireVascEvent(entry, VascFrontendEventType.SELECT, rowObject);
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(rowObject);
entry.getVascFrontendData().getVascFrontend().renderEdit();
} catch (Exception e) {
throw new RuntimeException("Could not renderEdit: "+e.getMessage(),e);
}
}
// refresh all drop down lists..
for (String key:supportBean.getEditSelectItemModels().keySet()) {
Object o = supportBean.getEditSelectItemModels().get(key);
if (o instanceof JSFListModel) {
JSFListModel t = (JSFListModel)o;
t.requestRefresh();
}
}
// set the support bean
String entrySupportVar = (String)getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY);
ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+"}", Object.class);
ve2.setValue(FacesContext.getCurrentInstance().getELContext(), getSupportBean());
// set init for component renderer
if (init) {
initClear = false;
if (link!=null | state!=null) {
initClear = true;
}
}
super.encodeBegin(context);
}
public UIComponent getCurrentView() {
UIComponent result = getFacet(renderFacetState);
if (result==null) {
throw new IllegalArgumentException("Could not get facet: "+renderFacetState);
}
return result;
}
public JSFVascEntrySupportBean getSupportBean() {
return supportBean;
}
public void setRenderFacetState(String renderFacetState) {
this.renderFacetState=renderFacetState;
}
public String getRenderFacetState() {
return renderFacetState;
}
/**
* @return the injectTableOptionOnChange
*/
public String getInjectTableOptionOnChange() {
return injectTableOptionOnChange;
}
/**
* @param injectTableOptionOnChange the injectTableOptionOnChange to set
*/
public void setInjectTableOptionOnChange(String injectTableOptionOnChange) {
this.injectTableOptionOnChange = injectTableOptionOnChange;
}
public VascEntry createClonedVascEntry() {
String entryName = null;
VascController vascController = null;
VascFrontendData frontendData = null;
if (getAttributes().get(VASC_CONTROLLER_KEY) instanceof String) {
// fix for JSP tag handler
logger.finer("Getting expression: "+getAttributes().get(VASC_CONTROLLER_KEY));
ValueExpression ve1 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), (String)getAttributes().get(VASC_CONTROLLER_KEY), Object.class);
ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), (String)getAttributes().get(VASC_FRONTEND_DATA_KEY), Object.class);
ValueExpression ve3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), (String)getAttributes().get(ENTRY_NAME_KEY), String.class);
vascController = (VascController)ve1.getValue( FacesContext.getCurrentInstance().getELContext());
frontendData = (VascFrontendData)ve2.getValue( FacesContext.getCurrentInstance().getELContext());
entryName = (String)ve3.getValue( FacesContext.getCurrentInstance().getELContext());
} else {
vascController = (VascController)getAttributes().get(VASC_CONTROLLER_KEY);
frontendData = (VascFrontendData)getAttributes().get(VASC_FRONTEND_DATA_KEY);
entryName = (String)getAttributes().get(ENTRY_NAME_KEY);
}
if (link!=null) {
entryName = link.getVascEntryId();
}
if (state!=null) {
entryName = state.getVascEntry().getId();
}
VascEntry entry = vascController.getVascEntryController().getVascEntryById(entryName);
if (entry==null) {
throw new NullPointerException("Could not locate '"+entryName+"' from : "+vascController);
}
frontendData.setVascFrontend(null); // reset data obj. todo rm this.
frontendData.setVascController(vascController);
entry.setVascFrontendData(frontendData);
try {
frontendData.initFrontendListeners(entry,"jsf");
} catch (InstantiationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry);
frontendData.getVascEntryState().setVascBackend(backend);
frontendData.getVascEntryState().setVascEntry(entry);
if (state!=null) {
// copy prevois parent
frontendData.getVascEntryState().setParent(state.getParent());
}
if (link!=null) {
// save state
if (linkState==null) {
frontendData.getVascEntryState().setParent(getVascEntry().getVascFrontendData().getVascEntryState());
} else {
frontendData.getVascEntryState().setParent(linkState);
}
// Set parameters
try {
Object selected = getSupportBean().getSelected().getRecord();
for (String parameterName:link.getEntryParameterFieldIdKeys()) {
String fieldId = link.getEntryParameterFieldId(parameterName);
VascEntryField v = getVascEntry().getVascEntryFieldById(fieldId);
if (v==null) {
logger.warning("Could nog get VascEntryField for fieldID: "+fieldId);
continue;
}
if (v.getVascEntryFieldValue()==null) {
logger.warning("Could not get VascEntryFieldValue for fieldID: "+fieldId);
continue;
}
Object selectedValue = v.getVascEntryFieldValue().getValue(v, selected);
// set data parameter on new vasc entry
entry.getVascFrontendData().getVascEntryState().getVascBackendState().setDataParameter(parameterName, selectedValue);
logger.fine("Setting link parameter: "+parameterName+" with: "+selectedValue);
}
for (String fieldId:link.getEntryCreateFieldValueKeys()) {
String selectedfieldId = link.getEntryParameterFieldId(fieldId);
Object selectedValue = selected;
if (selectedfieldId!=null) {
VascEntryField v = getVascEntry().getVascEntryFieldById(selectedfieldId);
selectedValue = v.getVascEntryFieldValue().getValue(v, selected);
}
// create listener for new objects
entry.getVascFrontendData().addVascEntryFrontendEventListener(new CreateEntryFieldValuesListener2(fieldId,selectedValue));
}
} catch (Exception e) {
throw new RuntimeException("error: "+e.getMessage(),e);
}
}
String entrySupportVar = (String)getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY);
entry.getVascFrontendData().addVascEntryFrontendEventListener(new JSFVascEntryEventListener(entrySupportVar));
return entry;
}
class CreateEntryFieldValuesListener2 implements VascEntryFrontendEventListener {
private static final long serialVersionUID = 1L;
private String fieldId = null;
private Object value = null;
public CreateEntryFieldValuesListener2(String fieldId,Object value) {
if (fieldId==null) {
throw new NullPointerException("fieldId may not be null");
}
this.fieldId=fieldId;
this.value=value;
}
public VascFrontendEventType[] getEventTypes() {
VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.PRE_CREATE};
return result;
}
public void vascEvent(VascEntry entry,Object data) {
VascEntryField field = entry.getVascEntryFieldById(fieldId);
try {
field.getVascEntryFieldValue().setValue(field, data, value);
} catch (VascException e) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e);
}
}
}
}

View file

@ -0,0 +1,572 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.util.List;
import java.util.logging.Logger;
import javax.el.ELContext;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;
import javax.faces.component.UISelectMany;
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.component.html.HtmlInputText;
import javax.faces.component.html.HtmlInputTextarea;
import javax.faces.component.html.HtmlMessage;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlSelectBooleanCheckbox;
import javax.faces.component.html.HtmlSelectManyListbox;
import javax.faces.component.html.HtmlSelectManyMenu;
import javax.faces.component.html.HtmlSelectOneListbox;
import javax.faces.component.html.HtmlSelectOneMenu;
import javax.faces.component.html.HtmlSelectOneRadio;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.MethodExpressionActionListener;
import javax.faces.event.ValueChangeEvent;
import javax.faces.event.ValueChangeListener;
import javax.faces.render.Renderer;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.VascLinkEntry;
import net.forwardfire.vasc.core.VascLinkEntryType;
import net.forwardfire.vasc.core.actions.RowVascAction;
import net.forwardfire.vasc.core.ui.VascOptionValueModelListener;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel;
import net.forwardfire.vasc.impl.actions.AddRowAction;
/**
* Renders an JSF vasc entry views.
*
* This is a bit hacky because I'm not a JSF guro.
*
* @author Willem Cazander
* @version 1.0 Nov 16, 2008
*/
public class JSFVascUIComponentRenderer extends Renderer {
private Logger logger = null;
public JSFVascUIComponentRenderer() {
logger = Logger.getLogger(JSFVascUIComponentRenderer.class.getName());
}
@Override
public void encodeBegin(FacesContext facesContext,UIComponent component) throws IOException {
super.encodeBegin(facesContext, component);
ResponseWriter writer = facesContext.getResponseWriter();
JSFVascUIComponent comp = (JSFVascUIComponent)component;
logger.fine("renderen encodeBegin for: "+comp.getRenderFacetState());
writer.startElement("div", component);
//String styleClass = (String)attributes.get(Shuffler.STYLECLASS_ATTRIBUTE_KEY);
//writer.writeAttribute("class", styleClass, null);
// check if injection is needed
if (comp.getInitClear()!=null) {
injectAll(facesContext,comp,comp.getInitClear());
// hack for edit back action to set field disabled
VascEntry entry = comp.getVascEntry();
entry.getVascFrontendData().getVascFrontendHelper().editReadOnlyUIComponents(entry);
}
// render the current facet of the vasc component
UIComponent view = comp.getCurrentView();
view.encodeAll(facesContext);
}
@Override
public void encodeEnd(FacesContext facesContext,UIComponent component) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
writer.endElement("div");
}
// ========== All private
private void injectAll(FacesContext context,JSFVascUIComponent comp,boolean clean) {
String injectEditFieldsId = (String)comp.getAttributes().get(JSFVascUIComponent.INJECT_EDIT_FIELDS_ID);
String injectTableOptionsId = (String)comp.getAttributes().get(JSFVascUIComponent.INJECT_TABLE_OPTIONS_ID);
String injectTableColumnsId = (String)comp.getAttributes().get(JSFVascUIComponent.INJECT_TABLE_COLUMNS_ID);
UIComponent injectEditFieldsComponent = JSFVascUIComponent.findComponentById(comp.getFacet("editView"),injectEditFieldsId);
UIComponent injectTableOptionsComponent = JSFVascUIComponent.findComponentById(comp.getFacet("listView"),injectTableOptionsId);
UIComponent injectTableColumnsComponent = JSFVascUIComponent.findComponentById(comp.getFacet("listView"),injectTableColumnsId);
if (injectEditFieldsComponent==null) {
throw new NullPointerException("Could not find injectEditFieldsId: "+injectEditFieldsId);
}
if (injectTableOptionsComponent==null) {
throw new NullPointerException("Could not find injectTableOptionsId: "+injectTableOptionsId);
}
if (injectTableColumnsComponent==null) {
throw new NullPointerException("Could not find injectTableColumnsId: "+injectTableColumnsId);
}
if (clean) {
logger.finer("Cleaning of all dynamic JSF components.");
injectEditFieldsComponent.getChildren().clear();
injectTableOptionsComponent.getChildren().clear();
injectTableColumnsComponent.getChildren().clear();
}
logger.finer("Injection of all dynamic JSF components.");
try {
addEditFields(context, injectEditFieldsComponent);
addTableOptions(context, injectTableOptionsComponent,comp);
addColumns(context,comp,injectTableColumnsComponent );
} catch (Exception e) {
throw new RuntimeException("Error while injecting; "+e.getMessage(),e);
}
}
private String i18n(VascEntry entry,String key,Object...params) {
return entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key,params);
}
private void addEditFields(FacesContext fc,UIComponent grid) throws FacesException, VascException {
Application application = fc.getApplication();
UIViewRoot viewRoot = fc.getViewRoot();
JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(grid);
VascEntry entry = comp.getVascEntry();
if (entry==null) {
throw new NullPointerException("No parent vasc component found.");
}
String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY);
int column = 0;
for (VascEntryField c:entry.getVascEntryFields()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderEdit(c)==false) {
continue;
}
//System.out.println("Multi edit size: "+c.getVascEntryFieldType().getUIComponentCount(c)+" of: "+c.getVascEntryFieldType());
for (int i=0;i<c.getVascEntryFieldType().getUIComponentCount(c);i++) {
VascUIComponent label = c.getVascEntryFieldType().provideLabelUIComponent(i,c);
VascValueModel model = new VascValueModel();
model.setValue(i18n(entry,c.getName()));
label.createComponent(entry,c,model,grid);
VascUIComponent editor = c.getVascEntryFieldType().provideEditorUIComponent(i,c);
model = new VascValueModel(c.getVascEntryFieldType().provideEditorVascValueModel(i,c));
//model.setValue(c.getVascEntryFieldValue().getValue(c, bean));
//model.addListener(new VascColumnValueModelListener(c,bean));
UIInput jsfEdit = (UIInput)editor.createComponent(entry,c,model,grid);
jsfEdit.addValidator(new VascJSFInputValidator2(c.getId()));
int index = VascDataBackendBean.getIndexId(c);
ValueExpression ve7 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".selected.field"+index+"}", Object.class);
jsfEdit.setValueExpression("value", ve7);
ValueExpression ve8 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".selected != null}", Boolean.class);
jsfEdit.setValueExpression("rendered", ve8);
HtmlMessage message = (HtmlMessage)application.createComponent(HtmlMessage.COMPONENT_TYPE);
message.setId(viewRoot.createUniqueId());
message.setFor(jsfEdit.getId());
message.setErrorClass("style_textBlue");
message.setFatalClass("style_textRed");
message.setInfoClass("style_textBlack");
message.setWarnClass("style_textGreen");
grid.getChildren().add(message);
column++;
// i==0 is for multi field editor support... which is still very in progress
if (i==0) {
entry.getVascFrontendData().addFieldVascUIComponents(c, editor,jsfEdit);
}
}
}
}
class VascJSFInputValidator2 implements Validator,Serializable {
private static final long serialVersionUID = -5715250529474737642L;
private Logger logger = null;
private String fieldId = null;
public VascJSFInputValidator2(String fieldId) {
this.fieldId=fieldId;
logger = Logger.getLogger(VascJSFInputValidator2.class.getName());
}
public void validate(FacesContext context, UIComponent component,Object object) throws ValidatorException {
// always oke, we are runned by phase listener
}
public void validatePhase(FacesContext context, UIComponent component,Object object) throws ValidatorException {
JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(component);
VascEntry entry = comp.getVascEntry();
StringBuffer buf;
try {
VascEntryField field = entry.getVascEntryFieldById(fieldId);
int index = VascDataBackendBean.getIndexId(field);
String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY);
logger.fine("sup-sel: "+comp.getSupportBean().getSelected()+" index: "+index);
// note we have to set the value to the vasc backend before we can run validation
ValueExpression ve7 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".selected.field"+index+"}", Object.class);
ve7.setValue(FacesContext.getCurrentInstance().getELContext(), object);
List<String> errors = entry.getVascFrontendData().getVascFrontendHelper().validateObjectField(field);
logger.fine("Validate: "+component+" errors: "+errors.size()+" value: "+object);
if (errors.isEmpty()) {
return; // no errors
}
buf = new StringBuffer(200);
for (String err:errors) {
buf.append(err);
buf.append('\n');
}
} catch (Exception e) {
e.printStackTrace();
return;
}
FacesMessage message = new FacesMessage(buf.toString());
message.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(message);
}
}
private void addTableOptions(FacesContext fc,UIComponent grid,JSFVascUIComponent comp) throws FacesException, VascException {
//Application application = fc.getApplication();
//UIViewRoot viewRoot = fc.getViewRoot();
//JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(grid);
VascEntry entry = comp.getVascEntry();
for (VascEntryField option:entry.getListOptions()) {
for (int i=0;i<option.getVascEntryFieldType().getUIComponentCount(option);i++) {
VascUIComponent label = option.getVascEntryFieldType().provideLabelUIComponent(i,option);
VascValueModel model = new VascValueModel();
model.setValue(i18n(entry,option.getName()));
label.createComponent(entry,option,model,grid);
VascUIComponent editor = option.getVascEntryFieldType().provideEditorUIComponent(i,option);
model = new VascValueModel(option.getVascEntryFieldType().provideEditorVascValueModel(i,option));
model.addListener(new VascOptionValueModelListener(option));
model.setValue(option.getDefaultValue());
UIInput jsfEdit = (UIInput)editor.createComponent(entry,option,model,grid);
jsfEdit.addValueChangeListener(new ModelChangeListener(model));
if (comp.getInjectTableOptionOnChange()!=null && comp.getInjectTableOptionOnChange().isEmpty()==false) {
if (jsfEdit instanceof HtmlSelectBooleanCheckbox) {
((HtmlSelectBooleanCheckbox)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange());
}
if (jsfEdit instanceof HtmlSelectManyMenu) {
((HtmlSelectManyMenu)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange());
}
if (jsfEdit instanceof HtmlInputText) {
((HtmlInputText)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange());
}
if (jsfEdit instanceof HtmlInputTextarea) {
((HtmlInputTextarea)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange());
}
if (jsfEdit instanceof HtmlSelectManyListbox) {
((HtmlSelectManyListbox)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange());
}
if (jsfEdit instanceof HtmlSelectOneMenu) {
((HtmlSelectOneMenu)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange());
}
if (jsfEdit instanceof HtmlSelectOneRadio) {
((HtmlSelectOneRadio)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange());
}
if (jsfEdit instanceof HtmlSelectOneListbox) {
((HtmlSelectOneListbox)jsfEdit).setOnchange(comp.getInjectTableOptionOnChange());
}
}
Class<?> clazz = option.getVascEntryFieldType().getAutoDetectClass();
if (clazz!=null && model.getValue()!=null) {
if (clazz.equals(model.getValue().getClass())==false) {
// lets try setting correct default.
try {
Constructor<?> c = clazz.getConstructor(String.class);
Object value = c.newInstance(model.getValue());
jsfEdit.setValue(value);
} catch (Exception e) {
throw new VascException(e);
}
} else {
jsfEdit.setValue(model.getValue()); // set default value
}
}
// i==0 is for multi field editor support... which is stell very in progress aka not working
if (i==0) {
entry.getVascFrontendData().addFieldVascUIComponents(option, editor,jsfEdit);
}
}
}
entry.getVascFrontendData().getVascFrontendHelper().headerOptionsCreatedFillData(entry);
}
public class ModelChangeListener implements ValueChangeListener,Serializable {
private static final long serialVersionUID = 1L;
VascValueModel model;
public ModelChangeListener(VascValueModel model) {
this.model=model;
}
public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {
try {
model.setValue(event.getNewValue());
} catch (VascException e) {
throw new AbortProcessingException(e);
}
}
}
private void addColumns(FacesContext fc,JSFVascUIComponent comp,UIComponent table) {
Application application = fc.getApplication();
UIViewRoot viewRoot = fc.getViewRoot();
VascEntry entry = comp.getVascEntry();
String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY);
String tableRecordVar = (String)comp.getAttributes().get(JSFVascUIComponent.TABLE_RECORD_VAR_KEY);
if (!entry.getVascFrontendData().getVascFrontendHelper().getMultiRowActions(entry).isEmpty()) {
UIColumn colUp = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE);
colUp.setId(viewRoot.createUniqueId());
/*
// Select box head in table
HtmlCommandLink selectAll = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
selectAll.setId(viewRoot.createUniqueId());
selectAll.setType("selectAll");
MethodExpression actionExpression = getMethodExpression("#{"+entrySupportVar+".selectAllAction}");
MethodExpressionActionListener meActionListener = new MethodExpressionActionListener(actionExpression);
selectAll.addActionListener(meActionListener);
HtmlOutputText orderUp = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
orderUp.setId(viewRoot.createUniqueId());
orderUp.setEscape(false);
orderUp.setValue("selectAll");
selectAll.getChildren().add(orderUp);
colUp.setHeader(selectAll);
*/
HtmlSelectBooleanCheckbox select = (HtmlSelectBooleanCheckbox)application.createComponent(HtmlSelectBooleanCheckbox.COMPONENT_TYPE);
select.setId(viewRoot.createUniqueId());
select.setStyleClass("js_table_select_all");
ValueExpression ve1 = application.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(),"#{"+entrySupportVar+".vascEntry.vascFrontendData.vascEntryState.multiActionSelection["+tableRecordVar+".recordId]}",Object.class);
select.setValueExpression("value", ve1);
colUp.getChildren().add(select);
table.getChildren().add(colUp);
}
for (VascEntryField c:entry.getVascEntryFields()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderList(c)==false) {
continue;
}
UIColumn col = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE);
col.setId(viewRoot.createUniqueId());
HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
link.setId(viewRoot.createUniqueId());
link.setType(c.getId());
MethodExpression actionExpression = getMethodExpression("#{"+entrySupportVar+".sortAction}");
MethodExpressionActionListener meActionListener = new MethodExpressionActionListener(actionExpression);
link.addActionListener(meActionListener);
HtmlOutputText out2 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
out2.setId(viewRoot.createUniqueId());
out2.setEscape(false);
out2.setValue(i18n(entry,c.getName())+"&nbsp;");
HtmlOutputText orderUp = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
orderUp.setId(viewRoot.createUniqueId());
orderUp.setEscape(false);
orderUp.setValue("&#x2191;"); //
ValueExpression ren2 = application.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".sortOrder==true and "+entrySupportVar+".sortField=='"+c.getId()+"'}", Boolean.class);
orderUp.setValueExpression("rendered", ren2);
HtmlOutputText orderDown = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
orderDown.setId(viewRoot.createUniqueId());
orderDown.setEscape(false);
orderDown.setValue("&#x2193;"); //
ValueExpression ren3 = application.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".sortOrder==false and "+entrySupportVar+".sortField=='"+c.getId()+"'}", Boolean.class);
orderDown.setValueExpression("rendered", ren3);
link.getChildren().add(out2);
link.getChildren().add(orderUp);
link.getChildren().add(orderDown);
col.setHeader(link);
HtmlOutputText out = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
out.setId(viewRoot.createUniqueId());
int index = VascDataBackendBean.getIndexId(c);
ValueExpression ve1 = application.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(),"#{"+tableRecordVar+".field"+index+"}",Object.class);
out.setValueExpression("value", ve1);
col.getChildren().add(out);
table.getChildren().add(col);
}
if (entry.getVascFrontendData().getVascEntryState().getVascBackend().isRecordMoveable()) {
UIColumn colUp = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE);
colUp.setId(viewRoot.createUniqueId());
HtmlCommandLink linkUp = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
linkUp.setId(viewRoot.createUniqueId());
linkUp.setType("up");
MethodExpression actionExpression = getMethodExpression("#{"+entrySupportVar+".moveAction}");
MethodExpressionActionListener meActionListener = new MethodExpressionActionListener(actionExpression);
linkUp.addActionListener(meActionListener);
HtmlOutputText orderUp = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
orderUp.setId(viewRoot.createUniqueId());
orderUp.setEscape(false);
orderUp.setValue("&#x2191;&nbsp;up"); //
linkUp.getChildren().add(orderUp);
colUp.getChildren().add(linkUp);
table.getChildren().add(colUp);
HtmlCommandLink linkDown = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
linkDown.setId(viewRoot.createUniqueId());
linkDown.setType("down");
MethodExpression actionExpression2 = getMethodExpression("#{"+entrySupportVar+".moveAction}");
MethodExpressionActionListener meActionListener2 = new MethodExpressionActionListener(actionExpression2);
linkDown.addActionListener(meActionListener2);
UIColumn colDown = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE);
colDown.setId(viewRoot.createUniqueId());
HtmlOutputText orderDown = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
orderDown.setId(viewRoot.createUniqueId());
orderDown.setEscape(false);
orderDown.setValue("&#x2193;&nbsp;down"); //
linkDown.getChildren().add(orderDown);
colDown.getChildren().add(linkDown);
table.getChildren().add(colDown);
}
for (VascLinkEntry vascLink:entry.getVascFrontendData().getVascFrontendHelper().getVascLinkEntryByType(entry, VascLinkEntryType.LIST)) {
UIColumn col = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE);
col.setId(viewRoot.createUniqueId());
UIOutput colHeader = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);
colHeader.setId(viewRoot.createUniqueId());
colHeader.setValue("link");
col.setHeader(colHeader);
HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
link.setId(viewRoot.createUniqueId());
link.setType(vascLink.getId());
MethodExpression actionExpression = getMethodExpression("#{"+entrySupportVar+".linkAction}");
MethodExpressionActionListener meActionListener = new MethodExpressionActionListener(actionExpression);
link.addActionListener(meActionListener);
HtmlOutputText out = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
out.setId(viewRoot.createUniqueId());
out.setValue(i18n(entry,vascLink.getName()));
link.getChildren().add(out);
col.getChildren().add(link);
table.getChildren().add(col);
}
for (RowVascAction action:entry.getRowActions()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderRowVascAction(action)==false) {
continue;
}
if (AddRowAction.ACTION_ID.equals(action.getId())) {
continue;
}
UIColumn col = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE);
col.setId(viewRoot.createUniqueId());
UIOutput colHeader = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);
colHeader.setId(viewRoot.createUniqueId());
colHeader.setValue(i18n(entry,action.getName()));
col.setHeader(colHeader);
HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
link.setId(viewRoot.createUniqueId());
link.setType(action.getId());
MethodExpression actionExpression = getMethodExpression("#{"+entrySupportVar+".rowAction}");
MethodExpressionActionListener meActionListener = new MethodExpressionActionListener(actionExpression);
link.addActionListener(meActionListener);
HtmlOutputText out = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
out.setId(viewRoot.createUniqueId());
out.setValue(i18n(entry,action.getName()));
link.getChildren().add(out);
col.getChildren().add(link);
table.getChildren().add(col);
}
}
private MethodExpression getMethodExpression(String name) {
Class<?>[] argtypes = new Class[1];
argtypes[0] = ActionEvent.class;
FacesContext facesCtx = FacesContext.getCurrentInstance();
ELContext elContext = facesCtx.getELContext();
return facesCtx.getApplication().getExpressionFactory().createMethodExpression(elContext, name, null, argtypes);
}
};

View file

@ -0,0 +1,232 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.webapp.UIComponentELTag;
/**
*
*
* @author Willem Cazander
* @version 1.0 Nov 16, 2008
*/
public class JSFVascUIComponentTag extends UIComponentELTag {
public static final String COMPONENT_TYPE = "vasc.jsf.component";
public static final String RENDERER_TYPE = "vasc.jsf.component.renderer";
private ValueExpression vascController = null;
private ValueExpression vascFrontendData = null;
private ValueExpression entryName = null;
private ValueExpression entrySupportVar = null;
private ValueExpression tableRecordVar = null;
private ValueExpression injectEditFieldsId = null;
private ValueExpression injectTableOptionsId = null;
private ValueExpression injectTableColumnsId = null;
private ValueExpression disableLinkColumns = null;
@Override
public String getComponentType() {
return COMPONENT_TYPE;
}
@Override
public String getRendererType() {
return RENDERER_TYPE;
}
/**
* @see javax.faces.webapp.UIComponentELTag#setProperties(javax.faces.component.UIComponent)
*/
@Override
protected void setProperties(UIComponent component) {
super.setProperties(component);
processProperty(component, vascController, JSFVascUIComponent.VASC_CONTROLLER_KEY);
processProperty(component, vascFrontendData, JSFVascUIComponent.VASC_FRONTEND_DATA_KEY);
processProperty(component, entryName, JSFVascUIComponent.ENTRY_NAME_KEY);
processProperty(component, entrySupportVar, JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY);
processProperty(component, tableRecordVar, JSFVascUIComponent.TABLE_RECORD_VAR_KEY);
processProperty(component, injectEditFieldsId, JSFVascUIComponent.INJECT_EDIT_FIELDS_ID);
processProperty(component, injectTableOptionsId,JSFVascUIComponent.INJECT_TABLE_OPTIONS_ID);
processProperty(component, injectTableColumnsId,JSFVascUIComponent.INJECT_TABLE_COLUMNS_ID);
processProperty(component, disableLinkColumns ,JSFVascUIComponent.DISABLE_LINK_COLUMNS);
}
public void release() {
super.release();
vascController = null;
vascFrontendData = null;
entryName = null;
entrySupportVar = null;
tableRecordVar = null;
injectEditFieldsId = null;
injectTableOptionsId = null;
injectTableColumnsId = null;
disableLinkColumns = null;
}
protected final void processProperty(final UIComponent component, final ValueExpression property,final String propertyName) {
if (property != null) {
if(property.isLiteralText()) {
component.getAttributes().put(propertyName, property.getExpressionString());
} else {
component.setValueExpression(propertyName, property);
}
}
}
// ============= BEAN FIELDS
/**
* @return the vascController
*/
public ValueExpression getVascController() {
return vascController;
}
/**
* @param vascController the vascController to set
*/
public void setVascController(ValueExpression vascController) {
this.vascController = vascController;
}
/**
* @return the entryName
*/
public ValueExpression getEntryName() {
return entryName;
}
/**
* @param entryName the entryName to set
*/
public void setEntryName(ValueExpression entryName) {
this.entryName = entryName;
}
/**
* @return the vascFrontendData
*/
public ValueExpression getVascFrontendData() {
return vascFrontendData;
}
/**
* @param vascFrontendData the vascFrontendData to set
*/
public void setVascFrontendData(ValueExpression vascFrontendData) {
this.vascFrontendData = vascFrontendData;
}
/**
* @return the entrySupportVar
*/
public ValueExpression getEntrySupportVar() {
return entrySupportVar;
}
/**
* @param entrySupportVar the entrySupportVar to set
*/
public void setEntrySupportVar(ValueExpression entrySupportVar) {
this.entrySupportVar = entrySupportVar;
}
/**
* @return the injectEditFieldsId
*/
public ValueExpression getInjectEditFieldsId() {
return injectEditFieldsId;
}
/**
* @param injectEditFieldsId the injectEditFieldsId to set
*/
public void setInjectEditFieldsId(ValueExpression injectEditFieldsId) {
this.injectEditFieldsId = injectEditFieldsId;
}
/**
* @return the injectTableOptionsId
*/
public ValueExpression getInjectTableOptionsId() {
return injectTableOptionsId;
}
/**
* @param injectTableOptionsId the injectTableOptionsId to set
*/
public void setInjectTableOptionsId(ValueExpression injectTableOptionsId) {
this.injectTableOptionsId = injectTableOptionsId;
}
/**
* @return the injectTableColumnsId
*/
public ValueExpression getInjectTableColumnsId() {
return injectTableColumnsId;
}
/**
* @param injectTableColumnsId the injectTableColumnsId to set
*/
public void setInjectTableColumnsId(ValueExpression injectTableColumnsId) {
this.injectTableColumnsId = injectTableColumnsId;
}
/**
* @return the tableRecordVar
*/
public ValueExpression getTableRecordVar() {
return tableRecordVar;
}
/**
* @param tableRecordVar the tableRecordVar to set
*/
public void setTableRecordVar(ValueExpression tableRecordVar) {
this.tableRecordVar = tableRecordVar;
}
/**
* @return the disableLinkColumns
*/
public ValueExpression getDisableLinkColumns() {
return disableLinkColumns;
}
/**
* @param disableLinkColumns the disableLinkColumns to set
*/
public void setDisableLinkColumns(ValueExpression disableLinkColumns) {
this.disableLinkColumns = disableLinkColumns;
}
}

View file

@ -0,0 +1,107 @@
/**
*
*/
package net.forwardfire.vasc.frontends.web.jsf;
import java.util.Iterator;
import java.util.Map;
import java.util.logging.Logger;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.frontends.web.jsf.JSFVascUIComponentRenderer.VascJSFInputValidator2;
/**
* JSFVascValidatePhaseListener runs the vasc field edit fields.
*
* @author Willem Cazander
* @version 1.0 Nov 15, 2009
*/
public class JSFVascValidatePhaseListener implements PhaseListener {
private static final long serialVersionUID = 1L;
private Logger logger = null;
public JSFVascValidatePhaseListener() {
logger = Logger.getLogger(JSFVascValidatePhaseListener.class.getName());
}
private static final String SAVE_ACTION_ID_HACK = "VASC_SAVE";
public void afterPhase(PhaseEvent event) {
FacesContext context = event.getFacesContext();
// we really only want validation this early when saveing.
// this is currently a bit hacky impl;
Map<String,String> requestMap = context.getExternalContext().getRequestParameterMap();
for (String key:requestMap.keySet()) {
if (key.contains(SAVE_ACTION_ID_HACK)) {
validateUIInput(context.getViewRoot(),context);
return;
}
}
}
public void beforePhase(PhaseEvent event) {
}
public PhaseId getPhaseId() {
return PhaseId.PROCESS_VALIDATIONS;
}
private void validateUIInput(UIComponent component,FacesContext context) {
if (component instanceof UIInput) {
JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(component);
logger.finer("Validate UIInput: "+component+" comp: "+comp);
if (comp==null) {
return; // non-vasc ui-input
}
if (comp.getSupportBean().getSelected()==null) {
return; // no editing
}
VascEntry entry = comp.getVascEntry();
if (entry.getVascFrontendData().getVascEntryState().getEntryDataObject()==null) {
return; // we are not in edit mode.
}
UIInput in = (UIInput)component;
for (Validator v:in.getValidators()) {
if (v instanceof VascJSFInputValidator2) {
VascJSFInputValidator2 validator = (VascJSFInputValidator2)v;
try {
in.setValid(true);
validator.validatePhase(context, in, in.getValue());
} catch (ValidatorException ve) {
in.setValid(false);
// note: ve has the message already but this is the UIInput way
FacesMessage message;
String validatorMessageString = in.getValidatorMessage();
if (null != validatorMessageString) {
message = new FacesMessage(FacesMessage.SEVERITY_ERROR,validatorMessageString,validatorMessageString);
message.setSeverity(FacesMessage.SEVERITY_ERROR);
} else {
message = ve.getFacesMessage();
}
if (message != null) {
context.addMessage(in.getClientId(context), message);
}
}
}
}
}
Iterator<UIComponent> kids = component.getFacetsAndChildren();
while (kids.hasNext()) {
UIComponent child = kids.next();
validateUIInput(child,context);
}
}
}

View file

@ -0,0 +1,521 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf;
import java.io.Serializable;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
/**
*
*
* @author Willem Cazander
* @version 1.0 May 03, 2009
*/
public class VascDataBackendBean implements Serializable {
private static final long serialVersionUID = 3881688974089760074L;
private VascEntry entry = null;
private Object record = null;
private boolean realValue = false;
private int recordId = 0;
public VascDataBackendBean(VascEntry entry,Object record,int recordId) {
this.entry=entry;
this.record=record;
this.recordId=recordId;
}
public boolean isRealValue() {
return realValue;
}
public void setRealValue(boolean realValue) {
this.realValue=realValue;
}
static public VascEntryField getFieldIdByIndex(VascEntry entry,int index) {
if (index>entry.getVascEntryFields().size()) {
throw new IllegalArgumentException("Index is bigger then total field size: "+index);
}
return entry.getVascEntryFields().get(index);
}
static public int getIndexId(VascEntryField field) {
int i =0;
for (VascEntryField f:field.getVascEntry().getVascEntryFields()) {
if (f.getId().equals(field.getId())) {
return i;
}
i++;
}
throw new IllegalArgumentException("Could not find field.");
}
private Object getValue(int index) {
try {
VascEntryField field = getFieldIdByIndex(entry,index);
VascEntryFieldValue value = field.getVascEntryFieldValue();
if (isRealValue()) {
return value.getValue(field, record);
}
return value.getDisplayValue(field, record);
} catch (VascException e) {
return "Error: "+e.getMessage();
}
}
private void setValue(int index,Object valueObject) {
try {
VascEntryField field = getFieldIdByIndex(entry,index);
VascEntryFieldValue value = field.getVascEntryFieldValue();
value.setValue(field, record,valueObject);
} catch (VascException e) {
throw new RuntimeException("Could not set value on record.",e);
}
}
public Object getRecord() {
return record;
}
public int getRecordId() {
return recordId;
}
// GET/SET bean methods for using in EL
public Object getField0() {
return getValue(0);
}
public void setField0(Object o) {
setValue(0,o);
}
public Object getField1() {
return getValue(1);
}
public void setField1(Object o) {
setValue(1,o);
}
public Object getField2() {
return getValue(2);
}
public void setField2(Object o) {
setValue(2,o);
}
public Object getField3() {
return getValue(3);
}
public void setField3(Object o) {
setValue(3,o);
}
public Object getField4() {
return getValue(4);
}
public void setField4(Object o) {
setValue(4,o);
}
public Object getField5() {
return getValue(5);
}
public void setField5(Object o) {
setValue(5,o);
}
public Object getField6() {
return getValue(6);
}
public void setField6(Object o) {
setValue(6,o);
}
public Object getField7() {
return getValue(7);
}
public void setField7(Object o) {
setValue(7,o);
}
public Object getField8() {
return getValue(8);
}
public void setField8(Object o) {
setValue(8,o);
}
public Object getField9() {
return getValue(9);
}
public void setField9(Object o) {
setValue(9,o);
}
public Object getField10() {
return getValue(10);
}
public void setField10(Object o) {
setValue(10,o);
}
public Object getField11() {
return getValue(11);
}
public void setField11(Object o) {
setValue(11,o);
}
public Object getField12() {
return getValue(12);
}
public void setField12(Object o) {
setValue(12,o);
}
public Object getField13() {
return getValue(13);
}
public void setField13(Object o) {
setValue(13,o);
}
public Object getField14() {
return getValue(14);
}
public void setField14(Object o) {
setValue(14,o);
}
public Object getField15() {
return getValue(15);
}
public void setField15(Object o) {
setValue(15,o);
}
public Object getField16() {
return getValue(16);
}
public void setField16(Object o) {
setValue(16,o);
}
public Object getField17() {
return getValue(17);
}
public void setField17(Object o) {
setValue(17,o);
}
public Object getField18() {
return getValue(18);
}
public void setField18(Object o) {
setValue(18,o);
}
public Object getField19() {
return getValue(19);
}
public void setField19(Object o) {
setValue(19,o);
}
public Object getField20() {
return getValue(20);
}
public void setField20(Object o) {
setValue(20,o);
}
public Object getField21() {
return getValue(21);
}
public void setField21(Object o) {
setValue(21,o);
}
public Object getField22() {
return getValue(22);
}
public void setField22(Object o) {
setValue(22,o);
}
public Object getField23() {
return getValue(23);
}
public void setField23(Object o) {
setValue(23,o);
}
public Object getField24() {
return getValue(24);
}
public void setField24(Object o) {
setValue(24,o);
}
public Object getField25() {
return getValue(25);
}
public void setField25(Object o) {
setValue(25,o);
}
public Object getField26() {
return getValue(26);
}
public void setField26(Object o) {
setValue(26,o);
}
public Object getField27() {
return getValue(27);
}
public void setField27(Object o) {
setValue(27,o);
}
public Object getField28() {
return getValue(28);
}
public void setField28(Object o) {
setValue(28,o);
}
public Object getField29() {
return getValue(29);
}
public void setField29(Object o) {
setValue(29,o);
}
public Object getField30() {
return getValue(30);
}
public void setField30(Object o) {
setValue(30,o);
}
public Object getField31() {
return getValue(31);
}
public void setField31(Object o) {
setValue(31,o);
}
public Object getField32() {
return getValue(32);
}
public void setField32(Object o) {
setValue(32,o);
}
public Object getField33() {
return getValue(33);
}
public void setField33(Object o) {
setValue(33,o);
}
public Object getField34() {
return getValue(34);
}
public void setField34(Object o) {
setValue(34,o);
}
public Object getField35() {
return getValue(35);
}
public void setField35(Object o) {
setValue(35,o);
}
public Object getField36() {
return getValue(36);
}
public void setField36(Object o) {
setValue(36,o);
}
public Object getField37() {
return getValue(37);
}
public void setField37(Object o) {
setValue(37,o);
}
public Object getField38() {
return getValue(38);
}
public void setField38(Object o) {
setValue(38,o);
}
public Object getField39() {
return getValue(39);
}
public void setField39(Object o) {
setValue(39,o);
}
public Object getField40() {
return getValue(40);
}
public void setField40(Object o) {
setValue(40,o);
}
public Object getField41() {
return getValue(41);
}
public void setField41(Object o) {
setValue(41,o);
}
public Object getField42() {
return getValue(42);
}
public void setField42(Object o) {
setValue(42,o);
}
public Object getField43() {
return getValue(43);
}
public void setField43(Object o) {
setValue(43,o);
}
public Object getField44() {
return getValue(44);
}
public void setField44(Object o) {
setValue(44,o);
}
public Object getField45() {
return getValue(45);
}
public void setField45(Object o) {
setValue(45,o);
}
public Object getField46() {
return getValue(46);
}
public void setField46(Object o) {
setValue(46,o);
}
public Object getField47() {
return getValue(47);
}
public void setField47(Object o) {
setValue(47,o);
}
public Object getField48() {
return getValue(48);
}
public void setField48(Object o) {
setValue(48,o);
}
public Object getField49() {
return getValue(49);
}
public void setField49(Object o) {
setValue(49,o);
}
}

View file

@ -0,0 +1,191 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf;
import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.FactoryFinder;
import javax.faces.application.ViewExpiredException;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContextFactory;
import javax.faces.lifecycle.Lifecycle;
import javax.faces.lifecycle.LifecycleFactory;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Parses the Request info path info 3 vasc attributes an dispatches the request to the templateFile.
*
* @author Willem Cazander
* @version 1.0 Mar 21, 2009
*/
public class VascRequestFacesFilter implements Filter {
private static final long serialVersionUID = 10l;
private Logger logger = null;
private String templateFile = null;
private ServletContext servletContext = null;
private String resourceBundle = null;
/**
* @see javax.servlet.Filter#destroy()
*/
public void destroy() {
servletContext = null;
templateFile = null;
logger = null;
}
/**
* @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
*/
public void init(FilterConfig config) throws ServletException {
logger = Logger.getLogger(VascRequestFacesFilter.class.getName());
templateFile=config.getInitParameter("templateFile");
if (templateFile==null) {
throw new ServletException("No templateFile init-param found.");
}
String resourceBundle=config.getInitParameter("resourceBundle");
if (resourceBundle==null) {
throw new ServletException("No resourceBundle init-param found.");
}
ResourceBundle.getBundle(resourceBundle); // test if it loads
servletContext=config.getServletContext();
}
/**
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest)servletRequest;
HttpServletResponse response = (HttpServletResponse)servletResponse;
// request info
String path = request.getRequestURI();
String v = "/vasc/";
if (path.contains(v)) {
path = path.substring(path.indexOf(v)+v.length());
}
// stuff to fill
String entityName = null;
String actionName = null;
String actionRecordId = null;
// parse request info
//path = path.substring(1); // rm /
int index = path.indexOf("/"); // check next /
String actionString = null;
if (index>0) {
actionString = path.substring(index+1);
entityName = path.substring(0,index);
} else {
entityName = path;
}
if (actionString!=null) {
index = actionString.indexOf("/");
String recordString = null;
if (index>0) {
recordString = actionString.substring(index+1);
actionName = actionString.substring(0,index);
} else {
actionName = actionString;
}
if (recordString!=null) {
actionRecordId = recordString;
}
}
//log
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,"entityName="+entityName+" actionName="+actionName+" actionRecordId="+actionRecordId);
}
// Acquire the FacesContext instance for this request
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext == null) {
FacesContextFactory facesContextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
facesContext = facesContextFactory.getFacesContext(servletContext, request, response, lifecycle);
ProtectedFacesContext.setFacesContextAsCurrentInstance(facesContext);
UIViewRoot viewRoot = facesContext.getApplication().getViewHandler().createView(facesContext,entityName+actionName);
facesContext.setViewRoot(viewRoot);
}
// add to response
request.setAttribute("requestScopeVascEntityName", entityName);
request.setAttribute("requestScopeVascActionName", actionName);
request.setAttribute("requestScopeVascRecordId" , actionRecordId);
request.setAttribute("requestScopeVascPath" , request.getRequestURI());
// Set page title
Locale locale = facesContext.getViewRoot().getLocale();
if (locale==null) {
logger.info("Failling back to defualt.");
locale = new Locale("nl");
}
try {
ResourceBundle i18n = ResourceBundle.getBundle(resourceBundle,locale);
String titleI18n = i18n.getString("vasc.entry."+entityName+".name");
request.setAttribute("requestScopeVascEntityNameI18n" ,titleI18n);
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("requestScopeVascEntityNameI18n" ,entityName);
}
try {
request.getRequestDispatcher(templateFile).forward(request, response);
} catch (ViewExpiredException e) {
// lets try again
response.sendRedirect(request.getRequestURL().toString());
}
// done
}
private abstract static class ProtectedFacesContext extends FacesContext {
protected static void setFacesContextAsCurrentInstance(FacesContext facesContext) {
FacesContext.setCurrentInstance(facesContext);
}
}
}

View file

@ -0,0 +1,123 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf;
import java.io.IOException;
import java.util.Locale;
import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
/**
* Fixes the action url
*
* @author Willem Cazander
* @version 1.0 May 05, 2009
*/
public class VascViewHandler extends ViewHandler {
private ViewHandler parentViewHandler = null;
public VascViewHandler(ViewHandler viewHandler) {
super();
this.parentViewHandler = viewHandler;
}
/**
* @see javax.faces.application.ViewHandler#getActionURL(javax.faces.context.FacesContext, java.lang.String)
*/
@Override
public String getActionURL(FacesContext context, String name) {
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
if (request.getAttribute("requestScopeVascPath")==null) {
return parentViewHandler.getActionURL(context, name);
}
String path = (String)request.getAttribute("requestScopeVascPath");
return path;
}
/**
* @see javax.faces.application.ViewHandler#calculateLocale(javax.faces.context.FacesContext)
*/
@Override
public Locale calculateLocale(FacesContext context) {
return parentViewHandler.calculateLocale(context);
}
/**
* @see javax.faces.application.ViewHandler#calculateRenderKitId(javax.faces.context.FacesContext)
*/
@Override
public String calculateRenderKitId(FacesContext context) {
return parentViewHandler.calculateRenderKitId(context);
}
/**
* @see javax.faces.application.ViewHandler#createView(javax.faces.context.FacesContext, java.lang.String)
*/
@Override
public UIViewRoot createView(FacesContext context, String name) {
return parentViewHandler.createView(context, name);
}
/**
* @see javax.faces.application.ViewHandler#getResourceURL(javax.faces.context.FacesContext, java.lang.String)
*/
@Override
public String getResourceURL(FacesContext context, String resource) {
return parentViewHandler.getResourceURL(context, resource);
}
/**
* @see javax.faces.application.ViewHandler#renderView(javax.faces.context.FacesContext, javax.faces.component.UIViewRoot)
*/
@Override
public void renderView(FacesContext context, UIViewRoot viewRoot) throws IOException, FacesException {
parentViewHandler.renderView(context, viewRoot);
}
/**
* @see javax.faces.application.ViewHandler#restoreView(javax.faces.context.FacesContext, java.lang.String)
*/
@Override
public UIViewRoot restoreView(FacesContext context, String name) {
return parentViewHandler.restoreView(context, name);
}
/**
* @see javax.faces.application.ViewHandler#writeState(javax.faces.context.FacesContext)
*/
@Override
public void writeState(FacesContext context) throws IOException {
parentViewHandler.writeState(context);
}
}

View file

@ -0,0 +1,77 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf.ui;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.frontends.web.jsf.JSFVascUIComponent;
/**
*
*
* @author Willem Cazander
* @version 1.0 Aug 8, 2009
*/
abstract public class AbstractJSFBaseComponent implements VascUIComponent {
protected String componentId = null;
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
return "";
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String text) {
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
UIComponent component = (UIComponent)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
return component.isRendered();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
// todo: disabled until templates fixes
//UIComponent component = (UIComponent)net.forwardfire.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
//component.setRendered(rendered);
}
}

View file

@ -0,0 +1,79 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf.ui;
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlSelectBooleanCheckbox;
import javax.faces.context.FacesContext;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascValueModel;
import net.forwardfire.vasc.frontends.web.jsf.JSFVascUIComponent;
/**
*
*
* @author Willem Cazander
* @version 1.0 Mar 28, 2009
*/
public class JSFBoolean extends AbstractJSFBaseComponent {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
HtmlSelectBooleanCheckbox component = (HtmlSelectBooleanCheckbox)application.createComponent(HtmlSelectBooleanCheckbox.COMPONENT_TYPE);
component.setId(viewRoot.createUniqueId());
componentId = component.getId();
((UIComponent)gui).getChildren().add(component);
return component;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
HtmlSelectBooleanCheckbox component = (HtmlSelectBooleanCheckbox)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
return component.isDisabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
HtmlSelectBooleanCheckbox component = (HtmlSelectBooleanCheckbox)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
component.setDisabled(disabled);
}
}

View file

@ -0,0 +1,75 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf.ui;
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.context.FacesContext;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascValueModel;
/**
*
*
* @author Willem Cazander
* @version 1.0 Mar 25, 2009
*/
public class JSFLabel extends AbstractJSFBaseComponent {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
HtmlOutputText component = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
component.setId(viewRoot.createUniqueId());
componentId = component.getId();
component.setValue(""+model.getValue());
((UIComponent)gui).getChildren().add(component);
return component;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return false;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
}
}

View file

@ -0,0 +1,157 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf.ui;
import java.io.Serializable;
import java.util.List;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.component.UISelectItems;
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlSelectOneMenu;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascSelectItem;
import net.forwardfire.vasc.core.ui.VascValueModel;
import net.forwardfire.vasc.frontends.web.jsf.JSFVascUIComponent;
/**
*
*
* @author Willem Cazander
* @version 1.0 Mar 28, 2009
*/
public class JSFList extends AbstractJSFBaseComponent {
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
HtmlSelectOneMenu component = (HtmlSelectOneMenu)application.createComponent(HtmlSelectOneMenu.COMPONENT_TYPE);
component.setId(viewRoot.createUniqueId());
componentId = component.getId();
JSFVascUIComponent comp = JSFVascUIComponent.findVascParent((UIComponent)gui);
String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY);
ValueExpression itemsTestVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".editSelectItemModels['jsfListItems_"+componentId+"']}", JSFListModel.class);
JSFListModel t = new JSFListModel(entryField);
itemsTestVE.setValue(FacesContext.getCurrentInstance().getELContext(), t);
component.setConverter(new VascConverter(t));
((UIComponent)gui).getChildren().add(component);
setValueTestModel(component);
return component;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
HtmlSelectOneMenu component = (HtmlSelectOneMenu)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
return component.isDisabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
HtmlSelectOneMenu component = (HtmlSelectOneMenu)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
component.setDisabled(disabled);
}
private void setValueTestModel(HtmlSelectOneMenu component) {
Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
UISelectItems item = (UISelectItems)application.createComponent(UISelectItems.COMPONENT_TYPE);
item.setId(viewRoot.createUniqueId());
JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,null);
String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY);
String id = component.getId();
ValueExpression itemsVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".editSelectItemModels['jsfListItems_"+id+"']}", List.class);
item.setValueExpression("value", itemsVE);
component.getChildren().clear();
component.getChildren().add(item);
}
}
class VascConverter implements Converter,Serializable {
private static final long serialVersionUID = 6198813637409531713L;
private JSFListModel testModel = null;
public VascConverter(JSFListModel testModel) {
this.testModel=testModel;
}
/**
* Convert an ID to an Object
*/
public Object getAsObject(FacesContext context,UIComponent component,String value) throws ConverterException {
if (context == null) { throw new NullPointerException("context may not be null"); }
if (component == null) { throw new NullPointerException("component may not be null"); }
if (value == null) { return null; }
if ((value=value.trim()).length() == 0) { return null; }
for (VascSelectItem v:testModel.getVascItems()) {
if (value.equals(v.getKeyValue())) {
return v.getValue();
}
}
throw new ConverterException("Could not convert value as object: "+value);
}
/**
* Converts an Object to an ID.
*/
public String getAsString(FacesContext context,UIComponent component,Object value) throws ConverterException {
if (context == null) { throw new NullPointerException("context may not be null"); }
if (component == null) { throw new NullPointerException("component may not be null"); }
if (value == null) { return ""; }
for (VascSelectItem v:testModel.getVascItems()) {
if (value.equals(v.getValue())) {
return v.getKeyValue();
}
}
throw new ConverterException("Could not convert value as string: "+value);
}
}

View file

@ -0,0 +1,182 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf.ui;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import javax.faces.model.SelectItem;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascSelectItem;
import net.forwardfire.vasc.core.ui.VascSelectItemModel;
/**
*
*
* @author Willem Cazander
* @version 1.0 Mar 28, 2009
*/
public class JSFListModel implements Serializable,List<SelectItem> {
private static final long serialVersionUID = -5266070864271715383L;
private VascEntryField entryField;
private List<VascSelectItem> items = null;
private List<SelectItem> selectItems = null;
private boolean refresh = true;
public JSFListModel() {
items = new ArrayList<VascSelectItem>(40);
selectItems = new ArrayList<SelectItem>(40);
}
public JSFListModel(VascEntryField entryField) {
this();
this.entryField=entryField;
}
public List<VascSelectItem> getVascItems() {
refresh();
return items;
}
public List<SelectItem> getSelectItems() {
refresh();
return selectItems;
}
public void requestRefresh() {
refresh = true;
}
private void refresh() {
if (refresh==false) {
return;
}
refresh=false;
items.clear();
selectItems.clear();
VascSelectItemModel itemModel = (VascSelectItemModel)entryField.getVascEntryFieldType().getDataObject();
try {
items = itemModel.getVascSelectItems(entryField.getVascEntry());
} catch (VascException e) {
throw new RuntimeException(e);
}
for (VascSelectItem v:items) {
selectItems.add(convert(v));
}
}
private SelectItem convert(VascSelectItem v) {
SelectItem si = new SelectItem();
si.setLabel(v.getLabel());
si.setValue(v.getValue());
si.setDisabled(v.isDisabled());
return si;
}
// === LIST interface
public void add(int arg0, SelectItem arg1) {
getSelectItems().add(arg0,arg1);
}
public boolean add(SelectItem arg0) {
return getSelectItems().add(arg0);
}
public boolean addAll(Collection<? extends SelectItem> arg0) {
return getSelectItems().addAll(arg0);
}
public boolean addAll(int arg0, Collection<? extends SelectItem> arg1) {
return getSelectItems().addAll(arg0,arg1);
}
public void clear() {
getSelectItems().clear();
}
public boolean contains(Object arg0) {
return getSelectItems().contains(arg0);
}
public boolean containsAll(Collection<?> arg0) {
return getSelectItems().containsAll(arg0);
}
public SelectItem get(int index) {
return getSelectItems().get(index);
}
public int indexOf(Object arg0) {
return getSelectItems().indexOf(arg0);
}
public boolean isEmpty() {
return getSelectItems().isEmpty();
}
public Iterator<SelectItem> iterator() {
return getSelectItems().iterator();
}
public int lastIndexOf(Object arg0) {
return getSelectItems().lastIndexOf(arg0);
}
public ListIterator<SelectItem> listIterator() {
return getSelectItems().listIterator();
}
public ListIterator<SelectItem> listIterator(int arg0) {
return getSelectItems().listIterator(arg0);
}
public SelectItem remove(int arg0) {
return getSelectItems().remove(arg0);
}
public boolean remove(Object arg0) {
return getSelectItems().remove(arg0);
}
public boolean removeAll(Collection<?> arg0) {
return getSelectItems().removeAll(arg0);
}
public boolean retainAll(Collection<?> arg0) {
return getSelectItems().retainAll(arg0);
}
public SelectItem set(int arg0, SelectItem arg1) {
return getSelectItems().set(arg0, arg1);
}
public int size() {
return getSelectItems().size();
}
public List<SelectItem> subList(int arg0, int arg1) {
return getSelectItems().subList(arg0, arg1);
}
public Object[] toArray() {
return getSelectItems().toArray();
}
public <T> T[] toArray(T[] a) {
return getSelectItems().toArray(a);
}
}

View file

@ -0,0 +1,117 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf.ui;
import java.io.Serializable;
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlInputText;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascValueModel;
import net.forwardfire.vasc.frontends.web.jsf.JSFVascUIComponent;
/**
*
*
* @author Willem Cazander
* @version 1.0 Mar 25, 2009
*/
public class JSFText extends AbstractJSFBaseComponent {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
HtmlInputText component = (HtmlInputText)application.createComponent(HtmlInputText.COMPONENT_TYPE);
component.setId(viewRoot.createUniqueId());
componentId = component.getId();
component.setConverter(new VascNullConverter());
Integer sizeEdit = entryField.getSizeEdit();
if (sizeEdit!=null) {
component.setSize(sizeEdit);
}
((UIComponent)gui).getChildren().add(component);
return component;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
HtmlInputText component = (HtmlInputText)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
return component.isDisabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
HtmlInputText component = (HtmlInputText)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
component.setDisabled(disabled);
}
}
class VascNullConverter implements Converter,Serializable {
private static final long serialVersionUID = 61988136374095313L;
/**
* Convert an ID to an Object
*/
public Object getAsObject(FacesContext context,UIComponent component,String value) throws ConverterException {
//System.out.println("getAsObject: "+component+" value: "+value);
if (context == null) { throw new NullPointerException("context may not be null"); }
if (component == null) { throw new NullPointerException("component may not be null"); }
if (value == null) { return ""; }
if ((value=value.trim()).length() == 0) { return ""; }
return value;
}
/**
* Converts an Object to an ID.
*/
public String getAsString(FacesContext context,UIComponent component,Object value) throws ConverterException {
//System.out.println("getAsString: "+component+" value: "+value);
if (context == null) { throw new NullPointerException("context may not be null"); }
if (component == null) { throw new NullPointerException("component may not be null"); }
if (value == null) { return ""; }
return ""+value;
}
}

View file

@ -0,0 +1,87 @@
/*
* 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 net.forwardfire.vasc.frontends.web.jsf.ui;
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlInputTextarea;
import javax.faces.context.FacesContext;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.ui.VascValueModel;
import net.forwardfire.vasc.frontends.web.jsf.JSFVascUIComponent;
/**
*
*
* @author Willem Cazander
* @version 1.0 Mar 25, 2009
*/
public class JSFTextArea extends AbstractJSFBaseComponent {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
HtmlInputTextarea component = (HtmlInputTextarea)application.createComponent(HtmlInputTextarea.COMPONENT_TYPE);
component.setId(viewRoot.createUniqueId());
componentId = component.getId();
String cols = entryField.getVascEntryFieldType().getProperty("editor.columns");
if (cols!=null && "".equals(cols)==false) {
component.setCols(new Integer(cols));
}
String rows = entryField.getVascEntryFieldType().getProperty("editor.rows");
if (rows!=null && "".equals(rows)==false) {
component.setRows(new Integer(rows));
}
((UIComponent)gui).getChildren().add(component);
return component;
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
HtmlInputTextarea component = (HtmlInputTextarea)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
return component.isDisabled();
}
/**
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
HtmlInputTextarea component = (HtmlInputTextarea)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
component.setDisabled(disabled);
}
}

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<!-- The New -->
<component>
<description><![CDATA[Renders a templated vasc entry]]></description>
<display-name>Vasc JSF Component</display-name>
<component-type>vasc.jsf.component</component-type>
<component-class>net.forwardfire.vasc.frontends.web.jsf.JSFVascUIComponent</component-class>
<component-extension>
<renderer-type>vasc.jsf.component.renderer</renderer-type>
</component-extension>
</component>
<render-kit>
<renderer>
<component-family>vasc.jsf.component.family</component-family>
<renderer-type>vasc.jsf.component.renderer</renderer-type>
<renderer-class>net.forwardfire.vasc.frontends.web.jsf.JSFVascUIComponentRenderer</renderer-class>
</renderer>
</render-kit>
<application>
<locale-config/>
<view-handler>net.forwardfire.vasc.frontends.web.jsf.VascViewHandler</view-handler>
</application>
<factory/>
<lifecycle/>
</faces-config>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://vasc.idcanet.com/vasc.tld</namespace>
<tag>
<tag-name>vascEntry</tag-name>
<component>
<component-type>vasc.jsf.component</component-type>
<renderer-type>vasc.jsf.component.renderer</renderer-type>
</component>
</tag>
</facelet-taglib>

View file

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8" ?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<description>Vasc JSF 2.1 library</description>
<display-name>Vasc</display-name>
<tlib-version>2.1</tlib-version>
<short-name>vasc</short-name>
<uri>http://vasc.idcanet.com/vasc.tld</uri>
<!-- DROPED JSP Support until <deferred-value> is fixed for jbossas6
<tag>
<description>Renders the vasc entry JSF Frontend Renderer</description>
<name>vascEntry</name>
<tag-class>net.forwardfire.vasc.frontends.web.jsf.JSFVascUIComponentTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>id</name>
<required>false</required>
</attribute>
<attribute>
<name>rendered</name>
<required>false</required>
<deferred-value>
<type>boolean</type>
</deferred-value>
</attribute>
<attribute>
<name>binding</name>
<required>false</required>
<deferred-value>
<type>javax.faces.component.UIComponent</type>
</deferred-value>
</attribute>
<attribute>
<name>vascController</name>
<required>true</required>
<deferred-value>
<type>net.forwardfire.vasc.core.VascController</type>
</deferred-value>
</attribute>
<attribute>
<name>entryName</name>
<required>false</required>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>vascFrontendData</name>
<required>true</required>
<deferred-value>
<type>net.forwardfire.vasc.core.VascFrontendData</type>
</deferred-value>
</attribute>
<attribute>
<name>entrySupportVar</name>
<required>true</required>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>tableRecordVar</name>
<required>true</required>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>injectEditFieldsId</name>
<required>true</required>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>injectTableOptionsId</name>
<required>true</required>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>injectTableColumnsId</name>
<required>true</required>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>disableLinkColumns</name>
<required>false</required>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
</tag>
-->
</taglib>