2007-03-22 00:01:07 +00:00
|
|
|
/*
|
|
|
|
* 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.swt;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2007-03-25 23:20:47 +00:00
|
|
|
import org.eclipse.jface.viewers.ILabelProviderListener;
|
|
|
|
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
|
|
|
import org.eclipse.jface.viewers.ITableLabelProvider;
|
2007-03-22 00:01:07 +00:00
|
|
|
import org.eclipse.jface.viewers.TableViewer;
|
2007-03-25 23:20:47 +00:00
|
|
|
import org.eclipse.jface.viewers.Viewer;
|
2007-03-22 00:01:07 +00:00
|
|
|
import org.eclipse.swt.SWT;
|
|
|
|
import org.eclipse.swt.graphics.Color;
|
|
|
|
import org.eclipse.swt.graphics.Font;
|
2007-03-25 23:20:47 +00:00
|
|
|
import org.eclipse.swt.graphics.Image;
|
2007-03-22 00:01:07 +00:00
|
|
|
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.Event;
|
|
|
|
import org.eclipse.swt.widgets.Label;
|
|
|
|
import org.eclipse.swt.widgets.Listener;
|
|
|
|
import org.eclipse.swt.widgets.Table;
|
|
|
|
import org.eclipse.swt.widgets.TableColumn;
|
|
|
|
|
|
|
|
import com.idcanet.vasc.core.VascTable;
|
|
|
|
import com.idcanet.vasc.core.VascUserOption;
|
|
|
|
import com.idcanet.vasc.core.VascViewRenderer;
|
|
|
|
import com.idcanet.vasc.core.actions.RowVascAction;
|
|
|
|
import com.idcanet.vasc.core.column.VascTableColumn;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Willem Cazander
|
|
|
|
* @version 1.0 Mar 21, 2007
|
|
|
|
*/
|
|
|
|
public class SwtVascViewRenderer implements VascViewRenderer {
|
|
|
|
|
|
|
|
private Logger logger = null;
|
|
|
|
private Composite parent = null;
|
|
|
|
private VascTable table = null;
|
|
|
|
|
|
|
|
public SwtVascViewRenderer(Composite parent) {
|
|
|
|
logger = Logger.getLogger(SwtVascViewRenderer.class.getName());
|
|
|
|
this.parent=parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void renderView(VascTable table) {
|
2007-03-25 23:20:47 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
table.setTableData(table.getVascDataSource().executeQuery(table.getQuery()));
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 00:01:07 +00:00
|
|
|
this.table=table;
|
|
|
|
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);
|
|
|
|
|
|
|
|
// should be last
|
|
|
|
partCreated();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void createHeader(Composite header) {
|
|
|
|
logger.finest("Creating header");
|
|
|
|
|
|
|
|
header.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
|
|
|
Color c = new Color(header.getDisplay(),255,255,255);
|
|
|
|
header.setBackground(c);
|
|
|
|
|
|
|
|
if(table.getHeaderName()!=null) {
|
|
|
|
Font headerFont = new Font(header.getDisplay(), "verdana", 16, SWT.BOLD);
|
|
|
|
Label l = new Label(header, SWT.CENTER);
|
|
|
|
l.setFont(headerFont);
|
|
|
|
l.setText(table.getVascTextValue().getTextValue(table.getHeaderName()));
|
|
|
|
l.setBackground(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
// create options
|
|
|
|
for(VascUserOption option:table.getUserOptions()) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
if(option.getLabelText()!=null) {
|
|
|
|
Label l = new Label(header,SWT.WRAP);
|
|
|
|
l.setText(crudTable.i18n(cpo.getLabelText()));
|
|
|
|
l.setBackground(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
// create ValueHolder
|
|
|
|
cpo.setValueHolder(new ValueHolder(null));
|
|
|
|
// create control
|
|
|
|
cpo.setTempObjectPropertyControl(cpo.getPropertyEditor().createPropertyEditor(header,cpo.getValueHolder()));
|
|
|
|
|
|
|
|
cpo.getValueHolder().addPropertyChangeListener(this);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void createBody(Composite body) {
|
|
|
|
logger.finer("Creating body");
|
|
|
|
|
2007-03-25 23:20:47 +00:00
|
|
|
//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);
|
2007-03-22 00:01:07 +00:00
|
|
|
final Table table2 = tableViewer.getTable();
|
|
|
|
table2.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
|
|
table2.setHeaderVisible(true);
|
|
|
|
table2.setLinesVisible(true);
|
|
|
|
|
2007-03-25 23:20:47 +00:00
|
|
|
// Set the content and label providers
|
|
|
|
tableViewer.setContentProvider(new ListConverterContentProvider());
|
|
|
|
tableViewer.setLabelProvider(new DefaultLabelProvider(table));
|
|
|
|
|
|
|
|
for(VascTableColumn c:table.getTableColumns()) {
|
|
|
|
TableColumn tc = new TableColumn(table2, SWT.LEFT);
|
|
|
|
tc.setText(c.getName());
|
|
|
|
tc.setToolTipText(c.getToolTip());
|
|
|
|
tc.setMoveable(false);
|
|
|
|
tc.setResizable(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 00:01:07 +00:00
|
|
|
//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;
|
|
|
|
}
|
|
|
|
// sort the data based on column and direction
|
|
|
|
String prop = (String)currentColumn.getData("PROP");
|
|
|
|
|
|
|
|
List l = new ArrayList(10);
|
|
|
|
/*
|
|
|
|
for(int i=0;i<crudTable.getSelectionInList().getSize();i++) {
|
|
|
|
l.add(crudTable.getSelectionInList().getElementAt(i));
|
|
|
|
}
|
|
|
|
BeanPropertyComparator c = new BeanPropertyComparator();
|
|
|
|
c.setAscending(dir!=SWT.DOWN);
|
|
|
|
c.setProperty(prop);
|
|
|
|
Collections.sort(l,c);
|
|
|
|
crudTable.getSelectionInList().setList(l);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Integer totalSize = VascTable.getTotalColumnSize(table);
|
|
|
|
logger.finer("Total size: "+totalSize);
|
|
|
|
TableColumn[] columns = table2.getColumns();
|
|
|
|
for (int i = 0; i < columns.length; i++) {
|
|
|
|
columns[i].pack();
|
|
|
|
columns[i].setMoveable(true);
|
|
|
|
columns[i].setResizable(true);
|
|
|
|
columns[i].addListener(SWT.Selection, sortListener);
|
|
|
|
//columns[i].setData("PROP",table.getTableColumns().get(i)....);
|
|
|
|
if(totalSize!=null) {
|
|
|
|
Integer cWidth = table.getTableColumns().get(i).getWidth();
|
|
|
|
columns[i].setWidth(cWidth);
|
|
|
|
/*
|
|
|
|
columns[i].setWidth((int)((double)tableWidth/(double)totalSize)*cWidth);
|
|
|
|
logger.finest("Setting column width: "+(int)((double)tableWidth/(double)totalSize)*cWidth+" total: "+totalSize+" c: "+cWidth+" of column: "+i);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.fine("Table with columns created: "+table2.getColumnCount());
|
2007-03-28 17:16:40 +00:00
|
|
|
|
|
|
|
tableViewer.setInput(table);
|
2007-03-22 00:01:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void createFooter(Composite footer) {
|
|
|
|
logger.finest("Creating footer");
|
|
|
|
for(RowVascAction action:table.getRowActions()) {
|
|
|
|
|
|
|
|
//action.createActionObject(table);
|
|
|
|
|
|
|
|
//Button ton = new Button(footer, SWT.NONE);
|
|
|
|
//addButton.setText(crudTable.i18n("generic.add"));
|
|
|
|
//addButton.setImage(crudTable.getImageDescriptor("icons/fam/table_add.png").createImage());
|
|
|
|
//addButton.addSelectionListener(new AddEvent(crudTable));
|
|
|
|
//action.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is called when all createPartControl is done with creating Parts
|
|
|
|
*/
|
|
|
|
public void partCreated() {
|
2007-03-25 23:20:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class DefaultLabelProvider implements ITableLabelProvider {
|
|
|
|
|
|
|
|
private VascTable table = null;
|
|
|
|
|
|
|
|
public DefaultLabelProvider(VascTable table) {
|
|
|
|
this.table=table;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
|
|
|
|
*/
|
|
|
|
public Image getColumnImage(Object arg0, int arg1) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
|
|
|
|
*/
|
|
|
|
public String getColumnText(Object bean, int columnNumber) {
|
|
|
|
System.out.println("Rending column; "+columnNumber+" bean: "+bean);
|
|
|
|
VascTableColumn vtc = table.getTableColumns().get(columnNumber);
|
|
|
|
if (vtc.getColumnRenderer()!=null) {
|
|
|
|
//do iets
|
|
|
|
return "RENDER";
|
|
|
|
} else {
|
|
|
|
return ""+vtc.getVascColumnValue().getValue(vtc,bean);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
|
|
|
|
*/
|
|
|
|
public void addListener(ILabelProviderListener arg0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
|
|
|
|
*/
|
|
|
|
public void dispose() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
|
|
|
|
*/
|
|
|
|
public boolean isLabelProperty(Object arg0, String arg1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
|
|
|
|
*/
|
|
|
|
public void removeListener(ILabelProviderListener arg0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ListConverterContentProvider implements IStructuredContentProvider {
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
|
|
|
|
*/
|
|
|
|
public Object[] getElements(Object obj) {
|
|
|
|
return ((VascTable)obj).getTableData().toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
|
|
|
|
*/
|
|
|
|
public void dispose() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @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) {
|
|
|
|
}
|
|
|
|
|
2007-03-22 00:01:07 +00:00
|
|
|
}
|
|
|
|
}
|