Skip to content

Commit f3c0c5c

Browse files
committed
Generate the typescript through a configurator class
1 parent 86fd28f commit f3c0c5c

File tree

3 files changed

+76
-89
lines changed

3 files changed

+76
-89
lines changed

src/main/java/com/jwebmp/core/base/ComponentBase.java

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
* @author GedMarc
3939
* @since 22 Apr 2016
4040
*/
41-
@SuppressWarnings("MissingClassJavaDoc")
41+
@SuppressWarnings({"MissingClassJavaDoc", "LombokGetterMayBeUsed"})
4242
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY,
43-
getterVisibility = JsonAutoDetect.Visibility.NONE,
44-
setterVisibility = JsonAutoDetect.Visibility.NONE)
43+
getterVisibility = JsonAutoDetect.Visibility.NONE,
44+
setterVisibility = JsonAutoDetect.Visibility.NONE)
4545
@JsonInclude(JsonInclude.Include.NON_NULL)
4646
@Log
4747
public class ComponentBase<J extends ComponentBase<J>> implements IComponentBase<J>
@@ -78,6 +78,11 @@ public class ComponentBase<J extends ComponentBase<J>> implements IComponentBase
7878
*/
7979
private boolean touched;
8080

81+
/**
82+
* If the render/preconfigure started from this component
83+
*/
84+
private boolean startOfRender;
85+
8186
/**
8287
* A set of properties for this component
8388
*/
@@ -124,8 +129,7 @@ public J cloneComponent()
124129
{
125130
component = (J) clone();
126131
component.setID(GUIDGenerator.generateGuid());
127-
}
128-
catch (CloneNotSupportedException ex)
132+
} catch (CloneNotSupportedException ex)
129133
{
130134
ComponentBase.log.log(Level.SEVERE, "Cloning Error in Shell", ex);
131135
}
@@ -202,8 +206,7 @@ public String getNewLine()
202206
if (!isTiny())
203207
{
204208
return StaticStrings.STRING_NEWLINE_TEXT;
205-
}
206-
else
209+
} else
207210
{
208211
return StaticStrings.STRING_EMPTY;
209212
}
@@ -255,8 +258,7 @@ protected StringBuilder getText(StringBuilder sb)
255258
if (text == null)
256259
{
257260
return new StringBuilder();
258-
}
259-
else
261+
} else
260262
{
261263
sb.append(text);
262264
return sb;
@@ -434,7 +436,7 @@ public boolean equals(Object obj)
434436
}
435437
ComponentBase<?> other = (ComponentBase<?>) obj;
436438
return other.getID()
437-
.equals(getID());
439+
.equals(getID());
438440
}
439441

440442
/**
@@ -581,7 +583,7 @@ public boolean hasProperty(String propertyName)
581583
public String getProperty(String propertyName)
582584
{
583585
return getProperties().get(propertyName)
584-
.toString();
586+
.toString();
585587
}
586588

587589
/**
@@ -597,12 +599,11 @@ public String getClassCanonicalName()
597599
if (getClass().getCanonicalName() != null)
598600
{
599601
return getClass().getCanonicalName()
600-
.replace(StaticStrings.CHAR_DOT, StaticStrings.CHAR_UNDERSCORE);
602+
.replace(StaticStrings.CHAR_DOT, StaticStrings.CHAR_UNDERSCORE);
601603
}
602604
return getClass().getName()
603-
.replace(StaticStrings.CHAR_DOT, StaticStrings.CHAR_UNDERSCORE);
604-
}
605-
catch (NullPointerException npe)
605+
.replace(StaticStrings.CHAR_DOT, StaticStrings.CHAR_UNDERSCORE);
606+
} catch (NullPointerException npe)
606607
{
607608
ComponentBase.log.log(Level.FINE, "Null Pointer in getting canonical name", npe);
608609
return getClass().getTypeName();
@@ -617,4 +618,28 @@ public void destroy()
617618
getProperties().clear();
618619
setProperties(null);
619620
}
621+
622+
/**
623+
* If the render process was started by this
624+
*
625+
* @return startOfRender
626+
*/
627+
@Override
628+
public boolean isStartOfRender()
629+
{
630+
return startOfRender;
631+
}
632+
633+
/**
634+
* If this component started the render process
635+
*
636+
* @param startOfRender
637+
* @return
638+
*/
639+
@Override
640+
public J setStartOfRender(boolean startOfRender)
641+
{
642+
this.startOfRender = startOfRender;
643+
return (J) this;
644+
}
620645
}

src/main/java/com/jwebmp/core/base/ComponentHTMLBase.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
"WeakerAccess",
4545
"UnusedReturnValue"})
4646
public abstract class ComponentHTMLBase<F extends GlobalFeatures, E extends GlobalEvents, J extends ComponentHTMLBase<F, E, J>> extends
47-
ComponentEventBase<F, E, J> implements
48-
IComponentHTMLBase<J>
47+
ComponentEventBase<F, E, J> implements
48+
IComponentHTMLBase<J>
4949
{
5050

5151
/**
@@ -496,7 +496,6 @@ public J setTag(ComponentTypes tag)
496496
return (J) this;
497497
}
498498

499-
500499
/**
501500
* Returns the HTML for the given object
502501
* <p>
@@ -511,22 +510,11 @@ public String toString(boolean outputHtml)
511510
return toString(0);
512511
}
513512

514-
/**
515-
* Returns this components HTML after configuration and pre-rendering
516-
*
517-
* @param tabCount The number of tabs to indent by
518-
* @return The sting with the given tab counts
519-
*/
520-
@JsonIgnore
521-
@Getter
522-
@Setter
523-
private boolean startedRender = false;
524-
525513
@Override
526514
@NotNull
527515
public String toString(Integer tabCount)
528516
{
529-
startedRender = true;
517+
setStartOfRender(true);
530518
var out = String.valueOf(renderHTML(tabCount));
531519
return out;
532520
}

src/main/java/com/jwebmp/core/base/ComponentHierarchyBase.java

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ public void destroy()
277277
try
278278
{
279279
next.destroy();
280-
} catch (Exception e)
280+
}
281+
catch (Exception e)
281282
{
282283
ComponentHierarchyBase.log.log(Level.SEVERE, "UUnable to destroy", e);
283284
}
@@ -759,7 +760,8 @@ public boolean removeClass(@NotNull Enum<?> className)
759760
{
760761
getClasses().remove(className.toString());
761762
return true;
762-
} else
763+
}
764+
else
763765
{
764766
return false;
765767
}
@@ -882,36 +884,6 @@ public Set<String> getVariablesAll()
882884
return null;
883885
}
884886

885-
@Override
886-
public String toString(Integer tabCount)
887-
{
888-
var s = super.toString(tabCount);
889-
if (isStartedRender())
890-
{
891-
// for (C child : getChildren())
892-
// {
893-
Set<IOnComponentAdded> components = IGuiceContext.loaderToSet(ServiceLoader.load(IOnComponentAdded.class));
894-
for (IOnComponentAdded component : components)
895-
{
896-
try
897-
{
898-
component.onComponentAdded(null, (ComponentHierarchyBase<?, ?, ?, ?, ?>) this);
899-
} catch (Throwable T)
900-
{
901-
log.log(Level.SEVERE, "Error on component added", T);
902-
}
903-
}
904-
// }
905-
906-
Set<IAfterRenderComplete> afterRenderCompletes = IGuiceContext.loaderToSet(ServiceLoader.load(IAfterRenderComplete.class));
907-
for (var renderComplete : afterRenderCompletes)
908-
{
909-
renderComplete.process(this);
910-
}
911-
}
912-
return s;
913-
}
914-
915887
@Override
916888
protected StringBuilder renderHTML(int tabCount)
917889
{
@@ -926,7 +898,8 @@ protected StringBuilder renderHTML(int tabCount)
926898
{
927899
renderChildren = result;
928900
}
929-
} catch (Throwable T)
901+
}
902+
catch (Throwable T)
930903
{
931904
log.log(Level.WARNING, "Error in processing html render interceptor", T);
932905
}
@@ -1004,17 +977,25 @@ protected void preConfigure()
1004977
setNewLineForClosingTag(hasChildren());
1005978
}
1006979
super.preConfigure();
1007-
Set<IOnComponentConfigured> components = IGuiceContext.loaderToSet(ServiceLoader.load(IOnComponentConfigured.class));
1008-
for (IOnComponentConfigured component : components)
980+
if (isStartOfRender())
1009981
{
1010-
try
1011-
{
1012-
component.onComponentConfigured(null, this);
1013-
} catch (Throwable T)
982+
Set<IOnComponentConfigured> components = IGuiceContext.loaderToSet(ServiceLoader.load(IOnComponentConfigured.class));
983+
for (IOnComponentConfigured component : components)
1014984
{
1015-
log.log(Level.SEVERE, "Error on component added", T);
985+
try
986+
{
987+
component.onComponentConfigured(null, this);
988+
}
989+
catch (Throwable T)
990+
{
991+
log.log(Level.SEVERE, "Error on component added", T);
992+
}
1016993
}
1017994
}
995+
else
996+
{
997+
getProperties().put("ComponentConfigured", true);
998+
}
1018999
}
10191000

10201001
/**
@@ -1080,19 +1061,6 @@ public Set<StringBuilder> getQueriesAll()
10801061
return reallyAllQueries;
10811062
}
10821063

1083-
/**
1084-
* Pre-Configure the children tree
1085-
*
1086-
* @return
1087-
* @see ComponentBase#toString()
1088-
*/
1089-
@Override
1090-
@NotNull
1091-
public String toString()
1092-
{
1093-
return super.toString();
1094-
}
1095-
10961064
/**
10971065
* Processes the queries
10981066
*
@@ -1156,10 +1124,12 @@ private void processAngularObjects(@NotNull IComponentHierarchyBase<?, ?> next,
11561124
try
11571125
{
11581126
map.put(key, value);
1159-
} catch (ClassCastException cce)
1127+
}
1128+
catch (ClassCastException cce)
11601129
{
11611130
ComponentHierarchyBase.log.log(Level.WARNING, "Incorrect Object Type, Perhaps JavaScriptPart?", cce);
1162-
} catch (Exception e)
1131+
}
1132+
catch (Exception e)
11631133
{
11641134
ComponentHierarchyBase.log.log(Level.WARNING, "Unable to render angular object", e);
11651135
}
@@ -1192,7 +1162,8 @@ public boolean readChildrenPropertyFirstResult(String propertyName, boolean retu
11921162
try
11931163
{
11941164
return Boolean.parseBoolean(propertyValue);
1195-
} catch (Exception e)
1165+
}
1166+
catch (Exception e)
11961167
{
11971168
ComponentHierarchyBase.log.log(Level.WARNING, "Property value was not a boolean.", e);
11981169
}
@@ -1311,7 +1282,8 @@ protected StringBuilder renderChildren()
13111282
{
13121283
sb.append(getNewLine())
13131284
.append(chb.renderHTML(getCurrentTabIndents() + (chb.isTiny() ? 0 : 1)));
1314-
} catch (Exception e)
1285+
}
1286+
catch (Exception e)
13151287
{
13161288
log.log(Level.SEVERE, "Cannot work on child object - " + child.getClass()
13171289
.getCanonicalName() + "\n, adding to the tree\n", e);
@@ -1340,7 +1312,8 @@ public Boolean isNewLineForClosingTag()
13401312
if (hasChildren() && !isTiny())
13411313
{
13421314
return true;
1343-
} else
1315+
}
1316+
else
13441317
{
13451318
return super.isNewLineForClosingTag();
13461319
}
@@ -1405,7 +1378,8 @@ public <T> Set<T> getConfigurations(Class<T> configurationType, boolean children
14051378
.filter(b -> configurationType.isAssignableFrom(b.getClass()))
14061379
.collect(Collectors.toSet()));
14071380
}
1408-
} else
1381+
}
1382+
else
14091383
{
14101384
out.addAll((Collection<? extends T>) getConfigurations().stream()
14111385
.filter(b -> configurationType.isAssignableFrom(b.getClass()))

0 commit comments

Comments
 (0)