[svn r382] hacked jsf frontend working
This commit is contained in:
parent
37fdf22282
commit
9a605f177a
123 changed files with 7035 additions and 2418 deletions
|
|
@ -31,30 +31,35 @@ import java.io.OutputStream;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
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.ControlEvent;
|
||||
import org.eclipse.swt.events.ControlListener;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
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.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
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.FileDialog;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
|
|
@ -62,20 +67,24 @@ import org.eclipse.swt.widgets.Text;
|
|||
import org.eclipse.swt.widgets.ToolBar;
|
||||
import org.eclipse.swt.widgets.ToolItem;
|
||||
|
||||
import com.idcanet.fff.SwingImageHelper;
|
||||
import com.idcanet.vasc.core.AbstractVascFrontend;
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
import com.idcanet.vasc.core.VascFrontendData;
|
||||
import com.idcanet.vasc.core.actions.GlobalVascAction;
|
||||
import com.idcanet.vasc.core.actions.RowVascAction;
|
||||
import com.idcanet.vasc.core.entry.VascEntryEventListener;
|
||||
import com.idcanet.vasc.core.entry.VascEntryExporter;
|
||||
import com.idcanet.vasc.core.ui.VascColumnValueModelListener;
|
||||
import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType;
|
||||
import com.idcanet.vasc.core.ui.VascOptionValueModelListener;
|
||||
import com.idcanet.vasc.core.ui.VascUIComponent;
|
||||
import com.idcanet.vasc.core.ui.VascValueModel;
|
||||
import com.idcanet.vasc.core.ui.VascValueModelListener;
|
||||
import com.idcanet.vasc.frontends.swt.ui.SwtBoolean;
|
||||
import com.idcanet.vasc.frontends.swt.ui.SwtButton;
|
||||
import com.idcanet.vasc.frontends.swt.ui.SwtLabel;
|
||||
import com.idcanet.vasc.frontends.swt.ui.SwtList;
|
||||
import com.idcanet.vasc.frontends.swt.ui.SwtText;
|
||||
import com.idcanet.vasc.frontends.swt.ui.SwtTextArea;
|
||||
|
||||
|
|
@ -88,6 +97,7 @@ public class SwtVascFrontend extends AbstractVascFrontend {
|
|||
|
||||
private Logger logger = null;
|
||||
private Composite parent = null;
|
||||
private boolean renderGlobalActions = true;
|
||||
|
||||
public SwtVascFrontend(Composite parent) {
|
||||
logger = Logger.getLogger(SwtVascFrontend.class.getName());
|
||||
|
|
@ -104,6 +114,7 @@ public class SwtVascFrontend extends AbstractVascFrontend {
|
|||
vfd.putVascUIComponent(VascUIComponent.VASC_LABEL,SwtLabel.class.getName());
|
||||
vfd.putVascUIComponent(VascUIComponent.VASC_TEXT, SwtText.class.getName());
|
||||
vfd.putVascUIComponent(VascUIComponent.VASC_BUTTON, SwtButton.class.getName());
|
||||
vfd.putVascUIComponent(VascUIComponent.VASC_LIST, SwtList.class.getName());
|
||||
|
||||
// optional UI components
|
||||
vfd.putVascUIComponent(VascUIComponent.VASC_BOOLEAN , SwtBoolean.class.getName());
|
||||
|
|
@ -112,8 +123,24 @@ public class SwtVascFrontend extends AbstractVascFrontend {
|
|||
//vfd.putVascUIComponent(VascUIComponent.VASC_COLOR, SwtColorChooser.class.getName());
|
||||
}
|
||||
|
||||
|
||||
private static final String[] FILTER_NAMES = {
|
||||
/**
|
||||
* @return the renderGlobalActions
|
||||
*/
|
||||
public boolean isRenderGlobalActions() {
|
||||
return renderGlobalActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param renderGlobalActions the renderGlobalActions to set
|
||||
*/
|
||||
public void setRenderGlobalActions(boolean renderGlobalActions) {
|
||||
this.renderGlobalActions = renderGlobalActions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static final String[] FILTER_NAMES = {
|
||||
"All Files (*.*)",
|
||||
"Comma Separated Values Files (*.csv)",
|
||||
"Microsoft Excel Spreadsheet Files (*.xls)",
|
||||
|
|
@ -125,7 +152,7 @@ public class SwtVascFrontend extends AbstractVascFrontend {
|
|||
FileDialog dlg = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
|
||||
dlg.setFilterNames(FILTER_NAMES);
|
||||
dlg.setFilterExtensions(FILTER_EXTS);
|
||||
dlg.setFileName(entry.getHeaderName()+".csv");
|
||||
dlg.setFileName(entry.getName()+".csv");
|
||||
String fileName = dlg.open();
|
||||
logger.fine("FileName: "+fileName);
|
||||
if (fileName == null) {
|
||||
|
|
@ -144,225 +171,33 @@ public class SwtVascFrontend extends AbstractVascFrontend {
|
|||
}
|
||||
}
|
||||
|
||||
public void renderEdit(Object object) throws Exception {
|
||||
|
||||
public void renderEdit() throws Exception {
|
||||
logger.fine("Rending Edit View");
|
||||
|
||||
object = entry.getVascFrontendData().getVascFrontendHelper().initEditObject(entry, object);
|
||||
|
||||
SwtVascEditDialog dialog = new SwtVascEditDialog(Display.getCurrent().getActiveShell(),object,"Vasc Edit","Edit");
|
||||
Object result = dialog.open();
|
||||
if(result==null) {
|
||||
return;
|
||||
SwtVascEditDialog dialog = new SwtVascEditDialog(entry);
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
public void renderDelete() throws Exception {
|
||||
boolean del = askDelete( Display.getCurrent().getActiveShell() );
|
||||
if (del==false) {
|
||||
return;
|
||||
}
|
||||
// yes
|
||||
entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry);
|
||||
}
|
||||
|
||||
private boolean askDelete(Shell shell) {
|
||||
logger.finest("Asking for delete");
|
||||
MessageBox askDelete = new MessageBox(shell,SWT.ICON_QUESTION|SWT.YES|SWT.NO);
|
||||
askDelete.setText(i18n("crud.event.delete.confim.title"));
|
||||
askDelete.setMessage(i18n("crud.event.delete.confim.question"));
|
||||
int state = askDelete.open();
|
||||
if (state == SWT.YES) {
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
try {
|
||||
result = entry.getVascDataSource().merge(object);
|
||||
//table.getVascTableController().fireModelUpdateListeners(result);
|
||||
} finally {
|
||||
//TODO: or merge into table == faster
|
||||
entry.getVascTableController().refreshData(entry);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public ImageDescriptor getImageDescriptor(String path) {
|
||||
try {
|
||||
path = i18n(path);
|
||||
|
||||
|
||||
logger.fine("Loading image: "+path);
|
||||
ImageDescriptor result = ImageDescriptor.createFromFile(path.getClass(), path);
|
||||
result = ImageDescriptor.createFromFile(SwingImageHelper.class, path);
|
||||
if(result==null) {
|
||||
// try load fff
|
||||
//result = ImageDescriptor.createFromURL(SwingImageHelper.class.getClass().getResource(path));
|
||||
}
|
||||
if(result==null) {
|
||||
throw new NullPointerException("Can't load resource: "+path);
|
||||
}
|
||||
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 void renderDelete(Object rowBean) throws Exception {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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,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);
|
||||
try {
|
||||
createBody(body);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
//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) throws Exception {
|
||||
body.setLayout(new GridLayout(2, true));
|
||||
body.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
|
||||
|
||||
for (VascEntryField c:entry.getVascEntryFields()) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().initEditObjectColumn(c, bean);
|
||||
if (c.getEdit()==false) {
|
||||
continue;
|
||||
}
|
||||
//if (c.isEditReadOnly()==true) {
|
||||
|
||||
for (int i=0;i<c.getVascEntryFieldType().getUIComponentCount(c);i++) {
|
||||
|
||||
VascUIComponent label = c.getVascEntryFieldType().provideLabelUIComponent(i,c);
|
||||
VascValueModel model = new VascValueModel();
|
||||
model.setValue(i18n(c.getName()));
|
||||
label.createComponent(entry,c,model,body);
|
||||
|
||||
VascUIComponent editor = c.getVascEntryFieldType().provideEditorUIComponent(i,c);
|
||||
model = new VascValueModel(c.getVascEntryFieldType().provideEditorVascValueModel(i,c));
|
||||
model.setValue(c.getVascEntryFieldValue().getValue(c, bean));
|
||||
model.addListener(new VascColumnValueModelListener(c,bean));
|
||||
Object g = editor.createComponent(entry,c,model,body);
|
||||
|
||||
if (i==0) {
|
||||
entry.getVascFrontendData().addFieldVascUIComponents(c, editor,g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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(getImageDescriptor("vasc.dialog.save.image").createImage());
|
||||
saveButton.setText(i18n("vasc.dialog.save.name"));
|
||||
saveButton.setToolTipText(i18n("vasc.dialog.save.tooltip"));
|
||||
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(getImageDescriptor("vasc.dialog.cancel.image").createImage());
|
||||
cancelButton.setText(i18n("vasc.dialog.cancel.name"));
|
||||
cancelButton.setToolTipText(i18n("vasc.dialog.cancel.tooltip"));
|
||||
cancelButton.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
result = null;
|
||||
shell.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public Object defaultColumnEditor(VascEntryField column,Object bean,Object gui) throws Exception {
|
||||
|
||||
Composite body = (Composite)gui;
|
||||
Text text = new Text(body,SWT.SINGLE);
|
||||
text.addSelectionListener(new TextListener(column,bean));
|
||||
text.setText(""+column.getVascEntryFieldValue().getValue(column, bean));
|
||||
return text;
|
||||
}
|
||||
|
||||
class TextListener extends SelectionAdapter {
|
||||
|
||||
private VascEntryField column = null;
|
||||
private Object bean = null;
|
||||
|
||||
public TextListener(VascEntryField column,Object bean) {
|
||||
this.column=column;
|
||||
this.bean=bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
|
||||
*/
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
// SHIT it works :)
|
||||
Object value = e.data;
|
||||
logger.finer("Setting value: "+value);
|
||||
try {
|
||||
column.getVascEntryFieldValue().setValue(column, bean, value);
|
||||
} catch (Exception ee) {
|
||||
ee.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void renderView() throws Exception {
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.marginHeight = 0;
|
||||
|
|
@ -390,85 +225,138 @@ public class SwtVascFrontend extends AbstractVascFrontend {
|
|||
createHeader(header);
|
||||
createBody(body);
|
||||
createFooter(footer);
|
||||
|
||||
// should be last
|
||||
partCreated();
|
||||
}
|
||||
|
||||
|
||||
public void createHeader(Composite header) {
|
||||
logger.finest("Creating header");
|
||||
Color c = header.getDisplay().getSystemColor(SWT.COLOR_WHITE);
|
||||
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.marginHeight = 0;
|
||||
layout.marginWidth = 0;
|
||||
layout.marginTop = 0;
|
||||
header.setLayout(layout);
|
||||
header.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
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));
|
||||
|
||||
header.setBackground(c);
|
||||
|
||||
if (isRenderGlobalActions()) {
|
||||
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));
|
||||
|
||||
ToolBar toolBar = new ToolBar(headerBar, SWT.NONE);
|
||||
for (GlobalVascAction action:entry.getGlobalActions()) {
|
||||
if (entry.getVascFrontendData().getVascFrontendHelper().renderGlobalVascAction(action)==false) {
|
||||
continue;
|
||||
}
|
||||
ToolItem item = new ToolItem(toolBar, SWT.PUSH);
|
||||
item.setText(i18n(action.getName()));
|
||||
item.setToolTipText(i18n(action.getDescription()));
|
||||
item.setImage((Image)i18nImage(action.getImage()));
|
||||
item.addSelectionListener(new GlobalActionListener(action));
|
||||
}
|
||||
}
|
||||
|
||||
Composite headerName = new Composite(header, SWT.NONE);
|
||||
GridLayout bodyLayout = new GridLayout();
|
||||
bodyLayout.numColumns = 1;
|
||||
bodyLayout.numColumns = 2;
|
||||
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:entry.getGlobalActions()) {
|
||||
ToolItem item = new ToolItem(toolBar, SWT.PUSH);
|
||||
item.setText(i18n(action.getName()));
|
||||
item.setToolTipText(i18n(action.getToolTip()));
|
||||
if (action.getImage()!=null) {
|
||||
item.setImage(getImageDescriptor(action.getImage()).createImage());
|
||||
}
|
||||
item.addSelectionListener(new GlobalActionListener(action));
|
||||
}
|
||||
|
||||
|
||||
Color c = new Color(header.getDisplay(),255,255,255);
|
||||
headerName.setBackground(c);
|
||||
if(entry.getHeaderName()!=null) {
|
||||
Font headerFont = new Font(header.getDisplay(), "verdana", 16, SWT.BOLD);
|
||||
Label l = new Label(headerName, SWT.CENTER);
|
||||
l.setImage(getImageDescriptor(entry.getHeaderImage()).createImage());
|
||||
l.setFont(headerFont);
|
||||
l.setText(i18n(entry.getHeaderName()));
|
||||
l.setBackground(c);
|
||||
|
||||
Label l = new Label(headerName, SWT.CENTER);
|
||||
l.setImage((Image)i18nImage(entry.getListImage()));
|
||||
l.setBackground(c);
|
||||
|
||||
Font headerFont = new Font(header.getDisplay(), "verdana", 16, SWT.BOLD);
|
||||
l = new Label(headerName, SWT.CENTER);
|
||||
l.setFont(headerFont);
|
||||
l.setText(i18n(entry.getName()));
|
||||
l.setBackground(c);
|
||||
|
||||
Composite headerText = new Composite(header, SWT.NONE);
|
||||
bodyLayout = new GridLayout();
|
||||
bodyLayout.numColumns = 1;
|
||||
headerText.setLayout(bodyLayout);
|
||||
headerText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
headerText.setBackground(c);
|
||||
|
||||
l = new Label(headerText, SWT.CENTER);
|
||||
l.setText(i18n(entry.getListDescription()));
|
||||
l.setBackground(c);
|
||||
|
||||
Composite headerSplit = new Composite(header, SWT.NONE);
|
||||
GridLayout headerSplitLayout = new GridLayout();
|
||||
headerSplitLayout.numColumns = 2;
|
||||
headerSplit.setLayout(headerSplitLayout);
|
||||
headerSplit.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
Composite headerOptions = new Composite(headerSplit, SWT.NONE);
|
||||
GridLayout headerOptionsLayout = new GridLayout();
|
||||
headerOptionsLayout.numColumns = 2;
|
||||
headerOptions.setLayout(headerOptionsLayout);
|
||||
headerOptions.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
try {
|
||||
for (VascEntryField option:entry.getListOptions()) {
|
||||
for (int i=0;i<option.getVascEntryFieldType().getUIComponentCount(option);i++) {
|
||||
|
||||
com.idcanet.vasc.core.ui.VascUIComponent label = option.getVascEntryFieldType().provideLabelUIComponent(i,option);
|
||||
VascValueModel model = new VascValueModel();
|
||||
model.setValue(i18n(option.getName()));
|
||||
label.createComponent(entry,option,model,headerOptions);
|
||||
|
||||
com.idcanet.vasc.core.ui.VascUIComponent editor = option.getVascEntryFieldType().provideEditorUIComponent(i,option);
|
||||
model = new VascValueModel(option.getVascEntryFieldType().provideEditorVascValueModel(i,option));
|
||||
model.addListener(new VascOptionValueModelListener(option));
|
||||
model.setValue(null);
|
||||
model.addListener(new VascValueModelListener() {
|
||||
public void valueUpdate(VascValueModel model) throws VascException {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry);// mm
|
||||
}
|
||||
});
|
||||
Object edit = editor.createComponent(entry,option,model,headerOptions);
|
||||
|
||||
// i==0 is for multi field editor support... which is stell very in progress
|
||||
if (i==0) {
|
||||
entry.getVascFrontendData().addFieldVascUIComponents(option, editor,edit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
*/
|
||||
//}
|
||||
}
|
||||
class GlobalActionListener extends SelectionAdapter {
|
||||
Composite headerRightOptions = new Composite(headerSplit, SWT.NONE | SWT.RIGHT | SWT.TOP );
|
||||
GridLayout headerRightOptionsLayout = new GridLayout();
|
||||
headerRightOptionsLayout.numColumns = 2;
|
||||
headerRightOptions.setLayout(headerRightOptionsLayout);
|
||||
headerRightOptions.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
Label searchLabel = new Label(headerRightOptions, SWT.CENTER);
|
||||
searchLabel.setText("Zoeken:");
|
||||
|
||||
final Text text = new Text(headerRightOptions, SWT.NONE | SWT.BORDER );
|
||||
text.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
String value = text.getText();
|
||||
try {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().searchAction(entry, value);
|
||||
} catch (Exception ee) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
entry.getVascFrontendData().getVascFrontendHelper().headerOptionsCreatedFillData(entry);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalActionListener extends SelectionAdapter {
|
||||
|
||||
private GlobalVascAction action = null;
|
||||
|
||||
public GlobalActionListener(GlobalVascAction action) {
|
||||
|
|
@ -483,28 +371,26 @@ public class SwtVascFrontend extends AbstractVascFrontend {
|
|||
try {
|
||||
action.doGlobalAction(entry);
|
||||
} catch (Exception e) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(e, entry);
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void createBody(Composite body) {
|
||||
logger.finer("Creating body");
|
||||
|
||||
|
||||
|
||||
// Create the table viewer to display the players
|
||||
final TableViewer tableViewer = new TableViewer(body, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
|
||||
// SWT.CHECK
|
||||
final TableViewer tableViewer = new TableViewer(body, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
|
||||
final Table table2 = tableViewer.getTable();
|
||||
table2.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
table2.setHeaderVisible(true);
|
||||
table2.setLinesVisible(true);
|
||||
|
||||
body.addControlListener(new ResizeTableControlListener(body,table2));
|
||||
|
||||
table2.addSelectionListener(new SelectionListener() {
|
||||
|
||||
/**
|
||||
|
|
@ -542,36 +428,34 @@ public class SwtVascFrontend extends AbstractVascFrontend {
|
|||
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);
|
||||
/*
|
||||
* //columns[i].setData("PROP",table.getTableColumns().get(i)....);
|
||||
*
|
||||
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);
|
||||
*/
|
||||
table2.setSortDirection(dir);
|
||||
VascEntryField field = (VascEntryField)currentColumn.getData();
|
||||
entry.getVascFrontendData().getVascFrontendHelper().sortAction(entry, field);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
entry.addVascEntryEventListener(VascEventType.DATA_LIST_UPDATE, new VascEntryEventListener() {
|
||||
public void vascEvent(VascEntry entry,VascEventType type,Object data) {
|
||||
tableViewer.refresh();
|
||||
table2.deselectAll();
|
||||
}
|
||||
public VascEntryEventListener clone() throws CloneNotSupportedException {
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
for(VascEntryField c:entry.getVascEntryFields()) {
|
||||
|
||||
for (VascEntryField c:entry.getVascEntryFields()) {
|
||||
if (entry.getVascFrontendData().getVascFrontendHelper().renderList(c)==false) {
|
||||
continue;
|
||||
}
|
||||
TableColumn tc = new TableColumn(table2, SWT.LEFT);
|
||||
tc.setText(c.getName());
|
||||
tc.setToolTipText(c.getDescription());
|
||||
if (c.getImage()!=null) {
|
||||
tc.setImage(getImageDescriptor(c.getImage()).createImage());
|
||||
}
|
||||
tc.setText(i18n(c.getName()));
|
||||
tc.setData(c);
|
||||
tc.setToolTipText(i18n(c.getDescription()));
|
||||
tc.setImage((Image)i18nImage(c.getImage()));
|
||||
tc.addListener(SWT.Selection, sortListener);
|
||||
tc.setMoveable(false);
|
||||
tc.setMoveable(true);
|
||||
tc.setResizable(true);
|
||||
}
|
||||
|
||||
|
|
@ -579,14 +463,15 @@ public class SwtVascFrontend extends AbstractVascFrontend {
|
|||
logger.finer("Total size: "+totalWidth);
|
||||
TableColumn[] columns = table2.getColumns();
|
||||
for (int i = 0; i < columns.length; i++) {
|
||||
Integer cWidth = entry.getVascEntryFields().get(i).getSizeEdit();
|
||||
if (cWidth==null) {
|
||||
break;
|
||||
VascEntryField c = (VascEntryField)columns[i].getData();
|
||||
Integer cWidth = c.getSizeList();
|
||||
if (cWidth!=null) {
|
||||
//int w = (int)((double)totalSize/(double)totalSize)*cWidth;
|
||||
columns[i].setWidth(cWidth);
|
||||
//logger.finest("Setting column width: "+w+" total: "+totalSize+" c: "+cWidth+" of column: "+i);
|
||||
} else {
|
||||
columns[i].pack();
|
||||
}
|
||||
//int w = (int)((double)totalSize/(double)totalSize)*cWidth;
|
||||
columns[i].setWidth(cWidth);
|
||||
columns[i].pack();
|
||||
//logger.finest("Setting column width: "+w+" total: "+totalSize+" c: "+cWidth+" of column: "+i);
|
||||
}
|
||||
logger.fine("Table with columns created: "+table2.getColumnCount());
|
||||
|
||||
|
|
@ -594,27 +479,64 @@ public class SwtVascFrontend extends AbstractVascFrontend {
|
|||
tableViewer.refresh();
|
||||
}
|
||||
|
||||
|
||||
class ResizeTableControlListener implements ControlListener {
|
||||
Composite comp = null;
|
||||
Table table = null;
|
||||
public ResizeTableControlListener(Composite comp,Table table) {
|
||||
this.comp=comp;
|
||||
this.table=table;
|
||||
}
|
||||
public void controlResized(ControlEvent e) {
|
||||
Rectangle area = comp.getClientArea();
|
||||
Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
|
||||
int width = area.width - 2*table.getBorderWidth();
|
||||
if (preferredSize.y > area.height + table.getHeaderHeight()) {
|
||||
// Subtract the scrollbar width from the total column width
|
||||
// if a vertical scrollbar will be required
|
||||
Point vBarSize = table.getVerticalBar().getSize();
|
||||
width -= vBarSize.x;
|
||||
}
|
||||
Point oldSize = table.getSize();
|
||||
if (oldSize.x > area.width) {
|
||||
// table is getting smaller so make the columns
|
||||
// smaller first and then resize the table to
|
||||
// match the client area width
|
||||
table.setSize(area.width, area.height);
|
||||
} else {
|
||||
// table is getting bigger so make the table
|
||||
// bigger first and then make the columns wider
|
||||
// to match the client area width
|
||||
table.setSize(area.width, area.height);
|
||||
//column1.setWidth(width/3);
|
||||
//column2.setWidth(width - column1.getWidth());
|
||||
}
|
||||
}
|
||||
public void controlMoved(ControlEvent e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void createFooter(Composite footer) {
|
||||
logger.finest("Creating footer");
|
||||
for(RowVascAction action:entry.getRowActions()) {
|
||||
for( RowVascAction action:entry.getRowActions()) {
|
||||
if (entry.getVascFrontendData().getVascFrontendHelper().renderRowVascAction(action)==false) {
|
||||
continue;
|
||||
}
|
||||
Button actionButton = new Button(footer, SWT.NONE);
|
||||
actionButton.setText(i18n(action.getName()));
|
||||
actionButton.setToolTipText(i18n(action.getToolTip()));
|
||||
if (action.getImage()!=null) {
|
||||
actionButton.setImage(getImageDescriptor(action.getImage()).createImage());
|
||||
}
|
||||
actionButton.setToolTipText(i18n(action.getDescription()));
|
||||
actionButton.setImage((Image)i18nImage(action.getImage()));
|
||||
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)
|
||||
*/
|
||||
|
|
@ -624,17 +546,11 @@ public class SwtVascFrontend extends AbstractVascFrontend {
|
|||
try {
|
||||
action.doRowAction(entry, entry.getVascFrontendData().getEntryDataObject());
|
||||
} catch (Exception e) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(e, entry);
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is called when all createPartControl is done with creating Parts
|
||||
*/
|
||||
public void partCreated() {
|
||||
|
||||
}
|
||||
|
||||
class DefaultLabelProvider implements ITableLabelProvider {
|
||||
|
||||
|
|
@ -655,10 +571,27 @@ public class SwtVascFrontend extends AbstractVascFrontend {
|
|||
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
|
||||
*/
|
||||
public String getColumnText(Object bean, int columnNumber) {
|
||||
VascEntryField vtc = entry.getVascEntryFields().get(columnNumber);
|
||||
|
||||
int col=0;
|
||||
VascEntryField vtc = null;
|
||||
for (VascEntryField c:entry.getVascEntryFields()) {
|
||||
if (entry.getVascFrontendData().getVascFrontendHelper().renderList(c)==false) {
|
||||
continue;
|
||||
}
|
||||
if (col==columnNumber) {
|
||||
vtc = c;
|
||||
break;
|
||||
}
|
||||
col++;
|
||||
}
|
||||
if (vtc==null) {
|
||||
// should not happen
|
||||
vtc = entry.getVascEntryFields().get(columnNumber);
|
||||
}
|
||||
|
||||
//if (vtc.getVascColumnRenderer()==null) {
|
||||
try {
|
||||
return ""+vtc.getVascEntryFieldValue().getValue(vtc,bean);
|
||||
return vtc.getVascEntryFieldValue().getDisplayValue(vtc,bean);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING,"Error in get value: '"+vtc.getVascEntryFieldValue()+"' error: "+e.getMessage(),e);
|
||||
return "Err";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue