1 // @file wxNamingViewerFrame.cpp
3 // @author Charlie Frasch <cfrasch@atdesk.com>
5 #include "wxNamingViewerFrame.h"
7 #include "wx/clipbrd.h"
8 #include "orbsvcs/Naming/Naming_Client.h"
9 #include "wxNamingViewer.h"
10 #include "wxSelectNSDialog.h"
11 #include "ace/SString.h"
13 #if defined(__WXGTK__) || defined(__WXMOTIF__)
14 #include "mondrian.xpm"
22 buttonSelectNS
= IDC_SELECT_NS
26 BEGIN_EVENT_TABLE( WxNamingViewerFrame
, wxFrame
)
27 EVT_MENU( menuQuit
, WxNamingViewerFrame::OnQuit
)
28 EVT_MENU( menuAbout
, WxNamingViewerFrame::OnAbout
)
29 EVT_MENU( menuCopy
, WxNamingViewerFrame::onMenuCopy
)
30 EVT_UPDATE_UI( menuCopy
, WxNamingViewerFrame::onUpdateUICopy
)
31 EVT_BUTTON( buttonSelectNS
, WxNamingViewerFrame::onSelectNS
)
35 WxNamingViewerFrame::WxNamingViewerFrame(
36 const wxString
& title
,
49 SetIcon( wxICON( mondrian
));
51 wxMenu
* fileMenu
= new wxMenu( "", wxMENU_TEAROFF
);
52 fileMenu
->Append( menuQuit
, "E&xit", "Quit this program");
54 wxMenu
* editMenu
= new wxMenu( "", wxMENU_TEAROFF
);
55 editMenu
->Append( menuCopy
, "&Copy\tCtrl+C");
57 wxMenu
* helpMenu
= new wxMenu();
58 helpMenu
->Append( menuAbout
, "&About...", "Show about dialog");
60 wxMenuBar
* menuBar
= new wxMenuBar();
61 menuBar
->Append( fileMenu
, "&File");
62 menuBar
->Append( editMenu
, "&Edit");
63 menuBar
->Append( helpMenu
, "&Help");
66 wxPanel
* panel
= new wxPanel(
69 wxBoxSizer
* topSizer
= new wxBoxSizer( wxVERTICAL
);
70 topSizer
->Add( panel
, 1, wxGROW
);
72 wxBoxSizer
* nsSizer
= new wxStaticBoxSizer(
78 serverText
= new wxTextCtrl(
85 wxButton
* selectNSButton
= new wxButton(
91 nsSizer
->Add( serverText
, 1, wxGROW
);
92 nsSizer
->Add( selectNSButton
, 0, wxALIGN_LEFT
| wxLEFT
, 10);
94 wxBoxSizer
* treeSizer
= new wxBoxSizer( wxVERTICAL
);
95 treeSizer
->Add( nsSizer
, 0, wxGROW
);
96 tree
= new WxNamingTree(
98 WxNamingTree::treeCtrl
);
99 treeSizer
->Add( tree
, 1, wxGROW
);
101 panel
->SetAutoLayout( TRUE
);
102 panel
->SetSizer( treeSizer
);
103 treeSizer
->Fit( this);
104 treeSizer
->SetSizeHints( this);
106 selectNS
= new WxSelectNSDialog( this);
114 WxNamingViewerFrame::~WxNamingViewerFrame()
120 void WxNamingViewerFrame::OnQuit( wxCommandEvent
& WXUNUSED(event
))
126 void WxNamingViewerFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
129 "wxNamingViewer Version 1.1\n"
130 "Author: Charlie Frasch <cfrasch@atdesk.com>");
134 "About wxNamingViewer",
135 wxOK
| wxICON_INFORMATION
,
140 void WxNamingViewerFrame::onMenuCopy( wxCommandEvent
& WXUNUSED( event
))
142 tree
->copySelectedToClipboard();
146 void WxNamingViewerFrame::onSelectNS( wxCommandEvent
& WXUNUSED( event
))
148 switch( selectNS
->ShowModal()) {
153 // TODO: need hourglass
154 CORBA::Object_var object
= pOrb
->string_to_object(
155 selectNS
->getIOR().c_str());
156 rootContext
= CosNaming::NamingContext::_narrow( object
.in ());
157 server
= selectNS
->getServerName();
158 serverText
->SetValue( server
);
161 } catch( CORBA::Exception
const & ex
) {
171 // TODO: need hourglass
180 void WxNamingViewerFrame::onUpdateUICopy( wxUpdateUIEvent
& event
)
182 event
.Enable( tree
->isNodeSelected());
186 void WxNamingViewerFrame::resolve()
188 tree
->resolve( rootContext
.in ());
192 void WxNamingViewerFrame::setDefaultNS()
195 serverText
->SetValue( server
);
197 TAO_Naming_Client client
;
198 if (client
.init( pOrb
) == 0) {
200 rootContext
= client
.get_context();
202 // For debugging, sets up some initial contexts in the NS
204 CosNaming::NamingContext_var app2;
205 app2 = rootContext->new_context();
207 CosNaming::Name name;
209 name[0].id = CORBA::string_dup( "app2");
210 rootContext->rebind_context( name, app2);
212 CosNaming::NamingContext_var devices;
213 devices = app2->new_context();
214 name[0].id = CORBA::string_dup( "devices");
215 app2->rebind_context( name, devices);
217 CosNaming::NamingContext_var collections;
218 collections = app2->new_context();
219 name[0].id = CORBA::string_dup( "collections");
220 app2->rebind_context( name, collections);
222 name[0].id = CORBA::string_dup( "my app");
223 CORBA::Object_var myApp = CORBA::Object::_nil();
224 app2->rebind( name, myApp);
226 name[0].id = CORBA::string_dup( "dev1");
227 CORBA::Object_var dev1 = CORBA::Object::_nil();
228 devices->rebind( name, myApp);
230 name[0].id = CORBA::string_dup( "dev2");
231 CORBA::Object_var dev2 = CORBA::Object::_nil();
232 devices->rebind( name, myApp);