Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2005 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;
 
 import java.util.List;
 
 
 
This widget shows a list of versions.
 
 public class VersionChooser extends Composite {
 
     private ConstantsCore constants = GWT.createConstantsCore.class );
     private static ImagesCore images    = GWT.createImagesCore.class );
     private AssetServiceAsync assetService = GWT.create(AssetService.class);
 
     private String        packageUUID;
     private String        assetName;
     private ListBox versionChooser;
     private List<TableDataRowversionInfo = new ArrayList<TableDataRow>();
     private String currentVersion;
     private final ClientFactory clientFactory;
     private final EventBus eventBus;
 
     public VersionChooserClientFactory clientFactory,
                            EventBus eventBus,
                            String currentVersion,
                            String pacakgeUUID,
                            String assetName,
                            Command ref ) {
         this. = clientFactory;
         this. = eventBus;
         this. = pacakgeUUID;
         this. = assetName;
         this. = currentVersion;
 
         VerticalPanel verticalPanel = new VerticalPanel();
          = new ListBox();
         loadHistoryData();
         verticalPanel.add();
 
         Button open = new Button"View selected version" );
         open.addClickHandlernew ClickHandler() {
             public void onClick(ClickEvent event) {
                     showVersion.getValue.getSelectedIndex() ) );
             	} 
             }
 
         } );
         verticalPanel.add(open);       
 
         initWidgetverticalPanel );
     }

    
Actually load the history data, as demanded.
 
     protected void loadHistoryData() {
         		                                                ,
                                                                 new GenericCallback<TableDataResult>() {
                                                                     public void onSuccess(TableDataResult table) {
                                                                         if ( table == null || table.data.length ==0) {
                                                                            .addItem(.NoHistory());
                                                                            .add(null);
                                                                            return;
                                                                        }
                                                                        TableDataRow[] rows = table.data;
                                                                        Arrays.sortrows,
                                                                                     new Comparator<TableDataRow>() {
                                                                                         public int compare(TableDataRow r1,
                                                                                                            TableDataRow r2) {                                                                                         
                                                                                             Integer v2 = Integer.valueOfr2.values[0] );
                                                                                             Integer v1 = Integer.valueOfr1.values[0] );
                                                                                             return v2.compareTov1 );
                                                                                         }
                                                                                     } );
                                                                        for (TableDataRow row : rows) {
                                                                            String s = .property0ModifiedOn1By23(
                                                                                    row.values[0],
                                                                                    row.values[2],
                                                                                    row.values[4],
                                                                                    row.values[1]);
                                                                            .addItem(s,
                                                                                    row.id);
                                                                            .add(row);
                                                                        }
                                                                        selectCurrentVersion();
                                                                    }
                                                                } );
    }
    
    public String getSelectedVersionUUID() {
    	if( != null) {
    	} else {
    		return null;
    	}
    }
    
    private void selectCurrentVersion(String currentVersion) {
        for(int i=0;i<.size(); i++) {
            TableDataRow row = .get(i);
            if(row.values[0].equals(currentVersion)) {
                .setSelectedIndex(i);
                break;
            }
        }
    }
    
    public String getSelectedVersionName() {
        if( != null) {
        	if(t != null) {
        		return t.values[0];
        	} 
        } 
        return null;        
    }

    
This should popup a view of the chosen historical version.
    private void showVersion(final String versionUUID) {
        LoadingPopup.showMessage.LoadingVersionFromHistory() );
        .loadRuleAssetversionUUID,
                                                             new GenericCallback<Asset>() {
                                                                 public void onSuccess(Asset asset) {
                                                                     asset.setReadonlytrue );
                                                                     Image image = new Image(.snapshot());
                                                                     image.setAltText(..Snapshot());
                                                                     final FormStylePopup pop = new FormStylePopup(image,
                                                                                                                    .VersionNumber0Of1(
                                                                                                                                   asset.getVersionNumber(),
                                                                                                                                   asset.getName() ),
                                                                             800);
                                                                     RuleViewerWrapper viewer = new RuleViewerWrapper(
                                                                             ,
                                                                             ,
                                                                             asset,
                                                                             true
                                                                                                                                                          );
                                                                     viewer.setWidth"100%" );
                                                                     viewer.setHeight"100%" );
                                                                     pop.addRowviewer );
                                                                     pop.show();
                                                                 }
                                                             } );
    }
New to GrepCode? Check out our FAQ X