Skip to content

Commit

Permalink
Attempt to fix #50, Target Platform content editor not editable
Browse files Browse the repository at this point in the history
EnablementReconcilation misses out in case the parent isn't enabled while enabling the adapter/scrollable. This fix try to detect these situation and trigger adapter enabling once again when parent is recognized as enabled too.
  • Loading branch information
fappel committed Dec 7, 2015
1 parent 40422b6 commit aca5958
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Expand Up @@ -134,19 +134,31 @@ public void disableAdapterAndShowScrollable() {
assertThat( adapter.getEnabled() ).isTrue();
}

@Test
public void enableScrollableIfAdapterParentGetsEnabled() {
scrollable.setEnabled( true );
when( adapter.isEnabled() ).thenReturn( true );

reconciliation.run();

assertThat( scrollable.getEnabled() ).isTrue();
assertThat( adapter.getEnabled() ).isTrue();
assertThat( reconciliation.adapterEnabled ).isTrue();
}

private static Composite stubAdapter() {
Composite result = mock( Composite.class );
simulateVisibilityAttribute( result );
simulateEnablementAttribute( result );
return result;
}

private static Scrollable stubScrollable() {
Scrollable result = mock( Scrollable.class );
simulateVisibilityAttribute( result );
simulateEnablementAttribute( result );
return result;
}

private static void simulateVisibilityAttribute( final Control control ) {
private static void simulateEnablementAttribute( final Control control ) {
doAnswer( enablementStub( control ) ).when( control ).setEnabled( anyBoolean() );
}

Expand Down
Expand Up @@ -9,6 +9,7 @@ class EnablementReconciliation {
private final Composite adapter;

boolean scrollableEnabled;
boolean adapterEnabled;

EnablementReconciliation( Composite adapter, ScrollableControl<? extends Scrollable> scrollable ) {
this.adapter = adapter;
Expand All @@ -21,6 +22,10 @@ void run() {
if( adapter.getEnabled() != scrollableEnabled ) {
adapter.setEnabled( scrollableEnabled );
}
if( scrollableEnabled && adapterEnabled != adapter.isEnabled() ) {
adapter.setEnabled( scrollableEnabled );
adapterEnabled = adapter.isEnabled();
}
}

boolean setEnabled( boolean enabled ) {
Expand All @@ -36,6 +41,7 @@ boolean setEnabled( boolean enabled ) {
}
scrollable.setEnabled( result );
scrollableEnabled = scrollable.getEnabled();
adapterEnabled = adapter.isEnabled();
return result;
}

Expand Down

0 comments on commit aca5958

Please sign in to comment.