File: wb_component_physical.h

package info (click to toggle)
mysql-workbench 6.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 113,932 kB
  • ctags: 87,814
  • sloc: ansic: 955,521; cpp: 427,465; python: 59,728; yacc: 59,129; xml: 54,204; sql: 7,091; objc: 965; makefile: 638; sh: 613; java: 237; perl: 30; ruby: 6; php: 1
file content (280 lines) | stat: -rw-r--r-- 11,088 bytes parent folder | download
1
2
3
4
5
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/* 
 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of the
 * License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#ifndef _WB_COMPONENT_PHYSICAL_H_
#define _WB_COMPONENT_PHYSICAL_H_

// Physical Model Handling

#include "workbench/wb_backend_public_interface.h"

#include "base/trackable.h"
#include "base/notifications.h"

#include "wb_component.h"

#include "grt/icon_manager.h"

#include "grts/structs.workbench.h"

#include "wbcanvas/workbench_physical_model_impl.h"

namespace wb {
  
  
  enum RelationshipType {
    Relationship11Id,
    Relationship1nId,
    RelationshipnmId,
    Relationship11NonId,
    Relationship1nNonId,
    RelationshipPick
  };


  enum ObjectType {
    ObjectTable,
    ObjectView,
    ObjectRoutineGroup
  };

  class CatalogTreeBE;
  class RelationshipFloater;

  #define WB_TOOL_PTABLE "physical/table"
  #define WB_TOOL_PROUTINEGROUP "physical/routinegroup"
  #define WB_TOOL_PVIEW "physical/view"

  #define WB_TOOL_PREL11_NOID "physical/rel11_noid"
  #define WB_TOOL_PREL1n_NOID "physical/rel1n_noid"
  #define WB_TOOL_PREL11 "physical/rel11"
  #define WB_TOOL_PREL1n "physical/rel1n"
  #define WB_TOOL_PRELnm "physical/relnm"
  #define WB_TOOL_PREL_PICK "physical/relpick"
  
  class MYSQLWBBACKEND_PUBLIC_FUNC WBComponentPhysical : virtual public WBComponent
  {
  public:
    WBComponentPhysical(WBContext *wb);
    virtual ~WBComponentPhysical();

    static std::string name() { return "physical"; }
    virtual std::string get_name() { return WBComponentPhysical::name(); }
    virtual std::string get_diagram_class_name() { return workbench_physical_Diagram::static_class_name(); }

    // Model
    db_SchemaRef add_new_db_schema(const workbench_physical_ModelRef &model);
    void delete_db_schema(const db_SchemaRef &schema);

    db_DatabaseObjectRef add_new_db_table(const db_SchemaRef &schema, const std::string &template_name = "");
    db_DatabaseObjectRef add_new_db_view(const db_SchemaRef &schema);
    db_DatabaseObjectRef add_new_db_routine(const db_SchemaRef &schema);
    db_DatabaseObjectRef add_new_db_routine_group(const db_SchemaRef &schema);

    db_ScriptRef add_new_stored_script(const workbench_physical_ModelRef &model, const std::string &path="");
    GrtStoredNoteRef add_new_stored_note(const workbench_physical_ModelRef &model, const std::string &path= "");

    std::list<model_FigureRef> interactive_place_db_objects(ModelDiagramForm *vform, int x, int y, 
      const std::list<db_DatabaseObjectRef> &objects);
    std::list<model_FigureRef> interactive_place_db_objects(ModelDiagramForm *vform, int x, int y, 
      const std::list<db_DatabaseObjectRef> &objects, grt::CopyContext& copy_context);
    
    model_FigureRef place_db_object(ModelDiagramForm *view, const base::Point &pos, const db_DatabaseObjectRef &object,
                         bool select_figure= true);
    void place_new_db_object(ModelDiagramForm *view, const base::Point &pos, ObjectType type);

    db_DatabaseObjectRef clone_db_object_to_schema(const db_SchemaRef &schema, const db_DatabaseObjectRef &object, grt::CopyContext &copy_context);

    virtual void block_model_notifications();
    virtual void unblock_model_notifications();

    virtual void delete_db_object(const db_DatabaseObjectRef &object);

    void setup_physical_model(grt::GRT *grt, workbench_DocumentRef &doc, 
                              const std::string &rdbms_name, const std::string &rdbms_version);


    bool has_figure_for_object_in_active_view(const GrtObjectRef &object, ModelDiagramForm *vform= 0);

    void privilege_list_changed(grt::internal::OwnedList *list, bool added, const grt::ValueRef &value,
                                const db_CatalogRef &catalog);
    void remove_user(const db_UserRef &user);
    void remove_role(const db_RoleRef &role);

    db_UserRef add_new_user(const workbench_physical_ModelRef &model);
    db_RoleRef add_new_role(const workbench_physical_ModelRef &model);
    
    void remove_references_to_object(const db_DatabaseObjectRef &object);
    virtual void close_document();

  protected:
    enum RelationshipToolState
    {
      RIdle,
      RPickingStart,
      RPickingEnd,
      RFinished,
      RCancelled
    };

    class RelationshipToolContext : public base::trackable
    {
    private:
      WBComponentPhysical *owner;
      ModelDiagramForm *view;
      RelationshipToolState state;
      std::string last_message;
      RelationshipType type;
      workbench_physical_TableFigureRef hovering;
      std::vector<db_ColumnRef> columns;
      std::vector<db_ColumnRef> refcolumns;

      RelationshipFloater *floater;

      workbench_physical_TableFigureRef itable;
      workbench_physical_TableFigureRef ftable;

      bool pick_table(const workbench_physical_TableFigureRef &table);
      bool pick_reftable(const workbench_physical_TableFigureRef &table);

      bool pick_column(const workbench_physical_TableFigureRef &table, const db_ColumnRef &column);
      bool pick_refcolumn(const workbench_physical_TableFigureRef &table, const db_ColumnRef &column);
      bool done_picking_columns()
      {
        return (!columns.empty() && columns.size() == refcolumns.size());
      }

      bool finish_for_tables();
      bool finish_for_columns();
      bool finish();

      bool add_column(const db_ColumnRef &column);
      bool add_refcolumn(const db_ColumnRef &column);

      void on_figure_crossed(const model_ObjectRef &owner, mdc::CanvasItem *item, bool enter, const base::Point &pos);
      void enter_table(const workbench_physical_TableFigureRef& table);
      void leave_table(const workbench_physical_TableFigureRef& table);
            
      void source_picking_done();

    public:
      RelationshipToolContext(WBComponentPhysical *owner, ModelDiagramForm *form, RelationshipType type);
      
      void cancel();

      bool button_press(ModelDiagramForm *view, const base::Point &pos);
    };

    virtual void load_app_options(bool update);

    virtual void setup_context_grt(grt::GRT *grt, WBOptions *options);

    void init_catalog_grt(const db_mgmt_RdbmsRef &rdbms,
                          const std::string &db_versionRef,
                          workbench_physical_ModelRef &model);

    grt::ListRef<db_UserDatatype> create_builtin_user_datatypes(const db_CatalogRef &catalog, const db_mgmt_RdbmsRef &rdbms);
    
    virtual void setup_canvas_tool(ModelDiagramForm *view, const std::string &tool);

    virtual app_ToolbarRef get_tools_toolbar();
    virtual app_ToolbarRef get_tool_options(const std::string &tool);
    virtual grt::ListRef<app_ShortcutItem> get_shortcut_items();

    virtual void reset_document();
    virtual void document_loaded();
    void add_schema_listeners(const db_SchemaRef &schema);
    void add_schema_object_listeners(const grt::ObjectRef &object);

    virtual bool delete_model_object(const model_ObjectRef &object, bool figure_only);

    virtual bool handles_figure(const model_ObjectRef &figure);
    virtual bool can_paste_object(const grt::ObjectRef &object);
    virtual model_ObjectRef paste_object(ModelDiagramForm *view, const grt::ObjectRef &object, grt::CopyContext &copy_context);
    virtual void copy_object_to_clipboard(const grt::ObjectRef &object, grt::CopyContext &copy_context);



    virtual void activate_canvas_object(const model_ObjectRef &figure, bool newwindow);

    virtual std::string get_object_tooltip(const model_ObjectRef &object, mdc::CanvasItem *item);

    // Toolbar Handling
    virtual std::vector<std::string> get_command_dropdown_items(const std::string &option);

    // drag&drop
    virtual bool accepts_drop(ModelDiagramForm *view, int x, int y, const std::string &type, const std::list<GrtObjectRef> &objects);
    virtual bool perform_drop(ModelDiagramForm *view, int x, int y, const std::string &type, const std::list<GrtObjectRef> &objects);
    virtual bool perform_drop(ModelDiagramForm *view, int x, int y, const std::string &type, const std::string &data);

  public:
    boost::function<void (model_ModelRef)> _refresh_catalog_tree_view;
    virtual GrtObjectRef get_object_for_figure(const model_ObjectRef &object);
  private:
    grt::DictRef delete_db_schema(const db_SchemaRef &schema, bool check_empty);
    
    RelationshipToolContext *start_relationship(ModelDiagramForm *view, const base::Point &pos, RelationshipType type);
    void cancel_relationship(ModelDiagramForm *view, RelationshipToolContext *rctx);

    bool create_nm_relationship(ModelDiagramForm *view, workbench_physical_TableFigureRef table1, 
                                    workbench_physical_TableFigureRef table2,
                                    bool imandatory, bool fmandatory);

  private:
    std::map<std::string, app_ToolbarRef> _toolbars;
    grt::ListRef<app_ShortcutItem> _shortcuts;

    std::vector<std::string> _collation_list;

    std::map<std::string, boost::signals2::connection> _object_listeners;

    std::map<std::string, boost::signals2::connection> _schema_content_listeners;
    std::map<std::string, boost::signals2::connection> _schema_list_listeners;
//    std::list<sigc::connection> _blockable_listeners;

    std::map<std::string, boost::signals2::connection> _figure_list_listeners;
    boost::signals2::connection _model_list_listener;
    boost::signals2::connection _catalog_object_list_listener;
    
    void refresh_ui_for_object(const GrtObjectRef &object);

    bool update_table_fk_connection(const db_TableRef &table, const db_ForeignKeyRef &fk, bool added);

    // Listeners
    void model_object_list_changed(grt::internal::OwnedList *list, bool added, const grt::ValueRef &value);

    void view_object_list_changed(grt::internal::OwnedList *list, bool added, const grt::ValueRef &value, const model_DiagramRef &view);

    void catalog_object_list_changed(grt::internal::OwnedList *list, bool added, const grt::ValueRef &value, const db_CatalogRef &catalog);
    void schema_object_list_changed(grt::internal::OwnedList *list, bool added, const grt::ValueRef &value, const db_SchemaRef &schema);

    void foreign_key_changed(const db_ForeignKeyRef &fk);

    void schema_content_object_changed(const db_DatabaseObjectRef &object);

    void schema_member_changed(const std::string &name, const grt::ValueRef &ovalue, const db_SchemaRef &schema);

    bool handle_button_event(ModelDiagramForm*, mdc::MouseButton, bool, base::Point, mdc::EventState, void *data);

  };

};


#endif