summaryrefslogtreecommitdiff
path: root/TAO/utils/wxNamingViewer/wxSelectNSDialog.cpp
blob: 0601ca662f45132e69001d48e8924cf6a166245a (plain)
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
// $Id$
// wxSelectNSDialog.cpp

#include "pch.h"
#include "wxSelectNSDialog.h"

#include "ace/Configuration.h"
#include "wxAddNameServerDlg.h"
#include "wxAutoDialog.h"
#include "wxNamingViewer.h"



BEGIN_EVENT_TABLE( WxSelectNSDialog, wxDialog)
  EVT_BUTTON( IDC_ADD, WxSelectNSDialog::onAdd)
  EVT_BUTTON( IDC_DEFAULT, WxSelectNSDialog::onDefault)
  EVT_BUTTON( wxID_OK, WxSelectNSDialog::onOK)
  EVT_BUTTON( IDC_REMOVE, WxSelectNSDialog::onRemove)
  EVT_INIT_DIALOG( WxSelectNSDialog::onInitDialog)
  EVT_LISTBOX_DCLICK( IDC_SERVERS, WxSelectNSDialog::onLeftDClick)
END_EVENT_TABLE()


WxSelectNSDialog::WxSelectNSDialog( wxWindow* parent):
  wxDialog(),
  config( 0)
{
  LoadFromResource( parent, "selectNS");
  servers = static_cast<wxListBox*>( wxFindWindowByName(
      "serversList",
      this));
  assert( servers);

#if defined (ACE_WIN32)
  HKEY hKey = ACE_Configuration_Win32Registry::resolve_key(
      HKEY_LOCAL_MACHINE,
      "Software\\TAO\\NamingViewer\\Servers");
  config = new ACE_Configuration_Win32Registry( hKey);
#else
  // TODO: non-windoz
    assert( config);
#endif
  ACE_Configuration_Section_Key section = config->root_section();
  int index = 0;
  ACE_TString name;
  ACE_Configuration::VALUETYPE type;
  while(config->enumerate_values( section, index, name, type) == 0) {

    ACE_TString value;
    if(config->get_string_value( section, name.c_str(), value) == 0) {

      servers->Append(
          name.c_str(),
          new wxString( value.c_str()));

    }
    index++;

  }
}


WxSelectNSDialog::~WxSelectNSDialog()
{
  int count = servers->Number();
  for (int i = 0; i < count; i++) {

    delete static_cast<wxString*>( servers->GetClientData( i));

  }
}


void WxSelectNSDialog::onAdd( wxCommandEvent& WXUNUSED(event))
{
  WxAutoDialog<WxAddNameServerDlg> dialog( new WxAddNameServerDlg( this));
  if (dialog->ShowModal() == wxID_OK) {

    servers->Append(
        dialog->getServerName(),
        new wxString( dialog->getIor()));
    ACE_Configuration_Section_Key section = config->root_section();
    ACE_TString value = dialog->getIor().c_str();
    config->set_string_value(
        section,
        dialog->getServerName().c_str(),
        value);

  }
}


void WxSelectNSDialog::onDefault( wxCommandEvent& WXUNUSED(event))
{
  EndModal( IDC_DEFAULT);
}


void WxSelectNSDialog::onInitDialog( wxInitDialogEvent& event)
{
  wxButton* ctrl = static_cast<wxButton*>( wxFindWindowByName(
      "okButton",
      this));
  assert( ctrl);
  ctrl->SetDefault();
  servers->SetFocus();
}


void WxSelectNSDialog::onLeftDClick( wxMouseEvent& event)
{
  int index = servers->GetSelection();
  // I don't think index will ever be -1!
  assert( index != -1);
  ior = *static_cast<wxString*>( servers->GetClientData( index));
  serverName = servers->GetString( index);
  EndModal( wxID_OK);
}


void WxSelectNSDialog::onOK( wxCommandEvent& WXUNUSED(event))
{
  int index = servers->GetSelection();
  if (index == -1) {

    wxMessageBox(
        "You must select a server or cancel",
       "Error",
        wxOK | wxICON_EXCLAMATION);
    return;
  }
  ior = *static_cast<wxString*>( servers->GetClientData( index));
  serverName = servers->GetString( index);
  EndModal( wxID_OK);
}


void WxSelectNSDialog::onRemove( wxCommandEvent& WXUNUSED(event))
{
  int index = servers->GetSelection();
  if (index != -1) {

    wxString name = servers->GetString( index);
    delete static_cast<wxString*>( servers->GetClientData( index));
    servers->Delete( index);

    ACE_Configuration_Section_Key section = config->root_section();;
    config->remove_value( section, name);

  }
}