/src/com/edgytech/umongo/DocFieldText.java

https://github.com/asanchezdelc/umongo · Java · 104 lines · 66 code · 13 blank · 25 comment · 2 complexity · a879e214568d86382f18334f5af45afc MD5 · raw file

  1. /**
  2. * Copyright (C) 2010 EdgyTech Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.edgytech.umongo;
  17. import com.edgytech.swingfast.ButtonBase;
  18. import com.edgytech.swingfast.Div;
  19. import com.edgytech.swingfast.EnumListener;
  20. import com.edgytech.swingfast.XmlComponentUnit;
  21. import com.mongodb.util.JSON;
  22. import java.util.logging.Level;
  23. import com.edgytech.umongo.DocFieldText.Item;
  24. /**
  25. *
  26. * @author antoine
  27. */
  28. public class DocFieldText extends Div implements EnumListener<Item> {
  29. enum Item {
  30. fields,
  31. value,
  32. edit,
  33. up,
  34. down,
  35. remove,
  36. addField,
  37. addKey,
  38. addType
  39. }
  40. DocFieldObject _object;
  41. String key;
  42. Object value;
  43. /**
  44. * Creates a new instance of FieldFile
  45. */
  46. public DocFieldText() {
  47. try {
  48. xmlLoad(Resource.getXmlDir(), Resource.File.docFieldText, null);
  49. } catch (Exception ex) {
  50. getLogger().log(Level.SEVERE, null, ex);
  51. }
  52. setEnumBinding(Item.values(), this);
  53. }
  54. /**
  55. * Creates a new instance of FieldFile
  56. */
  57. public DocFieldText(String id, String key, Object value, DocFieldObject object) {
  58. this();
  59. setId(id);
  60. setLabel(key);
  61. this.key = key;
  62. this.value = value;
  63. this._object = object;
  64. setStringFieldValue(Item.value, JSON.serialize(value));
  65. if (value == null)
  66. getJComponentBoundUnit(Item.edit).visible = false;
  67. }
  68. public void edit(ButtonBase button) {
  69. value = UMongo.instance.getGlobalStore().editValue(key, value);
  70. setStringFieldValue(Item.value, JSON.serialize(value));
  71. updateComponent();
  72. _object.commitComponent();
  73. }
  74. public void remove(ButtonBase button) {
  75. _object.remove(key);
  76. }
  77. public void moveUp(ButtonBase button) {
  78. _object.moveUp(key);
  79. }
  80. public void moveDown(ButtonBase button) {
  81. _object.moveDown(key);
  82. }
  83. public void actionPerformed(Item enm, XmlComponentUnit unit, Object src) {
  84. }
  85. public Object getValue() {
  86. return value;
  87. }
  88. public String getKey() {
  89. return key;
  90. }
  91. }