Home » Eclipse Projects » WindowBuilder » WB Bindings Not Working Properly(After updating to WB 1.1.0 ... and SWT Designer 1.1.0 ...)
| |
Re: WB Bindings Not Working Properly [message #735445 is a reply to message #735083] |
Tue, 11 October 2011 20:23 |
Eric Messages: 3 Registered: February 2010 |
Junior Member |
|
|
Hi Eric,
Thank you for your response.
Quote:Did the code for your app change? If so, what exactly changed?
Nothing changed, I just upgraded and recompiled.
Quote:Did you change your Eclipse version at all?
Same version.
Here is my code:
Database access through Annotations and Hibernate (Its own plugin)
package edu.unmc.cns.condb.model.hibernate.db;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import edu.unmc.cns.condb.model.AbstractModelObject;
/**
* AbstractDistributionType entity provides the base persistence definition of
* the DistributionType entity.
* @author eric
*/
@MappedSuperclass
public abstract class AbstractDistributionType extends AbstractModelObject implements java.io.Serializable {
// Fields
private Integer distributionTypeID;
private String distributionType;
private String description;
// Constructors
/** default constructor */
public AbstractDistributionType() {
}
/** minimal constructor */
public AbstractDistributionType(String distributionType) {
this.distributionType = distributionType;
}
// Property accessors
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "distributiontype_id", unique = true, nullable = false, updatable = false)
public Integer getDistributionTypeID() {
return this.distributionTypeID;
}
public void setDistributionTypeID(Integer distributionTypeID) {
this.distributionTypeID = distributionTypeID;
}
@Column(name = "distributiontype", unique = true, nullable = false, length = 50, updatable = false)
public String getDistributionType() {
return this.distributionType;
}
public void setDistributionType(String distributionType) {
this.distributionType = distributionType;
}
@Column(name = "description", length = 50, updatable = false)
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString(){
return this.distributionType;
}
}
package edu.unmc.cns.condb.model.hibernate.db;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* DistributionType entity.
* @author eric
*/
@Entity
@Table(name = "tbldistributiontypes", schema = "public")
public class DistributionType extends AbstractDistributionType implements java.io.Serializable {
// Constructors
/** default constructor */
public DistributionType() {
}
/** minimal constructor */
public DistributionType(String distributionType) {
super(distributionType);
}
}
Distribution Plugin...
Model for the bindings.
package edu.unmc.cns.mcnp.distribution.model;
import java.util.ArrayList;
import java.util.List;
import edu.unmc.cns.condb.model.hibernate.db.DistributionType;
/**
* @author eric
*
*/
public class DistributionTypes extends AbstractModelObject {
private List<DistributionType> distributionTypes = new ArrayList<DistributionType>();
/**
*
*/
public DistributionTypes() {
// TODO Auto-generated constructor stub
}
/**
* @return the distributionTypes
*/
public List<DistributionType> getDistributionTypes() {
return distributionTypes;
}
/**
* @param distributionTypes
* the distributionTypes to set
*/
public void setDistributionTypes(List<DistributionType> distributionTypes) {
this.distributionTypes = distributionTypes;
firePropertyChange("distributionTypes", null, distributionTypes);
}
public void addDistributionType(DistributionType dtype) {
this.distributionTypes.add(dtype);
firePropertyChange("distributionTypes", null, distributionTypes);
}
public void removeDistributionType(DistributionType dtype) {
this.distributionTypes.remove(dtype);
firePropertyChange("distributionTypes", null, distributionTypes);
}
}
package edu.unmc.cns.mcnp.distribution.model;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
/**
* @author eric
*
*/
public class AbstractModelObject {
private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
public void addPropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.addPropertyChangeListener(listener);
}
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.removePropertyChangeListener(listener);
}
public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
}
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
}
The view part and a controller.
package edu.unmc.cns.mcnp.distribution.view;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
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.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
import com.swtdesigner.SWTResourceManager;
import edu.unmc.cns.mcnp.distribution.view.controller.DistributionTypeViewController;
public class DistributionTypeView extends ViewPart {
public static final String ID = "edu.unmc.cns.mcnp.distribution.view.DistributionTypeView_ID"; //$NON-NLS-1$
private Group grpDistributionTypeList;
private Label lblManageDistributionType;
private Table tbldistrotype;
private TableViewer tableViewer;
private TableColumn tblclmnId;
private TableViewerColumn tableViewerColumn;
private TableColumn tblclmnType;
private TableViewerColumn tableViewerColumn_1;
private TableColumn tblclmnDescription;
private TableViewerColumn tableViewerColumn_2;
private TableColumn tblclmnLastUpdated;
private TableViewerColumn tableViewerColumn_3;
private Group grpEditDistributionType;
private Label lblDistributionType;
private Text txtDistributiontype;
private Label lblDescription;
private Text txtDescription;
private Composite composite;
private Label label;
private Label label_1;
private Button btnSave;
private Label label_2;
private Button btnClear;
private boolean newrecord = true;
private DistributionTypeViewController m_controller;
public DistributionTypeView() {
}
/**
* Create contents of the view part.
*
* @param parent
*/
@Override
public void createPartControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new FormLayout());
this.grpDistributionTypeList = new Group(container, SWT.NONE);
this.grpDistributionTypeList.setText("Distribution Type List");
this.grpDistributionTypeList.setLayout(new GridLayout(1, false));
FormData fd_grpDistributionTypeList = new FormData();
fd_grpDistributionTypeList.bottom = new FormAttachment(50);
fd_grpDistributionTypeList.right = new FormAttachment(100, -10);
fd_grpDistributionTypeList.top = new FormAttachment(0, 10);
fd_grpDistributionTypeList.left = new FormAttachment(0, 10);
this.grpDistributionTypeList.setLayoutData(fd_grpDistributionTypeList);
this.lblManageDistributionType = new Label(this.grpDistributionTypeList, SWT.NONE);
this.lblManageDistributionType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
this.lblManageDistributionType.setText("Manage Distribution Type");
this.lblManageDistributionType.setFont(SWTResourceManager.getFont("Tahoma", 12, SWT.BOLD));
tableViewer = new TableViewer(this.grpDistributionTypeList, SWT.BORDER | SWT.FULL_SELECTION);
this.tbldistrotype = tableViewer.getTable();
this.tbldistrotype.setLinesVisible(true);
this.tbldistrotype.setHeaderVisible(true);
this.tbldistrotype.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
tableViewerColumn = new TableViewerColumn(this.tableViewer, SWT.NONE);
this.tblclmnId = tableViewerColumn.getColumn();
this.tblclmnId.setWidth(50);
this.tblclmnId.setText("ID");
tableViewerColumn_1 = new TableViewerColumn(this.tableViewer, SWT.NONE);
this.tblclmnType = tableViewerColumn_1.getColumn();
this.tblclmnType.setWidth(150);
this.tblclmnType.setText("Type");
tableViewerColumn_2 = new TableViewerColumn(this.tableViewer, SWT.NONE);
this.tblclmnDescription = tableViewerColumn_2.getColumn();
this.tblclmnDescription.setWidth(200);
this.tblclmnDescription.setText("Description");
tableViewerColumn_3 = new TableViewerColumn(this.tableViewer, SWT.NONE);
this.tblclmnLastUpdated = tableViewerColumn_3.getColumn();
this.tblclmnLastUpdated.setWidth(100);
this.tblclmnLastUpdated.setText("Last Updated");
this.grpEditDistributionType = new Group(container, SWT.NONE);
this.grpEditDistributionType.setText("Edit Distribution Type");
this.grpEditDistributionType.setLayout(new GridLayout(2, false));
FormData fd_grpEditDistributionType = new FormData();
fd_grpEditDistributionType.bottom = new FormAttachment(100, -10);
fd_grpEditDistributionType.right = new FormAttachment(this.grpDistributionTypeList, 0, SWT.RIGHT);
fd_grpEditDistributionType.top = new FormAttachment(this.grpDistributionTypeList, 5);
fd_grpEditDistributionType.left = new FormAttachment(this.grpDistributionTypeList, 0, SWT.LEFT);
this.grpEditDistributionType.setLayoutData(fd_grpEditDistributionType);
this.lblDistributionType = new Label(this.grpEditDistributionType, SWT.NONE);
this.lblDistributionType.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
this.lblDistributionType.setText("Distribution Type");
this.txtDistributiontype = new Text(this.grpEditDistributionType, SWT.BORDER);
this.txtDistributiontype.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
this.lblDescription = new Label(this.grpEditDistributionType, SWT.NONE);
this.lblDescription.setText("Description");
this.txtDescription = new Text(this.grpEditDistributionType, SWT.BORDER);
this.txtDescription.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(this.grpEditDistributionType, SWT.NONE);
new Label(this.grpEditDistributionType, SWT.NONE);
new Label(this.grpEditDistributionType, SWT.NONE);
this.composite = new Composite(this.grpEditDistributionType, SWT.NONE);
this.composite.setLayout(new FillLayout(SWT.HORIZONTAL));
GridData gd_composite = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_composite.heightHint = 32;
this.composite.setLayoutData(gd_composite);
this.label = new Label(this.composite, SWT.NONE);
this.label_1 = new Label(this.composite, SWT.NONE);
this.btnSave = new Button(this.composite, SWT.NONE);
this.btnSave.setText("Save");
this.btnSave.setEnabled(false);
this.label_2 = new Label(this.composite, SWT.NONE);
this.btnClear = new Button(this.composite, SWT.NONE);
this.btnClear.setText("Clear");
m_controller = new DistributionTypeViewController(this);
createActions();
initializeToolBar();
initializeMenu();
}
/**
* Create the actions.
*/
private void createActions() {
// Create the actions
}
/**
* Initialize the toolbar.
*/
private void initializeToolBar() {
IToolBarManager toolbarManager = getViewSite().getActionBars().getToolBarManager();
}
/**
* Initialize the menu.
*/
private void initializeMenu() {
IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
}
@Override
public void setFocus() {
// Set the focus
}
public TableViewer getTableViewer() {
return tableViewer;
}
public Text getTxtDistributiontype() {
return txtDistributiontype;
}
public Text getTxtDescription() {
return txtDescription;
}
}
package edu.unmc.cns.mcnp.distribution.view.controller;
import java.util.List;
import edu.unmc.cns.condb.model.hibernate.db.DistributionType;
import edu.unmc.cns.condb.model.hibernate.db.dao.DistributionTypeDAO;
import edu.unmc.cns.mcnp.distribution.model.DistributionTypes;
import edu.unmc.cns.mcnp.distribution.view.DistributionTypeView;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.SWT;
/**
* @author eric
*
*/
public class DistributionTypeViewController {
private DataBindingContext m_bindingContext;
private DistributionTypeView m_distributionTypeView = null;
private DistributionType m_distributionType = new DistributionType();
private DistributionTypes m_distributiontypes = new DistributionTypes();
/**
*
*/
public DistributionTypeViewController(DistributionTypeView m_distributionTypeView) {
this.m_distributionTypeView = m_distributionTypeView;
initializeData();
m_bindingContext = initDataBindings();
}
private void initializeData() {
DistributionTypeDAO dao = new DistributionTypeDAO();
List<DistributionType> types = dao.findAll();
for (DistributionType dtype : types) {
this.m_distributiontypes.addDistributionType(dtype);
}
}
/**
* @param m_distributionTypeView
* the m_distributionTypeView to set
*/
public void setM_distributionTypeView(DistributionTypeView m_distributionTypeView) {
this.m_distributionTypeView = m_distributionTypeView;
}
/**
* @return the m_distributionTypeView
*/
public DistributionTypeView getM_distributionTypeView() {
return m_distributionTypeView;
}
/**
* @param m_distributiontypes
* the m_distributiontypes to set
*/
public void setM_distributiontypes(DistributionTypes m_distributiontypes) {
this.m_distributiontypes = m_distributiontypes;
}
/**
* @return the m_distributiontypes
*/
public DistributionTypes getM_distributiontypes() {
return m_distributiontypes;
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
ObservableListContentProvider listContentProvider = new ObservableListContentProvider();
m_distributionTypeView.getTableViewer().setContentProvider(listContentProvider);
//
IObservableMap[] observeMaps = BeansObservables.observeMaps(listContentProvider.getKnownElements(), DistributionType.class, new String[]{"distributionTypeID", "distributionType", "description", "ctlUpdDTTM"});
m_distributionTypeView.getTableViewer().setLabelProvider(new ObservableMapLabelProvider(observeMaps));
//
IObservableList distributiontypesDistributionTypesObserveList = BeansObservables.observeList(Realm.getDefault(), m_distributiontypes, "distributionTypes");
m_distributionTypeView.getTableViewer().setInput(distributiontypesDistributionTypesObserveList);
//
IObservableValue distributionTypeViewgetTxtDistributiontypeObserveTextObserveWidget = SWTObservables.observeText(m_distributionTypeView.getTxtDistributiontype(), SWT.Modify);
IObservableValue distributionTypeViewgetTableViewerObserveSingleSelection = ViewersObservables.observeSingleSelection(m_distributionTypeView.getTableViewer());
IObservableValue distributionTypeViewgetTableViewerDistributionTypeObserveDetailValue = BeansObservables.observeDetailValue(distributionTypeViewgetTableViewerObserveSingleSelection, DistributionType.class, "distributionType", String.class);
bindingContext.bindValue(distributionTypeViewgetTxtDistributiontypeObserveTextObserveWidget, distributionTypeViewgetTableViewerDistributionTypeObserveDetailValue, null, null);
//
IObservableValue distributionTypeViewgetTxtDescriptionObserveTextObserveWidget = SWTObservables.observeText(m_distributionTypeView.getTxtDescription(), SWT.Modify);
IObservableValue distributionTypeViewgetTableViewerObserveSingleSelection_1 = ViewersObservables.observeSingleSelection(m_distributionTypeView.getTableViewer());
IObservableValue distributionTypeViewgetTableViewerDescriptionObserveDetailValue = BeansObservables.observeDetailValue(distributionTypeViewgetTableViewerObserveSingleSelection_1, DistributionType.class, "description", String.class);
bindingContext.bindValue(distributionTypeViewgetTxtDescriptionObserveTextObserveWidget, distributionTypeViewgetTableViewerDescriptionObserveDetailValue, null, null);
//
return bindingContext;
}
}
Like I stated before, this has been working for the last six months. There has been no changes to the code nor we have updated the Eclipse version.
Hope this help.
Thanks again for your help.
eric
|
|
| | | |
Goto Forum:
Current Time: Fri Apr 26 14:14:36 GMT 2024
Powered by FUDForum. Page generated in 0.03604 seconds
|