Class: RField

Inherits:
Gtk::ToggleButton
  • Object
show all
Defined in:
lib/RelationBuilder/RTable/RField.rb

Overview

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, field = nil) ⇒ RField

Returns a new instance of RField.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/RelationBuilder/RTable/RField.rb', line 6

def initialize(table,field=nil)
	@table=table
	super("",false)
	remove(child)
	@label=Gtk::Label.new
	set_child(@index_holder=Gtk::Table.new(5,1))
	@index_holder.attach(@label,0,1,0,1)
	@index_holder.attach(@primary_img=Gtk::Image.new(@table.parentM.img_primary.scale(10,10)).set_no_show_all(true),1,2,0,1,Gtk::SHRINK)
	@index_holder.attach(@unique_img=Gtk::Image.new(@table.parentM.img_unique.scale(10,10)).set_no_show_all(true),2,3,0,1,Gtk::SHRINK)
	@index_holder.attach(@index_img=Gtk::Image.new(@table.parentM.img_index.scale(10,10)).set_no_show_all(true),3,4,0,1,Gtk::SHRINK)
	set_field(field)
	signal_connect("toggled"){|me,ev| @table.parentM.changed(self)}
	signal_connect('button-press-event'){|me,ev|
		if ev.button == 3
			@table.parentM.set_focused_item(@table)
			menu=Gtk::Menu.new
			menu.signal_connect("deactivate",self){|menu,table| @table.parentM.set_focused_item(nil)}
			menu.append(pr=Gtk::ImageMenuItem.new("`#{field_name}` properties").set_image(Gtk::Image.new(Gtk::Stock::PROPERTIES,Gtk::IconSize::MENU)))
				pr.signal_connect("activate"){|me| @table.alter_field(@field)}
			if @table.parentM.rel_ed_status == :start
				menu.append(re=Gtk::ImageMenuItem.new("finish add relation here `#{field_name}`").set_image(Gtk::Image.new(Gtk::Stock::CONNECT,Gtk::IconSize::MENU)))
					re.signal_connect("activate"){|me| @table.parentM.rel_edit(self,:finish)}
				menu.append(rc=Gtk::ImageMenuItem.new("cancel relation").set_image(Gtk::Image.new(Gtk::Stock::CANCEL,Gtk::IconSize::MENU)))
					rc.signal_connect("activate"){|me| @table.parentM.rel_edit(self,:cancel)}
				else
				menu.append(re=Gtk::ImageMenuItem.new("start add relation here `#{field_name}`").set_image(Gtk::Image.new(Gtk::Stock::CONNECT,Gtk::IconSize::MENU)))
					re.signal_connect("activate"){|me| @table.parentM.rel_edit(self,:start)}
			end
			menu.append(rf=Gtk::ImageMenuItem.new("remove field `#{field_name}`").set_image(Gtk::Image.new(Gtk::Stock::REMOVE,Gtk::IconSize::MENU)))
				rf.signal_connect("activate"){|me| @table.remove_field(field_name)}
			menu.append(afa=Gtk::ImageMenuItem.new("append field after `#{field_name}`").set_image(Gtk::Image.new(Gtk::Stock::ADD,Gtk::IconSize::MENU)))
				afa.signal_connect("activate"){|me| @table.alter_field(nil,field_name)}
			menu.show_all
			menu.popup(nil,nil,ev.button,ev.time)
			true
			else
			false
		end
	}
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



46
47
48
# File 'lib/RelationBuilder/RTable/RField.rb', line 46

def field
  @field
end

#tableObject (readonly)

Returns the value of attribute table.



46
47
48
# File 'lib/RelationBuilder/RTable/RField.rb', line 46

def table
  @table
end

Instance Method Details

#field_nameObject



79
80
81
# File 'lib/RelationBuilder/RTable/RField.rb', line 79

def field_name
	@field["Field"] || "undefined"
end

#inspectObject



89
90
91
# File 'lib/RelationBuilder/RTable/RField.rb', line 89

def inspect
	"RField:#{field_name} of #{table}"
end

#set_field(field) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/RelationBuilder/RTable/RField.rb', line 48

def set_field(field)
	@field=field
	@label.set_label(field["Field"]) unless field["Field"] == @label.label
	if f=@field["Type"].index("(")
		@field["Size"]=field["Type"][f+1 .. field["Type"].index(")") -1]
		@field["Type"]=field["Type"][0 .. f-1]
	end
	
	#set style
	set_style(@table.parentM.field_style[@field["Type"]]) if @table.parentM.field_style.has_key?(@field["Type"]) && style != @table.parentM.field_style[@field["Type"]]
	#remove old images
	#@index_holder.children.each{|ch| @index_holder.remove(ch)}
	#re-add label
	#@index_holder.attach(@label,0,1,0,2)
	#show images
	show_primary=false
	show_unique=false
	show_index=false
	@table.indexes.each{|index|
		if index["field"]==@field["Field"]
			show_primary=(index["name"]=="PRIMARY")
			show_unique=(index["unique"] == true)
			show_index=(index["unique"] == false)
		end
	}
	@primary_img.set_visible(show_primary) if @primary_img.visible? != show_primary
	@unique_img.set_visible(show_unique) if @unique_img.visible? != show_unique
	@index_img.set_visible(show_index) if @index_img.visible? != show_index
	show_all
end

#table_nameObject



82
83
84
# File 'lib/RelationBuilder/RTable/RField.rb', line 82

def table_name
	@table.table
end

#table_widthObject



85
86
87
# File 'lib/RelationBuilder/RTable/RField.rb', line 85

def table_width
	@table.widget.allocation.width
end

#to_sObject



92
93
94
# File 'lib/RelationBuilder/RTable/RField.rb', line 92

def to_s
	inspect
end