Project

General

Profile

Revision 58dba687

ID58dba687a51cb1c277ec73c9c7324fcc775a1b94
Parent 54d20fb4
Child 073d62ba

Added by Patrick Plitzner almost 4 years ago

ref #6131 Refactor settings dialog

  • extracted abstract class
  • set style for OK/Cancel button

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/AbstractSettingsDialogWindow.java
1
package eu.etaxonomy.cdm.vaadin.view.dbstatus;
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.vaadin.presenter.dbstatus.settings.SettingsPresenter;
11

  
12
@SuppressWarnings("serial")
13
public abstract class AbstractSettingsDialogWindow extends CustomComponent {
14

  
15
	protected Button okButton;
16
	protected Button cancelButton;
17
	protected final SettingsPresenter presenter;
18
	protected Window window;
19
	protected AbstractOrderedLayout mainLayout;
20

  
21
	public AbstractSettingsDialogWindow() {
22
        buildMainLayout();
23
        presenter = new SettingsPresenter();
24
        init();
25
	}
26

  
27
	protected abstract AbstractLayout buildMainLayout();
28

  
29
	protected abstract void init();
30

  
31
	protected HorizontalLayout createOkCancelButtons() {
32
		HorizontalLayout buttonToolBar = new HorizontalLayout();
33
	    // cancelButton
34
	    cancelButton = new Button();
35
	    cancelButton.setCaption("Cancel");
36
	    cancelButton.setImmediate(true);
37
	    cancelButton.addStyleName("dialogButton");
38
	    buttonToolBar.addComponent(cancelButton);
39
	
40
	    // okButton
41
	    okButton = new Button();
42
	    okButton.setCaption("OK");
43
	    okButton.setImmediate(true);
44
	    okButton.addStyleName("dialogButton");
45
	    buttonToolBar.addComponent(okButton);
46
		return buttonToolBar;
47
	}
48

  
49
	public Window createWindow() {
50
	    window = new Window();
51
	    window.setModal(true);
52
	    window.setWidth("60%");
53
	    window.setHeight("80%");
54
	    window.setCaption("Settings");
55
	    window.setContent(mainLayout);
56
	    return window;
57
	}
58

  
59
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSettingsConfigWindow.java
12 12
import java.sql.SQLException;
13 13
import java.util.Set;
14 14

  
15
import com.vaadin.data.Container;
16 15
import com.vaadin.data.Property;
17 16
import com.vaadin.data.Property.ValueChangeEvent;
18 17
import com.vaadin.data.Property.ValueChangeListener;
19 18
import com.vaadin.data.util.sqlcontainer.RowId;
20 19
import com.vaadin.server.VaadinSession;
21 20
import com.vaadin.ui.AbstractLayout;
22
import com.vaadin.ui.AbstractOrderedLayout;
23 21
import com.vaadin.ui.Alignment;
24
import com.vaadin.ui.Button;
25 22
import com.vaadin.ui.Button.ClickEvent;
26 23
import com.vaadin.ui.Button.ClickListener;
27 24
import com.vaadin.ui.ComboBox;
28
import com.vaadin.ui.CustomComponent;
29 25
import com.vaadin.ui.HorizontalLayout;
30 26
import com.vaadin.ui.ListSelect;
31 27
import com.vaadin.ui.Notification;
32 28
import com.vaadin.ui.Table.ColumnHeaderMode;
33 29
import com.vaadin.ui.TreeTable;
34 30
import com.vaadin.ui.VerticalLayout;
35
import com.vaadin.ui.Window;
36 31

  
37 32
import eu.etaxonomy.cdm.model.common.TermVocabulary;
38 33
import eu.etaxonomy.cdm.model.location.NamedArea;
......
40 35
import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer;
41 36
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
42 37
import eu.etaxonomy.cdm.vaadin.container.TaxonTreeContainer;
43
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.settings.SettingsPresenter;
44 38
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
45 39
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
46 40

  
......
49 43
 * @author pplitzner
50 44
 *
51 45
 */
52
public class DistributionSettingsConfigWindow extends CustomComponent implements ValueChangeListener, ClickListener{
46
public class DistributionSettingsConfigWindow extends AbstractSettingsDialogWindow implements ValueChangeListener, ClickListener{
53 47

  
54 48
	private static final long serialVersionUID = 1439411115014088780L;
55 49
	private ComboBox classificationBox;
56 50
    private ComboBox distAreaBox;
57 51
    private ListSelect namedAreaList;
58 52
    private TreeTable taxonTree;
59
    private Button okButton;
60
    private Button cancelButton;
61
    private final SettingsPresenter presenter;
62
	private Window window;
63
	private AbstractOrderedLayout mainLayout;
64

  
65 53
    /**
66 54
     * The constructor should first build the main layout, set the
67 55
     * composition root and then do any custom initialization.
......
71 59
     * @param distributionTableView
72 60
     */
73 61
    public DistributionSettingsConfigWindow(DistributionTableView distributionTableView) {
74
        buildMainLayout();
75
        presenter = new SettingsPresenter();
76
        init();
62
    	super();
77 63
    }
78 64

  
79
    private void init() {
80
        Container distributionContainer = presenter.getDistributionContainer();
81
        TermVocabulary<NamedArea> chosenArea = presenter.getChosenArea();
65
    protected void init() {
66
    	//init classification and taxon selection
67
        TaxonNode chosenTaxonNode = presenter.getChosenTaxonNode();
82 68

  
83 69
        classificationBox.setContainerDataSource(new TaxonNodeContainer(null));
70
        Object classificationSelection = null;
84 71
		if(classificationBox.getItemIds().size()==1){
85
		    classificationBox.setValue(classificationBox.getItemIds().iterator().next());
72
			//only one classification exists
73
		    classificationSelection = classificationBox.getItemIds().iterator().next();
86 74
		}
87
        TaxonNode chosenTaxonNode = presenter.getChosenTaxonNode();
88
        if(chosenTaxonNode!=null){
89
        	classificationBox.setValue(chosenTaxonNode.getClassification().getRootNode());
75
		else if(chosenTaxonNode!=null){
76
			//get the classification from the selected taxon node
77
			classificationSelection = chosenTaxonNode.getClassification().getRootNode();
78
		}
79
        if(classificationSelection!=null){
80
        	classificationBox.setValue(classificationSelection);
90 81
        	try {
91
                taxonTree.setContainerDataSource(new TaxonTreeContainer((TaxonNode) classificationBox.getValue()));
82
                taxonTree.setContainerDataSource(new TaxonTreeContainer((TaxonNode) classificationSelection));
83
                taxonTree.setVisibleColumns("Name");
92 84
            } catch (SQLException e) {
93 85
                // TODO Auto-generated catch block
94 86
                e.printStackTrace();
95 87
            }
96
        	taxonTree.select(new RowId(chosenTaxonNode.getId()));
97
            taxonTree.setVisibleColumns("Name");
88
        	if(chosenTaxonNode!=null){
89
    			taxonTree.select(new RowId(chosenTaxonNode.getId()));
90
        	}
98 91
        }
99 92
        classificationBox.addValueChangeListener(this);
100
        distAreaBox.setContainerDataSource(distributionContainer);
93
        
94
        TermVocabulary<NamedArea> chosenArea = presenter.getChosenArea();
95
        distAreaBox.setContainerDataSource(presenter.getDistributionContainer());
101 96
        distAreaBox.setValue(chosenArea);
102 97
        distAreaBox.addValueChangeListener(this);
103 98

  
......
112 107
        cancelButton.addClickListener(this);
113 108
    }
114 109

  
115
    public Window createWindow(){
116
        window = new Window();
117
        window.setModal(true);
118
        window.setWidth("60%");
119
        window.setHeight("80%");
120
        window.setCaption("Settings");
121
        window.setContent(mainLayout);
122
        return window;
123
    }
124

  
125
    private AbstractLayout buildMainLayout() {
110
    protected AbstractLayout buildMainLayout() {
126 111

  
127 112
        mainLayout = new VerticalLayout();
128 113
        mainLayout.setSizeFull();
......
191 176
        leftAndRightContainer.addComponent(rightContainer);
192 177

  
193 178
        //button toolbar
194
        HorizontalLayout buttonToolBar = new HorizontalLayout();
195
        // cancelButton
196
        cancelButton = new Button();
197
        cancelButton.setCaption("Cancel");
198
        cancelButton.setImmediate(true);
199
        buttonToolBar.addComponent(cancelButton);
200

  
201
        // okButton
202
        okButton = new Button();
203
        okButton.setCaption("OK");
204
        okButton.setImmediate(true);
205
        buttonToolBar.addComponent(okButton);
179
        HorizontalLayout buttonToolBar = createOkCancelButtons();
206 180

  
207 181
        mainLayout.addComponent(leftAndRightContainer);
208 182
        mainLayout.addComponent(buttonToolBar);
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java
15 15
import com.vaadin.server.VaadinSession;
16 16
import com.vaadin.ui.AbstractLayout;
17 17
import com.vaadin.ui.Alignment;
18
import com.vaadin.ui.Button;
19 18
import com.vaadin.ui.Button.ClickEvent;
20 19
import com.vaadin.ui.Button.ClickListener;
21 20
import com.vaadin.ui.CheckBox;
22
import com.vaadin.ui.CustomComponent;
23 21
import com.vaadin.ui.HorizontalLayout;
24 22
import com.vaadin.ui.TwinColSelect;
25 23
import com.vaadin.ui.VerticalLayout;
26
import com.vaadin.ui.Window;
27 24

  
28
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.settings.SettingsPresenter;
29 25
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
30 26

  
31 27
/**
......
33 29
 * @date 22.04.2015
34 30
 *
35 31
 */
36
public class SettingsConfigWindow extends CustomComponent implements ValueChangeListener, ClickListener{
32
public class SettingsConfigWindow extends AbstractSettingsDialogWindow implements ValueChangeListener, ClickListener{
37 33

  
38 34
	private static final long serialVersionUID = -8220442386869594032L;
39
    private VerticalLayout mainLayout;
40 35
    private TwinColSelect distStatusSelect;
41 36
    private CheckBox boxToggleAbbreviatedLabels;
42
    private Button okButton;
43
    private Button cancelButton;
44
    private final SettingsPresenter presenter;
45
	private Window window;
46
	private DistributionTableView distributionTableView;
37
    private DistributionTableView distributionTableView;
47 38

  
48 39
    /**
49 40
     * The constructor should first build the main layout, set the
......
54 45
     * @param distributionTableView
55 46
     */
56 47
    public SettingsConfigWindow(DistributionTableView distributionTableView) {
48
    	super();
57 49
    	this.distributionTableView = distributionTableView;
58
        buildMainLayout();
59
        presenter = new SettingsPresenter();
60
        init();
61 50
    }
62 51

  
63
    private void init() {
52
    protected void init() {
64 53
        boxToggleAbbreviatedLabels.addValueChangeListener(this);
65 54
        distStatusSelect.setContainerDataSource(presenter.getDistributionStatusContainer());
66 55

  
......
68 57
        cancelButton.addClickListener(this);
69 58
    }
70 59

  
71
    public Window createWindow(){
72
        window = new Window();
73
        window.setModal(true);
74
        window.setWidth("60%");
75
        window.setHeight("80%");
76
        window.setCaption("Settings");
77
        window.setContent(mainLayout);
78
        return window;
79
    }
80

  
81
    private AbstractLayout buildMainLayout() {
60
    protected AbstractLayout buildMainLayout() {
82 61

  
83 62
    	mainLayout = new VerticalLayout();
84 63
        mainLayout.setImmediate(false);
......
102 81
        mainLayout.setSizeFull();
103 82

  
104 83
        //button toolbar
105
        HorizontalLayout buttonContainer = new HorizontalLayout();
106
        // cancelButton
107
        cancelButton = new Button();
108
        cancelButton.setCaption("Cancel");
109
        cancelButton.setImmediate(true);
110
        buttonContainer.addComponent(cancelButton);
111

  
112
        // okButton
113
        okButton = new Button();
114
        okButton.setCaption("OK");
115
        okButton.setImmediate(true);
116
        buttonContainer.addComponent(okButton);
84
        HorizontalLayout buttonContainer = createOkCancelButtons();
117 85

  
118 86
        mainLayout.addComponent(buttonContainer);
119 87
        mainLayout.setComponentAlignment(buttonContainer, Alignment.BOTTOM_RIGHT);
src/main/webapp/VAADIN/themes/edit/styles.scss
8 8

  
9 9
  // Include mytheme theme styles in your theme
10 10
  @include edit;
11
}
12

  
13

  
14
.dialogButton {
15
    min-width: 80px;
11 16
}
src/main/webapp/VAADIN/themes/macosx/styles.scss
175 175
	font-weight: bold;
176 176
	text-shadow: #fff 0 1px 0;
177 177
	padding: 0;
178
}
179

  
180
.dialogButton {
181
    min-width: 80px;
178 182
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)