parent
2cfb3a6d58
commit
9de8550c11
@ -1,12 +0,0 @@ |
|||||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui; |
|
||||||
|
|
||||||
import com.vaadin.navigator.View; |
|
||||||
|
|
||||||
public interface NamedView extends View { |
|
||||||
/** |
|
||||||
* Navigation view name used for this view. |
|
||||||
* |
|
||||||
* @return view name. |
|
||||||
*/ |
|
||||||
String getViewName(); |
|
||||||
} |
|
||||||
@ -0,0 +1,114 @@ |
|||||||
|
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation; |
||||||
|
|
||||||
|
import java.util.Stack; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import com.vaadin.navigator.Navigator; |
||||||
|
import com.vaadin.ui.Notification; |
||||||
|
import com.vaadin.ui.UI; |
||||||
|
|
||||||
|
import de.kreth.googleconnectors.calendar.CalendarAdapter; |
||||||
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness; |
||||||
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao; |
||||||
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; |
||||||
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PflichtenDao; |
||||||
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier; |
||||||
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.EventDetails; |
||||||
|
|
||||||
|
@Component |
||||||
|
public class ClubhelperNavigation { |
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ClubhelperNavigation.class); |
||||||
|
|
||||||
|
@Autowired |
||||||
|
PersonDao personDao; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
GroupDao groupDao; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
EventBusiness eventBusiness; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
PflichtenDao pflichtenDao; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
SecurityVerifier securityGroupVerifier; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
CalendarAdapter calendarAdapter; |
||||||
|
|
||||||
|
private ClubNavigator navi; |
||||||
|
|
||||||
|
public void configure(UI mainUI) { |
||||||
|
|
||||||
|
navi = new ClubNavigator().init(mainUI); |
||||||
|
|
||||||
|
// Create and register the views
|
||||||
|
MainView mainView = new MainView(personDao, groupDao, eventBusiness, securityGroupVerifier); |
||||||
|
navi.addView("", mainView); |
||||||
|
navi.addView(ClubhelperViews.MainView.name(), mainView); |
||||||
|
navi.addView(ClubhelperViews.LoginUI.name(), new LoginUI(personDao, securityGroupVerifier)); |
||||||
|
navi.addView(ClubhelperViews.PersonEditView.name(), new PersonEditView(groupDao, personDao)); |
||||||
|
navi.addView(ClubhelperViews.EventDetails.name(), |
||||||
|
new EventDetails(personDao, groupDao, eventBusiness, pflichtenDao, calendarAdapter)); |
||||||
|
|
||||||
|
mainUI.getPage().addBrowserWindowResizeListener(ev -> { |
||||||
|
int width = ev.getWidth(); |
||||||
|
int height = ev.getHeight(); |
||||||
|
if (LOGGER.isDebugEnabled()) { |
||||||
|
LOGGER.debug("Changed Window Size: [w={},h={}]", width, height); |
||||||
|
Notification.show("Size Changed", "Changed Window Size: [w=" + width + ",h=" + height + "]", |
||||||
|
Notification.Type.TRAY_NOTIFICATION); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
public void navigateTo(String navigationState) { |
||||||
|
navi.navigateTo(navigationState); |
||||||
|
} |
||||||
|
|
||||||
|
public class ClubNavigator extends Navigator { |
||||||
|
|
||||||
|
private static final long serialVersionUID = -6503600786209888296L; |
||||||
|
private final Stack<ClubhelperViews> navigationViewNames = new Stack<>(); |
||||||
|
|
||||||
|
ClubNavigator init(UI ui) { |
||||||
|
init(ui, null, new SingleComponentContainerViewDisplay(ui)); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void navigateTo(String navigationState) { |
||||||
|
ClubhelperViews byState = ClubhelperViews.byState(navigationState); |
||||||
|
if (navigationViewNames.contains(byState)) { |
||||||
|
int index = navigationViewNames.indexOf(byState); |
||||||
|
LOGGER.warn("Navigating to previously visited View. Removing some history"); |
||||||
|
while (navigationViewNames.size() > index) { |
||||||
|
navigationViewNames.remove(index); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
int width = navi.getUI().getPage().getBrowserWindowWidth(); |
||||||
|
boolean loggedIn = securityGroupVerifier.isLoggedin(); |
||||||
|
if (!loggedIn && width < 1000) { |
||||||
|
navigationViewNames.clear(); |
||||||
|
navigationViewNames.add(ClubhelperViews.MainView); |
||||||
|
super.navigateTo(ClubhelperViews.LoginUI.name()); |
||||||
|
} else { |
||||||
|
navigationViewNames.add(byState); |
||||||
|
super.navigateTo(navigationState); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void back() { |
||||||
|
navigationViewNames.pop(); |
||||||
|
navigateTo(navigationViewNames.pop().name()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation; |
||||||
|
|
||||||
|
public enum ClubhelperViews { |
||||||
|
MainView, EventDetails, PersonEditView, LoginUI; |
||||||
|
|
||||||
|
public static ClubhelperViews byState(String state) { |
||||||
|
for (ClubhelperViews v : values()) { |
||||||
|
if (state.startsWith(v.name())) { |
||||||
|
return v; |
||||||
|
} |
||||||
|
} |
||||||
|
throw new IllegalArgumentException("View not found for state=" + state); |
||||||
|
} |
||||||
|
} |
||||||
@ -1,65 +1,61 @@ |
|||||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui; |
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation; |
||||||
|
|
||||||
import org.slf4j.Logger; |
import org.slf4j.Logger; |
||||||
import org.slf4j.LoggerFactory; |
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
import com.vaadin.navigator.Navigator; |
import com.vaadin.navigator.Navigator; |
||||||
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; |
import com.vaadin.navigator.View; |
||||||
import com.vaadin.ui.Alignment; |
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; |
||||||
import com.vaadin.ui.LoginForm; |
import com.vaadin.ui.Alignment; |
||||||
import com.vaadin.ui.Notification; |
import com.vaadin.ui.LoginForm; |
||||||
import com.vaadin.ui.VerticalLayout; |
import com.vaadin.ui.Notification; |
||||||
|
import com.vaadin.ui.VerticalLayout; |
||||||
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; |
|
||||||
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; |
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; |
||||||
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier; |
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; |
||||||
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier; |
||||||
public class LoginUI extends VerticalLayout implements NamedView { |
|
||||||
|
public class LoginUI extends VerticalLayout implements View { |
||||||
public static final String VIEW_NAME = "LoginUI"; |
|
||||||
private static final long serialVersionUID = 4339018452507960084L; |
private static final long serialVersionUID = 4339018452507960084L; |
||||||
private final Logger logger = LoggerFactory.getLogger(getClass()); |
private final Logger logger = LoggerFactory.getLogger(getClass()); |
||||||
|
|
||||||
private Navigator navigator; |
private Navigator navigator; |
||||||
private String parameters; |
private String parameters; |
||||||
|
|
||||||
public LoginUI(PersonDao personDao, SecurityVerifier securityGroupVerifier) { |
public LoginUI(PersonDao personDao, SecurityVerifier securityGroupVerifier) { |
||||||
|
|
||||||
LoginForm lf = new LoginForm(); |
LoginForm lf = new LoginForm(); |
||||||
lf.addLoginListener(e -> { |
lf.addLoginListener(e -> { |
||||||
|
|
||||||
String username = e.getLoginParameter("username"); |
String username = e.getLoginParameter("username"); |
||||||
String password = e.getLoginParameter("password"); |
String password = e.getLoginParameter("password"); |
||||||
|
|
||||||
try { |
try { |
||||||
Person loggedin = personDao.findLoginUser(username, password); |
Person loggedin = personDao.findLoginUser(username, password); |
||||||
securityGroupVerifier.setLoggedinPerson(loggedin); |
securityGroupVerifier.setLoggedinPerson(loggedin); |
||||||
navigator.navigateTo(MainView.VIEW_NAME + '/' + parameters); |
navigator.navigateTo(ClubhelperViews.MainView.name() + '/' + parameters); |
||||||
} catch (final Exception ex) { |
} catch (final Exception ex) { |
||||||
ex.printStackTrace(); |
ex.printStackTrace(); |
||||||
logger.error("Error on login for User={}", e.getLoginParameter("username"), ex); |
logger.error("Error on login for User={}", e.getLoginParameter("username"), ex); |
||||||
String message = "Incorrect user or password for " + e.getLoginParameter("username") + "\n" |
String message = "Incorrect user or password for " + e.getLoginParameter("username") + "\n" |
||||||
+ ex.getMessage(); |
+ ex.getMessage(); |
||||||
Notification.show(message, Notification.Type.ERROR_MESSAGE); |
Notification.show(message, Notification.Type.ERROR_MESSAGE); |
||||||
} |
} |
||||||
}); |
}); |
||||||
addComponent(lf); |
addComponent(lf); |
||||||
setComponentAlignment(lf, Alignment.MIDDLE_CENTER); |
setComponentAlignment(lf, Alignment.MIDDLE_CENTER); |
||||||
setSizeFull(); |
setSizeFull(); |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public void enter(ViewChangeEvent event) { |
public void enter(ViewChangeEvent event) { |
||||||
navigator = event.getNavigator(); |
navigator = event.getNavigator(); |
||||||
parameters = event.getParameters(); |
parameters = event.getParameters(); |
||||||
if (parameters == null) { |
if (parameters == null) { |
||||||
parameters = ""; |
parameters = ""; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
@Override |
} |
||||||
public String getViewName() { |
|
||||||
return VIEW_NAME; |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue