Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TaskEditorWidget extends Composite implements Editor<TaskProxy>, HasSelectionHandlers<FormPanel.FormLabel>{
- private static TaskEditorWidgetUiBinder uiBinder = GWT
- .create(TaskEditorWidgetUiBinder.class);
- interface TaskEditorWidgetUiBinder extends UiBinder<Widget, TaskEditorWidget> {}
- @UiField protected FormPanel form;
- @UiField protected TextField titleEditor;
- @UiField protected TextArea descriptionEditor;
- @UiField protected PropertiesMultiSelect propertiesEditor;
- @UiField(provided=true) protected ValueListBox<AccountProxy> assignedToEditor;
- public TaskEditorWidget() {
- assignedToEditor = new ValueListBox<AccountProxy>(AccountProxy.renderer , AccountProxy.keyProvider );
- initWidget(uiBinder.createAndBindUi(this));
- }
- public void setAccounts(List<AccountProxy> accounts){
- assignedToEditor.setAcceptableValues(new ArrayList<AccountProxy>(accounts) );
- }
- @Override
- public HandlerRegistration addSelectionHandler(
- SelectionHandler<FormLabel> handler) {
- return form.addSelectionHandler(handler);
- }
- public void addProperties(List<String> properties) {
- for(String prop : properties){
- propertiesEditor.addProperty(prop, "");
- }
- }
- public List<String> getPropertyNames() {
- return propertiesEditor.getPropertyNames();
- }
- }
- // *********************************************
- public class PropertiesMultiSelect extends Composite implements IsResettable{
- private static PropertiesMultiSelectUiBinder uiBinder = GWT.create(PropertiesMultiSelectUiBinder.class);
- interface PropertiesMultiSelectUiBinder extends UiBinder<Widget, PropertiesMultiSelect> {}
- @UiField protected TextField addText;
- @UiField protected Anchor addAnchor;
- @UiField protected ElementPanel tbody;
- public PropertiesMultiSelect() {
- initWidget(uiBinder.createAndBindUi(this));
- setStyleName("property-multiselect");
- }
- public void setValues(Map<String, String> values){
- // TODO reset
- for(String key : values.keySet()){
- addProperty(key, values.get(key));
- }
- }
- public Map<String, String> getValues(){
- HashMap<String, String> result = new HashMap<String, String>();
- for(Widget w : tbody){
- PropertyRow row = (PropertyRow) w;
- result.put(row.getProperty(), row.getValue());
- }
- return result;
- }
- public List<String> getPropertyNames(){
- return new ArrayList<String>(getValues().keySet());
- }
- public void addProperty(String property, String value){
- PropertyRow row = new PropertyRow(property);
- row.setValue(value);
- tbody.add(row);
- addText.setValue("");
- }
- @UiHandler("addAnchor")
- protected void addClick(ClickEvent e){
- addProperty();
- }
- @UiHandler("addText")
- protected void addEnterKey(KeyPressEvent e){
- if(e.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER){
- addProperty();
- }
- }
- private void addProperty(){
- String prop = addText.getValue().trim();
- if(!prop.isEmpty() && !getValues().containsKey(prop)){
- addProperty(prop, "");
- }
- }
- private static class PropertyRow extends Composite{
- private String property;
- private TextField field;
- public PropertyRow(String propName) {
- this.property = propName;
- ElementPanel row = new ElementPanel("tr");
- initWidget(row);
- ElementPanel td1 = new ElementPanel("td");
- td1.getElement().setInnerText(propName);
- td1.setStyleName("labelColumn");
- row.add(td1);
- ElementPanel td2 = new ElementPanel("td");
- this.field = new TextField();
- td2.add(this.field);
- row.add(td2);
- ElementPanel td3 = new ElementPanel("td");
- td3.setStyleName("actionColumn delete");
- Anchor a = new Anchor();
- a.setStyleName("");
- a.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- PropertyRow.this.removeFromParent();
- }
- });
- td3.add(a);
- row.add(td3);
- }
- public String getProperty() {
- return property;
- }
- public String getValue(){
- return field.getValue();
- }
- public void setValue(String value){
- field.setValue(value);
- }
- }
- @Override
- public void reset() {
- addText.setValue("");
- tbody.clear();
- }
- }
Add Comment
Please, Sign In to add comment