[svn r246] added annotatioins and made some actions
This commit is contained in:
parent
54ca574e58
commit
a4d1ff1c57
15 changed files with 679 additions and 25 deletions
|
|
@ -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<crudTable.getSelectionInList().getSize();i++) {
|
||||
l.add(crudTable.getSelectionInList().getElementAt(i));
|
||||
|
|
@ -233,13 +491,30 @@ public class SwtVascViewRenderer implements VascViewRenderer {
|
|||
|
||||
//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.
|
||||
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.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.info("Row Action");
|
||||
action.doRowAction(table, table.getSelectedObject());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is called when all createPartControl is done with creating Parts
|
||||
|
|
@ -256,14 +531,14 @@ public class SwtVascViewRenderer implements VascViewRenderer {
|
|||
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) {
|
||||
|
|
@ -278,26 +553,26 @@ public class SwtVascViewRenderer implements VascViewRenderer {
|
|||
|
||||
}
|
||||
|
||||
/* (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) {
|
||||
|
|
@ -307,20 +582,20 @@ public class SwtVascViewRenderer implements VascViewRenderer {
|
|||
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue