Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2010 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.ruleeditor;
 /*
  * 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.
  */
 
 
 
 import  org.drools.guvnor.client.categorynav.CategoryExplorerWidget;
 import  org.drools.guvnor.client.categorynav.CategorySelectHandler;
 import  org.drools.guvnor.client.common.DirtyableComposite;
 import  org.drools.guvnor.client.common.DirtyableFlexTable;
 import  org.drools.guvnor.client.common.FormStylePopup;
 import  org.drools.guvnor.client.common.ImageButton;
 import  org.drools.guvnor.client.common.SmallLabel;
 import  org.drools.guvnor.client.rpc.MetaData;
 import  org.drools.guvnor.client.messages.Constants;
 
 import  com.google.gwt.user.client.ui.Button;
 import  com.google.gwt.user.client.ui.ClickListener;
 import  com.google.gwt.user.client.ui.FlexTable;
 import  com.google.gwt.user.client.ui.Image;
 import  com.google.gwt.user.client.ui.VerticalPanel;
 import  com.google.gwt.user.client.ui.Widget;
 import  com.google.gwt.core.client.GWT;

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.

Author(s):
Michael Neale
Fernando Meyer
 
 public class AssetCategoryEditor extends DirtyableComposite {
 
     private MetaData data;
     private DirtyableFlexTable layout = new DirtyableFlexTable();
     private FlexTable list;
 	private boolean readOnly;
     private Constants constants = GWT.create(Constants.class);


    

Parameters:
d The meta data.
readOnly If it is to be non editable.
 
     public AssetCategoryEditor(MetaData dboolean 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 = new ImageButton("images/new_item.gif");
         add.setTitle(.AddANewCategory());
 
         add.addClickListener( new ClickListener() {
             public void onClick(Widget w) {
                doOKClick();
            }
        });
        actions.add( add );
        .setWidget( 0, 1, actions );
    }
    protected void removeCategory(int idx) {
        .removeCategory( idx );
        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 < ..i++ ) {
            final int idx = i;
            list.setWidget( i, 0, new SmallLabel(.[i]) );
            if (!) {
	            Image del = new ImageButton("images/trash.gif");
	            del.setTitle(.RemoveThisCategory());
	            del.addClickListener( new ClickListener() {
	                public void onClick(Widget w) {
	                    removeCategory(idx);
	                }
	            } );
	            list.setWidget( i, 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) {
        .addCategory( selectedPath );
        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 CategoryExplorerWidget(new CategorySelectHandler() {
                public void selected(String sel) {
                     = sel;
                }
            });
            vert.add(  );
            vert.add(  );
            addRow( vert );
            .addClickListener( new ClickListener() {
                public void onClick(Widget w) {
                    if ( != null &&  !"".equals()) {
                        addToCategory();
                    }
                    hide();
                }
            });
        }
    }
New to GrepCode? Check out our FAQ X