Project

General

Profile

« Previous | Next » 

Revision d574f7e6

Added by Andreas Kohlbecker almost 7 years ago

ref #6169 TeamOrPersonField with buttons to remove and add Person and Team instances

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java
11 11
import com.vaadin.data.fieldgroup.BeanFieldGroup;
12 12
import com.vaadin.data.fieldgroup.FieldGroup;
13 13
import com.vaadin.data.util.BeanItem;
14
import com.vaadin.server.FontAwesome;
14 15
import com.vaadin.server.UserError;
16
import com.vaadin.ui.Button;
15 17
import com.vaadin.ui.Component;
16 18
import com.vaadin.ui.CssLayout;
19
import com.vaadin.ui.themes.ValoTheme;
17 20

  
18 21
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
19 22
import eu.etaxonomy.cdm.model.agent.Person;
......
21 24
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
22 25
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
23 26
import eu.etaxonomy.vaadin.component.CompositeCustomField;
24
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesListSelect;
25 27
import eu.etaxonomy.vaadin.component.SwitchableTextField;
28
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesListSelect;
26 29

  
27 30
/**
28 31
 * @author a.kohlbecker
......
36 39
    private static final String PRIMARY_STYLE = "v-team-or-person-field";
37 40

  
38 41
    private CssLayout root = new CssLayout();
42
    private CssLayout toolBar= new CssLayout();
39 43
    private CssLayout compositeWrapper = new CssLayout();
40 44

  
45
    private Button removeButton = new Button(FontAwesome.REMOVE);
46
    private Button personButton = new Button(FontAwesome.USER);
47
    private Button teamButton = new Button(FontAwesome.USERS);
48

  
41 49
    // Fields for case when value is a Person
42 50
    private PersonField personField = new PersonField();
43 51

  
......
56 64
        addStyledComponent(titleField);
57 65
        addStyledComponent(nomenclaturalTitleField);
58 66
        addStyledComponent(personsListEditor);
67
        addStyledComponents(removeButton, personButton, teamButton);
68

  
59 69

  
60 70
        addSizedComponent(root);
61 71
        addSizedComponent(compositeWrapper);
......
70 80
     */
71 81
    @Override
72 82
    protected Component initContent() {
73
        root.setPrimaryStyleName(PRIMARY_STYLE);
83

  
84
        removeButton.addClickListener(e -> {
85
            setValue(null);
86
            updateToolBarButtonStates();
87
        });
88
        removeButton.setDescription("Remove");
89

  
90
        personButton.addClickListener(e -> {
91
            setValue(Person.NewInstance()); // FIXME add SelectField or open select dialog, use ToOneSelect field!!
92
            updateToolBarButtonStates();
93
        });
94
        personButton.setDescription("Add person");
95
        teamButton.addClickListener(e -> {
96
            setValue(Team.NewInstance()); // FIXME add SelectField or open select dialog, use ToOneSelect field!!
97
            updateToolBarButtonStates();
98
        });
99
        teamButton.setDescription("Add team");
100

  
101
        toolBar.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP + " toolbar");
102
        toolBar.addComponents(removeButton, personButton, teamButton);
103

  
74 104
        compositeWrapper.setStyleName("margin-wrapper");
105
        compositeWrapper.addComponent(toolBar);
106

  
107
        root.setPrimaryStyleName(PRIMARY_STYLE);
75 108
        root.addComponent(compositeWrapper);
76 109
        return root;
77 110
    }
......
84 117
        return TeamOrPersonBase.class;
85 118
    }
86 119

  
120
    private void updateToolBarButtonStates(){
121
        TeamOrPersonBase<?> val = getInternalValue();
122
        removeButton.setEnabled(val != null);
123
        personButton.setEnabled(val == null);
124
        teamButton.setEnabled(val == null);
125
    }
126

  
87 127
    /**
88 128
     * {@inheritDoc}
89 129
     */
......
94 134

  
95 135
        newValue = HibernateProxyHelper.deproxy(newValue);
96 136

  
137
        compositeWrapper.removeAllComponents();
138
        compositeWrapper.addComponent(toolBar);
139

  
97 140
        if(newValue == null) {
98 141
            return;
99 142
        }
......
123 166
            setComponentError(new UserError("TeamOrPersonField Error: Unsupported value type: " + newValue.getClass().getName()));
124 167
        }
125 168

  
169
        updateToolBarButtonStates();
126 170
        checkUserPermissions(newValue);
127 171
    }
128 172

  
src/main/webapp/VAADIN/themes/edit-valo/custom-fields.scss
121 121
    
122 122
   // team-or-person-field
123 123
   .v-team-or-person-field {
124
   
125
        .toolbar {
126
            float: right;
127
            height: $v-unit-size;
128
        }
124 129
        .margin-wrapper {
125 130
            @include composite-field-wrapper;
131
            
126 132
        }
127 133
    }
128 134
    

Also available in: Unified diff