1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
// @file wxNamingViewerFrame.cpp
//
// @author Charlie Frasch <cfrasch@atdesk.com>
#include "pch.h"
#include "wxNamingViewerFrame.h"
#include "wx/clipbrd.h"
#include "orbsvcs/Naming/Naming_Client.h"
#include "wxNamingViewer.h"
#include "wxSelectNSDialog.h"
#include "ace/SString.h"
#if defined(__WXGTK__) || defined(__WXMOTIF__)
#include "mondrian.xpm"
#endif
enum {
menuQuit = 1,
menuAbout,
menuCopy,
buttonSelectNS = IDC_SELECT_NS
};
BEGIN_EVENT_TABLE( WxNamingViewerFrame, wxFrame)
EVT_MENU( menuQuit, WxNamingViewerFrame::OnQuit)
EVT_MENU( menuAbout, WxNamingViewerFrame::OnAbout)
EVT_MENU( menuCopy, WxNamingViewerFrame::onMenuCopy)
EVT_UPDATE_UI( menuCopy, WxNamingViewerFrame::onUpdateUICopy)
EVT_BUTTON( buttonSelectNS, WxNamingViewerFrame::onSelectNS)
END_EVENT_TABLE()
WxNamingViewerFrame::WxNamingViewerFrame(
const wxString& title,
const wxPoint& pos,
const wxSize& size,
CORBA::ORB_ptr pOrb):
wxFrame(
0,
-1, title,
pos,
size),
pOrb( pOrb),
tree( 0),
server( "")
{
SetIcon( wxICON( mondrian));
wxMenu* fileMenu = new wxMenu( "", wxMENU_TEAROFF);
fileMenu->Append( menuQuit, "E&xit", "Quit this program");
wxMenu* editMenu = new wxMenu( "", wxMENU_TEAROFF);
editMenu->Append( menuCopy, "&Copy\tCtrl+C");
wxMenu* helpMenu = new wxMenu();
helpMenu->Append( menuAbout, "&About...", "Show about dialog");
wxMenuBar* menuBar = new wxMenuBar();
menuBar->Append( fileMenu, "&File");
menuBar->Append( editMenu, "&Edit");
menuBar->Append( helpMenu, "&Help");
SetMenuBar( menuBar);
wxPanel* panel = new wxPanel(
this,
-1);
wxBoxSizer* topSizer = new wxBoxSizer( wxVERTICAL);
topSizer->Add( panel, 1, wxGROW);
wxBoxSizer* nsSizer = new wxStaticBoxSizer(
new wxStaticBox(
panel,
IDC_NS,
"Name Server"),
wxHORIZONTAL);
serverText = new wxTextCtrl(
panel,
IDC_SERVER,
"",
wxDefaultPosition,
wxSize( 158, 20),
wxTE_READONLY);
wxButton* selectNSButton = new wxButton(
panel,
IDC_SELECT_NS,
"Select",
wxDefaultPosition,
wxSize( 50, 20));
nsSizer->Add( serverText, 1, wxGROW);
nsSizer->Add( selectNSButton, 0, wxALIGN_LEFT | wxLEFT, 10);
wxBoxSizer* treeSizer = new wxBoxSizer( wxVERTICAL);
treeSizer->Add( nsSizer, 0, wxGROW);
tree = new WxNamingTree(
panel,
WxNamingTree::treeCtrl);
treeSizer->Add( tree, 1, wxGROW);
panel->SetAutoLayout( TRUE );
panel->SetSizer( treeSizer );
treeSizer->Fit( this);
treeSizer->SetSizeHints( this);
selectNS = new WxSelectNSDialog( this);
tree->setOrb( pOrb);
setDefaultNS();
resolve();
}
WxNamingViewerFrame::~WxNamingViewerFrame()
{
selectNS->Destroy();
}
void WxNamingViewerFrame::OnQuit( wxCommandEvent& WXUNUSED(event))
{
Close( TRUE);
}
void WxNamingViewerFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxString msg(
"wxNamingViewer Version 1.1\n"
"Author: Charlie Frasch <cfrasch@atdesk.com>");
wxMessageBox(
msg.c_str(),
"About wxNamingViewer",
wxOK | wxICON_INFORMATION,
this);
}
void WxNamingViewerFrame::onMenuCopy( wxCommandEvent& WXUNUSED( event))
{
tree->copySelectedToClipboard();
}
void WxNamingViewerFrame::onSelectNS( wxCommandEvent& WXUNUSED( event))
{
switch( selectNS->ShowModal()) {
case wxID_OK:
try {
// TODO: need hourglass
CORBA::Object_var object = pOrb->string_to_object(
selectNS->getIOR().c_str());
rootContext = CosNaming::NamingContext::_narrow( object.in ());
server = selectNS->getServerName();
serverText->SetValue( server);
resolve();
} catch( CORBA::Exception const & ex) {
wxMessageBox(
ex._info().c_str(),
"CORBA::Exception");
}
break;
case IDC_DEFAULT:
// TODO: need hourglass
setDefaultNS();
resolve();
break;
}
}
void WxNamingViewerFrame::onUpdateUICopy( wxUpdateUIEvent& event)
{
event.Enable( tree->isNodeSelected());
}
void WxNamingViewerFrame::resolve()
{
tree->resolve( rootContext.in ());
}
void WxNamingViewerFrame::setDefaultNS()
{
server = "Default";
serverText->SetValue( server);
TAO_Naming_Client client;
if (client.init( pOrb) == 0) {
rootContext = client.get_context();
// For debugging, sets up some initial contexts in the NS
/*
CosNaming::NamingContext_var app2;
app2 = rootContext->new_context();
CosNaming::Name name;
name.length( 1);
name[0].id = CORBA::string_dup( "app2");
rootContext->rebind_context( name, app2);
CosNaming::NamingContext_var devices;
devices = app2->new_context();
name[0].id = CORBA::string_dup( "devices");
app2->rebind_context( name, devices);
CosNaming::NamingContext_var collections;
collections = app2->new_context();
name[0].id = CORBA::string_dup( "collections");
app2->rebind_context( name, collections);
name[0].id = CORBA::string_dup( "my app");
CORBA::Object_var myApp = CORBA::Object::_nil();
app2->rebind( name, myApp);
name[0].id = CORBA::string_dup( "dev1");
CORBA::Object_var dev1 = CORBA::Object::_nil();
devices->rebind( name, myApp);
name[0].id = CORBA::string_dup( "dev2");
CORBA::Object_var dev2 = CORBA::Object::_nil();
devices->rebind( name, myApp);
*/
}
}
|