From c70383591c468ed1c289791f8b2bfaad12aca804 Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 25 Jan 2010 20:45:34 +0000 Subject: [PATCH] 298704 --- .../di/cdg/penelope/ui/annotation/View.java | 23 +++++++++++ .../ui/mvp/AbstractViewEnhancerAspect.aj | 38 ++++++++++++++++++ .../di/cdg/penelope/ui/mvp/IManagedView.java | 19 +++++++++ .../di/cdg/penelope/ui/mvp/IPresenter.java | 32 +++++++++++++++ .../src/test/ViewEnhancerIntegrationTest.java | 40 +++++++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/annotation/View.java create mode 100644 tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/mvp/AbstractViewEnhancerAspect.aj create mode 100644 tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/mvp/IManagedView.java create mode 100644 tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/mvp/IPresenter.java create mode 100644 tests/multiIncremental/pr298704_testaspects/base/src/test/ViewEnhancerIntegrationTest.java diff --git a/tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/annotation/View.java b/tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/annotation/View.java new file mode 100644 index 000000000..c69ae7121 --- /dev/null +++ b/tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/annotation/View.java @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2009 Collaborative Development Group, C.S. Dept., University of Bari + * + * All rights reserved. This program and the accompanying materials are made available under + * the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + */ +package it.uniba.di.cdg.penelope.ui.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks views to be injected. + */ +@Retention( RetentionPolicy.RUNTIME ) +@Target( ElementType.TYPE ) +@Inherited +public @interface View { +} diff --git a/tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/mvp/AbstractViewEnhancerAspect.aj b/tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/mvp/AbstractViewEnhancerAspect.aj new file mode 100644 index 000000000..80dd4650d --- /dev/null +++ b/tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/mvp/AbstractViewEnhancerAspect.aj @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2009 Collaborative Development Group, C.S. Dept., University of Bari + * + * All rights reserved. This program and the accompanying materials are made available under + * the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + */ +package it.uniba.di.cdg.penelope.ui.mvp; + +import it.uniba.di.cdg.penelope.ui.annotation.View; + +import java.util.ArrayList; +import java.util.List; + +/** + * Augments views with support for View events. + */ +public abstract aspect AbstractViewEnhancerAspect { + pointcut scope(); + + declare parents: (@View *) implements IManagedView; + + private final List IManagedView.presenters = new ArrayList(); + + public void IManagedView.fire( Object event ) { + for (IPresenter presenter : presenters) { + presenter.dispatchEvent( event ); + } + } + + public void IManagedView.registerPresenter( IPresenter presenter ) { + presenters.add( presenter ); + } + + public void IManagedView.unregisterPresenter( IPresenter presenter ) { + presenters.remove( presenter ); + } +} diff --git a/tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/mvp/IManagedView.java b/tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/mvp/IManagedView.java new file mode 100644 index 000000000..7be156875 --- /dev/null +++ b/tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/mvp/IManagedView.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2009 Collaborative Development Group, C.S. Dept., University of Bari + * + * All rights reserved. This program and the accompanying materials are made available under + * the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + */ +package it.uniba.di.cdg.penelope.ui.mvp; + +/** + * + */ +public interface IManagedView { + void fire( Object event ); + + void registerPresenter( IPresenter presenter ); + + void unregisterPresenter( IPresenter presenter ); +} diff --git a/tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/mvp/IPresenter.java b/tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/mvp/IPresenter.java new file mode 100644 index 000000000..6cdb46dfb --- /dev/null +++ b/tests/multiIncremental/pr298704_baseaspects/base/src/it/uniba/di/cdg/penelope/ui/mvp/IPresenter.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2009 Collaborative Development Group, C.S. Dept., University of Bari + * + * All rights reserved. This program and the accompanying materials are made available under + * the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + */ +package it.uniba.di.cdg.penelope.ui.mvp; + +import java.beans.PropertyChangeListener; + +/** + * Basic interface for Presenter implementations. Within Penelope, a Presenter is a supervising controller + * which reacts to view events (see the View Events mechanism): the view just displays the session state stored within + * the Presentation Model. + */ +public interface IPresenter extends PropertyChangeListener { + /** + * View has been created. + */ + void onViewCreated(); + + /** + * View has been destroyed. + */ + void onViewDisposed(); + + /** + * @param event + */ + void dispatchEvent( Object event ); +} diff --git a/tests/multiIncremental/pr298704_testaspects/base/src/test/ViewEnhancerIntegrationTest.java b/tests/multiIncremental/pr298704_testaspects/base/src/test/ViewEnhancerIntegrationTest.java new file mode 100644 index 000000000..a10ddd060 --- /dev/null +++ b/tests/multiIncremental/pr298704_testaspects/base/src/test/ViewEnhancerIntegrationTest.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2009 Collaborative Development Group, C.S. Dept., University of Bari + * + * All rights reserved. This program and the accompanying materials are made available under + * the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + */ +package test; + +import it.uniba.di.cdg.penelope.ui.annotation.View; +import it.uniba.di.cdg.penelope.ui.mvp.IManagedView; +import it.uniba.di.cdg.penelope.ui.mvp.AbstractViewEnhancerAspect; + +/** + * + */ +public class ViewEnhancerIntegrationTest { + +@View + public static class MockView { + + } + + static aspect ViewEnhancerAspect extends AbstractViewEnhancerAspect { + pointcut scope() : within( test.ViewEnhancerIntegrationTest ); + } + + public void simulateViewCreation() { + } + + public void shouldAugmentView() { + //given @View class has been augmented + + //when + MockView view = new MockView(); + + //then + // assertTrue( view instanceof IManagedView ); + } +} -- 2.39.5