sessionConfigurations = ClientHelper.readFileProperties(CONFIGS_FOLDER + CONFIGS_LIBRARY, CONFIGS_FOLDER);
final JComboBox configs = new JComboBox();
configs.setMaximumRowCount(20);
configs.addItem(new FileEntry("", null));
if (sessionConfigurations != null) {
for (FileEntry fe : sessionConfigurations) {
configs.addItem(fe);
}
}
expertPanel.add(configs, BorderLayout.PAGE_START);
sessionParameterTextArea = new JTextArea();
sessionParameterTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
expertPanel.add(new JScrollPane(sessionParameterTextArea), BorderLayout.CENTER);
loginTabs.addTab("Expert", expertPanel);
// repository
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.PAGE_AXIS));
buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
add(buttonPanel, BorderLayout.PAGE_END);
loadRepositoryButton = createButton("Load Repositories");
buttonPanel.add(loadRepositoryButton);
getRootPane().setDefaultButton(loadRepositoryButton);
createRepositoryBox(buttonPanel);
loginButton = createButton("Login");
buttonPanel.add(loginButton);
loginButton.setEnabled(false);
// listeners
loadRepositoryButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
repositoryBox.removeAllItems();
try {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
createClientSession();
List<Repository> repositories = clientSession.getRepositories();
Collections.sort(repositories, new Comparator<Repository>() {
@Override
public int compare(Repository r1, Repository r2) {
if (r1 == null || r1.getName() == null) {
return 1;
}
if (r2 == null || r2.getName() == null) {
return -1;
}
return r1.getName().compareTo(r2.getName());
}
});
if (repositories.size() > 0) {
for (Repository repository : repositories) {
repositoryBox.addItem(repository);
}
repositoryBox.setEnabled(true);
loginButton.setEnabled(true);
getRootPane().setDefaultButton(loginButton);
} else {
repositoryBox.setEnabled(false);
loginButton.setEnabled(false);
getRootPane().setDefaultButton(loadRepositoryButton);
}
} catch (Exception ex) {
repositoryBox.setEnabled(false);
loginButton.setEnabled(false);
getRootPane().setDefaultButton(loadRepositoryButton);
ClientHelper.showError(getOwner(), ex);
} finally {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
});
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
clientSession.createSession(repositoryBox.getSelectedIndex());
canceled = false;
hideDialog();
} catch (Exception ex) {
repositoryBox.setEnabled(false);
loginButton.setEnabled(false);
getRootPane().setDefaultButton(loadRepositoryButton);
ClientHelper.showError(getOwner(), ex);
} finally {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
getRootPane().setDefaultButton(loadRepositoryButton);
}
}
});
loginTabs.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
expertLogin = (loginTabs.getSelectedComponent() == expertPanel);
if (expertLogin) {
configs.setSelectedIndex(0);
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> parameter : createBasicSessionParameters().entrySet()) {
sb.append(parameter.getKey());
sb.append("=");
sb.append(parameter.getValue());
sb.append("\n");
}
sessionParameterTextArea.setText(sb.toString());
sessionParameterTextArea.setCaretPosition(0);
}
}
});
configs.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
FileEntry fe = (FileEntry) e.getItem();
sessionParameterTextArea.setText(ClientHelper.readFileAndRemoveHeader(fe.getFile()));
sessionParameterTextArea.setCaretPosition(0);
}
});
ClientHelper.installEscapeBinding(this, getRootPane(), false);