Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2011 JBoss Inc
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
   * use this file except in compliance with the License. You may obtain a copy of
   * the License at
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  * License for the specific language governing permissions and limitations under
  * the License.
  */
 package org.drools.workbench.screens.guided.dtable.client.widget.table;
 
 import java.util.List;
 
A Decorated Grid for Decision Tables
 
         implements
         DeleteColumnEvent.Handler,
 
     //Factories to create new data elements
     protected final DecisionTableCellFactory cellFactory;
 
                                                      DecisionTableCellFactory cellFactory,
                                                      DecisionTableCellValueFactory cellValueFactory,
                                                      EventBus eventBus,
                                                      Panel mainPanel,
                                                      Panel bodyPanel,
                                                      AbstractMergableGridWidget<GuidedDecisionTable52BaseColumngridWidget,
                                                      AbstractDecoratedGridHeaderWidget<GuidedDecisionTable52BaseColumnheaderWidget,
                                                      AbstractDecoratedGridSidebarWidget<GuidedDecisionTable52BaseColumnsidebarWidget ) {
         superresources,
                eventBus,
                mainPanel,
                bodyPanel,
                gridWidget,
                headerWidget,
                sidebarWidget );
         if ( cellFactory == null ) {
             throw new IllegalArgumentException"cellFactory cannot be null" );
         }
         if ( cellValueFactory == null ) {
             throw new IllegalArgumentException"cellValueFactory cannot be null" );
         }
         this. = cellFactory;
         this. = cellValueFactory;
 
         //Wire-up event handlers
         eventBus.addHandler.,
                              this );
         eventBus.addHandler.,
                              this );
         eventBus.addHandler.,
                             this );
    }
    public void onSetModelSetModelEvent<GuidedDecisionTable52event ) {
        DynamicData data = new DynamicData();
        GuidedDecisionTable52 model = event.getModel();
        List<DynamicColumn<BaseColumn>> columns = new ArrayList<DynamicColumn<BaseColumn>>();
        setupInternalModelmodel,
                            columns,
                            data );
        //Raise event setting data and columns for UI components
                                                                                          data,
                                                                                          columns );
        .fireEventsime );
    }
    private void setupInternalModelGuidedDecisionTable52 model,
                                     List<DynamicColumn<BaseColumn>> columns,
                                     DynamicData data ) {
        int colIndex = 0;
        int columnWidth = 0;
        int defaultColumnWidth = 100;
        // Dummy rows because the underlying DecoratedGridWidget expects there
        // to be enough rows to receive the columns data
        for ( int iRow = 0; iRow < model.getData().size(); iRow++ ) {
            data.addRow();
        }
        // Static columns, Row#
        BaseColumn rowNumberCol = model.getRowNumberCol();
        DynamicColumn<BaseColumnrowNumberColumn = new DynamicColumn<BaseColumn>( rowNumberCol,
                                                                                   .getCellrowNumberCol ),
                                                                                   colIndex,
                                                                                   true,
                                                                                   false,
                                                                                    );
        rowNumberColumn.setWidth( 24 );
        columns.addrowNumberColumn );
        data.addColumncolIndex,
                        makeRowNumberColumnDatamodel,
                                                 rowNumberCol,
                                                 colIndex++ ),
                        true );
        // Static columns, Description
        BaseColumn descriptionCol = model.getDescriptionCol();
        DynamicColumn<BaseColumndescriptionColumn = new DynamicColumn<BaseColumn>( descriptionCol,
                                                                                     .getCelldescriptionCol ),
                                                                                     colIndex,
                                                                                      );
        columnWidth = descriptionCol.getWidth();
        descriptionColumn.setWidthcolumnWidth <= 0 ? defaultColumnWidth : columnWidth );
        columns.adddescriptionColumn );
        data.addColumncolIndex,
                        makeColumnDatamodel,
                                        descriptionCol,
                                        colIndex++ ),
                        true );
        // Initialise CellTable's Metadata columns
        for ( MetadataCol52 col : model.getMetadataCols() ) {
            DynamicColumn<BaseColumncolumn = new DynamicColumn<BaseColumn>( col,
                                                                              .getCellcol ),
                                                                              colIndex,
                                                                               );
            columnWidth = col.getWidth();
            col.setWidthcolumnWidth <= 0 ? defaultColumnWidth : columnWidth );
            column.setVisible( !col.isHideColumn() );
            columns.addcolumn );
            data.addColumncolIndex,
                            makeColumnDatamodel,
                                            col,
                                            colIndex++ ),
                            column.isVisible() );
        }
        // Initialise CellTable's Attribute columns
        for ( AttributeCol52 col : model.getAttributeCols() ) {
            DynamicColumn<BaseColumncolumn = new DynamicColumn<BaseColumn>( col,
                                                                              .getCellcol ),
                                                                              colIndex,
                                                                               );
            columnWidth = col.getWidth();
            column.setWidthcolumnWidth <= 0 ? defaultColumnWidth : columnWidth );
            column.setVisible( !col.isHideColumn() );
            column.setSystemControlledcol.isUseRowNumber() );
            column.setSortable( !col.isUseRowNumber() );
            columns.addcolumn );
            data.addColumncolIndex,
                            makeColumnDatamodel,
                                            col,
                                            colIndex++ ),
                            column.isVisible() );
        }
        // Initialise CellTable's Condition columns
        for ( CompositeColumn<?> cc : model.getConditions() ) {
            if ( cc instanceof LimitedEntryBRLConditionColumn ) {
                LimitedEntryBRLConditionColumn brl = (LimitedEntryBRLConditionColumncc;
                DynamicColumn<BaseColumncolumn = new DynamicColumn<BaseColumn>( brl,
                                                                                  .getCellbrl ),
                                                                                  colIndex,
                                                                                   );
                columnWidth = brl.getWidth();
                column.setWidthcolumnWidth <= 0 ? defaultColumnWidth : columnWidth );
                column.setVisible( !brl.isHideColumn() );
                columns.addcolumn );
                data.addColumncolIndex,
                                makeColumnDatamodel,
                                                brl,
                                                colIndex++ ),
                                column.isVisible() );
            } else if ( cc instanceof BRLConditionColumn ) {
                BRLConditionColumn brl = (BRLConditionColumncc;
                for ( BRLConditionVariableColumn variable : brl.getChildColumns() ) {
                    DynamicColumn<BaseColumncolumn = new DynamicColumn<BaseColumn>( variable,
                                                                                      .getCellvariable ),
                                                                                      colIndex,
                                                                                       );
                    columnWidth = variable.getWidth();
                    column.setWidthcolumnWidth <= 0 ? defaultColumnWidth : columnWidth );
                    column.setVisible( !variable.isHideColumn() );
                    columns.addcolumn );
                    data.addColumncolIndex,
                                    makeColumnDatamodel,
                                                    variable,
                                                    colIndex++ ),
                                    column.isVisible() );
                }
            } else if ( cc instanceof Pattern52 ) {
                Pattern52 p = (Pattern52cc;
                for ( ConditionCol52 col : p.getChildColumns() ) {
                    DynamicColumn<BaseColumncolumn = new DynamicColumn<BaseColumn>( col,
                                                                                      .getCellcol ),
                                                                                      colIndex,
                                                                                       );
                    columnWidth = col.getWidth();
                    column.setWidthcolumnWidth <= 0 ? defaultColumnWidth : columnWidth );
                    column.setVisible( !col.isHideColumn() );
                    columns.addcolumn );
                    data.addColumncolIndex,
                                    makeColumnDatamodel,
                                                    col,
                                                    colIndex++ ),
                                    column.isVisible() );
                }
            }
        }
        // Initialise CellTable's Action columns
        for ( ActionCol52 col : model.getActionCols() ) {
            if ( col instanceof LimitedEntryBRLActionColumn ) {
                LimitedEntryBRLActionColumn brl = (LimitedEntryBRLActionColumncol;
                DynamicColumn<BaseColumncolumn = new DynamicColumn<BaseColumn>( brl,
                                                                                  .getCellbrl ),
                                                                                  colIndex,
                                                                                   );
                columnWidth = brl.getWidth();
                column.setWidthcolumnWidth <= 0 ? defaultColumnWidth : columnWidth );
                column.setVisible( !brl.isHideColumn() );
                columns.addcolumn );
                data.addColumncolIndex,
                                makeColumnDatamodel,
                                                brl,
                                                colIndex++ ),
                                column.isVisible() );
            } else if ( col instanceof BRLActionColumn ) {
                BRLActionColumn brl = (BRLActionColumncol;
                for ( BRLActionVariableColumn variable : brl.getChildColumns() ) {
                    DynamicColumn<BaseColumncolumn = new DynamicColumn<BaseColumn>( variable,
                                                                                      .getCellvariable ),
                                                                                      colIndex,
                                                                                       );
                    columnWidth = variable.getWidth();
                    column.setWidthcolumnWidth <= 0 ? defaultColumnWidth : columnWidth );
                    column.setVisible( !variable.isHideColumn() );
                    columns.addcolumn );
                    data.addColumncolIndex,
                                    makeColumnDatamodel,
                                                    variable,
                                                    colIndex++ ),
                                    column.isVisible() );
                }
            } else {
                DynamicColumn<BaseColumncolumn = new DynamicColumn<BaseColumn>( col,
                                                                                  .getCellcol ),
                                                                                  colIndex,
                                                                                   );
                columnWidth = col.getWidth();
                column.setWidthcolumnWidth <= 0 ? defaultColumnWidth : columnWidth );
                column.setVisible( !col.isHideColumn() );
                columns.addcolumn );
                data.addColumncolIndex,
                                makeColumnDatamodel,
                                                col,
                                                colIndex++ ),
                                column.isVisible() );
            }
        }
        AnalysisCol52 analysisCol = model.getAnalysisCol();
        DynamicColumn<BaseColumnanalysisColumn = new DynamicColumn<BaseColumn>( analysisCol,
                                                                                  .getCellanalysisCol ),
                                                                                  colIndex,
                                                                                  true,
                                                                                  false,
                                                                                   );
        analysisColumn.setVisible( !analysisCol.isHideColumn() );
        analysisColumn.setWidth( 200 );
        columns.addanalysisColumn );
        data.addColumncolIndex,
                        makeAnalysisColumnDatamodel,
                                                analysisCol,
                                                colIndex++ ),
                        analysisColumn.isVisible() );
    }
    // Make a column of data representing the Row Number column for insertion into a DecoratedGridWidget
    // We don't rely upon the values in the existing data as legacy tables co't guarantee it is sorted
    private List<CellValue<? extends Comparable<?>>> makeRowNumberColumnDataGuidedDecisionTable52 model,
                                                                              BaseColumn column,
                                                                              int colIndex ) {
        int dataSize = model.getData().size();
        List<CellValue<? extends Comparable<?>>> columnData = new ArrayList<CellValue<? extends Comparable<?>>>( dataSize );
        for ( int iRow = 0; iRow < dataSizeiRow++ ) {
            DTCellValue52 dcv = new DTCellValue52();
            dcv.setNumericValueiRow + 1 );
            CellValue<? extends Comparable<?>> cv = .convertModelCellValuecolumn,
                                                                                            dcv );
            columnData.addcv );
        }
        return columnData;
    }
    // Make a column of data for insertion into a DecoratedGridWidget
    private List<CellValue<? extends Comparable<?>>> makeColumnDataGuidedDecisionTable52 model,
                                                                     BaseColumn column,
                                                                     int colIndex ) {
        int dataSize = model.getData().size();
        List<CellValue<? extends Comparable<?>>> columnData = new ArrayList<CellValue<? extends Comparable<?>>>( dataSize );
        for ( int iRow = 0; iRow < dataSizeiRow++ ) {
            List<DTCellValue52row = model.getData().getiRow );
            DTCellValue52 dcv = row.getcolIndex );
            CellValue<? extends Comparable<?>> cv = .convertModelCellValuecolumn,
                                                                                            dcv );
            columnData.addcv );
        }
        return columnData;
    }
    // Make a column of data representing the Analysis column for insertion into a DecoratedGridWidget
    private List<CellValue<? extends Comparable<?>>> makeAnalysisColumnDataGuidedDecisionTable52 model,
                                                                             AnalysisCol52 column,
                                                                             int colIndex ) {
        model.initAnalysisColumn();
        int dataSize = model.getAnalysisData().size();
        List<CellValue<? extends Comparable<?>>> columnData = new ArrayList<CellValue<? extends Comparable<?>>>( dataSize );
        for ( int iRow = 0; iRow < dataSizeiRow++ ) {
            CellValue<? extends Comparable<?>> cv = .makeNewAnalysisCellValue();
            columnData.addcv );
        }
        return columnData;
    }
    public void onInsertColumnInsertColumnEvent<BaseColumnDTCellValue52event ) {
        List<DynamicColumn<BaseColumn>> columns = new ArrayList<DynamicColumn<BaseColumn>>();
        List<List<CellValue<? extends Comparable<?>>>> columnsData = new ArrayList<List<CellValue<? extends Comparable<?>>>>();
        List<BaseColumnallColumns = event.getColumns();
        List<List<DTCellValue52>> allColumnsData = event.getColumnsData();
        for ( int iCol = 0; iCol < event.getColumns().size(); iCol++ ) {
            final BaseColumn column = allColumns.getiCol );
            final List<DTCellValue52columnData = allColumnsData.getiCol );
            DynamicColumn<BaseColumndc = new DynamicColumn<BaseColumn>( column,
                                                                          .getCellcolumn ),
                                                                           );
            dc.setVisible( !column.isHideColumn() );
            List<CellValue<? extends Comparable<?>>> dcd = .convertColumnDatacolumn,
                                                                                               columnData );
            columns.adddc );
            columnsData.adddcd );
        }
        //Raise event setting data and columns for UI components
                                                                                                 columnsData,
                                                                                                 event.getIndex(),
                                                                                                 event.redraw() );
        .fireEventice );
        //Assert dimensions once column has been added
        if ( event.redraw() ) {
            Scheduler.get().scheduleDeferrednew Command() {
                public void execute() {
                    assertDimensions();
                }
            } );
        }
    }
    public void onDeleteColumnDeleteColumnEvent event ) {
        if ( event.redraw() ) {
            Scheduler.get().scheduleDeferrednew Command() {
                public void execute() {
                    assertDimensions();
                }
            } );
        }
    }
New to GrepCode? Check out our FAQ X