moved to sub projects
This commit is contained in:
parent
a523cc9122
commit
dff60035cf
182 changed files with 251 additions and 46 deletions
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc.frontends.swt;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.ui.VascColumnValueModelListener;
|
||||
import net.forwardfire.vasc.core.ui.VascUIComponent;
|
||||
import net.forwardfire.vasc.core.ui.VascValueModel;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
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.Control;
|
||||
import org.eclipse.swt.widgets.Dialog;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 13, 2009
|
||||
*/
|
||||
public class SwtVascEditDialog extends Dialog {
|
||||
|
||||
private VascEntry entry = null;
|
||||
private Shell shell = null;
|
||||
|
||||
public SwtVascEditDialog (VascEntry entry) {
|
||||
super (Display.getCurrent().getActiveShell(), 0);
|
||||
this.entry=entry;
|
||||
}
|
||||
|
||||
protected String i18n(String key,Object...params) {
|
||||
return entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key,params);
|
||||
}
|
||||
|
||||
protected Object i18nImage(String key) {
|
||||
if (entry.getVascFrontendData().getVascEntryResourceImageResolver()==null) {
|
||||
return null;
|
||||
}
|
||||
return entry.getVascFrontendData().getVascEntryResourceImageResolver().getImageValue(entry,key);
|
||||
}
|
||||
|
||||
public void open() throws VascException {
|
||||
shell = new Shell(getParent(), SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
|
||||
shell.setText(i18n(entry.getName()));
|
||||
|
||||
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);
|
||||
|
||||
shell.pack();
|
||||
shell.open();
|
||||
|
||||
Display display = shell.getDisplay();
|
||||
while (!shell.isDisposed()) {
|
||||
if (!display.readAndDispatch()) {
|
||||
display.sleep();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void createHeader(Composite header) {
|
||||
|
||||
String displayFieldId = entry.getDisplayNameFieldId();
|
||||
VascEntryField dis = entry.getVascEntryFieldById(displayFieldId);
|
||||
if (dis==null) {
|
||||
throw new RuntimeException("Could not find: "+displayFieldId+" from: "+entry.getId());
|
||||
}
|
||||
String name = null;
|
||||
try {
|
||||
Object bean = entry.getVascFrontendData().getVascEntryState().getEntryDataObject();
|
||||
name = dis.getVascEntryFieldValue().getDisplayValue(dis, bean);
|
||||
} catch (VascException e) {
|
||||
throw new RuntimeException("Could not display value from "+entry.getId(),e);
|
||||
}
|
||||
|
||||
Color c = new Color(header.getDisplay(),255,255,255);
|
||||
header.setBackground(c);
|
||||
|
||||
Label img = new Label(header, SWT.NONE);
|
||||
if (entry.getVascFrontendData().getVascEntryState().isEditCreate()) {
|
||||
img.setImage((Image)i18nImage(entry.getCreateImage()));
|
||||
} else {
|
||||
img.setImage((Image)i18nImage(entry.getEditImage()));
|
||||
}
|
||||
img.setBackground(c);
|
||||
|
||||
Font headerFont = new Font(header.getDisplay(), "verdana", 14, SWT.NONE);
|
||||
Label l = new Label(header, SWT.CENTER);
|
||||
if (entry.getVascFrontendData().getVascEntryState().isEditCreate()) {
|
||||
l.setText(i18n(entry.getCreateDescription(),name));
|
||||
} else {
|
||||
l.setText(i18n(entry.getEditDescription(),name));
|
||||
}
|
||||
l.setFont(headerFont);
|
||||
l.setBackground(c);
|
||||
}
|
||||
|
||||
public void createBody(Composite body) throws VascException {
|
||||
body.setLayout(new GridLayout(2, true));
|
||||
body.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
Object bean = entry.getVascFrontendData().getVascEntryState().getEntryDataObject();
|
||||
|
||||
entry.getVascFrontendData().clearFieldRenderObjects(); // only needed for swt use
|
||||
|
||||
for (VascEntryField c:entry.getVascEntryFields()) {
|
||||
if (entry.getVascFrontendData().getVascFrontendHelper().renderEdit(c)==false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
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()));
|
||||
Control realLabel = (Control)label.createComponent(entry,c,model,body);
|
||||
realLabel.setToolTipText(i18n(c.getDescription()));
|
||||
|
||||
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));
|
||||
Control edit = (Control )editor.createComponent(entry,c,model,body);
|
||||
|
||||
if (edit.getLayoutData()==null) { // is for textarea which has custum layout data
|
||||
GridData gridData = new GridData();
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
gridData.grabExcessVerticalSpace = true;
|
||||
gridData.horizontalAlignment = GridData.FILL;
|
||||
gridData.verticalAlignment = GridData.FILL;
|
||||
edit.setLayoutData(gridData);
|
||||
}
|
||||
|
||||
if (i==0) {
|
||||
entry.getVascFrontendData().addFieldVascUIComponents(c, editor,edit);
|
||||
}
|
||||
}
|
||||
}
|
||||
entry.getVascFrontendData().getVascFrontendHelper().editReadOnlyUIComponents(entry);
|
||||
}
|
||||
|
||||
public void createFooter(Composite body) {
|
||||
Button saveButton = new Button(body, SWT.NONE);
|
||||
saveButton.setImage((Image)i18nImage("vasc.action.saveAction.image"));
|
||||
saveButton.setText(i18n("vasc.action.saveAction.name"));
|
||||
saveButton.setToolTipText(i18n("vasc.action.saveAction.description"));
|
||||
saveButton.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
try {
|
||||
boolean error = entry.getVascFrontendData().getVascFrontendHelper().validateAndSetErrorText(entry);
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
entry.getVascFrontendData().getVascFrontendHelper().mergeObject(entry);
|
||||
shell.dispose();
|
||||
} catch (Exception ee) {
|
||||
ee.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
Button cancelButton = new Button(body, SWT.NONE);
|
||||
cancelButton.setImage((Image)i18nImage("vasc.action.cancelAction.image"));
|
||||
cancelButton.setText(i18n("vasc.action.cancelAction.name"));
|
||||
cancelButton.setToolTipText(i18n("vasc.action.cancelAction.description"));
|
||||
cancelButton.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(null);
|
||||
shell.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,668 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc.frontends.swt;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.forwardfire.vasc.core.AbstractVascFrontend;
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.VascFrontendData;
|
||||
import net.forwardfire.vasc.core.actions.GlobalVascAction;
|
||||
import net.forwardfire.vasc.core.actions.RowVascAction;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryExporter;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType;
|
||||
import net.forwardfire.vasc.core.ui.VascOptionValueModelListener;
|
||||
import net.forwardfire.vasc.core.ui.VascUIComponent;
|
||||
import net.forwardfire.vasc.core.ui.VascValueModel;
|
||||
import net.forwardfire.vasc.core.ui.VascValueModelListener;
|
||||
import net.forwardfire.vasc.frontends.swt.ui.SwtBoolean;
|
||||
import net.forwardfire.vasc.frontends.swt.ui.SwtButton;
|
||||
import net.forwardfire.vasc.frontends.swt.ui.SwtLabel;
|
||||
import net.forwardfire.vasc.frontends.swt.ui.SwtList;
|
||||
import net.forwardfire.vasc.frontends.swt.ui.SwtText;
|
||||
import net.forwardfire.vasc.frontends.swt.ui.SwtTextArea;
|
||||
|
||||
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.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;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.swt.widgets.ToolBar;
|
||||
import org.eclipse.swt.widgets.ToolItem;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 21, 2007
|
||||
*/
|
||||
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());
|
||||
this.parent=parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.VascFrontend#getFrontendType()
|
||||
*/
|
||||
public String getFrontendType() {
|
||||
return "swt";
|
||||
}
|
||||
|
||||
/**
|
||||
* Add swt implmented ui components
|
||||
*/
|
||||
protected void addUiComponents() {
|
||||
VascFrontendData vfd = getVascEntry().getVascFrontendData();
|
||||
|
||||
// required UI components
|
||||
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());
|
||||
//vfd.putVascUIComponent(VascUIComponent.VASC_DATE , SwtDate.class.getName());
|
||||
vfd.putVascUIComponent(VascUIComponent.VASC_TEXTAREA, SwtTextArea.class.getName());
|
||||
//vfd.putVascUIComponent(VascUIComponent.VASC_COLOR, SwtColorChooser.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the renderGlobalActions
|
||||
*/
|
||||
public boolean isRenderGlobalActions() {
|
||||
return renderGlobalActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param renderGlobalActions the renderGlobalActions to set
|
||||
*/
|
||||
public void setRenderGlobalActions(boolean renderGlobalActions) {
|
||||
this.renderGlobalActions = renderGlobalActions;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object i18nImage(String key) {
|
||||
if (entry.getVascFrontendData().getVascEntryResourceImageResolver()==null) {
|
||||
return null;
|
||||
}
|
||||
return entry.getVascFrontendData().getVascEntryResourceImageResolver().getImageValue(entry,key);
|
||||
}
|
||||
|
||||
private static final String[] FILTER_NAMES = {
|
||||
"All Files (*.*)",
|
||||
"Comma Separated Values Files (*.csv)",
|
||||
"Microsoft Excel Spreadsheet Files (*.xls)",
|
||||
};
|
||||
/** These filter extensions are used to filter which files are displayed. */
|
||||
private static final String[] FILTER_EXTS = { "*.*","*.csv","*.xls" };
|
||||
|
||||
public void renderExport(VascEntryExporter exporter) throws Exception {
|
||||
FileDialog dlg = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
|
||||
dlg.setFilterNames(FILTER_NAMES);
|
||||
dlg.setFilterExtensions(FILTER_EXTS);
|
||||
dlg.setFileName(entry.getName()+".csv");
|
||||
String fileName = dlg.open();
|
||||
logger.fine("FileName: "+fileName);
|
||||
if (fileName == null) {
|
||||
return;
|
||||
}
|
||||
OutputStream out = new FileOutputStream(fileName);
|
||||
try {
|
||||
exporter.doExport(out, entry);
|
||||
} catch (Exception e) {
|
||||
//MessageDialog.openError(Display.getCurrent().getActiveShell(),crudTable.i18n("crud.event.export.error.title"),crudTable.i18n("crud.event.export.error.message"));
|
||||
logger.log(Level.WARNING,"Error: "+e.getMessage(),e);
|
||||
} finally {
|
||||
if (out!=null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void renderEdit() throws Exception {
|
||||
logger.fine("Rending Edit View");
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void renderView() throws Exception {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
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 = 2;
|
||||
headerName.setLayout(bodyLayout);
|
||||
headerName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
headerName.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++) {
|
||||
|
||||
net.forwardfire.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);
|
||||
|
||||
net.forwardfire.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
this.action=action;
|
||||
}
|
||||
/**
|
||||
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
|
||||
*/
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
logger.fine("Global Action");
|
||||
try {
|
||||
action.doGlobalAction(entry);
|
||||
} catch (Exception e) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void createBody(Composite body) {
|
||||
logger.finer("Creating body");
|
||||
|
||||
|
||||
|
||||
// Create the table viewer to display the players
|
||||
// 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() {
|
||||
|
||||
/**
|
||||
* @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.fine("Slecting data: "+data);
|
||||
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(data);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Set the content and label providers
|
||||
tableViewer.setContentProvider(new ListConverterContentProvider());
|
||||
tableViewer.setLabelProvider(new DefaultLabelProvider(entry));
|
||||
//TODO: add renderer support
|
||||
|
||||
//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;
|
||||
}
|
||||
table2.setSortDirection(dir);
|
||||
VascEntryField field = (VascEntryField)currentColumn.getData();
|
||||
entry.getVascFrontendData().getVascFrontendHelper().sortAction(entry, field);
|
||||
}
|
||||
};
|
||||
|
||||
entry.getVascFrontendData().addVascEntryFrontendEventListener(new VascEntryFrontendEventListener() {
|
||||
public VascFrontendEventType[] getEventTypes() {
|
||||
VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.POST_READ};
|
||||
return result;
|
||||
}
|
||||
public void vascEvent(VascEntry entry,Object data) {
|
||||
tableViewer.refresh();
|
||||
table2.deselectAll();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
for (VascEntryField c:entry.getVascEntryFields()) {
|
||||
if (entry.getVascFrontendData().getVascFrontendHelper().renderList(c)==false) {
|
||||
continue;
|
||||
}
|
||||
TableColumn tc = new TableColumn(table2, SWT.LEFT);
|
||||
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(true);
|
||||
tc.setResizable(true);
|
||||
}
|
||||
|
||||
int totalWidth = entry.getVascFrontendData().getVascFrontendHelper().getTotalColumnsWidth(entry);
|
||||
logger.finer("Total size: "+totalWidth);
|
||||
TableColumn[] columns = table2.getColumns();
|
||||
for (int i = 0; i < columns.length; i++) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
logger.fine("Table with columns created: "+table2.getColumnCount());
|
||||
|
||||
tableViewer.setInput(entry);
|
||||
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()) {
|
||||
if (entry.getVascFrontendData().getVascFrontendHelper().renderRowVascAction(action)==false) {
|
||||
continue;
|
||||
}
|
||||
Button actionButton = new Button(footer, SWT.NONE);
|
||||
actionButton.setText(i18n(action.getName()));
|
||||
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)
|
||||
*/
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
logger.fine("Row Action");
|
||||
try {
|
||||
action.doRowAction(entry, entry.getVascFrontendData().getVascEntryState().getEntryDataObject());
|
||||
} catch (Exception e) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DefaultLabelProvider implements ITableLabelProvider {
|
||||
|
||||
private VascEntry entry = null;
|
||||
|
||||
public DefaultLabelProvider(VascEntry entry) {
|
||||
this.entry=entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
|
||||
*/
|
||||
public Image getColumnImage(Object arg0, int arg1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
|
||||
*/
|
||||
public String getColumnText(Object bean, int 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().getDisplayValue(vtc,bean);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING,"Error in get value: '"+vtc.getVascEntryFieldValue()+"' error: "+e.getMessage(),e);
|
||||
return "Err";
|
||||
}
|
||||
//}
|
||||
// see custem column renderer, so this code will never be called
|
||||
//return "CUSTEM_RENDER";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
|
||||
*/
|
||||
public void addListener(ILabelProviderListener arg0) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
|
||||
*/
|
||||
public boolean isLabelProperty(Object arg0, String arg1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
|
||||
*/
|
||||
public void removeListener(ILabelProviderListener arg0) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ListConverterContentProvider implements IStructuredContentProvider {
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
|
||||
*/
|
||||
public Object[] getElements(Object obj) {
|
||||
return ((VascEntry)obj).getVascFrontendData().getVascEntryState().getEntryDataList().toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc.frontends.swt.ui;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.ui.VascUIComponent;
|
||||
import net.forwardfire.vasc.core.ui.VascValueModel;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 13, 2009
|
||||
*/
|
||||
public class SwtBoolean implements VascUIComponent {
|
||||
|
||||
private Button button = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
private Color errorColor = null;
|
||||
|
||||
public Object createComponent(final VascEntry entry,VascEntryField entryField,final VascValueModel model,Object gui) throws VascException {
|
||||
button = new Button((Composite)gui, SWT.CHECK);
|
||||
orgBackgroundColor = button.getBackground();
|
||||
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
|
||||
//button.setImage(getImageDescriptor("vasc.dialog.save.image").createImage());
|
||||
button.setText("");
|
||||
Object value = model.getValue();
|
||||
if (value!=null) {
|
||||
button.setSelection(new Boolean(model.getValue()+""));
|
||||
}
|
||||
//button.setToolTipText(i18n("vasc.dialog.save.tooltip"));
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
Boolean value = button.getSelection();
|
||||
try {
|
||||
System.out.println("setting value: "+value);
|
||||
model.setValue(value);
|
||||
} catch (Exception ee) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
|
||||
}
|
||||
}
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (button==null) {
|
||||
return null;
|
||||
}
|
||||
return button.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String text) {
|
||||
if (button==null) {
|
||||
return;
|
||||
}
|
||||
button.setToolTipText(text);
|
||||
if (text==null) {
|
||||
button.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
button.setBackground(errorColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !button.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
button.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return button.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
button.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc.frontends.swt.ui;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.ui.VascUIComponent;
|
||||
import net.forwardfire.vasc.core.ui.VascValueModel;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 13, 2009
|
||||
*/
|
||||
public class SwtButton implements VascUIComponent {
|
||||
|
||||
private Button button = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
private Color errorColor = null;
|
||||
|
||||
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
|
||||
button = new Button((Composite)gui, SWT.NONE);
|
||||
orgBackgroundColor = button.getBackground();
|
||||
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
|
||||
//button.setImage(getImageDescriptor("vasc.dialog.save.image").createImage());
|
||||
button.setText(model.getValue()+"");
|
||||
//button.setToolTipText(i18n("vasc.dialog.save.tooltip"));
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
}
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (button==null) {
|
||||
return null;
|
||||
}
|
||||
return button.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String text) {
|
||||
if (button==null) {
|
||||
return;
|
||||
}
|
||||
button.setToolTipText(text);
|
||||
if (text==null) {
|
||||
button.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
button.setBackground(errorColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !button.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
button.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return button.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
button.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
|
|
@ -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 net.forwardfire.vasc.frontends.swt.ui;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.ui.VascUIComponent;
|
||||
import net.forwardfire.vasc.core.ui.VascValueModel;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 13, 2009
|
||||
*/
|
||||
public class SwtLabel implements VascUIComponent {
|
||||
|
||||
private Label label = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
private Color errorColor = null;
|
||||
|
||||
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
|
||||
label = new Label((Composite)gui, SWT.NONE);
|
||||
orgBackgroundColor = label.getBackground();
|
||||
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
|
||||
label.setText(model.getValue()+"");
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (label==null) {
|
||||
return null;
|
||||
}
|
||||
return label.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String text) {
|
||||
if (label==null) {
|
||||
return;
|
||||
}
|
||||
label.setToolTipText(text);
|
||||
if (text==null) {
|
||||
label.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
label.setBackground(errorColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !label.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
label.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return label.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
label.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc.frontends.swt.ui;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.ui.VascSelectItem;
|
||||
import net.forwardfire.vasc.core.ui.VascSelectItemModel;
|
||||
import net.forwardfire.vasc.core.ui.VascUIComponent;
|
||||
import net.forwardfire.vasc.core.ui.VascValueModel;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 10, 2009
|
||||
*/
|
||||
public class SwtList implements VascUIComponent {
|
||||
|
||||
private Combo combo = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
private Color errorColor = null;
|
||||
private List<VascSelectItem> data = null;
|
||||
|
||||
public Object createComponent(final VascEntry entry,VascEntryField entryField,final VascValueModel model,Object gui) throws VascException {
|
||||
combo = new Combo((Composite)gui,SWT.SINGLE | SWT.BORDER);
|
||||
combo.setVisibleItemCount(8);
|
||||
VascSelectItemModel items = (VascSelectItemModel)entryField.getVascEntryFieldType().getDataObject();
|
||||
if (items!=null) {
|
||||
data = items.getVascSelectItems(entry);
|
||||
}
|
||||
fillCombo();
|
||||
orgBackgroundColor = combo.getBackground();
|
||||
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
|
||||
combo.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
VascSelectItem item = findItem(combo.getText());
|
||||
if (item!=null) {
|
||||
try {
|
||||
model.setValue(item.getValue());
|
||||
} catch (Exception ee) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// sets default selected
|
||||
for (VascSelectItem i:data) {
|
||||
Object iValue = i.getValue();
|
||||
Object mValue = model.getValue();
|
||||
if (iValue==null && mValue==null) {
|
||||
combo.setText(i.getLabel());
|
||||
break;
|
||||
}
|
||||
if (iValue==null) {
|
||||
continue;
|
||||
}
|
||||
if (iValue.equals(mValue)) {
|
||||
combo.setText(i.getLabel());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (combo.getText()==null) {
|
||||
combo.setText(data.get(0).getLabel()); // select top one.
|
||||
}
|
||||
return combo;
|
||||
}
|
||||
|
||||
private void fillCombo() {
|
||||
if (data==null | combo==null) {
|
||||
return;
|
||||
}
|
||||
for (VascSelectItem i:data) {
|
||||
if (i.isDisabled()) {
|
||||
continue;
|
||||
}
|
||||
combo.add(i.getLabel());
|
||||
}
|
||||
}
|
||||
|
||||
private VascSelectItem findItem(String text) {
|
||||
for (VascSelectItem i:data) {
|
||||
if (i.getLabel().equals(text)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (combo==null) {
|
||||
return null;
|
||||
}
|
||||
return combo.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String text) {
|
||||
if (combo==null) {
|
||||
return;
|
||||
}
|
||||
combo.setToolTipText(text);
|
||||
if (text==null) {
|
||||
combo.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
combo.setBackground(errorColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !combo.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
combo.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return combo.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
combo.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc.frontends.swt.ui;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.ui.VascUIComponent;
|
||||
import net.forwardfire.vasc.core.ui.VascValueModel;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
|
||||
/**
|
||||
* Renders the swt text field.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 13, 2009
|
||||
*/
|
||||
public class SwtText implements VascUIComponent {
|
||||
|
||||
private Text text = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
private Color errorColor = null;
|
||||
|
||||
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
|
||||
text = new Text((Composite)gui, SWT.NONE | SWT.BORDER);
|
||||
orgBackgroundColor = text.getBackground();
|
||||
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
|
||||
Object value = model.getValue();
|
||||
if (value!=null) {
|
||||
text.setText(value.toString());
|
||||
}
|
||||
text.addModifyListener(new TextListener(model,entry));
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
class TextListener implements ModifyListener {
|
||||
private VascValueModel model = null;
|
||||
private VascEntry entry = null;
|
||||
|
||||
public TextListener(VascValueModel model,VascEntry entry) {
|
||||
this.model=model;
|
||||
this.entry=entry;
|
||||
}
|
||||
|
||||
public void modifyText(ModifyEvent e) {
|
||||
Object value = text.getText();
|
||||
try {
|
||||
model.setValue(value);
|
||||
} catch (Exception ee) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (text==null) {
|
||||
return null;
|
||||
}
|
||||
return text.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String textString) {
|
||||
if (text==null) {
|
||||
return;
|
||||
}
|
||||
text.setToolTipText(textString);
|
||||
if (textString==null) {
|
||||
text.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
text.setBackground(errorColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !text.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
text.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return text.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
text.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc.frontends.swt.ui;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.ui.VascUIComponent;
|
||||
import net.forwardfire.vasc.core.ui.VascValueModel;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.FontMetrics;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 13, 2009
|
||||
*/
|
||||
public class SwtTextArea implements VascUIComponent {
|
||||
|
||||
private Text text = null;
|
||||
private Color orgBackgroundColor = null;
|
||||
private Color errorColor = null;
|
||||
|
||||
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
|
||||
text = new Text((Composite)gui, SWT.MULTI | SWT.BORDER);
|
||||
orgBackgroundColor = text.getBackground();
|
||||
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
|
||||
|
||||
int cols = 25;
|
||||
int rows = 3;
|
||||
|
||||
String colsString = entryField.getVascEntryFieldType().getProperty("editor.columns");
|
||||
if (colsString!=null && "".equals(colsString)==false) {
|
||||
cols = new Integer(colsString);
|
||||
}
|
||||
String rowsString = entryField.getVascEntryFieldType().getProperty("editor.rows");
|
||||
if (rowsString!=null && "".equals(rowsString)==false) {
|
||||
rows = new Integer(rowsString);
|
||||
}
|
||||
|
||||
GC gc = new GC(text);
|
||||
FontMetrics fm = gc.getFontMetrics ();
|
||||
gc.dispose ();
|
||||
int width = cols * fm.getAverageCharWidth();
|
||||
int height = rows * fm.getHeight();
|
||||
GridData data = new GridData();
|
||||
data.widthHint = width;
|
||||
data.heightHint = height;
|
||||
text.setLayoutData(data);
|
||||
Object value = model.getValue();
|
||||
if (value!=null) {
|
||||
text.setText(value.toString());
|
||||
}
|
||||
text.addModifyListener(new TextListener(model,entry));
|
||||
return text;
|
||||
}
|
||||
|
||||
class TextListener implements ModifyListener {
|
||||
private VascValueModel model = null;
|
||||
private VascEntry entry = null;
|
||||
|
||||
public TextListener(VascValueModel model,VascEntry entry) {
|
||||
this.model=model;
|
||||
this.entry=entry;
|
||||
}
|
||||
|
||||
public void modifyText(ModifyEvent e) {
|
||||
Object value = text.getText();
|
||||
try {
|
||||
model.setValue(value);
|
||||
} catch (Exception ee) {
|
||||
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#getErrorText()
|
||||
*/
|
||||
public String getErrorText() {
|
||||
if (text==null) {
|
||||
return null;
|
||||
}
|
||||
return text.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
|
||||
*/
|
||||
public void setErrorText(String textString) {
|
||||
if (text==null) {
|
||||
return;
|
||||
}
|
||||
text.setToolTipText(textString);
|
||||
if (textString==null) {
|
||||
text.setBackground(orgBackgroundColor);
|
||||
} else {
|
||||
text.setBackground(errorColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isDisabled()
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !text.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setDisabled(boolean)
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
text.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#isRendered()
|
||||
*/
|
||||
public boolean isRendered() {
|
||||
return text.isVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.ui.VascUIComponent#setRendered(boolean)
|
||||
*/
|
||||
public void setRendered(boolean rendered) {
|
||||
text.setVisible(rendered);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,619 @@
|
|||
/*
|
||||
* Copyright 2004-2006 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 net.forwardfire.vasc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.viewers.CellEditor;
|
||||
import org.eclipse.jface.viewers.CheckboxCellEditor;
|
||||
import org.eclipse.jface.viewers.ColorCellEditor;
|
||||
import org.eclipse.jface.viewers.ComboBoxCellEditor;
|
||||
import org.eclipse.jface.viewers.ICellModifier;
|
||||
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.TextCellEditor;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.window.ApplicationWindow;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
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.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Item;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests a simple x4o xml language.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jul 24, 2006
|
||||
*/
|
||||
public class SWTTableViewerTest extends TestCase {
|
||||
|
||||
public void setUp() throws Exception {
|
||||
// enable all logs
|
||||
//InputStream loggingProperties = this.getClass().getResourceAsStream("/META-INF/logging.properties");
|
||||
//LogManager.getLogManager().readConfiguration( loggingProperties );
|
||||
//loggingProperties.close();
|
||||
|
||||
// load xtes queries
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new PersonEditor().run();
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
public void testNull() throws Exception {
|
||||
assertEquals(true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class PersonEditor extends ApplicationWindow {
|
||||
// Table column names/properties
|
||||
public static final String NAME = "Name";
|
||||
|
||||
public static final String MALE = "Male?";
|
||||
|
||||
public static final String AGE = "Age Range";
|
||||
|
||||
public static final String SHIRT_COLOR = "Shirt Color";
|
||||
|
||||
public static final String[] PROPS = { NAME, MALE, AGE, SHIRT_COLOR };
|
||||
|
||||
// The data model
|
||||
private java.util.List people;
|
||||
|
||||
/**
|
||||
* Constructs a PersonEditor
|
||||
*/
|
||||
public PersonEditor() {
|
||||
super(null);
|
||||
people = new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the application
|
||||
*/
|
||||
public void run() {
|
||||
// Don't return from open() until window closes
|
||||
setBlockOnOpen(true);
|
||||
|
||||
// Open the main window
|
||||
open();
|
||||
|
||||
// Dispose the display
|
||||
Display.getCurrent().dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the shell
|
||||
*
|
||||
* @param shell
|
||||
* the shell
|
||||
*/
|
||||
protected void configureShell(Shell shell) {
|
||||
super.configureShell(shell);
|
||||
shell.setText("Person Editor");
|
||||
shell.setSize(400, 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the main window's contents
|
||||
*
|
||||
* @param parent
|
||||
* the main window
|
||||
* @return Control
|
||||
*/
|
||||
protected Control createContents(Composite parent) {
|
||||
Composite composite = new Composite(parent, SWT.NONE);
|
||||
composite.setLayout(new GridLayout(1, false));
|
||||
|
||||
// Add a button to create the new person
|
||||
Button newPerson = new Button(composite, SWT.PUSH);
|
||||
newPerson.setText("Create New Person");
|
||||
|
||||
// Add the TableViewer
|
||||
final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION);
|
||||
tv.setContentProvider(new PersonContentProvider());
|
||||
tv.setLabelProvider(new PersonLabelProvider());
|
||||
tv.setInput(people);
|
||||
|
||||
// Set up the table
|
||||
Table table = tv.getTable();
|
||||
table.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
|
||||
new TableColumn(table, SWT.CENTER).setText(NAME);
|
||||
new TableColumn(table, SWT.CENTER).setText(MALE);
|
||||
new TableColumn(table, SWT.CENTER).setText(AGE);
|
||||
new TableColumn(table, SWT.CENTER).setText(SHIRT_COLOR);
|
||||
|
||||
for (int i = 0, n = table.getColumnCount(); i < n; i++) {
|
||||
table.getColumn(i).pack();
|
||||
}
|
||||
|
||||
table.setHeaderVisible(true);
|
||||
table.setLinesVisible(true);
|
||||
|
||||
// Add a new person when the user clicks button
|
||||
newPerson.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
Person p = new Person();
|
||||
p.setName("Name");
|
||||
p.setMale(true);
|
||||
p.setAgeRange(Integer.valueOf("0"));
|
||||
p.setShirtColor(new RGB(255, 0, 0));
|
||||
people.add(p);
|
||||
tv.refresh();
|
||||
}
|
||||
});
|
||||
|
||||
// Create the cell editors
|
||||
CellEditor[] editors = new CellEditor[4];
|
||||
editors[0] = new TextCellEditor(table);
|
||||
editors[1] = new CheckboxCellEditor(table);
|
||||
editors[2] = new ComboBoxCellEditor(table, AgeRange.INSTANCES,
|
||||
SWT.READ_ONLY);
|
||||
editors[3] = new ColorCellEditor(table);
|
||||
|
||||
// Set the editors, cell modifier, and column properties
|
||||
tv.setColumnProperties(PROPS);
|
||||
tv.setCellModifier(new PersonCellModifier(tv));
|
||||
tv.setCellEditors(editors);
|
||||
|
||||
return composite;
|
||||
}
|
||||
|
||||
/**
|
||||
* The application entry point
|
||||
*
|
||||
* @param args
|
||||
* the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
new PersonEditor().run();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class provides the content for the person table
|
||||
*/
|
||||
|
||||
class PersonContentProvider implements IStructuredContentProvider {
|
||||
/**
|
||||
* Returns the Person objects
|
||||
*/
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return ((List) inputElement).toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposes any created resources
|
||||
*/
|
||||
public void dispose() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the input changes
|
||||
*/
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class provides the content for the FoodList application
|
||||
*/
|
||||
|
||||
class FoodContentProvider implements IStructuredContentProvider {
|
||||
/**
|
||||
* Gets the food items for the list
|
||||
*
|
||||
* @param arg0
|
||||
* the data model
|
||||
* @return Object[]
|
||||
*/
|
||||
public Object[] getElements(Object arg0) {
|
||||
return ((GroceryList) arg0).getFoods().toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposes any created resources
|
||||
*/
|
||||
public void dispose() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the input changes
|
||||
*
|
||||
* @param arg0
|
||||
* the viewer
|
||||
* @param arg1
|
||||
* the old input
|
||||
* @param arg2
|
||||
* the new input
|
||||
*/
|
||||
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class represents the cell modifier for the PersonEditor program
|
||||
*/
|
||||
|
||||
class PersonCellModifier implements ICellModifier {
|
||||
private Viewer viewer;
|
||||
|
||||
public PersonCellModifier(Viewer viewer) {
|
||||
this.viewer = viewer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the property can be modified
|
||||
*
|
||||
* @param element
|
||||
* the element
|
||||
* @param property
|
||||
* the property
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean canModify(Object element, String property) {
|
||||
// Allow editing of all values
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for the property
|
||||
*
|
||||
* @param element
|
||||
* the element
|
||||
* @param property
|
||||
* the property
|
||||
* @return Object
|
||||
*/
|
||||
public Object getValue(Object element, String property) {
|
||||
Person p = (Person) element;
|
||||
if (PersonEditor.NAME.equals(property))
|
||||
return p.getName();
|
||||
else if (PersonEditor.MALE.equals(property))
|
||||
return Boolean.valueOf(p.isMale());
|
||||
else if (PersonEditor.AGE.equals(property))
|
||||
return p.getAgeRange();
|
||||
else if (PersonEditor.SHIRT_COLOR.equals(property))
|
||||
return p.getShirtColor();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies the element
|
||||
*
|
||||
* @param element
|
||||
* the element
|
||||
* @param property
|
||||
* the property
|
||||
* @param value
|
||||
* the value
|
||||
*/
|
||||
public void modify(Object element, String property, Object value) {
|
||||
if (element instanceof Item)
|
||||
element = ((Item) element).getData();
|
||||
|
||||
Person p = (Person) element;
|
||||
if (PersonEditor.NAME.equals(property))
|
||||
p.setName((String) value);
|
||||
else if (PersonEditor.MALE.equals(property))
|
||||
p.setMale(((Boolean) value).booleanValue());
|
||||
else if (PersonEditor.AGE.equals(property))
|
||||
p.setAgeRange((Integer) value);
|
||||
else if (PersonEditor.SHIRT_COLOR.equals(property))
|
||||
p.setShirtColor((RGB) value);
|
||||
|
||||
// Force the viewer to refresh
|
||||
viewer.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class represents a person
|
||||
*/
|
||||
|
||||
class Person {
|
||||
private String name;
|
||||
|
||||
private boolean male;
|
||||
|
||||
private Integer ageRange;
|
||||
|
||||
private RGB shirtColor;
|
||||
|
||||
/**
|
||||
* @return Returns the ageRange.
|
||||
*/
|
||||
public Integer getAgeRange() {
|
||||
return ageRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ageRange
|
||||
* The ageRange to set.
|
||||
*/
|
||||
public void setAgeRange(Integer ageRange) {
|
||||
this.ageRange = ageRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the male.
|
||||
*/
|
||||
public boolean isMale() {
|
||||
return male;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param male
|
||||
* The male to set.
|
||||
*/
|
||||
public void setMale(boolean male) {
|
||||
this.male = male;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* The name to set.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the shirtColor.
|
||||
*/
|
||||
public RGB getShirtColor() {
|
||||
return shirtColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param shirtColor
|
||||
* The shirtColor to set.
|
||||
*/
|
||||
public void setShirtColor(RGB shirtColor) {
|
||||
this.shirtColor = shirtColor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class contains all the foods on the "grocery list"
|
||||
*/
|
||||
|
||||
class GroceryList {
|
||||
// Holds the foods
|
||||
private List foods;
|
||||
|
||||
/**
|
||||
* Constructs a grocery list
|
||||
*/
|
||||
public GroceryList() {
|
||||
foods = new ArrayList();
|
||||
|
||||
// Add some foods
|
||||
foods.add(new Food("Broccoli", true));
|
||||
foods.add(new Food("Bundt Cake", false));
|
||||
foods.add(new Food("Cabbage", true));
|
||||
foods.add(new Food("Candy Canes", false));
|
||||
foods.add(new Food("Eggs", true));
|
||||
foods.add(new Food("Potato Chips", false));
|
||||
foods.add(new Food("Milk", true));
|
||||
foods.add(new Food("Soda", false));
|
||||
foods.add(new Food("Chicken", true));
|
||||
foods.add(new Food("Cinnamon Rolls", false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the foods in this grocery list
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
public List getFoods() {
|
||||
return Collections.unmodifiableList(foods);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class represents a type of food
|
||||
*/
|
||||
|
||||
class Food {
|
||||
// The name of the food
|
||||
private String name;
|
||||
|
||||
// Is it healthy?
|
||||
private boolean healthy;
|
||||
|
||||
/**
|
||||
* Food constructor
|
||||
*
|
||||
* @param name
|
||||
* the name
|
||||
* @param healthy
|
||||
* whether or not it's healthy
|
||||
*/
|
||||
public Food(String name, boolean healthy) {
|
||||
this.name = name;
|
||||
this.healthy = healthy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this is healthy
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isHealthy() {
|
||||
return healthy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class provides the labels for the person table
|
||||
*/
|
||||
|
||||
class PersonLabelProvider implements ITableLabelProvider {
|
||||
/**
|
||||
* Returns the image
|
||||
*
|
||||
* @param element
|
||||
* the element
|
||||
* @param columnIndex
|
||||
* the column index
|
||||
* @return Image
|
||||
*/
|
||||
public Image getColumnImage(Object element, int columnIndex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the column text
|
||||
*
|
||||
* @param element
|
||||
* the element
|
||||
* @param columnIndex
|
||||
* the column index
|
||||
* @return String
|
||||
*/
|
||||
public String getColumnText(Object element, int columnIndex) {
|
||||
Person person = (Person) element;
|
||||
switch (columnIndex) {
|
||||
case 0:
|
||||
return person.getName();
|
||||
case 1:
|
||||
return Boolean.toString(person.isMale());
|
||||
case 2:
|
||||
return AgeRange.INSTANCES[person.getAgeRange().intValue()];
|
||||
case 3:
|
||||
return person.getShirtColor().toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener
|
||||
*
|
||||
* @param listener
|
||||
* the listener
|
||||
*/
|
||||
public void addListener(ILabelProviderListener listener) {
|
||||
// Ignore it
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposes any created resources
|
||||
*/
|
||||
public void dispose() {
|
||||
// Nothing to dispose
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether altering this property on this element will affect the
|
||||
* label
|
||||
*
|
||||
* @param element
|
||||
* the element
|
||||
* @param property
|
||||
* the property
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isLabelProperty(Object element, String property) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a listener
|
||||
*
|
||||
* @param listener
|
||||
* the listener
|
||||
*/
|
||||
public void removeListener(ILabelProviderListener listener) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This class encapsulates age ranges
|
||||
*/
|
||||
|
||||
class AgeRange {
|
||||
public static final String NONE = "";
|
||||
|
||||
public static final String BABY = "0 - 3";
|
||||
|
||||
public static final String TODDLER = "4 - 7";
|
||||
|
||||
public static final String CHILD = "8 - 12";
|
||||
|
||||
public static final String TEENAGER = "13 - 19";
|
||||
|
||||
public static final String ADULT = "20 - ?";
|
||||
|
||||
public static final String[] INSTANCES = { NONE, BABY, TODDLER, CHILD,
|
||||
TEENAGER, ADULT };
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright 2004-2006 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 net.forwardfire.vasc;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.frontends.swt.SwtVascFrontend;
|
||||
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests a simple x4o xml language.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jul 24, 2006
|
||||
*/
|
||||
public class SWTTest extends TestCase {
|
||||
|
||||
public void setUp() throws Exception {
|
||||
// enable all logs
|
||||
//InputStream loggingProperties = this.getClass().getResourceAsStream("/META-INF/logging.properties");
|
||||
//LogManager.getLogManager().readConfiguration( loggingProperties );
|
||||
//loggingProperties.close();
|
||||
|
||||
// load xtes queries
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
public void testNull() throws Exception {
|
||||
assertEquals(true, true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new SWTTest().doSWT();
|
||||
}
|
||||
|
||||
public void doSWT() throws Exception {
|
||||
|
||||
// get GUI
|
||||
Display display = new Display();
|
||||
Shell shell = new Shell(display);
|
||||
shell.setText("Vasc Test - Swt");
|
||||
|
||||
// define redering and render
|
||||
SwtVascFrontend render = new SwtVascFrontend(shell);
|
||||
|
||||
|
||||
VascEntry entry = TestTable.getVascTable();
|
||||
entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry);
|
||||
render.initEntry(entry);
|
||||
render.renderView();
|
||||
|
||||
// view
|
||||
shell.open();
|
||||
// Set up the event loop.
|
||||
while (!shell.isDisposed()) {
|
||||
if (!display.readAndDispatch()) {
|
||||
// If no more entries in event queue
|
||||
display.sleep();
|
||||
}
|
||||
}
|
||||
display.dispose();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,172 @@
|
|||
|
||||
/*
|
||||
* Copyright 2004-2006 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 net.forwardfire.vasc;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import net.forwardfire.vasc.annotations.VascDefaultValue;
|
||||
import net.forwardfire.vasc.annotations.VascEntry;
|
||||
import net.forwardfire.vasc.annotations.VascI18n;
|
||||
import net.forwardfire.vasc.annotations.VascModelReference;
|
||||
import net.forwardfire.vasc.annotations.VascStyle;
|
||||
import net.forwardfire.vasc.validators.VascDateFuture;
|
||||
import net.forwardfire.vasc.validators.VascObjectNotNull;
|
||||
import net.forwardfire.vasc.validators.VascStringLength;
|
||||
|
||||
|
||||
//import org.hibernate.validator.NotNull;
|
||||
//import org.hibernate.validator.Max;
|
||||
|
||||
|
||||
/**
|
||||
* TestModel
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 28, 2007
|
||||
*/
|
||||
@VascEntry(headerName="En een tooltip op het model")
|
||||
public class TestModel {
|
||||
|
||||
private String name = null;
|
||||
private String description = null;
|
||||
private Float price = null;
|
||||
private Boolean active = null;
|
||||
private Date date = null;
|
||||
private TestModel testModel = null;
|
||||
private String hexColor = null;
|
||||
//private Node nonEditorField = null;
|
||||
|
||||
/**
|
||||
* @return the date
|
||||
*/
|
||||
@VascDateFuture
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param date the date to set
|
||||
*/
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
@VascI18n( name="omscheiving",
|
||||
description="De omscrijving",
|
||||
image="/resources/images/gabelfresser.gif",
|
||||
helpId="help.id")
|
||||
@VascDefaultValue(value="xxxxx")
|
||||
@VascStyle(sizeList=200)
|
||||
// @NotNull
|
||||
// @Max(value=10)
|
||||
@VascObjectNotNull
|
||||
@VascStringLength(max=10)
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the price
|
||||
*/
|
||||
public Float getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param price the price to set
|
||||
*/
|
||||
public void setPrice(Float price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
|
||||
// @NotNull
|
||||
@VascObjectNotNull
|
||||
@VascModelReference
|
||||
@VascI18n(image="/resources/images/gabelfresser.gif")
|
||||
public TestModel getTestModel() {
|
||||
return testModel;
|
||||
}
|
||||
|
||||
public void setTestModel(TestModel testModel) {
|
||||
this.testModel = testModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the active
|
||||
*/
|
||||
public Boolean getActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param active the active to set
|
||||
*/
|
||||
public void setActive(Boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the hexColor
|
||||
*/
|
||||
public String getHexColor() {
|
||||
return hexColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hexColor the hexColor to set
|
||||
*/
|
||||
public void setHexColor(String hexColor) {
|
||||
this.hexColor = hexColor;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import net.forwardfire.vasc.core.AbstractVascBackend;
|
||||
import net.forwardfire.vasc.core.VascBackendState;
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
|
||||
import net.forwardfire.vasc.core.ui.VascSelectItem;
|
||||
import net.forwardfire.vasc.core.ui.VascSelectItemModel;
|
||||
import net.forwardfire.vasc.impl.entry.BeanPropertyVascEntryFieldValue;
|
||||
import net.forwardfire.vasc.impl.entry.BeanVascEntryRecordCreator;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 21, 2007
|
||||
*/
|
||||
public class TestModelVascDataSource extends AbstractVascBackend implements VascSelectItemModel {
|
||||
|
||||
private List<Object> testModels = null;
|
||||
private String nullLabel = null;
|
||||
private String nullKeyValue = null;
|
||||
|
||||
public TestModelVascDataSource() {
|
||||
testModels = new ArrayList<Object>(2);
|
||||
|
||||
TestModel t = new TestModel();
|
||||
t.setDate(new Date());
|
||||
t.setDescription("yoyo test");
|
||||
t.setName("this Name");
|
||||
t.setPrice(34.1f);
|
||||
t.setActive(true);
|
||||
t.setHexColor("#FF66EE");
|
||||
testModels.add(t);
|
||||
|
||||
t = new TestModel();
|
||||
t.setDate(new Date());
|
||||
t.setDescription("Model2 test");
|
||||
t.setName("BeanSourde");
|
||||
t.setPrice(19.2f);
|
||||
t.setActive(false);
|
||||
t.setTestModel((TestModel)testModels.get(0));
|
||||
testModels.add(t);
|
||||
}
|
||||
public TestModelVascDataSource(List<Object> testModels) {
|
||||
this.testModels=testModels;
|
||||
}
|
||||
|
||||
public List<Object> execute(VascBackendState state) throws VascException {
|
||||
return testModels;
|
||||
}
|
||||
|
||||
public void persist(Object object) throws VascException {
|
||||
testModels.add(object);
|
||||
}
|
||||
|
||||
public Object merge(Object object) throws VascException {
|
||||
if(testModels.contains(object)==false) {
|
||||
testModels.add(object);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
public void delete(Object object) throws VascException {
|
||||
testModels.remove(object);
|
||||
}
|
||||
|
||||
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
|
||||
return new BeanPropertyVascEntryFieldValue(field.getBackendName());
|
||||
}
|
||||
|
||||
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
|
||||
return new BeanVascEntryRecordCreator(TestModel.class);
|
||||
}
|
||||
|
||||
// --- VascSelectItemModel interface
|
||||
|
||||
public List<VascSelectItem> getVascSelectItems(VascEntry entry) {
|
||||
List<VascSelectItem> res = new ArrayList<VascSelectItem>(4);
|
||||
for (Object o:testModels) {
|
||||
TestModel t = (TestModel)o;
|
||||
VascSelectItem i = new VascSelectItem(t.getName(),t);
|
||||
res.add(i);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the nullLabel
|
||||
*/
|
||||
public String getNullLabel() {
|
||||
return nullLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nullLabel the nullLabel to set
|
||||
*/
|
||||
public void setNullLabel(String nullLabel) {
|
||||
this.nullLabel = nullLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the nullKeyValue
|
||||
*/
|
||||
public String getNullKeyValue() {
|
||||
return nullKeyValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nullKeyValue the nullKeyValue to set
|
||||
*/
|
||||
public void setNullKeyValue(String nullKeyValue) {
|
||||
this.nullKeyValue = nullKeyValue;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* Copyright 2004-2006 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 net.forwardfire.vasc;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.forwardfire.vasc.core.VascBackend;
|
||||
import net.forwardfire.vasc.core.VascBackendControllerLocal;
|
||||
import net.forwardfire.vasc.core.VascController;
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.VascFrontendData;
|
||||
import net.forwardfire.vasc.impl.DefaultVascBackedEntryFinalizer;
|
||||
import net.forwardfire.vasc.impl.DefaultVascFactory;
|
||||
import net.forwardfire.vasc.impl.DefaultVascFrontendData;
|
||||
import net.forwardfire.vasc.impl.DefaultVascFrontendHelper;
|
||||
import net.forwardfire.vasc.impl.VascBackendProxyPaged;
|
||||
import net.forwardfire.vasc.impl.VascBackendProxySearch;
|
||||
import net.forwardfire.vasc.impl.VascBackendProxySort;
|
||||
import net.forwardfire.vasc.impl.actions.AddRowAction;
|
||||
import net.forwardfire.vasc.impl.actions.CSVExportGlobalAction;
|
||||
import net.forwardfire.vasc.impl.actions.DeleteRowAction;
|
||||
import net.forwardfire.vasc.impl.actions.EditRowAction;
|
||||
import net.forwardfire.vasc.impl.actions.RefreshDataGlobalAction;
|
||||
import net.forwardfire.vasc.impl.actions.XMLExportGlobalAction;
|
||||
import net.forwardfire.vasc.impl.x4o.VascParser;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 2, 2007
|
||||
*/
|
||||
public class TestTable {
|
||||
|
||||
static VascController getDefaultVascController() throws Exception {
|
||||
VascController c = DefaultVascFactory.getDefaultVascController(2288L,"idca.nl","user","admin");
|
||||
|
||||
// for test
|
||||
TestModelVascDataSource backend = new TestModelVascDataSource();
|
||||
backend.setId("testBackend1");
|
||||
((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(backend);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
static public void fill(VascEntry entry,VascController vascController) {
|
||||
|
||||
|
||||
VascFrontendData frontendData = DefaultVascFactory.getDefaultVascFrontendData("i18n.vasc", Locale.getDefault());
|
||||
frontendData.setVascController(vascController);
|
||||
entry.setVascFrontendData(frontendData);
|
||||
VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry);
|
||||
frontendData.getVascEntryState().setVascBackend(backend);
|
||||
frontendData.getVascEntryState().setVascEntry(entry);
|
||||
|
||||
|
||||
entry.addRowAction(new AddRowAction());
|
||||
entry.addRowAction(new EditRowAction());
|
||||
entry.addRowAction(new DeleteRowAction());
|
||||
|
||||
entry.addGlobalAction(new XMLExportGlobalAction());
|
||||
entry.addGlobalAction(new CSVExportGlobalAction());
|
||||
entry.addGlobalAction(new RefreshDataGlobalAction());
|
||||
|
||||
// hackje om deze manuale actions van i18n keys te voorzien;
|
||||
// this is temp untill x4o templaing
|
||||
DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer();
|
||||
try {
|
||||
f.finalizeVascEntry(entry, vascController);
|
||||
} catch (VascException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static public VascEntry getVascTable() throws Exception {
|
||||
|
||||
VascController c = getDefaultVascController();
|
||||
|
||||
VascParser parser = new VascParser(c);
|
||||
File f = File.createTempFile("test-vasc", ".xml");
|
||||
parser.setDebugOutputStream(new FileOutputStream(f));
|
||||
parser.parseResource("vasc/tables.xml");
|
||||
|
||||
VascEntry entry = parser.getVascController().getVascEntryController().getVascEntryById("test1");
|
||||
fill(entry,c);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
static void printEntry(VascEntry e) throws Exception {
|
||||
|
||||
System.out.println("");
|
||||
System.out.println("=== Printing entry ===");
|
||||
System.out.println("");
|
||||
|
||||
for (Method m:e.getClass().getMethods()) {
|
||||
if (m.getName().startsWith("get")==false) { //a bit dirty
|
||||
continue;
|
||||
}
|
||||
if (m.getParameterTypes().length>0) {
|
||||
continue;
|
||||
}
|
||||
System.out.println("prop: "+m.getName()+" -> "+m.invoke(e));
|
||||
}
|
||||
|
||||
System.out.println("");
|
||||
System.out.println("=== Fields ===");
|
||||
for (VascEntryField vef:e.getVascEntryFields()) {
|
||||
|
||||
System.out.println("=== Field: "+vef.getId());
|
||||
|
||||
for (Method m:vef.getClass().getMethods()) {
|
||||
if (m.getName().startsWith("get")==false) { //a bit dirty
|
||||
continue;
|
||||
}
|
||||
if (m.getParameterTypes().length>0) {
|
||||
continue;
|
||||
}
|
||||
System.out.println("prop: "+m.getName()+" -> "+m.invoke(vef));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue