-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#666 TableForm redesign, ListField compiles (but not integrated yet)
- Loading branch information
1 parent
9f7a92f
commit 7222fd2
Showing
12 changed files
with
175 additions
and
61 deletions.
There are no files selected for viewing
14 changes: 9 additions & 5 deletions
14
elements/src/main/java/com/manydesigns/elements/KeyValueAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
package com.manydesigns.elements; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Abstraction over key-value data for Elements forms (e.g. JSON objects, HTTP requests, etc.) | ||
* | ||
* @author Angelo Lupo - angelo.lupo@manydesigns.com | ||
* @author Giampiero Granatella - giampiero.granatella@manydesigns.com | ||
* @author Emanuele Poggi - emanuele.poggi@manydesigns.com | ||
* @author Alessio Stalla - alessio.stalla@manydesigns.com | ||
*/ | ||
public interface KeyValueAccessor { | ||
public static final String copyright = | ||
"Copyright (C) 2005-2020 ManyDesigns srl"; | ||
String copyright = "Copyright (C) 2005-2024 ManyDesigns srl"; | ||
|
||
Object get(String name); | ||
void set(String name, Object value); | ||
boolean has(String name); | ||
|
||
KeyValueAccessor object(String name); | ||
List<KeyValueAccessor> list(String name); | ||
|
||
KeyValueAccessor list(String name); | ||
|
||
KeyValueAccessor atIndex(int index); | ||
|
||
int length(); | ||
} |
36 changes: 36 additions & 0 deletions
36
elements/src/main/java/com/manydesigns/elements/KeyValueListAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.manydesigns.elements; | ||
|
||
import com.manydesigns.elements.json.JSONObjectAccessor; | ||
|
||
public abstract class KeyValueListAccessor implements KeyValueAccessor { | ||
protected KeyValueAccessor currentObjectAccessor; | ||
|
||
@Override | ||
public Object get(String name) { | ||
return currentObjectAccessor != null ? currentObjectAccessor.get(name) : null; | ||
} | ||
|
||
@Override | ||
public void set(String name, Object value) { | ||
if (currentObjectAccessor != null) { | ||
currentObjectAccessor.set(name, value); | ||
} else { | ||
throw new IllegalStateException("No element in the list"); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean has(String name) { | ||
return currentObjectAccessor != null && currentObjectAccessor.has(name); | ||
} | ||
|
||
@Override | ||
public KeyValueAccessor object(String name) { | ||
return currentObjectAccessor != null ? currentObjectAccessor.object(name) : null; | ||
} | ||
|
||
@Override | ||
public KeyValueAccessor list(String name) { | ||
return currentObjectAccessor != null ? currentObjectAccessor.list(name) : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
elements/src/main/java/com/manydesigns/elements/json/JSONArrayAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.manydesigns.elements.json; | ||
|
||
import com.manydesigns.elements.KeyValueListAccessor; | ||
import org.json.JSONArray; | ||
|
||
public class JSONArrayAccessor extends KeyValueListAccessor { | ||
|
||
private final JSONArray jsonArray; | ||
|
||
public JSONArrayAccessor(JSONArray jsonArray) { | ||
this.jsonArray = jsonArray; | ||
if (!jsonArray.isEmpty()) { | ||
currentObjectAccessor = new JSONObjectAccessor(jsonArray.getJSONObject(0)); | ||
} | ||
} | ||
|
||
protected JSONArrayAccessor(JSONArray jsonArray, JSONObjectAccessor currentAccessor) { | ||
this.jsonArray = jsonArray; | ||
this.currentObjectAccessor = currentAccessor; | ||
} | ||
|
||
@Override | ||
public KeyValueListAccessor atIndex(int index) { | ||
return new JSONArrayAccessor(jsonArray, new JSONObjectAccessor(jsonArray.getJSONObject(index))); | ||
} | ||
|
||
@Override | ||
public int length() { | ||
return jsonArray.length(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.