diff --git a/.gitignore b/.gitignore index 1d7646181e..cf5f93d1b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .metadata .settings .project +.factorypath target/ .classpath *.i[mpw][lrs] @@ -13,3 +14,5 @@ nb-configuration.xml rebel.xml .springBeans workbench.xmi +.vscode + diff --git a/.travis.yml b/.travis.yml index 85e6e9f00a..e532a69e55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,16 @@ +dist: trusty language: java jdk: -- openjdk7 - oraclejdk8 addons: apt: packages: - - oracle-java8-installer + - openjdk-8-jdk sudo: false notifications: email: - mgrigorov@apache.org + - solomax@apache.org irc: channels: - chat.freenode.net##wicket diff --git a/annotation/pom.xml b/annotation/pom.xml index 2d67e60ad9..7aff621518 100644 --- a/annotation/pom.xml +++ b/annotation/pom.xml @@ -5,7 +5,7 @@ org.wicketstuff wicketstuff-core - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-annotation diff --git a/annotationeventdispatcher-parent/README.md b/annotationeventdispatcher-parent/README.md index ad2b21d3f1..5e34f29504 100644 --- a/annotationeventdispatcher-parent/README.md +++ b/annotationeventdispatcher-parent/README.md @@ -28,13 +28,12 @@ The library uses a Wicket `IInitializer` to install itself into an application s Configuration ------------- -The configuration object for the library, `AnnotationEventDispatcherConfig`, can be accessed via an application's metadata: `Application.get().getMetaData(Initializer.ANNOTATION_EVENT_DISPATCHER_CONFIG_CONTEXT_KEY)`. +The configuration object for the library, `AnnotationEventDispatcherConfig`, can be accessed via: `AnnotationEventDispatcherConfig.get(Application.get())`. -Currently, there is just one configuration parameter: +Currently, there are just two configuration parameters: * class filter that events must implement in order to be handled by the annotation dispatcher; by default, there is no filter - -Whether an event is dispatched to a given event handler method is controlled by the Component#canCallListenerInterface(Method) method. By default, this method returns false if the component is either disabled or not visible. +* whether event should be dispatched to invisible/disabled components, default is false Usage ----- diff --git a/annotationeventdispatcher-parent/annotationeventdispatcher/pom.xml b/annotationeventdispatcher-parent/annotationeventdispatcher/pom.xml index 2677b68e70..a60584e9a4 100644 --- a/annotationeventdispatcher-parent/annotationeventdispatcher/pom.xml +++ b/annotationeventdispatcher-parent/annotationeventdispatcher/pom.xml @@ -4,7 +4,7 @@ org.wicketstuff wicketstuff-annotationeventdispatcher-parent - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-annotationeventdispatcher diff --git a/annotationeventdispatcher-parent/annotationeventdispatcher/src/main/java/org/wicketstuff/event/annotation/AnnotationEventDispatcher.java b/annotationeventdispatcher-parent/annotationeventdispatcher/src/main/java/org/wicketstuff/event/annotation/AnnotationEventDispatcher.java index 9cc7bcae1d..24cda3e195 100644 --- a/annotationeventdispatcher-parent/annotationeventdispatcher/src/main/java/org/wicketstuff/event/annotation/AnnotationEventDispatcher.java +++ b/annotationeventdispatcher-parent/annotationeventdispatcher/src/main/java/org/wicketstuff/event/annotation/AnnotationEventDispatcher.java @@ -76,15 +76,13 @@ private boolean containsOnEventMethod(final Class clazz) public void dispatchEvent(final Object sink, final IEvent event, final Component component) { AnnotationEventSink eventSink = eventSinkByClass.get(sink.getClass()); - AnnotationEventDispatcherConfig config = Application.get().getMetaData( - Initializer.ANNOTATION_EVENT_DISPATCHER_CONFIG_CONTEXT_KEY); - if (eventSink != null - && eventSink != EMPTY_SINK - && (config.getEventFilter() == null || config.getEventFilter().isAssignableFrom( - event.getPayload().getClass()))) - { - eventSink.onEvent(sink, event); + if (eventSink != null&& eventSink != EMPTY_SINK) { + AnnotationEventDispatcherConfig config = AnnotationEventDispatcherConfig.get(Application.get()); + + if (config.allowDispatch(sink, event)) + { + eventSink.onEvent(sink, event); + } } } - } diff --git a/annotationeventdispatcher-parent/annotationeventdispatcher/src/main/java/org/wicketstuff/event/annotation/AnnotationEventDispatcherConfig.java b/annotationeventdispatcher-parent/annotationeventdispatcher/src/main/java/org/wicketstuff/event/annotation/AnnotationEventDispatcherConfig.java index dc7bd88d68..81525a9c9a 100644 --- a/annotationeventdispatcher-parent/annotationeventdispatcher/src/main/java/org/wicketstuff/event/annotation/AnnotationEventDispatcherConfig.java +++ b/annotationeventdispatcher-parent/annotationeventdispatcher/src/main/java/org/wicketstuff/event/annotation/AnnotationEventDispatcherConfig.java @@ -1,13 +1,32 @@ package org.wicketstuff.event.annotation; +import org.apache.wicket.Application; +import org.apache.wicket.Component; +import org.apache.wicket.event.IEvent; + public class AnnotationEventDispatcherConfig { private Class eventFilter = null; + private boolean dispatchToNonVisibleComponents = false; + public AnnotationEventDispatcherConfig() { super(); } + public boolean isDispatchToNonVisibleComponents() { + return dispatchToNonVisibleComponents; + } + + public void setDispatchToNonVisibleComponents(final boolean dispatchToNonVisibleComponents) { + this.dispatchToNonVisibleComponents = dispatchToNonVisibleComponents; + } + + public AnnotationEventDispatcherConfig dispatchToNonVisibleComponents(final boolean dispatchToNonVisibleComponents) { + setDispatchToNonVisibleComponents(dispatchToNonVisibleComponents); + return this; + } + public Class getEventFilter() { return eventFilter; } @@ -16,5 +35,31 @@ public AnnotationEventDispatcherConfig eventFilter(final Class eventFilter) { this.eventFilter = eventFilter; return this; } + + /** + * By default dispatching is not allowed when: + * + * + * @param sink the sink to dispatch to + * @param event the event to dispatch + * @return true if dispatch is allowed + */ + public boolean allowDispatch(final Object sink, final IEvent event) + { + return (eventFilter == null || eventFilter.isAssignableFrom(event.getPayload().getClass())) + && (dispatchToNonVisibleComponents || (sink instanceof Component && ((Component)sink).canCallListener())); + } + /** + * Get the configuration. + * + * @param application + * @return configuration + */ + public static AnnotationEventDispatcherConfig get(Application application) { + return application.getMetaData(Initializer.ANNOTATION_EVENT_DISPATCHER_CONFIG_CONTEXT_KEY); + } } diff --git a/annotationeventdispatcher-parent/annotationeventdispatcher/src/main/java/org/wicketstuff/event/annotation/AnnotationEventSink.java b/annotationeventdispatcher-parent/annotationeventdispatcher/src/main/java/org/wicketstuff/event/annotation/AnnotationEventSink.java index 799a098e97..11483456f6 100644 --- a/annotationeventdispatcher-parent/annotationeventdispatcher/src/main/java/org/wicketstuff/event/annotation/AnnotationEventSink.java +++ b/annotationeventdispatcher-parent/annotationeventdispatcher/src/main/java/org/wicketstuff/event/annotation/AnnotationEventSink.java @@ -135,31 +135,28 @@ private void onEvent(final Set onEventMethods, final Object sink, final { for (Method method : onEventMethods) { - if (canCallListenerInterface(sink)) + OnEvent onEvent = method.getAnnotation(OnEvent.class); + if (isPayloadApplicableToHandler(onEvent, payload)) { - OnEvent onEvent = method.getAnnotation(OnEvent.class); - if (isPayloadApplicableToHandler(onEvent, payload)) + Object result = method.invoke(sink, payload); + if (result instanceof Visit) { - Object result = method.invoke(sink, payload); - if (result instanceof Visit) + Visit visit = (Visit) result; + if (visit.isDontGoDeeper()) { - Visit visit = (Visit) result; - if (visit.isDontGoDeeper()) - { - event.dontBroadcastDeeper(); - } - else if (visit.isStopped()) - { - event.stop(); - break; - } + event.dontBroadcastDeeper(); } - else if (onEvent.stop()) + else if (visit.isStopped()) { event.stop(); break; } } + else if (onEvent.stop()) + { + event.stop(); + break; + } } } } catch (InvocationTargetException e) diff --git a/annotationeventdispatcher-parent/annotationeventdispatcher/src/test/java/org/wicketstuff/event/annotation/TypedAnnotationEventDispatcherTest.java b/annotationeventdispatcher-parent/annotationeventdispatcher/src/test/java/org/wicketstuff/event/annotation/TypedAnnotationEventDispatcherTest.java index 860ef9e1f4..1731705cc4 100644 --- a/annotationeventdispatcher-parent/annotationeventdispatcher/src/test/java/org/wicketstuff/event/annotation/TypedAnnotationEventDispatcherTest.java +++ b/annotationeventdispatcher-parent/annotationeventdispatcher/src/test/java/org/wicketstuff/event/annotation/TypedAnnotationEventDispatcherTest.java @@ -121,6 +121,25 @@ public void eventNotSentToNonVisibleComponent() Assert.assertEquals(0, container.personsHandled); } + @Test + public void eventSentToNonVisibleComponentWhenConfigured() + { + AnnotationEventDispatcherConfig.get(tester.getApplication()).dispatchToNonVisibleComponents(true); + + ComponentOne one = new ComponentOne("id1"); + ComponentTwo two = new ComponentTwo("id2"); + TestContainer container = new TestContainer("container"); + container.add(one, two); + two.setVisible(false); + tester.startComponentInPage(container); + one.send(container.getApplication(), Broadcast.BREADTH, new SaveEvent<>(null, new Widget())); + Assert.assertEquals(0, one.personsHandled); + Assert.assertEquals(1, one.widgetsHandled); + Assert.assertEquals(1, two.savesHandled); + Assert.assertEquals(1, container.widgetsHandled); + Assert.assertEquals(0, container.personsHandled); + } + @Test(expected = IllegalStateException.class) public void exceptionWhenGenericDoesNotAgreeWithTypes() { diff --git a/annotationeventdispatcher-parent/pom.xml b/annotationeventdispatcher-parent/pom.xml index c67fa20fcd..1e3cf0207b 100644 --- a/annotationeventdispatcher-parent/pom.xml +++ b/annotationeventdispatcher-parent/pom.xml @@ -6,7 +6,7 @@ org.wicketstuff wicketstuff-core - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-annotationeventdispatcher-parent Annotation Event Dispatcher - Parent diff --git a/async-tasks-parent/async-tasks-demo/pom.xml b/async-tasks-parent/async-tasks-demo/pom.xml index 6f7e2c1902..713d2a0a25 100644 --- a/async-tasks-parent/async-tasks-demo/pom.xml +++ b/async-tasks-parent/async-tasks-demo/pom.xml @@ -4,7 +4,7 @@ org.wicketstuff async-tasks-parent - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT async-task-demo diff --git a/async-tasks-parent/async-tasks-impl/pom.xml b/async-tasks-parent/async-tasks-impl/pom.xml index da86a1df60..9096bd8242 100644 --- a/async-tasks-parent/async-tasks-impl/pom.xml +++ b/async-tasks-parent/async-tasks-impl/pom.xml @@ -5,7 +5,7 @@ org.wicketstuff async-tasks-parent - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT async-task-impl diff --git a/async-tasks-parent/pom.xml b/async-tasks-parent/pom.xml index c7880c5f96..f0082faaee 100644 --- a/async-tasks-parent/pom.xml +++ b/async-tasks-parent/pom.xml @@ -5,7 +5,7 @@ org.wicketstuff wicketstuff-core - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT async-tasks-parent diff --git a/autocomplete-tagit-parent/autocomplete-tagit-examples/pom.xml b/autocomplete-tagit-parent/autocomplete-tagit-examples/pom.xml index 42fbac6e20..f17c786859 100644 --- a/autocomplete-tagit-parent/autocomplete-tagit-examples/pom.xml +++ b/autocomplete-tagit-parent/autocomplete-tagit-examples/pom.xml @@ -3,7 +3,7 @@ org.wicketstuff wicketstuff-autocomplete-tagit-parent - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-autocomplete-tagit-examples diff --git a/autocomplete-tagit-parent/autocomplete-tagit/pom.xml b/autocomplete-tagit-parent/autocomplete-tagit/pom.xml index 795315c658..8c2a504133 100644 --- a/autocomplete-tagit-parent/autocomplete-tagit/pom.xml +++ b/autocomplete-tagit-parent/autocomplete-tagit/pom.xml @@ -4,7 +4,7 @@ org.wicketstuff wicketstuff-autocomplete-tagit-parent - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-autocomplete-tagit diff --git a/autocomplete-tagit-parent/pom.xml b/autocomplete-tagit-parent/pom.xml index 7cfe3d84e3..72bd788836 100644 --- a/autocomplete-tagit-parent/pom.xml +++ b/autocomplete-tagit-parent/pom.xml @@ -6,7 +6,7 @@ org.wicketstuff wicketstuff-core - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-autocomplete-tagit-parent Autocomplete Tag It Parent diff --git a/closure-compiler/pom.xml b/closure-compiler/pom.xml index b277e59a88..cf3e05a69a 100644 --- a/closure-compiler/pom.xml +++ b/closure-compiler/pom.xml @@ -6,7 +6,7 @@ org.wicketstuff wicketstuff-core - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-closure-compiler @@ -18,6 +18,11 @@ com.google.javascript closure-compiler + + com.google.protobuf + protobuf-java + 3.8.0 + junit junit diff --git a/closure-compiler/src/main/java/org/wicketstuff/closurecompiler/ClosureCompilerJavaScriptCompressor.java b/closure-compiler/src/main/java/org/wicketstuff/closurecompiler/ClosureCompilerJavaScriptCompressor.java index b0d979dcbb..90d6fe1030 100644 --- a/closure-compiler/src/main/java/org/wicketstuff/closurecompiler/ClosureCompilerJavaScriptCompressor.java +++ b/closure-compiler/src/main/java/org/wicketstuff/closurecompiler/ClosureCompilerJavaScriptCompressor.java @@ -1,7 +1,6 @@ package org.wicketstuff.closurecompiler; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.apache.wicket.javascript.IJavaScriptCompressor; @@ -63,7 +62,7 @@ public String compress(String uncompressed) public final String compressSource(String uncompressed) throws Exception { // environment for compilation - final List externs = CommandLineRunner.getDefaultExterns(); + final List externs = CommandLineRunner.getBuiltinExterns(CompilerOptions.Environment.BROWSER); // create compiler + options final Compiler compiler = new Compiler(); @@ -76,7 +75,6 @@ public final String compressSource(String uncompressed) throws Exception options.removeUnusedVars = false; options.removeUnusedLocalVars = false; options.removeUnusedPrototypeProperties = false; - options.removeUnusedPrototypePropertiesInExterns = false; // custom configuration options configure(compiler, options, externs); @@ -92,7 +90,7 @@ public final String compressSource(String uncompressed) throws Exception if (result.success == false) { - throw new ClosureCompilationException(Arrays.asList(result.errors)); + throw new ClosureCompilationException(result.errors); } return compiler.toSource(); } diff --git a/dashboard-parent/dashboard-core/pom.xml b/dashboard-parent/dashboard-core/pom.xml index 7c059a73a6..e904061d3c 100644 --- a/dashboard-parent/dashboard-core/pom.xml +++ b/dashboard-parent/dashboard-core/pom.xml @@ -7,17 +7,13 @@ org.wicketstuff wicketstuff-dashboard-parent - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-dashboard-core jar Wicketstuff Dashboard Core - - 1.4.10 - - diff --git a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/DashboardContextInitializer.java b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/DashboardContextInitializer.java index c07c97f102..de64e56576 100644 --- a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/DashboardContextInitializer.java +++ b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/DashboardContextInitializer.java @@ -45,4 +45,8 @@ public void init(Application application) { public void destroy(Application application) { // does noting } + + public static DashboardContext getDashboardContext() { + return Application.get().getMetaData(DASHBOARD_CONTEXT_KEY); + } } diff --git a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/DefaultWidgetFactory.java b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/DefaultWidgetFactory.java index 9dcace2fe7..9812961ddd 100644 --- a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/DefaultWidgetFactory.java +++ b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/DefaultWidgetFactory.java @@ -1,11 +1,11 @@ /* * Copyright 2012 Decebal Suiu - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with * the License. You may obtain a copy of the License in the LICENSE file, or 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. @@ -15,37 +15,34 @@ import java.lang.reflect.Constructor; import java.util.UUID; +import org.apache.wicket.Application; + /** * Default {@link WidgetFactory} which creates a widget by specified widget class name * @author Decebal Suiu */ public class DefaultWidgetFactory implements WidgetFactory { + @Override @SuppressWarnings("unchecked") public Widget createWidget(WidgetDescriptor widgetDescriptor) { String widgetClassName = widgetDescriptor.getWidgetClassName(); try { - Class widgetClass = (Class) Class.forName(widgetClassName); + Class widgetClass = (Class)Application.get().getApplicationSettings().getClassResolver().resolveClass(widgetClassName); Constructor constructor = widgetClass.getConstructor(); Widget widget = constructor.newInstance(); String widgetId = createWidgetId(widgetDescriptor, widget); widget.setId(widgetId); widget.init(); - + return widget; - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } - return null; } protected String createWidgetId(WidgetDescriptor widgetDescriptor, Widget widget) { return UUID.randomUUID().toString(); } - } diff --git a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/DefaultWidgetRegistry.java b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/DefaultWidgetRegistry.java index 075d0ef1a8..8d6539e891 100644 --- a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/DefaultWidgetRegistry.java +++ b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/DefaultWidgetRegistry.java @@ -1,11 +1,11 @@ /* * Copyright 2012 Decebal Suiu - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with * the License. You may obtain a copy of the License in the LICENSE file, or 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. @@ -18,17 +18,17 @@ /** * Default {@link WidgetRegistry} implementation. * Override this class if you need to tire registry with some underling storage - * + * * @author Decebal Suiu */ public class DefaultWidgetRegistry implements WidgetRegistry { private List widgetDescriptors; - + public DefaultWidgetRegistry() { widgetDescriptors = new ArrayList(); } - + @Override public List getWidgetDescriptors() { return widgetDescriptors; @@ -43,7 +43,7 @@ public WidgetRegistry registerWidget(WidgetDescriptor widgetDescriptor) { if (widgetDescriptor != null) { widgetDescriptors.add(widgetDescriptor); } - + return this; } @@ -54,19 +54,19 @@ public WidgetDescriptor getWidgetDescriptorByClassName(String widgetClassName) { return widgetDescriptor; } } - + return null; } - - @Override + + @Override public WidgetDescriptor getWidgetDescriptorByTypeName(String widgetTypeName) { for (WidgetDescriptor widgetDescriptor : widgetDescriptors) { if (widgetDescriptor.getTypeName().equals(widgetTypeName)) { return widgetDescriptor; } } - - return null; + + return null; } } diff --git a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/WidgetActionsFactory.java b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/WidgetActionsFactory.java index 4939852dbf..e58f93339d 100644 --- a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/WidgetActionsFactory.java +++ b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/WidgetActionsFactory.java @@ -1,11 +1,11 @@ /* * Copyright 2012 Decebal Suiu - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with * the License. You may obtain a copy of the License in the LICENSE file, or 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. @@ -21,5 +21,5 @@ public interface WidgetActionsFactory { public List createWidgetActions(Widget widget); - + } diff --git a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/DashboardContextInjector.java b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/DashboardContextInjector.java index b4cb5d9f71..8308e50ec2 100644 --- a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/DashboardContextInjector.java +++ b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/DashboardContextInjector.java @@ -1,11 +1,11 @@ /* * Copyright 2012 Decebal Suiu - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with * the License. You may obtain a copy of the License in the LICENSE file, or 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. @@ -22,11 +22,11 @@ public class DashboardContextInjector implements IComponentInstantiationListener { private DashboardContext dashboardContext; - + public DashboardContextInjector() { dashboardContext = new DashboardContext(); } - + public DashboardContextInjector(DashboardContext dashboardContext) { this.dashboardContext = dashboardContext; } @@ -41,5 +41,4 @@ public void onInstantiation(Component component) { ((DashboardContextAware) component).setDashboardContext(dashboardContext); } } - } diff --git a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/DashboardPanel.java b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/DashboardPanel.java index 4060085ea2..bcee42e8d5 100644 --- a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/DashboardPanel.java +++ b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/DashboardPanel.java @@ -12,6 +12,8 @@ */ package org.wicketstuff.dashboard.web; +import static org.wicketstuff.dashboard.DashboardContextInitializer.getDashboardContext; + import java.util.ArrayList; import java.util.List; @@ -32,11 +34,9 @@ * Wicket {@link Panel} which should be used on a page to render a {@link Dashboard} * @author Decebal Suiu */ -public class DashboardPanel extends GenericPanel implements DashboardContextAware { +public class DashboardPanel extends GenericPanel { private static final long serialVersionUID = 1L; - private transient DashboardContext dashboardContext; - private List columnPanels; private IModel rtlModel; @@ -52,18 +52,6 @@ public Dashboard getDashboard() { return getModelObject(); } - @Override - public void setDashboardContext(DashboardContext dashboardContext) { - this.dashboardContext = dashboardContext; - } - - /** - * Used by children. - */ - public DashboardContext getDashboardContext() { - return dashboardContext; - } - @Override public void onEvent(IEvent event) { super.onEvent(event); @@ -105,7 +93,7 @@ private void onWidgetAdded(DashboardEvent dashboardEvent) { Dashboard dashboard = getDashboard(); DashboardUtils.updateWidgetLocations(dashboard, dashboardEvent); dashboard.addWidget(addedWidget); - dashboardContext.getDashboardPersister().save(dashboard); + getDashboardContext().getDashboardPersister().save(dashboard); } private void onWidgetRemoved(DashboardEvent dashboardEvent) { @@ -113,13 +101,13 @@ private void onWidgetRemoved(DashboardEvent dashboardEvent) { Dashboard dashboard = getDashboard(); DashboardUtils.updateWidgetLocations(dashboard, dashboardEvent); dashboard.deleteWidget(removedWidget.getId()); - dashboardContext.getDashboardPersister().save(dashboard); + getDashboardContext().getDashboardPersister().save(dashboard); } protected void onWidgetsSorted(DashboardEvent dashboardEvent) { Dashboard dashboard = getDashboard(); DashboardUtils.updateWidgetLocations(dashboard, dashboardEvent); - dashboardContext.getDashboardPersister().save(dashboard); + getDashboardContext().getDashboardPersister().save(dashboard); } private void addColumnsPanel() { @@ -130,7 +118,7 @@ private void addColumnsPanel() { @Override protected void onBeforeRender() { if (!hasBeenRendered()) { - columnPanels = new ArrayList(); + columnPanels = new ArrayList<>(); } super.onBeforeRender(); diff --git a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/WidgetActionsPanel.java b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/WidgetActionsPanel.java index fd97730c7d..41d95e4614 100644 --- a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/WidgetActionsPanel.java +++ b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/WidgetActionsPanel.java @@ -12,6 +12,8 @@ */ package org.wicketstuff.dashboard.web; +import static org.wicketstuff.dashboard.DashboardContextInitializer.getDashboardContext; + import java.util.List; import org.apache.wicket.AttributeModifier; @@ -27,26 +29,21 @@ /** * @author Decebal Suiu */ -public class WidgetActionsPanel extends GenericPanel implements DashboardContextAware { +public class WidgetActionsPanel extends GenericPanel { private static final long serialVersionUID = 1L; - private transient DashboardContext dashboardContext; - public WidgetActionsPanel(String id, IModel model) { super(id, model); IModel> actionsModel = new LoadableDetachableModel>() { - private static final long serialVersionUID = 1L; @Override protected List load() { - return dashboardContext.getWidgetActionsFactory().createWidgetActions(getWidget()); + return getDashboardContext().getWidgetActionsFactory().createWidgetActions(getWidget()); } - }; ListView actionsView = new ListView("action", actionsModel) { - private static final long serialVersionUID = 1L; @Override @@ -57,16 +54,10 @@ protected void populateItem(ListItem item) { link.add(AttributeModifier.replace("title", action.getTooltip())); item.add(link); } - }; add(actionsView); } - @Override - public void setDashboardContext(DashboardContext dashboardContext) { - this.dashboardContext = dashboardContext; - } - private Widget getWidget() { return getModelObject(); } diff --git a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/WidgetHeaderPanel.java b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/WidgetHeaderPanel.java index 52985b179c..2436727a01 100644 --- a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/WidgetHeaderPanel.java +++ b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/WidgetHeaderPanel.java @@ -12,6 +12,8 @@ */ package org.wicketstuff.dashboard.web; +import static org.wicketstuff.dashboard.DashboardContextInitializer.getDashboardContext; + import org.apache.wicket.AttributeModifier; import org.apache.wicket.ajax.AjaxEventBehavior; import org.apache.wicket.ajax.AjaxRequestTarget; @@ -28,11 +30,9 @@ /** * @author Decebal Suiu */ -public class WidgetHeaderPanel extends GenericPanel implements DashboardContextAware { +public class WidgetHeaderPanel extends GenericPanel { private static final long serialVersionUID = 1L; - private transient DashboardContext dashboardContext; - public WidgetHeaderPanel(String id, IModel model) { super(id, model); @@ -53,7 +53,7 @@ protected void onEvent(AjaxRequestTarget target) { // save the new state of widget/dashboard Dashboard dashboard = findParent(DashboardPanel.class).getDashboard(); - dashboardContext.getDashboardPersister().save(dashboard); + getDashboardContext().getDashboardPersister().save(dashboard); // change toggle's image target.add(toggle.add(AttributeModifier.replace("class", getCssClass()))); @@ -80,18 +80,13 @@ public String getObject() { } private String getCssClass() { - return String.format("dragbox-toggle %s", getWidget().isCollapsed() ? "collapsed" : "expanded"); + return "dragbox-toggle " + (getWidget().isCollapsed() ? "collapsed" : "expanded"); } public Widget getWidget() { return getModelObject(); } - @Override - public void setDashboardContext(DashboardContext dashboardContext) { - this.dashboardContext = dashboardContext; - } - @Override public void renderHead(IHeaderResponse response) { super.renderHead(response); diff --git a/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/wicket-package_pt.properties.xml b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/wicket-package_pt.properties.xml new file mode 100644 index 0000000000..b4082cd20f --- /dev/null +++ b/dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/wicket-package_pt.properties.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/dashboard-parent/dashboard-examples/pom.xml b/dashboard-parent/dashboard-examples/pom.xml index 881ca3c971..bfdaa4576e 100644 --- a/dashboard-parent/dashboard-examples/pom.xml +++ b/dashboard-parent/dashboard-examples/pom.xml @@ -7,7 +7,7 @@ org.wicketstuff wicketstuff-dashboard-parent - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-dashboard-examples diff --git a/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/AddWidgetPage.java b/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/AddWidgetPage.java index 7d4f4e5194..55e8a09562 100644 --- a/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/AddWidgetPage.java +++ b/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/AddWidgetPage.java @@ -20,12 +20,10 @@ * @author Decebal Suiu */ public class AddWidgetPage extends WebPage { - private static final long serialVersionUID = 1L; public AddWidgetPage() { Dashboard dashboard = WicketApplication.get().getDashboard(); - add(new AddWidgetPanel("addWidgetPanel", new Model(dashboard))); + add(new AddWidgetPanel("addWidgetPanel", new Model<>(dashboard))); } - } diff --git a/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/AddWidgetPanel.java b/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/AddWidgetPanel.java index d8f837c936..15c5665709 100644 --- a/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/AddWidgetPanel.java +++ b/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/AddWidgetPanel.java @@ -12,6 +12,8 @@ */ package org.wicketstuff.dashboard.examples; +import static org.wicketstuff.dashboard.DashboardContextInitializer.getDashboardContext; + import java.util.List; import org.apache.wicket.ajax.AjaxRequestTarget; @@ -28,46 +30,39 @@ import org.wicketstuff.dashboard.Widget; import org.wicketstuff.dashboard.WidgetDescriptor; import org.wicketstuff.dashboard.WidgetFactory; -import org.wicketstuff.dashboard.web.DashboardContext; -import org.wicketstuff.dashboard.web.DashboardContextAware; import org.wicketstuff.dashboard.web.DashboardEvent; /** * @author Decebal Suiu */ -public class AddWidgetPanel extends GenericPanel implements DashboardContextAware { - +public class AddWidgetPanel extends GenericPanel { private static final long serialVersionUID = 1L; - private transient DashboardContext dashboardContext; - public AddWidgetPanel(String id, IModel model) { super(id, model); add(new BookmarkablePageLink("backDashboard", getApplication().getHomePage())); - List widgetDescriptors = dashboardContext.getWidgetRegistry().getWidgetDescriptors(); + List widgetDescriptors = getDashboardContext().getWidgetRegistry().getWidgetDescriptors(); ListView listView = new ListView("widgetList", widgetDescriptors) { - private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem item) { item.add(new WidgetDescriptorPanel("widget", item.getModel())); } - }; listView.setRenderBodyOnly(true); add(listView); } public Dashboard getDashboard() { + Dashboard dashboard = getDashboardContext().getDashboardPersister().load(); + if (dashboard != null) { + // might be updated + setModelObject(dashboard); + } return getModelObject(); - - } - @Override - public void setDashboardContext(DashboardContext dashboardContext) { - this.dashboardContext = dashboardContext; } private String getUniqueWidgetTitle(String title, int count) { @@ -75,19 +70,15 @@ private String getUniqueWidgetTitle(String title, int count) { if (count > 0) { uniqueTitle = title + " " + count; } - - List widgets = getDashboard().getWidgets(); - for (Widget widget : widgets) { + for (Widget widget : getDashboard().getWidgets()) { if (widget.getTitle().equals(uniqueTitle)) { uniqueTitle = getUniqueWidgetTitle(title, count + 1); } } - return uniqueTitle; } private class WidgetDescriptorPanel extends GenericPanel { - private static final long serialVersionUID = 1L; private String message = ""; @@ -100,7 +91,6 @@ public WidgetDescriptorPanel(String id, final IModel model) { add(new Label("provider", model.getObject().getProvider())); add(new Label("description", model.getObject().getDescription())); final Label label = new Label("message", new LoadableDetachableModel() { - private static final long serialVersionUID = 1L; @Override @@ -108,22 +98,19 @@ protected String load() { if (count == 1) { return message; } - return message + " (" + count + ")"; } - }); label.setOutputMarkupId(true); label.setOutputMarkupPlaceholderTag(true); label.setVisible(false); add(label); AjaxLink addLink = new AjaxLink("addWidget") { - private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { - WidgetFactory widgetFactory = dashboardContext.getWidgetFactory(); + WidgetFactory widgetFactory = getDashboardContext().getWidgetFactory(); Widget widget = widgetFactory.createWidget(model.getObject()); widget.setTitle(getUniqueWidgetTitle(widget.getTitle(), count)); // DashboardPanel is on other page @@ -131,17 +118,14 @@ public void onClick(AjaxRequestTarget target) { Dashboard dashboard = getDashboard(); DashboardUtils.updateWidgetLocations(dashboard, new DashboardEvent(target, DashboardEvent.EventType.WIDGET_ADDED, widget)); dashboard.addWidget(widget); - dashboardContext.getDashboardPersister().save(dashboard); + getDashboardContext().getDashboardPersister().save(dashboard); message = "added"; label.setVisible(true); target.add(label); count++; } - }; add(addLink); } - } - } diff --git a/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/WicketApplication.java b/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/WicketApplication.java index b266773877..0e2f55c355 100644 --- a/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/WicketApplication.java +++ b/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/WicketApplication.java @@ -12,10 +12,11 @@ */ package org.wicketstuff.dashboard.examples; +import static org.wicketstuff.dashboard.DashboardContextInitializer.getDashboardContext; + import org.apache.wicket.Page; import org.apache.wicket.protocol.http.WebApplication; import org.wicketstuff.dashboard.Dashboard; -import org.wicketstuff.dashboard.DashboardContextInitializer; import org.wicketstuff.dashboard.DefaultDashboard; import org.wicketstuff.dashboard.examples.jqplot.DemoChartFactory; import org.wicketstuff.dashboard.examples.justgage.DemoJustGageFactory; @@ -37,8 +38,6 @@ */ public class WicketApplication extends WebApplication { - private Dashboard dashboard; - public static WicketApplication get() { return (WicketApplication) WebApplication.get(); } @@ -78,9 +77,6 @@ public void init() { JustGageWidget.setJustGageFactory(new DemoJustGageFactory()); HighChartsWidget.setHighChartsFactory(new DemoHighChartsFactory()); - // init dashboard from context - initDashboard(); - // <<< end dashboard settings } @@ -101,18 +97,11 @@ public Session newSession(Request request, Response response) { */ public Dashboard getDashboard() { - return dashboard; - } - - private DashboardContext getDashboardContext() { - return getMetaData(DashboardContextInitializer.DASHBOARD_CONTEXT_KEY); - } - - private void initDashboard() { - dashboard = getDashboardContext().getDashboardPersister().load(); + Dashboard dashboard = getDashboardContext().getDashboardPersister().load(); if (dashboard == null) { dashboard = new DefaultDashboard("default", "Default"); } + return dashboard; } } diff --git a/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/jqplot/DemoChartFactory.java b/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/jqplot/DemoChartFactory.java index 1a1362d511..60c4b27b92 100644 --- a/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/jqplot/DemoChartFactory.java +++ b/dashboard-parent/dashboard-examples/src/main/java/org/wicketstuff/dashboard/examples/jqplot/DemoChartFactory.java @@ -18,12 +18,12 @@ import org.wicketstuff.dashboard.widgets.jqplot.ChartFactory; import org.wicketstuff.dashboard.widgets.jqplot.JqPlotWidget; -import br.com.digilabs.jqplot.Chart; -import br.com.digilabs.jqplot.chart.AreaChart; -import br.com.digilabs.jqplot.chart.BarChart; -import br.com.digilabs.jqplot.chart.LineChart; -import br.com.digilabs.jqplot.chart.PieChart; -import br.com.digilabs.jqplot.elements.Serie; +import org.wicketstuff.jqplot.lib.Chart; +import org.wicketstuff.jqplot.lib.chart.AreaChart; +import org.wicketstuff.jqplot.lib.chart.BarChart; +import org.wicketstuff.jqplot.lib.chart.LineChart; +import org.wicketstuff.jqplot.lib.chart.PieChart; +import org.wicketstuff.jqplot.lib.elements.Serie; /** * @author Decebal Suiu diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-charts/pom.xml b/dashboard-parent/dashboard-widgets/dashboard-widgets-charts/pom.xml index 74fe1c4d07..7d62b6f596 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-charts/pom.xml +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-charts/pom.xml @@ -7,7 +7,7 @@ org.wicketstuff wicketstuff-dashboard-widgets - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-dashboard-widgets-charts diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-charts/src/main/java/org/wicketstuff/dashboard/widgets/charts/settings/HighChartsSettingsPanel.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-charts/src/main/java/org/wicketstuff/dashboard/widgets/charts/settings/HighChartsSettingsPanel.java index 55c2fe97af..57419f6cec 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-charts/src/main/java/org/wicketstuff/dashboard/widgets/charts/settings/HighChartsSettingsPanel.java +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-charts/src/main/java/org/wicketstuff/dashboard/widgets/charts/settings/HighChartsSettingsPanel.java @@ -12,7 +12,10 @@ */ package org.wicketstuff.dashboard.widgets.charts.settings; -import com.googlecode.wickedcharts.highcharts.options.SeriesType; +import static org.wicketstuff.dashboard.DashboardContextInitializer.getDashboardContext; + +import java.util.Arrays; + import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.AjaxLink; import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink; @@ -23,22 +26,19 @@ import org.apache.wicket.model.PropertyModel; import org.wicketstuff.dashboard.Dashboard; import org.wicketstuff.dashboard.Widget; -import org.wicketstuff.dashboard.web.DashboardContext; -import org.wicketstuff.dashboard.web.DashboardContextAware; import org.wicketstuff.dashboard.web.DashboardPanel; import org.wicketstuff.dashboard.web.WidgetPanel; import org.wicketstuff.dashboard.widgets.charts.HighChartsWidget; import org.wicketstuff.dashboard.widgets.charts.HighChartsWidgetView; -import java.util.Arrays; +import com.googlecode.wickedcharts.highcharts.options.SeriesType; /** * @author Paul Bors */ -public class HighChartsSettingsPanel extends GenericPanel implements DashboardContextAware { +public class HighChartsSettingsPanel extends GenericPanel { private static final long serialVersionUID = 1L; - private transient DashboardContext dashboardContext; private SeriesType seriesType; public HighChartsSettingsPanel(String id, IModel model) { @@ -46,23 +46,24 @@ public HighChartsSettingsPanel(String id, IModel model) { setOutputMarkupPlaceholderTag(true); - Form form = new Form("form"); + Form form = new Form<>("form"); add(form); seriesType = SeriesType.valueOf(getModelObject().getSettings().get(Settings.seriesType.name())); - DropDownChoice choice = new DropDownChoice(Settings.seriesType.name(), + DropDownChoice choice = new DropDownChoice<>(Settings.seriesType.name(), new PropertyModel(this, Settings.seriesType.name()), Arrays.asList(SeriesType.values())); form.add(choice); form.add(new AjaxSubmitLink("submit") { private static final long serialVersionUID = 1L; + @Override protected void onSubmit(AjaxRequestTarget target) { getModelObject().getSettings().put(Settings.seriesType.name(), seriesType.name()); getModelObject().updateChart(); Dashboard dashboard = findParent(DashboardPanel.class).getDashboard(); - dashboardContext.getDashboardPersister().save(dashboard); + getDashboardContext().getDashboardPersister().save(dashboard); hideSettingPanel(target); @@ -89,11 +90,6 @@ public void onClick(AjaxRequestTarget target) { } - @Override - public void setDashboardContext(DashboardContext dashboardContext) { - this.dashboardContext = dashboardContext; - } - private void hideSettingPanel(AjaxRequestTarget target) { setVisible(false); target.add(this); diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/pom.xml b/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/pom.xml index 8f40cc48cd..e1550868bc 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/pom.xml +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/pom.xml @@ -7,7 +7,7 @@ org.wicketstuff wicketstuff-dashboard-widgets - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-dashboard-widgets-jqplot diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/ChartContainer.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/ChartContainer.java index 0d9e205fb4..70d1c06ec7 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/ChartContainer.java +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/ChartContainer.java @@ -27,8 +27,8 @@ import org.apache.wicket.resource.JQueryPluginResourceReference; import org.wicketstuff.jqplot.behavior.JqPlotBehavior; -import br.com.digilabs.jqplot.Chart; -import br.com.digilabs.jqplot.JqPlotUtils; +import org.wicketstuff.jqplot.lib.Chart; +import org.wicketstuff.jqplot.lib.JqPlotUtils; /** * @author Decebal Suiu diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/ChartFactory.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/ChartFactory.java index 4019ff75c2..609a34039a 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/ChartFactory.java +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/ChartFactory.java @@ -12,7 +12,7 @@ */ package org.wicketstuff.dashboard.widgets.jqplot; -import br.com.digilabs.jqplot.Chart; +import org.wicketstuff.jqplot.lib.Chart; /** * @author Decebal Suiu diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/JqPlotSettingsPanel.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/JqPlotSettingsPanel.java index b457d9a065..3a42600dc5 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/JqPlotSettingsPanel.java +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/JqPlotSettingsPanel.java @@ -12,6 +12,8 @@ */ package org.wicketstuff.dashboard.widgets.jqplot; +import static org.wicketstuff.dashboard.DashboardContextInitializer.getDashboardContext; + import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.AjaxLink; import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink; @@ -22,19 +24,15 @@ import org.apache.wicket.model.PropertyModel; import org.wicketstuff.dashboard.Dashboard; import org.wicketstuff.dashboard.Widget; -import org.wicketstuff.dashboard.web.DashboardContext; -import org.wicketstuff.dashboard.web.DashboardContextAware; import org.wicketstuff.dashboard.web.DashboardPanel; import org.wicketstuff.dashboard.web.WidgetPanel; /** * @author Decebal Suiu */ -public class JqPlotSettingsPanel extends GenericPanel implements DashboardContextAware { - +public class JqPlotSettingsPanel extends GenericPanel { private static final long serialVersionUID = 1L; - private transient DashboardContext dashboardContext; private String chartType; public JqPlotSettingsPanel(String id, IModel model) { @@ -42,22 +40,21 @@ public JqPlotSettingsPanel(String id, IModel model) { setOutputMarkupPlaceholderTag(true); - Form form = new Form("form"); + Form form = new Form<>("form"); chartType = getModelObject().getSettings().get("chartType"); // chartType = ChartWidget.BAR_TYPE; - DropDownChoice choice = new DropDownChoice("chartType", + DropDownChoice choice = new DropDownChoice<>("chartType", new PropertyModel(this, "chartType"), JqPlotWidget.TYPES); form.add(choice); form.add(new AjaxSubmitLink("submit") { - private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target) { getModelObject().getSettings().put("chartType", chartType); Dashboard dashboard = findParent(DashboardPanel.class).getDashboard(); - dashboardContext.getDashboardPersister().save(dashboard); + getDashboardContext().getDashboardPersister().save(dashboard); hideSettingPanel(target); // TODO @@ -69,17 +66,14 @@ protected void onSubmit(AjaxRequestTarget target) { @Override protected void onError(AjaxRequestTarget target) { } - }); form.add(new AjaxLink("cancel") { - private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { hideSettingPanel(target); } - }); add(form); @@ -93,14 +87,8 @@ public void setChartType(String chartType) { this.chartType = chartType; } - @Override - public void setDashboardContext(DashboardContext dashboardContext) { - this.dashboardContext = dashboardContext; - } - private void hideSettingPanel(AjaxRequestTarget target) { setVisible(false); target.add(this); } - } diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/JqPlotWidget.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/JqPlotWidget.java index ea8b653dd9..51fb44420f 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/JqPlotWidget.java +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/JqPlotWidget.java @@ -21,7 +21,7 @@ import org.wicketstuff.dashboard.Widget; import org.wicketstuff.dashboard.web.WidgetView; -import br.com.digilabs.jqplot.Chart; +import org.wicketstuff.jqplot.lib.Chart; /** * @author Decebal Suiu diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/JqPlotWidgetView.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/JqPlotWidgetView.java index 66fba30bb4..846b980c26 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/JqPlotWidgetView.java +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-jqplot/src/main/java/org/wicketstuff/dashboard/widgets/jqplot/JqPlotWidgetView.java @@ -18,7 +18,7 @@ import org.wicketstuff.dashboard.Widget; import org.wicketstuff.dashboard.web.WidgetView; -import br.com.digilabs.jqplot.Chart; +import org.wicketstuff.jqplot.lib.Chart; /** * @author Decebal Suiu diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-justgage/pom.xml b/dashboard-parent/dashboard-widgets/dashboard-widgets-justgage/pom.xml index b6e8235e2e..7769254164 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-justgage/pom.xml +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-justgage/pom.xml @@ -7,7 +7,7 @@ org.wicketstuff wicketstuff-dashboard-widgets - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-dashboard-widgets-justgage diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-loremipsum/pom.xml b/dashboard-parent/dashboard-widgets/dashboard-widgets-loremipsum/pom.xml index 1f5eef2087..3d97dc89cb 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-loremipsum/pom.xml +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-loremipsum/pom.xml @@ -7,7 +7,7 @@ org.wicketstuff wicketstuff-dashboard-widgets - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-dashboard-widgets-loremipsum diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/pom.xml b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/pom.xml index 96cd4d2874..3c2804268f 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/pom.xml +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/pom.xml @@ -7,19 +7,11 @@ org.wicketstuff wicketstuff-dashboard-widgets - 8.0.0-SNAPSHOT + 8.18.0-SNAPSHOT wicketstuff-dashboard-widgets-ofchart jar Wicketstuff OpenFlashChart Widget - - - - ro.nextreports - jofc2 - ${jofc2.version} - - diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/ChartSettingsPanel.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/ChartSettingsPanel.java index 9d379837d7..1402785a2e 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/ChartSettingsPanel.java +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/ChartSettingsPanel.java @@ -12,6 +12,8 @@ */ package org.wicketstuff.dashboard.widgets.ofchart; +import static org.wicketstuff.dashboard.DashboardContextInitializer.getDashboardContext; + import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.AjaxLink; import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink; @@ -22,19 +24,15 @@ import org.apache.wicket.model.PropertyModel; import org.wicketstuff.dashboard.Dashboard; import org.wicketstuff.dashboard.Widget; -import org.wicketstuff.dashboard.web.DashboardContext; -import org.wicketstuff.dashboard.web.DashboardContextAware; import org.wicketstuff.dashboard.web.DashboardPanel; import org.wicketstuff.dashboard.web.WidgetPanel; /** * @author Decebal Suiu */ -public class ChartSettingsPanel extends GenericPanel implements DashboardContextAware { - +public class ChartSettingsPanel extends GenericPanel { private static final long serialVersionUID = 1L; - private transient DashboardContext dashboardContext; private String chartType; public ChartSettingsPanel(String id, IModel model) { @@ -42,22 +40,21 @@ public ChartSettingsPanel(String id, IModel model) { setOutputMarkupPlaceholderTag(true); - Form form = new Form("form"); + Form form = new Form<>("form"); chartType = getModelObject().getSettings().get("chartType"); // chartType = ChartWidget.BAR_TYPE; - DropDownChoice choice = new DropDownChoice("chartType", + DropDownChoice choice = new DropDownChoice<>("chartType", new PropertyModel(this, "chartType"), ChartWidget.TYPES); form.add(choice); form.add(new AjaxSubmitLink("submit") { - private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target) { getModelObject().getSettings().put("chartType", chartType); Dashboard dashboard = findParent(DashboardPanel.class).getDashboard(); - dashboardContext.getDashboardPersister().save(dashboard); + getDashboardContext().getDashboardPersister().save(dashboard); hideSettingPanel(target); // TODO @@ -69,17 +66,14 @@ protected void onSubmit(AjaxRequestTarget target) { @Override protected void onError(AjaxRequestTarget target) { } - }); form.add(new AjaxLink("cancel") { - private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { hideSettingPanel(target); } - }); add(form); @@ -93,14 +87,8 @@ public void setChartType(String chartType) { this.chartType = chartType; } - @Override - public void setDashboardContext(DashboardContext dashboardContext) { - this.dashboardContext = dashboardContext; - } - private void hideSettingPanel(AjaxRequestTarget target) { setVisible(false); target.add(this); } - } diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/OpenFlashChart.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/OpenFlashChart.java index e2417db66f..135f9cd8d8 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/OpenFlashChart.java +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/OpenFlashChart.java @@ -1,11 +1,11 @@ /* * Copyright 2012 Decebal Suiu - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with * the License. You may obtain a copy of the License in the LICENSE file, or 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. @@ -24,10 +24,10 @@ /** * http://cwiki.apache.org/WICKET/open-flash-chart-and-wicket.html */ -public class OpenFlashChart extends GenericPanel { +public class OpenFlashChart extends GenericPanel { private static final long serialVersionUID = 1L; - + private String width; private String height; private SWFObject swf; @@ -42,31 +42,29 @@ public OpenFlashChart(String id, String width, String height, IModel mod @Override public void renderHead(IHeaderResponse response) { super.renderHead(response); - + response.render(JavaScriptHeaderItem.forReference(new PackageResourceReference(OpenFlashChart.class, "res/saveChartImage.js"))); } - + @Override protected void onInitialize() { super.onInitialize(); - + String swfUrl = toAbsolutePath(urlFor(new PackageResourceReference(OpenFlashChart.class, "res/open-flash-chart.swf"), null).toString()); - + // see http://ofc2dz.com/OFC2/downloads/ofc2Downloads.html // http://ofc2dz.com/OFC2/examples/MiscellaneousPatches.html (Passing the Char Parameter "ID" when saving images (23-Feb-2009)) swfUrl = swfUrl.concat("?id=").concat(getMarkupId()); -// System.out.println("swfUrl = " + swfUrl); swf = new SWFObject(swfUrl, width, height, "9.0.0"); add(swf); } - + @Override protected void onBeforeRender() { String jsonUrl = getUrlForJson(); -// System.out.println("jsonUrl = " + jsonUrl); - swf.addParameter("data-file", jsonUrl); + swf.addParameter("data-file", jsonUrl); swf.addParameter("wmode", "transparent"); - + super.onBeforeRender(); } @@ -74,12 +72,13 @@ private String getUrlForJson() { PageParameters parameters = new PageParameters(); parameters.add("widgetId", getModelObject().getId()); String jsonUrl = urlFor(new DataResourceReference(), parameters).toString(); - - return toAbsolutePath(jsonUrl); + + //return toAbsolutePath(jsonUrl); + return urlFor(new DataResourceReference(), parameters).toString(); } private String toAbsolutePath(String relativePath) { return getRequestCycle().getUrlRenderer().renderFullUrl(Url.parse(relativePath)); - } - + } + } diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/SWFObject.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/SWFObject.java index cbea5ddc98..e4a45b8919 100644 --- a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/SWFObject.java +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/SWFObject.java @@ -25,6 +25,8 @@ import org.apache.wicket.request.cycle.RequestCycle; import org.apache.wicket.request.resource.PackageResourceReference; +import com.github.openjson.JSONObject; + /** * http://cwiki.apache.org/WICKET/open-flash-chart-and-wicket.html */ @@ -32,8 +34,8 @@ public class SWFObject extends Behavior { private static final long serialVersionUID = 1L; - private Map parameters = new HashMap(); - private Map attributes = new HashMap(); + private Map parameters = new HashMap<>(); + private Map attributes = new HashMap<>(); private String version; private String flashUrl; @@ -119,26 +121,7 @@ protected Map getAttributes() { } private String buildDataObject(Map data) { - String quote = "\""; - if ((data != null) && !data.isEmpty()) { - StringBuilder result = new StringBuilder(); - int size = getParameters().entrySet().size(); - int count = 0; - for (Map.Entry e : getParameters().entrySet()) { - result.append("{"); - result.append(quote).append(e.getKey()).append(quote). - append(":"). - append(quote).append(e.getValue()).append(quote); - result.append("}"); - if (count < size-1) { - result.append(","); - } - count++; - } - return result.toString(); - } - - return "{}"; + JSONObject obj = data == null ? new JSONObject() : new JSONObject(data); + return obj.toString(); } - -} \ No newline at end of file +} diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/res/open-flash-chart.swf b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/res/open-flash-chart.swf index 255c25ae98..3a01e52aee 100644 Binary files a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/res/open-flash-chart.swf and b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/res/open-flash-chart.swf differ diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/res/open-flash-chart.swf.bad b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/res/open-flash-chart.swf.bad deleted file mode 100644 index 2684e04e53..0000000000 Binary files a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/org/wicketstuff/dashboard/widgets/ofchart/res/open-flash-chart.swf.bad and /dev/null differ diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/NullAwareJsonWriter.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/NullAwareJsonWriter.java new file mode 100644 index 0000000000..dc9dd10dfc --- /dev/null +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/NullAwareJsonWriter.java @@ -0,0 +1,20 @@ +package ro.nextreports.jofc2; + +import java.io.Writer; + +import com.thoughtworks.xstream.io.json.JsonWriter; + +public class NullAwareJsonWriter extends JsonWriter { + public NullAwareJsonWriter(Writer writer) { + super(writer); + } + + @Override + protected void addValue(String value, Type type) { + if (type == Type.STRING && value == null) { + writer.write("null"); + } else { + super.addValue(value, type); + } + } +} diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/OFC.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/OFC.java new file mode 100644 index 0000000000..8d1928ee0a --- /dev/null +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/OFC.java @@ -0,0 +1,245 @@ +/* +This file is part of jofc2. + +jofc2 is free software: you can redistribute it and/or modify +it under the terms of the Lesser GNU General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +jofc2 is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +See . + */ +package ro.nextreports.jofc2; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import com.github.openjson.JSONException; +import com.github.openjson.JSONObject; +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.converters.ConverterMatcher; +import com.thoughtworks.xstream.converters.SingleValueConverter; + +import ro.nextreports.jofc2.model.Chart; +import ro.nextreports.jofc2.model.Text; +import ro.nextreports.jofc2.model.axis.Axis; +import ro.nextreports.jofc2.model.axis.Label; +import ro.nextreports.jofc2.model.axis.XAxis; +import ro.nextreports.jofc2.model.axis.XAxisLabels; +import ro.nextreports.jofc2.model.axis.YAxis; +import ro.nextreports.jofc2.model.elements.AnimatedElement; +import ro.nextreports.jofc2.model.elements.AreaHollowChart; +import ro.nextreports.jofc2.model.elements.BarChart; +import ro.nextreports.jofc2.model.elements.Element; +import ro.nextreports.jofc2.model.elements.FilledBarChart; +import ro.nextreports.jofc2.model.elements.HorizontalBarChart; +import ro.nextreports.jofc2.model.elements.LineChart; +import ro.nextreports.jofc2.model.elements.NullElement; +import ro.nextreports.jofc2.model.elements.PieChart; +import ro.nextreports.jofc2.model.elements.ScatterChart; +import ro.nextreports.jofc2.model.elements.ShapeChart; +import ro.nextreports.jofc2.model.elements.SketchBarChart; +import ro.nextreports.jofc2.model.elements.StackedBarChart; +import ro.nextreports.jofc2.model.elements.Tooltip; +import ro.nextreports.jofc2.model.metadata.Alias; +import ro.nextreports.jofc2.model.metadata.Converter; + +/** + *

+ * This is the class responsible for converting a Chart object into the JSON + * string which feeds the charting widget. There is no need to make explicit use + * of this class, but if necessary, there are several ways to do so: + *

+ *
    + *
  1. The "instance" field contains a static instance of an OFC object.
  2. + *
  3. The Chart object overrides toString() and uses this instance to render + * itself.
  4. + *
  5. For tricky threading situations, you may prefer to create and manage + * instances of OFC yourself.
  6. + *
+ *

+ * Theoretically, XStream (the JSON conversion library used here) is + * thread-safe, but it does not hurt to have the option to synchronize or to + * have thread local instances, whatever may be necessary. + *

+ */ +public class OFC { + + private static final Class[] models = new Class[] { + Axis.class, + Text.class, + XAxis.class, + YAxis.class, + XAxisLabels.class, + Label.class, + Element.class, + Axis.class, + BarChart.class, + PieChart.class, + HorizontalBarChart.class, + LineChart.class, + ScatterChart.class, + AreaHollowChart.class, + PieChart.Slice.class, + HorizontalBarChart.Bar.class, + Label.Rotation.class, + ScatterChart.Point.class, + FilledBarChart.class, + SketchBarChart.class, + StackedBarChart.class, + StackedBarChart.StackValue.class, + StackedBarChart.Stack.class, + StackedBarChart.Key.class, + BarChart.Bar.class, + FilledBarChart.Bar.class, + SketchBarChart.Bar.class, + LineChart.Dot.class, + LineChart.Style.class, + NullElement.class, + Chart.class, + ShapeChart.class, + ShapeChart.Point.class, + Tooltip.class, + Tooltip.Type.class, + AnimatedElement.class, + AnimatedElement.OnShow.class + }; + private final XStream converter = new XStream(new OFCJSONDriver()); + + /** + * Sole constructor. + */ + public OFC() { + for (Class c : models) { + doAlias(c); + doRegisterConverter(c); + } + } + + public static OFC getInstance() { + return LazyInstance.instance; + } + + private void doAlias(Class c) { + if (c.isAnnotationPresent(Alias.class)) { + converter.alias(c.getAnnotation(Alias.class).value(), c); + } + for (Field f : c.getDeclaredFields()) { + if (f.isAnnotationPresent(Alias.class)) { + converter.aliasField(f.getAnnotation(Alias.class).value(), c, f.getName()); + } + } + } + + private void doRegisterConverter(Class c) { + if (c.isAnnotationPresent(Converter.class)) { + Class clazz = c.getAnnotation(Converter.class).value(); + try { + if (SingleValueConverter.class.isAssignableFrom(clazz)) { + converter.registerConverter((SingleValueConverter) clazz.newInstance()); + } else { + converter.registerConverter((com.thoughtworks.xstream.converters.Converter) clazz.newInstance()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + /** + * Use this method in your applications to send data back to the chart + * widget. + * + * @param c + * the chart to render + * @throws OFCException + * when rendering fails + * @return the JSONified chart data + */ + public String render(Chart c) throws OFCException { + String json = converter.toXML(c); + try { + return new JSONObject(json).getString(Chart.class.getName()); + } catch (JSONException je) { + throw new OFCException(json, je); + } + } + + /** + * Use this method for debugging purposes. + * + * @param c + * the chart to render + * @param indentationLevel + * number of spaces to use for indentation + * @throws OFCException + * when rendering fails + * @return pretty-printed JSONified chart data + */ + public String prettyPrint(Chart c, int indentationLevel) throws OFCException { + String json = converter.toXML(c); + try { + return new JSONObject(json).getJSONObject(Chart.class.getName()) + .toString(indentationLevel); + } catch (JSONException je) { + throw new OFCException(json, je); + } + } + + /** + * Convenience method for converting Collections to Arrays. You can use this + * where the API has limited support for collections: + * getLabels().addLabels(OFC.toArray(stringList, String.class)); + * + * @param collection + * The collection to use + * @param type + * The supertype for the collection. This will commonly be Integer, + * Number, etc. + * @return the array of the collection + */ + @SuppressWarnings("unchecked") + public static T[] toArray(Collection collection, Class type) { + return collection.toArray((T[]) Array.newInstance(type, collection.size())); + } + + /** + * Convenience method to generate labels from a collection of Objects, if so + * desired. + * + * @param source + * the source collection holding Objects. + * @return a collection of all the objects toString() method invoked + */ + public static List stringify(List source) { + List strings = new ArrayList(source.size()); + for (Object o : source) { + strings.add(o.toString()); + } + return strings; + } + + /** + * Convenience method to generate labels from an array of disparate Objects. + * + * @param objects + * the array of objects to convert + * @return a collection of all the objects toString() result + */ + public static String[] stringify(Object... objects) { + return stringify(Arrays.asList(objects)).toArray(new String[objects.length]); + } +} + +class LazyInstance { + + protected static final OFC instance = new OFC(); +} diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/OFCException.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/OFCException.java new file mode 100644 index 0000000000..5672face29 --- /dev/null +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/OFCException.java @@ -0,0 +1,33 @@ +/* +This file is part of jofc2. + +jofc2 is free software: you can redistribute it and/or modify +it under the terms of the Lesser GNU General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +jofc2 is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +See . +*/ + +package ro.nextreports.jofc2; + +public class OFCException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public OFCException(Throwable t) { + super(t); + } + + public OFCException(String message) { + super(message); + } + + public OFCException(String message, Throwable t) { + super(message, t); + } +} diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/OFCJSONDriver.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/OFCJSONDriver.java new file mode 100644 index 0000000000..ec2390a85a --- /dev/null +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/OFCJSONDriver.java @@ -0,0 +1,14 @@ +package ro.nextreports.jofc2; + +import java.io.Writer; + +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver; + +public class OFCJSONDriver extends JsonHierarchicalStreamDriver { + + @Override + public HierarchicalStreamWriter createWriter(Writer out) { + return new NullAwareJsonWriter(out); + } +} diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/Chart.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/Chart.java new file mode 100644 index 0000000000..655b84a0d8 --- /dev/null +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/Chart.java @@ -0,0 +1,330 @@ +/* +This file is part of jofc2. + +jofc2 is free software: you can redistribute it and/or modify +it under the terms of the Lesser GNU General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +jofc2 is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +See . + */ +package ro.nextreports.jofc2.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; + +import ro.nextreports.jofc2.OFC; +import ro.nextreports.jofc2.OFCException; +import ro.nextreports.jofc2.model.axis.XAxis; +import ro.nextreports.jofc2.model.axis.YAxis; +import ro.nextreports.jofc2.model.elements.Element; +import ro.nextreports.jofc2.model.elements.Legend; +import ro.nextreports.jofc2.model.elements.Tooltip; + +/** + * This is the most important class in the Java OFC library. Start here, + * configuring the title, axes, legends, labels, and draw-able elements in your + * chart. Coerce the object to a String with the toString() method to get the + * chart data back out. + */ +public class Chart implements Serializable { + + private static final long serialVersionUID = -1868082240169089976L; + private Text title; + private XAxis x_axis; + private YAxis y_axis; + private YAxis y_axis_right; + private Text y_legend; + private Text x_legend; + private String bg_colour; + private int is_decimal_separator_comma = 0; + private int is_fixed_num_decimals_forced = 0; + private int is_thousand_separator_disabled = 0; + private int num_decimals = 2; + private Collection elements = new ArrayList(); + private Legend legend; + private Tooltip tooltip; + private String inner_bg_colour; + + public XAxis getXAxis() { + return x_axis; + } + + public Chart() { + //nothing... + } + + public Chart(String titleText) { + this(titleText, null); + } + + public Chart(String titleText, String style) { + this.setTitle(new Text(titleText, style)); + } + + public Tooltip getTooltip() + { + return tooltip; + } + + public void setTooltip(Tooltip tooltip) + { + this.tooltip = tooltip; + } + + public Chart setXAxis(XAxis x_axis) { + this.x_axis = x_axis; + return this; + } + + public YAxis getYAxis() { + return y_axis; + } + + public Chart setYAxis(YAxis y_axis) { + this.y_axis = y_axis; + return this; + } + + public Chart setYAxisRight(YAxis y_axis_right) { + this.y_axis_right = y_axis_right; + return this; + } + + public YAxis getYAxisRight() { + return y_axis_right; + } + + public Text getTitle() { + return title; + } + + public Chart setTitle(Text title) { + this.title = title; + return this; + } + + public Text getXLegend() { + return x_legend; + } + + public Chart setXLegend(Text x_legend) { + this.x_legend = x_legend; + return this; + } + + public Text getYLegend() { + return y_legend; + } + + public Chart setYLegend(Text y_legend) { + this.y_legend = y_legend; + return this; + } + + public String getBackgroundColour() { + return bg_colour; + } + + public Chart setBackgroundColour(String bg_colour) { + this.bg_colour = bg_colour; + return this; + } + + public Collection getElements() { + return elements; + } + + public Chart setElements(Collection elements) { + this.elements.clear(); + this.elements.addAll(elements); + return this; + } + + public Chart addElements(Element... e) { + elements.addAll(Arrays.asList(e)); + return this; + } + + public Chart addElements(Collection coll) { + elements.addAll(coll); + return this; + } + + public boolean removeElement(Element e) { + return elements.remove(e); + } + + public Element getElementByText(String text) { + for (Element e : getElements()) { + if (text.equals(e.getText())) return e; + } + return null; + } + + /** + * @throws OFCException can throw an OFCException if there is a problem + * rendering this Chart object. This exception would indicate an issue with + * the ro.nextreports.jofc2 library itself. + */ + @Override + public String toString() throws OFCException { + return OFC.getInstance().render(this); + } + + /** + * @return a well formatted JSON File which is much more easy for debugging + * (toString() returns only one line) + */ + public String toDebugString() { + return OFC.getInstance().prettyPrint(this, 3); + } + + /** + * @return true if a comma is used as decimal separator and + * false if a dot is used as decimal separator. + */ + public boolean isDecimalSeparatorComma() { + return is_decimal_separator_comma == 1; + } + + /** + * Configures the symbols used to format decimal numbers. If the given value + * is false the American format (e.g. 1,234.45) is used. If the + * given value is true the German format (1.234,45) is used. + * Other formats like the French one are not yet supported by OFC. + * + * @param is_decimal_separator_comma + * true sets the decimal format to German, + * false to American. + */ + public void setDecimalSeparatorIsComma(boolean is_decimal_separator_comma) { + this.is_decimal_separator_comma = is_decimal_separator_comma ? 1 : 0; + } + + /** + * @return true if decimals are fixed to num_decimals and + * false if not. + */ + public boolean isFixedNumDecimalsForced() { + return is_fixed_num_decimals_forced == 1; + } + + /** + * Configures OFC to use fixed decimals (with num_decimals length). E.g. + * num_decimals=2 for true 1.1 will be 1.10 or 1 will be 1.00, + * for false 1.1 remains 1.1 and 1 remains 1 + * + * @param is_fixed_num_decimals_forced + * true sets OFC to use fixed decimal length + * false switches off fixed decimal length + */ + public void setFixedNumDecimalsForced(boolean is_fixed_num_decimals_forced) { + this.is_fixed_num_decimals_forced = is_fixed_num_decimals_forced ? 1 : 0; + } + + /** + * @return true if thousand separators are used (e.g. 1.000 or + * 1,000... depending on is_decimal_separator_comma), + * false otherwise. + */ + public boolean isThousandSeparatorDisabled() { + return is_thousand_separator_disabled == 1; + } + + /** + * @param is_thousand_separator_disabled + * true turns on the thousand separator (e.g. 1.000 or 1,000... + * depending on is_decimal_separator_comma) + * false turns of the thousand separator (e.g. 1000) + */ + public void setThousandSeparatorDisabled(boolean is_thousand_separator_disabled) { + this.is_thousand_separator_disabled = is_thousand_separator_disabled ? 1 : 0; + } + + /** + * @return the max number of decimals printed out in OFC.
+ */ + public int getNumDecimals() { + return num_decimals; + } + + /** + * @param num_decimals the max number of decimals printed out in OFC.
+ * Allowed values 0 - 16.
+ */ + public void setNumDecimals(int num_decimals) { + this.num_decimals = num_decimals; + } + + public void computeYAxisRange(int steps) { + Double min = null; + double max = 0; + double stepWidth = 1; + if (getElements() != null) { + if (getYAxis() == null) { + YAxis ya = new YAxis(); + this.setYAxis(ya); + } + for (Element e : getElements()) { + max = Math.max(max, e.getMaxValue()); + min = nullSafeMin(min, e.getMinValue()); + } + if (min == null) { + min = 0.0; + } + stepWidth = getStepWidth(Math.abs(max - min), steps); + min = Math.floor(min / stepWidth) * stepWidth; + max = Math.ceil(max / stepWidth) * stepWidth; + getYAxis().setRange(min, max, stepWidth); + + } + } + + private Double nullSafeMin(Double min, double doubleValue) { + if (null == min) { + min = doubleValue; + } + min = Math.min(min, doubleValue); + return min; + } + + private double getStepWidth(double distance, int steps) { + double result = distance / steps; + double exponent = Math.floor(Math.log10(result))+1; + result = result / Math.pow(10, exponent); + if (result > 0.5) { + result = 1; + } else if (result > 0.25) { + result = 0.5; + } else { + result = 0.25; + } + return result * Math.pow(10, exponent); + } + + + public Legend getLegend() { + return legend; + } + + + public void setLegend(Legend legend) { + this.legend = legend; + } + + public void setInnerBackgroundColour(String inner_bg_colour) { + this.inner_bg_colour = inner_bg_colour; + } + + public String getInnerBackgroundColour() { + return inner_bg_colour; + } +} diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/Text.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/Text.java new file mode 100644 index 0000000000..51bdfd1f16 --- /dev/null +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/Text.java @@ -0,0 +1,86 @@ +/* +This file is part of jofc2. + +jofc2 is free software: you can redistribute it and/or modify +it under the terms of the Lesser GNU General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +jofc2 is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +See . + */ +package ro.nextreports.jofc2.model; + +import java.io.Serializable; + +public class Text implements Serializable { + + /** + * + */ + public static final String TEXT_ALIGN_CENTER = "center"; + public static final String TEXT_ALIGN_LEFT = "left"; + public static final String TEXT_ALIGN_RIGHT = "right"; + private static final long serialVersionUID = -2390229886841547192L; + private String text; + private String style; + + public Text() { + this(null, null); + } + + public Text(String text) { + this(text, null); + } + + public Text(String text, String style) { + setText(text); + setStyle(style); + } + + public String getText() { + return text; + } + + public Text setText(String text) { + this.text = text; + return this; + } + + public String getStyle() { + return style; + } + + public Text setStyle(String style) { + this.style = style; + return this; + } + + public static String createStyle(int fontsize, String color, String textalign) { + StringBuilder sb = new StringBuilder(); + if (fontsize != 0) { + sb.append("font-size: "); + sb.append(fontsize); + sb.append("px;"); + } + if (color != null) { + sb.append("color: "); + sb.append(color); + sb.append(";"); + } + if (textalign != null) { + sb.append("text-align: "); + sb.append(textalign); + sb.append(";"); + } + return sb.toString(); + } + + public static String createStyle(int fontsize){ + return createStyle(fontsize, null, null); + } +} diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/axis/Axis.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/axis/Axis.java new file mode 100644 index 0000000000..fd1b43559a --- /dev/null +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/axis/Axis.java @@ -0,0 +1,119 @@ +/* +This file is part of jofc2. + +jofc2 is free software: you can redistribute it and/or modify +it under the terms of the Lesser GNU General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +jofc2 is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +See . +*/ + +package ro.nextreports.jofc2.model.axis; + +import java.io.Serializable; + +import ro.nextreports.jofc2.model.metadata.Alias; + + +public abstract class Axis implements Serializable{ + /** + * + */ + private static final long serialVersionUID = 4823643361437691998L; + private Integer stroke; + private String colour; + @Alias("grid-colour") private String grid_colour; + private Double steps; + private Integer offset; + @Alias("3d") private Integer threed; + private Double min; + private Double max; + + + public Integer getStroke() { + return stroke; + } + public Axis setStroke(Integer stroke) { + this.stroke = stroke; + return this; + } + public String getColour() { + return colour; + } + public Axis setColour(String colour) { + this.colour = colour; + return this; + } + public String getGridColour() { + return grid_colour; + } + public Axis setGridColour(String grid_colour) { + this.grid_colour = grid_colour; + return this; + } + public Double getSteps() { + return steps; + } + public Axis setSteps(Double steps) { + this.steps = steps; + return this; + } + public Axis setSteps(Integer steps) { + this.steps = steps.doubleValue(); + return this; + } + public Integer getOffset() { + return offset; + } + public Axis setOffset(Boolean offset) { + if (offset == null) this.offset = null; + else this.offset = offset ? 1 : 0; + return this; + } + public Integer get3D() { + return threed; + } + public Axis set3D(Integer threed) { + this.threed = threed; + return this; + } + public Double getMin() { + return min; + } + public Axis setMin(Double min) { + this.min = min; + return this; + } + public Axis setMin(Integer min) { + this.min = min.doubleValue(); + return this; + } + public Double getMax() { + return max; + } + public Axis setMax(Double max) { + this.max = max; + return this; + } + public Axis setMax(Integer max) { + this.max = max.doubleValue(); + return this; + } + public Axis setRange(Number min, Number max, Number steps) { + setMin(min.doubleValue()); + setMax(max.doubleValue()); + setSteps(steps == null ? null : steps.doubleValue()); + return this; + } + + public Axis setRange(Number min, Number max) { + return setRange(min, max, getSteps()); + } + +} diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/axis/Label.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/axis/Label.java new file mode 100644 index 0000000000..15758134d1 --- /dev/null +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/axis/Label.java @@ -0,0 +1,106 @@ +/* +This file is part of jofc2. + +jofc2 is free software: you can redistribute it and/or modify +it under the terms of the Lesser GNU General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +jofc2 is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +See . + */ +package ro.nextreports.jofc2.model.axis; + +import java.io.Serializable; + +import ro.nextreports.jofc2.model.metadata.Converter; +import ro.nextreports.jofc2.util.RotationConverter; + +public class Label implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -6976582830606939527L; + /** + * + */ + private String text; + private String colour; + private Integer size; + private Rotation rotate; + private Boolean visible; + + @Converter(RotationConverter.class) + public static enum Rotation { + VERTICAL(-90), HALF_DIAGONAL(-24), DIAGONAL(-45), HORIZONTAL(0); + + private final int degrees; + + Rotation(int degrees) { + this.degrees = degrees; + } + + @Override + public String toString() { + return String.valueOf(degrees); + } + } + + public Label() { + this(null); + } + + public Label(String text) { + setText(text); + } + + public String getText() { + return text; + } + + public Label setText(String text) { + this.text = text; + return this; + } + + public String getColour() { + return colour; + } + + public Label setColour(String colour) { + this.colour = colour; + return this; + } + + public Integer getSize() { + return size; + } + + public Label setSize(Integer size) { + this.size = size; + return this; + } + + public Rotation getRotation() { + return rotate; + } + + public Label setRotation(Rotation rotate) { + this.rotate = rotate; + return this; + } + + public Boolean getVisible() { + return visible; + } + + public Label setVisible(Boolean visible) { + this.visible = visible; + return this; + } +} diff --git a/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/axis/XAxis.java b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/axis/XAxis.java new file mode 100644 index 0000000000..15e7ee34bc --- /dev/null +++ b/dashboard-parent/dashboard-widgets/dashboard-widgets-ofchart/src/main/java/ro/nextreports/jofc2/model/axis/XAxis.java @@ -0,0 +1,74 @@ +/* +This file is part of jofc2. + +jofc2 is free software: you can redistribute it and/or modify +it under the terms of the Lesser GNU General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +jofc2 is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +See . +*/ + +package ro.nextreports.jofc2.model.axis; + +import java.util.List; + +import ro.nextreports.jofc2.model.metadata.Alias; + + +public class XAxis extends Axis { + /** + * + */ + private static final long serialVersionUID = -7007897621631089309L; + @Alias("tick-height") private Integer tick_height; + private XAxisLabels labels = new XAxisLabels(); + + public XAxis setTickHeight(Integer tick_height) { + this.tick_height = tick_height; + return this; + } + + public Integer getTickHeight() { + return tick_height; + } + + public XAxisLabels getLabels() { + return labels; + } + + public XAxis setXAxisLabels(XAxisLabels labels) { + this.labels = labels; + return this; + } + + public XAxis setLabels(String... labels) { + this.labels = new XAxisLabels(labels); + return this; + } + + public XAxis setLabels(List labels) { + this.labels = new XAxisLabels(labels); + return this; + } + + public XAxis addLabels(String... labels) { + this.labels.addLabels(labels); + return this; + } + + public XAxis addLabels(Label... labels) { + this.labels.addLabels(labels); + return this; + } + + public XAxis addLabels(List