| 27 | | private ProjectListComposite listComposite; |
|---|
| 28 | | private ProjectDetailComposite detailComposite; |
|---|
| 29 | | |
|---|
| 30 | | @SuppressWarnings("unchecked") |
|---|
| 31 | | public <T extends Composite> T createComposite(Class<T> clazz, Composite parent, int style) { |
|---|
| 32 | | if (clazz == ProjectListComposite.class) { |
|---|
| 33 | | if (listComposite != null) { |
|---|
| 34 | | throw new RuntimeException("List Composite is only create once time."); |
|---|
| 35 | | } |
|---|
| 36 | | listComposite = new ProjectListComposite(parent, style); |
|---|
| 37 | | ProjectContentProvider contentProvider = (ProjectContentProvider) this.getComponent(ProjectContentProvider.class); |
|---|
| 38 | | listComposite.getListViewer().setContentProvider(contentProvider); |
|---|
| 39 | | listComposite.getListViewer().setLabelProvider(contentProvider); |
|---|
| 40 | | listComposite.getFetchButton().addSelectionListener((ProjectFetchAction) this.getComponent(ProjectFetchAction.class)); |
|---|
| 41 | | listComposite.getAddButton().addSelectionListener((ProjectAddAction) this.getComponent(ProjectAddAction.class)); |
|---|
| 42 | | ProjectApplyAction applyAction = (ProjectApplyAction) this.getComponent(ProjectApplyAction.class); |
|---|
| 43 | | applyAction.setSelectionProvider(listComposite.getListViewer()); |
|---|
| 44 | | listComposite.getApplyButton().addSelectionListener(applyAction); |
|---|
| 45 | | ProjectRemoveAction removeAction = (ProjectRemoveAction) this.getComponent(ProjectRemoveAction.class); |
|---|
| 46 | | removeAction.setSelectionProvider(listComposite.getListViewer()); |
|---|
| 47 | | listComposite.getRemoveButton().addSelectionListener(removeAction); |
|---|
| 48 | | return (T) listComposite; |
|---|
| 49 | | } |
|---|
| 50 | | if (clazz == ProjectDetailComposite.class) { |
|---|
| 51 | | if (detailComposite != null) { |
|---|
| 52 | | throw new RuntimeException("Detail Composite is only create once time."); |
|---|
| 53 | | } |
|---|
| 54 | | detailComposite = new ProjectDetailComposite(parent, style); |
|---|
| 55 | | return (T) detailComposite; |
|---|
| 56 | | } |
|---|
| 57 | | return null; |
|---|
| | 22 | public ProjectListComposite createListComposite(Composite parent, int style) { |
|---|
| | 23 | ApplicationEventPublisher applicationEventPublisher = DefaultEventPublisher.getDefault(); |
|---|
| | 24 | |
|---|
| | 25 | HttpClientConnection connection = new JSONAcceptableHttpConnection(); |
|---|
| | 26 | connection.setFollowRedirects(true); |
|---|
| | 27 | |
|---|
| | 28 | Converter<Project> converter = new JSONConverter<Project>(Project.class); |
|---|
| | 29 | |
|---|
| | 30 | ProjectDataSource dataSource = new ProjectDataSource(); |
|---|
| | 31 | dataSource.setApplicationEventPublisher(applicationEventPublisher); |
|---|
| | 32 | dataSource.setConnection(connection); |
|---|
| | 33 | dataSource.setConverter(converter); |
|---|
| | 34 | |
|---|
| | 35 | ProjectContentProvider contentProvider = new ProjectContentProvider(); |
|---|
| | 36 | contentProvider.setDataSource(dataSource); |
|---|
| | 37 | applicationEventPublisher.addListener(contentProvider); |
|---|
| | 38 | |
|---|
| | 39 | ProjectListComposite listComposite = new ProjectListComposite(parent, style); |
|---|
| | 40 | listComposite.getListViewer().setContentProvider(contentProvider); |
|---|
| | 41 | listComposite.getListViewer().setLabelProvider(contentProvider); |
|---|
| | 42 | |
|---|
| | 43 | ProjectFetchAction fetchAction = new ProjectFetchAction(); |
|---|
| | 44 | fetchAction.setApplicationEventPublisher(applicationEventPublisher); |
|---|
| | 45 | |
|---|
| | 46 | ProjectAddAction addAction = new ProjectAddAction(); |
|---|
| | 47 | addAction.setContentProvider(contentProvider); |
|---|
| | 48 | |
|---|
| | 49 | ProjectApplyAction applyAction = new ProjectApplyAction(); |
|---|
| | 50 | applyAction.setDataSource(dataSource); |
|---|
| | 51 | applyAction.setSelectionProvider(listComposite.getListViewer()); |
|---|
| | 52 | |
|---|
| | 53 | ProjectRemoveAction removeAction = new ProjectRemoveAction(); |
|---|
| | 54 | removeAction.setDataSource(dataSource); |
|---|
| | 55 | removeAction.setSelectionProvider(listComposite.getListViewer()); |
|---|
| | 56 | |
|---|
| | 57 | return listComposite; |
|---|
| 60 | | private HttpClientConnection connection; |
|---|
| 61 | | private Converter<Project> converter; |
|---|
| 62 | | private ProjectDataSource dataSource; |
|---|
| 63 | | private ProjectContentProvider contentProvider; |
|---|
| 64 | | private ProjectFetchAction fetchAction; |
|---|
| 65 | | private ProjectAddAction addAction; |
|---|
| 66 | | private ProjectApplyAction applyAction; |
|---|
| 67 | | private ProjectRemoveAction removeAction; |
|---|
| 68 | | |
|---|
| 69 | | @SuppressWarnings("unchecked") |
|---|
| 70 | | public synchronized Object getComponent(Object key) { |
|---|
| 71 | | if (key == ApplicationEventPublisher.class) { |
|---|
| 72 | | return DefaultEventPublisher.getDefault(); |
|---|
| 73 | | } |
|---|
| 74 | | if (key == DataSource.class) { |
|---|
| 75 | | if (this.dataSource == null) { |
|---|
| 76 | | this.dataSource = new ProjectDataSource(); |
|---|
| 77 | | this.dataSource.setApplicationEventPublisher((ApplicationEventPublisher) this.getComponent(ApplicationEventPublisher.class)); |
|---|
| 78 | | this.dataSource.setConnection((Connection) this.getComponent(Connection.class)); |
|---|
| 79 | | this.dataSource.setConverter((Converter<Project>) this.getComponent(Converter.class)); |
|---|
| 80 | | } |
|---|
| 81 | | return this.dataSource; |
|---|
| 82 | | } |
|---|
| 83 | | if (key == Connection.class) { |
|---|
| 84 | | if (this.connection == null) { |
|---|
| 85 | | this.connection = new JSONAcceptableHttpConnection(); |
|---|
| 86 | | this.connection.setFollowRedirects(true); |
|---|
| 87 | | } |
|---|
| 88 | | return this.connection; |
|---|
| 89 | | } |
|---|
| 90 | | if (key == Converter.class) { |
|---|
| 91 | | if (this.converter == null) { |
|---|
| 92 | | this.converter = new JSONConverter<Project>(Project.class); |
|---|
| 93 | | } |
|---|
| 94 | | return this.converter; |
|---|
| 95 | | } |
|---|
| 96 | | if ( |
|---|
| 97 | | key == IContentProvider.class || |
|---|
| 98 | | key == IStructuredContentProvider.class || |
|---|
| 99 | | key == ILabelProvider.class || |
|---|
| 100 | | key == ProjectContentProvider.class |
|---|
| 101 | | ) { |
|---|
| 102 | | if (contentProvider == null) { |
|---|
| 103 | | contentProvider = new ProjectContentProvider(); |
|---|
| 104 | | ApplicationEventPublisher applicationEventPublisher = (ApplicationEventPublisher) this.getComponent(ApplicationEventPublisher.class); |
|---|
| 105 | | applicationEventPublisher.addListener(contentProvider); |
|---|
| 106 | | contentProvider.setDataSource((DataSource<Integer, Project>) this.getComponent(DataSource.class)); |
|---|
| 107 | | } |
|---|
| 108 | | return contentProvider; |
|---|
| 109 | | } |
|---|
| 110 | | if (key == ProjectFetchAction.class) { |
|---|
| 111 | | if (fetchAction == null) { |
|---|
| 112 | | fetchAction = new ProjectFetchAction(); |
|---|
| 113 | | fetchAction.setApplicationEventPublisher((ApplicationEventPublisher) this.getComponent(ApplicationEventPublisher.class)); |
|---|
| 114 | | } |
|---|
| 115 | | return fetchAction; |
|---|
| 116 | | } |
|---|
| 117 | | if (key == ProjectAddAction.class) { |
|---|
| 118 | | if (addAction == null) { |
|---|
| 119 | | addAction = new ProjectAddAction(); |
|---|
| 120 | | addAction.setContentProvider((ProjectContentProvider) this.getComponent(ProjectContentProvider.class)); |
|---|
| 121 | | } |
|---|
| 122 | | return addAction; |
|---|
| 123 | | } |
|---|
| 124 | | if (key == ProjectApplyAction.class) { |
|---|
| 125 | | if (applyAction == null) { |
|---|
| 126 | | applyAction = new ProjectApplyAction(); |
|---|
| 127 | | applyAction.setDataSource((ProjectDataSource) this.getComponent(DataSource.class)); |
|---|
| 128 | | } |
|---|
| 129 | | return applyAction; |
|---|
| 130 | | } |
|---|
| 131 | | if (key == ProjectRemoveAction.class) { |
|---|
| 132 | | if (removeAction == null) { |
|---|
| 133 | | removeAction = new ProjectRemoveAction(); |
|---|
| 134 | | removeAction.setDataSource((ProjectDataSource) this.getComponent(DataSource.class)); |
|---|
| 135 | | } |
|---|
| 136 | | return removeAction; |
|---|
| 137 | | } |
|---|
| 138 | | throw new RuntimeException("No Component is found."); |
|---|
| | 60 | public ProjectDetailComposite createDetailComposite(Composite parent, int style) { |
|---|
| | 61 | ProjectDetailComposite detailComposite = new ProjectDetailComposite(parent, style); |
|---|
| | 62 | return detailComposite; |
|---|