|
| 1 | +/** |
| 2 | + * Copyright 2014-2017 Riccardo Massera (TheCoder4.Eu) and Stephan Rauh (http://www.beyondjava.net). |
| 3 | + * |
| 4 | + * This file is part of BootsFaces. |
| 5 | + * |
| 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +* you may not use this file except in compliance with the License. |
| 8 | +* You may obtain a copy of the License at |
| 9 | +* |
| 10 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +* |
| 12 | +* Unless required by applicable law or agreed to in writing, software |
| 13 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +* See the License for the specific language governing permissions and |
| 16 | +* limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package net.bootsfaces.component.openStreetMap; |
| 20 | + |
| 21 | +import javax.faces.context.FacesContext; |
| 22 | +import javax.faces.event.AbortProcessingException; |
| 23 | +import javax.faces.event.ComponentSystemEvent; |
| 24 | +import javax.faces.event.ListenerFor; |
| 25 | +import javax.faces.event.ListenersFor; |
| 26 | +import javax.faces.event.PostAddToViewEvent; |
| 27 | + |
| 28 | +import javax.el.ValueExpression; |
| 29 | +import javax.faces.component.FacesComponent; |
| 30 | +import javax.faces.component.UIComponent; |
| 31 | +import javax.faces.component.UIComponentBase; |
| 32 | +import javax.faces.component.UIViewRoot; |
| 33 | +import javax.faces.component.behavior.ClientBehaviorHolder; |
| 34 | +import javax.faces.event.FacesEvent; |
| 35 | + |
| 36 | +import net.bootsfaces.C; |
| 37 | +import net.bootsfaces.listeners.AddResourcesListener; |
| 38 | +import net.bootsfaces.render.Tooltip; |
| 39 | +import net.bootsfaces.utils.BsfUtils; |
| 40 | + |
| 41 | +/** This class holds the attributes of <b:openStreetMap />. */ |
| 42 | +@ListenersFor({ @ListenerFor(systemEventClass = PostAddToViewEvent.class) }) |
| 43 | +@FacesComponent(OpenStreetMap.COMPONENT_TYPE) |
| 44 | +public class OpenStreetMap extends OpenStreetMapCore implements ClientBehaviorHolder { |
| 45 | + |
| 46 | + public static final String COMPONENT_TYPE = C.BSFCOMPONENT + ".openStreetMap.OpenStreetMap"; |
| 47 | + |
| 48 | + public static final String COMPONENT_FAMILY = C.BSFCOMPONENT; |
| 49 | + |
| 50 | + public static final String DEFAULT_RENDERER = "net.bootsfaces.component.openStreetMap.OpenStreetMap"; |
| 51 | + |
| 52 | +// private static final Collection<String> EVENT_NAMES = Collections.unmodifiableCollection(Arrays.asList("click", |
| 53 | +// "dblclick", "dragstart", "dragover", "drop", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup")); |
| 54 | + |
| 55 | + public OpenStreetMap() { |
| 56 | + setRendererType(DEFAULT_RENDERER); |
| 57 | + Tooltip.addResourceFiles(); |
| 58 | +// AddResourcesListener.addThemedCSSResource("core.css"); |
| 59 | +// AddResourcesListener |
| 60 | +// .addResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/images/layers-2x.png"); |
| 61 | +// AddResourcesListener |
| 62 | +// .addResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/images/layers.png"); |
| 63 | +// AddResourcesListener.addResourceIfNecessary( |
| 64 | +// "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/images/marker-icon-2x.png"); |
| 65 | +// AddResourcesListener |
| 66 | +// .addResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/images/marker-icon.png"); |
| 67 | +// AddResourcesListener.addResourceIfNecessary( |
| 68 | +// "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/images/marker-shadow.png"); |
| 69 | + AddResourcesListener |
| 70 | + .addResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet-src.js"); |
| 71 | + AddResourcesListener |
| 72 | + .addResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet-src.js.map"); |
| 73 | + AddResourcesListener.addResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet.css"); |
| 74 | + AddResourcesListener.addResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet.js"); |
| 75 | + AddResourcesListener |
| 76 | + .addResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet.js.map"); |
| 77 | + } |
| 78 | + |
| 79 | + public void setValueExpression(String name, ValueExpression binding) { |
| 80 | + name = BsfUtils.snakeCaseToCamelCase(name); |
| 81 | + super.setValueExpression(name, binding); |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public boolean getRendersChildren() { |
| 86 | + return true; |
| 87 | + } |
| 88 | + |
| 89 | +// public Collection<String> getEventNames() { |
| 90 | +// return EVENT_NAMES; |
| 91 | +// } |
| 92 | + |
| 93 | +// public String getDefaultEventName() { |
| 94 | +// return "click"; |
| 95 | +// } |
| 96 | + |
| 97 | + public void processEvent(ComponentSystemEvent event) throws AbortProcessingException { |
| 98 | +// if (isAutoUpdate()) { |
| 99 | +// if (FacesContext.getCurrentInstance().isPostback()) { |
| 100 | +// FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add(getClientId()); |
| 101 | +// } |
| 102 | +// super.processEvent(event); |
| 103 | +// } |
| 104 | + } |
| 105 | + |
| 106 | + public String getFamily() { |
| 107 | + return COMPONENT_FAMILY; |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * <p> |
| 112 | + * Queue an event for broadcast at the end of the current request processing |
| 113 | + * lifecycle phase. The default implementation in {@link UIComponentBase} must |
| 114 | + * delegate this call to the <code>queueEvent()</code> method of the parent |
| 115 | + * {@link UIComponent}. |
| 116 | + * </p> |
| 117 | + * |
| 118 | + * @param event {@link FacesEvent} to be queued |
| 119 | + * |
| 120 | + * @throws IllegalStateException if this component is not a descendant of a |
| 121 | + * {@link UIViewRoot} |
| 122 | + * @throws NullPointerException if <code>event</code> is <code>null</code> |
| 123 | + */ |
| 124 | + public void queueEvent(FacesEvent event) { |
| 125 | + FacesContext context = FacesContext.getCurrentInstance(); |
| 126 | + String indexes = (String) context.getExternalContext().getRequestParameterMap().get("indexes"); |
| 127 | + context.getELContext().getELResolver().setValue(context.getELContext(), null, "indexes", indexes); |
| 128 | + String typeOfSelection = (String) context.getExternalContext().getRequestParameterMap().get("typeOfSelection"); |
| 129 | + context.getELContext().getELResolver().setValue(context.getELContext(), null, "typeOfSelection", |
| 130 | + typeOfSelection); |
| 131 | + try { |
| 132 | + int oldIndex = getRowIndex(); |
| 133 | + int index = Integer.valueOf(indexes); |
| 134 | + setRowIndex(index); |
| 135 | + super.queueEvent(event); |
| 136 | + setRowIndex(oldIndex); |
| 137 | + } catch (Exception multipleIndexes) { |
| 138 | + super.queueEvent(event); |
| 139 | + |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | +} |
0 commit comments