dataBinding and property change notification [message #692074] |
Sun, 03 July 2011 12:45 |
mousa.alsulaimi Messages: 18 Registered: June 2011 |
Junior Member |
|
|
is there a way to be notified when a property is changed i have tried IPropertyChangeListener , where i have added the property change listener to the preference store , but it did not work , when i change the properties in the preference store nothing happens , can any one help my ...... here is my code :
package com.capmtech.prefrences;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.databinding.WorkbenchProperties;
import org.eclipse.swt.widgets.List;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Label;
public class TestPerfrancePage extends PreferencePage implements IWorkbenchPreferencePage {
static private final String PREFERENCE_PATH ="InstrumentWatch.DectionaryTree" ;
/**
* Create the preference page.
*/
List target , source ;
public TestPerfrancePage() {
}
/**
* Create contents of the preference page.
* @param parent
*/
@Override
public Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
ListViewer viewer = new ListViewer(container) ;
source = viewer.getList() ;
source.add(new ListItem("id").toString()) ;
source.add(new ListItem("symbol").toString()) ;
source.add(new ListItem("qnty").toString()) ;
source.add(new ListItem("new price").toString()) ;
source.add(new ListItem("old price").toString()) ;
source.setBounds(20, 81, 118, 158);
Button btnAdd = new Button(container, SWT.NONE);
btnAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
}
});
btnAdd.setBounds(144, 99, 75, 25);
btnAdd.setText("\u2192");
Button btnRemove = new Button(container, SWT.NONE);
btnRemove.setBounds(144, 199, 75, 25);
btnRemove.setText("\u2190");
ListViewer listViewer = new ListViewer(container, SWT.BORDER | SWT.V_SCROLL);
target = listViewer.getList();
target.setBounds(227, 81, 102, 158);
Label lblColumnList = new Label(container, SWT.NONE);
lblColumnList.setBounds(21, 52, 102, 15);
lblColumnList.setText("Column list : ");
Label lblDisplayedColumns = new Label(container, SWT.NONE);
lblDisplayedColumns.setBounds(227, 52, 112, 15);
lblDisplayedColumns.setText("Displayed Columns");
btnAdd.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseDown(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseDoubleClick(MouseEvent e) {
// TODO Auto-generated method stub
try{
String selected = source.getSelection()[0] ;
target.add(selected) ;
source.remove(selected) ;
IEclipsePreferences prefs = ConfigurationScope.INSTANCE.getNode("com.capmtech.prefrences") ;
// System.out.println(" old value (from source ) : "+prefs.getBoolean(PREFERENCE_PATH+selected, true) );
PlatformUI.getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
//
@Override
public void propertyChange(PropertyChangeEvent event) {
// TODO Auto-generated method stub
System.out.println(" property name : "+ event.getProperty());
//
}
}) ;
// prefs.remove(PREFERENCE_PATH+selected) ;
prefs.putBoolean(PREFERENCE_PATH+selected, true) ;
}catch(ArrayIndexOutOfBoundsException ex)
{
//ex.printStackTrace() ;
}
}
}) ;
btnRemove.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseDown(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseDoubleClick(MouseEvent e) {
// TODO Auto-generated method stub
try{String selected = target.getSelection()[0] ;
source.add(selected) ;
target.remove(selected) ;
IEclipsePreferences prefs = ConfigurationScope.INSTANCE.getNode("com.capmtech.prefrences") ;
// System.out.println(" old value (from target) : "+PlatformUI.getPreferenceStore().getBoolean(PREFERENCE_PATH+selected) );
prefs.putBoolean(PREFERENCE_PATH+selected, false) ;
}catch(ArrayIndexOutOfBoundsException ex)
{
//ex.printStackTrace() ;
}
}
}) ;
return container;
}
/**
* Initialize the preference page.
*/
public void init(IWorkbench workbench) {
// Initialize the preference page
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.02615 seconds