Project

General

Profile

Revision 7b6f4230

ID7b6f42304d1105a719fad1945b063cf876806d7d
Parent 67aa5f47
Child 0b44c814

Added by Andreas Kohlbecker almost 4 years ago

adding spring-mvp framework

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/phycobank/RegistrationWorkflowView.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.view.phycobank;
10

  
11
import com.vaadin.navigator.View;
12
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
13
import com.vaadin.spring.annotation.SpringView;
14

  
15
import eu.etaxonomy.cdm.vaadin.design.phycobank.RegistrationWorkflowDesign;
16
import eu.etaxonomy.cdm.vaadin.presenter.phycobank.RegistrationType;
17

  
18
/**
19
 * @author a.kohlbecker
20
 * @since Mar 2, 2017
21
 *
22
 */
23
@SpringView(name=RegistrationWorkflowView.NAME)
24
public class RegistrationWorkflowView extends RegistrationWorkflowDesign implements View {
25

  
26
    private static final long serialVersionUID = -213040114015958970L;
27

  
28
    public static final String NAME = "workflow";
29

  
30
    RegistrationType regType = null;
31

  
32
    /**
33
     * {@inheritDoc}
34
     */
35
    @Override
36
    public void enter(ViewChangeEvent event) {
37
        if(event.getParameters() != null){
38
           String[] params = event.getParameters().split("/");
39
           if(params.length > 0){
40
               regType = RegistrationType.valueOf(params[0]);
41
               title.setValue(title.getValue() + "  " + regType.name() + " ...");
42
           }
43
        }
44

  
45
    }
46

  
47
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/phycobank/RegistrationWorkflowViewBean.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.view.phycobank;
10

  
11
import com.vaadin.navigator.View;
12
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
13
import com.vaadin.spring.annotation.SpringView;
14

  
15
import eu.etaxonomy.cdm.vaadin.design.phycobank.RegistrationWorkflowDesign;
16
import eu.etaxonomy.cdm.vaadin.presenter.phycobank.RegistrationType;
17

  
18
/**
19
 * @author a.kohlbecker
20
 * @since Mar 2, 2017
21
 *
22
 */
23
@SpringView(name=RegistrationWorkflowView.NAME)
24
public class RegistrationWorkflowView extends RegistrationWorkflowDesign implements View {
25

  
26
    private static final long serialVersionUID = -213040114015958970L;
27

  
28
    public static final String NAME = "workflow";
29

  
30
    RegistrationType regType = null;
31

  
32
    /**
33
     * {@inheritDoc}
34
     */
35
    @Override
36
    public void enter(ViewChangeEvent event) {
37
        if(event.getParameters() != null){
38
           String[] params = event.getParameters().split("/");
39
           if(params.length > 0){
40
               regType = RegistrationType.valueOf(params[0]);
41
               title.setValue(title.getValue() + "  " + regType.name() + " ...");
42
           }
43
        }
44

  
45
    }
46

  
47
}
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPresenter.java
1
package eu.etaxonomy.vaadin.mvp;
2

  
3
import java.util.logging.Logger;
4

  
5
import com.vaadin.spring.annotation.SpringComponent;
6

  
7
/**
8
 * AbstractPresenter is the base class of all presenter components. Presenter's
9
 * role is to govern the view and control the complex UI logic based on
10
 * notifications presenter receives from its view.
11
 *
12
 * @author Peter / Vaadin
13
 *
14
 * @param <V>
15
 *            type of the view this presenter governs
16
 */
17
@SpringComponent
18
public abstract class AbstractPresenter<V extends ApplicationView> {
19

  
20
	private V view;
21

  
22
	protected V getView() {
23
		return view;
24
	}
25

  
26
	/**
27
	 * Notifies the presenter that its view is initialized so that presenter can
28
	 * start its own initialization if required.
29
	 *
30
	 * @param view
31
	 */
32
	protected final void init(V view) {
33
		Logger.getLogger(getClass().getName()).info("Presenter init");
34
		this.view = view;
35
		onPresenterReady();
36
	}
37

  
38
	/**
39
	 * Extending classes should overwrite this method in order to perform logic
40
	 * after presenter has finished initializing.
41
	 */
42
	protected void onPresenterReady() {
43
		Logger.getLogger(getClass().getName()).info("Presenter ready");
44
	}
45

  
46
	/**
47
	 * Extending classes should overwrite this method to react to the event when
48
	 * user has navigated into the view that this presenter governs.
49
	 */
50
	public void onViewEnter() {
51
		Logger.getLogger(getClass().getName()).info("View entered");
52
	}
53

  
54
	public void onViewExit() {
55

  
56
	}
57
}
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractView.java
1
package eu.etaxonomy.vaadin.mvp;
2

  
3
import java.util.logging.Logger;
4

  
5
import javax.annotation.PostConstruct;
6

  
7
import org.springframework.beans.BeansException;
8
import org.springframework.context.ApplicationContext;
9
import org.springframework.context.ApplicationContextAware;
10

  
11
import com.vaadin.ui.CustomComponent;
12

  
13
/**
14
 * AbstractView is the base class of all MVP views. It takes care of finding
15
 * appropriate presenter component for the view.
16
 * 
17
 * @param
18
 * 			<P>
19
 *            type of the presenter this view uses.
20
 * 
21
 * @author Peter / Vaadin
22
 */
23
public abstract class AbstractView<P extends AbstractPresenter> extends CustomComponent
24
		implements ApplicationContextAware {
25

  
26
	private P presenter;
27

  
28
	private ApplicationContext applicationContext;
29

  
30
	@PostConstruct
31
	protected final void init() {
32
		Logger.getLogger(getClass().getSimpleName()).info("View init");
33
		presenter.init((ApplicationView) this);
34

  
35
		onViewReady();
36
	}
37

  
38
	protected void setPresenter(P presenter) {
39
		this.presenter = presenter;
40
	}
41

  
42
	protected abstract void injectPresenter(P presenter);
43

  
44
	@Override
45
	public void detach() {
46
		getPresenter().onViewExit();
47
		super.detach();
48
	}
49

  
50
	protected void onViewReady() {
51
		Logger.getLogger(getClass().getSimpleName()).info("View ready");
52
	}
53

  
54
	protected P getPresenter() {
55
		return presenter;
56
	}
57

  
58
	@Override
59
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
60
		this.applicationContext = applicationContext;
61
	}
62
}
src/main/java/eu/etaxonomy/vaadin/mvp/ApplicationView.java
1
package eu.etaxonomy.vaadin.mvp;
2

  
3
public interface ApplicationView<P extends AbstractPresenter> {
4

  
5
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)