Project

General

Profile

« Previous | Next » 

Revision 793a7b67

Added by Andreas Kohlbecker almost 7 years ago

ref #6169 ReferenceEditor: field visibility by ReferenceType & inReference field added

View differences:

ivy.xml
1
<?xml version="1.0"?>
2
<!DOCTYPE ivy-module [
3
	<!ENTITY vaadin.version "7.7.9">
4
]>
5
<ivy-module version="2.0"
6
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7
	xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
8
	<info organisation="com.example" module="v7proj" />
9
	<configurations>
10
		<!-- The default configuration, which should be deployed to the server -->
11
		<conf name="default" />
12
		<!-- A configuration only needed when compiling the widget set. Should 
13
			not be deployed to the server -->
14
		<conf name="widgetset-compile" />
15
		<!-- A configuration used in compilation of server side classes only.
16
			Should be deployed to the server -->
17
		<conf name="nodeploy" />
18
	</configurations>
19
	<dependencies defaultconf="default" defaultconfmapping="default->default">
20
		<!-- The core server part of Vaadin -->
21
		<dependency org="com.vaadin" name="vaadin-server" rev="&vaadin.version;" />
22

  
23
		<!-- Vaadin themes -->
24
		<dependency org="com.vaadin" name="vaadin-themes" rev="&vaadin.version;" />
25

  
26
		<!-- Push support -->
27
		<dependency org="com.vaadin" name="vaadin-push" rev="&vaadin.version;" />
28

  
29
		<!-- TestBench 4 -->
30
		<dependency org="com.vaadin" name="vaadin-testbench-api" rev="&vaadin.version;" conf="nodeploy -> default" />
31

  
32
		<!-- Precompiled DefaultWidgetSet -->
33
		<dependency org="com.vaadin" name="vaadin-client-compiled"
34
			rev="&vaadin.version;" />
35

  
36
		<!-- Vaadin client side, needed for widget set compilation -->
37
		<dependency org="com.vaadin" name="vaadin-client" rev="&vaadin.version;"
38
			 conf="widgetset-compile->default" />
39

  
40
		<!-- Compiler for custom widget sets. Should not be deployed -->
41
		<dependency org="com.vaadin" name="vaadin-client-compiler"
42
			rev="&vaadin.version;" conf="widgetset-compile->default" />
43
	</dependencies>
44
</ivy-module>
ivysettings.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<ivysettings>
3
	<settings defaultResolver="default" />
4
	<resolvers>
5
		<chain name="default">
6
			<!-- Public Maven repository -->
7
			<ibiblio name="public" m2compatible="true" />
8

  
9
			<!-- Vaadin Add-on repository -->
10
			<ibiblio name="vaadin-addons" usepoms="true" m2compatible="true"
11
				root="http://maven.vaadin.com/vaadin-addons" />
12

  
13
			<!-- Vaadin snapshots repository -->
14
			<ibiblio name="vaadin-snapshots" usepoms="true" m2compatible="true"
15
				root="https://oss.sonatype.org/content/repositories/vaadin-snapshots" />
16
			<!-- Repository used for Vaadin modified smartsprites library -->
17
			<dual name="custom-smartsprites">
18
				<filesystem name="smartsprites-ivy">
19
					<ivy pattern="${basedir}/ivymodule/[module]-ivy-[revision].xml" />
20
				</filesystem>
21
				<url name="smartsprites-artifact">
22
					<artifact
23
						pattern="http://dev.vaadin.com/svn/versions/6.8/build/smartsprites/lib/[artifact](-[revision]).[ext]" />
24
				</url>
25
			</dual>
26
		</chain>
27
	</resolvers>
28
	<modules>
29
		<!-- Vaadin patched SmartSprites -->
30
		<module organisation="com.carrotsearch" name="smartsprites"
31
			revision="0.2.3-itmill" resolver="custom-smartsprites" />
32
	</modules>
33

  
34

  
35
</ivysettings>
src/main/java/com/example/cdm_vaadin/Cdm_vaadinUI.java
1
package com.example.cdm_vaadin;
2

  
3
import com.vaadin.annotations.Theme;
4
import com.vaadin.server.VaadinRequest;
5
import com.vaadin.ui.Button;
6
import com.vaadin.ui.Button.ClickEvent;
7
import com.vaadin.ui.Label;
8
import com.vaadin.ui.UI;
9
import com.vaadin.ui.VerticalLayout;
10

  
11
@SuppressWarnings("serial")
12
@Theme("cdm_vaadin")
13
public class Cdm_vaadinUI extends UI {
14

  
15
	@Override
16
	protected void init(VaadinRequest request) {
17
		final VerticalLayout layout = new VerticalLayout();
18
		layout.setMargin(true);
19
		setContent(layout);
20

  
21
		Button button = new Button("Click Me");
22
		button.addClickListener(new Button.ClickListener() {
23
			public void buttonClick(ClickEvent event) {
24
				layout.addComponent(new Label("Thank you for clicking"));
25
			}
26
		});
27
		layout.addComponent(button);
28
	}
29

  
30
}
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java
138 138
    @Override
139 139
    protected void addDefaultStyles() {
140 140
        // no default styles here
141

  
142 141
    }
143 142

  
144 143
    /**
src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferencePopupEditor.java
11 11
import java.util.Arrays;
12 12
import java.util.Collection;
13 13

  
14
import org.springframework.beans.factory.annotation.Autowired;
14 15
import org.springframework.context.annotation.Scope;
15 16
import org.springframework.security.core.GrantedAuthority;
16 17

  
......
22 23

  
23 24
import eu.etaxonomy.cdm.model.reference.Reference;
24 25
import eu.etaxonomy.cdm.model.reference.ReferenceType;
26
import eu.etaxonomy.cdm.persistence.query.OrderHint;
27
import eu.etaxonomy.cdm.vaadin.component.SelectFieldFactory;
25 28
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
26 29
import eu.etaxonomy.cdm.vaadin.component.common.TimePeriodField;
27 30
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
......
40 43

  
41 44
    private static final long serialVersionUID = -4347633563800758815L;
42 45

  
46
    @Autowired
47
    private SelectFieldFactory selectFieldFactory;
48

  
43 49
    private TextField titleField;
44 50

  
45 51
    private final static int GRID_COLS = 4;
......
90 96
        ListSelect typeSelect = new ListSelect("Reference type", Arrays.asList(ReferenceType.values()));
91 97
        typeSelect.setNullSelectionAllowed(false);
92 98
        typeSelect.setRows(1);
99
        typeSelect.addValueChangeListener(e -> updateFieldVisibility((ReferenceType)e.getProperty().getValue()));
93 100
        addField(typeSelect, "type", 3, row);
94 101
        grid.setComponentAlignment(typeSelect, Alignment.TOP_RIGHT);
95 102
        row++;
......
113 120
        addTextField("Pages", "pages", 2, row);
114 121
        addTextField("Editor", "editor", 3, row).setWidth(100, Unit.PERCENTAGE);
115 122
        row++;
123
        ListSelect inReferenceSelect = selectFieldFactory.createListSelect("In-reference", Reference.class, OrderHint.ORDER_BY_TITLE_CACHE.asList(), "titleCache");
124
        inReferenceSelect.setWidth(100, Unit.PERCENTAGE);
125
        inReferenceSelect.setRows(1);
126
        addField(inReferenceSelect, "inReference", 0, row, 3, row);
127
        row++;
116 128
        addTextField("Place published", "placePublished", 0, row, 1, row).setWidth(100, Unit.PERCENTAGE);
117 129
        TextField publisherField = addTextField("Publisher", "publisher", 2, row, 3, row);
118 130
        publisherField.setWidth(100, Unit.PERCENTAGE);
......
134 146

  
135 147
    }
136 148

  
149
    /**
150
     * @param value
151
     * @return
152
     */
153
    private Object updateFieldVisibility(ReferenceType value) {
154
        getField("volume").setVisible(value.isVolumeReference());
155

  
156
        getField("placePublished").setVisible(value.isPublication());
157
        getField("publisher").setVisible(value.isPublication());
158

  
159
        getField("editor").setVisible(value.isPrintedUnit());
160
        getField("seriesPart").setVisible(value.isPrintedUnit());
161

  
162
        getField("inReference").setVisible(value.isPrintedUnit() || value.isSection());
163
        getField("pages").setVisible(value.isSection());
164

  
165
        return null;
166
    }
167

  
137 168
    /**
138 169
     * {@inheritDoc}
139 170
     */
src/main/java/eu/etaxonomy/cdm/vaadin/view/taxon/TaxonNamePopupEditor.java
199 199
     */
200 200
    private void updateFieldVisibility(Rank rank) {
201 201
        boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES());
202
        // TODO use getField() instead and remove field references
202 203
        infraSpecificEpithetField.setVisible(rank.isInfraSpecific());
203 204
        specificEpithetField.setVisible(isSpeciesOrBelow);
204 205
        infraGenericEpithetField.setVisible(rank.isInfraGenericButNotSpeciesGroup());
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPopupEditor.java
380 380
        return field;
381 381
    }
382 382

  
383
    protected Field<?> getField(Object propertyId){
384
        return fieldGroup.getField(propertyId);
385
    }
386

  
383 387
    protected void addComponent(Component component) {
384 388
        fieldLayout.addComponent(component);
385 389
        applyDefaultComponentStyles(component);
src/main/webapp/VAADIN/themes/cdm_vaadin/cdm_vaadin.scss
1
// Global variable overrides. Must be declared before importing Valo.
2

  
3
// Defines the plaintext font size, weight and family. Font size affects general component sizing.
4
//$v-font-size: 16px;
5
//$v-font-weight: 300;
6
//$v-font-family: "Open Sans", sans-serif;
7

  
8
// Defines the border used by all components.
9
//$v-border: 1px solid (v-shade 0.7);
10
//$v-border-radius: 4px;
11

  
12
// Affects the color of some component elements, e.g Button, Panel title, etc
13
//$v-background-color: hsl(210, 0%, 98%);
14
// Affects the color of content areas, e.g  Panel and Window content, TextField input etc
15
//$v-app-background-color: $v-background-color;
16

  
17
// Affects the visual appearance of all components
18
//$v-gradient: v-linear 8%;
19
//$v-bevel-depth: 30%;
20
//$v-shadow-opacity: 5%;
21

  
22
// Defines colors for indicating status (focus, success, failure)
23
//$v-focus-color: valo-focus-color(); // Calculates a suitable color automatically
24
//$v-friendly-color: #2c9720;
25
//$v-error-indicator-color: #ed473b;
26

  
27
// For more information, see: https://vaadin.com/book/-/page/themes.valo.html
28
// Example variants can be copy/pasted from https://vaadin.com/wiki/-/wiki/Main/Valo+Examples
29

  
30
@import "../valo/valo.scss";
31

  
32
@mixin cdm_vaadin {
33
  @include valo;
34

  
35
  // Insert your own theme rules here
36
}
src/main/webapp/VAADIN/themes/cdm_vaadin/styles.scss
1
@import "addons.scss";
2
@import "cdm_vaadin.scss";
3

  
4
/* This file prefixes all rules with the theme name to avoid causing conflicts with other themes. */
5
/* The actual styles should be defined in cdm_vaadin.scss */
6
.cdm_vaadin {
7
  @include addons;
8
  @include cdm_vaadin;
9
}
src/main/webapp/WEB-INF/web.xml
33 33
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
34 34
        <load-on-startup>1</load-on-startup>
35 35
    </servlet>
36
    <servlet>
37
    	<servlet-name>Cdm_vaadin Application</servlet-name>
38
    	<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
39
    	<init-param>
40
    		<description>
41
    		Vaadin UI class to use</description>
42
    		<param-name>UI</param-name>
43
    		<param-value>com.example.cdm_vaadin.Cdm_vaadinUI</param-value>
44
    	</init-param>
45
    	<init-param>
46
    		<description>
47
    		Legacy mode to return the value of the property as a string from AbstractProperty.toString()</description>
48
    		<param-name>legacyPropertyToString</param-name>
49
    		<param-value>false</param-value>
50
    	</init-param>
51
    </servlet>
36 52

  
37 53
    <servlet-mapping>
38 54
        <servlet-name>cdm-vaadin</servlet-name>
39 55
        <url-pattern>/</url-pattern>
40 56
    </servlet-mapping>
57
    <servlet-mapping>
58
    	<servlet-name>Cdm_vaadin Application</servlet-name>
59
    	<url-pattern>/*</url-pattern>
60
    </servlet-mapping>
41 61

  
42 62

  
43 63
    <filter>
......
79 99
      <param-name>productionMode</param-name>
80 100
      <param-value>false</param-value>
81 101
    </context-param>
102
    <context-param>
103
    	<description>
104
    	Vaadin production mode</description>
105
    	<param-name>productionMode</param-name>
106
    	<param-value>false</param-value>
107
    </context-param>
82 108
</web-app>
test/com/example/cdm_vaadin/Cdm_vaadinTest.java
1
package com.example.cdm_vaadin;
2

  
3
import com.vaadin.testbench.ScreenshotOnFailureRule;
4
import com.vaadin.testbench.TestBenchTestCase;
5
import com.vaadin.testbench.elements.ButtonElement;
6
import com.vaadin.testbench.elements.LabelElement;
7

  
8
import org.junit.Before;
9
import org.junit.Rule;
10
import org.junit.Test;
11
import org.openqa.selenium.firefox.FirefoxDriver;
12

  
13
import java.util.List;
14

  
15
import static org.junit.Assert.assertEquals;
16
import static org.junit.Assert.assertFalse;
17

  
18
/**
19
 * This class contains JUnit tests, which are run using Vaadin TestBench 4.
20
 *
21
 * To run this, first get an evaluation license from
22
 * https://vaadin.com/addon/vaadin-testbench and follow the instructions at
23
 * https://vaadin.com/directory/help/installing-cval-license to install it.
24
 *
25
 * Once the license is installed, you can run this class as a JUnit test.
26
 */
27
public class Cdm_vaadinTest extends TestBenchTestCase {
28
    @Rule
29
    public ScreenshotOnFailureRule screenshotOnFailureRule =
30
            new ScreenshotOnFailureRule(this, true);
31

  
32
    @Before
33
    public void setUp() throws Exception {
34
        setDriver(new FirefoxDriver()); // Firefox
35

  
36
        // To use Chrome, first install chromedriver.exe from
37
        // http://chromedriver.storage.googleapis.com/index.html
38
        // on your system path (e.g. C:\Windows\System32\)
39
        //   setDriver(new ChromeDriver()); // Chrome
40

  
41
        // To use Internet Explorer, first install iedriverserver.exe from
42
        // http://selenium-release.storage.googleapis.com/index.html?path=2.43/
43
        // on your system path (e.g. C:\Windows\System32\)
44
        //   setDriver(new InternetExplorerDriver()); // IE
45

  
46
        // To test headlessly (without a browser), first install phantomjs.exe
47
        // from http://phantomjs.org/download.html on your system path
48
        // (e.g. C:\Windows\System32\)
49
        //   setDriver(new PhantomJSDriver()); // PhantomJS headless browser
50
    }
51

  
52
    /**
53
     * Opens the URL where the application is deployed.
54
     */
55
    private void openTestUrl() {
56
        getDriver().get("http://localhost:8080/cdm-vaadin");
57
    }
58

  
59
    @Test
60
    public void testClickButton() throws Exception {
61
        openTestUrl();
62

  
63
        // At first there should be no labels
64
        assertFalse($(LabelElement.class).exists());
65

  
66
        // Click the button
67
        ButtonElement clickMeButton = $(ButtonElement.class).
68
                caption("Click Me").first();
69
        clickMeButton.click();
70

  
71
        // There should now be one label
72
        assertEquals(1, $(LabelElement.class).all().size());
73
        // ... with the specified text
74
        assertEquals("Thank you for clicking",
75
                $(LabelElement.class).first().getText());
76

  
77
        // Click the button again
78
        clickMeButton.click();
79

  
80
        // There should now be two labels
81
        List<LabelElement> allLabels = $(LabelElement.class).all();
82
        assertEquals(2, allLabels.size());
83
        // ... and the last label should have the correct text
84
        LabelElement lastLabel = allLabels.get(1);
85
        assertEquals("Thank you for clicking", lastLabel.getText());
86
    }
87
}

Also available in: Unified diff