class RelationBuilder

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint(dpblnt@gmail.com)

Attributes

field_style[R]
focused_item[R]
holder[R]
img_index[R]
img_primary[R]
img_unique[R]
rel_ed_status[R]
relations[R]
show_only_query[R]
tables[R]
widget[R]

Public Class Methods

new(show_only_query=false) click to toggle source
Calls superclass method
# File lib/RelationBuilder.rb, line 8
        def initialize(show_only_query=false)
                @img_unique=Gdk::Pixdata.deserialize([71, 100, 107, 80, 0, 0, 1, 216, 2, 1, 0, 2, 0, 0, 0, 64, 0, 0, 0, 16, 0, 0, 0, 16, 145, 0, 0, 0, 0, 142, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 153, 153, 204, 255, 1, 102, 102, 102, 255, 136, 153, 153, 204, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 153, 153, 204, 255, 1, 102, 102, 102, 255, 136, 153, 153, 204, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 142, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 1, 102, 102, 102, 255, 136, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 3, 102, 102, 102, 255, 255, 255, 255, 255, 0, 0, 0, 255, 130, 255, 255, 255, 255, 130, 204, 0, 0, 255, 131, 255, 255, 255, 255, 130, 204, 0, 0, 255, 2, 255, 255, 255, 255, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 132, 255, 255, 255, 255, 130, 204, 0, 0, 255, 131, 255, 255, 255, 255, 130, 204, 0, 0, 255, 2, 255, 255, 255, 255, 102, 102, 102, 255, 130, 0, 0, 0, 0, 3, 102, 102, 102, 255, 255, 255, 255, 255, 0, 0, 0, 255, 130, 255, 255, 255, 255, 130, 204, 0, 0, 255, 131, 255, 255, 255, 255, 130, 204, 0, 0, 255, 2, 255, 255, 255, 255, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 132, 255, 255, 255, 255, 130, 204, 0, 0, 255, 131, 255, 255, 255, 255, 130, 204, 0, 0, 255, 2, 255, 255, 255, 255, 102, 102, 102, 255, 130, 0, 0, 0, 0, 3, 102, 102, 102, 255, 255, 255, 255, 255, 0, 0, 0, 255, 130, 255, 255, 255, 255, 130, 204, 0, 0, 255, 131, 255, 255, 255, 255, 130, 204, 0, 0, 255, 2, 255, 255, 255, 255, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 132, 255, 255, 255, 255, 135, 204, 0, 0, 255, 2, 255, 255, 255, 255, 102, 102, 102, 255, 130, 0, 0, 0, 0, 6, 102, 102, 102, 255, 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255, 102, 102, 102, 255, 255, 255, 255, 255, 133, 204, 0, 0, 255, 130, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 1, 102, 102, 102, 255, 136, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 142, 102, 102, 102, 255, 145, 0, 0, 0, 0]).to_pixbuf(true)
                @img_index=Gdk::Pixdata.deserialize([71, 100, 107, 80, 0, 0, 2, 106, 2, 1, 0, 2, 0, 0, 0, 64, 0, 0, 0, 16, 0, 0, 0, 16, 145, 0, 0, 0, 0, 142, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 153, 153, 204, 255, 1, 102, 102, 102, 255, 132, 153, 153, 204, 255, 5, 128, 128, 128, 255, 255, 255, 255, 255, 255, 255, 153, 255, 255, 204, 51, 255, 0, 0, 0, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 153, 153, 204, 255, 1, 102, 102, 102, 255, 131, 153, 153, 204, 255, 4, 128, 128, 128, 255, 255, 255, 255, 255, 255, 255, 153, 255, 255, 204, 51, 255, 130, 0, 0, 0, 255, 130, 0, 0, 0, 0, 135, 102, 102, 102, 255, 4, 128, 128, 128, 255, 255, 255, 255, 255, 255, 255, 153, 255, 255, 204, 51, 255, 130, 0, 0, 0, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 255, 255, 255, 255, 3, 128, 128, 128, 255, 255, 255, 153, 255, 255, 204, 51, 255, 130, 0, 0, 0, 255, 2, 255, 255, 255, 255, 102, 102, 102, 255, 130, 0, 0, 0, 0, 9, 102, 102, 102, 255, 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255, 102, 102, 102, 255, 255, 255, 255, 255, 128, 128, 128, 255, 255, 255, 255, 255, 255, 204, 51, 255, 130, 0, 0, 0, 255, 130, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 3, 102, 102, 102, 255, 128, 128, 128, 255, 255, 255, 255, 255, 133, 255, 204, 51, 255, 130, 0, 0, 0, 255, 130, 0, 0, 0, 0, 5, 102, 102, 102, 255, 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255, 102, 102, 102, 255, 132, 0, 0, 0, 255, 2, 255, 255, 255, 255, 255, 204, 51, 255, 130, 0, 0, 0, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 255, 255, 255, 255, 3, 128, 128, 128, 255, 255, 255, 255, 255, 255, 204, 51, 255, 130, 0, 0, 0, 255, 2, 255, 255, 255, 255, 102, 102, 102, 255, 130, 0, 0, 0, 0, 9, 102, 102, 102, 255, 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255, 102, 102, 102, 255, 255, 255, 255, 255, 128, 128, 128, 255, 255, 255, 255, 255, 255, 204, 51, 255, 130, 0, 0, 0, 255, 130, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 255, 255, 255, 255, 1, 255, 204, 51, 255, 130, 0, 0, 0, 255, 131, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 7, 102, 102, 102, 255, 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255, 102, 102, 102, 255, 255, 255, 255, 255, 255, 204, 51, 255, 130, 0, 0, 0, 255, 132, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 2, 102, 102, 102, 255, 255, 255, 255, 255, 130, 0, 0, 0, 255, 133, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 142, 102, 102, 102, 255, 145, 0, 0, 0, 0]).to_pixbuf(true)
                @img_primary=Gdk::Pixdata.deserialize([71, 100, 107, 80, 0, 0, 2, 190, 2, 1, 0, 2, 0, 0, 0, 64, 0, 0, 0, 16, 0, 0, 0, 16, 145, 0, 0, 0, 0, 135, 102, 102, 102, 255, 133, 0, 0, 0, 255, 130, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 153, 153, 204, 255, 10, 102, 102, 102, 255, 153, 153, 204, 255, 0, 0, 0, 255, 230, 184, 0, 255, 234, 187, 0, 255, 240, 192, 0, 255, 245, 196, 0, 255, 250, 200, 0, 255, 0, 0, 0, 255, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 153, 153, 204, 255, 7, 102, 102, 102, 255, 0, 0, 0, 255, 232, 186, 0, 255, 234, 187, 0, 255, 238, 190, 0, 255, 0, 0, 0, 255, 249, 199, 0, 255, 130, 254, 203, 0, 255, 1, 0, 0, 0, 255, 130, 0, 0, 0, 0, 133, 102, 102, 102, 255, 3, 0, 0, 0, 255, 236, 189, 0, 255, 238, 190, 0, 255, 131, 244, 195, 0, 255, 3, 252, 202, 0, 255, 249, 199, 0, 255, 0, 0, 0, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 10, 102, 102, 102, 255, 255, 255, 255, 255, 0, 0, 0, 255, 251, 201, 0, 255, 253, 202, 0, 255, 245, 196, 0, 255, 239, 191, 0, 255, 234, 187, 0, 255, 0, 0, 0, 255, 102, 102, 102, 255, 130, 0, 0, 0, 0, 5, 102, 102, 102, 255, 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255, 102, 102, 102, 255, 130, 255, 255, 255, 255, 7, 0, 0, 0, 255, 250, 200, 0, 255, 243, 194, 0, 255, 236, 189, 0, 255, 0, 0, 0, 255, 255, 255, 255, 255, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 3, 0, 0, 0, 255, 241, 193, 0, 255, 0, 0, 0, 255, 130, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 6, 102, 102, 102, 255, 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255, 102, 102, 102, 255, 255, 255, 255, 255, 130, 0, 0, 0, 255, 3, 249, 199, 0, 255, 242, 194, 0, 255, 0, 0, 0, 255, 130, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 3, 0, 0, 0, 255, 243, 194, 0, 255, 0, 0, 0, 255, 130, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 6, 102, 102, 102, 255, 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255, 102, 102, 102, 255, 255, 255, 255, 255, 130, 0, 0, 0, 255, 3, 250, 200, 0, 255, 245, 196, 0, 255, 0, 0, 0, 255, 130, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 3, 0, 0, 0, 255, 247, 198, 0, 255, 0, 0, 0, 255, 130, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 6, 102, 102, 102, 255, 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255, 102, 102, 102, 255, 255, 255, 255, 255, 130, 0, 0, 0, 255, 3, 252, 202, 0, 255, 248, 198, 0, 255, 0, 0, 0, 255, 130, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 1, 102, 102, 102, 255, 131, 255, 255, 255, 255, 3, 0, 0, 0, 255, 249, 199, 0, 255, 0, 0, 0, 255, 130, 255, 255, 255, 255, 1, 102, 102, 102, 255, 130, 0, 0, 0, 0, 137, 102, 102, 102, 255, 1, 0, 0, 0, 255, 132, 102, 102, 102, 255, 145, 0, 0, 0, 0]).to_pixbuf(true)

                @field_style={
                        'tinyint'=>Gtk::Style.new.set_bg(Gtk::STATE_NORMAL,0x4000,0x5700,0xdd00),
                        'int'=>Gtk::Style.new.set_bg(Gtk::STATE_NORMAL,0x4000,0xa500,0xdd00),
                        'bigint'=>Gtk::Style.new.set_bg(Gtk::STATE_NORMAL,0x4000,0xd800,0xdd00),
                        'double'=>Gtk::Style.new.set_bg(Gtk::STATE_NORMAL,0x5800,0xdd00,0x4000),
                        'float'=>Gtk::Style.new.set_bg(Gtk::STATE_NORMAL,0x4000,0xdd00,0x6600),
                        'char'=>Gtk::Style.new.set_bg(Gtk::STATE_NORMAL,0xdd00,0x4000,0xd200),
                        'tinytext'=>Gtk::Style.new.set_bg(Gtk::STATE_NORMAL,0xdd00,0xd400,0x0000),
                        'text'=>Gtk::Style.new.set_bg(Gtk::STATE_NORMAL,0xdd00,0xd400,0x4000),
                        'varchar'=>Gtk::Style.new.set_bg(Gtk::STATE_NORMAL,0xef00,0xe300,0x1400),
                        'date'=>Gtk::Style.new.set_bg(Gtk::STATE_NORMAL,0xc000,0xb000,0x4000),
                        'datetime'=>Gtk::Style.new.set_bg(Gtk::STATE_NORMAL,0xef00,0xb000,0x1000),
                }
                @field_style.each_value{|fs|
                        norm=fs.bg(Gtk::STATE_NORMAL)
                        fs.set_bg(Gtk::STATE_ACTIVE,norm.red,norm.green,norm.blue)
                        fs.set_bg(Gtk::STATE_PRELIGHT,
                                norm.red  + 0x1000,
                                norm.green+ 0x1000,
                                norm.blue + 0x1000)
                }

                super()
                @base_object=nil
                @rel_ed=Array.new
                @relations=Hash.new
                @tables=Hash.new
                @holder=Gtk::VBox.new
                @widget=Gtk::Fixed.new
                @widget.signal_connect("expose-event"){|me,ev| draw_focused;draw_relations; true}
                add_with_viewport(@eb=Gtk::EventBox.new.add(@widget))
                visible_window=false

                @eb.signal_connect('button-press-event'){|me,ev|
                        if ev.button == 2
                                @dragging = true
                                @xshift=ev.x
                                @yshift=ev.y
                        end
                        if ev.button == 3
                                if @rel_ed_status == :start
                                        rel_edit(nil,:cancel)
                                else
                                menu=Gtk::Menu.new
                                menu.append(newt=Gtk::ImageMenuItem.new("create table").set_image(Gtk::Image.new(Gtk::Stock::NEW,Gtk::IconSize::MENU)))
                                newt.signal_connect("activate"){|me|
                                                dialog=Gtk::MessageDialog.new(nil,Gtk::Dialog::Flags::MODAL,Gtk::MessageDialog::QUESTION,Gtk::MessageDialog::ButtonsType::OK_CANCEL,"creating table")
                                                dialog.vbox.pack_start(Gtk::Label.new("table name"))
                                                dialog.vbox.pack_start(table_name=Gtk::Entry.new)
                                                dialog.show_all
                                                if dialog.run == Gtk::Dialog::ResponseType::OK
                                                        client.query("CREATE TABLE `#{table_name.text}` (`id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE = MYISAM")
                                                        add_existing_table(table_name.text)
                                                end
                                                dialog.destroy
                                        
                                }
                                
                                #add tables to the menu
                                menu.append(a=Gtk::ImageMenuItem.new("add existing table").set_image(Gtk::Image.new(Gtk::Stock::OPEN,Gtk::IconSize::MENU)))
                                a.set_submenu(Gtk::Menu.new)
                                client.query("show tables").each{|row|
                                        #row2=qrow("select count(id) as c from tables where name='#{row[0]}'")
                                        #if row2["c"]=="0"
                                        unless @tables.has_key?(row[0])
                                                a.submenu.append(tn=Gtk::ImageMenuItem.new(row[0],false).set_image(Gtk::Image.new(Gtk::Stock::ADD,Gtk::IconSize::MENU)))

                                                tn.signal_connect("activate",row[0],menu){|me,table_name,menu|
                                                        #add the table
                                                        add_existing_table(table_name)
                                                        menu.destroy
                                                }
                                        end
                                }

                                menu.append(reload_srv=Gtk::ImageMenuItem.new("Reload Server Model").set_image(Gtk::Image.new(Gtk::Stock::REFRESH,Gtk::IconSize::MENU)))
                                reload_srv.signal_connect("activate"){|me|
                                        reload_server_rb
                                }

                                menu.show_all
                                menu.popup(nil,nil,ev.button,ev.time)
                                end
                        end
                        true
                }
                @eb.signal_connect('button-release-event'){|me,ev|
                        @dragging=false if @dragging
                        true
                }
                @eb.signal_connect('motion-notify-event'){|me,event|
#                       p "moving: #{px}(#{@x}) #{py}(#{@y}) H:#{hadjustment.lower} #{hadjustment.upper} V:#{vadjustment.lower} #{vadjustment.upper}"
#                       ch=false
                        if @dragging
                                px=@xshift - self.pointer[0]
                                py=@yshift - self.pointer[1]
                                px=hadjustment.lower if px < hadjustment.lower
                                py=vadjustment.lower if py < hadjustment.lower
                                px=hadjustment.upper - hadjustment.page_size if px > hadjustment.upper - hadjustment.page_size
                                py=vadjustment.upper - vadjustment.page_size if py > vadjustment.upper - vadjustment.page_size
                                hadjustment.value=px
                                vadjustment.value=py
                        end
                        true
                }

                @rel_ed_status=nil
                @dragging=false
                signal_connect("realize"){|me| @base_object.center_on_me unless @base_object.nil?}

                @show_only_query=show_only_query
        end

Public Instance Methods

add_existing_table(table_name) click to toggle source
# File lib/RelationBuilder.rb, line 438
def add_existing_table(table_name)
        unless @tables.has_key?(table_name)
                query("insert into tables (name,rbx,rby) values('#{table_name}','#{@widget.pointer[0]}','#{@widget.pointer[1]}')")
                reload_server_rb(true,table_name)
        end
end
build_query() click to toggle source
# File lib/RelationBuilder.rb, line 452
def build_query
        sql=@query_id
        sql
end
changed(notifier=nil) click to toggle source
Calls superclass method
# File lib/RelationBuilder.rb, line 460
def changed(notifier=nil)
        edebug("#{notifier} changed, notifying observers","relation-builder")
        super()
        notify_observers(self,notifier)
end
clear() click to toggle source
# File lib/RelationBuilder.rb, line 389
def clear
        @widget.queue_draw_area(0, 0, @widget.allocation.width, @widget.allocation.height)
end
draw_focused() click to toggle source
# File lib/RelationBuilder.rb, line 219
def draw_focused
        return if @focused_item.nil? || !@focused_item.realized?
        cr=@widget.window.create_cairo_context
        x1,y1=@focused_item.widget.translate_coordinates(@widget,0,0)
        width=@focused_item.widget.allocation.width
        height=@focused_item.widget.allocation.height

        cr.set_source_rgba(0.2,0.9,0.4,0.4)
        cr.set_line_width(10)

        cr.rounded_rectangle(x1-10,y1-10,width+20,height+20,20)
        cr.stroke
end
draw_relations() click to toggle source
# File lib/RelationBuilder.rb, line 233
        def draw_relations
                cr=@widget.window.create_cairo_context
                @relations.each_value{|rel|
                        next unless rel.visible? && rel.handle.realized?
                        begin
                                x1=rel.rfield1.table.widget.translate_coordinates(@widget,0,0)[0]
                                y1=rel.rfield1.translate_coordinates(@widget,0,0)[1]
                                x2=rel.rfield2.table.widget.translate_coordinates(@widget,0,0)[0]
                                y2=rel.rfield2.translate_coordinates(@widget,0,0)[1]
                                xr,yr=rel.handle.translate_coordinates(@widget,0,0)
                                if x1<x2
                                        t=x1
                                        x1=x2
                                        x2=t

                                        t=y1
                                        y1=y2
                                        y2=t

                                        w2,w1,wr=[rel.rfield1.table_width, rel.rfield2.table_width, rel.handle.allocation.width]
                                else
                                        w1,w2,wr=[rel.rfield1.table_width, rel.rfield2.table_width, rel.handle.allocation.width]
                                end
                                high=(@focused_item == rel.rfield1.table) || (@focused_item == rel.rfield2.table)
                                rescue
                                x1=nil
                        end
                        unless x1.nil?
                                y1+=rel.rfield1.allocation.height/2 #vertical midle of field1
                                y2+=rel.rfield2.allocation.height/2 #vertical middle of field2
                                yr+=rel.handle.allocation.height/2  #vertical middle of relation_handle
                                xr+=rel.handle.allocation.width/2           #horizontal middle of relation_handle
                                m1,m2=[0,0]

#                               f1=Math.atan(1.0*(yr-y1)/(x1-xr))
#                               f2=Math.atan(1.0*(yr-y2)/(x2-xr))
#                               f3=(f1+f2)/2

                                if x1+w1/2 < xr
                                        x1+=w1
                                        d1=1
                                        m1=x1-xr
                                        else
                                        m1=xr-x1
                                        d1=-1
                                end

                                if x2+w2/2 < xr
                                        x2+=w2
                                        m2=x2-xr
                                        d2=1
                                        else
                                        m2=xr-x2
                                        d2=-1
                                end

                                f1=Math.atan(1.0*(yr-y1)/(x1-xr))
                                f1=f1-Math::PI if xr>x1

                                f2=Math.atan(1.0*(yr-y2)/(x2-xr))
                                f2=f2-Math::PI if xr>x2

                                f3=(f1+f2)/2+Math::PI/2
#                               f3=f3-Math::PI if xr>x1 && x1<x2 || x1>x2 && xr>x2

                                r1=((x1-xr).abs+(yr-y1).abs)/2
                                r2=((x2-xr).abs+(yr-y2).abs)/2

                                #draw highlighted
                                if high
                                        cr.set_source_rgba(0.9,0.9,0.2,0.4)
                                        cr.set_line_width(8)
                                        #arrow
                                        cr.move_to(x2+5*(m2<=>0),y2-5)
                                        cr.line_to(x2,y2)
                                        cr.line_to(x2+5*(m2<=>0),y2+5)
                                        #second arrow
                                        if rel.rel_type == "o"
                                                cr.move_to(x1+5*(m1<=>0),y1-5)
                                                cr.line_to(x1,y1)
                                                cr.line_to(x1+5*(m1<=>0),y1+5)
                                        end
                                        #relation
                                        cr.move_to(x1,y1)
                                        cr.curve_to(x1+r1*d1,y1, xr+r1*Math.cos(f3),yr-r1*Math.sin(f3),xr,yr)

                                        cr.move_to(x2,y2)
                                        cr.curve_to(x2+r2*d2,y2, xr+r2*Math.cos(f3-Math::PI),yr-r2*Math.sin(f3-Math::PI),xr,yr)
                                        cr.stroke
                                end

                                if rel.active?
                                        cr.set_source_rgba(0,0,1,0.8)
                                        cr.set_line_width(4)
                                        else
                                        cr.set_source_rgba(0,0.4,0,0.8)
                                        cr.set_line_width(2)
                                end

                                #draw arrow
                                cr.move_to(x2+5*d2,y2-5)
                                cr.line_to(x2,y2)
                                cr.line_to(x2+5*d2,y2+5)
                                
                                if rel.rel_type == "o"
                                        #draw second arrow
                                        cr.move_to(x1+5*d1,y1-5)
                                        cr.line_to(x1,y1)
                                        cr.line_to(x1+5*d1,y1+5)
                                end

                                
                                cr.move_to(x1,y1)
                                cr.curve_to(x1+r1*d1,y1, xr+r1*Math.cos(f3),yr-r1*Math.sin(f3),xr,yr)

                                cr.move_to(x2,y2)
                                cr.curve_to(x2+r2*d2,y2, xr+r2*Math.cos(f3-Math::PI),yr-r2*Math.sin(f3-Math::PI),xr,yr)

                                cr.stroke
=begin
                                #draw control angle 1
                                cr.set_source_rgba(0.1,0.9,0.1,0.8).set_line_width(0.5).set_dash(5)
                                cr.move_to(xr,yr).line_to(xr+r1*Math.cos(f1),yr-r1*Math.sin(f1))
                                cr.stroke

                                #draw control angle 2
                                cr.set_source_rgba(0.1,0.1,0.9,0.8).set_line_width(0.5).set_dash(10)
                                cr.move_to(xr,yr).line_to(xr+r2*Math.cos(f2),yr-r2*Math.sin(f2))
                                cr.stroke
                                
                                #draw the control points

                                cr.set_dash(100000)

                                cr.set_source_rgba(0.9,0.1,0.1,0.4)
                                cr.set_line_width(1)

                                cr.move_to(x1,y1)
                                cr.line_to(x1+r1*d1,y1)
                                cr.move_to(xr,yr)
                                cr.line_to(xr+r1*Math.cos(f3),yr-r1*Math.sin(f3))

                                cr.stroke
                                cr.set_source_rgba(0.1,0.1,0.9,0.4)

                                cr.move_to(x2,y2)
                                cr.line_to(x2+r2*d2,y2)
                                cr.move_to(xr,yr)
                                cr.line_to(xr+r2*Math.cos(f3-Math::PI),yr-r2*Math.sin(f3-Math::PI))

                                cr.stroke
=end
                        end
                }
        end
find_relation(rfield1,rfield2) click to toggle source
# File lib/RelationBuilder.rb, line 411
def find_relation(rfield1,rfield2)
        rel=nil
        @relations.each_value{|r| 
                if [r.rfield1,r.rfield2] == [rfield1,rfield2] or [r.rfield1,r.rfield2] == [rfield2,rfield1]
                        rel=r 
                end
                }
        rel
end
inspect() click to toggle source
# File lib/RelationBuilder.rb, line 195
def inspect
        title
end
rel_edit(rfield,status) click to toggle source
# File lib/RelationBuilder.rb, line 393
        def rel_edit(rfield,status)
                @rel_ed_status=status
#               @rel_ed.push(rfield) if rfield.active?
                case status
                        when :start
                                x1,y1=rfield.translate_coordinates(@widget,0,0)
                                @rel_in_ed=Relation.new(self,{"src_table" => rfield.table_name, "src_field" => rfield.field_name, "rbx" => x1-30, "rby" => y1-30})
                                @relations[0]=@rel_in_ed
                                @rel_in_ed.show_me
                        when :finish
                                @rel_in_ed.set_rfield2(rfield)
                                @rel_in_ed.edit
                                @rel_in_ed.show_me
                        when :cancel
                                @rel_in_ed.remove
                end
        end
reload(target=nil) click to toggle source
# File lib/RelationBuilder.rb, line 149
def reload(target=nil)
        @search_window=SearchWindow.new(self) unless @search_window
        @rq_window=RunQuery.new(self) unless @rq_window

        ctables=cache.get("tables")
        crelations=cache.get("relations")
        ctables.each_pair{|table_name,table|
                if @tables.has_key?(table_name)
                        @tables[table_name].update(table)
                else
                        @tables[table_name]=RTable.new(self,table)
                end
        }
        crelations.each_pair{|rel_id,rel|
                if @relations.has_key?(rel_id)
                        @relations[rel_id].reload(rel)
                else
                        @relations[rel_id]=Relation.new(self,rel)
                end
        }
        review_all
end
reload_server_rb(reload_me_too=true,table=nil,relation=nil) click to toggle source
# File lib/RelationBuilder.rb, line 445
def reload_server_rb(reload_me_too=true,table=nil,relation=nil)
        Thread.new{
                ManqodDB.instance.manqod_db.relation_builder.update(table,relation) if ManqodDB.instance.manqod_db.relation_builder
                reload if reload_me_too
        }
end
remove_table(table,from_sql=false) click to toggle source
# File lib/RelationBuilder.rb, line 421
def remove_table(table,from_sql=false)
        @tables[table].fields.each{|field,field_wg|
                @relations.each_value{|rel|
                        if rel.rfield1 == field_wg or rel.rfield2 == field_wg
                                edebug("removing #{rel}","relation-builder")
                                rel.remove
                        end
                }
        }
        query("delete from tables where id='#{@tables[table].table_id}'")
        client.query("drop table `#{table}`") if from_sql
        @tables[table].widget.destroy
        @tables.delete(table)
        reload_server_rb(true,table)
        changed(@tables[table])
end
review_all() click to toggle source
# File lib/RelationBuilder.rb, line 172
def review_all
        if @show_only_query
                #show only related to query
                @tables.each_value{|table| table.set_visibility(false)}
                @relations.each_value{|rel| rel.set_visibility(rel.active?)}
                @relations.each_value{|rel|
                        if rel.active?
                                rel.rfield1.table.show_neighbours
                                rel.rfield2.table.show_neighbours
                        end
                }
                @base_object.show_neighbours if @base_object
        else
                #show all
                @tables.each_value{|table| table.set_visibility(true)}
                @relations.each_value{|rel| rel.set_visibility(true)}
        end
        clear
end
set_base_object(new_bo) click to toggle source
# File lib/RelationBuilder.rb, line 456
def set_base_object(new_bo)
        @base_object=new_bo
        @base_object.center_on_me
end
set_focused_item(item) click to toggle source
# File lib/RelationBuilder.rb, line 202
        def set_focused_item(item)
                return if @focused_item == item
                if !@focused_item.nil?
                        @focused_item.set_state(Gtk::STATE_NORMAL)
                        @focused_item.dragging=false
                end
                @focused_item=item
                set_focus_child(@focused_item)
                if !@focused_item.nil?
                        @focused_item.set_state(Gtk::STATE_PRELIGHT) 
                        @focused_item.set_has_focus(true)
                end
                clear
#               info.update(focused_item)
                @focused_item
        end
table_by_id(table_id) click to toggle source
# File lib/RelationBuilder.rb, line 132
def table_by_id(table_id)
        found=nil
        @tables.each_pair{|table_name,tableo|
                if tableo.table_id.to_i == table_id.to_i
                        found=tableo
                        break
                end
        }
        found
end
table_by_name(table_name) click to toggle source
# File lib/RelationBuilder.rb, line 128
def table_by_name(table_name)
        tables[table_name]
end
title() click to toggle source
# File lib/RelationBuilder.rb, line 192
def title
        "Relation Builder on #{manqod_db}"
end
to_s() click to toggle source
# File lib/RelationBuilder.rb, line 198
def to_s
        inspect
end
update(notifier=nil) click to toggle source
# File lib/RelationBuilder.rb, line 143
def update(notifier=nil)
        reload
        @search_window.update(get_ancestor(Gtk::Window))
        @rq_window.update(get_ancestor(Gtk::Window))
end