Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / utils / wxNamingViewer / wxNamingViewerFrame.cpp
blobabd14d11e1f6be1c2633905daf1813ca878672dc
1 // @file wxNamingViewerFrame.cpp
2 //
3 // @author Charlie Frasch <cfrasch@atdesk.com>
4 #include "pch.h"
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"
15 #endif
18 enum {
19 menuQuit = 1,
20 menuAbout,
21 menuCopy,
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)
32 END_EVENT_TABLE()
35 WxNamingViewerFrame::WxNamingViewerFrame(
36 const wxString& title,
37 const wxPoint& pos,
38 const wxSize& size,
39 CORBA::ORB_ptr pOrb):
40 wxFrame(
42 -1, title,
43 pos,
44 size),
45 pOrb( pOrb),
46 tree( 0),
47 server( "")
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");
64 SetMenuBar( menuBar);
66 wxPanel* panel = new wxPanel(
67 this,
68 -1);
69 wxBoxSizer* topSizer = new wxBoxSizer( wxVERTICAL);
70 topSizer->Add( panel, 1, wxGROW);
72 wxBoxSizer* nsSizer = new wxStaticBoxSizer(
73 new wxStaticBox(
74 panel,
75 IDC_NS,
76 "Name Server"),
77 wxHORIZONTAL);
78 serverText = new wxTextCtrl(
79 panel,
80 IDC_SERVER,
81 "",
82 wxDefaultPosition,
83 wxSize( 158, 20),
84 wxTE_READONLY);
85 wxButton* selectNSButton = new wxButton(
86 panel,
87 IDC_SELECT_NS,
88 "Select",
89 wxDefaultPosition,
90 wxSize( 50, 20));
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(
97 panel,
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);
108 tree->setOrb( pOrb);
109 setDefaultNS();
110 resolve();
114 WxNamingViewerFrame::~WxNamingViewerFrame()
116 selectNS->Destroy();
120 void WxNamingViewerFrame::OnQuit( wxCommandEvent& WXUNUSED(event))
122 Close( TRUE);
126 void WxNamingViewerFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
128 wxString msg(
129 "wxNamingViewer Version 1.1\n"
130 "Author: Charlie Frasch <cfrasch@atdesk.com>");
132 wxMessageBox(
133 msg.c_str(),
134 "About wxNamingViewer",
135 wxOK | wxICON_INFORMATION,
136 this);
140 void WxNamingViewerFrame::onMenuCopy( wxCommandEvent& WXUNUSED( event))
142 tree->copySelectedToClipboard();
146 void WxNamingViewerFrame::onSelectNS( wxCommandEvent& WXUNUSED( event))
148 switch( selectNS->ShowModal()) {
150 case wxID_OK:
151 try {
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);
159 resolve();
161 } catch( CORBA::Exception const & ex) {
163 wxMessageBox(
164 ex._info().c_str(),
165 "CORBA::Exception");
168 break;
170 case IDC_DEFAULT:
171 // TODO: need hourglass
172 setDefaultNS();
173 resolve();
174 break;
180 void WxNamingViewerFrame::onUpdateUICopy( wxUpdateUIEvent& event)
182 event.Enable( tree->isNodeSelected());
186 void WxNamingViewerFrame::resolve()
188 tree->resolve( rootContext.in ());
192 void WxNamingViewerFrame::setDefaultNS()
194 server = "Default";
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;
208 name.length( 1);
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);