11/**
22 The MIT License (MIT)
33
4- Copyright (c) 2010-2025 interference
4+ Copyright (c) 2010-2026 interference
55
66 Permission is hereby granted, free of charge, to any person obtaining a copy of
77 this software and associated documentation files (the "Software"), to deal in
@@ -34,22 +34,24 @@ this software and associated documentation files (the "Software"), to deal in
3434 */
3535
3636public class MgmtContainer {
37- MgmtColumn mgmtColumn ;
38- MgmtAction mgmtAction ;
39- MgmtLink mgmtLink ;
40- Field field ;
41- Method method ;
42- Class c ;
43- Field idField ;
44-
45- public MgmtContainer (MgmtColumn mgmtColumn , MgmtAction mgmtAction , MgmtLink mgmtLink , Field field , Method method , Class c , Field idField ) {
37+ final MgmtColumn mgmtColumn ;
38+ final MgmtAction mgmtAction ;
39+ final MgmtLink mgmtLink ;
40+ final Field field ;
41+ final Method method ;
42+ final Class c ;
43+ final Field idField ;
44+ final boolean autoGenerate ;
45+
46+ public MgmtContainer (MgmtColumn mgmtColumn , MgmtAction mgmtAction , MgmtLink mgmtLink , Field field , Method method , Class c , Field idField , boolean autoGenerate ) {
4647 this .mgmtColumn = mgmtColumn ;
4748 this .mgmtAction = mgmtAction ;
4849 this .mgmtLink = mgmtLink ;
4950 this .field = field ;
5051 this .method = method ;
5152 this .c = c ;
5253 this .idField = idField ;
54+ this .autoGenerate = autoGenerate ;
5355 }
5456
5557 public MgmtColumn getMgmtColumn () {
@@ -84,21 +86,45 @@ public String getHeader() {
8486 }
8587 }
8688
87- public String getValue (Object o , String objectId , String sessionId , int pageId ) throws NoSuchMethodException , IllegalAccessException , InvocationTargetException {
89+ public String getValue (Object o , int tableId , String sessionId , int pageId , boolean showMgmtLink , boolean showEditLink ) throws NoSuchMethodException , IllegalAccessException , InvocationTargetException {
8890 if (this .mgmtColumn == null || this .field == null ) {
8991 return null ;
9092 } else {
9193 String getName = "get" + this .field .getName ().substring (0 ,1 ).toUpperCase () + this .field .getName ().substring (1 );
9294 Method m = this .c .getMethod (getName , null );
9395 Object result = m .invoke (o , null );
94- if (this .mgmtLink != null ) {
95- return "<a href=\" ?showtable=" +objectId +"&session_id=" +sessionId +"&page_id=10\" >" +result +"</a>" ;
96+ if (this .isId () && showEditLink ) {
97+ return "<a href=\" ?action=edit&table_id=" +tableId +"&object_id=" +this .getId (o )+"&session_id=" +sessionId +"&page_id=" +pageId +"\" >" +result +"</a>" ;
98+ } else if (this .mgmtLink != null && showMgmtLink ) {
99+ return "<a href=\" ?action=showtable&table_id=" +this .getId (o )+"&session_id=" +sessionId +"&page_id=" +pageId +"\" >" +result +"</a>" ;
96100 } else {
97101 return String .valueOf (result );
98102 }
99103 }
100104 }
101105
106+ public String getInsertLink (int tableId , String sessionId , int pageId ) {
107+ return "<a href=\" ?action=insert&table_id=" +tableId +"&session_id=" +sessionId +"&page_id=" +pageId +"\" >Insert new</a>" ;
108+ }
109+
110+ public String getFormElement (Object o ) throws NoSuchMethodException , IllegalAccessException , InvocationTargetException {
111+ if (this .mgmtColumn == null || this .field == null ) {
112+ return null ;
113+ } else {
114+ Object result = "" ;
115+ String disabled = "" ;
116+ if (o != null ) {
117+ String getName = "get" + this .field .getName ().substring (0 , 1 ).toUpperCase () + this .field .getName ().substring (1 );
118+ Method m = this .c .getMethod (getName , null );
119+ result = m .invoke (o , null );
120+ disabled = this .field .equals (this .idField ) ? "disabled" : "" ;
121+ } else {
122+ disabled = this .field .equals (this .idField ) && this .autoGenerate ? "disabled" : "" ;
123+ }
124+ return "<input type=\" text\" size=\" 100\" name=\" " +this .field .getName ()+"\" " + disabled + " value=\" " +String .valueOf (result )+"\" >\n " ;
125+ }
126+ }
127+
102128 public String getId (Object o ) throws NoSuchMethodException , IllegalAccessException , InvocationTargetException {
103129 if (this .idField == null ) {
104130 return null ;
@@ -113,4 +139,12 @@ public String getId(Object o) throws NoSuchMethodException, IllegalAccessExcepti
113139 public boolean isCommand () {
114140 return this .method != null && this .mgmtAction != null ;
115141 }
142+
143+ public boolean isId () {
144+ return this .field != null && this .field .equals (this .idField );
145+ }
146+
147+ public boolean isAutoGenerate () {
148+ return autoGenerate ;
149+ }
116150}
0 commit comments