KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corbaclient > Connection


1 package org.enhydra.shark.corbaclient;
2
3 import java.awt.*;
4 import java.awt.event.*;
5
6 import javax.swing.*;
7
8 import org.enhydra.shark.corba.WorkflowService.*;
9 import org.omg.CORBA.*; // All CORBA applications need these classes.
10
import org.omg.CosNaming.*; // Client will use the naming service.
11

12 /**
13  * Implements dialog for connection to the workflow engine. User
14  * enters it's username, password, nameserver host name and
15  * nameserver port. If data are correct, it retrieves the
16  * WorkflowServer object that is registred at the nameserver, and
17  * gets the WorkflowClientService instance which is used to
18  * retreive data from engine.
19  *
20  * @author Sasa Bojanic
21  * @version 1.0
22  */

23 public class Connection extends ActionPanel {
24
25    private static Dimension textFieldDimension=new Dimension(200,20);
26
27
28    private String JavaDoc username=null;
29    private String JavaDoc pwd=null;
30
31    private JTextField usernameField;
32    private JPasswordField passwordField;
33    private JTextField nameServerHostField;
34    private JTextField nameServerPortField;
35    private JTextField workflowServerNameField;
36
37    private SharkConnection workflowService;
38
39    private SharkClient workflowClient;
40
41    public Connection(JFrame parent,SharkClient workflowClient){
42       super();
43       this.workflowClient=workflowClient;
44       super.init();
45       super.initDialog(parent,ResourceManager.getLanguageDependentString("DialogConnectToWorkflowServer"),true,true);
46    }
47
48    protected void createActions () {}
49
50    protected Component createCenterComponent (){
51       JPanel panel = new JPanel();
52
53       panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
54       panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
55
56       // username
57
JPanel unPanel=new JPanel();
58       unPanel.setLayout(new BoxLayout(unPanel,BoxLayout.X_AXIS));
59       JLabel unl=new JLabel(ResourceManager.getLanguageDependentString("UsernameKey")+":");
60       unPanel.add(Box.createHorizontalGlue());
61       unPanel.add(unl);
62       usernameField=new JTextField();
63       usernameField.setMinimumSize(new Dimension(textFieldDimension));
64       usernameField.setMaximumSize(new Dimension(textFieldDimension));
65       usernameField.setPreferredSize(new Dimension(textFieldDimension));
66       unPanel.add(usernameField);
67
68       // password
69
JPanel pwdPanel=new JPanel();
70       pwdPanel.setLayout(new BoxLayout(pwdPanel,BoxLayout.X_AXIS));
71       JLabel pwdl = new JLabel(ResourceManager.getLanguageDependentString("PasswordKey")+":");
72       pwdPanel.add(Box.createHorizontalGlue());
73       pwdPanel.add(pwdl);
74       passwordField = new JPasswordField();
75       passwordField.setMinimumSize(new Dimension(textFieldDimension));
76       passwordField.setMaximumSize(new Dimension(textFieldDimension));
77       passwordField.setPreferredSize(new Dimension(textFieldDimension));
78       pwdPanel.add(passwordField);
79
80       // nameserver host
81
JPanel nshPanel=new JPanel();
82       nshPanel.setLayout(new BoxLayout(nshPanel,BoxLayout.X_AXIS));
83       JLabel nshl=new JLabel(ResourceManager.getLanguageDependentString("NameServerHostKey")+":");
84       nshPanel.add(Box.createHorizontalGlue());
85       nshPanel.add(nshl);
86       nameServerHostField=new JTextField("localhost");
87       nameServerHostField.setMinimumSize(new Dimension(textFieldDimension));
88       nameServerHostField.setMaximumSize(new Dimension(textFieldDimension));
89       nameServerHostField.setPreferredSize(new Dimension(textFieldDimension));
90       nshPanel.add(nameServerHostField);
91
92       // nameserver port
93
JPanel nspPanel=new JPanel();
94       nspPanel.setLayout(new BoxLayout(nspPanel,BoxLayout.X_AXIS));
95       JLabel nspl=new JLabel(ResourceManager.getLanguageDependentString("NameServerPortKey")+":");
96       nspPanel.add(Box.createHorizontalGlue());
97       nspPanel.add(nspl);
98       nameServerPortField=new JTextField("10123");
99       nameServerPortField.setMinimumSize(new Dimension(textFieldDimension));
100       nameServerPortField.setMaximumSize(new Dimension(textFieldDimension));
101       nameServerPortField.setPreferredSize(new Dimension(textFieldDimension));
102       nspPanel.add(nameServerPortField);
103
104       // nameserver port
105
JPanel wsnPanel=new JPanel();
106       wsnPanel.setLayout(new BoxLayout(wsnPanel,BoxLayout.X_AXIS));
107       JLabel wsnl=new JLabel(ResourceManager.getLanguageDependentString("WorkflowServerKey")+":");
108       wsnPanel.add(Box.createHorizontalGlue());
109       wsnPanel.add(wsnl);
110       workflowServerNameField=new JTextField("Shark");
111       workflowServerNameField.setMinimumSize(new Dimension(textFieldDimension));
112       workflowServerNameField.setMaximumSize(new Dimension(textFieldDimension));
113       workflowServerNameField.setPreferredSize(new Dimension(textFieldDimension));
114       wsnPanel.add(workflowServerNameField);
115
116       panel.add(unPanel);
117       panel.add(pwdPanel);
118       panel.add(nshPanel);
119       panel.add(nspPanel);
120       panel.add(wsnPanel);
121       return panel;
122    }
123
124    protected void applyChanges () {
125       try {
126          connectToServer();
127          workflowService.connect(usernameField.getText(),
128                                  new String JavaDoc(passwordField.getPassword()),"","");
129          username=usernameField.getText();
130          pwd=new String JavaDoc(passwordField.getPassword());
131       } catch (ConnectFailed cf) {
132          workflowService=null;
133          username=null;
134          pwd=null;
135          JOptionPane.showMessageDialog(this,
136                                        ResourceManager.getLanguageDependentString("ErrorUncorrectLogin"),
137                                        ResourceManager.getLanguageDependentString("DialogConnectToWorkflowServer"),
138                                        JOptionPane.ERROR_MESSAGE);
139       } catch (Exception JavaDoc ex) {
140          workflowService=null;
141          username=null;
142          JOptionPane.showMessageDialog(this,
143                                        ResourceManager.getLanguageDependentString("ErrorTheServerIsDownOrItIsBusy"),
144                                        ResourceManager.getLanguageDependentString("DialogConnectToWorkflowServer"),
145                                        JOptionPane.ERROR_MESSAGE);
146       }
147       updateClient();
148       if (username!=null) {
149          myDialog.hide();
150       }
151    }
152
153    private void connectToServer () {
154       try{
155          workflowService = workflowClient.findWorkflowServer(
156             nameServerHostField.getText().trim(),
157             nameServerPortField.getText().trim(),
158             workflowServerNameField.getText().trim()).getSharkConnection();
159       } catch(Exception JavaDoc e) {
160          //e.printStackTrace();
161
}
162    }
163
164
165    protected void cancelChanges () {
166       workflowService=null;
167       username=null;
168       myDialog.hide();
169       updateClient();
170    }
171
172    private void updateClient () {
173       workflowClient.setUsername(username);
174       workflowClient.setPassword(pwd);
175       workflowClient.setService(workflowService);
176       workflowClient.setTitle();
177    }
178
179    public void showDialog() {
180       passwordField.setText("");
181       super.showDialog();
182    }
183
184 }
185
186
187
Popular Tags