Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #403 Provide API to name the 'Back' button #405

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,30 @@ public void testGetTitle() {
}

@Test
public void testSetTitleReturnsDescritor() {
public void testSetTitleReturnsDescriptor() {
PageDescriptor descriptor = new PageDescriptor( "foo", TestPage.class );

PageDescriptor actualDescriptor = descriptor.setTitle( "bar" );

assertSame( descriptor, actualDescriptor );
}

@Test
public void testGetBackCaption() {
PageDescriptor descriptor = new PageDescriptor( "foo", TestPage.class );
descriptor.setBackCaption( "Leave" );

assertEquals( "Leave", descriptor.getBackCaption() );
}

@Test
public void testSetBackCaptionReturnsDescriptor() {
PageDescriptor descriptor = new PageDescriptor( "foo", TestPage.class );
PageDescriptor actualDescriptor = descriptor.setBackCaption( "Leave" );

assertSame( descriptor, actualDescriptor );
}

@Test
public void testGetImage() {
InputStream image = PageDescriptorTest.class.getResourceAsStream( "testImage.png" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

import com.eclipsesource.tabris.internal.ui.rendering.ActionRenderer;
import com.eclipsesource.tabris.internal.ui.rendering.UIRenderer;
Expand Down Expand Up @@ -100,6 +101,7 @@ public void testSetsDefaultAttributes() {

verify( remoteObject ).set( "parent", "foo1" );
verify( remoteObject ).set( "title", "bar" );
verify( remoteObject, never() ).set( eq( "backCaption" ), Mockito.anyString() );
verify( remoteObject ).set( "control", WidgetUtil.getId( remotePage.getControl() ) );
verify( remoteObject ).set( "style", new JsonArray().add( "DEFAULT" ) );
verify( remoteObject ).set( "topLevel", true );
Expand Down Expand Up @@ -196,6 +198,15 @@ public void testSetTitle() {
verify( remoteObject ).set( "title", "bar" );
}

@Test
public void testSetBackCaption() {
when( descriptor.getBackCaption() ).thenReturn( "Eject" );

new RemotePage( ui, uiRenderer, descriptor, mock( PageData.class ) );

verify( remoteObject ).set( "backCaption", "Eject" );
}

@Test
public void testGetData() {
PageData data = mock( PageData.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void testSetsDefaultValues() {
assertSame( TestPage.class, descriptor.getPageType() );
assertFalse( descriptor.isTopLevel() );
assertEquals( "", descriptor.getTitle() );
assertNull( descriptor.getBackCaption() );
assertNull( descriptor.getImage() );
assertEquals( 0, descriptor.getPageStyle().length );
}
Expand Down Expand Up @@ -131,6 +132,34 @@ public void testHasTitle() {
assertEquals( "bar", title );
}

@Test
public void testSetsBackCaption() {
PageConfiguration config = new PageConfiguration( "foo", TestPage.class ).setBackCaption( "Leave" );

PageDescriptor descriptor = config.getAdapter( PageDescriptor.class );

assertEquals( "Leave", config.getBackCaption() );
assertEquals( "Leave", descriptor.getBackCaption() );
}

@Test
public void testSetsBackCaptionReturnsPageConfig() {
PageConfiguration config = new PageConfiguration( "foo", TestPage.class ).setTitle( "bar" );

PageConfiguration actualConfig = config.setBackCaption( "backCaption" );

assertSame( config, actualConfig );
}

@Test
public void testBackCaptionIsNullByDefault() {
PageConfiguration config = new PageConfiguration( "foo", TestPage.class ).setTitle( "bar" );

String backCaption = config.getBackCaption();

assertNull( backCaption );
}

@Test( expected = IllegalArgumentException.class )
public void testSetTitleFailsWithNull() {
new PageConfiguration( "foo", TestPage.class ).setTitle( null );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class Constants {
public static final String PROPERTY_ACTIVE_PAGE = "activePage";
public static final String PROPERTY_PAGE_ID = "pageId";
public static final String PROPERTY_TITLE = "title";
public static final String PROPERTY_BACK_CAPTION = "backCaption";
public static final String PROPERTY_STYLE = "style";
public static final String PROPERTY_TOP_LEVEL = "topLevel";
public static final String PROPERTY_VISIBILITY = "visibility";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class PageDescriptor implements Serializable {
private boolean topLevel;
private PageStyle[] style;
private String title;
private String backCaption;
private byte[] image;

public PageDescriptor( String id, Class<? extends Page> pageType ) {
Expand Down Expand Up @@ -75,6 +76,15 @@ public String getTitle() {
return title;
}

public PageDescriptor setBackCaption( String backCaption ) {
this.backCaption = backCaption;
return this;
}

public String getBackCaption() {
return backCaption;
}

public PageDescriptor setPageStyle( PageStyle... style ) {
this.style = style;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
******************************************************************************/
package com.eclipsesource.tabris.internal.ui;

import static com.eclipsesource.tabris.internal.Constants.PROPERTY_BACK_CAPTION;
import static com.eclipsesource.tabris.internal.Constants.PROPERTY_CONTROL;
import static com.eclipsesource.tabris.internal.Constants.PROPERTY_IMAGE;
import static com.eclipsesource.tabris.internal.Constants.PROPERTY_PARENT;
Expand Down Expand Up @@ -65,6 +66,7 @@ public RemotePage( UI ui, RemoteUI uiRenderer, PageDescriptor descriptor, PageDa
this.page = InstanceCreator.createInstance( descriptor.getPageType() );
this.remoteActions = new ArrayList<ActionRenderer>();
setTitle( descriptor.getTitle() );
setBackCaption( descriptor.getBackCaption() );
setAttributes();
}

Expand All @@ -91,6 +93,12 @@ private JsonArray createPageStyleParameter( PageStyle[] pageStyle ) {
return createJsonArray( result );
}

private void setBackCaption( String backCaption ) {
if ( backCaption != null && backCaption.trim().length() > 0 ) {
remoteObject.set( PROPERTY_BACK_CAPTION, backCaption );
}
}

private void setImage() {
Image image = createImage( descriptor.getImage() );
if( image != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class PageConfiguration implements Adaptable, Serializable {
private final Class<? extends Page> pageType;
private final List<ActionConfiguration> actions;
private String title;
private String backCaption;
private PageStyle[] style;
private boolean topLevel;
private byte[] image;
Expand All @@ -74,6 +75,7 @@ public PageConfiguration( String pageId, Class<? extends Page> pageType ) {
this.id = pageId;
this.pageType = pageType;
this.title = "";
this.backCaption = null;
this.topLevel = false;
this.style = new PageStyle[] {};
this.actions = new ArrayList<ActionConfiguration>();
Expand Down Expand Up @@ -126,7 +128,7 @@ public PageConfiguration setTitle( String title ) {

/**
* <p>
* Returns the page title."
* Returns the page title.
* </p>
*
* @since 1.4
Expand All @@ -135,6 +137,30 @@ public String getTitle() {
return title;
}

/**
* <p>
* Defines the text for the back button.
* </p>
*
* @param backCaption the text for the back button. If {@code null} or empty, the default text is used.
* @since 1.4.5
*/
public PageConfiguration setBackCaption( String backCaption ) {
this.backCaption = backCaption;
return this;
}

/**
* <p>
* Returns the text for the back button. Default value: {@code null}.
* </p>
*
* @since 1.4.5
*/
public String getBackCaption() {
return backCaption;
}

/**
* <p>
* Defines the style of a page. A page can have multiple styles.
Expand Down Expand Up @@ -253,6 +279,7 @@ public <T> T getAdapter( Class<T> adapter ) {
private PageDescriptor createDescriptor() {
PageDescriptor pageDescriptor = new PageDescriptor( id, pageType )
.setTitle( title )
.setBackCaption( backCaption )
.setImage( image )
.setTopLevel( topLevel )
.setPageStyle( style );
Expand Down