Implemented UI improvements and overall fixes of minor issues.

Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/089e9512
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/089e9512
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/089e9512

Branch: refs/heads/master
Commit: 089e951265c99270fc07506bf28dbca142890b93
Parents: dff68de
Author: anatole <anat...@apache.org>
Authored: Fri Jun 3 23:16:19 2016 +0200
Committer: anatole <anat...@apache.org>
Committed: Tue Aug 16 15:51:30 2016 +0200

----------------------------------------------------------------------
 .../org/apache/tamaya/ui/ApplicationLayout.java | 52 ++++++--------------
 .../main/java/org/apache/tamaya/ui/Content.java | 34 -------------
 .../main/java/org/apache/tamaya/ui/NavBar.java  | 47 +++++++++++++-----
 .../java/org/apache/tamaya/ui/UIConstants.java  |  1 +
 .../java/org/apache/tamaya/ui/VadiinApp.java    | 21 +++++---
 .../java/org/apache/tamaya/ui/ViewProvider.java |  9 +++-
 .../tamaya/ui/components/LazyProvider.java      | 49 ++++++++++++++----
 .../org/apache/tamaya/ui/views/ConfigView.java  |  8 ++-
 .../org/apache/tamaya/ui/views/HomeView.java    | 12 +++--
 .../org/apache/tamaya/ui/views/SystemView.java  |  8 ++-
 ui/src/test/resources/config/application.yml    |  6 ++-
 11 files changed, 141 insertions(+), 106 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/089e9512/ui/src/main/java/org/apache/tamaya/ui/ApplicationLayout.java
----------------------------------------------------------------------
diff --git a/ui/src/main/java/org/apache/tamaya/ui/ApplicationLayout.java 
b/ui/src/main/java/org/apache/tamaya/ui/ApplicationLayout.java
index 01df605..678dc4d 100644
--- a/ui/src/main/java/org/apache/tamaya/ui/ApplicationLayout.java
+++ b/ui/src/main/java/org/apache/tamaya/ui/ApplicationLayout.java
@@ -18,14 +18,15 @@
  */
 package org.apache.tamaya.ui;
 
-import com.vaadin.navigator.Navigator;
 import com.vaadin.ui.HorizontalLayout;
 import com.vaadin.ui.Panel;
-import org.apache.tamaya.spi.ServiceContextManager;
-import org.apache.tamaya.ui.components.LazyProvider;
+import com.vaadin.ui.UI;
 import org.apache.tamaya.ui.components.PageTitleUpdater;
 import org.apache.tamaya.ui.views.ErrorView;
 
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
 /**
  * UI main layout.
  */
@@ -33,17 +34,21 @@ public class ApplicationLayout extends HorizontalLayout {
 
     private NavBar navBar;
     private Panel content;
-    private Navigator navigator;
+    private NavigationBar navigator;
 
-    public ApplicationLayout() {
+    public ApplicationLayout(UI ui) {
         addStyleName(UIConstants.MAIN_LAYOUT);
         setSizeFull();
         initLayouts();
-        setupNavigator();
+        setupNavigator(ui);
+    }
+
+    public NavigationBar getNavigationBar(){
+        return navigator;
     }
 
     private void initLayouts() {
-        navBar = new NavBar();
+        navBar = new NavBar(this);
         // Use panel as main content container to allow it's content to scroll
         content = new Panel();
         content.setSizeFull();
@@ -53,44 +58,17 @@ public class ApplicationLayout extends HorizontalLayout {
         setExpandRatio(content, 1);
     }
 
-    private void setupNavigator() {
-        navigator = new Navigator(VadiinApp.getCurrent(), content);
 
-        registerViews();
+    private void setupNavigator(UI ui) {
+        navigator = new NavigationBar(ui, content, navBar);
 
         // Add view change listeners so we can do things like select the 
correct menu item and update the page title
         navigator.addViewChangeListener(navBar);
         navigator.addViewChangeListener(new PageTitleUpdater());
 
-        navigator.navigateTo(navigator.getState());
-    }
-
-    private void registerViews() {
-        for(ViewProvider provider: 
ServiceContextManager.getServiceContext().getServices(ViewProvider.class)) {
-            addView(provider);
-        }
+        navigator.navigateTo("/home");
         navigator.setErrorView(ErrorView.class);
     }
 
-    /**
-     * Registers av given view to the navigator and adds it to the NavBar
-     */
-    private void addView(ViewProvider provider) {
 
-        switch (provider.getLifecycle()) {
-            case CREATE:
-            case EAGER:
-                try {
-                    navigator.addView(provider.getUrlPattern(), 
provider.createView());
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-                break;
-            case LAZY:
-            default:
-                navigator.addProvider(new 
LazyProvider(provider.getUrlPattern(), provider));
-                break;
-        }
-        navBar.addViewButton(provider.getUrlPattern(), 
provider.getDisplayName());
-    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/089e9512/ui/src/main/java/org/apache/tamaya/ui/Content.java
----------------------------------------------------------------------
diff --git a/ui/src/main/java/org/apache/tamaya/ui/Content.java 
b/ui/src/main/java/org/apache/tamaya/ui/Content.java
deleted file mode 100644
index c03fdf1..0000000
--- a/ui/src/main/java/org/apache/tamaya/ui/Content.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.ui;
-
-import com.vaadin.ui.HorizontalSplitPanel;
-import com.vaadin.ui.Label;
-
-import java.io.Serializable;
-
-/**
- * Created by atsticks on 29.03.16.
- */
-public class Content extends HorizontalSplitPanel implements Serializable{
-
-    public Content(){
-        this.addComponents(new Label("Left"), new Label("Content"));
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/089e9512/ui/src/main/java/org/apache/tamaya/ui/NavBar.java
----------------------------------------------------------------------
diff --git a/ui/src/main/java/org/apache/tamaya/ui/NavBar.java 
b/ui/src/main/java/org/apache/tamaya/ui/NavBar.java
index efc13a5..4cbc764 100644
--- a/ui/src/main/java/org/apache/tamaya/ui/NavBar.java
+++ b/ui/src/main/java/org/apache/tamaya/ui/NavBar.java
@@ -18,12 +18,11 @@
  */
 package org.apache.tamaya.ui;
 
+import com.sun.javafx.menu.SeparatorMenuItemBase;
 import com.vaadin.navigator.ViewChangeListener;
 import com.vaadin.server.FontAwesome;
 import com.vaadin.shared.ui.label.ContentMode;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.CssLayout;
-import com.vaadin.ui.Label;
+import com.vaadin.ui.*;
 import org.apache.tamaya.spi.ServiceContextManager;
 import org.apache.tamaya.ui.event.EventBus;
 import org.apache.tamaya.ui.event.LogoutEvent;
@@ -36,22 +35,25 @@ import java.util.Map;
 /**
  * Left side navigation bar.
  */
-public class NavBar extends CssLayout implements ViewChangeListener {
+public class NavBar extends VerticalLayout implements ViewChangeListener {
 
     private Map<String, Button> buttonMap = new HashMap<>();
 
-    public NavBar() {
-        setHeight("100%");
+    public NavBar(ApplicationLayout appLayout) {
+        // setHeight("100%");
+        setWidth(200, Unit.PIXELS);
         addStyleName(UIConstants.MENU_ROOT);
         addStyleName(UIConstants.NAVBAR);
+        setDefaultComponentAlignment(Alignment.TOP_LEFT);
         MessageProvider messages = 
ServiceContextManager.getServiceContext().getService(MessageProvider.class);
         Label logo = new Label("<strong>"+ 
messages.getMessage("project.name")+"</strong>", ContentMode.HTML);
         logo.addStyleName(UIConstants.MENU_TITLE);
         addComponent(logo);
-        addLogoutButton();
+        addLogoutAndSettingsButton(appLayout);
     }
 
-    private void addLogoutButton() {
+
+    private void addLogoutAndSettingsButton(final ApplicationLayout appLayout) 
{
         MessageProvider messages = 
ServiceContextManager.getServiceContext().getService(MessageProvider.class);
         Button logout = new 
Button(messages.getMessage("default.label.logout"), new Button.ClickListener() {
             @Override
@@ -64,11 +66,20 @@ public class NavBar extends CssLayout implements 
ViewChangeListener {
                 CurrentUser.set(null);
             }
         });
-        addComponent(logout);
-
         logout.addStyleName(UIConstants.BUTTON_LOGOUT);
         logout.addStyleName(UIConstants.BUTTON_BORDERLESS);
         logout.setIcon(FontAwesome.SIGN_OUT);
+        Button settings = new Button("...", new Button.ClickListener() {
+            @Override
+            public void buttonClick(Button.ClickEvent clickEvent) {
+                UISettingsDialog dlog = new 
UISettingsDialog(appLayout.getNavigationBar());
+                dlog.show();
+            }
+        });
+        settings.addStyleName(UIConstants.BUTTON_SETTINGS);
+        settings.addStyleName(UIConstants.BUTTON_BORDERLESS);
+        VerticalLayout buttons = new VerticalLayout(logout, settings);
+        addComponent(buttons);
     }
 
     public void addViewButton(final String uri, String displayName) {
@@ -78,10 +89,20 @@ public class NavBar extends CssLayout implements 
ViewChangeListener {
                 EventBus.post(new NavigationEvent(uri));
             }
         });
-        viewButton.addStyleName(UIConstants.MENU_ITEM);
+        viewButton.addStyleName(UIConstants.BUTTON_LOGOUT);
+        // viewButton.addStyleName(UIConstants.MENU_ITEM);
         viewButton.addStyleName(UIConstants.BUTTON_BORDERLESS);
-        buttonMap.put(uri, viewButton);
         addComponent(viewButton, components.size() - 1);
+        viewButton.setHeight(20, Unit.PIXELS);
+
+        buttonMap.put(uri, viewButton);
+    }
+
+    public void removeViewButton(String uri) {
+        Button button = buttonMap.remove(uri);
+        if(button!=null) {
+            removeComponent(button);
+        }
     }
 
     @Override
@@ -99,4 +120,6 @@ public class NavBar extends CssLayout implements 
ViewChangeListener {
             button.addStyleName(UIConstants.SELECTED);
         }
     }
+
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/089e9512/ui/src/main/java/org/apache/tamaya/ui/UIConstants.java
----------------------------------------------------------------------
diff --git a/ui/src/main/java/org/apache/tamaya/ui/UIConstants.java 
b/ui/src/main/java/org/apache/tamaya/ui/UIConstants.java
index 2f75b5c..ecf90ff 100644
--- a/ui/src/main/java/org/apache/tamaya/ui/UIConstants.java
+++ b/ui/src/main/java/org/apache/tamaya/ui/UIConstants.java
@@ -32,4 +32,5 @@ public class UIConstants extends ValoTheme {
 
 
     public static final String BUTTON_LOGOUT = "logout";
+    public static final String BUTTON_SETTINGS = BUTTON_TINY;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/089e9512/ui/src/main/java/org/apache/tamaya/ui/VadiinApp.java
----------------------------------------------------------------------
diff --git a/ui/src/main/java/org/apache/tamaya/ui/VadiinApp.java 
b/ui/src/main/java/org/apache/tamaya/ui/VadiinApp.java
index 9f8b37c..f3f362b 100644
--- a/ui/src/main/java/org/apache/tamaya/ui/VadiinApp.java
+++ b/ui/src/main/java/org/apache/tamaya/ui/VadiinApp.java
@@ -21,9 +21,11 @@ package org.apache.tamaya.ui;
 import com.google.common.eventbus.Subscribe;
 import com.vaadin.annotations.Theme;
 import com.vaadin.annotations.Title;
+import com.vaadin.navigator.Navigator;
 import com.vaadin.server.Page;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.server.VaadinSession;
+import com.vaadin.ui.Panel;
 import com.vaadin.ui.UI;
 import org.apache.tamaya.ui.event.LogoutEvent;
 import org.apache.tamaya.ui.event.NavigationEvent;
@@ -41,19 +43,16 @@ import org.apache.tamaya.ui.views.login.LoginView;
 @Title("Tamaya")
 public class VadiinApp extends UI {
 
-    private Content content = new Content();
-
-
     public VadiinApp(){
+        super(new Panel());
         super.setPollInterval(2000);
     }
 
     @Override
     protected void init(VaadinRequest vaadinRequest) {
         setupEventBus();
-
         if (CurrentUser.isLoggedIn()) {
-            setContent(new ApplicationLayout());
+            setContent(new ApplicationLayout(this));
         } else {
             setContent(new LoginView());
         }
@@ -63,12 +62,20 @@ public class VadiinApp extends UI {
     public void userLoggedIn(
             LoginEvent event) {
         CurrentUser.set(event.getUser());
-        setContent(new ApplicationLayout());
+        setContent(new ApplicationLayout(this));
     }
 
     @Subscribe
     public void navigateTo(NavigationEvent evt) {
-        getNavigator().navigateTo(evt.getViewName());
+        if(getNavigator()==null){
+            return;
+        }
+        if(evt.getViewName().isEmpty()){
+            getNavigator().navigateTo("/home");
+
+        }else {
+            getNavigator().navigateTo(evt.getViewName());
+        }
     }
 
     public static VadiinApp getCurrent() {

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/089e9512/ui/src/main/java/org/apache/tamaya/ui/ViewProvider.java
----------------------------------------------------------------------
diff --git a/ui/src/main/java/org/apache/tamaya/ui/ViewProvider.java 
b/ui/src/main/java/org/apache/tamaya/ui/ViewProvider.java
index 35990ab..578689f 100644
--- a/ui/src/main/java/org/apache/tamaya/ui/ViewProvider.java
+++ b/ui/src/main/java/org/apache/tamaya/ui/ViewProvider.java
@@ -44,6 +44,12 @@ public interface ViewProvider {
     ViewLifecycle getLifecycle();
 
     /**
+     * Get the view's name, used for resolving the view display name.
+     * @return the view's name.
+     */
+    String getName();
+
+    /**
      * Get the url pattern where this view should be accessible.
      * @return the url pattern, not null.
      */
@@ -60,7 +66,8 @@ public interface ViewProvider {
     /**
      * Method that is called to create a new view instance.
      * @see #getLifecycle()
+     * @param params any parameters that may be needed to create the view.
      * @return a new view instance, not null.
      */
-    View createView();
+    View createView(Object... params);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/089e9512/ui/src/main/java/org/apache/tamaya/ui/components/LazyProvider.java
----------------------------------------------------------------------
diff --git a/ui/src/main/java/org/apache/tamaya/ui/components/LazyProvider.java 
b/ui/src/main/java/org/apache/tamaya/ui/components/LazyProvider.java
index 5bc69cf..2d1547f 100644
--- a/ui/src/main/java/org/apache/tamaya/ui/components/LazyProvider.java
+++ b/ui/src/main/java/org/apache/tamaya/ui/components/LazyProvider.java
@@ -19,31 +19,62 @@
 package org.apache.tamaya.ui.components;
 
 import com.vaadin.navigator.View;
+import org.apache.tamaya.spi.ServiceContextManager;
 import org.apache.tamaya.ui.ViewProvider;
+import org.apache.tamaya.ui.services.MessageProvider;
 
 import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * Lazily initializes a view when it's first accessed, then always returns the
  * same instance on subsequent calls.
  */
-public class LazyProvider implements com.vaadin.navigator.ViewProvider {
-    private ViewProvider provider;
+public class LazyProvider implements ViewProvider {
+    private static final Logger LOG = Logger.getLogger(
+            LazyProvider.class.getName());
+    private Class<? extends View> viewClass;
     private View view;
+    private String urlPattern;
+    private String name;
 
-    public LazyProvider(String viewName, ViewProvider provider) {
-        this.provider = Objects.requireNonNull(provider);
+    public LazyProvider(String name, String urlPattern, Class<? extends View> 
viewClass) {
+        this.viewClass = Objects.requireNonNull(viewClass);
+        this.urlPattern = Objects.requireNonNull(urlPattern);
+        this.name = Objects.requireNonNull(name);
     }
 
     @Override
-    public String getViewName(String s) {
-        return provider.getUrlPattern();
+    public String getUrlPattern() {
+        return urlPattern;
+    }
+
+
+    @Override
+    public ViewLifecycle getLifecycle() {
+        return ViewLifecycle.LAZY;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String getDisplayName() {
+        return 
ServiceContextManager.getServiceContext().getService(MessageProvider.class)
+                .getMessage(name);
     }
 
     @Override
-    public View getView(String viewName) {
-        if (view == null) {
-            view = provider.createView();
+    public View createView(Object... params) {
+        if(view==null){
+            try {
+                view = viewClass.newInstance();
+            } catch (Exception e) {
+                LOG.log(Level.SEVERE, "Failed to create view: "+urlPattern, e);
+            }
         }
         return view;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/089e9512/ui/src/main/java/org/apache/tamaya/ui/views/ConfigView.java
----------------------------------------------------------------------
diff --git a/ui/src/main/java/org/apache/tamaya/ui/views/ConfigView.java 
b/ui/src/main/java/org/apache/tamaya/ui/views/ConfigView.java
index 1e32037..8b1fa3b 100644
--- a/ui/src/main/java/org/apache/tamaya/ui/views/ConfigView.java
+++ b/ui/src/main/java/org/apache/tamaya/ui/views/ConfigView.java
@@ -45,6 +45,7 @@ import java.util.TreeMap;
 /**
  * View for evaluating the current convifugration tree.
  */
+@Priority(10)
 public class ConfigView extends VerticalSpacedLayout implements View {
 
     /**
@@ -59,6 +60,11 @@ public class ConfigView extends VerticalSpacedLayout 
implements View {
         }
 
         @Override
+        public String getName() {
+            return "view.config.name";
+        }
+
+        @Override
         public String getUrlPattern() {
             return "/config";
         }
@@ -70,7 +76,7 @@ public class ConfigView extends VerticalSpacedLayout 
implements View {
         }
 
         @Override
-        public View createView(){
+        public View createView(Object... params){
             return new ConfigView();
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/089e9512/ui/src/main/java/org/apache/tamaya/ui/views/HomeView.java
----------------------------------------------------------------------
diff --git a/ui/src/main/java/org/apache/tamaya/ui/views/HomeView.java 
b/ui/src/main/java/org/apache/tamaya/ui/views/HomeView.java
index 9ce88ef..9d371d0 100644
--- a/ui/src/main/java/org/apache/tamaya/ui/views/HomeView.java
+++ b/ui/src/main/java/org/apache/tamaya/ui/views/HomeView.java
@@ -48,20 +48,26 @@ public class HomeView extends VerticalSpacedLayout 
implements View {
         }
 
         @Override
+        public String getName() {
+            return "view.home.name";
+        }
+
+        @Override
         public String getUrlPattern() {
-            return "";
+            return "/home";
         }
 
         @Override
         public String getDisplayName() {
             return 
ServiceContextManager.getServiceContext().getService(MessageProvider.class)
-                    .getMessage("view.home.name");
+                    .getMessage(getName());
         }
 
         @Override
-        public View createView(){
+        public View createView(Object... params) {
             return new HomeView();
         }
+
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/089e9512/ui/src/main/java/org/apache/tamaya/ui/views/SystemView.java
----------------------------------------------------------------------
diff --git a/ui/src/main/java/org/apache/tamaya/ui/views/SystemView.java 
b/ui/src/main/java/org/apache/tamaya/ui/views/SystemView.java
index 4b76edb..e980a02 100644
--- a/ui/src/main/java/org/apache/tamaya/ui/views/SystemView.java
+++ b/ui/src/main/java/org/apache/tamaya/ui/views/SystemView.java
@@ -43,6 +43,7 @@ import java.util.Map;
 /**
  * View showing the current loaded system components.
  */
+@Priority(10000)
 public class SystemView extends VerticalSpacedLayout implements View {
 
 
@@ -58,6 +59,11 @@ public class SystemView extends VerticalSpacedLayout 
implements View {
         }
 
         @Override
+        public String getName() {
+            return "view.system.name";
+        }
+
+        @Override
         public String getUrlPattern() {
             return "/system";
         }
@@ -69,7 +75,7 @@ public class SystemView extends VerticalSpacedLayout 
implements View {
         }
 
         @Override
-        public View createView(){
+        public View createView(Object... params){
             return new SystemView();
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/089e9512/ui/src/test/resources/config/application.yml
----------------------------------------------------------------------
diff --git a/ui/src/test/resources/config/application.yml 
b/ui/src/test/resources/config/application.yml
index 33c353c..10ef339 100644
--- a/ui/src/test/resources/config/application.yml
+++ b/ui/src/test/resources/config/application.yml
@@ -29,4 +29,8 @@ server:
       - type: http
         port: 8091
       - type: https
-        port: 8453
\ No newline at end of file
+        port: 8453
+
+ui:
+  disabled-views:
+    - "view.system.name"
\ No newline at end of file

Reply via email to