diff --git a/src/com/idcanet/vasc/annotations/VascDefaultValue.java b/src/com/idcanet/vasc/annotations/VascDefaultValue.java index 4947135..ab49bea 100644 --- a/src/com/idcanet/vasc/annotations/VascDefaultValue.java +++ b/src/com/idcanet/vasc/annotations/VascDefaultValue.java @@ -45,5 +45,7 @@ public @interface VascDefaultValue { /** * The defaultValue of the method */ - Class defaultValue(); + Class defaultValueClass() default Object.class; + + String defaultValue() default "null"; } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/VascDataSource.java b/src/com/idcanet/vasc/core/VascDataSource.java index 148369d..a6e3080 100644 --- a/src/com/idcanet/vasc/core/VascDataSource.java +++ b/src/com/idcanet/vasc/core/VascDataSource.java @@ -42,4 +42,7 @@ public interface VascDataSource { public void persist(Object object) throws Exception; + public Object merge(Object object) throws Exception; + + public void delete(Object object) throws Exception; } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/VascViewRenderer.java b/src/com/idcanet/vasc/core/VascViewRenderer.java index 879be6a..71092f4 100644 --- a/src/com/idcanet/vasc/core/VascViewRenderer.java +++ b/src/com/idcanet/vasc/core/VascViewRenderer.java @@ -36,4 +36,5 @@ public interface VascViewRenderer { public void renderView(VascTable table); + public void renderEdit(VascTable table,Object rowBean); } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/actions/AbstractVascAction.java b/src/com/idcanet/vasc/core/actions/AbstractVascAction.java new file mode 100644 index 0000000..f3cda51 --- /dev/null +++ b/src/com/idcanet/vasc/core/actions/AbstractVascAction.java @@ -0,0 +1,68 @@ + +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.core.actions; + + +/** + * + * @author Willem Cazander + * @version 1.0 Mar 30, 2007 + */ +abstract public class AbstractVascAction implements VascAction { + + private String name = null; + private String toolTip = null; + + /** + * @return the name + */ + public String getName() { + return name; + } + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + /** + * @return the toolTip + */ + public String getToolTip() { + return toolTip; + } + /** + * @param toolTip the toolTip to set + */ + public void setToolTip(String toolTip) { + this.toolTip = toolTip; + } + + + +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/actions/VascAction.java b/src/com/idcanet/vasc/core/actions/VascAction.java index d8fab98..dc3ba7a 100644 --- a/src/com/idcanet/vasc/core/actions/VascAction.java +++ b/src/com/idcanet/vasc/core/actions/VascAction.java @@ -36,7 +36,9 @@ import com.idcanet.vasc.core.VascTable; public interface VascAction { public String getName(); + public void setName(String name); public String getToolTip(); + public void setToolTip(String toolTip); - public Object createActionObject(VascTable table); + //public Object createActionObject(VascTable table); } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/column/VascAnnotationTableColumn.java b/src/com/idcanet/vasc/core/column/VascAnnotationTableColumn.java new file mode 100644 index 0000000..0d778f6 --- /dev/null +++ b/src/com/idcanet/vasc/core/column/VascAnnotationTableColumn.java @@ -0,0 +1,60 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.core.column; + + +/** + * + * @author Willem Cazander + * @version 1.0 Apr 11, 2007 + */ +public class VascAnnotationTableColumn extends VascTableColumn { + + private String beanProperty = null; + + public VascAnnotationTableColumn() { + + } + public VascAnnotationTableColumn(String beanProperty) { + setBeanProperty(beanProperty); + } + + + /** + * @return the beanProperty + */ + public String getBeanProperty() { + return beanProperty; + } + + /** + * @param beanProperty the beanProperty to set + */ + public void setBeanProperty(String beanProperty) { + this.beanProperty = beanProperty; + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/actions/AddRowAction.java b/src/com/idcanet/vasc/impl/actions/AddRowAction.java new file mode 100644 index 0000000..b8638f1 --- /dev/null +++ b/src/com/idcanet/vasc/impl/actions/AddRowAction.java @@ -0,0 +1,48 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.impl.actions; + +import com.idcanet.vasc.core.VascTable; +import com.idcanet.vasc.core.actions.AbstractVascAction; +import com.idcanet.vasc.core.actions.RowVascAction; + +/** + * + * @author Willem Cazander + * @version 1.0 Mar 30, 2007 + */ +public class AddRowAction extends AbstractVascAction implements RowVascAction { + + public AddRowAction() { + setName("generic.crud.add"); + setToolTip("generic.toolTip"); + } + + public void doRowAction(VascTable table,Object rowObject) { + table.getVascViewRenderer().renderEdit(table,rowObject); + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/actions/DeleteRowAction.java b/src/com/idcanet/vasc/impl/actions/DeleteRowAction.java new file mode 100644 index 0000000..7bd6c23 --- /dev/null +++ b/src/com/idcanet/vasc/impl/actions/DeleteRowAction.java @@ -0,0 +1,52 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.impl.actions; + +import com.idcanet.vasc.core.VascTable; +import com.idcanet.vasc.core.actions.AbstractVascAction; +import com.idcanet.vasc.core.actions.RowVascAction; + +/** + * + * @author Willem Cazander + * @version 1.0 Mar 30, 2007 + */ +public class DeleteRowAction extends AbstractVascAction implements RowVascAction { + + public DeleteRowAction() { + setName("generic.crud.delete"); + setToolTip("generic.toolTip"); + } + + public void doRowAction(VascTable table,Object rowObject) { + try { + table.getVascDataSource().delete(rowObject); + } catch (Exception e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/actions/EditRowAction.java b/src/com/idcanet/vasc/impl/actions/EditRowAction.java new file mode 100644 index 0000000..a69cb98 --- /dev/null +++ b/src/com/idcanet/vasc/impl/actions/EditRowAction.java @@ -0,0 +1,49 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.impl.actions; + +import com.idcanet.vasc.core.VascTable; +import com.idcanet.vasc.core.actions.AbstractVascAction; +import com.idcanet.vasc.core.actions.RowVascAction; + +/** + * + * @author Willem Cazander + * @version 1.0 Mar 30, 2007 + */ +public class EditRowAction extends AbstractVascAction implements RowVascAction { + + public EditRowAction() { + setName("generic.crud.edit"); + setToolTip("generic.toolTip"); + } + + + public void doRowAction(VascTable table,Object rowObject) { + table.getVascViewRenderer().renderEdit(table,rowObject); + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/actions/XMLExportGlobalAction.java b/src/com/idcanet/vasc/impl/actions/XMLExportGlobalAction.java new file mode 100644 index 0000000..44de566 --- /dev/null +++ b/src/com/idcanet/vasc/impl/actions/XMLExportGlobalAction.java @@ -0,0 +1,49 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.impl.actions; + +import com.idcanet.vasc.core.VascTable; +import com.idcanet.vasc.core.actions.AbstractVascAction; +import com.idcanet.vasc.core.actions.GlobalVascAction; + +/** + * + * @author Willem Cazander + * @version 1.0 Mar 30, 2007 + */ +public class XMLExportGlobalAction extends AbstractVascAction implements GlobalVascAction { + + public XMLExportGlobalAction() { + setName("generic.crud.export.xml.name"); + setToolTip("generic.crud.export.xml.tooltip"); + } + + + public void doGlobalAction(VascTable table) { + //table.getVascViewRenderer().render + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/serv5/Serv5HibernateVascDataSource.java b/src/com/idcanet/vasc/impl/serv5/Serv5HibernateVascDataSource.java index 1bb16e8..dd38714 100644 --- a/src/com/idcanet/vasc/impl/serv5/Serv5HibernateVascDataSource.java +++ b/src/com/idcanet/vasc/impl/serv5/Serv5HibernateVascDataSource.java @@ -77,6 +77,24 @@ public class Serv5HibernateVascDataSource implements VascDataSource { Hibernate3Factory.getSession(getSession()).close(); } } + + public Object merge(Object object) throws Exception { + try { + return Hibernate3Factory.getSession(getSession()).merge(object); + } finally { + Hibernate3Factory.getSession(getSession()).close(); + } + } + + public void delete(Object object) throws Exception { + try { + Object newObject = Hibernate3Factory.getSession(getSession()).merge(object); + Hibernate3Factory.getSession(getSession()).delete(newObject); + } finally { + Hibernate3Factory.getSession(getSession()).close(); + } + } + /** * @return the session */ diff --git a/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java b/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java index fa0cd4a..da9d102 100644 --- a/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java +++ b/src/com/idcanet/vasc/impl/swt/SwtVascViewRenderer.java @@ -27,32 +27,45 @@ package com.idcanet.vasc.impl.swt; import java.util.ArrayList; -import java.util.Collections; import java.util.List; +import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.text.TabExpander; + +import org.eclipse.jface.action.IToolBarManager; 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.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.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.Dialog; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; import com.idcanet.vasc.core.VascTable; import com.idcanet.vasc.core.VascUserOption; import com.idcanet.vasc.core.VascViewRenderer; +import com.idcanet.vasc.core.actions.GlobalVascAction; import com.idcanet.vasc.core.actions.RowVascAction; import com.idcanet.vasc.core.column.VascTableColumn; @@ -72,6 +85,177 @@ public class SwtVascViewRenderer implements VascViewRenderer { this.parent=parent; } + public void renderEdit(VascTable table,Object object) { + + logger.info("Rending Edit View"); + + if (object==null) { + try { + object = table.getVascRecordCreator().newRecord(table); + logger.finest("created: "+object); + } catch (Exception e) { + e.printStackTrace(); + //logger.log(Level.WARNING,"Error while creating new: "+crudTable.getRecordClass()); + return; + } + } + + //CrudEditDialog editDialog = new CrudEditDialog(event.display.getActiveShell(),crudTable,element,crudTable.i18n("crud.event.add.title"),crudTable.i18n("crud.event.add.title")); + + SwtVascEditDialog dialog = new SwtVascEditDialog(Display.getCurrent().getActiveShell(),table,object,"Edit","TOITO"); + Object result = dialog.open(); + if(result==null) { + return; + } + try { + result = table.getVascDataSource().merge(object); + //FlowstatsPlugin.getDefault().fireModelUpdateListeners(result); + + } catch (Exception e) { + logger.log(Level.WARNING,"EJB Error: "+e.getMessage(),e); + } finally { + //crudTable.getCrudTableDataSource().fillCrudDataList(crudTable); + } + } + + public class SwtVascEditDialog extends Dialog { + + private Shell shell = null; + private String headerText = null; + private String title = null; + private Object result = null; + private Object bean = null; + + public SwtVascEditDialog (Shell parent,VascTable table,Object bean,String title,String headerText) { + super (parent, 0); + this.headerText = headerText; + this.title = title; + this.bean = bean; + } + public Object open() { + shell = new Shell(getParent(), SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL); + shell.setText(title); + + 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); + + // should be last + partCreated(); + + shell.pack(); + shell.open(); + + Display display = shell.getDisplay(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + //image.dispose(); + //closeDialog(); + return result; + } + + public void createBody(Composite body) { + body.setLayout(new GridLayout(2, true)); + body.setLayoutData(new GridData(GridData.FILL_BOTH)); + + for(VascTableColumn c:table.getTableColumns()) { + Label l = new Label(body, SWT.WRAP); + l.setText(c.getName()); + + if(c.getToolTip()!=null) { + l.setToolTipText(c.getToolTip()); + } + + if(c.getVascColumnEditor()==null) { + Label valueLabel = new Label(body, SWT.WRAP); + valueLabel.setText(""+c.getVascColumnValue().getValue(c, bean)); + } else { + c.getVascColumnEditor().createColumnEditor(c); + } + // SWTComponentFactory.createLabel(body,ba.getValueModel(c.getObjectProperty()),SWT.WRAP); + // continue; + //} + //ValueModel vm = ba.getValueModel(c.getObjectProperty()); + + //c.getVascColumnEditor().createColumnEditor(c); + + + // set the default value before creating property + /* + if(vm.getValue()==null & c.getDefaultValue()!=null) { + try { + logger.finer("Setting default value for: "+c.getName()+" def: "+c.getDefaultValue()); + vm.setValue(c.getDefaultValue()); + } catch (Exception e) { + logger.log(Level.WARNING,"Error in setting default value: '"+c.getDefaultValue()+"' error: "+e.getMessage(),e); + } + } + */ + //Control editor = c.getPropertyEditor().createPropertyEditor(body,vm); + GridData gridData = new GridData(); + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + //editor.setLayoutData(gridData); + //c.setTempObjectPropertyControl(editor); + } + + // create some spaceing , should replace by seperator + new Label(body, SWT.WRAP); + new Label(body, SWT.WRAP); + + Button saveButton = new Button(body, SWT.NONE); + //saveButton.setImage(crudTable.getImageDescriptor("icons/fam/tick.png").createImage()); + saveButton.setText("generic.save"); + saveButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + //if(hasRecordError()) { + // return; + //} + //result = bean; + shell.dispose(); + } + }); + Button cancelButton = new Button(body, SWT.NONE); + //cancelButton.setImage(crudTable.getImageDescriptor("icons/fam/cancel.png").createImage()); + cancelButton.setText("generic.cancel"); + cancelButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + result = null; + shell.dispose(); + } + }); + } + } + + public void renderView(VascTable table) { try { @@ -113,18 +297,50 @@ public class SwtVascViewRenderer implements VascViewRenderer { partCreated(); } - public void createHeader(Composite header) { logger.finest("Creating header"); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + header.setLayout(layout); header.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - Color c = new Color(header.getDisplay(),255,255,255); - header.setBackground(c); + + 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)); + + Composite headerName = new Composite(header, SWT.NONE); + GridLayout bodyLayout = new GridLayout(); + bodyLayout.numColumns = 1; + headerName.setLayout(bodyLayout); + headerName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + //headerName.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Composite headerOptions = new Composite(header, SWT.NONE); + GridLayout footerLayout = new GridLayout(); + footerLayout.numColumns = 1; + headerOptions.setLayout(footerLayout); + //headerOptions.setLayoutData(new GridData(SWT.NONE)); + headerOptions.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + ToolBar toolBar = new ToolBar(headerBar, SWT.NONE); + for (GlobalVascAction action:table.getGlobalActions()) { + ToolItem item = new ToolItem(toolBar, SWT.PUSH); + item.setText(action.getName()); + item.setToolTipText(action.getToolTip()); + item.addSelectionListener(new GlobalActionListener(action)); + } + + + Color c = new Color(header.getDisplay(),255,255,255); + headerName.setBackground(c); if(table.getHeaderName()!=null) { Font headerFont = new Font(header.getDisplay(), "verdana", 16, SWT.BOLD); - Label l = new Label(header, SWT.CENTER); + Label l = new Label(headerName, SWT.CENTER); l.setFont(headerFont); l.setText(table.getVascTextValue().getTextValue(table.getHeaderName())); l.setBackground(c); @@ -149,16 +365,58 @@ public class SwtVascViewRenderer implements VascViewRenderer { */ } } + 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.info("Global Action"); + action.doGlobalAction(table); + } + } + + + + + + + + public void createBody(Composite body) { logger.finer("Creating body"); - //final TableViewer tableViewer = JFaceComponentFactory.createTableViewer(body,table.getSelectionInList(),getTableColumns(crudTable),false); // Create the table viewer to display the players final TableViewer tableViewer = new TableViewer(body); final Table table2 = tableViewer.getTable(); table2.setLayoutData(new GridData(GridData.FILL_BOTH)); table2.setHeaderVisible(true); table2.setLinesVisible(true); + + 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.info("Slecting data: "+data); + table.setSelectedObject(data); + } + + }); // Set the content and label providers tableViewer.setContentProvider(new ListConverterContentProvider()); @@ -187,9 +445,9 @@ public class SwtVascViewRenderer implements VascViewRenderer { dir = SWT.UP; } // sort the data based on column and direction - String prop = (String)currentColumn.getData("PROP"); + //String prop = (String)currentColumn.getData("PROP"); - List l = new ArrayList(10); + //List l = new ArrayList(10); /* for(int i=0;i