You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2016/10/17 18:21:44 UTC
[24/50] [abbrv] incubator-tamaya-extensions git commit: Modulularized
UI module, added multi file based i18n, using config mechanisms.
Modulularized UI module, added multi file based i18n, using config mechanisms.
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/c7828a4b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/c7828a4b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/c7828a4b
Branch: refs/heads/master
Commit: c7828a4b0c75d77f5d4830ec436aecf45424a1ee
Parents: f3d3288
Author: anatole <an...@apache.org>
Authored: Sat Apr 16 08:25:46 2016 +0200
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Fri Sep 30 21:29:37 2016 +0200
----------------------------------------------------------------------
.../org/apache/tamaya/events/ui/EventView.java | 134 +++++++++++++++++++
.../services/org.apache.tamaya.ui.ViewProvider | 19 +++
src/main/resources/ui/lang/tamaya.properties | 5 +
.../tamaya/events/RandomPropertySource.java | 48 +++++++
.../org.apache.tamaya.spi.PropertySource | 19 +++
.../services/org.apache.tamaya.ui.ViewProvider | 19 +++
src/test/resources/config/application.yml | 13 ++
7 files changed, 257 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c7828a4b/src/main/java/org/apache/tamaya/events/ui/EventView.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/events/ui/EventView.java b/src/main/java/org/apache/tamaya/events/ui/EventView.java
new file mode 100644
index 0000000..a69b04c
--- /dev/null
+++ b/src/main/java/org/apache/tamaya/events/ui/EventView.java
@@ -0,0 +1,134 @@
+/*
+ * 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.events.ui;
+
+import com.vaadin.data.Property;
+import com.vaadin.navigator.View;
+import com.vaadin.navigator.ViewChangeListener;
+import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.ui.*;
+import org.apache.tamaya.events.ConfigEvent;
+import org.apache.tamaya.events.ConfigEventListener;
+import org.apache.tamaya.events.ConfigEventManager;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.ui.UIConstants;
+import org.apache.tamaya.ui.ViewProvider;
+import org.apache.tamaya.ui.components.VerticalSpacedLayout;
+import org.apache.tamaya.ui.services.MessageProvider;
+
+import javax.annotation.Priority;
+
+
+public class EventView extends VerticalSpacedLayout implements View {
+
+ @Priority(20)
+ public static final class Provider implements ViewProvider{
+
+ @Override
+ public ViewLifecycle getLifecycle() {
+ return ViewLifecycle.EAGER;
+ }
+
+ @Override
+ public String getUrlPattern() {
+ return "/events";
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "view.events.name";
+ }
+
+ @Override
+ public View createView(){
+ return new EventView();
+ }
+ }
+
+ private CheckBox changeMonitorEnabled = new CheckBox(ServiceContextManager.getServiceContext()
+ .getService(MessageProvider.class).getMessage("view.events.button.enableMonitoring"));
+ private Button clearViewButton = new Button(ServiceContextManager.getServiceContext()
+ .getService(MessageProvider.class).getMessage("view.events.button.clearView"));
+ private Table eventsTable = new Table(ServiceContextManager.getServiceContext()
+ .getService(MessageProvider.class).getMessage("view.events.table.name"));
+
+
+ public EventView() {
+ Label caption = new Label(ServiceContextManager.getServiceContext()
+ .getService(MessageProvider.class).getMessage("view.events.name"));
+ Label description = new Label(ServiceContextManager.getServiceContext()
+ .getService(MessageProvider.class).getMessage("view.events.description"),
+ ContentMode.HTML);
+
+ ConfigEventManager.addListener(new ConfigEventListener() {
+ @Override
+ public void onConfigEvent(ConfigEvent<?> event) {
+ addEvent(event);
+ }
+ });
+ changeMonitorEnabled.addValueChangeListener(new Property.ValueChangeListener() {
+ @Override
+ public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
+ ConfigEventManager.enableChangeMonitoring(changeMonitorEnabled.getValue());
+ }
+ });
+ clearViewButton.addClickListener(new Button.ClickListener() {
+ @Override
+ public void buttonClick(Button.ClickEvent clickEvent) {
+ eventsTable.removeAllItems();
+ }
+ });
+
+ changeMonitorEnabled.setData(ConfigEventManager.isChangeMonitoring());
+ eventsTable.addContainerProperty("Timestamp", Long.class, null);
+ eventsTable.addContainerProperty("Type", Class.class, null);
+ eventsTable.addContainerProperty("Payload", String.class, null);
+ eventsTable.addContainerProperty("Version", String.class, null);
+ eventsTable.setPageLength(20);
+ eventsTable.setWidth("100%");
+ eventsTable.setResponsive(true);
+
+ HorizontalLayout hl = new HorizontalLayout();
+ hl.addComponents(changeMonitorEnabled, clearViewButton);
+ caption.addStyleName(UIConstants.LABEL_HUGE);
+ description.addStyleName(UIConstants.LABEL_LARGE);
+ addComponents(caption, description, hl, eventsTable);
+ }
+
+ private void addEvent(ConfigEvent<?> evt){
+ eventsTable.addItem(new Object[]{evt.getTimestamp(), evt.getResourceType().getSimpleName(),
+ String.valueOf(evt.getResource()),evt.getVersion()});
+ this.markAsDirty();
+ }
+
+
+ private String getCaption(String key, String value) {
+ int index = key.lastIndexOf('.');
+ if(index<0){
+ return key + " = " + value;
+ }else{
+ return key.substring(index+1) + " = " + value;
+ }
+ }
+
+ @Override
+ public void enter(ViewChangeListener.ViewChangeEvent event) {
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c7828a4b/src/main/resources/META-INF/services/org.apache.tamaya.ui.ViewProvider
----------------------------------------------------------------------
diff --git a/src/main/resources/META-INF/services/org.apache.tamaya.ui.ViewProvider b/src/main/resources/META-INF/services/org.apache.tamaya.ui.ViewProvider
new file mode 100644
index 0000000..f779d5c
--- /dev/null
+++ b/src/main/resources/META-INF/services/org.apache.tamaya.ui.ViewProvider
@@ -0,0 +1,19 @@
+#
+# 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 current 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.
+#
+org.apache.tamaya.events.ui.EventView$Provider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c7828a4b/src/main/resources/ui/lang/tamaya.properties
----------------------------------------------------------------------
diff --git a/src/main/resources/ui/lang/tamaya.properties b/src/main/resources/ui/lang/tamaya.properties
new file mode 100644
index 0000000..37ca420
--- /dev/null
+++ b/src/main/resources/ui/lang/tamaya.properties
@@ -0,0 +1,5 @@
+view.events.name=Configuration Events
+view.events.table.name=Observed Events
+view.events.button.enableMonitoring=Change Monitor active
+view.events.button.clearView=Clear View
+view.events.description=This view shows the configuration events triggered in the system.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c7828a4b/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/events/RandomPropertySource.java b/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
new file mode 100644
index 0000000..f32ead7
--- /dev/null
+++ b/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
@@ -0,0 +1,48 @@
+package org.apache.tamaya.events;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * PropertySource that provides a randome entry, different on each access!
+ */
+public class RandomPropertySource implements PropertySource{
+
+ private Map<String, String> data = new HashMap<>();
+
+ @Override
+ public int getOrdinal() {
+ return 0;
+ }
+
+ @Override
+ public String getName() {
+ return "random";
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ if(key.equals("random.new")){
+ return PropertyValue.of(key, String.valueOf(Math.random()),getName());
+ }
+ return null;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ synchronized(data) {
+ data.put("random.new", String.valueOf(Math.random()));
+ data.put("_random.new.source", getName());
+ data.put("_random.new.timestamp", String.valueOf(System.currentTimeMillis()));
+ return new HashMap<>(data);
+ }
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c7828a4b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
new file mode 100644
index 0000000..9c2b9f6
--- /dev/null
+++ b/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -0,0 +1,19 @@
+#
+# 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 current 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.
+#
+org.apache.tamaya.events.RandomPropertySource
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c7828a4b/src/test/resources/META-INF/services/org.apache.tamaya.ui.ViewProvider
----------------------------------------------------------------------
diff --git a/src/test/resources/META-INF/services/org.apache.tamaya.ui.ViewProvider b/src/test/resources/META-INF/services/org.apache.tamaya.ui.ViewProvider
new file mode 100644
index 0000000..f779d5c
--- /dev/null
+++ b/src/test/resources/META-INF/services/org.apache.tamaya.ui.ViewProvider
@@ -0,0 +1,19 @@
+#
+# 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 current 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.
+#
+org.apache.tamaya.events.ui.EventView$Provider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c7828a4b/src/test/resources/config/application.yml
----------------------------------------------------------------------
diff --git a/src/test/resources/config/application.yml b/src/test/resources/config/application.yml
new file mode 100644
index 0000000..9ec8d5b
--- /dev/null
+++ b/src/test/resources/config/application.yml
@@ -0,0 +1,13 @@
+server:
+ type: default
+ maxThreads: 1024
+ applicationConnectors:
+ - type: http
+ port: 8090
+ - type: https
+ port: 8453
+ adminConnectors:
+ - type: http
+ port: 8091
+ - type: https
+ port: 8453
\ No newline at end of file