final DefaultStringOption servernameOption = (DefaultStringOption) ftpGroup.getOption(DocumentCreator.SERVERNAME_OPTION_ID);
final DefaultStringOption dirnameOption = (DefaultStringOption) ftpGroup.getOption(DocumentCreator.DIRECTORYNAME_OPTION_ID);
final DefaultStringOption passwordOption = (DefaultStringOption) ftpGroup.getOption(DocumentCreator.PASSWORD_OPTION_ID);
final JComponent optionsPane = builder.buildPage(project.getDocumentManager().getNetworkOptionGroups(), getPageID());
final Action testConnectionAction = new AbstractAction() {
{
putValue(Action.NAME, GanttLanguage.getInstance().getText("testFTPConnection"));
setEnabled(canEnableTestAction(ftpGroup));
}
public void actionPerformed(ActionEvent e) {
StringBuffer urlString = new StringBuffer();
urlString.append("ftp://");
urlString.append(usernameOption.getUncommitedValue()==null ? "":usernameOption.getUncommitedValue());
urlString.append(passwordOption.getUncommitedValue()==null ? "" : ":"+passwordOption.getUncommitedValue());
urlString.append("@");
urlString.append(servernameOption.getUncommitedValue());
urlString.append("/");
urlString.append(dirnameOption.getUncommitedValue());
urlString.append("/");
URL url = null;
try {
url = new URL(urlString.toString() + "test.txt");
URLConnection urlc = url.openConnection();
OutputStream os = urlc.getOutputStream();
os.write(("This is GanttProject +++ I was here!")
.getBytes());
os.close();
JOptionPane.showMessageDialog(optionsPane, GanttLanguage
.getInstance().getText("successFTPConnection"),
GanttLanguage.getInstance().getText("success"),
JOptionPane.INFORMATION_MESSAGE);
} catch (IOException e2) {
uiFacade.showErrorDialog(e2);
// JOptionPane.showMessageDialog(, GanttLanguage
// .getInstance().getText("errorFTPConnection"),
// GanttLanguage.getInstance().getText("error"),
// JOptionPane.ERROR_MESSAGE);
} finally {
}
}
};
ChangeValueListener listener = new ChangeValueListener() {
public void changeValue(ChangeValueEvent event) {
testConnectionAction.setEnabled(canEnableTestAction(ftpGroup));
}
};
servernameOption.addChangeValueListener(listener);
usernameOption.addChangeValueListener(listener);
passwordOption.addChangeValueListener(listener);