summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java79
1 files changed, 69 insertions, 10 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java
index ca39f170..e7e7adf5 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java
@@ -28,6 +28,8 @@ import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileFilter;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import java.util.regex.Matcher;
@@ -40,7 +42,6 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
private final Logger LOGGER = Logger.getLogger(ContainerUploadPage.class);
-
private final UploadWizardState state;
private final ImageDetailsRead existingImage;
private final ContainerDefinition containerDefinition;
@@ -122,9 +123,48 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
}
});
+ txtContainerImageFile.addMouseListener(new MouseListener() {
+ @Override public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() >= 2)
+ browseContainerImageFile();
+ }
+
+ @Override public void mousePressed(MouseEvent e) {
+
+ }
+
+ @Override public void mouseReleased(MouseEvent e) {
+
+ }
+
+ @Override public void mouseEntered(MouseEvent e) {
+
+ }
+
+ @Override public void mouseExited(MouseEvent e) {
+
+ }
+ });
+
btnBrowseForImage.requestFocus();
}
+ private void browseContainerImageFile() {
+ QFileChooser fc = new QFileChooser(Config.getUploadPath(), false);
+ fc.setAcceptAllFileFilterUsed(false);
+ fc.addChoosableFileFilter(new ContainerImageFileFiler());
+
+ int action = fc.showOpenDialog(getDialog());
+ File file = fc.getSelectedFile();
+ if (action != JFileChooser.APPROVE_OPTION || file == null) {
+ txtContainerImageFile.setText("");
+ return;
+ }
+
+ txtContainerImageFile.setText(file.getAbsolutePath());
+ LOGGER.info("Tar File selected");
+ }
+
private void browseFile() {
QFileChooser fc = new QFileChooser(Config.getUploadPath(), false);
@@ -149,10 +189,8 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
String imageName = file.getParentFile().getName();
File imageTarFile = new File(file.getParentFile(), imageName.concat(".tar"));
if (imageTarFile.exists()) {
- LOGGER.info("Upload also an created Image");
- state.diskFile = imageTarFile;
- } else {
- state.diskFile = getDummyFile();
+ txtContainerImageFile.setText(imageTarFile.getAbsolutePath());
+ LOGGER.info("Prebuild Container Image found");
}
Config.setUploadPath(file.getParent());
@@ -215,13 +253,20 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
ContainerMeta containerMeta = containerDefinition.getContainerMeta();
containerMeta.setBuildContextMethod(getBuildContextMethod().ordinal());
containerMeta.setImageName(txtImageName.getText());
+
+
+ File containerImageFile = new File(txtContainerImageFile.getText());
+ if (containerImageFile.exists())
+ state.diskFile = containerImageFile;
+ else
+ state.diskFile = getDummyFile();
+
switch (containerDefinition.getBuildContextMethod()) {
case FILE:
containerDefinition.setContainerRecipe(state.descriptionFile);
break;
case GIT_REPOSITORY:
containerMeta.setBuildContextUrl(txtGitRepo.getText());
- state.diskFile = getDummyFile();
state.descriptionFile = getDummyFile();
break;
}
@@ -231,15 +276,14 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
/**
* This function starts the image creation process. It is triggered by the
* "Next" button.
- *
+ * <p>
* Depending on the state, it will first try to get a UUID for the new image by
* calling createImage() of the thrift API. If a UUID is received, it will
* request an upload with requestImageVersionUpload(). If granted, it will
* finally start a thread for the UploadTask.
- *
+ * <p>
* Then a callback to the Gui is executed where we can process the upload state
* and give the user feedback about it.
- *
*/
@Override protected boolean wantNextOrFinish() {
// are we creating a new image? then either:
@@ -285,7 +329,7 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
private static class DockerfileFilter extends FileFilter {
@Override public boolean accept(File f) {
-
+
Pattern p = Pattern.compile("[Dd]ockerfile");
Matcher m = p.matcher(f.getName());
@@ -299,4 +343,19 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
return "Dockerfile";
}
}
+
+ private static class ContainerImageFileFiler extends FileFilter {
+
+ @Override public boolean accept(File f) {
+
+ boolean accept = false;
+ if ((f.isFile() && f.toString().endsWith(".tar")) || f.isDirectory())
+ accept = true;
+ return accept;
+ }
+
+ @Override public String getDescription() {
+ return "Container Image (.tar)";
+ }
+ }
}