1 | package clarin.cmdi.componentregistry.editor { |
---|
2 | import clarin.cmdi.componentregistry.common.LabelConstants; |
---|
3 | import clarin.cmdi.componentregistry.common.StyleConstants; |
---|
4 | import clarin.cmdi.componentregistry.common.components.DownIconButton; |
---|
5 | import clarin.cmdi.componentregistry.common.components.RemoveLabelButton; |
---|
6 | import clarin.cmdi.componentregistry.common.components.UpIconButton; |
---|
7 | import clarin.cmdi.componentregistry.editor.model.CMDComponent; |
---|
8 | import clarin.cmdi.componentregistry.editor.model.CMDComponentElement; |
---|
9 | |
---|
10 | import flash.events.Event; |
---|
11 | import flash.events.MouseEvent; |
---|
12 | |
---|
13 | import mx.binding.utils.BindingUtils; |
---|
14 | import mx.containers.Box; |
---|
15 | import mx.containers.Form; |
---|
16 | import mx.containers.FormItem; |
---|
17 | import mx.containers.HBox; |
---|
18 | import mx.containers.VBox; |
---|
19 | import mx.controls.Button; |
---|
20 | import mx.controls.Label; |
---|
21 | import mx.core.Container; |
---|
22 | import mx.core.UIComponent; |
---|
23 | |
---|
24 | [Event(name="removeElement", type="flash.events.Event")] |
---|
25 | public class ElementEdit extends Form { |
---|
26 | public static const REMOVE_ELEMENT_EVENT:String = "removeElement"; |
---|
27 | private var _element:CMDComponentElement; |
---|
28 | private var _parentComponent:CMDComponent; |
---|
29 | private var _parent:UIComponent; |
---|
30 | private var showToggleBox:ShowToggleBox; |
---|
31 | private var hideableForm:Form; |
---|
32 | |
---|
33 | public function ElementEdit(element:CMDComponentElement, parent:UIComponent, parentComponent:CMDComponent) { |
---|
34 | super(); |
---|
35 | this._element = element; |
---|
36 | this._parentComponent = parentComponent; |
---|
37 | this._parent = parent; |
---|
38 | styleName = StyleConstants.XMLBROWSER; |
---|
39 | |
---|
40 | setStyle("paddingBottom","5"); |
---|
41 | verticalScrollPolicy = "off"; |
---|
42 | horizontalScrollPolicy = "off"; |
---|
43 | |
---|
44 | } |
---|
45 | |
---|
46 | public function get element():CMDComponentElement { |
---|
47 | return _element; |
---|
48 | } |
---|
49 | |
---|
50 | public function get parentComponent():CMDComponent { |
---|
51 | return _parentComponent; |
---|
52 | } |
---|
53 | |
---|
54 | protected override function createChildren():void { |
---|
55 | super.createChildren(); |
---|
56 | |
---|
57 | addChild(createEditBar()); |
---|
58 | |
---|
59 | hideableForm = createHidableForm(); |
---|
60 | showToggleBox.visibleContainer = hideableForm; |
---|
61 | |
---|
62 | addChild(hideableForm); |
---|
63 | |
---|
64 | var summary:ElementSummary = new ElementSummary(); |
---|
65 | summary.element = _element; |
---|
66 | summary.visible = false; |
---|
67 | showToggleBox.invisibleContainer = summary; |
---|
68 | |
---|
69 | addChild(summary); |
---|
70 | |
---|
71 | hideableForm.addChild(createNameInput()); |
---|
72 | hideableForm.addChild(new ConceptLinkInput(LabelConstants.CONCEPTLINK, _element.conceptLink, function(val:String):void { |
---|
73 | _element.conceptLink = val; |
---|
74 | })); |
---|
75 | hideableForm.addChild(new FormItemInputLine(LabelConstants.DOCUMENTATION, _element.documentation, function(val:String):void { |
---|
76 | _element.documentation = val; |
---|
77 | })); |
---|
78 | hideableForm.addChild(new DisplayPriorityInput(LabelConstants.DISPLAY_PRIORITY, _element.displayPriority, function(val:String):void { |
---|
79 | _element.displayPriority = val; |
---|
80 | })); |
---|
81 | |
---|
82 | var cardinalityMinInput:CardinalityInput = new CardinalityInput(LabelConstants.CARDINALITY_MIN, _element.cardinalityMin, CardinalityInput.BOUNDED, function(val:String):void { |
---|
83 | _element.cardinalityMin = val; |
---|
84 | }); |
---|
85 | hideableForm.addChild(cardinalityMinInput); |
---|
86 | |
---|
87 | var cardinalityMaxInput:CardinalityInput = new CardinalityInput(LabelConstants.CARDINALITY_MAX, _element.cardinalityMax, CardinalityInput.UNBOUNDED, function(val:String):void { |
---|
88 | _element.cardinalityMax = val; |
---|
89 | }); |
---|
90 | // Max cardinatlity field should be disabled when multilingual is selected - binding to that field here |
---|
91 | BindingUtils.bindSetter(function(value:String):void { |
---|
92 | cardinalityMaxInput.enabled = _element.multilingual != "true"; |
---|
93 | }, _element, "multilingual"); |
---|
94 | hideableForm.addChild(cardinalityMaxInput); |
---|
95 | |
---|
96 | hideableForm.addChild(AttributeListEdit.createAndAddValueScheme(_element)); |
---|
97 | var multiLingualCheck:CheckboxInput = new CheckboxInput(LabelConstants.MULTILINGUAL, _element.multilingual == "true", function(val:Boolean):void { |
---|
98 | _element.multilingual = String(val); |
---|
99 | }); |
---|
100 | multiLingualCheck.toolTip = "Can the value of this element be in multiple languages? Setting this will cause \"Max occurences\" to be always unbounded."; |
---|
101 | BindingUtils.bindSetter(function(val:String):void { |
---|
102 | var show:Boolean = "string" == val; |
---|
103 | multiLingualCheck.visible = show; |
---|
104 | multiLingualCheck.includeInLayout = show; |
---|
105 | if (!show) { |
---|
106 | _element.multilingual = null; |
---|
107 | } |
---|
108 | }, _element, "valueSchemeSimple"); |
---|
109 | |
---|
110 | hideableForm.addChild(multiLingualCheck); |
---|
111 | handleCMDAttributeList(); |
---|
112 | } |
---|
113 | |
---|
114 | private function createHidableForm():Form { |
---|
115 | var form:Form = new Form(); |
---|
116 | form.styleName = StyleConstants.XMLBROWSER; |
---|
117 | form.setStyle("paddingTop","0"); |
---|
118 | form.setStyle("paddingBottom","0"); |
---|
119 | form.verticalScrollPolicy = "off"; |
---|
120 | form.horizontalScrollPolicy = "off"; |
---|
121 | return form; |
---|
122 | } |
---|
123 | |
---|
124 | private function createEditBar():HBox { |
---|
125 | var editBar:HBox = new HBox(); |
---|
126 | |
---|
127 | showToggleBox = new ShowToggleBox(); |
---|
128 | showToggleBox.visibleState = true; |
---|
129 | editBar.addChild(showToggleBox); |
---|
130 | |
---|
131 | editBar.addChild(createHeading()); |
---|
132 | var removeButton:Label = new RemoveLabelButton(); |
---|
133 | addFocusListeners(removeButton).addEventListener(MouseEvent.CLICK, fireRemoveComponent); |
---|
134 | editBar.addChild(removeButton); |
---|
135 | |
---|
136 | var downButton:Button = new DownIconButton(); |
---|
137 | addFocusListeners(downButton).addEventListener(MouseEvent.CLICK, moveDownElement); |
---|
138 | editBar.addChild(downButton); |
---|
139 | |
---|
140 | var upButton:Button = new UpIconButton(); |
---|
141 | addFocusListeners(upButton).addEventListener(MouseEvent.CLICK, moveUpElement); |
---|
142 | editBar.addChild(upButton); |
---|
143 | return editBar; |
---|
144 | } |
---|
145 | |
---|
146 | private function moveDownElement(event:Event):void { |
---|
147 | var elem:CMDComponentElement = element; |
---|
148 | if (parentComponent.moveDownElement(elem)) { |
---|
149 | var index:int = _parent.getChildIndex(this); |
---|
150 | if (index != numChildren - 1) { |
---|
151 | _parent.removeChild(this); |
---|
152 | _parent.addChildAt(this, index + 1); |
---|
153 | } |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | private function moveUpElement(event:Event):void { |
---|
158 | var elem:CMDComponentElement = element; |
---|
159 | if (parentComponent.moveUpElement(elem)) { |
---|
160 | var index:int = _parent.getChildIndex(this); |
---|
161 | if (index != 0) { |
---|
162 | _parent.removeChild(this); |
---|
163 | _parent.addChildAt(this, index - 1); |
---|
164 | } |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | private function addFocusListeners(comp:UIComponent):UIComponent { |
---|
169 | comp.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent):void { |
---|
170 | drawFocus(true); |
---|
171 | }); |
---|
172 | comp.addEventListener(MouseEvent.MOUSE_OUT, function(event:MouseEvent):void { |
---|
173 | drawFocus(false); |
---|
174 | }); |
---|
175 | return comp; |
---|
176 | } |
---|
177 | |
---|
178 | private function fireRemoveComponent(mouseEvent:MouseEvent):void { |
---|
179 | drawFocus(false); |
---|
180 | var event:Event = new Event(REMOVE_ELEMENT_EVENT); |
---|
181 | dispatchEvent(event); |
---|
182 | } |
---|
183 | |
---|
184 | private function handleCMDAttributeList():void { |
---|
185 | var attributeEdit:Container = new AttributeListEdit(_element, this); |
---|
186 | hideableForm.addChild(attributeEdit); |
---|
187 | } |
---|
188 | |
---|
189 | private function createHeading():FormItem { |
---|
190 | var heading:FormItem = new FormItem(); |
---|
191 | heading.label = LabelConstants.ELEMENT; |
---|
192 | heading.styleName = StyleConstants.XMLBROWSER_HEADER; |
---|
193 | return heading; |
---|
194 | } |
---|
195 | |
---|
196 | private function createNameInput():NameInputLine { |
---|
197 | var nameInput:NameInputLine = new NameInputLine(_element.name, function(val:String):void { |
---|
198 | _element.name = val; |
---|
199 | }, new ChildNameValidator(_parentComponent, element)); |
---|
200 | return nameInput; |
---|
201 | } |
---|
202 | } |
---|
203 | } |
---|