Skip to content

Commit

Permalink
GUVNOR-1682: Decision Tables: View mode where editing is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
manstis committed Jan 31, 2012
1 parent 3a44853 commit 15fbe9c
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 88 deletions.
Expand Up @@ -35,7 +35,6 @@
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasEnabled;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Widget;
Expand All @@ -57,7 +56,7 @@ public class CEPWindowOperatorsDropdown extends Composite
private HorizontalPanel parametersContainer = new HorizontalPanel();
private HorizontalPanel windowContainer = new HorizontalPanel();

private boolean isEnabled = true;
private boolean isReadOnly = false;

protected HasCEPWindow hcw;

Expand All @@ -69,8 +68,10 @@ public CEPWindowOperatorsDropdown() {
initWidget( windowContainer );
}

public CEPWindowOperatorsDropdown(HasCEPWindow hcw) {
public CEPWindowOperatorsDropdown(HasCEPWindow hcw,
boolean isReadOnly) {
this();
this.isReadOnly = isReadOnly;
setCEPWindow( hcw );
}

Expand Down Expand Up @@ -100,17 +101,6 @@ public String getValue(int index) {
return box.getValue( index );
}

public void setEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
box.setEnabled( isEnabled );
for ( int iChildWidgetIndex = 0; iChildWidgetIndex < parametersContainer.getWidgetCount(); iChildWidgetIndex++ ) {
Widget childWidget = parametersContainer.getWidget( iChildWidgetIndex );
if ( childWidget instanceof HasEnabled ) {
((HasEnabled) childWidget).setEnabled( isEnabled );
}
}
}

//Additional widget for CEP Window operator parameter
private Widget getOperatorExtension() {
parametersContainer.setStylePrimaryName( css.container() );
Expand Down Expand Up @@ -150,7 +140,7 @@ private void initialiseTextBox(AbstractRestrictedEntryTextBox txt) {
value );
}
txt.setText( value );
txt.setEnabled( isEnabled );
txt.setEnabled( !isReadOnly );
parametersContainer.add( txt );
parametersContainer.setVisible( true );
hcw.getWindow().setParameter( SharedConstants.OPERATOR_PARAMETER_GENERATOR,
Expand All @@ -163,10 +153,12 @@ private Widget getDropDown() {

String selected = "";
String selectedText = "";
box = new ListBox();

box = new ListBox();
box.setEnabled( !isReadOnly );
box.addItem( constants.noCEPWindow(),
"" );

for ( int i = 0; i < operators.size(); i++ ) {
String op = operators.get( i );
box.addItem( HumanReadable.getOperatorDisplayName( op ),
Expand Down
Expand Up @@ -538,18 +538,21 @@ private Widget createCEPWindowWidget(final RuleModeller modeller,
Label lbl = new Label( constants.OverCEPWindow() );
lbl.setStyleName( "paddedLabel" );
hp.add( lbl );
CEPWindowOperatorsDropdown cwo = new CEPWindowOperatorsDropdown( c );

cwo.addValueChangeHandler( new ValueChangeHandler<OperatorSelection>() {

public void onValueChange(ValueChangeEvent<OperatorSelection> event) {
setModified( true );
OperatorSelection selection = event.getValue();
String selected = selection.getValue();
c.getWindow().setOperator( selected );
getModeller().makeDirty();
}
} );
CEPWindowOperatorsDropdown cwo = new CEPWindowOperatorsDropdown( c,
readOnly );

if ( !this.isReadOnly() ) {
cwo.addValueChangeHandler( new ValueChangeHandler<OperatorSelection>() {

public void onValueChange(ValueChangeEvent<OperatorSelection> event) {
setModified( true );
OperatorSelection selection = event.getValue();
String selected = selection.getValue();
c.getWindow().setOperator( selected );
getModeller().makeDirty();
}
} );
}

hp.add( cwo );
return hp;
Expand Down
Expand Up @@ -35,6 +35,7 @@ public class TemplateDataCellFactory extends AbstractCellFactory<TemplateDataCol
public TemplateDataCellFactory(SuggestionCompletionEngine sce,
EventBus eventBus) {
super( sce,
false,
eventBus );
}

Expand Down Expand Up @@ -62,7 +63,7 @@ public TemplateDataCellFactory(SuggestionCompletionEngine sce,

//Make a drop-down or plain cell
if ( vals != null && vals.length > 0 ) {
PopupDropDownEditCell pudd = new PopupDropDownEditCell();
PopupDropDownEditCell pudd = new PopupDropDownEditCell( isReadOnly );
pudd.setItems( vals );
cell = new DecoratedGridCellValueAdaptor<String>( pudd,
eventBus );
Expand Down
Expand Up @@ -777,8 +777,8 @@ private Widget createCEPWindowWidget(final HasCEPWindow c) {
lbl.setStyleName( "paddedLabel" );
hp.add( lbl );

cwo = new CEPWindowOperatorsDropdown( c );
cwo.setEnabled( !isReadOnly );
cwo = new CEPWindowOperatorsDropdown( c,
isReadOnly );
if ( !isReadOnly ) {
cwo.addValueChangeHandler( new ValueChangeHandler<OperatorSelection>() {

Expand Down
Expand Up @@ -1418,8 +1418,9 @@ private void setupColumnsNote() {
}

private void setupDecisionTable() {
dtable = new VerticalDecisionTableWidget( new DecisionTableControlsWidget(),
dtable = new VerticalDecisionTableWidget( new DecisionTableControlsWidget( isReadOnly ),
getSCE(),
isReadOnly,
eventBus );
dtable.setPixelSize( 1000,
400 );
Expand Down
Expand Up @@ -45,6 +45,7 @@ public abstract class AbstractPopupEditCell<C, V> extends
protected final PopupPanel panel;
protected final VerticalPanel vPanel;
protected final SafeHtmlRenderer<String> renderer;
protected final boolean isReadOnly;
protected ValueUpdater<C> valueUpdater;

/**
Expand All @@ -54,11 +55,12 @@ public abstract class AbstractPopupEditCell<C, V> extends
*
* @param renderer
*/
public AbstractPopupEditCell() {
public AbstractPopupEditCell(boolean isReadOnly) {
super( "dblclick",
"keydown" );
this.renderer = SimpleSafeHtmlRenderer.getInstance();
this.vPanel = new VerticalPanel();
this.isReadOnly = isReadOnly;

// Pressing ESCAPE dismisses the pop-up loosing any changes
this.panel = new PopupPanel( true,
Expand Down Expand Up @@ -108,6 +110,11 @@ public void onBrowserEvent(Context context,
NativeEvent event,
ValueUpdater<C> valueUpdater) {

//If read-only ignore editing events
if ( isReadOnly ) {
return;
}

// KeyDown and "Enter" key-press is handled here
super.onBrowserEvent( context,
parent,
Expand Down
Expand Up @@ -37,17 +37,17 @@
* PatternsChangedEvents so that it's content can be maintained as and when
* Patterns are added, deleted or edited.
*/
public class PopupBoundPatternDropDownEditCell extends
AbstractPopupEditCell<String, String>
public class PopupBoundPatternDropDownEditCell extends AbstractPopupEditCell<String, String>
implements
BoundFactsChangedEvent.Handler {

private Constants constants = GWT.create( Constants.class );

private final ListBox listBox;

public PopupBoundPatternDropDownEditCell(EventBus eventBus) {
super();
public PopupBoundPatternDropDownEditCell(EventBus eventBus,
boolean isReadOnly) {
super( isReadOnly );
this.listBox = new ListBox();

// Tabbing out of the ListBox commits changes
Expand Down
Expand Up @@ -33,8 +33,9 @@ public class PopupDateEditCell extends AbstractPopupEditCell<Date, Date> {
private final DatePicker datePicker;
private final DateTimeFormat format;

public PopupDateEditCell(DateTimeFormat format) {
super();
public PopupDateEditCell(DateTimeFormat format,
boolean isReadOnly) {
super( isReadOnly );
if ( format == null ) {
throw new IllegalArgumentException( "format == null" );
}
Expand Down
Expand Up @@ -36,8 +36,8 @@ public class PopupDropDownEditCell extends
private final ListBox listBox;
private String[][] items;

public PopupDropDownEditCell() {
super();
public PopupDropDownEditCell(boolean isReadOnly) {
super( isReadOnly );
this.listBox = new ListBox();

// Tabbing out of the ListBox commits changes
Expand Down
Expand Up @@ -41,8 +41,8 @@ public class PopupNumericEditCell extends
// A valid number
private static final RegExp VALID = RegExp.compile( "(^[-+]?[0-9]*\\.?[0-9]*([eE][-+]?[0-9]*)?$)" );

public PopupNumericEditCell() {
super();
public PopupNumericEditCell(boolean isReadOnly) {
super(isReadOnly);
this.textBox = new TextBox();

// Tabbing out of the TextBox commits changes
Expand Down
Expand Up @@ -33,7 +33,11 @@ public class PopupTextEditCell extends AbstractPopupEditCell<String, String> {
private final TextBox textBox;

public PopupTextEditCell() {
super();
this( false );
}

public PopupTextEditCell(boolean isReadOnly) {
super( isReadOnly );
this.textBox = new TextBox();

// Tabbing out of the TextBox commits changes
Expand Down
Expand Up @@ -62,14 +62,16 @@ public class DecisionTableCellFactory extends AbstractCellFactory<BaseColumn> {
*
* @param sce
* SuggestionCompletionEngine to assist with drop-downs
* @param model
* The Decision Table model to assist data-type derivation
* @param isReadOnly
* Should cells be created for a read-only mode of operation
* @param eventBus
* An EventBus on which cells can subscribe to events
*/
public DecisionTableCellFactory(SuggestionCompletionEngine sce,
boolean isReadOnly,
EventBus eventBus) {
super( sce,
isReadOnly,
eventBus );
}

Expand Down Expand Up @@ -207,7 +209,8 @@ public void setModel(GuidedDecisionTable52 model) {
}

//Drop down of possible patterns
PopupBoundPatternDropDownEditCell pudd = new PopupBoundPatternDropDownEditCell( eventBus );
PopupBoundPatternDropDownEditCell pudd = new PopupBoundPatternDropDownEditCell( eventBus,
isReadOnly );
BRLRuleModel rm = new BRLRuleModel( model );
pudd.setFactBindings( rm.getLHSBoundFacts() );
return new DecoratedGridCellValueAdaptor<String>( pudd,
Expand Down Expand Up @@ -242,7 +245,7 @@ public void setModel(GuidedDecisionTable52 model) {
} else {

// Columns with lists of values, enums etc are always Text (for now)
PopupDropDownEditCell pudd = new PopupDropDownEditCell();
PopupDropDownEditCell pudd = new PopupDropDownEditCell( isReadOnly );
pudd.setItems( vals );
cell = new DecoratedGridCellValueAdaptor<String>( pudd,
eventBus );
Expand All @@ -252,7 +255,7 @@ public void setModel(GuidedDecisionTable52 model) {

// Make a new Cell for Dialect columns
private DecoratedGridCellValueAdaptor<String> makeDialectCell() {
PopupDropDownEditCell pudd = new PopupDropDownEditCell();
PopupDropDownEditCell pudd = new PopupDropDownEditCell( isReadOnly );
pudd.setItems( DIALECTS );
return new DecoratedGridCellValueAdaptor<String>( pudd,
eventBus );
Expand Down

0 comments on commit 15fbe9c

Please sign in to comment.