summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ContainerUploadPageLayout.java
blob: 171a059ee63d7ff324e6ad1d826a175326e74a8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package org.openslx.dozmod.gui.wizard.layout;

import org.openslx.dozmod.gui.control.QLabel;
import org.openslx.dozmod.gui.helper.GridManager;
import org.openslx.dozmod.gui.helper.I18n;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.WizardPage;
import org.openslx.virtualization.configuration.container.ContainerImageContext;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;

public class ContainerUploadPageLayout extends WizardPage {

	/**
	 * Version for serialization.
	 */
	private static final long serialVersionUID = -6361748362199780290L;

	protected final JTextField txtImageName;
	protected final JButton btnBrowseForImage;
	protected final JTextField txtImageFile;
	protected final QLabel lblImageName;
	protected final JTextArea txtInfoText;

	protected final JTextField txtImageRepo;

	protected final JTabbedPane tpInput;
	protected final JTextField txtGitRepo;

	protected final JTextField txtImageTar;
	protected final JButton btnBrowseImageTar;

	/**
	 * Constructor to define the Layout
	 */
	public ContainerUploadPageLayout(Wizard wizard) {

		super(wizard, I18n.PAGE_LAYOUT.getString("ContainerUploadPage.title"));
		setDescription(I18n.PAGE_LAYOUT.getString("ContainerUploadPage.description"));
		GridManager grid = new GridManager(this, 3, false);
		GridManager tmpGrid;

		// ####################################
		// Dockerfile Input Panel -- UNUSED --
		JPanel pnlDockerfileInput = new ContainerTabPanel(ContainerImageContext.DOCKERFILE);
		pnlDockerfileInput.setVisible(false);
		tmpGrid = new GridManager(pnlDockerfileInput, 3, true, new Insets(0, 5, 0, 5));
		QLabel imageFileCaption = new QLabel(
				I18n.PAGE_LAYOUT.getString("ContainerUploadPage.DockerFile.label"));
		txtImageFile = new JTextField();
		txtImageFile.setEditable(false);
		btnBrowseForImage = new JButton(I18n.PAGE_LAYOUT.getString("ImageUpload.Button.browseForImage.text"));
		btnBrowseForImage.setMnemonic(KeyEvent.VK_B);
		tmpGrid.add(imageFileCaption);
		tmpGrid.add(txtImageFile).fill(true, false).expand(true, false);
		tmpGrid.add(btnBrowseForImage);
		tmpGrid.finish(false);

		// ####################################
		// Git Repository Input Panel -- UNUSED --
		JPanel pnlGitRepositoryInput = new ContainerTabPanel(ContainerImageContext.GIT_REPOSITORY);
		pnlGitRepositoryInput.setVisible(false);
		tmpGrid = new GridManager(pnlGitRepositoryInput, 2, true, new Insets(0, 5, 0, 5));
		QLabel lblGitRepo = new QLabel(I18n.PAGE_LAYOUT.getString("ContainerUploadPage.GitRepository.label"));
		lblGitRepo.setToolTipText(
				I18n.PAGE_LAYOUT.getString("ContainerUploadPage.GitRepository.toolTipText"));
		txtGitRepo = new JTextField();
		txtGitRepo.setToolTipText(
				I18n.PAGE_LAYOUT.getString("ContainerUploadPage.GitRepository.toolTipText"));
		tmpGrid.add(lblGitRepo);
		tmpGrid.add(txtGitRepo).fill(true, false).expand(true, false);
		tmpGrid.finish(false);

		// ####################################
		// Container Archive Input Panel
		JPanel pnlContainerImage = new ContainerTabPanel(ContainerImageContext.DOCKER_ARCHIVE);
		pnlGitRepositoryInput.setVisible(false);
		tmpGrid = new GridManager(pnlContainerImage, 3, true, new Insets(0, 5, 0, 5));

		QLabel lblImageTarFile = new QLabel(
				I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ContainerImageFile.label"));
		lblImageTarFile.setToolTipText(
				I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ContainerImageFile.ToolTipText"));

		txtImageTar = new JTextField();
		txtImageTar.setEnabled(false);
		btnBrowseImageTar = new JButton(I18n.PAGE_LAYOUT.getString("ImageUpload.Button.browseForImage.text"));
		btnBrowseImageTar.setMnemonic(KeyEvent.VK_B);
		tmpGrid.add(lblImageTarFile);
		tmpGrid.add(txtImageTar).fill(true, false).expand(true, false);
		tmpGrid.add(btnBrowseImageTar);
		tmpGrid.finish(false);

		// ####################################
		// Image Repository Input Panel
		JPanel pnlImageRepo = new ContainerTabPanel(ContainerImageContext.IMAGE_REPOSITORY);
		pnlImageRepo.setVisible(true);
		tmpGrid = new GridManager(pnlImageRepo, 2, true, new Insets(0, 5, 0, 5));
		QLabel lblImageRepo = new QLabel(I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ImageRepo.label"));
		lblImageRepo.setToolTipText(
				I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ImageRepository.ToolTipText"));
		txtImageRepo = new JTextField();
		txtImageRepo.setEditable(true);
		txtImageRepo.setToolTipText(
				I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ImageRepository.ToolTipText"));
		tmpGrid.add(lblImageRepo);
		tmpGrid.add(txtImageRepo).fill(true, false).expand(true, false);
		tmpGrid.finish(false);

		// ####################################
		// Tabbed Input Pane
		tpInput = new JTabbedPane();
		// TODO we need first a proper backend in bwlp-sat to build container
		//tpInput.addTab("Dockerfile", pnlDockerfileInput);
		//tpInput.addTab("Git-Repository", pnlGitRepositoryInput);
		tpInput.addTab("Docker-Archive", pnlContainerImage);
		tpInput.addTab("Image-Repository", pnlImageRepo);
		tpInput.setSelectedIndex(0);
		grid.add(tpInput, 3).fill(true, false);
		grid.nextRow();

		// ####################################
		// Image Name
		lblImageName = new QLabel(I18n.PANEL.getString("ContainerPanel.Label.ImageName.text"));
		txtImageName = new JTextField();
		grid.add(lblImageName);
		grid.add(txtImageName, 2, 1).fill(true, false).expand(true, false);
		grid.nextRow();

		// ####################################
		// Info Box
		grid.add(Box.createVerticalGlue(), 3).expand(true, true);
		txtInfoText = new JTextArea();
		txtInfoText.setBorder(BorderFactory.createTitledBorder(
				I18n.PAGE_LAYOUT.getString("ContainerUploadPage.Infobox.label")));
		txtInfoText.setLineWrap(true);
		txtInfoText.setWrapStyleWord(true);
		txtInfoText.setEditable(false);
		txtInfoText.setFocusable(false);
		txtInfoText.setOpaque(false);
		txtInfoText.setText(I18n.PAGE_LAYOUT.getString("ContainerUploadPage.Infobox.text"));

		grid.add(txtInfoText, 3).fill(true, false).expand(true, false);
		grid.nextRow();

		grid.finish(true);
	}

	protected ContainerImageContext getCurrentContext() {
		return ((ContainerTabPanel) tpInput.getSelectedComponent()).containerImageContext;
	}

	static class ContainerTabPanel extends JPanel {
		private static final long serialVersionUID = -2418240236311026868L;
		public final ContainerImageContext containerImageContext;

		ContainerTabPanel(ContainerImageContext imageContext) {
			this.containerImageContext = imageContext;
		}
	}
}