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()) {
151 // TODO: need hourglass
152 CORBA::Object_var object
= pOrb
->string_to_object(
153 selectNS
->getIOR().c_str());
154 rootContext
= CosNaming::NamingContext::_narrow( object
.in ());
155 server
= selectNS
->getServerName();
156 serverText
->SetValue( server
);
158 } catch( CORBA::Exception
const & ex
) {
166 // TODO: need hourglass
174 void WxNamingViewerFrame::onUpdateUICopy( wxUpdateUIEvent
& event
)
176 event
.Enable( tree
->isNodeSelected());
180 void WxNamingViewerFrame::resolve()
182 tree
->resolve( rootContext
.in ());
186 void WxNamingViewerFrame::setDefaultNS()
189 serverText
->SetValue( server
);
191 TAO_Naming_Client client
;
192 if (client
.init( pOrb
) == 0) {
193 rootContext
= client
.get_context();
195 // For debugging, sets up some initial contexts in the NS
197 CosNaming::NamingContext_var app2;
198 app2 = rootContext->new_context();
200 CosNaming::Name name;
202 name[0].id = CORBA::string_dup( "app2");
203 rootContext->rebind_context( name, app2);
205 CosNaming::NamingContext_var devices;
206 devices = app2->new_context();
207 name[0].id = CORBA::string_dup( "devices");
208 app2->rebind_context( name, devices);
210 CosNaming::NamingContext_var collections;
211 collections = app2->new_context();
212 name[0].id = CORBA::string_dup( "collections");
213 app2->rebind_context( name, collections);
215 name[0].id = CORBA::string_dup( "my app");
216 CORBA::Object_var myApp = CORBA::Object::_nil();
217 app2->rebind( name, myApp);
219 name[0].id = CORBA::string_dup( "dev1");
220 CORBA::Object_var dev1 = CORBA::Object::_nil();
221 devices->rebind( name, myApp);
223 name[0].id = CORBA::string_dup( "dev2");
224 CORBA::Object_var dev2 = CORBA::Object::_nil();
225 devices->rebind( name, myApp);