Changeset 681
- Timestamp:
- 05/30/07 01:16:26 (2 years ago)
- Files:
-
- org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/META-INF/MANIFEST.MF (modified) (1 diff)
- org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/ProjectComponentsFactory.java (modified) (5 diffs)
- org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/models/Project.java (modified) (2 diffs)
- org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/models/ProjectDataSource.java (modified) (3 diffs)
- org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/views/project/ProjectContentProvider.java (modified) (2 diffs)
- org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/views/project/ProjectView.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/META-INF/MANIFEST.MF
r679 r681 9 9 org.eclipse.core.runtime, 10 10 org.jalcedo.client.jface, 11 org.jalcedo.client.rest 11 org.jalcedo.client.rest, 12 org.eclipse.core.databinding, 13 org.eclipse.core.databinding.beans, 14 org.eclipse.jface.databinding 12 15 Eclipse-LazyStart: true org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/ProjectComponentsFactory.java
r679 r681 1 1 package org.jalcedo.client.examples.rails; 2 2 3 import org.eclipse.jface.viewers.IContentProvider; 4 import org.eclipse.jface.viewers.ILabelProvider; 5 import org.eclipse.jface.viewers.IStructuredContentProvider; 3 6 import org.eclipse.swt.widgets.Composite; 4 7 import org.jalcedo.client.ds.DataSource; 5 8 import org.jalcedo.client.events.ApplicationEventPublisher; 6 9 import org.jalcedo.client.events.DefaultEventPublisher; 10 import org.jalcedo.client.examples.rails.controllers.project.ProjectFetchAction; 7 11 import org.jalcedo.client.examples.rails.models.Project; 8 12 import org.jalcedo.client.examples.rails.models.ProjectDataSource; 13 import org.jalcedo.client.examples.rails.views.project.ProjectContentProvider; 9 14 import org.jalcedo.client.examples.rails.views.project.ProjectDetailComposite; 10 15 import org.jalcedo.client.examples.rails.views.project.ProjectListComposite; … … 20 25 if (clazz == ProjectListComposite.class) { 21 26 ProjectListComposite composite = new ProjectListComposite(parent, style); 27 ProjectContentProvider contentProvider = (ProjectContentProvider) this.getComponent(ProjectContentProvider.class); 28 composite.getListViewer().setContentProvider(contentProvider); 29 composite.getListViewer().setLabelProvider(contentProvider); 30 composite.getFetchButton().addSelectionListener((ProjectFetchAction) this.getComponent(ProjectFetchAction.class)); 22 31 return (T) composite; 23 32 } … … 31 40 private HttpClientConnection connection; 32 41 private Converter<Project> converter; 33 private ProjectDataSource projectDataSource; 42 private ProjectDataSource dataSource; 43 private ProjectContentProvider contentProvider; 44 private ProjectFetchAction fetchAction; 34 45 35 46 @SuppressWarnings("unchecked") … … 39 50 } 40 51 if (key == DataSource.class) { 41 if (this. projectDataSource == null) {42 this. projectDataSource = new ProjectDataSource();43 this. projectDataSource.setApplicationEventPublisher((ApplicationEventPublisher) this.getComponent(ApplicationEventPublisher.class));44 this. projectDataSource.setConnection((Connection) this.getComponent(Connection.class));45 this. projectDataSource.setConverter((Converter<Project>) this.getComponent(Converter.class));52 if (this.dataSource == null) { 53 this.dataSource = new ProjectDataSource(); 54 this.dataSource.setApplicationEventPublisher((ApplicationEventPublisher) this.getComponent(ApplicationEventPublisher.class)); 55 this.dataSource.setConnection((Connection) this.getComponent(Connection.class)); 56 this.dataSource.setConverter((Converter<Project>) this.getComponent(Converter.class)); 46 57 } 47 return this. projectDataSource;58 return this.dataSource; 48 59 } 49 60 if (key == Connection.class) { … … 60 71 return this.converter; 61 72 } 73 if ( 74 key == IContentProvider.class || 75 key == IStructuredContentProvider.class || 76 key == ILabelProvider.class || 77 key == ProjectContentProvider.class 78 ) { 79 if (this.contentProvider == null) { 80 this.contentProvider = new ProjectContentProvider(); 81 ApplicationEventPublisher applicationEventPublisher = (ApplicationEventPublisher) this.getComponent(ApplicationEventPublisher.class); 82 applicationEventPublisher.addListener(this.contentProvider); 83 this.contentProvider.setDataSource((DataSource<Integer, Project>) this.getComponent(DataSource.class)); 84 } 85 return this.contentProvider; 86 } 87 if (key == ProjectFetchAction.class) { 88 if (this.fetchAction == null) { 89 this.fetchAction = new ProjectFetchAction(); 90 this.fetchAction.setApplicationEventPublisher((ApplicationEventPublisher) this.getComponent(ApplicationEventPublisher.class)); 91 } 92 return this.fetchAction; 93 } 62 94 return null; 63 95 } org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/models/Project.java
r665 r681 2 2 3 3 public class Project { 4 private intid;4 private Integer id; 5 5 private String firstName; 6 6 private String desc; … … 18 18 this.firstName = firstName; 19 19 } 20 public intgetId() {20 public Integer getId() { 21 21 return id; 22 22 } 23 public void setId( intid) {23 public void setId(Integer id) { 24 24 this.id = id; 25 25 } org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/models/ProjectDataSource.java
r679 r681 1 1 package org.jalcedo.client.examples.rails.models; 2 2 3 import java.util.ArrayList; 4 import java.util.HashMap; 3 5 import java.util.List; 6 import java.util.Map; 4 7 5 8 import org.jalcedo.client.ds.DataSource; … … 15 18 16 19 private Converter<Project> converter; 20 21 private Map<Integer, Project> projects; 22 23 public ProjectDataSource() { 24 this.projects = new HashMap<Integer, Project>(); 25 Project p0 = new Project(); 26 p0.setId(1); 27 p0.setFirstName("test"); 28 p0.setDesc("This is a test project."); 29 this.projects.put(p0.getId(), p0); 30 } 17 31 18 32 public Connection getConnection() { … … 42 56 43 57 public Project create(Project newObject) { 44 // TODO Auto-generated method stub 45 return null; 58 this.projects.put(newObject.getId(), newObject); 59 this.getApplicationEventPublisher().publishEvent(new ProjectEvent(newObject, ProjectEvent.ADDED)); 60 return newObject; 46 61 } 47 62 48 63 public void delete(Project detachedObject) { 49 // TODO Auto-generated method stub50 64 this.projects.remove(detachedObject.getId()); 65 this.getApplicationEventPublisher().publishEvent(new ProjectEvent(detachedObject, ProjectEvent.DELETED)); 51 66 } 52 67 53 68 public Project edit(Project detachedObject) { 54 // TODO Auto-generated method stub55 return null;69 this.getApplicationEventPublisher().publishEvent(new ProjectEvent(detachedObject, ProjectEvent.MODIFIED)); 70 return detachedObject; 56 71 } 57 72 58 73 public Project find(Integer key) { 59 // TODO Auto-generated method stub 60 return null; 74 return this.projects.get(key); 61 75 } 62 76 63 77 public List<Project> findList() { 64 String source = this.getConnection().get("http://localhost:3000/projects.json", null); 65 return this.getConverter().toList(source); 78 return new ArrayList<Project>(this.projects.values()); 66 79 } 67 80 org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/views/project/ProjectContentProvider.java
r679 r681 29 29 30 30 public Object[] getElements(Object inputElement) { 31 return this.getDataSource().findList().toArray();31 return (Object[]) inputElement; 32 32 } 33 33 … … 43 43 44 44 public void onApplicationEvent(ApplicationEvent event) { 45 if (event instanceof ProjectEvent && this.viewer != null) { 46 this.viewer.refresh(); 45 if (event instanceof ProjectEvent) { 46 ProjectEvent pe = (ProjectEvent) event; 47 if (pe.getType() == ProjectEvent.REFRESH) { 48 this.viewer.setInput(this.getDataSource().findList().toArray()); 49 } 47 50 } 48 51 } org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/views/project/ProjectView.java
r673 r681 1 1 package org.jalcedo.client.examples.rails.views.project; 2 2 3 import org.eclipse.core.databinding.DataBindingContext; 4 import org.eclipse.core.databinding.UpdateValueStrategy; 5 import org.eclipse.core.databinding.beans.BeansObservables; 6 import org.eclipse.core.databinding.observable.Realm; 7 import org.eclipse.core.databinding.observable.value.IObservableValue; 8 import org.eclipse.jface.databinding.swt.SWTObservables; 9 import org.eclipse.jface.databinding.viewers.ViewersObservables; 3 10 import org.eclipse.swt.SWT; 4 11 import org.eclipse.swt.layout.GridData; … … 17 24 ProjectComponentsFactory factory = ProjectComponentsFactory.getFactory(); 18 25 19 createListComposite(parent, factory); 20 createDetailComposite(parent, factory); 26 final ProjectListComposite listComposite = createListComposite(parent, factory); 27 final ProjectDetailComposite detailComposite = createDetailComposite(parent, factory); 28 29 // TODO set initial values. 30 listComposite.getListViewer().setInput(null); 31 32 // Set up data binding. In an RCP application, the threading Realm 33 // will be set for you automatically by the Workbench. In an SWT 34 // application, you can do this once, wrapping your binding 35 // method call. 36 Realm.runWithDefault(SWTObservables.getRealm(parent.getDisplay()), new Runnable() { 37 public void run() { 38 // 1. Observe changes in selection. 39 IObservableValue selection = ViewersObservables 40 .observeSingleSelection(listComposite.getListViewer()); 41 42 // 2. Observe the name property of the current selection. 43 IObservableValue firstNameObservable = BeansObservables 44 .observeDetailValue(Realm.getDefault(), selection, 45 "firstName", String.class); 46 IObservableValue descObservable = BeansObservables 47 .observeDetailValue(Realm.getDefault(), selection, 48 "desc", String.class); 49 50 // 3. Bind the Text widget to the name detail (selection's 51 // name). 52 DataBindingContext dbc = new DataBindingContext(); 53 dbc.bindValue(SWTObservables.observeText( 54 detailComposite.getFirstNameText(), SWT.None), firstNameObservable, 55 new UpdateValueStrategy(false, 56 UpdateValueStrategy.POLICY_NEVER), null); 57 dbc.bindValue(SWTObservables.observeText( 58 detailComposite.getDescText(), SWT.None), descObservable, 59 new UpdateValueStrategy(false, 60 UpdateValueStrategy.POLICY_NEVER), null); 61 } 62 }); 21 63 } 22 64 23 private voidcreateDetailComposite(Composite parent,65 private ProjectDetailComposite createDetailComposite(Composite parent, 24 66 ProjectComponentsFactory factory) { 25 67 GridData gridData = new GridData(); 26 //gridData.horizontalAlignment = GridData.FILL; 27 //gridData.grabExcessHorizontalSpace = true; 28 //gridData.grabExcessVerticalSpace = true; 29 //gridData.verticalAlignment = GridData.FILL; 30 Composite composite = factory.createComposite(ProjectDetailComposite.class, parent, SWT.NONE); 68 ProjectDetailComposite composite = factory.createComposite(ProjectDetailComposite.class, parent, SWT.NONE); 31 69 composite.setLayoutData(gridData); 70 71 return composite; 32 72 } 33 73 34 private voidcreateListComposite(Composite parent,74 private ProjectListComposite createListComposite(Composite parent, 35 75 ProjectComponentsFactory factory) { 36 76 GridData gridData = new GridData(); … … 38 78 gridData.grabExcessHorizontalSpace = true; 39 79 gridData.verticalAlignment = GridData.CENTER; 40 Composite composite = factory.createComposite(ProjectListComposite.class, parent, SWT.NONE); 41 //composite.setLayout(new GridLayout()); 80 ProjectListComposite composite = factory.createComposite(ProjectListComposite.class, parent, SWT.NONE); 42 81 composite.setLayoutData(gridData); 82 83 return composite; 43 84 } 44 85
