]>
git.argeo.org Git - gpl/argeo-suite.git/blob - org.argeo.app.geo/src/org/argeo/app/ol/AbstractOlObject.java
1 package org
.argeo
.app
.ol
;
3 import java
.util
.HashMap
;
5 import java
.util
.Objects
;
7 import org
.argeo
.app
.ux
.js
.AbstractJsObject
;
9 public abstract class AbstractOlObject
extends AbstractJsObject
{
10 public final static String JS_PACKAGE
= "argeo.tp.ol";
12 public AbstractOlObject(Object
... args
) {
13 super(args
.length
> 0 ? args
: new Object
[] { new HashMap
<String
, Object
>() });
16 // public AbstractOlObject(Map<String, Object> options) {
17 // super(new Object[] { options });
20 public String
getJsPackage() {
24 @SuppressWarnings("unchecked")
25 protected Map
<String
, Object
> getNewOptions() {
27 throw new IllegalStateException("Object " + getJsClassName() + " is not new");
28 Object
[] args
= getJsConstructorArgs();
29 if (args
.length
!= 1 || !(args
[0] instanceof Map
))
30 throw new IllegalStateException("Object " + getJsClassName() + " has no available options");
31 return (Map
<String
, Object
>) args
[0];
34 protected void doSetValue(String methodName
, String newOption
, Object value
) {
36 Objects
.requireNonNull(newOption
, "Value cannot be set as an option for " + getJsClassName() + ", use "
37 + methodName
+ "() after the object has been created");
38 getNewOptions().put(newOption
, value
);
40 Objects
.requireNonNull(methodName
, "Value cannot be set via a method for " + getJsClassName() + ", use "
41 + newOption
+ " before the object is created");
42 executeMethod(methodName
, value
);
46 public void set(String key
, Object value
) {
47 set(key
, value
, false);
50 public void set(String key
, Object value
, boolean silent
) {
52 getNewOptions().put(key
, value
);
54 executeMethod(getMethodName(), new Object
[] { key
, value
, silent
});
58 public Object
get(String key
) {
60 return getNewOptions().get(key
);
62 // TDO deal with reference if we are trying to get an object
63 return callMethod(getMethodName(), key
);
68 public static String
getJsClassName(Class
<?
> clss
) {
69 if (AbstractOlObject
.class.isAssignableFrom(clss
)) {
70 // NB: would failed for renamed classes
71 return JS_PACKAGE
+ "." + clss
.getSimpleName();
73 throw new IllegalArgumentException(clss
+ " is not an OpenLayers object");