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;
 
 
This is a viewer/editor for categories. It will show a list of categories currently applicable, and allow you to remove/add to them. It is intended to work with the meta data form.
 
 public class AssetCategoryEditor extends DirtyableComposite {
 
     private ConstantsCore constants = GWT.createConstantsCore.class );
     private static ImagesCore images    = GWT.createImagesCore.class );
 
     private MetaData           data;
     private DirtyableFlexTable layout    = new DirtyableFlexTable();
     private FlexTable          list;
     private boolean            readOnly;

    

Parameters:
d The meta data.
readOnly If it is to be non editable.
 
     public AssetCategoryEditor(MetaData d,
                                boolean readOnly) {
         this. = d;
 
          = new FlexTable();
         this. = readOnly;
         loadData );
         .setStyleName"rule-List" );
         .setWidget( 0,
                           0,
                            );
 
         if ( !readOnly ) {
             doActions();
         }
 
         initWidget );
     }
 
     private void doActions() {
         VerticalPanel actions = new VerticalPanel();
         Image add = ..NewItem();
         add.setTitle.AddANewCategory() );
 
         add.addClickHandlernew ClickHandler() {
             public void onClick(ClickEvent event) {
                 doOKClick();
             }
         } );
 
         actions.addadd );
         .setWidget( 0,
                           1,
                           actions );
 
     }
 
     protected void removeCategory(int idx) {
         .removeCategoryidx );
        makeDirty();
        resetBox();
    }
    private void resetBox() {
         = new FlexTable();
        .setStyleName"rule-List" );
        .setWidget( 0,
                          0,
                           );
        loadData );
        makeDirty();
    }
    private void loadData(FlexTable list) {
        for ( int i = 0; i < .getCategories().lengthi++ ) {
            final int idx = i;
            list.setWidgeti,
                            0,
                            new SmallLabel.getCategories()[i] ) );
            if ( ! ) {
                Image del = ..Trash();
                del.setTitle.RemoveThisCategory() );
                del.addClickHandlernew ClickHandler() {
                    public void onClick(ClickEvent event) {
                        removeCategoryidx );
                    }
                } );
                list.setWidgeti,
                                1,
                                del );
            }
        }
    }

    
Handles the OK click on the selector popup
    private void doOKClick() {
        CategorySelector sel = new CategorySelector();
        sel.show();
    }

    
Appy the change (selected path to be added).
    public void addToCategory(String selectedPath) {
        .addCategoryselectedPath );
        resetBox();
    }

    
This is a popup that allows you to select a category to add to the asset.
    class CategorySelector extends FormStylePopup {
        public Button                  ok = new Button.OK() );
        private CategoryExplorerWidget selector;
        public String                  selectedPath;
        public CategorySelector() {
            setTitle.SelectCategoryToAdd() );
            VerticalPanel vert = new VerticalPanel();
             = new CategoryExplorerWidgetnew CategorySelectHandler() {
                public void selected(String sel) {
                     = sel;
                }
            } );
            vert.add );
            vert.add );
            addRowvert );
            .addClickHandlernew ClickHandler() {
                public void onClick(ClickEvent event) {
                    if (  != null && !"".equals ) ) {
                        addToCategory );
                    }
                    hide();
                }
            } );
        }
    }
New to GrepCode? Check out our FAQ X