summaryrefslogtreecommitdiffstats
path: root/Dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java
diff options
context:
space:
mode:
Diffstat (limited to 'Dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java')
-rw-r--r--Dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java278
1 files changed, 195 insertions, 83 deletions
diff --git a/Dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java b/Dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java
index 88457e5a..a9461bb4 100644
--- a/Dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java
+++ b/Dozentenmodul/src/main/java/gui/image/FTPCreateUploader_GUI.java
@@ -14,6 +14,7 @@ import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
+import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.DateFormat;
@@ -43,6 +44,8 @@ import models.SessionData;
import models.person;
import org.apache.thrift.TException;
+import org.ini4j.InvalidFileFormatException;
+import org.ini4j.Wini;
import server.Server.Client;
import thrift.ThriftConnection;
@@ -73,6 +76,7 @@ public class FTPCreateUploader_GUI extends JFrame implements
JLabel labelfilesize;
JLabel labelZeit;
JLabel labelverbleibend;
+ JFileChooser fc;
long filesize;
double speed;
long bytesread;
@@ -83,29 +87,47 @@ public class FTPCreateUploader_GUI extends JFrame implements
JButton btnUploadStarten = new JButton("Upload auf Server starten");
JButton btnZurck = new JButton("Zur\u00FCck");
int progress = 0; // progress of upload
+ private boolean isCurrentlyLoading = false; // currently up or downloading
+ // file
-
/**
* Create the frame.
*/
public FTPCreateUploader_GUI() {
+
+ final Object[] options = { "Beenden", "Abbrechen" };
+
addWindowListener(new WindowAdapter() {
+
@Override
public void windowClosing(WindowEvent arg0) {
+
if (taskrun == true) {
- try {
- client.DeleteFtpUser(user.userName);
- } catch (TException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- JOptionPane.showMessageDialog(null,
- e1.getCause()+"\n"+e1.getMessage(),
- "Debug-Message", JOptionPane.ERROR_MESSAGE);
- }
- task.cancel(true);
- }
- con.closeThriftConnection();
- System.exit(0);
+ // check if user wants to quit.
+ int choice = JOptionPane
+ .showOptionDialog(
+ null,
+ "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);
@@ -117,13 +139,15 @@ public class FTPCreateUploader_GUI extends JFrame implements
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null,
- e.getCause()+"\n"+e.getMessage(),
- "Debug-Message", JOptionPane.ERROR_MESSAGE);
+ e.getCause() + "\n" + e.getStackTrace(), "Debug-Message",
+ JOptionPane.ERROR_MESSAGE);
}
// filename=name;
setBackground(Color.WHITE);
- setTitle("Dozentenmodul *Prototyp* - Image erzeugen");
+ setTitle("Dozentenmodul - Image erzeugen");
+ // Aktion die beim Schliessen durchgefuehrt werden soll
+ setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setBounds(0, 0, 603, 722);
GuiOrganizer.centerGUI(this);
@@ -137,7 +161,22 @@ public class FTPCreateUploader_GUI extends JFrame implements
JButton btnSpeicherortAuswhlen = new JButton("Image ausw\u00E4hlen");
btnSpeicherortAuswhlen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
- JFileChooser fc = new JFileChooser();
+ try {
+ Wini ini = new Wini(
+ new File(
+ "C:\\Users\\"
+ + System.getProperty("user.name")
+ + "\\AppData\\Roaming\\bwLehrpoolSuite\\config.ini"));
+ fc = new JFileChooser(ini.get("main",
+ "Letzter Uploadpfad", String.class));
+ } catch (InvalidFileFormatException e2) {
+ // TODO Auto-generated catch block
+ e2.printStackTrace();
+ } catch (IOException e2) {
+ // TODO Auto-generated catch block
+ e2.printStackTrace();
+ }
+
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.showOpenDialog(getParent());
@@ -159,16 +198,28 @@ public class FTPCreateUploader_GUI extends JFrame implements
btnSpeicherortAuswhlen.setVerticalAlignment(SwingConstants.TOP);
contentPanel.add(btnSpeicherortAuswhlen);
}
-
lblPath = new JLabel("");
+ try {
+ Wini ini = new Wini(new File("C:\\Users\\"
+ + System.getProperty("user.name")
+ + "\\AppData\\Roaming\\bwLehrpoolSuite\\config.ini"));
+ lblPath.setText(ini.get("main", "Letzter Uploadpfad", String.class));
+ } catch (InvalidFileFormatException e2) {
+ // TODO Auto-generated catch block
+ e2.printStackTrace();
+ } catch (IOException e2) {
+ // TODO Auto-generated catch block
+ e2.printStackTrace();
+ }
+
lblPath.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent arg0) {
- if (lblPath.getText().isEmpty()) {
+ if (lblPath.getText() == null) {
// wenn leer, dann upload button nicht freigeben
btnUploadStarten.setEnabled(false);
btnUploadStarten.setText("Bitte warten");
- } else {
- // wenn leer, dann upload button nicht freigeben
+ } else if (lblPath.getText().endsWith(".vmdk")) {
+ // wenn leer, dann upload button freigeben
btnUploadStarten.setEnabled(true);
btnUploadStarten.setText("Upload auf Server starten");
}
@@ -272,7 +323,7 @@ public class FTPCreateUploader_GUI extends JFrame implements
label_3.setBounds(80, 91, 14, 14);
contentPanel.add(label_3);
- JLabel lblVlimage = new JLabel("VL-Image");
+ JLabel lblVlimage = new JLabel("Image");
lblVlimage.setForeground(Color.BLUE);
lblVlimage.setBounds(91, 88, 46, 20);
contentPanel.add(lblVlimage);
@@ -315,19 +366,50 @@ public class FTPCreateUploader_GUI extends JFrame implements
finishButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
writeData();
+ try {
+ Wini ini = new Wini(
+ new File(
+ "C:\\Users\\"
+ + System.getProperty("user.name")
+ + "\\AppData\\Roaming\\bwLehrpoolSuite\\config.ini"));
+
+ // check if path has content, then write to file
+ if (lblPath.getText().contains("\\") == true) {
+ System.out.println("Hole Infos aus Label: "
+ + lblPath.getText());
+ ini.put("main",
+ "Letzter Uploadpfad",
+ lblPath.getText().substring(
+ 0,
+ lblPath.getText().lastIndexOf(
+ "\\")));
+ ini.store();
+ } else {
+ System.out.println("Mache nix");
+ }// end if
+ } catch (InvalidFileFormatException e2) {
+ // TODO Auto-generated catch block
+ e2.printStackTrace();
+ } catch (IOException e2) {
+ // TODO Auto-generated catch block
+ e2.printStackTrace();
+ }
dispose();
MainMenue_GUI m = new MainMenue_GUI();
m.setVisible(true);
if (taskrun == true) {
try {
client.DeleteFtpUser(user.userName);
-
+
} catch (TException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
- JOptionPane.showMessageDialog(null,
- e1.getCause()+"\n"+e1.getMessage(),
- "Debug-Message", JOptionPane.ERROR_MESSAGE);
+ JOptionPane.showMessageDialog(
+ null,
+ e1.getCause() + "\n"
+ + e1.getStackTrace(),
+ "Debug-Message",
+ JOptionPane.ERROR_MESSAGE);
}
task.cancel(true);
}
@@ -337,11 +419,37 @@ public class FTPCreateUploader_GUI extends JFrame implements
btnZurck.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- dispose();
-
- CreateImageTechnisch_GUI m = new CreateImageTechnisch_GUI();
- m.setVisible(true);
- }
+ // check if loading file or not
+ if (isCurrentlyLoading() == true) {
+ int choice = JOptionPane
+ .showOptionDialog(
+ null,
+ "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();
+ m.setVisible(true);
+
+ }// end if choice
+ } else {
+ dispose();
+ PermissionCreateImage_GUI m = new PermissionCreateImage_GUI();
+ m.setVisible(true);
+ }// end else
+ }// end action
});
btnZurck.setActionCommand("Cancel");
buttonPane.add(btnZurck);
@@ -352,55 +460,45 @@ public class FTPCreateUploader_GUI extends JFrame implements
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());
-
open.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) {
@@ -420,32 +518,32 @@ public class FTPCreateUploader_GUI extends JFrame implements
btnUploadStarten.setText("Bitte warten");
try {
- System.out.println("Test");
+ System.out.println("Getting FTP User");
user = client.getFtpUser();
- System.out.println("FTP name" + user.userName);
- System.out.println("FTP path" + user.path);
- System.out.println("FTP pass" + user.password);
+ System.out.println("FTP name: " + user.userName);
+ System.out.println("FTP path: " + user.path);
+ System.out.println("FTP pass: " + user.password);
} catch (TException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null,
- e.getCause()+"\n"+e.getMessage(),
- "Debug-Message", JOptionPane.ERROR_MESSAGE);
+ e.getCause() + "\n" + e.getStackTrace(), "Debug-Message",
+ JOptionPane.ERROR_MESSAGE);
}
DateFormat formatter = new SimpleDateFormat("yyyMMddhhmmss");
- System.out.println(formatter.format(new Date()) + "_"
- + person.verantwortlicher.getHochschule() + "_"
+ System.out.println("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");
- System.out.println("Uploading to host: "+host);
-
+ System.out.println("Uploading to host: " + host);
+
task = new UploadTask(host, port, user.userName, user.password,
- user.path+"temp/", uploadFile);
+ user.path + "temp/", uploadFile);
task.addPropertyChangeListener(this);
task.execute();
@@ -458,28 +556,16 @@ public class FTPCreateUploader_GUI extends JFrame implements
if ("progress" == arg0.getPropertyName()) {
progress = (Integer) arg0.getNewValue();
progressBar.setValue(progress);
-
- // Button zum Fertigstellen freischalten, wenn 100% erreicht sind
- if (progress == 0 || progress == 100) {
- // not uploading currently
- btnZurck.setEnabled(true);
- } else {
- // currently uploading, don't let user interact
- btnZurck.setEnabled(false);
- }
-
- // Fertigstellen erlauben wenn upload abgeschlossen
- if (progress == 100) {
- finishButton.setEnabled(true);
-
- } else {
- finishButton.setEnabled(false);
-
- }
}
-
+ // Fertigstellen erlauben wenn upload abgeschlossen
+ if (isCurrentlyLoading() == false) {
+ // isCurrentlyLoading();
+ finishButton.setEnabled(true);
+ } else {
+ finishButton.setEnabled(false);
+ }
if ("speed" == arg0.getPropertyName()) {
speed = (double) arg0.getNewValue();
@@ -520,8 +606,9 @@ public class FTPCreateUploader_GUI extends JFrame implements
public boolean writeData() {
try {
-
+
client.writeVLdata(Image.image.getImagename(),
+ Image.image.getDesc(),
person.verantwortlicher.getUsername(),
person.verantwortlicher.getVorname(),
person.verantwortlicher.getName(),
@@ -530,18 +617,43 @@ public class FTPCreateUploader_GUI extends JFrame implements
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.getRam(), Image.image.getCpu(), "temp/"
+ + Image.image.getNewName(),
+ Image.image.isVorlage(), Image.image.getFilesize(),
+ Image.image.getShareMode(), Image.image.getOS());
+
client.startFileCopy(Image.image.getNewName());
+
+ client.writeImageRights(Image.image.getImagename(),
+ person.verantwortlicher.getUsername(),
+ person.verantwortlicher.getName(),
+ person.verantwortlicher.getVorname(),
+ person.verantwortlicher.getEMail(),
+ person.verantwortlicher.getHochschule(),
+ person.verantwortlicher.getRole());
} catch (TException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null,
- e.getCause()+"\n"+e.getMessage(),
- "Debug-Message", JOptionPane.ERROR_MESSAGE);
+ e.getCause() + "\n" + e.getStackTrace(), "Debug-Message",
+ JOptionPane.ERROR_MESSAGE);
return false;
}
return true;
- }
-} \ No newline at end of file
+ }// end writeData()
+
+ public boolean isCurrentlyLoading() {
+ isCurrentlyLoading = false;
+
+ if (labelverbleibend.getText().equals("0 MB")
+ || labelverbleibend.getText().equals("0")) {
+ isCurrentlyLoading = false;
+ } else {
+ isCurrentlyLoading = true;
+ }
+
+ return isCurrentlyLoading;
+ }// end isCurrentlyLoading()
+
+}// end class \ No newline at end of file