1. #1
    Ext User
    Join Date
    Jun 2008
    Posts
    3
    Vote Rating
    0
    zhoujianghao is on a distinguished road

      0  

    Default How to clone a Field?

    How to clone a Field?


    Hi,
    I have a method with parameter abstract Field , i need to clone a new one and return it.
    just like:

    public Field cloneField(Field input)
    {
    return GWT.create(input.getClass());
    }
    It works fine in hostmode,but compile error in ant building with message:
    "Only class literals may be used as arguments to GWT.create()".
    Is that means abstract class or interface can't use in create method?
    Thanks.

  2. #2
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    2
    gslender is on a distinguished road

      0  

    Default


    No, it requires... Field.class - but in saying that, as its abstract there is not really a way to use it.. you should be creating sub classes of Field.

    Why do you want to clone the field? Perhaps there is another simpler solution.

  3. #3
    Ext User
    Join Date
    Jun 2008
    Posts
    3
    Vote Rating
    0
    zhoujianghao is on a distinguished road

      0  

    Default


    Actually, i want to build a MultiField's subclass which can add a Field repeatly just like add attachments in email, and the field doesn't need to know what exactly it is and can be added repeatly.

    Thanks.

  4. #4
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    2
    gslender is on a distinguished road

      0  

    Default


    ...still can't say I fully understand what you are doing - if you provide a small example/test case then I'd be happy to help you figure out another way to do what you need.

  5. #5
    Ext User
    Join Date
    Jun 2008
    Posts
    3
    Vote Rating
    0
    zhoujianghao is on a distinguished road

      0  

    Default


    Code:
    public class MyRepeatFieldGroup extends MultiField<Field> {
        
        private LayoutContainer lc = new LayoutContainer(new FormLayout());
        
        public BTRepeatEditorFieldGroup(final Field field) {
            setOrientation(Orientation.VERTICAL);
    
            lc.setLayoutOnChange(true);
            lc.add(new MyRepeatField(cloneField(field)));
            
            final LayoutContainer lc_btn = new LayoutContainer();
            final Button btn = new Button("Add");
            btn.setIconStyle("bt-icon-add");
            btn.addSelectionListener(new SelectionListener<ButtonEvent>(){
                public void componentSelected(ButtonEvent ce) {
                    lc.add(new BTRepeatEditorField(cloneField(field)));
                }});
            lc_btn.add(btn);
            add(new AdapterField(lc));
            add(new AdapterField(lc_btn));
        }
    }
    Code:
    public class MyRepeatField extends MultiField<Field> {
    
        private Field field;
        
        public MyRepeatField(Field field) {
            this.field = field;
            setHideLabel(true);
            field.setHideLabel(true);
            setOrientation(Orientation.HORIZONTAL);
            add(field);
            LabelField label = new LabelField("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
            label.setHideLabel(true);
            add(label);
            final Button btn = new Button("Delete");
            btn.setIconStyle("bt-icon-cancel");
            btn.addSelectionListener(new SelectionListener<ButtonEvent>(){
                public void componentSelected(ButtonEvent ce) {
                    MyRepeatField.this.removeFromParent();
                }});
            add(new AdapterField(btn));
        }
        
        public Object getRepeatValue()
        {
            return field.getValue();
        }
        
        public void setRepeateValue(Object obj)
        {
            field.setValue(obj);
        }
    }
    In the class MyRepeatFieldGroup's cloneField method i want to clone another one,and display repeatly.

  6. #6
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    2
    gslender is on a distinguished road

      0  

    Default


    zhoujianghao,

    Can you provide a section of code that uses the above snippet - start with onModuleLoad and go from there... I'm happy to help, but you need to provide complete code examples that clearly show the problem you are having.

    Also, can you provide some background on what you are trying to do - what is the goal behind trying to create new fields where you don't know what kind of field it is ??

  7. #7
    Sencha User
    Join Date
    Dec 2007
    Posts
    96
    Vote Rating
    0
    nanich is on a distinguished road

      0  

    Default Cloning a field in editors

    Cloning a field in editors


    In Editor Grid, when the columns rendered for the first time, everything works fine. But when the new columns gets added when another entity value changes on the UI, I needed to rebuild the whole column model which will re-create the column editors as well.
    But when I'm creating the column's underlying field only once... when it has got rendered for the first time, having the rendered flag as TRUE, the same will not get rendered for the subsequent store refreshes.

    So no editors are being seen on the UI from the second refresh of the grid onwards. So, the solution I found myself is to create a new clone of existing field so that the same will be considered for re-rendering when the editor gets rendered.

    It would be great if I can do the generic clone of a field with all the listeners attached to it.
    Thanks,
    nanich

Thread Participants: 2

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar