Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / utils / wxNamingViewer / wxViewIORDialog.cpp
blobf6ea0460cf57d1e38646849573c3674764aab61c
1 // @file wxViewIORDialog.cpp
2 //
3 // @author Charlie Frasch <cfrasch@atdesk.com>
4 #include "pch.h"
5 #include "wxViewIORDialog.h"
7 #include "tao/Profile.h"
8 #include "tao/Stub.h"
9 #include "wx/sizer.h"
10 #include "wx/textctrl.h"
11 #include "wx/treectrl.h"
12 #include "wxNamingViewer.h"
13 #include "ace/SString.h"
15 namespace // anonymous
17 void create_dialog_components( wxDialog* dialog)
19 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL);
22 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL);
23 sizer->Add(
24 new wxStaticText( dialog, -1, "IOR:" ),
26 wxALL,
27 5);
28 wxTextCtrl* iorText = new wxTextCtrl(
29 dialog,
30 IDC_IOR
32 iorText->SetName( "iorText");
33 sizer->Add(
34 iorText,
36 wxALL,
37 5);
38 topsizer->Add(
39 sizer,
41 wxALIGN_LEFT | wxEXPAND);
45 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL);
46 sizer->Add(
47 new wxStaticText( dialog, -1, "Repository ID:" ),
49 wxALL,
50 5);
51 wxTextCtrl* typeID = new wxTextCtrl(
52 dialog,
53 IDC_TYPE_ID
55 typeID->SetName( "typeIDText");
56 sizer->Add(
57 typeID,
59 wxALL,
60 5);
61 topsizer->Add(
62 sizer,
64 wxALIGN_LEFT | wxEXPAND);
68 wxTreeCtrl* profiles = new wxTreeCtrl(
69 dialog,
70 IDC_PROFILES,
71 wxDefaultPosition,
72 wxSize( 675, 140)
74 profiles->SetName( "profilesTree");
75 topsizer->Add(
76 profiles,
78 wxALL | wxEXPAND,
79 5);
82 wxBoxSizer* button_sizer = new wxBoxSizer( wxHORIZONTAL);
84 wxButton* okButton = new wxButton( dialog, wxID_OK, "OK" );
85 okButton->SetName( "okButton");
86 button_sizer->Add(
87 okButton,
89 wxALL,
90 5);
93 wxButton* applyButton = new wxButton( dialog, wxID_APPLY, "Apply" );
94 applyButton->SetName( "applyButton");
95 button_sizer->Add(
96 applyButton,
98 wxALL,
99 5);
102 button_sizer->Add(
103 new wxButton( dialog, wxID_CANCEL, "Cancel" ),
105 wxALL,
108 topsizer->Add(
109 button_sizer,
111 wxALIGN_CENTER);
113 dialog->SetSizer( topsizer);
114 topsizer->SetSizeHints( dialog);
116 }; // anonymous
118 BEGIN_EVENT_TABLE( WxViewIORDialog, wxDialog)
119 EVT_BUTTON( wxID_APPLY, WxViewIORDialog::OnApply)
120 EVT_TEXT( IDC_IOR, WxViewIORDialog::onIORText)
121 END_EVENT_TABLE()
124 WxViewIORDialog::WxViewIORDialog(
125 CORBA::ORB_ptr orb,
126 CORBA::Object_ptr object,
127 wxWindow* parent)
128 #if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
129 : wxDialog()
130 #else
131 : wxDialog(
132 parent,
133 IDD_NAMINGVIEWER_DIALOG,
134 "View IOR",
135 wxDefaultPosition,
136 wxSize(394,127),
137 wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU,
138 "viewIOR")
139 #endif // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
140 , orb( orb)
142 #if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
143 LoadFromResource( parent, "viewIOR");
144 #else
145 create_dialog_components( this);
146 #endif // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
147 iorText = static_cast<wxTextCtrl*>( wxFindWindowByName(
148 "iorText",
149 this));
150 assert( iorText);
151 typeIDText = static_cast<wxTextCtrl*>( wxFindWindowByName(
152 "typeIDText",
153 this));
154 assert( typeIDText);
155 profiles = static_cast<wxTreeCtrl*>( wxFindWindowByName(
156 "profilesTree",
157 this));
158 assert( typeIDText);
159 wxButton* ctrl = static_cast<wxButton*>( wxFindWindowByName(
160 "okButton",
161 this));
162 assert( ctrl);
163 ctrl->SetDefault();
164 applyButton = static_cast<wxButton*>( wxFindWindowByName(
165 "applyButton",
166 this));
167 assert( applyButton);
168 applyButton->Enable( false);
170 if (object != CORBA::Object::_nil()) {
171 WxViewIORDialog::object = CORBA::Object::_duplicate( object);
173 CORBA::String_var ior = orb->object_to_string( object);
174 WxViewIORDialog::ior = ior;
175 decodeIOR();
179 void WxViewIORDialog::decodeIOR()
181 profiles->DeleteAllItems();
183 // if object is nil, return out
184 if(CORBA::is_nil( object.in())) {
185 typeID = "";
186 TransferDataToWindow();
187 return;
190 // Get the stub
191 TAO_Stub* stub = object->_stubobj();
192 const char* type = stub->type_id;
193 typeID = type ? type : ""; // special case for INS objects, tao doesn't get the type id
194 TransferDataToWindow();
196 // Iterate through each profile and add an entry to the tree control
197 const TAO_MProfile& baseProfiles = stub->base_profiles();
198 CORBA::ULong count = baseProfiles.profile_count();
199 wxTreeItemId rootItem = profiles->AddRoot( "Profiles");
200 for( CORBA::ULong slot = 0; slot < count; slot++) {
201 const TAO_Profile* profile = baseProfiles.get_profile( slot);
202 try{
203 // The need to const_cast should disappear in TAO 1.1.2 BUT IT DIDN'T
204 char* profileString =
205 const_cast<TAO_Profile*>(profile)->to_string();
206 profiles->AppendItem( rootItem, profileString);
207 delete [] profileString;
208 } catch (const CORBA::Exception& ex) {
209 wxMessageBox( ex._info().c_str(), "CORBA::Exception");
213 profiles->Expand( rootItem);
217 void WxViewIORDialog::OnApply( wxCommandEvent& event)
219 wxDialog::OnApply( event);
220 try {
221 object = orb->string_to_object( ior);
222 decodeIOR();
223 } catch( CORBA::Exception& ex) {
224 wxMessageBox( ex._info().c_str(), "CORBA::Exception");
229 void WxViewIORDialog::onIORText( wxCommandEvent& event)
231 // Enable the Apply button if the IOR has changed
232 if (event.GetString() != ior) {
233 applyButton->Enable( true);
238 bool WxViewIORDialog::TransferDataFromWindow()
240 ior = iorText->GetValue();
241 return true;
245 bool WxViewIORDialog::TransferDataToWindow()
247 iorText->SetValue( ior);
248 typeIDText->SetValue( typeID);
249 return true;