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

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

Overview

Common component object.

Direct Known Subclasses

DataTable::DataTable, Form::FormButton, Form::InfoBar, Form::Input, Form::Label, Image, Table

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)



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'uu_os_gvc-0.9.6/lib/uu/os/gvc/component.rb', line 41

def initialize(container, data = nil)
  if (container.nil?) || (!container.kind_of?Container)
    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.



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

def attributes
  @attributes
end

- (Object) code (readonly)

Component code.



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

def code
  @code
end

- (Object) component_type (readonly)

Component type.



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

def component_type
  @component_type
end

- (Object) form (readonly)

ID of form to which component belongs.



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

def form
  @form
end

- (Object) height (readonly)

Component height.



32
33
34
# File 'uu_os_gvc-0.9.6/lib/uu/os/gvc/component.rb', line 32

def height
  @height
end

- (Object) id (readonly)

Unique component ID.



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

def id
  @id
end

- (Object) name (readonly)

Component name.



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

def name
  @name
end

- (Object) width (readonly)

Component width.



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

def width
  @width
end

Instance Method Details

- (Object) add_message(message)

Adds message for component.

Parameters:



108
109
110
111
112
# File 'uu_os_gvc-0.9.6/lib/uu/os/gvc/component.rb', line 108

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



121
122
123
# File 'uu_os_gvc-0.9.6/lib/uu/os/gvc/component.rb', line 121

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

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

Returns list of all component messages.

Returns:



97
98
99
100
101
102
103
# File 'uu_os_gvc-0.9.6/lib/uu/os/gvc/component.rb', line 97

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