📄 entityhelper.java
字号:
} /** * Check if entity <code>childEntityName</code> is a parent or itself for * entity <code>parentEntityName</code>. * * @param childEntityName child entity name * @param parentEntityName parent entity name * @return true or false */ public static boolean isChild(String childEntityName, String parentEntityName) { do { if(childEntityName != null && parentEntityName != null && childEntityName.equals(parentEntityName)) { return true; } childEntityName = getParentEntityName(childEntityName); } while(childEntityName != null); return false; } /** * Get Efield object by the efield name attribute. * * @param efieldName the efield name attribute * @param entity Entity object * @return Efield object * @throws UnknownEfieldException */ public static Efield getEfield(String efieldName, Entity entity) throws UnknownEfieldException { Object o = entity.getObject(efieldName); if(o == null || !(o instanceof Efield)) { throw new UnknownEfieldException(entity.getName(), efieldName); } return (Efield) o; } /** * Get Efield object by the src (database column name). * * @param src the database column name * @param entity Entity object * @return Efield object * @throws UnknownEfieldException */ public static Efield getEfieldBySrc(String src, Entity entity) { Object o = entity.getObject(src.toLowerCase()); if(o == null || !(o instanceof Efield)) { throw new UnknownEfieldException(entity.getName(), src); } return (Efield) o; } /** * Get Dataset object by the dataset name attribute. * * @param datasetName the dataset name attribute * @param entity Entity object * @return Dataset object * @throws UnknownEfieldException */ public static Dataset getDataset(String datasetName, Entity entity) throws UnknownEfieldException { Object o = entity.getObject(datasetName); if(o == null || !(o instanceof Dataset)) { throw new UnknownEfieldException(entity.getName(), datasetName); } return (Dataset) o; } /** * Get CustomField object by the efield name attribute. * * @param fieldName the efield name attribute * @param custom Custom object * @return CustomField object */ public static CustomField getCustomField(String fieldName, Custom custom) { Object o = custom.getObject(fieldName); return (o == null) ? null:(CustomField) o; } /** * Get ChainTable contains dataschemas for linking two entities. * * @param e2 the Entity 2 name attribute * @param entity the Entity 1 object * @return ChainTable object */ public static ChainTable getChainTable(String e2, Entity entity) { int chtable_count = entity.getChainTableCount(); for(int i = 0; i < chtable_count; i++) { ChainTable chtab = entity.getChainTable(i); if(chtab.getEntity().equals(e2)) { return chtab; } } return null; } /** * Get array of pkeys for given <code>entity</code>. * * @param entity Entity object * @return array of Efield object or NULL */ public static Efield[] getPkeys(Entity entity) { List pkeyFields = new ArrayList(); int fields = entity.getEfieldCount(); for(int i = 0; i < fields; i++) { Efield field = entity.getEfield(i); if(field.getPkey().booleanValue()) { pkeyFields.add(field); } } return (pkeyFields.size() == 0) ? null: (Efield[]) pkeyFields.toArray(new Efield[0]); } public static class FormHelper { //NullObjects for Layout and Form private static final Row[] NULL_ROWS = new Row[0]; private static final Header[] NULL_HEADERS = new Header[0]; private static final HiddenControl[] NULL_HIDDEN_CONTROLS = new HiddenControl[0]; private static final Button[] NULL_BUTTONS = new Button[0]; private static final Link[] NULL_LINKS = new Link[0]; private static final Button[] DEFAULT_BUTTONS = new Button[] { createButton("FORM_SEARCH_BUTTON"), createButton("FORM_CLEAR_BUTTON"), createButton("FORM_NEW_BUTTON"), createButton("FORM_CHANGE_OR_UPDATE_BUTTON") }; private static Button createButton(String buttonName) { Button button = new Button(); button.setName(buttonName); Captions caps = new Captions(); Caption cap = new Caption();// cap.setContent(); caps.addCaption(cap); button.setCaptions(caps); return button; } private static void checkAndCreateLayout(Form form) { if(form.getLayout() == null) { form.setLayout(new Layout()); } } public static Row[] getLayoutRows(Form form) { if(form.getLayout() == null) { return NULL_ROWS; } else { return form.getLayout().getRow(); } } public static void addLayoutRow(Form form, Row row) { checkAndCreateLayout(form); form.getLayout().addRow(row); } public static Header[] getLayoutHeaders(Form form) { if(form.getLayout() == null || form.getLayout().getHeaders() == null) { return NULL_HEADERS; } else { return form.getLayout().getHeaders().getHeader(); } } public static void addHeaderIntoLayout(Form form, Header header) { checkAndCreateLayout(form); if(form.getLayout().getHeaders() == null) { form.getLayout().setHeaders(new Headers()); } form.getLayout().getHeaders().addHeader(header); } public static HiddenControl[] getHiddenControls(Form form) { if(form.getLayout() == null || form.getLayout().getHiddenControls() == null) { return NULL_HIDDEN_CONTROLS; } else { return form.getLayout().getHiddenControls().getHiddenControl(); } } public static void addHiddenControl(Form form, HiddenControl hiddenControl) { checkAndCreateLayout(form); if(form.getLayout().getHiddenControls() == null) { form.getLayout().setHiddenControls(new HiddenControls()); } form.getLayout().getHiddenControls().addHiddenControl(hiddenControl); } public static Button[] getFormButtons(Form form) { Button[] buttons; if(form.getDefaultactions() || form.getButtons() == null) { buttons = DEFAULT_BUTTONS; } else { buttons = form.getButtons().getButton(); } return buttons; } public static Button getButtonById(Form form, String buttonId) { Button[] buttons = getFormButtons(form); for (Button button : buttons) { if (buttonId.equalsIgnoreCase(button.getName())) { return button; } } return null; } public static void addFormButton(Form form, Button button) { if(form.getButtons() == null) { form.setButtons(new Buttons()); } form.getButtons().addButton(button); } public static Link[] getFormLinks(Form form) { if(form.getLinks() == null) { return NULL_LINKS; } else { return form.getLinks().getLink(); } } public static void addFormLink(Form form, Link link) { if(form.getLinks() == null) { form.setLinks(new Links()); } form.getLinks().addLink(link); } public static boolean getFormDefaultActions(Form form) { return form.getButtons() == null || form.getButtons().getDefaultactions(); } public static String getButtonName(Form form, Button button) { return form.getName() + "__button__" + button.getName(); } public static String getHtmlElementName(Form form, Htmlelement htmlElement) { return form.getName() + "__htmlelement__" + htmlElement.getName(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -