Changeset 679

Show
Ignore:
Timestamp:
05/29/07 01:25:04 (2 years ago)
Author:
yuanying
Message:

Server application is added.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/META-INF/MANIFEST.MF

    r666 r679  
    88Require-Bundle: org.eclipse.ui, 
    99 org.eclipse.core.runtime, 
    10  org.jalcedo.client.jface 
     10 org.jalcedo.client.jface, 
     11 org.jalcedo.client.rest 
    1112Eclipse-LazyStart: true 
  • org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/ProjectComponentsFactory.java

    r672 r679  
    22 
    33import org.eclipse.swt.widgets.Composite; 
     4import org.jalcedo.client.ds.DataSource; 
    45import org.jalcedo.client.events.ApplicationEventPublisher; 
    56import org.jalcedo.client.events.DefaultEventPublisher; 
     7import org.jalcedo.client.examples.rails.models.Project; 
    68import org.jalcedo.client.examples.rails.models.ProjectDataSource; 
    79import org.jalcedo.client.examples.rails.views.project.ProjectDetailComposite; 
    810import org.jalcedo.client.examples.rails.views.project.ProjectListComposite; 
     11import org.jalcedo.client.rest.connect.Connection; 
     12import org.jalcedo.client.rest.connect.HttpClientConnection; 
     13import org.jalcedo.client.rest.convert.Converter; 
     14import org.jalcedo.client.rest.convert.JSONConverter; 
    915 
    1016public class ProjectComponentsFactory { 
     
    2329    } 
    2430     
     31    private HttpClientConnection connection; 
     32    private Converter<Project> converter; 
    2533    private ProjectDataSource projectDataSource; 
    2634     
    2735    @SuppressWarnings("unchecked") 
    28     public synchronized <T> T getComponent(Class<T> clazz) { 
    29         if (clazz == ApplicationEventPublisher.class) { 
    30             return (T) DefaultEventPublisher.getDefault(); 
     36    public synchronized Object getComponent(Object key) { 
     37        if (key == ApplicationEventPublisher.class) { 
     38            return DefaultEventPublisher.getDefault(); 
    3139        } 
    32         if (clazz == ProjectDataSource.class) { 
     40        if (key == DataSource.class) { 
    3341            if (this.projectDataSource == null) { 
    3442                this.projectDataSource = new ProjectDataSource(); 
    35                 this.projectDataSource.setApplicationEventPublisher(this.getComponent(ApplicationEventPublisher.class)); 
     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)); 
    3646            } 
    37             return (T) this.projectDataSource; 
     47            return this.projectDataSource; 
     48        } 
     49        if (key == Connection.class) { 
     50            if (this.connection == null) { 
     51                this.connection = new HttpClientConnection(); 
     52                this.connection.setFollowRedirects(true); 
     53            } 
     54            return this.connection; 
     55        } 
     56        if (key == Converter.class) { 
     57            if (this.converter == null) { 
     58                this.converter = new JSONConverter<Project>(Project.class); 
     59            } 
     60            return this.converter; 
    3861        } 
    3962        return null; 
  • org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/controllers/project/ProjectFetchAction.java

    r672 r679  
    33import org.eclipse.swt.events.SelectionEvent; 
    44import org.eclipse.swt.events.SelectionListener; 
     5import org.jalcedo.client.events.ApplicationEventPublisher; 
     6import org.jalcedo.client.examples.rails.models.ProjectEvent; 
    57 
    68public class ProjectFetchAction implements SelectionListener { 
     9     
     10    private ApplicationEventPublisher applicationEventPublisher; 
     11 
     12    public ApplicationEventPublisher getApplicationEventPublisher() { 
     13        return applicationEventPublisher; 
     14    } 
     15 
     16    public void setApplicationEventPublisher( 
     17            ApplicationEventPublisher applicationEventPublisher) { 
     18        this.applicationEventPublisher = applicationEventPublisher; 
     19    } 
    720 
    821    public void widgetDefaultSelected(SelectionEvent e) { 
     
    1225 
    1326    public void widgetSelected(SelectionEvent e) { 
    14         // TODO Auto-generated method stub 
    15  
     27        this.getApplicationEventPublisher().publishEvent(new ProjectEvent(this, ProjectEvent.REFRESH)); 
    1628    } 
    1729 
  • org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/models/ProjectDataSource.java

    r672 r679  
    55import org.jalcedo.client.ds.DataSource; 
    66import org.jalcedo.client.events.ApplicationEventPublisher; 
     7import org.jalcedo.client.rest.connect.Connection; 
     8import org.jalcedo.client.rest.convert.Converter; 
    79 
    810public class ProjectDataSource implements DataSource<Integer, Project> { 
    911     
    1012    private ApplicationEventPublisher applicationEventPublisher; 
     13     
     14    private Connection connection; 
     15     
     16    private Converter<Project> converter; 
     17 
     18    public Connection getConnection() { 
     19        return connection; 
     20    } 
     21 
     22    public void setConnection(Connection connection) { 
     23        this.connection = connection; 
     24    } 
     25 
     26    public Converter<Project> getConverter() { 
     27        return converter; 
     28    } 
     29 
     30    public void setConverter(Converter<Project> converter) { 
     31        this.converter = converter; 
     32    } 
    1133 
    1234    public ApplicationEventPublisher getApplicationEventPublisher() { 
     
    4062 
    4163    public List<Project> findList() { 
    42         // TODO Auto-generated method stub 
    43         return null
     64        String source = this.getConnection().get("http://localhost:3000/projects.json", null); 
     65        return this.getConverter().toList(source)
    4466    } 
    4567 
  • org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/views/project/ProjectContentProvider.java

    r672 r679  
    11package org.jalcedo.client.examples.rails.views.project; 
    22 
    3 public class ProjectContentProvider { 
     3import org.eclipse.jface.viewers.ILabelProvider; 
     4import org.eclipse.jface.viewers.IStructuredContentProvider; 
     5import org.eclipse.jface.viewers.LabelProvider; 
     6import org.eclipse.jface.viewers.Viewer; 
     7import org.jalcedo.client.ds.DataSource; 
     8import org.jalcedo.client.events.ApplicationEvent; 
     9import org.jalcedo.client.events.ApplicationEventListener; 
     10import org.jalcedo.client.examples.rails.models.Project; 
     11import org.jalcedo.client.examples.rails.models.ProjectEvent; 
     12 
     13public class ProjectContentProvider extends LabelProvider implements  
     14    IStructuredContentProvider,  
     15    ILabelProvider,  
     16    ApplicationEventListener { 
     17     
     18    private Viewer viewer; 
     19     
     20    private DataSource<Integer, Project> dataSource; 
     21 
     22    public DataSource<Integer, Project> getDataSource() { 
     23        return dataSource; 
     24    } 
     25 
     26    public void setDataSource(DataSource<Integer, Project> dataSource) { 
     27        this.dataSource = dataSource; 
     28    } 
     29 
     30    public Object[] getElements(Object inputElement) { 
     31        return this.getDataSource().findList().toArray(); 
     32    } 
     33 
     34    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 
     35        this.viewer = viewer; 
     36    } 
     37 
     38    @Override 
     39    public String getText(Object element) { 
     40        // TODO Auto-generated method stub 
     41        return super.getText(element); 
     42    } 
     43 
     44    public void onApplicationEvent(ApplicationEvent event) { 
     45        if (event instanceof ProjectEvent && this.viewer != null) { 
     46            this.viewer.refresh(); 
     47        } 
     48    } 
    449 
    550} 
  • org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/views/project/ProjectDetailComposite.java

    r673 r679  
    1818    private Label   descLabel = null; 
    1919    private Text    descText = null; 
    20  
    2120    private Group detailGroup = null; 
    22  
     21    private Composite applyComposite = null; 
    2322    private Button applyButton = null; 
     23    private Button removeButton = null; 
    2424 
    2525    public ProjectDetailComposite(Composite parent, int style) { 
     
    3030    public Button getApplyButton() { 
    3131        return applyButton; 
     32    } 
     33 
     34    public Button getRemoveButton() { 
     35        return removeButton; 
    3236    } 
    3337 
     
    9094     */ 
    9195    private void createDetailGroup() { 
     96        GridLayout gridLayout2 = new GridLayout(); 
     97        gridLayout2.numColumns = 1; 
     98        detailGroup = new Group(this, SWT.NONE); 
     99        createDetailComposite(); 
     100        detailGroup.setLayout(gridLayout2); 
     101        createApplyComposite(); 
     102    } 
     103 
     104    /** 
     105     * This method initializes applyComposite    
     106     * 
     107     */ 
     108    private void createApplyComposite() { 
    92109        GridData gridData3 = new GridData(); 
    93110        gridData3.horizontalAlignment = GridData.END; 
    94111        gridData3.verticalAlignment = GridData.CENTER; 
    95         detailGroup = new Group(this, SWT.NONE); 
    96         detailGroup.setLayout(new GridLayout()); 
    97         createDetailComposite(); 
    98         applyButton = new Button(detailGroup, SWT.NONE); 
     112        GridLayout gridLayout3 = new GridLayout(); 
     113        gridLayout3.numColumns = 2; 
     114        applyComposite = new Composite(detailGroup, SWT.NONE); 
     115        applyComposite.setLayout(gridLayout3); 
     116        applyComposite.setLayoutData(gridData3); 
     117        removeButton = new Button(applyComposite, SWT.NONE); 
     118        removeButton.setText("Remove"); 
     119        applyButton = new Button(applyComposite, SWT.NONE); 
    99120        applyButton.setText("Apply"); 
    100         applyButton.setLayoutData(gridData3); 
    101121    } 
    102122} 
  • org.jalcedo.client.examples/trunk/org.jalcedo.client.examples.rails/src/org/jalcedo/client/examples/rails/views/project/ProjectListComposite.java

    r673 r679  
    1515    private Button addButton = null; 
    1616    private Button fetchButton = null; 
    17     private Button removeButton = null; 
    1817    private ListViewer listViewer = null; 
    1918 
     
    3332    public Button getFetchButton() { 
    3433        return fetchButton; 
    35     } 
    36  
    37     public Button getRemoveButton() { 
    38         return removeButton; 
    3934    } 
    4035 
     
    6560        gridData5.horizontalAlignment = GridData.FILL; 
    6661        gridData5.verticalAlignment = GridData.CENTER; 
    67         GridData gridData4 = new GridData(); 
    68         gridData4.horizontalAlignment = GridData.FILL; 
    69         gridData4.verticalAlignment = GridData.CENTER; 
    7062        GridData gridData3 = new GridData(); 
    7163        gridData3.grabExcessHorizontalSpace = false; 
     
    8577        fetchButton.setText("Fetch"); 
    8678        fetchButton.setLayoutData(gridData3); 
    87         removeButton = new Button(menuComposite, SWT.NONE); 
    88         removeButton.setText("Remove"); 
    89         removeButton.setLayoutData(gridData4); 
    9079        addButton = new Button(getMenuComposite(), SWT.NONE); 
    9180        addButton.setText("Add");