Project

General

Profile

Download (2.89 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.vaadin.component.distributionStatus;
2

    
3
import com.vaadin.ui.AbstractLayout;
4
import com.vaadin.ui.AbstractOrderedLayout;
5
import com.vaadin.ui.Button;
6
import com.vaadin.ui.CustomComponent;
7
import com.vaadin.ui.HorizontalLayout;
8
import com.vaadin.ui.Window;
9

    
10
import eu.etaxonomy.cdm.i18n.Messages;
11
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.settings.SettingsPresenterBase;
12

    
13

    
14
/**
15
 * A base class for setting dialog windows.
16
 * 
17
 * @author fabreim
18
 * @since May 17, 2018
19
 *
20
 * @param <P> The SettingsPresenterBase the SettingsDialog is used for.
21
 */
22
@SuppressWarnings("serial")
23
public abstract class SettingsDialogWindowBase<P extends SettingsPresenterBase> extends CustomComponent {
24

    
25
	protected Button okButton;
26
	protected Button cancelButton;
27
	protected final P presenter;
28
	protected Window window;
29
	protected AbstractOrderedLayout mainLayout;
30

    
31
	public SettingsDialogWindowBase() {
32
        buildMainLayout();
33
        presenter = getPresenter();
34
        init();
35
	}
36

    
37
	/**
38
	 * Returns the presenter the settings window belongs to.
39
	 * @return The presenter the settings window belongs to. 
40
	 */
41
    protected abstract P getPresenter();
42

    
43
    /**
44
     * Builds the layout of the settings window.
45
     * @return Layout of the settings window.
46
     */
47
    protected abstract AbstractLayout buildMainLayout();
48

    
49
    /**
50
     * Initializes the settings window and populates it with content.
51
     */
52
	protected abstract void init();
53

    
54
	protected HorizontalLayout createOkCancelButtons() {
55
		HorizontalLayout buttonToolBar = new HorizontalLayout();
56
	    // cancelButton
57
	    cancelButton = new Button();
58
	    cancelButton.setCaption(Messages.getLocalizedString(Messages.SettingsDialogWindowBase_CANCEL));
59
	    cancelButton.setImmediate(true);
60
	    cancelButton.addStyleName("dialogButton"); //$NON-NLS-1$
61
	    buttonToolBar.addComponent(cancelButton);
62

    
63
	    // okButton
64
	    okButton = new Button();
65
	    okButton.setCaption(Messages.getLocalizedString(Messages.SettingsDialogWindowBase_OK));
66
	    okButton.setImmediate(true);
67
	    okButton.addStyleName("dialogButton"); //$NON-NLS-1$
68
	    buttonToolBar.addComponent(okButton);
69
		return buttonToolBar;
70
	}
71

    
72
	/**
73
	 * Creates the settings window and sets its caption.
74
	 * @param caption The caption of the window.
75
	 * @return The settings window to be displayed.
76
	 */
77
	public Window createWindow(String caption) {
78
	    window = new Window();
79
	    window.setModal(true);
80
	    window.setWidth("60%"); //$NON-NLS-1$
81
	    window.setHeight("80%"); //$NON-NLS-1$
82
	    window.setCaption(caption);
83
	    window.setContent(mainLayout);
84
	    return window;
85
	}
86

    
87
	/**
88
	 * Update OK/Cancel button depending on {@link #isValid()}
89
	 */
90
	protected void updateButtons(){
91
		okButton.setEnabled(isValid());
92
	}
93

    
94
	/**
95
	 * Evaluates if this dialog has all necessary values set in
96
	 * a correct state
97
	 * @return <code>true</code> if the status of this dialog is valid
98
	 */
99
	protected abstract boolean isValid();
100

    
101
}
(6-6/6)