Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
GUVNOR-2655: Guided Decision Table: Checkbox remains in row after las…
Browse files Browse the repository at this point in the history
…t row is deleted (#491)
  • Loading branch information
manstis authored and ederign committed Sep 6, 2016
1 parent c111817 commit 6197db2
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 72 deletions.
Expand Up @@ -26,7 +26,6 @@
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.IsWidget;
Expand Down Expand Up @@ -125,6 +124,7 @@ public void setup() {
setupStyleChangeHandler();
setupMergedStateValueChangeHandler();
setupAppendRowClickHandler();
setupDeleteRowClickHandler();

this.gridWidget1 = makeGridWidget1();
this.gridWidget2 = makeGridWidget2();
Expand Down Expand Up @@ -481,16 +481,26 @@ public void onValueChange( final ValueChangeEvent<Boolean> event ) {
}

private void setupAppendRowClickHandler() {
view.addAppendRowClickHandler( new ClickHandler() {
@Override
public void onClick( final ClickEvent event ) {
for ( GridWidget gridWidget : view.getGridWidgets() ) {
if ( gridWidget.isSelected() ) {
gridWidget.getModel().appendRow( new BaseGridRow() );
view.addAppendRowClickHandler( ( final ClickEvent event ) -> {
for ( GridWidget gridWidget : view.getGridWidgets() ) {
if ( gridWidget.isSelected() ) {
gridWidget.getModel().appendRow( new BaseGridRow() );
}
}
view.refresh();
} );
}

private void setupDeleteRowClickHandler() {
view.addDeleteRowClickHandler( ( final ClickEvent event ) -> {
for ( GridWidget gridWidget : view.getGridWidgets() ) {
if ( gridWidget.isSelected() ) {
if ( gridWidget.getModel().getRowCount() > 0 ) {
gridWidget.getModel().deleteRow( 0 );
}
}
view.refresh();
}
view.refresh();
} );
}

Expand Down
Expand Up @@ -77,7 +77,8 @@ interface Presenter extends GridSelectionManager {

/**
* Sets the Zoom level of the View.
* @param zoom An int based percentage, where for example 100 represents 100%. Must be positive.
* @param zoom
* An int based percentage, where for example 100 represents 100%. Must be positive.
*/
void setZoom( final int zoom );

Expand Down Expand Up @@ -114,4 +115,12 @@ interface Presenter extends GridSelectionManager {
*/
HandlerRegistration addAppendRowClickHandler( final ClickHandler handler );

/**
* Adds a handler for when the User, interacting with the View, requests a row to be deleted.
* @param handler
* The handler. Cannot be null.
* @return A registration for the handler.
*/
HandlerRegistration addDeleteRowClickHandler( final ClickHandler handler );

}
Expand Up @@ -49,7 +49,7 @@
margin-bottom: 10px;
}

.appendRow {
.buttons {
}
</style>

Expand All @@ -66,8 +66,9 @@
<div class="merged">
<div id="chkShowMerged"></div>
</div>
<div class="appendRow">
<div class="buttons">
<div id="btnAppendRow"></div>
<div id="btnDeleteRow"></div>
</div>
</div>

Expand Down
Expand Up @@ -73,6 +73,9 @@ public class WiresGridsDemoViewImpl extends Composite implements WiresGridsDemoV
@DataField("btnAppendRow")
Button btnAppendRow;

@DataField("btnDeleteRow")
Button btnDeleteRow;

private final DefaultGridLayer gridLayer = new DefaultGridLayer();
private final RestrictedMousePanMediator mousePanMediator = new RestrictedMousePanMediator( gridLayer );
private final Map<String, GridRendererTheme> themes = new HashMap<String, GridRendererTheme>();
Expand All @@ -84,11 +87,13 @@ public WiresGridsDemoViewImpl( final ListBox zoom,
final ListBox basicRendererSelector,
final CheckBox chkShowMerged,
final Button btnAppendRow,
final Button btnDeleteRow,
final TranslationService translationService ) {
this.zoom = zoom;
this.basicRendererSelector = basicRendererSelector;
this.chkShowMerged = chkShowMerged;
this.btnAppendRow = btnAppendRow;
this.btnDeleteRow = btnDeleteRow;
this.translationService = translationService;
}

Expand All @@ -100,6 +105,7 @@ public void setup() {

chkShowMerged.setText( translationService.getTranslation( WiresGridsDemoConstants.Options_ShowMerged ) );
btnAppendRow.setText( translationService.getTranslation( WiresGridsDemoConstants.Options_AppendRow ) );
btnDeleteRow.setText( translationService.getTranslation( WiresGridsDemoConstants.Options_DeleteRow ) );
}

private void setupCanvas() {
Expand Down Expand Up @@ -227,6 +233,11 @@ public HandlerRegistration addAppendRowClickHandler( final ClickHandler handler
return btnAppendRow.addClickHandler( handler );
}

@Override
public HandlerRegistration addDeleteRowClickHandler( final ClickHandler handler ) {
return btnDeleteRow.addClickHandler( handler );
}

@Override
public void onResize() {
gridPanel.onResize();
Expand Down
Expand Up @@ -35,4 +35,7 @@ public interface WiresGridsDemoConstants {
@TranslationKey(defaultValue = "")
String Options_AppendRow = "Options.AppendRow";

@TranslationKey(defaultValue = "")
String Options_DeleteRow = "Options.DeleteRow";

}
Expand Up @@ -238,11 +238,7 @@ protected void drawWithoutTransforms( Context2D context,
//If there's no RenderingInformation the GridWidget is not visible
final BaseGridRendererHelper.RenderingInformation renderingInformation = rendererHelper.getRenderingInformation();
if ( renderingInformation == null ) {
for ( GridColumn<?> column : model.getColumns() ) {
if ( column.getColumnRenderer() instanceof HasDOMElementResources ) {
( (HasDOMElementResources) column.getColumnRenderer() ).destroyResources();
}
}
destroyDOMElementResources();
return;
}

Expand All @@ -251,19 +247,33 @@ protected void drawWithoutTransforms( Context2D context,
final List<GridColumn<?>> allColumns = renderingInformation.getAllColumns();
final List<GridColumn<?>> bodyColumns = bodyBlockInformation.getColumns();
final List<GridColumn<?>> floatingColumns = floatingBlockInformation.getColumns();
final boolean isSelectionLayer = context.isSelection();

this.allColumns.addAll( allColumns );
this.bodyColumns.addAll( bodyColumns );
this.floatingColumns.addAll( floatingColumns );

//Signal columns to attach or detach rendering support
if ( !isSelectionLayer ) {
for ( GridColumn<?> column : model.getColumns() ) {
if ( bodyColumns.contains( column ) || floatingColumns.contains( column ) ) {
if ( column instanceof HasMultipleDOMElementResources ) {
( (HasMultipleDOMElementResources) column ).initialiseResources();
}
} else if ( column instanceof HasDOMElementResources ) {
( (HasDOMElementResources) column ).destroyResources();
}
}
}

//Draw if required
if ( this.bodyColumns.size() > 0 ) {
drawHeader( renderingInformation,
context.isSelection() );
isSelectionLayer );

if ( model.getRowCount() > 0 ) {
drawBody( renderingInformation,
context.isSelection() );
isSelectionLayer );
}

if ( body != null ) {
Expand Down Expand Up @@ -296,12 +306,18 @@ protected void drawWithoutTransforms( Context2D context,
add( selection );
}

} else {
if ( !context.isSelection() ) {
for ( GridColumn<?> column : model.getColumns() ) {
if ( column.getColumnRenderer() instanceof HasDOMElementResources ) {
( (HasDOMElementResources) column.getColumnRenderer() ).destroyResources();
}
}

//Signal columns to free any unused resources
if ( !isSelectionLayer ) {
for ( GridColumn<?> column : bodyColumns ) {
if ( column instanceof HasMultipleDOMElementResources ) {
( (HasMultipleDOMElementResources) column ).freeUnusedResources();
}
}
for ( GridColumn<?> column : floatingColumns ) {
if ( column instanceof HasMultipleDOMElementResources ) {
( (HasMultipleDOMElementResources) column ).freeUnusedResources();
}
}
}
Expand All @@ -312,6 +328,14 @@ protected void drawWithoutTransforms( Context2D context,
bb );
}

void destroyDOMElementResources() {
for ( GridColumn<?> column : model.getColumns() ) {
if ( column.getColumnRenderer() instanceof HasDOMElementResources ) {
( (HasDOMElementResources) column.getColumnRenderer() ).destroyResources();
}
}
}

@Override
public Group setVisible( final boolean visible ) {
if ( !visible ) {
Expand Down Expand Up @@ -377,19 +401,6 @@ protected void drawBody( final BaseGridRendererHelper.RenderingInformation rende
final int minVisibleRowIndex = renderingInformation.getMinVisibleRowIndex();
final int maxVisibleRowIndex = renderingInformation.getMaxVisibleRowIndex();

//Signal columns to attach or detach rendering support
if ( !isSelectionLayer ) {
for ( GridColumn<?> column : model.getColumns() ) {
if ( bodyColumns.contains( column ) || floatingColumns.contains( column ) ) {
if ( column.getColumnRenderer() instanceof HasMultipleDOMElementResources ) {
( (HasMultipleDOMElementResources) column.getColumnRenderer() ).initialiseResources();
}
} else if ( column instanceof HasDOMElementResources ) {
( (HasDOMElementResources) column.getColumnRenderer() ).destroyResources();
}
}
}

body = renderGridBodyWidget( bodyColumns,
bodyBlockInformation.getX(),
minVisibleRowIndex,
Expand Down Expand Up @@ -432,27 +443,16 @@ protected void drawBody( final BaseGridRendererHelper.RenderingInformation rende
renderingInformation ) );
}
}

//Signal columns to free any unused resources
if ( !isSelectionLayer ) {
for ( GridColumn<?> column : bodyColumns ) {
if ( column.getColumnRenderer() instanceof HasMultipleDOMElementResources ) {
( (HasMultipleDOMElementResources) column.getColumnRenderer() ).freeUnusedResources();
}
}
for ( GridColumn<?> column : floatingColumns ) {
if ( column.getColumnRenderer() instanceof HasMultipleDOMElementResources ) {
( (HasMultipleDOMElementResources) column.getColumnRenderer() ).freeUnusedResources();
}
}
}
}

/**
* Render the Widget's Header and append to this Group.
* @param allColumns All columns in the model.
* @param blockColumns The columns to render for a block.
* @param isSelectionLayer Is the SelectionLayer being rendered.
* @param allColumns
* All columns in the model.
* @param blockColumns
* The columns to render for a block.
* @param isSelectionLayer
* Is the SelectionLayer being rendered.
*/
protected Group renderGridHeaderWidget( final List<GridColumn<?>> allColumns,
final List<GridColumn<?>> blockColumns,
Expand All @@ -470,12 +470,18 @@ protected Group renderGridHeaderWidget( final List<GridColumn<?>> allColumns,

/**
* Render the Widget's Body and append to this Group.
* @param blockColumns The columns to render.
* @param absoluteColumnOffsetX Absolute offset from Grid's X co-ordinate to render first column in block.
* @param minVisibleRowIndex The index of the first visible row.
* @param maxVisibleRowIndex The index of the last visible row.
* @param isSelectionLayer Is the SelectionLayer being rendered.
* @param transformer SelectionTransformer in operation.
* @param blockColumns
* The columns to render.
* @param absoluteColumnOffsetX
* Absolute offset from Grid's X co-ordinate to render first column in block.
* @param minVisibleRowIndex
* The index of the first visible row.
* @param maxVisibleRowIndex
* The index of the last visible row.
* @param isSelectionLayer
* Is the SelectionLayer being rendered.
* @param transformer
* SelectionTransformer in operation.
*/
protected Group renderGridBodyWidget( final List<GridColumn<?>> blockColumns,
final double absoluteColumnOffsetX,
Expand Down Expand Up @@ -511,9 +517,12 @@ protected Group renderGridBodyWidget( final List<GridColumn<?>> blockColumns,

/**
* Render the selected ranges and append to the Body Group.
* @param blockColumns The columns to render.
* @param absoluteColumnOffsetX Absolute offset from Grid's X co-ordinate to render first column in block.
* @param renderingInformation Calculated rendering information supporting rendering.
* @param blockColumns
* The columns to render.
* @param absoluteColumnOffsetX
* Absolute offset from Grid's X co-ordinate to render first column in block.
* @param renderingInformation
* Calculated rendering information supporting rendering.
* @return A Group containing the boundary.
*/
protected Group renderGridBoundary( final List<GridColumn<?>> blockColumns,
Expand All @@ -532,11 +541,16 @@ protected Group renderGridBoundary( final List<GridColumn<?>> blockColumns,

/**
* Render the selected ranges and append to the Body Group.
* @param blockColumns The columns to render.
* @param absoluteColumnOffsetX Absolute offset from Grid's X co-ordinate to render first column in block.
* @param minVisibleRowIndex The index of the first visible row.
* @param maxVisibleRowIndex The index of the last visible row.
* @param transformer SelectionTransformer in operation.
* @param blockColumns
* The columns to render.
* @param absoluteColumnOffsetX
* Absolute offset from Grid's X co-ordinate to render first column in block.
* @param minVisibleRowIndex
* The index of the first visible row.
* @param maxVisibleRowIndex
* The index of the last visible row.
* @param transformer
* SelectionTransformer in operation.
* @return
*/
protected Group renderSelectedRanges( final List<GridColumn<?>> blockColumns,
Expand Down
Expand Up @@ -38,7 +38,15 @@ public class GridLienzoPanel extends FocusPanel implements RequiresResize,
protected final LienzoPanel lienzoPanel;

public GridLienzoPanel() {
this.lienzoPanel = new LienzoPanel();
this.lienzoPanel = new LienzoPanel() {
@Override
public void onResize() {
// Do nothing. Resize is handled by AttachHandler. LienzoPanel calls onResize() in
// it's onAttach() method which causes the Canvas to be redrawn. However when LienzoPanel
// is adopted by another Widget LienzoPanel's onAttach() is called before its children
// have been attached. Should redraw require children to be attached errors arise.
}
};

domElementContainer.add( lienzoPanel );
add( domElementContainer );
Expand All @@ -49,7 +57,15 @@ public GridLienzoPanel() {
public GridLienzoPanel( final int width,
final int height ) {
this.lienzoPanel = new LienzoPanel( width,
height );
height ) {
@Override
public void onResize() {
// Do nothing. Resize is handled by AttachHandler. LienzoPanel calls onResize() in
// it's onAttach() method which causes the Canvas to be redrawn. However when LienzoPanel
// is adopted by another Widget LienzoPanel's onAttach() is called before its children
// have been attached. Should redraw require children to be attached errors arise.
}
};
this.domElementContainer.setPixelSize( width,
height );

Expand All @@ -73,7 +89,9 @@ public void onScroll( final ScrollEvent scrollEvent ) {
addAttachHandler( new AttachEvent.Handler() {
@Override
public void onAttachOrDetach( final AttachEvent event ) {
onResize();
if ( event.isAttached() ) {
onResize();
}
}
} );
}
Expand Down

0 comments on commit 6197db2

Please sign in to comment.