com.talk2object.plum.interaction.viewgeneneration.ViewClass Maven / Gradle / Ivy
package com.talk2object.plum.interaction.viewgeneneration;
/**
* classical view names, but not limited to.
*
* format: top-class.sub-class.sub-sub-class
*
* @author jack
*
*/
public enum ViewClass {
/**
* root
*/
VISIBLE(null) {
@Override
public String getName() {
return "";
}
},
/**
* used for view-only scenario.
*/
SHOW(VISIBLE),
MENU(SHOW),
FORM(SHOW), FORM_FIELD(SHOW), ITEM(SHOW), LIST(SHOW), LIST_ITEM(ITEM), TABLE(
SHOW), ROW(SHOW), TABLE_ROW(ROW), GRID(SHOW), GRID_ROW(ROW), REPORT(
SHOW), WINDOWS(SHOW),
;
public String getFullName() {
if (parent != null)
return parent.getFullName() + "." + getName();
else
return toStandardName(getName());
}
/**
* e.g. foo.*
*
* @return
*/
public String compatibleExpr() {
return getFullName() + ".*";
}
public String getName() {
return toStandardName(name());
}
private ViewClass(ViewClass parent) {
this.parent = parent;
}
private ViewClass parent;
/**
* lower case, underscore to dash
*
* @param name
* @return
*/
public static String toStandardName(String name) {
return name.replaceAll("_", "-").toLowerCase();
}
/**
* e.g. table-abc matches table-*
*
* @param expression
* in wild card pattern
* @param viewClassName
* @return
*/
public static boolean matches(String viewClassName, String expression) {
// System.out.println(wildcardPattern);
viewClassName = viewClassName + ".";
String regexPattern = expression.replaceAll("\\.", "\\\\.").replaceAll(
"\\*", ".*");
// System.out.println(regexPattern);
return viewClassName.matches(regexPattern);
}
public static boolean matchClass(String viewClass, String expression) {
if (expression.equals(viewClass))
return true;
else
return matches(viewClass, expression);
}
public static boolean matches(ViewClass viewClass, String expression) {
String s1 = viewClass.getFullName();
return matchClass(s1, expression);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy