1 // @file wxViewIORDialog.cpp
3 // @author Charlie Frasch <cfrasch@atdesk.com>
5 #include "wxViewIORDialog.h"
7 #include "tao/Profile.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
);
24 new wxStaticText( dialog
, -1, "IOR:" ),
28 wxTextCtrl
* iorText
= new wxTextCtrl(
32 iorText
->SetName( "iorText");
41 wxALIGN_LEFT
| wxEXPAND
);
45 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
47 new wxStaticText( dialog
, -1, "Repository ID:" ),
51 wxTextCtrl
* typeID
= new wxTextCtrl(
55 typeID
->SetName( "typeIDText");
64 wxALIGN_LEFT
| wxEXPAND
);
68 wxTreeCtrl
* profiles
= new wxTreeCtrl(
74 profiles
->SetName( "profilesTree");
82 wxBoxSizer
* button_sizer
= new wxBoxSizer( wxHORIZONTAL
);
84 wxButton
* okButton
= new wxButton( dialog
, wxID_OK
, "OK" );
85 okButton
->SetName( "okButton");
93 wxButton
* applyButton
= new wxButton( dialog
, wxID_APPLY
, "Apply" );
94 applyButton
->SetName( "applyButton");
103 new wxButton( dialog
, wxID_CANCEL
, "Cancel" ),
113 dialog
->SetSizer( topsizer
);
114 topsizer
->SetSizeHints( dialog
);
118 BEGIN_EVENT_TABLE( WxViewIORDialog
, wxDialog
)
119 EVT_BUTTON( wxID_APPLY
, WxViewIORDialog::OnApply
)
120 EVT_TEXT( IDC_IOR
, WxViewIORDialog::onIORText
)
124 WxViewIORDialog::WxViewIORDialog(
126 CORBA::Object_ptr object
,
128 #if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
133 IDD_NAMINGVIEWER_DIALOG
,
137 wxRAISED_BORDER
| wxCAPTION
| wxTHICK_FRAME
| wxSYSTEM_MENU
,
139 #endif // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
142 #if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
143 LoadFromResource( parent
, "viewIOR");
145 create_dialog_components( this);
146 #endif // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
147 iorText
= static_cast<wxTextCtrl
*>( wxFindWindowByName(
151 typeIDText
= static_cast<wxTextCtrl
*>( wxFindWindowByName(
155 profiles
= static_cast<wxTreeCtrl
*>( wxFindWindowByName(
159 wxButton
* ctrl
= static_cast<wxButton
*>( wxFindWindowByName(
164 applyButton
= static_cast<wxButton
*>( wxFindWindowByName(
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
;
179 void WxViewIORDialog::decodeIOR()
181 profiles
->DeleteAllItems();
183 // if object is nil, return out
184 if(CORBA::is_nil( object
.in())) {
186 TransferDataToWindow();
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
);
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
);
221 object
= orb
->string_to_object( ior
);
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();
245 bool WxViewIORDialog::TransferDataToWindow()
247 iorText
->SetValue( ior
);
248 typeIDText
->SetValue( typeID
);