Changeset 684

Show
Ignore:
Timestamp:
05/30/07 20:11:46 (2 years ago)
Author:
yuanying
Message:

Project Editor is now available.

Files:

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  
    88import org.jalcedo.client.events.ApplicationEventPublisher; 
    99import org.jalcedo.client.events.DefaultEventPublisher; 
     10import org.jalcedo.client.examples.rails.controllers.project.ProjectAddAction; 
     11import org.jalcedo.client.examples.rails.controllers.project.ProjectApplyAction; 
    1012import org.jalcedo.client.examples.rails.controllers.project.ProjectFetchAction; 
     13import org.jalcedo.client.examples.rails.controllers.project.ProjectRemoveAction; 
    1114import org.jalcedo.client.examples.rails.models.Project; 
    1215import org.jalcedo.client.examples.rails.models.ProjectDataSource; 
     
    2124public class ProjectComponentsFactory { 
    2225     
     26    private ProjectListComposite listComposite; 
     27    private ProjectDetailComposite detailComposite; 
     28     
    2329    @SuppressWarnings("unchecked") 
    2430    public <T extends Composite> T createComposite(Class<T> clazz, Composite parent, int style) { 
    2531        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); 
    2736            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; 
    3246        } 
    3347        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; 
    3657        } 
    3758        return null; 
     
    4364    private ProjectContentProvider contentProvider; 
    4465    private ProjectFetchAction fetchAction; 
     66    private ProjectAddAction addAction; 
     67    private ProjectApplyAction applyAction; 
     68    private ProjectRemoveAction removeAction; 
    4569     
    4670    @SuppressWarnings("unchecked") 
     
    77101                key == ProjectContentProvider.class 
    78102            ) { 
    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)); 
    84108            } 
    85             return this.contentProvider; 
     109            return contentProvider; 
    86110        } 
    87111        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)); 
    91115            } 
    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; 
    93138        } 
    94139        return null; 
  • org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/controllers/project/ProjectAddAction.java

    r672 r684  
    33import org.eclipse.swt.events.SelectionEvent; 
    44import org.eclipse.swt.events.SelectionListener; 
     5import org.jalcedo.client.examples.rails.models.Project; 
     6import org.jalcedo.client.examples.rails.views.project.ProjectContentProvider; 
    57 
    68public 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    } 
    719 
    820    public void widgetDefaultSelected(SelectionEvent e) { 
     
    1224 
    1325    public void widgetSelected(SelectionEvent e) { 
    14         // TODO Auto-generated method stub 
    15  
     26        Project project = new Project(); 
     27        this.getContentProvider().add(project); 
    1628    } 
    1729 
  • org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/controllers/project/ProjectApplyAction.java

    r672 r684  
    11package org.jalcedo.client.examples.rails.controllers.project; 
    22 
     3import org.eclipse.jface.viewers.ISelection; 
     4import org.eclipse.jface.viewers.ISelectionProvider; 
     5import org.eclipse.jface.viewers.IStructuredSelection; 
    36import org.eclipse.swt.events.SelectionEvent; 
    47import org.eclipse.swt.events.SelectionListener; 
     8import org.jalcedo.client.examples.rails.models.Project; 
     9import org.jalcedo.client.examples.rails.models.ProjectDataSource; 
    510 
    611public 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    } 
    731 
    832    public void widgetDefaultSelected(SelectionEvent e) { 
     
    1236 
    1337    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        } 
    1648    } 
    1749 
  • org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/controllers/project/ProjectRemoveAction.java

    r672 r684  
    11package org.jalcedo.client.examples.rails.controllers.project; 
    22 
     3import org.eclipse.jface.viewers.ISelection; 
     4import org.eclipse.jface.viewers.ISelectionProvider; 
     5import org.eclipse.jface.viewers.IStructuredSelection; 
    36import org.eclipse.swt.events.SelectionEvent; 
    47import org.eclipse.swt.events.SelectionListener; 
     8import org.jalcedo.client.examples.rails.models.Project; 
     9import org.jalcedo.client.examples.rails.models.ProjectDataSource; 
    510 
    611public 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    } 
    731 
    832    public void widgetDefaultSelected(SelectionEvent e) { 
     
    1236 
    1337    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        } 
    1644    } 
    1745 
  • org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/views/project/ProjectContentProvider.java

    r681 r684  
    11package org.jalcedo.client.examples.rails.views.project; 
    22 
     3import org.eclipse.jface.viewers.AbstractListViewer; 
     4import org.eclipse.jface.viewers.AbstractTableViewer; 
    35import org.eclipse.jface.viewers.ILabelProvider; 
    46import org.eclipse.jface.viewers.IStructuredContentProvider; 
     
    3537        this.viewer = viewer; 
    3638    } 
     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    } 
    3747 
    3848    @Override 
     
    4454    public void onApplicationEvent(ApplicationEvent event) { 
    4555        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()); 
    5057        } 
    5158    } 
  • org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/views/project/ProjectView.java

    r681 r684  
    5252                DataBindingContext dbc = new DataBindingContext(); 
    5353                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); 
    5757                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); 
    6161            } 
    6262        }); 
     
    6666            ProjectComponentsFactory factory) { 
    6767        GridData gridData = new GridData(); 
     68        gridData.horizontalAlignment = GridData.FILL; 
     69        gridData.grabExcessHorizontalSpace = true; 
    6870        ProjectDetailComposite composite = factory.createComposite(ProjectDetailComposite.class, parent, SWT.NONE); 
    6971        composite.setLayoutData(gridData); 
     
    7779        gridData.horizontalAlignment = GridData.FILL; 
    7880        gridData.grabExcessHorizontalSpace = true; 
    79         gridData.verticalAlignment = GridData.CENTER; 
     81        gridData.grabExcessVerticalSpace = true; 
     82        gridData.verticalAlignment = GridData.FILL; 
    8083        ProjectListComposite composite = factory.createComposite(ProjectListComposite.class, parent, SWT.NONE); 
    8184        composite.setLayoutData(gridData);