summaryrefslogblamecommitdiffstats
path: root/dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java
blob: e656a7119b08ad5c75a07fd8bcf3fc178a6efd9e (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                  


                             
                          


                            

                                     

                                   




                                         

                                   


                                  
 





                                
                             
                               







                                                   
                                                       
 
                    
                    
                               
                          
                     
 
                               
                                    
 
                                      
                               
                      
                     
                      
                           
                               
 
                           

                                                            
 


                                          


                                                                
 


                                                         
 
                       
                                 
                                                            
                      
                                   
                             
                        
                               
                        




                              
                        


                       
                                

                                                            
                                                         
                                                                            
                                                  
                                                                   
                                               

                                                                                                       
                           
                                                                                  
                            






                                                                                                                                      
 

 
 


                            
                                                           


                                                                    
                                                       
 

                                                                     
 
                                                      


                                                                          
                                                                          




















                                                                                                                                                              
                                              

                                    
                





                                                                                               
                                                        

                                                                                                 

                 
                                 
                                           


                                                                       

                                          

                                                 
 





                                                                        
                                                                                         

                                                                                       
 
                                                                                          

                                                                                                     
                                                                 
                                                                                         
 
                                                                       
                                                                         
                                                                                 
                                                           
                                                                

                                                                                
                                                                                        
                                                
                                                                   
                                                                    
                                                  


                                 
                                                                            
                                                                                        

                                                                 
                                         
                                                            
 
                                                                                
                                                                              

                                                                                          
                                                                                    
                                                                           


                                                                                
                                                                          
                                                                                   


                                 


                                                                    
 
                                                   
 
                                                                         

                                                                       
 


                         
                                                              
                                                   

                                                       

                                                   
                                                         
                                              
 
                                                                                       
                                                                      
                                                           
 
                                                       
                                                    
                                          
 



                                                                      
 



                                                                       
 
                                                    
                                                    
                                          
 



                                                                        
 
                                                            
                                                    
                                          
 

                                                                  

                                                                          
 



                                                                    
 



                                                                           
 




                                                      
 
                                                                               


                                                                               
 
                                                              
                                 
                                                                                                                                     



                                                                  
 


                                                        
 
                                                                


                                                        
 


                                                  
 
                                                        


                                                     
 


                                                   
 
                                                            
                                                             
                                                   
 


                                                          
 


                                                               
 


                                                               
 


                                                               


                                                                      
                                                             
                                                   



                                                                         

                                                             








                                                                            

                                                




                                                   
                                                              
                                                   





                                                                                          

                                                                                  
                                                                                    











                                                                                                                                         


                                                                                     

                                                                                                         
                                                                                               
                                                                                             

                                                                                                  
                                                 
                                                
                                                                     
                                                               
                                                          
                                                                                       
                                                                   
                                                


                                                                                                    
 


                                                                                                  
                                                                                              
                                                                                  



                                                                                                                     

                                                                          
                                                 



                                         

                                                                                    



                                                                                          
                                                                                          















                                                                                                                                                               

                                                                                                                               


                                                                         
                                                        


                                                                                           
                                                                                          



                                                                                                                                                                                                                                                                                                 



                                                                                                                                         
                                                                                   
                                                                          
                                                                

                                                                                                        
                                                         
                                                        
 

                                                            


                                                                    

                                                                     

                         
 

                                                  
 

                                                
 


                                                              
                                                                   
                                                                    


                                                                          
                                                                       



                                                                          

                         
 
                                   
 


                                                                
                                                                   
                                                                 


                                                                           
                                                                  



                                                                          


                                     
 







                                                                    
                                 




                                                                    
                                                                                                                                               


                                            
                







                                                          
                         
         

                                                                     
 
                                  
                                        
                                                                                      
                                                         

                     
                                                           
                                                   


                                                                   

                                                          
                                                                                      
                                            
                                                        

                                                                                        
                 
                                                                             
 

                                                                                     





                                                                               
                                                          
 
                                                                               
                                                                 




                                                     
         

                                                              
 




                                                                        
 
                         
 

                                                                                         
                                                                                                       
                                            
                                                                         






                                                                   
 


                                                                    
 
                                                                               
                                                           
 
















                                                                                                                                                      
 



                                                                                      
 
                         

                                             



                                    
                        
                                                                      
                                                              
                                                                              




                                                                                
                                                                               







                                                                          

                                                            
 
                                                                       
 
                                                     




                                                                                


                                                                         


                                                                                                                                                                                                                                                        
                                                                  
                                                     
                                                                                                                            



                                                                                                                                     
                                                  









                                                                                                                                                              



                                  


                                                          
                                                        

                                                                                                 


                                     
 




                                             

                                                                          







                                                   







                                            

                                    



                                                           

                            
            
package gui.image;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JSeparator;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.FileNameExtensionFilter;

import models.Image;
import models.Links;
import models.RightsManagement;
import models.SessionData;
import models.person;

import org.apache.log4j.Logger;
import org.apache.thrift.TException;

import server.generated.Server.Client;
import thrift.ThriftConnection;
import util.OpenLinks;
import config.Config;
import ftp.UploadTask;
import gui.intro.About_GUI;
import gui.intro.MainMenue_GUI;

@SuppressWarnings("serial")
public class FTPCreateUploader_GUI extends JFrame implements
		PropertyChangeListener {

	/**
	 * Logger instance for this class.
	 */
	private final static Logger LOGGER = Logger
			.getLogger(FTPCreateUploader_GUI.class);


	@SuppressWarnings("unused")
	private JPanel contentPane;
	private final JPanel contentPanel = new JPanel();

	JLabel lblPath;
	JProgressBar progressBar;
	String host = SessionData.session.getServerAdress();
	int port = 21;
	server.generated.User user;
	String filename = "";
	File uploadFile;
	static String arg = "";
	UploadTask task;
	JLabel lblUpSpeed;
	JLabel lblFertig;
	JLabel lblFilesize;
	JLabel lblZeit;
	JLabel lblVerbleibend;
	JFileChooser fc;
	long filesize;
	double speed;
	long bytesread;
	boolean taskrun = false;
	ThriftConnection con = new ThriftConnection();
	Client client = models.Client.clientcon.getClient();
	JButton btnFinish = new JButton("Fertigstellen");
	JButton btnUploadStarten = new JButton("Upload auf Server starten");
	JButton btnZurck = new JButton("Zurück");
	JButton btnUploadStoppen = new JButton("Upload abbrechen");
	int progress = 0; // progress of upload
	private boolean isCurrentlyLoading = false; // currently up or downloading
												// file
	Component c = null;
	private boolean isAborted = false; //down- or upload was manually aborted 
	private String uuid;
	
	private static final String HELP_MESSAGE =	"<html><div align = \"center\">" +
		   	"Laden Sie hier Ihre .vmdk-Datei hoch, die dann als virtuelles Labor geladen werden kann.<br />" +
		   	"Wichtig ist, dass Sie zum Schluss auf \"Fertigstellen\" klicken, damit die Daten übernommen werden.<br />" +
		   	"Wenn Sie die Datei hochgeladen haben, dann aber auf \"zurück\" klicken, oder die Anwendung beenden,<br />" +
		   	"werden die Daten NICHT übernommen und auch die .vmdk-Datei wird nicht aktiv geschaltet." +
		   	"</div></html>";




	/**
	 * Create the frame.
	 */
	public FTPCreateUploader_GUI(Component formerGUI) {

		final Object[] options = { "Beenden", "Abbrechen" };

		addWindowListener(new WindowAdapter() {

			@Override
			public void windowClosing(WindowEvent arg0) {

				if (taskrun == true) {
					// check if user wants to quit.
					int choice = JOptionPane
							.showOptionDialog(
									c,
									"Aktuell ist ein Upload aktiv. Wollen Sie diesen Abbrechen und das Programm beenden?",
									"Upload aktiv",
									JOptionPane.YES_NO_CANCEL_OPTION,
									JOptionPane.QUESTION_MESSAGE, null,
									options, options[1]);
					// 0=beenden, 1=abbrechen
					if (choice == 0) {
						try {
							client.DeleteFtpUser(user.userName);
						} catch (TException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						task.cancel(true);
						con.closeThriftConnection();
						System.exit(0);
					}// end if choice
				} else {
					// no upload running, close window
					System.exit(0);
				}// end if taskrun
			}// end window closing
		});
		setResizable(false);
		
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException | InstantiationException
				| IllegalAccessException | UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			JOptionPane.showMessageDialog(c,
					e.getCause() + "\n" + e.getStackTrace(), "Debug-Message",
					JOptionPane.ERROR_MESSAGE);
		}

		// filename=name;
		setBackground(Color.WHITE);
		setTitle("Dozentenmodul - Image erzeugen");
		// Aktion die beim Schliessen durchgefuehrt werden soll
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

		setBounds(0, 0, 603, 722);
		setLocationRelativeTo(formerGUI);
		

		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBackground(SystemColor.menu);
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			JButton btnSpeicherortAuswhlen = new JButton("Image auswählen");
			btnSpeicherortAuswhlen.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {

					fc = new JFileChooser(Config.getLastUploadPath());
					FileNameExtensionFilter filter = new FileNameExtensionFilter(
							"VMDK-Container", "vmdk");
					fc.setFileFilter(filter);
					fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

					fc.showOpenDialog(getParent());
					File file = fc.getSelectedFile();
					// check if a file is selected and exists
					if (file != null) {
						// file selected
						uploadFile = file;
						filename = uploadFile.getName();
						lblPath.setText(file.getAbsolutePath());
					} else {
						// no file selected
						lblPath.setText("");
					}// end if
				}
			});

			btnSpeicherortAuswhlen.setBounds(102, 124, 173, 23);
			btnSpeicherortAuswhlen.setVerticalAlignment(SwingConstants.TOP);
			contentPanel.add(btnSpeicherortAuswhlen);
		}
		lblPath = new JLabel("");
		lblPath.setText(Config.getLastUploadPath());

		lblPath.addPropertyChangeListener(new PropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent arg0) {
				if (lblPath.getText() == null
						|| !lblPath.getText().endsWith(".vmdk")) {
					// Keine Auswahl oder Auswahl ist keine vmdk
					btnUploadStarten.setEnabled(false);
					btnUploadStarten.setText("Kein Image!");
				} else {
					// ok, enable it
					btnUploadStarten.setEnabled(true);
					btnUploadStarten.setText("Upload starten");
				}
			}
		});
		lblPath.setHorizontalAlignment(SwingConstants.LEFT);
		lblPath.setBounds(102, 158, 485, 23);
		contentPanel.add(lblPath);

		btnUploadStarten.setEnabled(false);

		btnUploadStarten.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				buttonUploadActionPerformed(arg0);

			}
		});

		btnUploadStarten.setBounds(102, 200, 173, 23);
		contentPanel.add(btnUploadStarten);

		progressBar = new JProgressBar(0, 100);
		progressBar.setStringPainted(true);

		progressBar.setBounds(102, 234, 485, 30);
		contentPanel.add(progressBar);

		JLabel lblUploadgeschwindigkeit = new JLabel("Uploadgeschwindigkeit:");
		lblUploadgeschwindigkeit.setBounds(102, 275, 141, 14);
		contentPanel.add(lblUploadgeschwindigkeit);

		JLabel label_1 = new JLabel("Fertig:");
		label_1.setBounds(102, 325, 46, 14);
		contentPanel.add(label_1);

		lblFertig = new JLabel("0");
		lblFertig.setHorizontalAlignment(SwingConstants.LEFT);
		lblFertig.setBounds(183, 325, 108, 14);
		contentPanel.add(lblFertig);

		lblUpSpeed = new JLabel("0");
		lblUpSpeed.setHorizontalAlignment(SwingConstants.LEFT);
		lblUpSpeed.setBounds(374, 275, 117, 14);
		contentPanel.add(lblUpSpeed);

		JLabel label_4 = new JLabel("von:");
		label_4.setBounds(318, 325, 46, 14);
		contentPanel.add(label_4);

		lblFilesize = new JLabel("0");
		lblFilesize.setHorizontalAlignment(SwingConstants.LEFT);
		lblFilesize.setBounds(374, 325, 117, 14);
		contentPanel.add(lblFilesize);

		JLabel label_6 = new JLabel("Verbleibend:");
		label_6.setBounds(102, 350, 71, 14);
		contentPanel.add(label_6);

		JLabel lblGeschtzteVerbleibendeZeit = new JLabel(
				"Geschätzte verbleibende Zeit:");
		lblGeschtzteVerbleibendeZeit.setBounds(102, 300, 150, 14);
		contentPanel.add(lblGeschtzteVerbleibendeZeit);

		lblZeit = new JLabel("0");
		lblZeit.setHorizontalAlignment(SwingConstants.LEFT);
		lblZeit.setBounds(374, 300, 117, 14);
		contentPanel.add(lblZeit);

		lblVerbleibend = new JLabel("0");
		lblVerbleibend.setHorizontalAlignment(SwingConstants.LEFT);
		lblVerbleibend.setBounds(183, 350, 108, 14);
		contentPanel.add(lblVerbleibend);

		JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBackground(SystemColor.menu);
		panel.setBounds(10, 11, 577, 57);
		contentPanel.add(panel);

		JLabel lblUploadIhresImage = new JLabel("Upload Ihres Images");
		lblUploadIhresImage.setFont(new Font("Tahoma", Font.BOLD, 18));
		lblUploadIhresImage.setBounds(10, 11, 509, 22);
		panel.add(lblUploadIhresImage);

		JTextPane txtpnFhreSieBitte = new JTextPane();
		txtpnFhreSieBitte
				.setText("Führen Sie bitte die folgenden 3 Schritte aus um Ihr Image auf unseren Server zu laden.");
		txtpnFhreSieBitte.setEditable(false);
		txtpnFhreSieBitte.setBackground(SystemColor.menu);
		txtpnFhreSieBitte.setBounds(10, 36, 509, 32);
		panel.add(txtpnFhreSieBitte);

		JSeparator separator = new JSeparator();
		separator.setBounds(0, 79, 597, 2);
		contentPanel.add(separator);

		JLabel lblNewLabel_1 = new JLabel("Hauptmenü");
		lblNewLabel_1.setForeground(Color.BLUE);
		lblNewLabel_1.setBounds(20, 88, 61, 20);
		contentPanel.add(lblNewLabel_1);

		JLabel label_3 = new JLabel(">");
		label_3.setBounds(80, 91, 14, 14);
		contentPanel.add(label_3);

		JLabel lblVlimage = new JLabel("Image");
		lblVlimage.setForeground(Color.BLUE);
		lblVlimage.setBounds(91, 88, 46, 20);
		contentPanel.add(lblVlimage);

		JLabel label_5 = new JLabel(">");
		label_5.setBounds(139, 91, 14, 14);
		contentPanel.add(label_5);

		JLabel lblNeubearbeiten = new JLabel("Neu");
		lblNeubearbeiten.setBounds(149, 91, 155, 14);
		contentPanel.add(lblNeubearbeiten);

		JSeparator separator_1 = new JSeparator();
		separator_1.setBounds(0, 627, 597, 2);
		contentPanel.add(separator_1);

		JLabel lblSchritt_1 = new JLabel("Schritt 1:");
		lblSchritt_1.setBounds(24, 128, 57, 14);
		contentPanel.add(lblSchritt_1);

		JLabel lblSchritt_2 = new JLabel("Schritt 2:");
		lblSchritt_2.setBounds(24, 204, 57, 14);
		contentPanel.add(lblSchritt_2);

		JLabel lblSchritt_3 = new JLabel("Schritt 3:");
		lblSchritt_3.setBounds(20, 423, 57, 14);
		contentPanel.add(lblSchritt_3);

		JLabel lblKlickenSieAuf = new JLabel(
				"Klicken Sie auf \"Fertigstellen\".");
		lblKlickenSieAuf.setBounds(98, 423, 241, 14);
		contentPanel.add(lblKlickenSieAuf);

		btnUploadStoppen = new JButton("Upload abbrechen");
		btnUploadStoppen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				isAborted = true; // set flag
				try {
					client.DeleteFtpUser(user.userName);
					LOGGER.info("Deleted FTP user.");
				} catch (TException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				task.cancel(true);
				resetValues();

				// reset buttons
				resetButtons();

			}
		});
		btnUploadStoppen.setEnabled(false);
		btnUploadStoppen.setBounds(307, 200, 173, 23);
		contentPanel.add(btnUploadStoppen);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setBackground(UIManager.getColor("Button.background"));
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				btnFinish.setEnabled(false);
				btnFinish.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						
						//save data
						boolean success = writeData();
						if(success==true){
							JOptionPane.showMessageDialog(c,
									"Die Daten wurden erfolgreich gespeichert.", "Daten gespeichert",
									JOptionPane.INFORMATION_MESSAGE);
						} else {
							JOptionPane.showMessageDialog(c,
									"Die Daten konnten nicht gespeichert werden.", "Fehler",
									JOptionPane.ERROR_MESSAGE);
						}

						File f = new File(lblPath.getText());
						if (f.isDirectory()) {
							// shouldn't be a directory, but let's check that
							// case anyway
							Config.setLastUploadPath(f.toString());
						} else if (f.getParentFile().isDirectory()) {
							Config.setLastUploadPath(f.getParentFile()
									.toString());
						}
						
						// save configuration
						Config.store();
						dispose();
						MainMenue_GUI m = new MainMenue_GUI(c);
						m.setVisible(true);
						
						if (taskrun == true) {
							try {
								client.DeleteFtpUser(user.userName);

							} catch (TException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
								JOptionPane.showMessageDialog(
										c,
										e1.getCause() + "\n"
												+ e1.getStackTrace(),
										"Debug-Message",
										JOptionPane.ERROR_MESSAGE);
							}
							task.cancel(true);
						}

					}
				});

				btnZurck.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						// check if loading file or not
						if (isCurrentlyLoading() == true) {
							int choice = JOptionPane
									.showOptionDialog(
											c,
											"Nicht abgeschlossene Uploads werden beendet. Trotzdem zurück gehen?",
											"Warnung",
											JOptionPane.YES_NO_CANCEL_OPTION,
											JOptionPane.QUESTION_MESSAGE, null,
											options, options[1]);
							// 0=beenden, 1=abbrechen
							if (choice == 0) {
								try {
									client.DeleteFtpUser(user.userName);
								} catch (TException e1) {
									// TODO Auto-generated catch block
									e1.printStackTrace();
								}
								task.cancel(true);
								// not loading files, go back one page
								dispose();
								PermissionCreateImage_GUI m = new PermissionCreateImage_GUI(c);
								//m.setVisible(true);

							}// end if choice
						} else {
							

							int selectedOption = JOptionPane
									.showConfirmDialog(
											c,
											"<html>Achtung: Alle Änderungen gehen verloren!<br />Klicken Sie auf fertigstellen, wenn Sie die Änderungen dauerhaft speichern möchten.<br /><br />Möchten Sie jetzt abbrechen und zurück?</html>",
											"Abbrechen und zurück",
											JOptionPane.YES_NO_OPTION);
							if (selectedOption == JOptionPane.YES_OPTION) {
								//System.out.println("CreateUploader X:"+formerGUI.getLocation().getX());
								//System.out.println("CreateUploader X:"+formerGUI.getLocation().getY());
								PermissionCreateImage_GUI m = new PermissionCreateImage_GUI(c);
								//m.setLocationRelativeTo(formerGUI);
								m.setVisible(true);
								dispose();
								
							} else {
								// for actions if "no" is selected. tbd.
							}
							

						}// end else
					}// end action
				});
				btnZurck.setActionCommand("Cancel");
				buttonPane.add(btnZurck);
				btnFinish.setActionCommand("Cancel");
				buttonPane.add(btnFinish);
			}
		}

		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu menu = new JMenu("Hilfe");
		menuBar.add(menu);

		JMenuItem menuItem = new JMenuItem("FAQ");
		menuItem.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				// OpenLinks open = new OpenLinks();
				URI windows;
				try {
					windows = new URI(Links.getFAQ());
					OpenLinks.openWebpage(windows);
				} catch (URISyntaxException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});

		menu.add(menuItem);

		JMenuItem menuItem_1 = new JMenuItem("OTRS");
		menuItem_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				OpenLinks open = new OpenLinks();
				URI windows;
				try {
					windows = new URI(Links.getOTRS());
					open.openWebpage(windows);
				} catch (URISyntaxException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		menu.add(menuItem_1);

		JMenuItem mntmAbout = new JMenuItem("About");
		mntmAbout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				About_GUI ab = new About_GUI();
				ab.setVisible(true);
			}
		});
		menu.add(mntmAbout);
		setVisible(true);
		
		JMenu mnNewMenu_Info = new JMenu("Info");
		mnNewMenu_Info.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				JOptionPane.showMessageDialog(c, HELP_MESSAGE, "Hilfe zu dieser Oberfläche", JOptionPane.INFORMATION_MESSAGE);
			}
		});
		menuBar.add(mnNewMenu_Info);
		
		try 
		{
			uuid = client.createRandomUUID(); 
		} catch (TException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		c = this;
	}

	private void buttonUploadActionPerformed(ActionEvent event) {

		isAborted = false;
		progressBar.setValue(0);
		btnUploadStarten.setEnabled(false); // verhindert einen weiteren klick
		btnUploadStarten.setText("Bitte warten");

		try {
			LOGGER.info("Getting FTP User...");
			user = client.getFtpUser();
			LOGGER.debug("FTP name: " + user.userName);
			LOGGER.debug("FTP path: " + user.path);
			LOGGER.debug("FTP pass: " + user.password);
		} catch (TException e) {
			// TODO Auto-generated catch block
			LOGGER.error("Konnte vom Satellit keinen FTP-User erhalten!");
			e.printStackTrace();
			JOptionPane.showMessageDialog(c,
					"Konnte vom Satellit keinen FTP-User erhalten!",
					"Debug-Message", JOptionPane.ERROR_MESSAGE);
		}
		DateFormat formatter = new SimpleDateFormat("yyyMMddHHmmss");

		LOGGER.info("Setting new name: " + formatter.format(new Date()) + "_"
				+ person.verantwortlicher.getHochschule() + "_"
				+ person.verantwortlicher.getUsername() + "_"
				+ Image.image.getImagename() + ".vmdk");
		Image.image.setNewName(formatter.format(new Date()) + "_"
				+ person.verantwortlicher.getHochschule() + "_"
				+ person.verantwortlicher.getUsername() + "_"
				+ Image.image.getImagename() + ".vmdk");
		LOGGER.info("Uploading to host: " + host);

		task = new UploadTask(host, port, user.userName, user.password,
				user.path + "temp/", uploadFile);

		task.addPropertyChangeListener(this);
		task.execute();
		taskrun = true;

	}

	public void propertyChange(PropertyChangeEvent arg0) {

		if (isAborted == false) {
			progress = 0;
			if ("progress" == arg0.getPropertyName()) {
				progress = (Integer) arg0.getNewValue();
				progressBar.setValue(progress);

			}

			// Fertigstellen erlauben wenn upload abgeschlossen und abbrechen
			// erlauben wenn kein load aktiv ist
			if (isCurrentlyLoading() == false || progressBar.getPercentComplete() == 1.0) {
				// no upload
				//LOGGER.info("finished uploading file");
				btnUploadStoppen.setEnabled(false);
				btnFinish.setEnabled(true);
			} else {
				// upload
				btnUploadStoppen.setEnabled(true);
				btnFinish.setEnabled(false);
			}

			if ("speed" == arg0.getPropertyName()) {
				speed = (double) arg0.getNewValue();
				// if(speed<=1){

				lblUpSpeed.setText(String.format("%.2f", speed)
						+ " MB/s");

			}
			if ("bytesread" == arg0.getPropertyName()) {
				bytesread = (long) arg0.getNewValue();
				lblFertig.setText((bytesread / 1024 / 1024) + " MB");
				lblVerbleibend
						.setText(((filesize / 1024 / 1024) - (bytesread / 1024 / 1024))
								+ " MB");

				lblZeit.setText(String
						.valueOf(
								((((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60) + 1)
						.substring(
								0,
								String.valueOf(
										(((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60)
										.lastIndexOf("."))
						+ " Minuten");

			}
			if ("filesize" == arg0.getPropertyName()) {
				filesize = (long) arg0.getNewValue();
				lblFilesize.setText((filesize / 1024 / 1024) + " MB");

			}
		} // end if(isAborted==false)
	}// end propertyChange

	public boolean writeData() {

		try {
			
			client.writeVLdata(Image.image.getImagename(),
					Image.image.getDesc(),
					person.verantwortlicher.getUsername(),
					person.verantwortlicher.getVorname(),
					person.verantwortlicher.getName(),
					person.verantwortlicher.getHochschule(),
					person.verantwortlicher.getEMail(),
					person.verantwortlicher.getTel(),
					person.verantwortlicher.getFakultaet(),
					Image.image.isLicensed(), 
					Image.image.isInternet(),
					Image.image.getRam(), 
					Image.image.getCpu(), 
					"temp/"+ Image.image.getNewName(),
					Image.image.isVorlage(), 
					Image.image.getFilesize(),
					Image.image.getShareMode(), 
					Image.image.getOS(),
					uuid);

			client.startFileCopy(Image.image.getNewName());

			client.writeImageRights(uuid,
					person.verantwortlicher.getUsername(),
					person.verantwortlicher.getName(),
					person.verantwortlicher.getVorname(),
					person.verantwortlicher.getEMail(),
					person.verantwortlicher.getHochschule(),
					person.verantwortlicher.getRole()
					);
			
			for(int i=0; i< RightsManagement.rightsManagement.getPermittedUserList().size(); i++)
			{
				//System.out.println("Writing additional rights for user "+RightsManagement.rightsManagement.getPermittedUserList().get(i).getUserID()+", User "+i+"/"+RightsManagement.rightsManagement.getPermittedUserList().size());
				client.writeAdditionalImageRights(
						uuid,
						RightsManagement.rightsManagement.getPermittedUserList().get(i).getUserID(),
						RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageRead(),
						RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageWrite(),
						RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageLinkAllowed(),
						RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageAdmin()
						);
				/*
				LOGGER.info(
						"Name: "+Image.image.getImagename()
						+"\tUserID: "+RightsManagement.rightsManagement.getPermittedUserList().get(i).getUserID()
						+"\tisImageRead: "+RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageRead()
						+"\tisImageWrite: "+RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageWrite()
						+"\tisImageLInkAllowed: "+RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageLinkAllowed()
						+"\tisImageAdmin: "+RightsManagement.rightsManagement.getPermittedUserList().get(i).isImageAdmin()
						);
						*/
			
			}//end for
			
			
		} catch (TException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			JOptionPane.showMessageDialog(c,
					e.getCause() + "\n" + e.getStackTrace(), "Debug-Message",
					JOptionPane.ERROR_MESSAGE);
			return false;
		}
		return true;

	}// end writeData()

	public boolean isCurrentlyLoading() {
		isCurrentlyLoading = false;

		if (lblVerbleibend.getText().equals("0 MB")
				|| lblVerbleibend.getText().equals("0")) {
			isCurrentlyLoading = false;
		} else {
			isCurrentlyLoading = true;
		}

		return isCurrentlyLoading;
	}// end isCurrentlyLoading()

	public void resetValues() {
		lblUpSpeed.setText("0");
		lblZeit.setText("0");
		lblFertig.setText("0");
		lblFilesize.setText("0");
		lblVerbleibend.setText("0");
		progressBar.setValue(0);
	}// end resetValues

	public void resetButtons() {
		btnFinish.setEnabled(false);
		btnUploadStarten.setEnabled(true);
		btnUploadStarten.setText("Upload starten");
		btnUploadStoppen.setEnabled(false);

	}// end resetButtons
}// end class