Changeset 684
- Timestamp:
- 05/30/07 20:11:46 (2 years ago)
- Files:
-
- org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/ProjectComponentsFactory.java (modified) (4 diffs)
- org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/controllers/project/ProjectAddAction.java (modified) (2 diffs)
- org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/controllers/project/ProjectApplyAction.java (modified) (2 diffs)
- org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/controllers/project/ProjectRemoveAction.java (modified) (2 diffs)
- org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/views/project/ProjectContentProvider.java (modified) (3 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/src/org/jalcedo/client/examples/rails/ProjectComponentsFactory.java
r681 r684 8 8 import org.jalcedo.client.events.ApplicationEventPublisher; 9 9 import org.jalcedo.client.events.DefaultEventPublisher; 10 import org.jalcedo.client.examples.rails.controllers.project.ProjectAddAction; 11 import org.jalcedo.client.examples.rails.controllers.project.ProjectApplyAction; 10 12 import org.jalcedo.client.examples.rails.controllers.project.ProjectFetchAction; 13 import org.jalcedo.client.examples.rails.controllers.project.ProjectRemoveAction; 11 14 import org.jalcedo.client.examples.rails.models.Project; 12 15 import org.jalcedo.client.examples.rails.models.ProjectDataSource; … … 21 24 public class ProjectComponentsFactory { 22 25 26 private ProjectListComposite listComposite; 27 private ProjectDetailComposite detailComposite; 28 23 29 @SuppressWarnings("unchecked") 24 30 public <T extends Composite> T createComposite(Class<T> clazz, Composite parent, int style) { 25 31 if (clazz == ProjectListComposite.class) { 26 ProjectListComposite composite = new ProjectListComposite(parent, style); 32 if (listComposite != null) { 33 throw new RuntimeException("List Composite is only create once time."); 34 } 35 listComposite = new ProjectListComposite(parent, style); 27 36 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)); 31 return (T) composite; 37 listComposite.getListViewer().setContentProvider(contentProvider); 38 listComposite.getListViewer().setLabelProvider(contentProvider); 39 listComposite.getFetchButton().addSelectionListener((ProjectFetchAction) this.getComponent(ProjectFetchAction.class)); 40 listComposite.getAddButton().addSelectionListener((ProjectAddAction) this.getComponent(ProjectAddAction.class)); 41 ProjectApplyAction applyAction = (ProjectApplyAction) this.getComponent(ProjectApplyAction.class); 42 applyAction.setSelectionProvider(listComposite.getListViewer()); 43 ProjectRemoveAction removeAction = (ProjectRemoveAction) this.getComponent(ProjectRemoveAction.class); 44 removeAction.setSelectionProvider(listComposite.getListViewer()); 45 return (T) listComposite; 32 46 } 33 47 if (clazz == ProjectDetailComposite.class) { 34 ProjectDetailComposite composite = new ProjectDetailComposite(parent, style); 35 return (T) composite; 48 if (detailComposite != null) { 49 throw new RuntimeException("Detail Composite is only create once time."); 50 } 51 detailComposite = new ProjectDetailComposite(parent, style); 52 ProjectApplyAction applyAction = (ProjectApplyAction) this.getComponent(ProjectApplyAction.class); 53 ProjectRemoveAction removeAction = (ProjectRemoveAction) this.getComponent(ProjectRemoveAction.class); 54 detailComposite.getApplyButton().addSelectionListener(applyAction); 55 detailComposite.getRemoveButton().addSelectionListener(removeAction); 56 return (T) detailComposite; 36 57 } 37 58 return null; … … 43 64 private ProjectContentProvider contentProvider; 44 65 private ProjectFetchAction fetchAction; 66 private ProjectAddAction addAction; 67 private ProjectApplyAction applyAction; 68 private ProjectRemoveAction removeAction; 45 69 46 70 @SuppressWarnings("unchecked") … … 77 101 key == ProjectContentProvider.class 78 102 ) { 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));103 if (contentProvider == null) { 104 contentProvider = new ProjectContentProvider(); 105 ApplicationEventPublisher applicationEventPublisher = (ApplicationEventPublisher) this.getComponent(ApplicationEventPublisher.class); 106 applicationEventPublisher.addListener(contentProvider); 107 contentProvider.setDataSource((DataSource<Integer, Project>) this.getComponent(DataSource.class)); 84 108 } 85 return this.contentProvider;109 return contentProvider; 86 110 } 87 111 if (key == ProjectFetchAction.class) { 88 if ( this.fetchAction == null) {89 this.fetchAction = new ProjectFetchAction();90 this.fetchAction.setApplicationEventPublisher((ApplicationEventPublisher) this.getComponent(ApplicationEventPublisher.class));112 if (fetchAction == null) { 113 fetchAction = new ProjectFetchAction(); 114 fetchAction.setApplicationEventPublisher((ApplicationEventPublisher) this.getComponent(ApplicationEventPublisher.class)); 91 115 } 92 return this.fetchAction; 116 return fetchAction; 117 } 118 if (key == ProjectAddAction.class) { 119 if (addAction == null) { 120 addAction = new ProjectAddAction(); 121 addAction.setContentProvider((ProjectContentProvider) this.getComponent(ProjectContentProvider.class)); 122 } 123 return addAction; 124 } 125 if (key == ProjectApplyAction.class) { 126 if (applyAction == null) { 127 ProjectApplyAction applyAction = new ProjectApplyAction(); 128 applyAction.setDataSource((ProjectDataSource) this.getComponent(DataSource.class)); 129 } 130 return applyAction; 131 } 132 if (key == ProjectRemoveAction.class) { 133 if (removeAction == null) { 134 ProjectRemoveAction removeAction = new ProjectRemoveAction(); 135 removeAction.setDataSource((ProjectDataSource) this.getComponent(DataSource.class)); 136 } 137 return removeAction; 93 138 } 94 139 return null; org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/controllers/project/ProjectAddAction.java
r672 r684 3 3 import org.eclipse.swt.events.SelectionEvent; 4 4 import org.eclipse.swt.events.SelectionListener; 5 import org.jalcedo.client.examples.rails.models.Project; 6 import org.jalcedo.client.examples.rails.views.project.ProjectContentProvider; 5 7 6 8 public class ProjectAddAction implements SelectionListener { 9 10 private ProjectContentProvider contentProvider; 11 12 public ProjectContentProvider getContentProvider() { 13 return contentProvider; 14 } 15 16 public void setContentProvider(ProjectContentProvider contentProvider) { 17 this.contentProvider = contentProvider; 18 } 7 19 8 20 public void widgetDefaultSelected(SelectionEvent e) { … … 12 24 13 25 public void widgetSelected(SelectionEvent e) { 14 // TODO Auto-generated method stub15 26 Project project = new Project(); 27 this.getContentProvider().add(project); 16 28 } 17 29 org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/controllers/project/ProjectApplyAction.java
r672 r684 1 1 package org.jalcedo.client.examples.rails.controllers.project; 2 2 3 import org.eclipse.jface.viewers.ISelection; 4 import org.eclipse.jface.viewers.ISelectionProvider; 5 import org.eclipse.jface.viewers.IStructuredSelection; 3 6 import org.eclipse.swt.events.SelectionEvent; 4 7 import org.eclipse.swt.events.SelectionListener; 8 import org.jalcedo.client.examples.rails.models.Project; 9 import org.jalcedo.client.examples.rails.models.ProjectDataSource; 5 10 6 11 public class ProjectApplyAction implements SelectionListener { 12 13 private ProjectDataSource dataSource; 14 private ISelectionProvider selectionProvider; 15 16 public ISelectionProvider getSelectionProvider() { 17 return selectionProvider; 18 } 19 20 public void setSelectionProvider(ISelectionProvider selectionProvider) { 21 this.selectionProvider = selectionProvider; 22 } 23 24 public ProjectDataSource getDataSource() { 25 return dataSource; 26 } 27 28 public void setDataSource(ProjectDataSource dataSource) { 29 this.dataSource = dataSource; 30 } 7 31 8 32 public void widgetDefaultSelected(SelectionEvent e) { … … 12 36 13 37 public void widgetSelected(SelectionEvent e) { 14 // TODO Auto-generated method stub 15 38 ISelection selection = this.getSelectionProvider().getSelection(); 39 if (selection instanceof IStructuredSelection) { 40 IStructuredSelection ss = (IStructuredSelection) selection; 41 Project project = (Project) ss.getFirstElement(); 42 if (project.getId() == null) { 43 this.getDataSource().create(project); 44 } else { 45 this.getDataSource().edit(project); 46 } 47 } 16 48 } 17 49 org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/controllers/project/ProjectRemoveAction.java
r672 r684 1 1 package org.jalcedo.client.examples.rails.controllers.project; 2 2 3 import org.eclipse.jface.viewers.ISelection; 4 import org.eclipse.jface.viewers.ISelectionProvider; 5 import org.eclipse.jface.viewers.IStructuredSelection; 3 6 import org.eclipse.swt.events.SelectionEvent; 4 7 import org.eclipse.swt.events.SelectionListener; 8 import org.jalcedo.client.examples.rails.models.Project; 9 import org.jalcedo.client.examples.rails.models.ProjectDataSource; 5 10 6 11 public class ProjectRemoveAction implements SelectionListener { 12 13 private ProjectDataSource dataSource; 14 private ISelectionProvider selectionProvider; 15 16 public ISelectionProvider getSelectionProvider() { 17 return selectionProvider; 18 } 19 20 public void setSelectionProvider(ISelectionProvider selectionProvider) { 21 this.selectionProvider = selectionProvider; 22 } 23 24 public ProjectDataSource getDataSource() { 25 return dataSource; 26 } 27 28 public void setDataSource(ProjectDataSource dataSource) { 29 this.dataSource = dataSource; 30 } 7 31 8 32 public void widgetDefaultSelected(SelectionEvent e) { … … 12 36 13 37 public void widgetSelected(SelectionEvent e) { 14 // TODO Auto-generated method stub 15 38 ISelection selection = this.getSelectionProvider().getSelection(); 39 if (selection instanceof IStructuredSelection) { 40 IStructuredSelection ss = (IStructuredSelection) selection; 41 Project project = (Project) ss.getFirstElement(); 42 this.getDataSource().delete(project); 43 } 16 44 } 17 45 org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/views/project/ProjectContentProvider.java
r681 r684 1 1 package org.jalcedo.client.examples.rails.views.project; 2 2 3 import org.eclipse.jface.viewers.AbstractListViewer; 4 import org.eclipse.jface.viewers.AbstractTableViewer; 3 5 import org.eclipse.jface.viewers.ILabelProvider; 4 6 import org.eclipse.jface.viewers.IStructuredContentProvider; … … 35 37 this.viewer = viewer; 36 38 } 39 40 public void add(Object object) { 41 if (this.viewer instanceof AbstractTableViewer) { 42 ((AbstractTableViewer) this.viewer).add(object); 43 } else if (this.viewer instanceof AbstractListViewer) { 44 ((AbstractListViewer) this.viewer).add(object); 45 } 46 } 37 47 38 48 @Override … … 44 54 public void onApplicationEvent(ApplicationEvent event) { 45 55 if (event instanceof ProjectEvent) { 46 ProjectEvent pe = (ProjectEvent) event; 47 if (pe.getType() == ProjectEvent.REFRESH) { 48 this.viewer.setInput(this.getDataSource().findList().toArray()); 49 } 56 this.viewer.setInput(this.getDataSource().findList().toArray()); 50 57 } 51 58 } org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/views/project/ProjectView.java
r681 r684 52 52 DataBindingContext dbc = new DataBindingContext(); 53 53 dbc.bindValue(SWTObservables.observeText( 54 detailComposite.getFirstNameText(), SWT. None), firstNameObservable,55 new UpdateValueStrategy( false,56 UpdateValueStrategy.POLICY_ NEVER), null);54 detailComposite.getFirstNameText(), SWT.Modify), firstNameObservable, 55 new UpdateValueStrategy(true, 56 UpdateValueStrategy.POLICY_UPDATE), null); 57 57 dbc.bindValue(SWTObservables.observeText( 58 detailComposite.getDescText(), SWT. None), descObservable,59 new UpdateValueStrategy( false,60 UpdateValueStrategy.POLICY_ NEVER), null);58 detailComposite.getDescText(), SWT.Modify), descObservable, 59 new UpdateValueStrategy(true, 60 UpdateValueStrategy.POLICY_UPDATE), null); 61 61 } 62 62 }); … … 66 66 ProjectComponentsFactory factory) { 67 67 GridData gridData = new GridData(); 68 gridData.horizontalAlignment = GridData.FILL; 69 gridData.grabExcessHorizontalSpace = true; 68 70 ProjectDetailComposite composite = factory.createComposite(ProjectDetailComposite.class, parent, SWT.NONE); 69 71 composite.setLayoutData(gridData); … … 77 79 gridData.horizontalAlignment = GridData.FILL; 78 80 gridData.grabExcessHorizontalSpace = true; 79 gridData.verticalAlignment = GridData.CENTER; 81 gridData.grabExcessVerticalSpace = true; 82 gridData.verticalAlignment = GridData.FILL; 80 83 ProjectListComposite composite = factory.createComposite(ProjectListComposite.class, parent, SWT.NONE); 81 84 composite.setLayoutData(gridData);
