use of com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass in project convertigo by convertigo.
the class LearnScreenClassWizard method performFinish.
public boolean performFinish() {
String screenClassName = null;
String criteriaName = null;
XPath criteria = null;
try {
DatabaseObject parentObject = page2.getParentObject();
if (parentObject != null) {
// create new screen class
htmlScreenClass = new HtmlScreenClass();
if (htmlScreenClass != null) {
screenClassName = page2.getScreenClassName();
if (!StringUtils.isNormalized(screenClassName))
throw new EngineException("Screenclass name is not normalized : \"" + screenClassName + "\".");
htmlScreenClass.setName(screenClassName);
htmlScreenClass.hasChanged = true;
htmlScreenClass.priority = parentObject.priority + 1;
parentObject.add(htmlScreenClass);
ConvertigoPlugin.logInfo("New screen class named '" + screenClassName + "' has been added!");
Engine.logBeans.debug("New screen class named '" + screenClassName + "' has been added!", null);
}
if (htmlScreenClass != null) {
criteria = new XPath();
if (criteria != null) {
criteriaName = criteria.getName();
criteria.hasChanged = true;
try {
htmlScreenClass.add(criteria);
ConvertigoPlugin.logInfo("New criteria named '" + criteriaName + "' has been added!");
Engine.logBeans.debug("New criteria named '" + criteriaName + "' has been added!", null);
} catch (EngineException e) {
throw e;
}
}
}
}
} catch (EngineException e) {
String message = "Unable to create new screenclass class!";
ConvertigoPlugin.logException(e, message);
}
return true;
}
use of com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass in project convertigo by convertigo.
the class HtmlTransaction method addExtractionRuleShemas.
private void addExtractionRuleShemas(Map<String, String> names, Map<String, String> types, List<String> schemas, HtmlScreenClass screenClass) throws Exception {
HtmlExtractionRule htmlExtractionRule = null;
String typeSchema, typeName;
String erSchema, erSchemaEltName, erSchemaEltNSType;
Map<String, String> type;
if (screenClass != null) {
for (ExtractionRule extractionRule : screenClass.getExtractionRules()) {
htmlExtractionRule = (HtmlExtractionRule) extractionRule;
if (htmlExtractionRule.isEnabled()) {
erSchemaEltName = htmlExtractionRule.getSchemaElementName();
erSchemaEltNSType = htmlExtractionRule.getSchemaElementNSType("p_ns");
if (!names.containsKey(erSchemaEltName)) {
names.put(erSchemaEltName, erSchemaEltNSType);
} else {
typeSchema = (String) names.get(erSchemaEltName);
if (!typeSchema.equals(erSchemaEltNSType)) {
throw new Exception("Transaction may generate at least two extraction rules named '" + erSchemaEltName + "' with different type : '" + typeSchema + "' and '" + erSchemaEltNSType + "'.\nPlease correct by changing tagname or name if tagname is empty");
}
}
erSchema = htmlExtractionRule.getSchema("p_ns");
if (!schemas.contains(erSchema)) {
schemas.add(erSchema);
}
type = htmlExtractionRule.getSchemaTypes();
for (Entry<String, String> entry : type.entrySet()) {
typeName = entry.getKey();
typeSchema = entry.getValue();
types.put(typeName, typeSchema);
}
}
}
List<ScreenClass> visc = screenClass.getInheritedScreenClasses();
for (ScreenClass inheritedScreenClass : visc) {
addExtractionRuleShemas(names, types, schemas, (HtmlScreenClass) inheritedScreenClass);
}
}
}
use of com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass in project convertigo by convertigo.
the class TreeDropAdapter method performDrop.
private void performDrop(Object data, final ProjectExplorerView explorerView, TreeObject targetTreeObject) throws EngineException, IOException {
boolean needReload = false;
final DatabaseObject dbo;
if (data instanceof String) {
String source = data.toString();
if (targetTreeObject instanceof ObjectsFolderTreeObject) {
ObjectsFolderTreeObject folderTreeObject = (ObjectsFolderTreeObject) targetTreeObject;
dbo = (DatabaseObject) folderTreeObject.getParent().getObject();
switch(folderTreeObject.folderType) {
case ObjectsFolderTreeObject.FOLDER_TYPE_CRITERIAS:
if (dbo instanceof HtmlScreenClass) {
// Creates a XPath criteria for this screen class
if (!dbo.equals(((HtmlConnector) dbo.getConnector()).getDefaultScreenClass())) {
((HtmlScreenClass) dbo).addCriteria(createXPath(source));
needReload = true;
}
}
break;
case ObjectsFolderTreeObject.FOLDER_TYPE_INHERITED_SCREEN_CLASSES:
if (dbo instanceof HtmlScreenClass) {
// Creates an inherited screen class with an XPath criteria for this screen class
HtmlScreenClass newSc = createHtmlScreenClass(dbo.priority + 1);
((HtmlScreenClass) dbo).addInheritedScreenClass(newSc);
newSc.addCriteria(createXPath(source));
needReload = true;
}
break;
case ObjectsFolderTreeObject.FOLDER_TYPE_EXTRACTION_RULES:
if (dbo instanceof HtmlScreenClass) {
NewObjectWizard newObjectWizard = new NewObjectWizard(dbo, "com.twinsoft.convertigo.beans.core.ExtractionRule", source, null);
WizardDialog wzdlg = new WizardDialog(Display.getDefault().getActiveShell(), newObjectWizard);
wzdlg.setPageSize(850, 650);
wzdlg.open();
needReload = true;
}
break;
default:
break;
}
if (needReload)
reloadTreeObject(explorerView, folderTreeObject.getParent());
} else if (targetTreeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) targetTreeObject;
dbo = (DatabaseObject) targetTreeObject.getObject();
if (databaseObjectTreeObject instanceof ScreenClassTreeObject) {
if (dbo instanceof HtmlScreenClass) {
// Creates an inherited screen class with an XPath criteria for this screen class
HtmlScreenClass newSc = createHtmlScreenClass(dbo.priority + 1);
((HtmlScreenClass) dbo).addInheritedScreenClass(newSc);
newSc.addCriteria(createXPath(source));
needReload = true;
}
} else if (dbo instanceof IXPathable) {
// Set XPath property
if (dbo instanceof XpathableStatement)
((XpathableStatement) dbo).setPureXpath(source);
else
((IXPathable) dbo).setXpath(source);
((DatabaseObject) dbo).hasChanged = true;
needReload = true;
}
if (needReload)
reloadTreeObject(explorerView, databaseObjectTreeObject);
} else if (targetTreeObject instanceof IPropertyTreeObject) {
IPropertyTreeObject pto = null;
if (detail == DND.DROP_MOVE) {
// Set XPath property
if (targetTreeObject instanceof IXPathable) {
((IXPathable) targetTreeObject).setXpath("." + source);
needReload = true;
} else // Add new row with xpath
if (targetTreeObject instanceof PropertyTableTreeObject) {
// // See Ticket #679 : Drag and drop without Control
// PropertyTableTreeObject description = (PropertyTableTreeObject)targetTreeObject;
// pto = description.addNewRow();
// needReload = true;
// if ((pto != null) && (pto instanceof IXPathable)) {
// ((IXPathable)pto).setXpath("."+source);
// }
String label = ((PropertyTableTreeObject) targetTreeObject).getRowDefaultLabel().toLowerCase();
throw new EngineException("Please hold on the 'Ctrl' key while dragging to create a new " + label);
}
} else if (detail == DND.DROP_COPY) {
// Add new row with xpath
if (targetTreeObject instanceof PropertyTableTreeObject) {
PropertyTableTreeObject description = (PropertyTableTreeObject) targetTreeObject;
pto = description.addNewRow();
needReload = true;
if ((pto != null) && (pto instanceof IXPathable)) {
((IXPathable) pto).setXpath("." + source);
}
} else // Add new column with xpath
if (targetTreeObject instanceof PropertyTableRowTreeObject) {
PropertyTableRowTreeObject row = (PropertyTableRowTreeObject) targetTreeObject;
pto = row.addNewColumn();
needReload = true;
if ((pto != null) && (pto instanceof IXPathable)) {
((IXPathable) pto).setXpath("." + source);
}
}
}
if (needReload) {
pto = (pto == null) ? (IPropertyTreeObject) targetTreeObject : pto;
targetTreeObject = ((IPropertyTreeObject) targetTreeObject).getTreeObjectOwner();
if (targetTreeObject instanceof DatabaseObjectTreeObject) {
// reloadTreeObject(explorerView, targetTreeObject);
TreeParent treeParent = targetTreeObject.getParent();
if (treeParent instanceof FolderTreeObject)
treeParent = treeParent.getParent();
explorerView.objectChanged(new CompositeEvent(treeParent.getObject(), pto.getPath()));
}
}
}
} else if (data instanceof StepSource) {
if (targetTreeObject instanceof DatabaseObjectTreeObject) {
final DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) targetTreeObject;
dbo = (DatabaseObject) targetTreeObject.getObject();
final Set<PropertyDescriptor> propertyDescriptors = new TreeSet<PropertyDescriptor>(new Comparator<PropertyDescriptor>() {
@Override
public int compare(PropertyDescriptor o1, PropertyDescriptor o2) {
return o1.getDisplayName().compareTo(o2.getDisplayName());
}
});
propertyDescriptors.addAll(CachedIntrospector.getPropertyDescriptors(dbo, Property.smartType));
propertyDescriptors.addAll(CachedIntrospector.getPropertyDescriptors(dbo, Property.sourceDefinition));
propertyDescriptors.addAll(CachedIntrospector.getPropertyDescriptors(dbo, Property.sourcesDefinition));
if (!propertyDescriptors.isEmpty()) {
// Retrieve Source definition
final XMLVector<String> sourceDefinition = new XMLVector<String>(2);
sourceDefinition.add(((StepSource) data).getPriority());
sourceDefinition.add(((StepSource) data).getXpath());
SelectionListener selectionListener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
PropertyDescriptor propertyDescriptor = (e == null) ? propertyDescriptors.iterator().next() : (PropertyDescriptor) e.widget.getData();
String propertyName = propertyDescriptor.getName();
if (propertyDescriptor.getPropertyType().isAssignableFrom(SmartType.class)) {
SmartType smartType = new SmartType();
smartType.setMode(Mode.SOURCE);
smartType.setSourceDefinition(sourceDefinition);
databaseObjectTreeObject.setPropertyValue(propertyDescriptor.getName(), smartType);
} else if (propertyName.equals("sourceDefinition")) {
// Use setPropertyValue in order to set object's value and fire necessary events
databaseObjectTreeObject.setPropertyValue(propertyDescriptor.getName(), sourceDefinition);
} else if (propertyName.equals("sourcesDefinition")) {
try {
XMLVector<XMLVector<Object>> sourcesDefinition = GenericUtils.cast(propertyDescriptor.getReadMethod().invoke(dbo));
// make a copy to make a property change
sourcesDefinition = new XMLVector<XMLVector<Object>>(sourcesDefinition);
XMLVector<Object> row = new XMLVector<Object>();
row.add("");
row.add(sourceDefinition);
row.add("");
sourcesDefinition.add(row);
databaseObjectTreeObject.setPropertyValue(propertyName, sourcesDefinition);
} catch (Exception ex) {
ConvertigoPlugin.logError("failed to add to sourcesDefinition of " + dbo.getName());
}
}
// Properties view needs to be refreshed
refreshPropertiesView(explorerView, databaseObjectTreeObject);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
};
if (propertyDescriptors.size() == 1) {
selectionListener.widgetSelected(null);
} else {
Shell shell = ConvertigoPlugin.getMainShell();
Menu dropMenu = new Menu(shell, SWT.POP_UP);
shell.setMenu(dropMenu);
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
MenuItem itemCheck = new MenuItem(dropMenu, SWT.NONE);
itemCheck.setText(propertyDescriptor.getDisplayName());
itemCheck.setData(propertyDescriptor);
itemCheck.addSelectionListener(selectionListener);
}
dropMenu.setVisible(true);
}
}
}
} else if (data instanceof PaletteSource) {
try {
if (targetTreeObject instanceof ObjectsFolderTreeObject) {
ObjectsFolderTreeObject folderTreeObject = (ObjectsFolderTreeObject) targetTreeObject;
targetTreeObject = folderTreeObject.getParent();
}
if (targetTreeObject instanceof DatabaseObjectTreeObject) {
DatabaseObject parent = (DatabaseObject) targetTreeObject.getObject();
String xmlData = ((PaletteSource) data).getXmlData();
Document document = XMLUtils.getDefaultDocumentBuilder().parse(new InputSource(new StringReader(xmlData)));
Element rootElement = document.getDocumentElement();
NodeList nodeList = rootElement.getChildNodes();
int len = nodeList.getLength();
Node node;
// Special objects move from palette
if (detail == DND.DROP_MOVE) {
for (int i = 0; i < len; i++) {
node = (Node) nodeList.item(i);
if (node.getNodeType() != Node.TEXT_NODE) {
if (paste(node, parent, true) == null) {
throw new Exception();
}
}
}
reloadTreeObject(explorerView, targetTreeObject);
}
} else {
throw new Exception();
}
} catch (Exception ex) {
ConvertigoPlugin.logError("failed to add from palette");
}
} else if (data instanceof MobileSource) {
try {
String jsonString = ((MobileSource) data).getJsonString();
if (targetTreeObject instanceof MobileUIComponentTreeObject) {
Shell shell = ConvertigoPlugin.getMainShell();
Menu dropMenu = new Menu(shell, SWT.POP_UP);
shell.setMenu(dropMenu);
MobileUIComponentTreeObject mcto = GenericUtils.cast(targetTreeObject);
for (IPropertyDescriptor descriptor : mcto.getPropertyDescriptors()) {
if (descriptor instanceof MobileSmartSourcePropertyDescriptor) {
MobileSmartSourcePropertyDescriptor cspd = GenericUtils.cast(descriptor);
if (!cspd.isReadOnly()) {
String propertyName = (String) cspd.getId();
String propertyLabel = (String) cspd.getDisplayName();
MenuItem itemCheck = new MenuItem(dropMenu, SWT.NONE);
itemCheck.setText(propertyLabel);
itemCheck.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType cst = new com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType();
cst.setMode(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType.Mode.SOURCE);
cst.setSmartValue(jsonString);
mcto.setPropertyValue(propertyName, cst);
refreshPropertiesView(explorerView, mcto);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
}
}
dropMenu.setVisible(true);
}
if (targetTreeObject instanceof NgxUIComponentTreeObject) {
Shell shell = ConvertigoPlugin.getMainShell();
Menu dropMenu = new Menu(shell, SWT.POP_UP);
shell.setMenu(dropMenu);
NgxUIComponentTreeObject mcto = GenericUtils.cast(targetTreeObject);
for (IPropertyDescriptor descriptor : mcto.getPropertyDescriptors()) {
if (descriptor instanceof NgxSmartSourcePropertyDescriptor) {
NgxSmartSourcePropertyDescriptor cspd = GenericUtils.cast(descriptor);
if (!cspd.isReadOnly()) {
String propertyName = (String) cspd.getId();
String propertyLabel = (String) cspd.getDisplayName();
MenuItem itemCheck = new MenuItem(dropMenu, SWT.NONE);
itemCheck.setText(propertyLabel);
itemCheck.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType cst = new com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType();
cst.setMode(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType.Mode.SOURCE);
cst.setSmartValue(jsonString);
mcto.setPropertyValue(propertyName, cst);
refreshPropertiesView(explorerView, mcto);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
}
}
dropMenu.setVisible(true);
} else {
throw new Exception();
}
} catch (Exception ex) {
ConvertigoPlugin.logError("failed to add mobile source");
}
}
}
use of com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass in project convertigo by convertigo.
the class ScHandlerStatement method getTagsForProperty.
@Override
public String[] getTagsForProperty(String propertyName) {
if (propertyName.equals("normalizedScreenClassName")) {
HtmlConnector connector = (HtmlConnector) getParent().getParent();
List<HtmlScreenClass> v = connector.getAllScreenClasses();
String[] sNames = new String[v.size() + 1];
sNames[0] = "";
for (int i = 1; i <= v.size(); i++) {
ScreenClass screenClass = (ScreenClass) v.get(i - 1);
String normalizedScreenClassName = StringUtils.normalize(screenClass.getName());
sNames[i] = normalizedScreenClassName;
}
return sNames;
}
return super.getTagsForProperty(propertyName);
}
use of com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass in project convertigo by convertigo.
the class HtmlConnectorDesignComposite method createScreenClassFromSelection.
public void createScreenClassFromSelection() throws EngineException {
String className = "com.twinsoft.convertigo.beans.core.ScreenClass";
// Retrieve selected criteria xpath
String criteriaXpath = xpathEvaluator.getSelectionXpath();
// Retrieve parent ScreenClass
HtmlScreenClass parentObject = getParentHtmlScreenClass();
NewObjectWizard newObjectWizard = new NewObjectWizard(parentObject, className);
WizardDialog wzdlg = new WizardDialog(Display.getCurrent().getActiveShell(), newObjectWizard);
wzdlg.setPageSize(850, 650);
wzdlg.open();
if (wzdlg.getReturnCode() != Window.CANCEL) {
HtmlScreenClass htmlScreenClass = (HtmlScreenClass) newObjectWizard.newBean;
if (htmlScreenClass != null) {
String screenClassName = htmlScreenClass.getName();
// Add criteria to screen class
createCriteria(htmlScreenClass, criteriaXpath);
// Set detected ScreenClass to newly created one
if (htmlConnector.isLearning()) {
detectedScreenClass = htmlScreenClass;
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) Detected screen class is set to newly created one named '" + screenClassName + "'");
} else {
ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) New screen class named '" + screenClassName + "' has been added");
}
// Reload parent ScreenClass in Tree
fireObjectChanged(new CompositeEvent(parentObject));
// Set selection on newly created screenclass
fireObjectSelected(new CompositeEvent(htmlScreenClass));
// Highlight new detected ScreenClass in Tree
if (htmlConnector.isLearning())
Engine.theApp.fireObjectDetected(new EngineEvent(htmlScreenClass));
// TODO:toolScreenclass.setEnabled(false);
}
}
}
Aggregations