use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class BeansDefaultValues method updateBeansDefaultValues.
private static Document updateBeansDefaultValues(Document document) throws Exception {
try (InputStream dbInputstream = BeansDefaultValues.class.getResourceAsStream("/com/twinsoft/convertigo/beans/database_objects.xml")) {
Document documentBeansXmlDatabase = XMLUtils.getDefaultDocumentBuilder().parse(dbInputstream);
TwsCachedXPathAPI xpath = new TwsCachedXPathAPI();
EnginePropertiesManager.initProperties();
SortedSet<Node> nodes = new TreeSet<Node>((n1, n2) -> {
return n1.getNodeValue().compareTo(n2.getNodeValue());
});
nodes.addAll(xpath.selectList(documentBeansXmlDatabase, "//bean/@classname"));
Element beans = document.getDocumentElement();
if (beans == null) {
beans = document.createElement("beans");
document.appendChild(beans);
}
String nVersion = VersionUtils.normalizeVersionString(ProductVersion.productVersion);
for (Node node : nodes) {
String classname = node.getNodeValue();
DatabaseObject dbo = (DatabaseObject) Class.forName(classname).getConstructor().newInstance();
Element def = dbo.toXml(document);
if (def.hasAttribute("priority")) {
def.setAttribute("priority", "0");
}
Element eBean = getBeanForVersion(xpath, beans, classname, nVersion);
if (eBean != null) {
String eVersion = eBean.getAttribute("version");
eBean.removeAttribute("version");
if (!checkIsSame(def, eBean)) {
if (eVersion.equals(nVersion)) {
beans.removeChild(eBean);
}
def.setAttribute("version", nVersion);
beans.insertBefore(def, beans.getFirstChild());
}
eBean.setAttribute("version", eVersion);
} else {
def.setAttribute("version", nVersion);
beans.insertBefore(def, beans.getFirstChild());
}
}
;
return document;
}
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class BeansDoc method createBeanElement.
private void createBeanElement(DboBean bean, boolean bEnable) throws Exception {
String databaseObjectClassName = bean.getClassName();
Class<?> databaseObjectClass = Class.forName(databaseObjectClassName);
DatabaseObject databaseObject = (DatabaseObject) databaseObjectClass.getConstructor().newInstance();
BeanInfo beanInfo = Introspector.getBeanInfo(databaseObjectClass);
BeanDescriptor databaseObjectBeanDescriptor = beanInfo.getBeanDescriptor();
String displayName = databaseObjectBeanDescriptor.getDisplayName();
String normalizedGroupName = normalize(groupName);
String normalizedCategoryName = normalize(categoryName);
String normalizedBeansCategoryName = normalize(beansCategoryName);
String normalizedName = normalize(displayName);
String path = (normalizedGroupName + "/" + normalizedCategoryName + "/" + normalizedBeansCategoryName + "/" + normalizedName).replaceAll("/+", "/");
String iconName = MySimpleBeanInfo.getIconName(beanInfo, BeanInfo.ICON_COLOR_32x32);
String iconPath = iconName.replaceFirst(".*/beans/", "");
try {
try (InputStream is = getClass().getResourceAsStream(iconName)) {
FileUtils.copyInputStreamToFile(is, new File(imageDirectory, iconPath));
}
} catch (Exception e) {
iconName = "/com/twinsoft/convertigo/beans/core/images/default_color_16x16.png";
iconPath = iconName.replaceFirst(".*/beans/", "");
try (InputStream is = getClass().getResourceAsStream(iconName)) {
FileUtils.copyInputStreamToFile(is, new File(imageDirectory, iconPath));
}
}
StringBuilder sb = new StringBuilder();
String permalink = "reference-manual/convertigo-objects/" + path + "/";
String metadesc = databaseObjectBeanDescriptor.getShortDescription();
metadesc = metadesc.replaceAll("<[a-zA-Z]*>|<\\/[a-zA-Z]*>|<br\\/>", " ");
metadesc = metadesc.replaceAll(":", " ");
metadesc = metadesc.replaceAll("\\|", " ");
if (metadesc.length() >= 150)
metadesc = metadesc.substring(0, 150);
sb.append("---\n" + "layout: page\n" + "title: " + displayName + "\n" + "sidebar: c8o_sidebar\n" + "permalink: " + permalink + "\n" + "metadesc: " + metadesc + "\n" + "ObjGroup: " + groupName + "\n" + "ObjCatName: " + normalizedBeansCategoryName + "\n" + "ObjName: " + displayName + "\n" + "ObjClass: " + databaseObjectClassName + "\n" + "ObjIcon: /images/beans/" + iconPath + "\n" + "topnav: topnavobj" + "\n" + "---\n");
if (bEnable) {
String description = databaseObjectBeanDescriptor.getShortDescription();
String shortDescription = description;
String longDescription = "";
Matcher mDescription = pDescription.matcher(description);
if (mDescription.matches()) {
shortDescription = mDescription.group(1);
if (mDescription.group(2) != null) {
longDescription = mDescription.group(2);
longDescription.replaceAll("\\n", "\n\n");
}
}
sb.append("##### " + shortDescription + "\n\n" + longDescription + "\n");
SortedMap<String, String> properties = new TreeMap<>();
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor databaseObjectPropertyDescriptor : propertyDescriptors) {
boolean skip = false;
longDescription = "";
// Don't display hidden property descriptors
if (databaseObjectPropertyDescriptor.isHidden()) {
skip = true;
}
Method getter = databaseObjectPropertyDescriptor.getReadMethod();
Method setter = databaseObjectPropertyDescriptor.getWriteMethod();
// Only display read/write property descriptors
if (getter == null || setter == null) {
skip = true;
}
String blackListedForParentClass = (String) databaseObjectPropertyDescriptor.getValue("blackListedForParentClass");
if (blackListedForParentClass != null) {
// check
for (DboParent parent : bean.getParents()) {
String parentName = parent.getClassName();
if (blackListedForParentClass.equals(parentName)) {
skip = true;
break;
}
}
}
if (skip) {
continue;
}
String category = "standard";
if (databaseObject instanceof ExtractionRule) {
category = "configuration";
if (databaseObjectPropertyDescriptor.isExpert()) {
category = "selection";
}
} else if (databaseObjectPropertyDescriptor.isExpert()) {
category = "expert";
}
description = databaseObjectPropertyDescriptor.getShortDescription();
mDescription = pDescription.matcher(description);
if (mDescription.matches()) {
description = mDescription.group(1).trim();
if (mDescription.group(2) != null) {
description += "<br/>" + mDescription.group(2).trim();
}
}
String type = databaseObjectPropertyDescriptor.getPropertyType().getSimpleName();
if ("true".equals("" + databaseObjectPropertyDescriptor.getValue("scriptable"))) {
type = "JS expression";
}
String propDisplayName = databaseObjectPropertyDescriptor.getDisplayName();
description = description.replace("|", "|");
String line = propDisplayName + " | " + type + " | " + category + " | " + description + "\n";
if (category.equals("standard")) {
category = "0";
}
properties.put(category + "_" + propDisplayName, line);
}
if (!properties.isEmpty()) {
sb.append("\nProperty | Type | Category | Description\n--- | --- | --- | ---\n");
for (String line : properties.values()) {
sb.append(line);
}
}
} else {
sb.append("##### Not yet documented.\nFor more information, do not hesitate to contact us in the forum in our Developer Network website: http://www.convertigo.com/itcenter.html\n");
}
String toWrite = sb.toString();
if (!"\n".equals(System.lineSeparator())) {
toWrite = toWrite.replace("\n", System.lineSeparator());
}
FileUtils.write(new File(outputDirectory, path + ".md"), toWrite, "UTF-8");
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class ProjectSchemaWizardPage method dialogChanged.
private void dialogChanged() {
if (projectName == null) {
updateStatus("Please select a project");
return;
}
try {
DatabaseObject dbo = ((ObjectExplorerWizardPage) getWizard().getPage("ObjectExplorerWizardPage")).getCreatedBean();
if (dbo != null) {
if (dbo instanceof ProjectSchemaReference) {
projectName = ProjectUrlParser.getUrl(projectName);
((ProjectSchemaReference) dbo).setProjectName(projectName);
}
}
} catch (NullPointerException e) {
updateStatus("New Bean has not been instantiated");
return;
}
updateStatus(null);
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class AbstractConnectorCompositeWrap method checkEventSource.
protected boolean checkEventSource(EventObject event) {
boolean isSourceFromConnector = false;
Object source = event.getSource();
if (event instanceof ConnectorEvent) {
if (source instanceof DatabaseObject) {
Connector connector = ((DatabaseObject) source).getConnector();
if ((connector != null) && (connector.equals(this.connector)))
isSourceFromConnector = true;
}
}
return isSourceFromConnector;
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class NgxComponentCreateAction method run.
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
int folderType = -1;
TreeObject parentTreeObject = null;
DatabaseObject databaseObject = null;
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
parentTreeObject = explorerView.getFirstSelectedTreeObject();
if (parentTreeObject instanceof ObjectsFolderTreeObject) {
ObjectsFolderTreeObject folderTreeObject = (ObjectsFolderTreeObject) parentTreeObject;
folderType = folderTreeObject.folderType;
parentTreeObject = folderTreeObject.getParent();
databaseObject = (DatabaseObject) parentTreeObject.getObject();
} else {
databaseObject = (DatabaseObject) parentTreeObject.getObject();
}
ComponentObjectWizard newObjectWizard = new ComponentObjectWizard(databaseObject, databaseObjectClassName, folderType);
WizardDialog wzdlg = new WizardDialog(shell, newObjectWizard);
wzdlg.setPageSize(850, 650);
wzdlg.open();
int result = wzdlg.getReturnCode();
if ((result != Window.CANCEL) && (newObjectWizard.newBean != null)) {
postCreate(parentTreeObject, newObjectWizard.newBean);
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to create a new database object '" + databaseObjectClassName + "'!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations