Skip to content

Commit

Permalink
Add MenuItemDecorator class
Browse files Browse the repository at this point in the history
Add possibility to set 'destructive' action style.

Change-Id: I181d889a042196e507e145c48f5aabf2304daa0c
  • Loading branch information
ifurnadjiev committed Aug 15, 2018
1 parent 09a4ac4 commit 04517f9
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2017 EclipseSource and others.
* Copyright (c) 2013, 2018 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -135,6 +135,11 @@ public void testHasLocalClipboard() {
assertContains( "localClipboard" );
}

@Test
public void testHasActionStyle() {
assertContains( "actionStyle" );
}

private void assertContains( String actualKey ) {
WhiteListEntry[] keys = DataWhitelist.WhiteListEntry.values();
boolean foundKey = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2018 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* EclipseSource - initial API and implementation
******************************************************************************/
package com.eclipsesource.tabris.widgets.enhancement;

import static com.eclipsesource.tabris.internal.DataWhitelist.WhiteListEntry.ACTION_STYLE;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import org.eclipse.swt.widgets.MenuItem;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import com.eclipsesource.tabris.test.util.TabrisEnvironment;

@RunWith( MockitoJUnitRunner.class )
public class MenuItemDecoratorTest {

@Rule
public TabrisEnvironment environment = new TabrisEnvironment();
private MenuItemDecorator decorator;
private MenuItem menuItem;

@Before
public void setUp() {
menuItem = mock( MenuItem.class );
decorator = new MenuItemDecorator( menuItem );
}

@Test
public void testDestructiveStyle() {
decorator.useDestructiveStyle();

verify( menuItem ).setData( ACTION_STYLE.getKey(), "destructive" );
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2017 EclipseSource and others.
* Copyright (c) 2012, 2018 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -15,6 +15,7 @@
import static org.mockito.Mockito.mock;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
Expand Down Expand Up @@ -209,4 +210,24 @@ public void testOnProgressBarDoesNotCache() {
assertNotSame( decorator1, decorator2 );
}

@Test
public void testOnMenuItem() {
assertNotNull( Widgets.onMenuItem( mock( MenuItem.class ) ) );
}

@Test( expected = IllegalArgumentException.class )
public void testOnMenuItemWithNull() {
Widgets.onMenuItem( null );
}

@Test
public void testOnMenuItemDoesNotCache() {
MenuItem widget = mock( MenuItem.class );

MenuItemDecorator decorator1 = Widgets.onMenuItem( widget );
MenuItemDecorator decorator2 = Widgets.onMenuItem( widget );

assertNotSame( decorator1, decorator2 );
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2017 EclipseSource and others.
* Copyright (c) 2013, 2018 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -38,7 +38,8 @@ public enum WhiteListEntry {
AUTO_CORRECT( "autoCorrect" ),
REFRESH_HANDLER( "refreshHandler" ),
REFRESH_COMPOSITE("refreshComposite"),
LOCAL_CLIPBOARD( "localClipboard" );
LOCAL_CLIPBOARD( "localClipboard" ),
ACTION_STYLE( "actionStyle" );

private final String key;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2018 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* EclipseSource - initial API and implementation
******************************************************************************/
package com.eclipsesource.tabris.widgets.enhancement;

import static com.eclipsesource.tabris.internal.DataWhitelist.WhiteListEntry.ACTION_STYLE;

import org.eclipse.swt.widgets.MenuItem;

import com.eclipsesource.tabris.internal.WidgetsUtil;

/**
* @since 3.5
*/
public class MenuItemDecorator {

private final MenuItem item;

MenuItemDecorator( MenuItem item ) {
this.item = item;
}

/**
* Enables the 'destructive' action style for this menu item (iOs only).
* A destructive action is shown in red.
*
* @since 3.5
*/
public MenuItemDecorator useDestructiveStyle() {
WidgetsUtil.setData( item, ACTION_STYLE, "destructive" );
return this;
}

}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2017 EclipseSource and others.
* Copyright (c) 2012, 2018 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -13,6 +13,7 @@
import static com.eclipsesource.tabris.internal.WidgetsUtil.checkComponent;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
Expand Down Expand Up @@ -93,6 +94,14 @@ public static ProgressBarDecorator onProgressBar( ProgressBar progressBar ) {
return new ProgressBarDecorator( progressBar );
}

/**
* @since 3.5
*/
public static MenuItemDecorator onMenuItem( MenuItem menuItem ) {
checkComponent( menuItem );
return new MenuItemDecorator( menuItem );
}

private Widgets() {
// prevent instantiation
}
Expand Down

0 comments on commit 04517f9

Please sign in to comment.