final Uploading uploading = new Uploading();
Util.startNewThread(Configuration.getClassLoader(), new Runnable() {
public void run() {
try {
boolean convertToGoogleDocsFormat = convertCheckBox.isEnabled() && convertCheckBox.isSelected();
OOoFormats currentFormat = getFormatOfDocument();
Creditionals credentionals;
if (wrapper.isServerSelectionNeeded()) {
String serverPath = (String)serversComboBox.getEditor().getItem();
wrapper.setServerPath(serverPath);
credentionals = wrapper.getCreditionalsForServer(serverPath);
} else {
credentionals = loginPanel1.getCreditionals();
}
String docName=getDocumentTitle();
boolean updateInsteadOfCreatingNew = false;
if (getNameFromComboBox) {
Object obj = docNameComboBox.getEditor().getItem();
if (obj instanceof String) {
docName = (String)obj;
} else {
docName = ((Document)obj).getTitle();
updateInsteadOfCreatingNew = true;
}
}
uploading.setVisible(true);
if (credentionals.isEmpty() && wrapper.checkIfAuthorizationNeeded(pathName, docName)) {
uploading.setVisible(false);
// we need ask user for credentials :-)
org.openoffice.gdocs.ui.LoginPanel loginPanel = new LoginPanel() {
@Override
public void storeCredentials(Creditionals creditionals) {
wrapper.storeCredentials(creditionals);
}
};
loginPanel.setSystem(system);
final MyLoginDialog dialog = new MyLoginDialog(UploadDialog.this);
dialog.setTitle("User & Password");
JPanel buttonsPanel = new JPanel();
JButton okButton = new JButton(Configuration.getResources().getString("OK"));
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.handleOK();
}
});
JButton cancelButton = new JButton(Configuration.getResources().getString("Cancel"));
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.handleOK();
}
});
buttonsPanel.add(okButton);
buttonsPanel.add(cancelButton);
dialog.getContentPane().setLayout(new BorderLayout());
dialog.getContentPane().add(loginPanel,BorderLayout.NORTH);
dialog.getContentPane().add(buttonsPanel,BorderLayout.SOUTH);
dialog.setModal(true);
dialog.pack();
dialog.setVisible(true);
dialog.setVisible(false);
if (dialog.getReturnCode()==JOptionPane.OK_OPTION) {
credentionals = loginPanel.getCreditionals();
} else {
upload = false;
}
uploading.setVisible(true);
}
if (credentionals.isEmpty() && wrapper.isServerSelectionNeeded()) {
wrapper.storeCredentials(credentionals);
}
uploading.setVisible(true);
wrapper.login(credentionals);
boolean upload = true;
if (wrapper.neededConversion(currentFormat) && (wrapper.isConversionObligatory() || convertToGoogleDocsFormat)) {
OOoFormats destinationFormat = wrapper.convertTo(currentFormat);
String msg = null;
switch (currentFormat.getHandlerType()) {
case 0: { msg = Configuration.getStringFromResources("NEED_CONVERSION_DOCUMENT", destinationFormat.getFormatName(), destinationFormat.getFileExtension(), system); break; }
case 1: { msg = Configuration.getStringFromResources("NEED_CONVERSION_SPREADSHEET", destinationFormat.getFormatName(), destinationFormat.getFileExtension(), system); break; }
case 2: { msg = Configuration.getStringFromResources("NEED_CONVERSION_PRESENTATION", destinationFormat.getFormatName(), destinationFormat.getFileExtension(), system); break; }
}
int option = JOptionPane.showConfirmDialog(UploadDialog.this,msg,currentFormat.getFormatName()+" -> "+destinationFormat.getFormatName(),JOptionPane.YES_NO_OPTION);
if (option == JOptionPane.YES_OPTION) {
pathName=Util.convertDocumentToFormat(pathName, currentFormat, destinationFormat, xFrame);
currentFormat = destinationFormat;
upload = true;
} else {
upload = false;
}
}
if (upload) {
final Wrapper.UploadUpdateStatus operationStatus;
String mimeType = null;
if (currentFormat!=null) {
mimeType = currentFormat.getMimeType();
}
if (updateInsteadOfCreatingNew) {
Document docToUpdate = ((Document)docNameComboBox.getSelectedItem());
operationStatus = wrapper.update(pathName, docToUpdate.getDocumentLink(), mimeType);
} else {
operationStatus = wrapper.upload(pathName,docName,mimeType,convertToGoogleDocsFormat);
}
boolean success = false;
if (operationStatus!=null) {
success = operationStatus.success();
}
if (success) {
String successMsg = "File Uploaded";
if (updateInsteadOfCreatingNew) {
successMsg = "File Updated";
}
final String msg = successMsg;
final OOoFormats docFormat = currentFormat;
new Thread(new Runnable() {
public void run() {
Uploading up = new Uploading();
up.setMessage(msg);
up.hideProgressBar();