Home » Eclipse Projects » Eclipse Platform » databinding for treeviewer with multi treeColumn
| | | | |
Re: databinding for treeviewer with multi treeColumn [message #328557 is a reply to message #328524] |
Tue, 27 May 2008 16:34 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Hao Missing name![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=d95776%40yahoo.com) Messages: 115 Registered: July 2009 |
Senior Member |
|
|
I tried your Label Provider and still got the same error.
org.eclipse.core.databinding - 4 - cannot get value
java.lang.IllegalArgumentException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:64)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at
org.eclipse.core.internal.databinding.beans.JavaBeanObservab leMap.doGet(JavaBeanObservableMap.java:105)
at
org.eclipse.core.databinding.observable.map.ComputedObservab leMap$1.handleSetChange(ComputedObservableMap.java:52)
at
org.eclipse.core.databinding.observable.set.SetChangeEvent.d ispatch(SetChangeEvent.java:61)
at
org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:129)
at
org.eclipse.core.databinding.observable.set.ObservableSet.fi reSetChange(ObservableSet.java:67)
at
org.eclipse.core.internal.databinding.observable.Unmodifiabl eObservableSet.access$0(UnmodifiableObservableSet.java:1)
at
org.eclipse.core.internal.databinding.observable.Unmodifiabl eObservableSet$1.handleSetChange(UnmodifiableObservableSet.j ava:30)
at
org.eclipse.core.databinding.observable.set.SetChangeEvent.d ispatch(SetChangeEvent.java:61)
at
org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:129)
at
org.eclipse.core.databinding.observable.set.ObservableSet.fi reSetChange(ObservableSet.java:67)
at
org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableSet.access$1(DetailObservableSet.java:1)
at
org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableSet$1.handleSetChange(DetailObservableSet. java:42)
at
org.eclipse.core.databinding.observable.set.SetChangeEvent.d ispatch(SetChangeEvent.java:61)
at
org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:129)
at
org.eclipse.core.databinding.observable.set.ObservableSet.fi reSetChange(ObservableSet.java:67)
at
org.eclipse.core.databinding.observable.set.WritableSet.add( WritableSet.java:90)
at
org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableSet.add(DetailObservableSet.java:106)
at
org.eclipse.jface.internal.databinding.viewers.ObservableCol lectionTreeContentProvider$TreeNode. <init>(ObservableCollectionTreeContentProvider.java:284)
at
org.eclipse.jface.internal.databinding.viewers.ObservableCol lectionTreeContentProvider.getOrCreateNode(ObservableCollect ionTreeContentProvider.java:181)
at
org.eclipse.jface.internal.databinding.viewers.ObservableCol lectionTreeContentProvider.getChildren(ObservableCollectionT reeContentProvider.java:162)
at
org.eclipse.jface.internal.databinding.viewers.ObservableCol lectionTreeContentProvider.getElements(ObservableCollectionT reeContentProvider.java:158)
at
org.eclipse.jface.databinding.viewers.ObservableListTreeCont entProvider.getElements(ObservableListTreeContentProvider.ja va:155)
at
org.eclipse.jface.viewers.StructuredViewer.getRawChildren(St ructuredViewer.java:937)
at
org.eclipse.jface.viewers.ColumnViewer.getRawChildren(Column Viewer.java:703)
at
org.eclipse.jface.viewers.AbstractTreeViewer.getRawChildren( AbstractTreeViewer.java:1330)
at
org.eclipse.jface.viewers.TreeViewer.getRawChildren(TreeView er.java:385)
at
org.eclipse.jface.viewers.AbstractTreeViewer.getFilteredChil dren(AbstractTreeViewer.java:636)
at
org.eclipse.jface.viewers.AbstractTreeViewer.getSortedChildr en(AbstractTreeViewer.java:602)
at
org.eclipse.jface.viewers.AbstractTreeViewer$1.run(AbstractT reeViewer.java:799)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:67)
at
org.eclipse.jface.viewers.AbstractTreeViewer.createChildren( AbstractTreeViewer.java:776)
at
org.eclipse.jface.viewers.TreeViewer.createChildren(TreeView er.java:634)
at
org.eclipse.jface.viewers.AbstractTreeViewer.internalInitial izeTree(AbstractTreeViewer.java:1490)
at
org.eclipse.jface.viewers.TreeViewer.internalInitializeTree( TreeViewer.java:823)
at
org.eclipse.jface.viewers.AbstractTreeViewer$5.run(AbstractT reeViewer.java:1474)
at
org.eclipse.jface.viewers.StructuredViewer.preservingSelecti on(StructuredViewer.java:1365)
at
org.eclipse.jface.viewers.TreeViewer.preservingSelection(Tre eViewer.java:397)
at
org.eclipse.jface.viewers.StructuredViewer.preservingSelecti on(StructuredViewer.java:1328)
at
org.eclipse.jface.viewers.AbstractTreeViewer.inputChanged(Ab stractTreeViewer.java:1467)
at
org.eclipse.jface.viewers.ContentViewer.setInput(ContentView er.java:251)
at
org.eclipse.jface.viewers.StructuredViewer.setInput(Structur edViewer.java:1603)
at
com.discover.plugin.phonebook.treeviewer.v34.ex.PhoneBookUsi ngTreeViewerEx1.initDataBindings(PhoneBookUsingTreeViewerEx1 .java:600)
at
com.discover.plugin.phonebook.treeviewer.v34.ex.PhoneBookUsi ngTreeViewerEx1.createContents(PhoneBookUsingTreeViewerEx1.j ava:549)
at
com.discover.plugin.phonebook.treeviewer.v34.ex.PhoneBookUsi ngTreeViewerEx1.open(PhoneBookUsingTreeViewerEx1.java:453)
at
com.discover.plugin.phonebook.treeviewer.v34.ex.PhoneBookUsi ngTreeViewerEx1$1.run(PhoneBookUsingTreeViewerEx1.java:439)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:288)
at
com.discover.plugin.phonebook.treeviewer.v34.ex.PhoneBookUsi ngTreeViewerEx1.main(PhoneBookUsingTreeViewerEx1.java:434)
Here are the source code.
package com.discover.plugin.phonebook.treeviewer.v34.ex;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import
org.eclipse.core.databinding.observable.masterdetail.IObserv ableFactory;
import org.eclipse.core.databinding.observable.value.IObservableVal ue;
import
org.eclipse.core.internal.databinding.observable.EmptyObserv ableList;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.databinding.swt.SWTObservables;
import
org.eclipse.jface.databinding.viewers.ObservableListTreeCont entProvider;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import
at.bestsolution.dataforms.util.viewers.GenericObservableMapL abelProvider;
public class PhoneBookUsingTreeViewerEx1 {
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(propertyN ame,
listener);
}
protected void firePropertyChange(String propertyName, Object oldValue,
Object newValue) {
propertyChangeSupport.firePropertyChange(propertyName, oldValue,
newValue);
}
}
class PersonPhone extends AbstractModelObject{
private String m_name = "";
private String m_email = "";
private String m_phone = "";
private String m_mobilePhone1 = "";
private String m_mobilePhone2 = "";
public PersonPhone() {
}
public PersonPhone(String name, String email, String phone, String
phone1,
String phone2) {
m_name = name;
m_email = email;
m_phone = phone;
m_mobilePhone1 = phone1;
m_mobilePhone2 = phone2;
}
public String getName() {
return m_name;
}
public void setName(String name) {
String oldValue = m_name;
m_name = name;
firePropertyChange("name", oldValue, m_name);
}
public String getEmail() {
return m_email;
}
public void setEmail(String email) {
String oldValue = m_email;
m_email = email;
firePropertyChange("email", oldValue, m_email);
}
public String getPhone() {
return m_phone;
}
public void setPhone(String phone) {
String oldValue = m_phone;
m_phone = phone;
firePropertyChange("phone", oldValue, m_phone);
}
public String getMobilePhone1() {
return m_mobilePhone1;
}
public void setMobilePhone1(String phone1) {
String oldValue = m_mobilePhone1;
m_mobilePhone1 = phone1;
firePropertyChange("mobilePhone1", oldValue, m_mobilePhone1);
}
public String getMobilePhone2() {
return m_mobilePhone2;
}
public void setMobilePhone2(String phone2) {
String oldValue = m_mobilePhone2;
m_mobilePhone2 = phone2;
firePropertyChange("mobilePhone2", oldValue, m_mobilePhone2);
}
@Override
public String toString() {
StringBuilder strBuf = new StringBuilder();
strBuf.append("name=");
strBuf.append(m_name);
strBuf.append(";");
strBuf.append("email=");
strBuf.append(m_email);
/**
strBuf.append(";");
strBuf.append("phone=");
strBuf.append(m_phone);
strBuf.append(";");
strBuf.append("mobilePhone1=");
strBuf.append(m_mobilePhone1);
strBuf.append(";");
strBuf.append("mobilePhone2=");
strBuf.append(m_mobilePhone2);
**/
return strBuf.toString();
}
}
class PersonPhoneGroup extends AbstractModelObject{
private final List m_persons = new ArrayList();
private String m_name;
public PersonPhoneGroup() {
}
public PersonPhoneGroup(String name) {
m_name = name;
}
public String getName() {
return m_name;
}
public void setName(String name) {
String oldValue = m_name;
m_name = name;
firePropertyChange("name", oldValue, m_name);
}
public void addPersonPhone(PersonPhone person) {
m_persons.add(person);
firePropertyChange("persons", null, m_persons);
}
public void removePersonPhone(PersonPhone person) {
m_persons.remove(person);
firePropertyChange("persons", null, m_persons);
}
public List getPersons() {
return m_persons;
}
public String getEmail() {
return "";
}
public void setEmail(String email) {
}
public String getPhone() {
return "";
}
public void setPhone(String phone) {
}
public String getMobilePhone1() {
return "";
}
public void setMobilePhone1(String phone1) {
}
public String getMobilePhone2() {
return "";
}
public void setMobilePhone2(String phone2) {
}
@Override
public String toString() {
String RL = System.getProperty("line.separator");
StringBuilder strBuf = new StringBuilder();
strBuf.append("Person Group - ");
strBuf.append(m_name);
strBuf.append(RL);
/**
for(Iterator it= m_persons.iterator(); it.hasNext(); ){
strBuf.append(it.next());
strBuf.append(RL);
}
**/
return strBuf.toString();
}
}
class PersonPhoneGroups extends AbstractModelObject {
private List m_groups;
public PersonPhoneGroups(){
m_groups = new ArrayList();
}
public void addGroup(PersonPhoneGroup group) {
m_groups.add(group);
firePropertyChange("groups", null, m_groups);
}
public void removeGroup(PersonPhoneGroup group) {
m_groups.remove(group);
firePropertyChange("groups", null, m_groups);
}
public List getGroups() {
return m_groups;
}
@Override
public String toString() {
String RL = System.getProperty("line.separator");
StringBuilder strBuf = new StringBuilder();
strBuf.append("Person Groups");
strBuf.append(RL);
/**
for(Iterator it= m_groups.iterator(); it.hasNext(); ){
strBuf.append(it.next());
strBuf.append(RL);
}
**/
return strBuf.toString();
}
public String getName() {
return "";
}
public void setName(String name) {
}
public String getEmail() {
return "";
}
public void setEmail(String email) {
}
public String getPhone() {
return "";
}
public void setPhone(String phone) {
}
public String getMobilePhone1() {
return "";
}
public void setMobilePhone1(String phone1) {
}
public String getMobilePhone2() {
return "";
}
public void setMobilePhone2(String phone2) {
}
}
public class PersonPhoneObservableFactory implements IObservableFactory{
public PersonPhoneObservableFactory() {
super();
}
public IObservable createObservable(Object target) {
if( target instanceof PersonPhoneGroups ){
return BeansObservables.observeList(Realm.getDefault(), target,
"groups", PersonPhoneGroup.class);
}else if( target instanceof PersonPhoneGroup ){
return BeansObservables.observeList(Realm.getDefault(), target,
"persons", PersonPhone.class);
}else{
return new EmptyObservableList(Realm.getDefault(), null);
}
}
}
private DataBindingContext m_bindingContext;
private TreeColumn newColumnTreeColumn_4;
private TreeColumn newColumnTreeColumn_3;
private TreeColumn newColumnTreeColumn_2;
private TreeColumn newColumnTreeColumn_1;
private TreeColumn newColumnTreeColumn;
private Tree tree;
private TreeViewer m_personViewer;
private PersonPhoneGroups m_groups = new PersonPhoneGroups();
private Text m_mobile2Text;
private Text m_mobile1Text;
private Text m_phoneText;
private Text m_emailText;
private Text m_nameText;
protected Shell shell;
class TreeLabelProvider implements ITableLabelProvider {
public String getColumnText(Object element, int columnIndex) {
if (columnIndex == 0) {
if (element instanceof PersonPhoneGroup) {
return ((PersonPhoneGroup)element).getName();
} else if (element instanceof PersonPhone) {
return ((PersonPhone)element).getName();
}
} else if (element instanceof PersonPhone) {
PersonPhone person = (PersonPhone) element;
switch (columnIndex) {
case 1:
return person.getEmail();
case 2:
return person.getPhone();
case 3:
return person.getMobilePhone1();
case 4:
return person.getMobilePhone2();
default:
return "";
}
}
return "";
}
public Image getColumnImage(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;
}
public void addListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
}
public void dispose() {
// TODO Auto-generated method stub
}
public boolean isLabelProperty(Object element, String property) {
// TODO Auto-generated method stub
return false;
}
public void removeListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
}
}
private void setDefaultValues() {
PersonPhoneGroup group1 = new PersonPhoneGroup("Developer Team");
m_groups.addGroup(group1);
//
PersonPhoneGroup group2 = new PersonPhoneGroup("Management Team");
m_groups.addGroup(group2);
//
PersonPhoneGroup group3 = new PersonPhoneGroup("Support Team");
m_groups.addGroup(group3);
group1.addPersonPhone(new PersonPhone("Konstantin Scheglov",
"kosta@nospam.com",
"1234567890", "", ""));
group1.addPersonPhone(new PersonPhone("Alexander Mitin",
"mitin@nospam.com", "",
"0987654321", ""));
group1.addPersonPhone(new PersonPhone("Alexander Lobas",
"lobas@nospam.com", "",
"", "111-222-333-00"));
group2.addPersonPhone(new PersonPhone("Mike Taylor",
"taylor@instantiations.com",
"503-598-4900", "", ""));
group2.addPersonPhone(new PersonPhone("Eric Clayberg",
"clayberg@instantiations.com", "+1 (503) 598-4900", "", ""));
group2.addPersonPhone(new PersonPhone("Dan Rubel",
"dan@instantiations.com",
"503-598-4900", "", ""));
group3.addPersonPhone(new PersonPhone("Gina Nebling",
"support@instantiations.com", "800-808-3737", "", ""));
}
public static void main(String[] args) {
Display display = new Display();
Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
public void run() {
try {
PhoneBookUsingTreeViewerEx1 window = new
PhoneBookUsingTreeViewerEx1();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Open the window
*/
public void open() {
final Display display = Display.getDefault();
setDefaultValues();
createContents();
initDataBindings0();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
/**
* Create contents of the window
*/
protected void createContents() {
shell = new Shell();
shell.setLayout(new FillLayout());
shell.setSize(789, 517);
shell.setText("Phone Book");
final SashForm sashForm = new SashForm(shell, SWT.VERTICAL);
m_personViewer = new TreeViewer(sashForm, SWT.FULL_SELECTION);
//m_personViewer.setLabelProvider(new TreeLabelProvider());
tree = m_personViewer.getTree();
tree.setLinesVisible(true);
tree.setHeaderVisible(true);
newColumnTreeColumn = new TreeColumn(tree, SWT.NONE);
newColumnTreeColumn.setWidth(148);
newColumnTreeColumn.setText("Name");
newColumnTreeColumn_1 = new TreeColumn(tree, SWT.NONE);
newColumnTreeColumn_1.setWidth(168);
newColumnTreeColumn_1.setText("E-mail");
newColumnTreeColumn_2 = new TreeColumn(tree, SWT.NONE);
newColumnTreeColumn_2.setWidth(119);
newColumnTreeColumn_2.setText("Phone");
newColumnTreeColumn_3 = new TreeColumn(tree, SWT.NONE);
newColumnTreeColumn_3.setWidth(100);
newColumnTreeColumn_3.setText("Mobile Phone 1");
newColumnTreeColumn_4 = new TreeColumn(tree, SWT.NONE);
newColumnTreeColumn_4.setWidth(100);
newColumnTreeColumn_4.setText("Mobile Phone 2");
final Composite detailComposite = new Composite(sashForm, SWT.BORDER);
final GridLayout gridLayout_2 = new GridLayout();
gridLayout_2.numColumns = 2;
detailComposite.setLayout(gridLayout_2);
final Label descriptionLabel = new Label(detailComposite, SWT.NONE);
descriptionLabel.setText("Description:");
new Label(detailComposite, SWT.NONE);
final Label label = new Label(detailComposite, SWT.NONE);
label.setText("Name:");
m_nameText = new Text(detailComposite, SWT.BORDER);
final GridData gd_m_nameText = new GridData(SWT.FILL, SWT.CENTER, true,
false);
m_nameText.setLayoutData(gd_m_nameText);
final Label emailLabel = new Label(detailComposite, SWT.NONE);
emailLabel.setText("E-mail:");
m_emailText = new Text(detailComposite, SWT.BORDER);
final GridData gd_m_emailText = new GridData(SWT.FILL, SWT.CENTER,
true, false);
m_emailText.setLayoutData(gd_m_emailText);
final Label phoneLabel = new Label(detailComposite, SWT.NONE);
phoneLabel.setText("Phone:");
m_phoneText = new Text(detailComposite, SWT.BORDER);
final GridData gd_m_phoneText = new GridData(SWT.FILL, SWT.CENTER,
true, false);
m_phoneText.setLayoutData(gd_m_phoneText);
final Label mobilePhone1Label = new Label(detailComposite, SWT.NONE);
mobilePhone1Label.setText("Mobile Phone 1:");
m_mobile1Text = new Text(detailComposite, SWT.BORDER);
final GridData gd_m_mobile1Text = new GridData(SWT.FILL, SWT.CENTER,
true, false);
m_mobile1Text.setLayoutData(gd_m_mobile1Text);
final Label mobilePhone2Label = new Label(detailComposite, SWT.NONE);
mobilePhone2Label.setText("Mobile Phone 2:");
m_mobile2Text = new Text(detailComposite, SWT.BORDER);
final GridData gd_m_mobile2Text = new GridData(SWT.FILL, SWT.CENTER,
true, false);
m_mobile2Text.setLayoutData(gd_m_mobile2Text);
sashForm.setWeights(new int[] {218, 262 });
m_bindingContext = initDataBindings();
//m_bindingContext = initDataBindings();
//
}
class PersonViewerUpdateValueStrategy extends UpdateValueStrategy {
protected IStatus doSet(IObservableValue observableValue, Object value) {
Realm.getDefault().asyncExec(new Runnable() {
public void run() {
m_personViewer.refresh();
}
});
return super.doSet(observableValue, value);
}
}
protected DataBindingContext initDataBindings() {
ObservableListTreeContentProvider contentProvider =
new ObservableListTreeContentProvider((IObservableFactory)new
PersonPhoneObservableFactory(), null);
m_personViewer.setContentProvider(contentProvider);
//Looks like the problem is the method BeansObservables.observeMaps(),
not the label provider's creation or setting.
//IObservableMap[] personViewerLabelProviderMaps00 =
BeansObservables.observeMaps(contentProvider.getKnownElement s(),
PersonPhoneGroups.class, new String[]{"name", "email", "phone",
"mobilePhone1", "mobilePhone2"});
IObservableMap[] personViewerLabelProviderMaps0 =
BeansObservables.observeMaps(contentProvider.getKnownElement s(),
PersonPhoneGroup.class, new String[]{"name", "email", "phone",
"mobilePhone1", "mobilePhone2"});
IObservableMap[] personViewerLabelProviderMaps1 =
BeansObservables.observeMaps(contentProvider.getKnownElement s(),
PersonPhone.class, new String[]{"name", "email", "phone", "mobilePhone1",
"mobilePhone2"});
//IObservableMap[] personViewerLabelProviderMaps = new
IObservableMap[personViewerLabelProviderMaps00.length+person ViewerLabelProviderMaps0.length+personViewerLabelProviderMap s1.length];
int mapLength =
personViewerLabelProviderMaps0.length+personViewerLabelProvi derMaps1.length;
IObservableMap[] personViewerLabelProviderMaps = new
IObservableMap[mapLength];
String[] templates = new String[mapLength];
int count=0;
//for(int i=0; i<personViewerLabelProviderMaps00.length; i++){
//personViewerLabelProviderMaps[count++] =
personViewerLabelProviderMaps00[i];
//}
for(int i=0; i<personViewerLabelProviderMaps0.length; i++){
templates[count] = "{0}";
personViewerLabelProviderMaps[count++] =
personViewerLabelProviderMaps0[i];
}
for(int i=0; i<personViewerLabelProviderMaps1.length; i++){
templates[count] = "{0}";
personViewerLabelProviderMaps[count++] =
personViewerLabelProviderMaps1[i];
}
// m_personViewer.setLabelProvider(new
ObservableMapLabelProvider(personViewerLabelProviderMaps));
//m_personViewer.setLabelProvider(new
GenericObservableMapCellLabelProvider(personViewerLabelProvi derMaps,
"{0}"));
m_personViewer.setLabelProvider(new
GenericObservableMapLabelProvider(personViewerLabelProviderM aps,
templates));
//IObservableMap map =
BeansObservables.observeMap(contentProvider.getKnownElements (),
PersonPhoneGroup.class, "name");
//m_personViewer.setLabelProvider(new ObservableMapLabelProvider(map));
//IObservableMap[] m_personViewerLabelProviderMaps =
BeansObservables.observeMaps(contentProvider.getKnownElement s(),
PersonPhoneGroup.class, new String[]{"persons"});
//m_personViewer.setLabelProvider(new
ObservableMapLabelProvider(m_personViewerLabelProviderMaps)) ;
m_personViewer.setInput(m_groups);
//
DataBindingContext bindingContext = new DataBindingContext();
//
//
return bindingContext;
}
public Image getColumnImage(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;
}
public void addListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
}
public void dispose() {
// TODO Auto-generated method stub
}
public boolean isLabelProperty(Object element, String property) {
// TODO Auto-generated method stub
return false;
}
public void removeListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
}
protected void initDataBindings0() {
/*
IObservableValue m_mobile2TextTextObserveWidget =
SWTObservables.observeText(m_mobile2Text, SWT.Modify);
IObservableValue m_mobile1TextTextObserveWidget =
SWTObservables.observeText(m_mobile1Text, SWT.Modify);
IObservableValue m_personViewerSelectionObserveSelection =
ViewersObservables.observeSingleSelection(m_personViewer);
IObservableValue m_personViewerSelectionObserveSelection_1 =
ViewersObservables.observeSingleSelection(m_personViewer);
IObservableValue m_emailTextTextObserveWidget =
SWTObservables.observeText(m_emailText, SWT.Modify);
IObservableValue m_nameTextTextObserveWidget =
SWTObservables.observeText(m_nameText, SWT.Modify);
IObservableValue m_personViewerSelectionObserveSelection_1_1 =
ViewersObservables.observeSingleSelection(m_personViewer);
IObservableValue m_phoneTextTextObserveWidget =
SWTObservables.observeText(m_phoneText, SWT.Modify);
IObservableValue m_personViewerSelectionObserveSelection_1_1_1 =
ViewersObservables.observeSingleSelection(m_personViewer);
IObservableValue m_personViewerSelectionObserveSelection_1_1_1_1 =
ViewersObservables.observeSingleSelection(m_personViewer);
IObservableValue m_personViewerMobilePhone2ObserveDetailValue =
BeansObservables.observeDetailValue(Realm.getDefault(),
m_personViewerSelectionObserveSelection_1, "mobilePhone2",
java.lang.String.class);
IObservableValue m_personViewerMobilePhone1ObserveDetailValue =
BeansObservables.observeDetailValue(Realm.getDefault(),
m_personViewerSelectionObserveSelection_1_1, "mobilePhone1",
java.lang.String.class);
IObservableValue m_personViewerEmailObserveDetailValue =
BeansObservables.observeDetailValue(Realm.getDefault(),
m_personViewerSelectionObserveSelection_1_1_1, "email",
java.lang.String.class);
IObservableValue m_personViewerNameObserveDetailValue =
BeansObservables.observeDetailValue(Realm.getDefault(),
m_personViewerSelectionObserveSelection_1_1_1_1, "name",
java.lang.String.class);
IObservableValue m_personViewerPhoneObserveDetailValue =
BeansObservables.observeDetailValue(Realm.getDefault(),
m_personViewerSelectionObserveSelection, "phone", java.lang.String.class);
//
//
//DataBindingContext bindingContext = new DataBindingContext();
DataBindingContext bindingContext = m_bindingContext;
//
bindingContext.bindValue(m_personViewerNameObserveDetailValu e,
m_nameTextTextObserveWidget, null, new PersonViewerUpdateValueStrategy());
bindingContext.bindValue(m_personViewerEmailObserveDetailVal ue,
m_emailTextTextObserveWidget, null, new PersonViewerUpdateValueStrategy());
bindingContext.bindValue(m_personViewerPhoneObserveDetailVal ue,
m_phoneTextTextObserveWidget, null, new PersonViewerUpdateValueStrategy());
bindingContext.bindValue(m_personViewerMobilePhone1ObserveDe tailValue,
m_mobile1TextTextObserveWidget, null, new
PersonViewerUpdateValueStrategy());
bindingContext.bindValue(m_personViewerMobilePhone2ObserveDe tailValue,
m_mobile2TextTextObserveWidget, null, new
PersonViewerUpdateValueStrategy());
//
//return bindingContext;
*/
}
}
|
|
| | | |
Re: databinding for treeviewer with multi treeColumn [message #328565 is a reply to message #328561] |
Tue, 27 May 2008 16:49 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Hao Missing name![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=d95776%40yahoo.com) Messages: 115 Registered: July 2009 |
Senior Member |
|
|
Send the error and code again for your getting it easily.
org.eclipse.core.databinding - 4 - cannot get value
java.lang.IllegalArgumentException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:64)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at
org.eclipse.core.internal.databinding.beans.JavaBeanObservab leMap.doGet(JavaBeanObservableMap.java:105)
at
org.eclipse.core.databinding.observable.map.ComputedObservab leMap$1.handleSetChange(ComputedObservableMap.java:52)
at
org.eclipse.core.databinding.observable.set.SetChangeEvent.d ispatch(SetChangeEvent.java:61)
at
org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:129)
at
org.eclipse.core.databinding.observable.set.ObservableSet.fi reSetChange(ObservableSet.java:67)
at
org.eclipse.core.internal.databinding.observable.Unmodifiabl eObservableSet.access$0(UnmodifiableObservableSet.java:1)
at
org.eclipse.core.internal.databinding.observable.Unmodifiabl eObservableSet$1.handleSetChange(UnmodifiableObservableSet.j ava:30)
at
org.eclipse.core.databinding.observable.set.SetChangeEvent.d ispatch(SetChangeEvent.java:61)
at
org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:129)
at
org.eclipse.core.databinding.observable.set.ObservableSet.fi reSetChange(ObservableSet.java:67)
at
org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableSet.access$1(DetailObservableSet.java:1)
at
org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableSet$1.handleSetChange(DetailObservableSet. java:42)
at
org.eclipse.core.databinding.observable.set.SetChangeEvent.d ispatch(SetChangeEvent.java:61)
at
org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:129)
at
org.eclipse.core.databinding.observable.set.ObservableSet.fi reSetChange(ObservableSet.java:67)
at
org.eclipse.core.databinding.observable.set.WritableSet.add( WritableSet.java:90)
at
org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableSet.add(DetailObservableSet.java:106)
at
org.eclipse.jface.internal.databinding.viewers.ObservableCol lectionTreeContentProvider$TreeNode. <init>(ObservableCollectionTreeContentProvider.java:284)
at
org.eclipse.jface.internal.databinding.viewers.ObservableCol lectionTreeContentProvider.getOrCreateNode(ObservableCollect ionTreeContentProvider.java:181)
at
org.eclipse.jface.internal.databinding.viewers.ObservableCol lectionTreeContentProvider.getChildren(ObservableCollectionT reeContentProvider.java:162)
at
org.eclipse.jface.internal.databinding.viewers.ObservableCol lectionTreeContentProvider.getElements(ObservableCollectionT reeContentProvider.java:158)
at
org.eclipse.jface.databinding.viewers.ObservableListTreeCont entProvider.getElements(ObservableListTreeContentProvider.ja va:155)
at
org.eclipse.jface.viewers.StructuredViewer.getRawChildren(St ructuredViewer.java:937)
at
org.eclipse.jface.viewers.ColumnViewer.getRawChildren(Column Viewer.java:703)
at
org.eclipse.jface.viewers.AbstractTreeViewer.getRawChildren( AbstractTreeViewer.java:1330)
at org.eclipse.jface.viewers.TreeViewer.getRawChildren(TreeView er.java:385)
at
org.eclipse.jface.viewers.AbstractTreeViewer.getFilteredChil dren(AbstractTreeViewer.java:636)
at
org.eclipse.jface.viewers.AbstractTreeViewer.getSortedChildr en(AbstractTreeViewer.java:602)
at
org.eclipse.jface.viewers.AbstractTreeViewer$1.run(AbstractT reeViewer.java:799)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:67)
at
org.eclipse.jface.viewers.AbstractTreeViewer.createChildren( AbstractTreeViewer.java:776)
at org.eclipse.jface.viewers.TreeViewer.createChildren(TreeView er.java:634)
at
org.eclipse.jface.viewers.AbstractTreeViewer.internalInitial izeTree(AbstractTreeViewer.java:1490)
at
org.eclipse.jface.viewers.TreeViewer.internalInitializeTree( TreeViewer.java:823)
at
org.eclipse.jface.viewers.AbstractTreeViewer$5.run(AbstractT reeViewer.java:1474)
at
org.eclipse.jface.viewers.StructuredViewer.preservingSelecti on(StructuredViewer.java:1365)
at
org.eclipse.jface.viewers.TreeViewer.preservingSelection(Tre eViewer.java:397)
at
org.eclipse.jface.viewers.StructuredViewer.preservingSelecti on(StructuredViewer.java:1328)
at
org.eclipse.jface.viewers.AbstractTreeViewer.inputChanged(Ab stractTreeViewer.java:1467)
at org.eclipse.jface.viewers.ContentViewer.setInput(ContentView er.java:251)
at
org.eclipse.jface.viewers.StructuredViewer.setInput(Structur edViewer.java:1603)
at
com.discover.plugin.phonebook.treeviewer.v34.ex.PhoneBookUsi ngTreeViewerEx1.initDataBindings(PhoneBookUsingTreeViewerEx1 .java:600)
at
com.discover.plugin.phonebook.treeviewer.v34.ex.PhoneBookUsi ngTreeViewerEx1.createContents(PhoneBookUsingTreeViewerEx1.j ava:549)
at
com.discover.plugin.phonebook.treeviewer.v34.ex.PhoneBookUsi ngTreeViewerEx1.open(PhoneBookUsingTreeViewerEx1.java:453)
at
com.discover.plugin.phonebook.treeviewer.v34.ex.PhoneBookUsi ngTreeViewerEx1$1.run(PhoneBookUsingTreeViewerEx1.java:439)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:288)
at
com.discover.plugin.phonebook.treeviewer.v34.ex.PhoneBookUsi ngTreeViewerEx1.main(PhoneBookUsingTreeViewerEx1.java:434)
Here are the source code.
package com.discover.plugin.phonebook.treeviewer.v34.ex;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import
org.eclipse.core.databinding.observable.masterdetail.IObserv ableFactory;
import org.eclipse.core.databinding.observable.value.IObservableVal ue;
import
org.eclipse.core.internal.databinding.observable.EmptyObserv ableList;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.databinding.swt.SWTObservables;
import
org.eclipse.jface.databinding.viewers.ObservableListTreeCont entProvider;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import
at.bestsolution.dataforms.util.viewers.GenericObservableMapL abelProvider;
public class PhoneBookUsingTreeViewerEx1 {
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(propertyN ame,
listener);
}
protected void firePropertyChange(String propertyName, Object oldValue,
Object newValue) {
propertyChangeSupport.firePropertyChange(propertyName, oldValue,
newValue);
}
}
class PersonPhone extends AbstractModelObject{
private String m_name = "";
private String m_email = "";
private String m_phone = "";
private String m_mobilePhone1 = "";
private String m_mobilePhone2 = "";
public PersonPhone() {
}
public PersonPhone(String name, String email, String phone, String phone1,
String phone2) {
m_name = name;
m_email = email;
m_phone = phone;
m_mobilePhone1 = phone1;
m_mobilePhone2 = phone2;
}
public String getName() {
return m_name;
}
public void setName(String name) {
String oldValue = m_name;
m_name = name;
firePropertyChange("name", oldValue, m_name);
}
public String getEmail() {
return m_email;
}
public void setEmail(String email) {
String oldValue = m_email;
m_email = email;
firePropertyChange("email", oldValue, m_email);
}
public String getPhone() {
return m_phone;
}
public void setPhone(String phone) {
String oldValue = m_phone;
m_phone = phone;
firePropertyChange("phone", oldValue, m_phone);
}
public String getMobilePhone1() {
return m_mobilePhone1;
}
public void setMobilePhone1(String phone1) {
String oldValue = m_mobilePhone1;
m_mobilePhone1 = phone1;
firePropertyChange("mobilePhone1", oldValue, m_mobilePhone1);
}
public String getMobilePhone2() {
return m_mobilePhone2;
}
public void setMobilePhone2(String phone2) {
String oldValue = m_mobilePhone2;
m_mobilePhone2 = phone2;
firePropertyChange("mobilePhone2", oldValue, m_mobilePhone2);
}
@Override
public String toString() {
StringBuilder strBuf = new StringBuilder();
strBuf.append("name=");
strBuf.append(m_name);
strBuf.append(";");
strBuf.append("email=");
strBuf.append(m_email);
/**
strBuf.append(";");
strBuf.append("phone=");
strBuf.append(m_phone);
strBuf.append(";");
strBuf.append("mobilePhone1=");
strBuf.append(m_mobilePhone1);
strBuf.append(";");
strBuf.append("mobilePhone2=");
strBuf.append(m_mobilePhone2);
**/
return strBuf.toString();
}
}
class PersonPhoneGroup extends AbstractModelObject{
private final List m_persons = new ArrayList();
private String m_name;
public PersonPhoneGroup() {
}
public PersonPhoneGroup(String name) {
m_name = name;
}
public String getName() {
return m_name;
}
public void setName(String name) {
String oldValue = m_name;
m_name = name;
firePropertyChange("name", oldValue, m_name);
}
public void addPersonPhone(PersonPhone person) {
m_persons.add(person);
firePropertyChange("persons", null, m_persons);
}
public void removePersonPhone(PersonPhone person) {
m_persons.remove(person);
firePropertyChange("persons", null, m_persons);
}
public List getPersons() {
return m_persons;
}
public String getEmail() {
return "";
}
public void setEmail(String email) {
}
public String getPhone() {
return "";
}
public void setPhone(String phone) {
}
public String getMobilePhone1() {
return "";
}
public void setMobilePhone1(String phone1) {
}
public String getMobilePhone2() {
return "";
}
public void setMobilePhone2(String phone2) {
}
@Override
public String toString() {
String RL = System.getProperty("line.separator");
StringBuilder strBuf = new StringBuilder();
strBuf.append("Person Group - ");
strBuf.append(m_name);
strBuf.append(RL);
/**
for(Iterator it= m_persons.iterator(); it.hasNext(); ){
strBuf.append(it.next());
strBuf.append(RL);
}
**/
return strBuf.toString();
}
}
class PersonPhoneGroups extends AbstractModelObject {
private List m_groups;
public PersonPhoneGroups(){
m_groups = new ArrayList();
}
public void addGroup(PersonPhoneGroup group) {
m_groups.add(group);
firePropertyChange("groups", null, m_groups);
}
public void removeGroup(PersonPhoneGroup group) {
m_groups.remove(group);
firePropertyChange("groups", null, m_groups);
}
public List getGroups() {
return m_groups;
}
@Override
public String toString() {
String RL = System.getProperty("line.separator");
StringBuilder strBuf = new StringBuilder();
strBuf.append("Person Groups");
strBuf.append(RL);
/**
for(Iterator it= m_groups.iterator(); it.hasNext(); ){
strBuf.append(it.next());
strBuf.append(RL);
}
**/
return strBuf.toString();
}
public String getName() {
return "";
}
public void setName(String name) {
}
public String getEmail() {
return "";
}
public void setEmail(String email) {
}
public String getPhone() {
return "";
}
public void setPhone(String phone) {
}
public String getMobilePhone1() {
return "";
}
public void setMobilePhone1(String phone1) {
}
public String getMobilePhone2() {
return "";
}
public void setMobilePhone2(String phone2) {
}
}
public class PersonPhoneObservableFactory implements IObservableFactory{
public PersonPhoneObservableFactory() {
super();
}
public IObservable createObservable(Object target) {
if( target instanceof PersonPhoneGroups ){
return BeansObservables.observeList(Realm.getDefault(), target, "groups",
PersonPhoneGroup.class);
}else if( target instanceof PersonPhoneGroup ){
return BeansObservables.observeList(Realm.getDefault(), target, "persons",
PersonPhone.class);
}else{
return new EmptyObservableList(Realm.getDefault(), null);
}
}
}
private DataBindingContext m_bindingContext;
private TreeColumn newColumnTreeColumn_4;
private TreeColumn newColumnTreeColumn_3;
private TreeColumn newColumnTreeColumn_2;
private TreeColumn newColumnTreeColumn_1;
private TreeColumn newColumnTreeColumn;
private Tree tree;
private TreeViewer m_personViewer;
private PersonPhoneGroups m_groups = new PersonPhoneGroups();
private Text m_mobile2Text;
private Text m_mobile1Text;
private Text m_phoneText;
private Text m_emailText;
private Text m_nameText;
protected Shell shell;
class TreeLabelProvider implements ITableLabelProvider {
public String getColumnText(Object element, int columnIndex) {
if (columnIndex == 0) {
if (element instanceof PersonPhoneGroup) {
return ((PersonPhoneGroup)element).getName();
} else if (element instanceof PersonPhone) {
return ((PersonPhone)element).getName();
}
} else if (element instanceof PersonPhone) {
PersonPhone person = (PersonPhone) element;
switch (columnIndex) {
case 1:
return person.getEmail();
case 2:
return person.getPhone();
case 3:
return person.getMobilePhone1();
case 4:
return person.getMobilePhone2();
default:
return "";
}
}
return "";
}
public Image getColumnImage(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;
}
public void addListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
}
public void dispose() {
// TODO Auto-generated method stub
}
public boolean isLabelProperty(Object element, String property) {
// TODO Auto-generated method stub
return false;
}
public void removeListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
}
}
private void setDefaultValues() {
PersonPhoneGroup group1 = new PersonPhoneGroup("Developer Team");
m_groups.addGroup(group1);
//
PersonPhoneGroup group2 = new PersonPhoneGroup("Management Team");
m_groups.addGroup(group2);
//
PersonPhoneGroup group3 = new PersonPhoneGroup("Support Team");
m_groups.addGroup(group3);
group1.addPersonPhone(new PersonPhone("Konstantin Scheglov",
"kosta@xxxxxxxx",
"1234567890", "", ""));
group1.addPersonPhone(new PersonPhone("Alexander Mitin", "mitin@xxxxxxxx",
"",
"0987654321", ""));
group1.addPersonPhone(new PersonPhone("Alexander Lobas", "lobas@xxxxxxxx",
"",
"", "111-222-333-00"));
group2.addPersonPhone(new PersonPhone("Mike Taylor", "taylor@xxxxxxxx",
"503-598-4900", "", ""));
group2.addPersonPhone(new PersonPhone("Eric Clayberg",
"clayberg@xxxxxxxx", "+1 (503) 598-4900", "", ""));
group2.addPersonPhone(new PersonPhone("Dan Rubel", "dan@xxxxxxxx",
"503-598-4900", "", ""));
group3.addPersonPhone(new PersonPhone("Gina Nebling",
"support@xxxxxxxx", "800-808-3737", "", ""));
}
public static void main(String[] args) {
Display display = new Display();
Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
public void run() {
try {
PhoneBookUsingTreeViewerEx1 window = new PhoneBookUsingTreeViewerEx1();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Open the window
*/
public void open() {
final Display display = Display.getDefault();
setDefaultValues();
createContents();
initDataBindings0();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
/**
* Create contents of the window
*/
protected void createContents() {
shell = new Shell();
shell.setLayout(new FillLayout());
shell.setSize(789, 517);
shell.setText("Phone Book");
final SashForm sashForm = new SashForm(shell, SWT.VERTICAL);
m_personViewer = new TreeViewer(sashForm, SWT.FULL_SELECTION);
//m_personViewer.setLabelProvider(new TreeLabelProvider());
tree = m_personViewer.getTree();
tree.setLinesVisible(true);
tree.setHeaderVisible(true);
newColumnTreeColumn = new TreeColumn(tree, SWT.NONE);
newColumnTreeColumn.setWidth(148);
newColumnTreeColumn.setText("Name");
newColumnTreeColumn_1 = new TreeColumn(tree, SWT.NONE);
newColumnTreeColumn_1.setWidth(168);
newColumnTreeColumn_1.setText("E-mail");
newColumnTreeColumn_2 = new TreeColumn(tree, SWT.NONE);
newColumnTreeColumn_2.setWidth(119);
newColumnTreeColumn_2.setText("Phone");
newColumnTreeColumn_3 = new TreeColumn(tree, SWT.NONE);
newColumnTreeColumn_3.setWidth(100);
newColumnTreeColumn_3.setText("Mobile Phone 1");
newColumnTreeColumn_4 = new TreeColumn(tree, SWT.NONE);
newColumnTreeColumn_4.setWidth(100);
newColumnTreeColumn_4.setText("Mobile Phone 2");
final Composite detailComposite = new Composite(sashForm, SWT.BORDER);
final GridLayout gridLayout_2 = new GridLayout();
gridLayout_2.numColumns = 2;
detailComposite.setLayout(gridLayout_2);
final Label descriptionLabel = new Label(detailComposite, SWT.NONE);
descriptionLabel.setText("Description:");
new Label(detailComposite, SWT.NONE);
final Label label = new Label(detailComposite, SWT.NONE);
label.setText("Name:");
m_nameText = new Text(detailComposite, SWT.BORDER);
final GridData gd_m_nameText = new GridData(SWT.FILL, SWT.CENTER, true,
false);
m_nameText.setLayoutData(gd_m_nameText);
final Label emailLabel = new Label(detailComposite, SWT.NONE);
emailLabel.setText("E-mail:");
m_emailText = new Text(detailComposite, SWT.BORDER);
final GridData gd_m_emailText = new GridData(SWT.FILL, SWT.CENTER,
true, false);
m_emailText.setLayoutData(gd_m_emailText);
final Label phoneLabel = new Label(detailComposite, SWT.NONE);
phoneLabel.setText("Phone:");
m_phoneText = new Text(detailComposite, SWT.BORDER);
final GridData gd_m_phoneText = new GridData(SWT.FILL, SWT.CENTER,
true, false);
m_phoneText.setLayoutData(gd_m_phoneText);
final Label mobilePhone1Label = new Label(detailComposite, SWT.NONE);
mobilePhone1Label.setText("Mobile Phone 1:");
m_mobile1Text = new Text(detailComposite, SWT.BORDER);
final GridData gd_m_mobile1Text = new GridData(SWT.FILL, SWT.CENTER,
true, false);
m_mobile1Text.setLayoutData(gd_m_mobile1Text);
final Label mobilePhone2Label = new Label(detailComposite, SWT.NONE);
mobilePhone2Label.setText("Mobile Phone 2:");
m_mobile2Text = new Text(detailComposite, SWT.BORDER);
final GridData gd_m_mobile2Text = new GridData(SWT.FILL, SWT.CENTER,
true, false);
m_mobile2Text.setLayoutData(gd_m_mobile2Text);
sashForm.setWeights(new int[] {218, 262 });
m_bindingContext = initDataBindings();
//m_bindingContext = initDataBindings();
//
}
class PersonViewerUpdateValueStrategy extends UpdateValueStrategy {
protected IStatus doSet(IObservableValue observableValue, Object value) {
Realm.getDefault().asyncExec(new Runnable() {
public void run() {
m_personViewer.refresh();
}
});
return super.doSet(observableValue, value);
}
}
protected DataBindingContext initDataBindings() {
ObservableListTreeContentProvider contentProvider = new
ObservableListTreeContentProvider((IObservableFactory)new
PersonPhoneObservableFactory(), null);
m_personViewer.setContentProvider(contentProvider);
//Looks like the problem is the method BeansObservables.observeMaps(), not
the label provider's creation or setting.
//IObservableMap[] personViewerLabelProviderMaps00 =
BeansObservables.observeMaps(contentProvider.getKnownElement s(),
PersonPhoneGroups.class, new String[]{"name", "email", "phone",
"mobilePhone1", "mobilePhone2"});
IObservableMap[] personViewerLabelProviderMaps0 =
BeansObservables.observeMaps(contentProvider.getKnownElement s(),
PersonPhoneGroup.class, new String[]{"name", "email", "phone",
"mobilePhone1", "mobilePhone2"});
IObservableMap[] personViewerLabelProviderMaps1 =
BeansObservables.observeMaps(contentProvider.getKnownElement s(),
PersonPhone.class, new String[]{"name", "email", "phone", "mobilePhone1",
"mobilePhone2"});
//IObservableMap[] personViewerLabelProviderMaps = new
IObservableMap[personViewerLabelProviderMaps00.length+person ViewerLabelProviderMaps0.length+personViewerLabelProviderMap s1.length];
int mapLength =
personViewerLabelProviderMaps0.length+personViewerLabelProvi derMaps1.length;
IObservableMap[] personViewerLabelProviderMaps = new
IObservableMap[mapLength];
String[] templates = new String[mapLength];
int count=0;
//for(int i=0; i<personViewerLabelProviderMaps00.length; i++){
//personViewerLabelProviderMaps[count++] =
personViewerLabelProviderMaps00[i];
//}
for(int i=0; i<personViewerLabelProviderMaps0.length; i++){
templates[count] = "{0}";
personViewerLabelProviderMaps[count++] = personViewerLabelProviderMaps0[i];
}
for(int i=0; i<personViewerLabelProviderMaps1.length; i++){
templates[count] = "{0}";
personViewerLabelProviderMaps[count++] = personViewerLabelProviderMaps1[i];
}
// m_personViewer.setLabelProvider(new
ObservableMapLabelProvider(personViewerLabelProviderMaps));
//m_personViewer.setLabelProvider(new
GenericObservableMapCellLabelProvider(personViewerLabelProvi derMaps,
"{0}"));
m_personViewer.setLabelProvider(new
GenericObservableMapLabelProvider(personViewerLabelProviderM aps,
templates));
//IObservableMap map =
BeansObservables.observeMap(contentProvider.getKnownElements (),
PersonPhoneGroup.class, "name");
//m_personViewer.setLabelProvider(new ObservableMapLabelProvider(map));
//IObservableMap[] m_personViewerLabelProviderMaps =
BeansObservables.observeMaps(contentProvider.getKnownElement s(),
PersonPhoneGroup.class, new String[]{"persons"});
//m_personViewer.setLabelProvider(new
ObservableMapLabelProvider(m_personViewerLabelProviderMaps)) ;
m_personViewer.setInput(m_groups);
//
DataBindingContext bindingContext = new DataBindingContext();
//
//
return bindingContext;
}
public Image getColumnImage(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;
}
public void addListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
}
public void dispose() {
// TODO Auto-generated method stub
}
public boolean isLabelProperty(Object element, String property) {
// TODO Auto-generated method stub
return false;
}
public void removeListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
}
protected void initDataBindings0() {
/*
IObservableValue m_mobile2TextTextObserveWidget =
SWTObservables.observeText(m_mobile2Text, SWT.Modify);
IObservableValue m_mobile1TextTextObserveWidget =
SWTObservables.observeText(m_mobile1Text, SWT.Modify);
IObservableValue m_personViewerSelectionObserveSelection =
ViewersObservables.observeSingleSelection(m_personViewer);
IObservableValue m_personViewerSelectionObserveSelection_1 =
ViewersObservables.observeSingleSelection(m_personViewer);
IObservableValue m_emailTextTextObserveWidget =
SWTObservables.observeText(m_emailText, SWT.Modify);
IObservableValue m_nameTextTextObserveWidget =
SWTObservables.observeText(m_nameText, SWT.Modify);
IObservableValue m_personViewerSelectionObserveSelection_1_1 =
ViewersObservables.observeSingleSelection(m_personViewer);
IObservableValue m_phoneTextTextObserveWidget =
SWTObservables.observeText(m_phoneText, SWT.Modify);
IObservableValue m_personViewerSelectionObserveSelection_1_1_1 =
ViewersObservables.observeSingleSelection(m_personViewer);
IObservableValue m_personViewerSelectionObserveSelection_1_1_1_1 =
ViewersObservables.observeSingleSelection(m_personViewer);
IObservableValue m_personViewerMobilePhone2ObserveDetailValue =
BeansObservables.observeDetailValue(Realm.getDefault(),
m_personViewerSelectionObserveSelection_1, "mobilePhone2",
java.lang.String.class);
IObservableValue m_personViewerMobilePhone1ObserveDetailValue =
BeansObservables.observeDetailValue(Realm.getDefault(),
m_personViewerSelectionObserveSelection_1_1, "mobilePhone1",
java.lang.String.class);
IObservableValue m_personViewerEmailObserveDetailValue =
BeansObservables.observeDetailValue(Realm.getDefault(),
m_personViewerSelectionObserveSelection_1_1_1, "email",
java.lang.String.class);
IObservableValue m_personViewerNameObserveDetailValue =
BeansObservables.observeDetailValue(Realm.getDefault(),
m_personViewerSelectionObserveSelection_1_1_1_1, "name",
java.lang.String.class);
IObservableValue m_personViewerPhoneObserveDetailValue =
BeansObservables.observeDetailValue(Realm.getDefault(),
m_personViewerSelectionObserveSelection, "phone", java.lang.String.class);
//
//
//DataBindingContext bindingContext = new DataBindingContext();
DataBindingContext bindingContext = m_bindingContext;
//
bindingContext.bindValue(m_personViewerNameObserveDetailValu e,
m_nameTextTextObserveWidget, null, new PersonViewerUpdateValueStrategy());
bindingContext.bindValue(m_personViewerEmailObserveDetailVal ue,
m_emailTextTextObserveWidget, null, new PersonViewerUpdateValueStrategy());
bindingContext.bindValue(m_personViewerPhoneObserveDetailVal ue,
m_phoneTextTextObserveWidget, null, new PersonViewerUpdateValueStrategy());
bindingContext.bindValue(m_personViewerMobilePhone1ObserveDe tailValue,
m_mobile1TextTextObserveWidget, null, new
PersonViewerUpdateValueStrategy());
bindingContext.bindValue(m_personViewerMobilePhone2ObserveDe tailValue,
m_mobile2TextTextObserveWidget, null, new
PersonViewerUpdateValueStrategy());
//
//return bindingContext;
*/
}
}
|
|
|
Goto Forum:
Current Time: Sun Sep 01 09:54:26 GMT 2024
Powered by FUDForum. Page generated in 0.04431 seconds
|