/* * 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; 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.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.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) { try { table.setTableData(table.getVascDataSource().executeQuery(table.getQuery())); } catch (Exception e) { e.printStackTrace(); } 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"); //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); // Set the content and label providers tableViewer.setContentProvider(new ListConverterContentProvider()); tableViewer.setLabelProvider(new DefaultLabelProvider(table)); //tv.setSorter(new PlayerViewerSorter()); tableViewer.setInput(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); } //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