2
Fork 0

[svn r249] fixed annotation support , added talbecontroller

This commit is contained in:
willemc 2007-04-28 17:59:11 +02:00
parent a4d1ff1c57
commit d88cb26330
20 changed files with 403 additions and 58 deletions

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 com.idcanet.vasc.impl;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.idcanet.vasc.annotations.VascAnnotationParser;
import com.idcanet.vasc.core.VascTable;
import com.idcanet.vasc.core.VascTableController;
import com.idcanet.vasc.core.column.VascAnnotationTableColumn;
import com.idcanet.vasc.core.column.VascTableColumn;
import com.idcanet.vasc.impl.column.BeanPropertyVascColumnValue;
/**
*
* @author Willem Cazander
* @version 1.0 Apr 28, 2007
*/
public class DefaultVascTableController implements VascTableController {
/**
* @see com.idcanet.vasc.core.VascTableController#finalizeVascColumns(com.idcanet.vasc.core.VascTable)
*/
public void finalizeVascColumns(VascTable table) throws Exception {
VascAnnotationParser vap = new VascAnnotationParser();
for(VascTableColumn c:table.getTableColumns()) {
if (c instanceof VascAnnotationTableColumn) {
VascAnnotationTableColumn column = (VascAnnotationTableColumn)c;
if (c.getName()==null) {
c.setName(vap.getVascNameKey(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty()));
}
if (c.getToolTip()==null) {
c.setToolTip(vap.getVascToolTipKey(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty()));
}
if (c.getDefaultValue()==null) {
c.setDefaultValue(vap.getVascDefaultValue(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty()));
}
if (c.getWidth()==null) {
Object obj = vap.getVascColumnWidth(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty());
if (obj instanceof Integer) {
c.setWidth((Integer)obj);
}
// get KEY
}
if (c.getHelpId()==null) {
c.setHelpId(vap.getVascHelpId(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty()));
}
if (c.getVascColumnValue()==null) {
c.setVascColumnValue(new BeanPropertyVascColumnValue(column.getBeanProperty()));
}
}
}
}
/**
* @see com.idcanet.vasc.core.VascTableController#finalizeVascTable(com.idcanet.vasc.core.VascTable)
*/
public void finalizeVascTable(VascTable table) throws Exception {
}
/**
* @see com.idcanet.vasc.core.VascTableController#getTotalColumnsWidth(com.idcanet.vasc.core.VascTable)
*/
public Integer getTotalColumnsWidth(VascTable table) {
int result = 0;
for(VascTableColumn c:table.getTableColumns()) {
if(c.getWidth()==null) {
Logger.getLogger(VascTable.class.getName()).finer("Column no size: "+c.getName());
return null;
}
result=+c.getWidth();
}
return result;
}
/**
* @see com.idcanet.vasc.core.VascTableController#refreshData()
*/
public void refreshData(VascTable table) throws Exception {
table.setTableData(table.getVascDataSource().executeQuery(table.getQuery()));
}
public void handleException(Exception e,VascTable table) {
Logger.getLogger(DefaultVascTableController.class.getName()).log(Level.WARNING,e.getMessage(),e);
}
}

View file

@ -42,7 +42,7 @@ public class AddRowAction extends AbstractVascAction implements RowVascAction {
setToolTip("generic.toolTip");
}
public void doRowAction(VascTable table,Object rowObject) {
public void doRowAction(VascTable table,Object rowObject) throws Exception {
table.getVascViewRenderer().renderEdit(table,rowObject);
}
}

View file

@ -42,11 +42,7 @@ public class DeleteRowAction extends AbstractVascAction implements RowVascAction
setToolTip("generic.toolTip");
}
public void doRowAction(VascTable table,Object rowObject) {
try {
table.getVascDataSource().delete(rowObject);
} catch (Exception e) {
e.printStackTrace();
}
public void doRowAction(VascTable table,Object rowObject) throws Exception {
table.getVascDataSource().delete(rowObject);
}
}

View file

@ -43,7 +43,7 @@ public class EditRowAction extends AbstractVascAction implements RowVascAction {
}
public void doRowAction(VascTable table,Object rowObject) {
public void doRowAction(VascTable table,Object rowObject) throws Exception {
table.getVascViewRenderer().renderEdit(table,rowObject);
}
}

View file

@ -0,0 +1,50 @@
/*
* 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 Apr 28, 2007
*/
public class RefreshDataGlobalAction extends AbstractVascAction implements GlobalVascAction {
public RefreshDataGlobalAction() {
setName("generic.refresh");
setToolTip("generic.crud.refresh.tooltip");
setImage("icons/fam/table_refresh.png");
}
public void doGlobalAction(VascTable table) {
//table.getVascViewRenderer().render
}
}

View file

@ -40,6 +40,7 @@ public class XMLExportGlobalAction extends AbstractVascAction implements GlobalV
public XMLExportGlobalAction() {
setName("generic.crud.export.xml.name");
setToolTip("generic.crud.export.xml.tooltip");
setImage("icons/fam/page_white_excel.png");
}

View file

@ -26,14 +26,10 @@
package com.idcanet.vasc.impl.swt;
import java.util.ArrayList;
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.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
@ -85,7 +81,7 @@ public class SwtVascViewRenderer implements VascViewRenderer {
this.parent=parent;
}
public void renderEdit(VascTable table,Object object) {
public void renderEdit(VascTable table,Object object) throws Exception {
logger.info("Rending Edit View");
@ -111,13 +107,41 @@ public class SwtVascViewRenderer implements VascViewRenderer {
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 ImageDescriptor getImageDescriptor(String path) {
try {
logger.info("Loading image: "+path);
//System.out.println("==== 1");
ImageDescriptor result = ImageDescriptor.createFromFile(path.getClass(), path);
if(result==null) {
// try load fff
//.out.println("==== 2");
//result = ImageDescriptor.createFromURL(SwingImageHelper.class.getClass().getResource(path));
}
//System.out.println("==== 3");
if(result==null) {
throw new NullPointerException("Can't load resource: "+path);
}
//System.out.println("==== 4 "+result.getImageData().height+" w:"+result.getImageData().width);
return result;
} catch (Exception e) {
logger.warning("Could not load image from path: '"+path+"'");
try {
ImageDescriptor result = null; //ImageDescriptor.createFromURL(SwingImageHelper.class.getClass().getResource("/META-INF/images/silk/png/bomb.png"));
if(result==null) {
throw new NullPointerException("Can't load resource: "+path);
}
return result;
} catch (Exception e2) {
return ImageDescriptor.getMissingImageDescriptor(); // default swt missing image fall back
}
}
}
public class SwtVascEditDialog extends Dialog {
private Shell shell = null;
@ -232,7 +256,7 @@ public class SwtVascViewRenderer implements VascViewRenderer {
new Label(body, SWT.WRAP);
Button saveButton = new Button(body, SWT.NONE);
//saveButton.setImage(crudTable.getImageDescriptor("icons/fam/tick.png").createImage());
saveButton.setImage(getImageDescriptor("icons/fam/tick.png").createImage());
saveButton.setText("generic.save");
saveButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
@ -244,7 +268,7 @@ public class SwtVascViewRenderer implements VascViewRenderer {
}
});
Button cancelButton = new Button(body, SWT.NONE);
//cancelButton.setImage(crudTable.getImageDescriptor("icons/fam/cancel.png").createImage());
cancelButton.setImage(getImageDescriptor("icons/fam/cancel.png").createImage());
cancelButton.setText("generic.cancel");
cancelButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
@ -256,14 +280,11 @@ public class SwtVascViewRenderer implements VascViewRenderer {
}
public void renderView(VascTable table) {
try {
table.setTableData(table.getVascDataSource().executeQuery(table.getQuery()));
} catch (Exception e) {
e.printStackTrace();
}
public void renderView(VascTable table) throws Exception {
table.getVascTableController().finalizeVascColumns(table);
table.getVascTableController().finalizeVascTable(table);
table.getVascTableController().refreshData(table);
this.table=table;
GridLayout layout = new GridLayout();
@ -378,7 +399,11 @@ public class SwtVascViewRenderer implements VascViewRenderer {
@Override
public void widgetSelected(SelectionEvent event) {
logger.info("Global Action");
action.doGlobalAction(table);
try {
action.doGlobalAction(table);
} catch (Exception e) {
table.getVascTableController().handleException(e, table);
}
}
}
@ -461,7 +486,7 @@ public class SwtVascViewRenderer implements VascViewRenderer {
}
};
Integer totalSize = VascTable.getTotalColumnSize(table);
Integer totalSize = table.getVascTableController().getTotalColumnsWidth(table);
logger.finer("Total size: "+totalSize);
TableColumn[] columns = table2.getColumns();
for (int i = 0; i < columns.length; i++) {
@ -494,7 +519,7 @@ public class SwtVascViewRenderer implements VascViewRenderer {
Button actionButton = new Button(footer, SWT.NONE);
actionButton.setText(action.getName());
actionButton.setToolTipText(action.getToolTip());
//actionButton.setImage(crudTable.getImageDescriptor("icons/fam/table_add.png").createImage());
actionButton.setImage(getImageDescriptor(action.getImage()).createImage());
actionButton.addSelectionListener(new ActionListener(action));
}
@ -512,7 +537,11 @@ public class SwtVascViewRenderer implements VascViewRenderer {
@Override
public void widgetSelected(SelectionEvent event) {
logger.info("Row Action");
action.doRowAction(table, table.getSelectedObject());
try {
action.doRowAction(table, table.getSelectedObject());
} catch (Exception e) {
table.getVascTableController().handleException(e, table);
}
}
}