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.guvnor.client.widgets.tables;
 
 
 
 import java.util.List;
 import java.util.Set;

Widget that shows rows of paged data where columns "uuid", "name" and "format" are common. A "checkbox" and "open" button column are added by default. Additional columns can be inserted inbetween these columns by overriding addAncillaryColumns(). A "RSS Feed" button can also be included if required.

Based upon work by Geoffrey de Smet.

 
 public abstract class AbstractAssetPagedTable<T extends AbstractAssetPageRowextends AbstractPagedTable<T> {
 
     // UI
     @SuppressWarnings("rawtypes")
     interface AssetPagedTableBinder
             extends
             UiBinder<WidgetAbstractAssetPagedTable> {
     }
 
     protected static final ConstantsCore constants = GWT.createConstantsCore.class );
 
     private static AssetPagedTableBinder uiBinder = GWT.createAssetPagedTableBinder.class );
 
     @UiField()
     protected Image feedImage;
 
     protected Set<CommandunloadListenerSet = new HashSet<Command>();
     protected MultiSelectionModel<T> selectionModel;
 
     protected String feedURL;
 
     private final ClientFactory clientFactory;
 
     public AbstractAssetPagedTable(int pageSize,
                                    ClientFactory clientFactory) {
         thispageSize,
                 null,
                 clientFactory );
     }
 
     public AbstractAssetPagedTable(int pageSize,
                                    String feedURL,
                                    ClientFactory clientFactory) {
         superpageSize );
         this. = feedURL;
         if ( this. == null
                 || "".equalsfeedURL ) ) {
             this..setVisiblefalse );
         }
 
        this. = clientFactory;
    }

    
Register an UnloadListener used to remove "RSS Feed Listeners" when the table is unloaded

Parameters:
unloadListener
    public void addUnloadListener(Command unloadListener) {
        .addunloadListener );
    }

    
Return an array of selected UUIDs. API is maintained for backwards compatibility of legacy code with AssetItemGrid's implementation

Returns:
    public String[] getSelectedRowUUIDs() {
        Set<T> selectedRows = .getSelectedSet();
        // Compatibility with existing API
        if ( selectedRows.size() == 0 ) {
            return null;
        }
        // Create the array of UUIDs
        String[] uuids = new String[selectedRows.size()];
        int rowCount = 0;
        for (T row : selectedRows) {
            uuids[rowCount++] = row.getUuid();
        }
        return uuids;
    }
    @UiHandler("archiveSelectedButton")
    public void archiveSelectedAssets(ClickEvent e) {
        if (getSelectedRowUUIDs() == null) {
            Window.alert(.PleaseSelectAnItemToArchive());
            return;
        }
        if (!Window.confirm(.AreYouSureYouWantToArchiveTheseItems())) {
            return;
        }
                new GenericCallback<Void>() {
                    public void onSuccess(Void arg0) {
                        Window.alert(.ArchivedAssets());
                        refresh();
                    }
                });
    }

    
Open selected item(s) to a single tab

Parameters:
e
    @UiHandler("openSelectedToSingleTabButton")
    public void openSelectedToSingleTab(ClickEvent e) {
        Set<T> selectedSet = .getSelectedSet();
        List<MultiViewRowmultiViewRowList = new ArrayList<MultiViewRow>( selectedSet.size() );
        for (T selected : selectedSet) {
            multiViewRowList.add(
                    new MultiViewRow(
                            selected.getUuid(),
                            selected.getName(),
                            selected.getFormat() ) );
        }
        .getPlaceController().goTonew MultiAssetPlacemultiViewRowList ) );
    }

    
Refresh table programmatically
    public void refresh() {
        .clear();
                true );
    }

    
Set up table and common columns. Additional columns can be appended between the "checkbox" and "open" columns by overriding addAncillaryColumns()
    @Override
    protected void doCellTable() {
        ProvidesKey<T> providesKey = new ProvidesKey<T>() {
            public Object getKey(T row) {
                return row.getUuid();
            }
        };
         = new CellTable<T>( providesKey );
         = new MultiSelectionModel<T>( providesKey );
        SelectionColumn.createAndAddSelectionColumn );
        ColumnPicker<T> columnPicker = new ColumnPicker<T>(  );
        SortableHeaderGroup<T> sortableHeaderGroup = new SortableHeaderGroup<T>(  );
        final TextColumn<T> uuidNumberColumn = new TextColumn<T>() {
            public String getValue(T row) {
                return row.getUuid();
            }
        };
        columnPicker.addColumnuuidNumberColumn,
                new SortableHeader<T, String>(
                        sortableHeaderGroup,
                        .uuid(),
                        uuidNumberColumn ),
                false );
        // Add any additional columns
        addAncillaryColumnscolumnPicker,
                sortableHeaderGroup );
        // Add "Open" button column
        Column<T, StringopenColumn = new Column<T, String>( new ButtonCell() ) {
            public String getValue(T row) {
                return .Open();
            }
        };
        openColumn.setFieldUpdaternew FieldUpdater<T, String>() {
            public void update(int index,
                               T row,
                               String value) {
                .getPlaceController().goTonew AssetEditorPlacerow.getUuid() ) );
            }
        } );
        columnPicker.addColumnopenColumn,
                new TextHeader.Open() ),
                true );
        .setWidth"100%" );
         = columnPicker.createToggleButton();
    }

    
Disconnect all listening consumers
    @Override
    protected void onUnload() {
        super.onUnload();
        for (Command unloadListener : ) {
            unloadListener.execute();
        }
    }

    
Link a data provider to the table

Parameters:
dataProvider
    public void setDataProvider(AsyncDataProvider<T> dataProvider) {
        this. = dataProvider;
        this..addDataDisplay );
    }

    
Construct a widget representing the table
    @Override
    protected Widget makeWidget() {
        return .createAndBindUithis );
    }
    @UiHandler("feedImage")
    void openFeed(ClickEvent e) {
        if ( !.isVisible()
                ||  == null
                || "".equals ) ) {
            return;
        }
        Window.open,
                "_blank",
                null );
    }

    
Open selected item(s) to separate tabs

Parameters:
e
    @UiHandler("openSelectedButton")
    void openSelected(ClickEvent e) {
        Set<T> selectedSet = .getSelectedSet();
        for (T selected : selectedSet) {
            .getPlaceController().goTonew AssetEditorPlaceselected.getUuid() ) );
        }
    }

    
Refresh table in response to ClickEvent

Parameters:
e
    @UiHandler("refreshButton")
    void refresh(ClickEvent e) {
        refresh();
    }
New to GrepCode? Check out our FAQ X