summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/BwIdmLinkWindow.java
blob: d24378ab1cc144606e3a7cd0cb83f379b6a22886 (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
package org.openslx.dozmod.gui.window;

import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URISyntaxException;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import org.apache.log4j.Logger;
import org.openslx.dozmod.Branding;
import org.openslx.dozmod.authentication.ShibbolethEcp;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.GridManager;
import org.openslx.dozmod.gui.helper.UiFeedback;
import org.openslx.dozmod.util.DesktopEnvironment;

/**
 * Class for showing window with button to open registration page in browser.
 */
@SuppressWarnings("serial")
public class BwIdmLinkWindow extends JDialog implements UiFeedback {
	private static final String title = "Registrierung erforderlich";
	private static final String infoText = "<html><body style='width:100%'>"
			+ "Sie sind nicht bei " + Branding.getServiceName() + " registriert. "
			+ "Bitte rufen Sie die angegebene Seite auf um sich zu registrieren und versuchen Sie es erneut."
			+ "</body></html>";

	protected JButton btnLink;
	protected JButton OkButton;

	private static final Logger LOGGER = Logger.getLogger(BwIdmLinkWindow.class);

	/**
	 * Don't use this, use static function open instead!
	 */
	public BwIdmLinkWindow(Frame modalParent) {
		super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL
				: ModalityType.MODELESS);

		final BwIdmLinkWindow me = this;
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

		// panel for the border.
		JPanel contentPanel = new JPanel();
		contentPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
		add(contentPanel);
		GridManager grid = new GridManager(contentPanel, 1);

		// infotext
		JLabel infoLabel = new JLabel(infoText);
		infoLabel.setBorder(BorderFactory.createTitledBorder("Hinweis"));
		grid.add(infoLabel).fill(true, true).expand(true, true).anchor(GridBagConstraints.CENTER);
		grid.nextRow();

		// button for opening the link
		btnLink = new JButton("Seite im Browser öffnen");
		btnLink.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				try {
					DesktopEnvironment.openWebpageUri(ShibbolethEcp.getRegistrationUrl().toURI());
				} catch (URISyntaxException e1) {
					LOGGER.error("Could not convert from url to uri: ", e1);
				}
			}
		});

		grid.add(btnLink).anchor(GridBagConstraints.CENTER).fill(false, false).expand(false, false);
		grid.nextRow();

		// text area for copying the link if needed.
		JTextArea linkText = new JTextArea(ShibbolethEcp.getRegistrationUrl().toString());
		linkText.setEditable(false);
		linkText.setMaximumSize(linkText.getPreferredSize());
		linkText.setMinimumSize(linkText.getPreferredSize());
		grid.add(linkText).anchor(GridBagConstraints.CENTER).fill(false, false).expand(false, false);
		grid.nextRow();

		// Ok button on the bottom
		JPanel bottomPane = new JPanel();
		bottomPane.setLayout(new BoxLayout(bottomPane, BoxLayout.LINE_AXIS));
		bottomPane.add(Box.createHorizontalGlue());

		// close/ok button
		OkButton = new JButton("Schließen");
		OkButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				me.dispose();
			}
		});
		bottomPane.add(OkButton);

		grid.add(bottomPane).fill(true, false).expand(true, false);
		grid.nextRow();
		grid.finish(false);

		// Scale window with font
		setMinimumSize(Gui.getScaledDimension(500, 200));
		setPreferredSize(getMinimumSize());
		setLocationRelativeTo(modalParent);
	}

	/**
	 * Open a new window for showing the registration page in browser.
	 * 
	 * @param modalParent the parent of the window.
	 */
	public static void open(Frame modalParent) {
		new BwIdmLinkWindow(modalParent).setVisible(true);
	}

	@Override
	public boolean wantConfirmQuit() {
		return false;
	}

	@Override
	public void escapePressed() {
		dispose();
	}
}