Class: UU::OS::GVC::Component

Inherits:
Object
  • Object
show all
Defined in:
uu_os_gvc-0.28.16/lib/uu/os/gvc/component.rb

Overview

Common component object.

Direct Known Subclasses

DataTable::DataTable, Form::FormButton, Form::InfoBar, Form::Input, Form::Label, Button, Icon, Image, Link, Table, Text, TouchIcon, Tree, UxmlFragment, Widget

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Component) initialize(container, data = nil)

Creates new instance of component.

Parameters:

  • container (UU::OS::GVC::Container)

    Container where to insert new component

  • data (String, Hash) (defaults to: nil)

    Initialization data in form of JSON string or Hash (optional)



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/component.rb', line 44

def initialize(container, data = nil)
  # Moved 'require' here because there was a cyclic dependency between
  # component.rb and container.rb.
  require 'uu/os/gvc/container'

  if (container.nil?)
    raise ArgumentError.new('Parent container must be defined to create new component.')
  end
  if data.nil?
    @attributes = {}
    return
  end
  if data.kind_of?String
    data = JSON.parse(data, :symbolize_names => true)
  end
  if data.kind_of?Hash
    @attributes = data
  elsif data.kind_of?Component
    if data.attributes
      @attributes = data.attributes
    else
      @attributes = {}
    end
  else
    raise ArgumentError.new("Component data must be JSON String or Hash, but was #{data.class}.")
  end
  @container = container
end

Instance Attribute Details

- (Object) attributes (readonly)

Deprecated.

Direct access to attribute values through the attributes attribute is deprecated and is not going to be supported in the future versions. Use individual attribute accessors instead.

Raw component attributes.



13
14
15
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/component.rb', line 13

def attributes
  @attributes
end

- (Object) code (readonly)

Component code.



22
23
24
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/component.rb', line 22

def code
  @code
end

- (Object) component_type (readonly)

Component type.



25
26
27
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/component.rb', line 25

def component_type
  @component_type
end

- (Object) form (readonly)

ID of form to which component belongs.



38
39
40
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/component.rb', line 38

def form
  @form
end

- (Object) height (readonly)

Deprecated.

component may not respect this dimension

Component height.



35
36
37
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/component.rb', line 35

def height
  @height
end

- (Object) id (readonly)

Unique component ID.



16
17
18
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/component.rb', line 16

def id
  @id
end

- (Object) name (readonly)

Component name.



19
20
21
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/component.rb', line 19

def name
  @name
end

- (Object) width (readonly)

Deprecated.

component may not respect this dimension

Component width.



30
31
32
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/component.rb', line 30

def width
  @width
end

Instance Method Details

- (Object) add_message(message)

Adds message for component.

Parameters:



115
116
117
118
119
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/component.rb', line 115

def add_message(message)
  msg = UU::OS::GVC::Message.new(message)
  msg.related_to << id
  @container.add_message(msg)
end

- (FalseClass, TrueClass) focus

Sets focus to this component. Actual behavior of focus depends on type of focused component and also on type of container in which is component placed. Only one component can be focused, setting focus on one component disables focus of previously focused component within container.

Returns:

  • (FalseClass, TrueClass)

    True if focus was set, else false



128
129
130
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/component.rb', line 128

def focus()
  return @container.focus(id)
end

- (Array<UU::OS::GVC::Message>) messages

Returns list of all component messages.

Returns:



104
105
106
107
108
109
110
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/component.rb', line 104

def messages
  result = []
  @container.messages.each do |message|
    result << message if message.related_to.include?id
  end
  result
end