use of com.twinsoft.convertigo.beans.core.Criteria in project convertigo by convertigo.
the class GetChildren method getChildren.
public static void getChildren(String qname, Element parent, int depth) throws Exception {
DatabaseObject dbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
List<DatabaseObject> children = dbo.getDatabaseObjectChildren();
// Get all children of the dbo
Element elt = createDboElement(parent.getOwnerDocument(), dbo, !children.isEmpty());
/*
* In case of ScreenClass, we have to get Criteria, ExtractionRule and Sheets manually.
* If fact, if the dbo is an inherited screen class, inherited Criteria, ExtractionRule and Sheets,
* won't be retrieved by the method #getDatabaseObjectChildren.
*/
if (dbo instanceof ScreenClass) {
ScreenClass sc = (ScreenClass) dbo;
boolean hasChildren = false;
// Get all Criteria
List<Criteria> criteria = sc.getCriterias();
for (Criteria criterion : criteria) {
children.remove(criterion);
Element eltCriterion = createScreenClassChildElement(parent.getOwnerDocument(), criterion, dbo);
elt.appendChild(eltCriterion);
hasChildren = true;
}
// Get all Extraction Rules
List<ExtractionRule> extractionRules = sc.getExtractionRules();
for (ExtractionRule extractionRule : extractionRules) {
children.remove(extractionRule);
Element eltExtractionRule = createScreenClassChildElement(parent.getOwnerDocument(), extractionRule, dbo);
elt.appendChild(eltExtractionRule);
hasChildren = true;
}
// Get all Sheets
List<Sheet> sheets = sc.getSheets();
for (Sheet sheet : sheets) {
children.remove(sheet);
Element eltSheet = createScreenClassChildElement(parent.getOwnerDocument(), sheet, dbo);
elt.appendChild(eltSheet);
hasChildren = true;
}
// In case of JavelinScreenClass, we also have to get the block factory manually
if (dbo instanceof JavelinScreenClass) {
JavelinScreenClass jsc = (JavelinScreenClass) sc;
BlockFactory blockFactory = jsc.getBlockFactory();
children.remove(blockFactory);
Element eltBlockFactory = createScreenClassChildElement(parent.getOwnerDocument(), blockFactory, dbo);
elt.appendChild(eltBlockFactory);
hasChildren = true;
}
if (hasChildren) {
elt.setAttribute("hasChildren", "true");
}
}
parent.appendChild(elt);
if (depth > 0) {
for (DatabaseObject child : children) {
getChildren(child.getQName(), elt, depth - 1);
}
}
}
use of com.twinsoft.convertigo.beans.core.Criteria in project convertigo by convertigo.
the class ScreenClassHelper method findScreenClass.
private SC findScreenClass(SC currentScreenClass) throws EngineException {
int scDepth = currentScreenClass.getDepth() * 3;
String tab = scDepth == 0 ? "" : String.format("%" + scDepth + "s", "");
Engine.logBeans.trace(tab + "Analyzing screen class " + currentScreenClass.getName());
currentScreenClass.checkSymbols();
for (Criteria criteria : currentScreenClass.getLocalCriterias()) {
criteria.checkSymbols();
if (criteria.isMatching(connector)) {
Engine.logBeans.trace(tab + ". Criteria " + criteria.getName() + " is matching");
} else {
Engine.logBeans.trace(tab + ". Criteria " + criteria.getName() + " not matching; aborting screen class analyze");
return null;
}
}
Engine.logBeans.trace(tab + "::: Screen class " + currentScreenClass.getName() + " is matching");
SC bestFoundScreenClass = currentScreenClass;
int bestFoundScreenClassNumberOfLocalCriterias = bestFoundScreenClass.getNumberOfLocalCriterias();
SC screenClass;
for (SC inheritedScreenClass : getInheritedScreenClasses(currentScreenClass)) if ((screenClass = findScreenClass(inheritedScreenClass)) != null) {
int screenClassNumberOfLocalCriterias = screenClass.getNumberOfLocalCriterias();
// Avoid the "folder" screen classes, i.e. those with no local criterias
if (screenClassNumberOfLocalCriterias != 0) {
if ((screenClass.getDepth() > bestFoundScreenClass.getDepth()) || (screenClassNumberOfLocalCriterias > bestFoundScreenClassNumberOfLocalCriterias)) {
bestFoundScreenClass = screenClass;
bestFoundScreenClassNumberOfLocalCriterias = screenClassNumberOfLocalCriterias;
Engine.logBeans.trace(tab + " >>> Found a better screen class " + screenClass.getName());
}
}
}
if (// Setting the returned screen class to the best found one
bestFoundScreenClass != null)
currentScreenClass = bestFoundScreenClass;
Engine.logBeans.trace(tab + "<<< Returning " + currentScreenClass.getName());
return currentScreenClass;
}
use of com.twinsoft.convertigo.beans.core.Criteria in project convertigo by convertigo.
the class HtmlConnectorDesignComposite method createCriteriasFromSelection.
public void createCriteriasFromSelection(Document dom) throws EngineException {
String className = "com.twinsoft.convertigo.beans.core.Criteria";
// Retrieve selected criterias xpath
String criteriaXpath = xpathEvaluator.getSelectionXpath();
// Retrieve parent ScreenClass
HtmlScreenClass parentObject = getParentHtmlScreenClass();
NewObjectWizard newObjectWizard = new NewObjectWizard(parentObject, className, criteriaXpath, dom);
WizardDialog wzdlg = new WizardDialog(Display.getCurrent().getActiveShell(), newObjectWizard);
wzdlg.setPageSize(850, 650);
wzdlg.open();
if (wzdlg.getReturnCode() != Window.CANCEL) {
Criteria criteria = (Criteria) newObjectWizard.newBean;
// Reload parent ScreenClass in Tree
fireObjectChanged(new CompositeEvent(parentObject));
// Set selection on last created criteria (will expand tree to new criteria)
if (criteria != null)
fireObjectSelected(new CompositeEvent(criteria));
// Set back selection on parent ScreenClass
fireObjectSelected(new CompositeEvent(parentObject));
}
}
use of com.twinsoft.convertigo.beans.core.Criteria in project convertigo by convertigo.
the class ClipboardManager method cutAndPaste.
public void cutAndPaste(final DatabaseObject object, DatabaseObject parentDatabaseObject) throws ConvertigoException {
// Verifying if a sheet with the same browser does not already exist
if (object instanceof Sheet) {
String browser = ((Sheet) object).getBrowser();
Sheet sheet = null;
if (parentDatabaseObject instanceof ScreenClass) {
sheet = ((ScreenClass) parentDatabaseObject).getLocalSheet(browser);
} else if (parentDatabaseObject instanceof RequestableObject) {
sheet = ((RequestableObject) parentDatabaseObject).getSheet(browser);
}
if (sheet != null) {
throw new EngineException("You cannot cut and paste the sheet because a sheet is already defined for the browser \"" + browser + "\" in the screen class \"" + parentDatabaseObject.getName() + "\".");
}
}
if (object instanceof Step) {
if (object instanceof ThenStep) {
throw new EngineException("You cannot cut the \"Then\" step");
}
if (object instanceof ElseStep) {
throw new EngineException("You cannot cut the \"Else\" step");
}
}
if (object instanceof Statement) {
if (object instanceof ThenStatement)
throw new EngineException("You cannot cut the \"Then\" statement");
if (object instanceof ElseStatement)
throw new EngineException("You cannot cut the \"Else\" statement");
}
// Verify object is accepted for paste
if (!DatabaseObjectsManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
}
if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
}
if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
String tplVersion = com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.getTplRequired(object);
throw new EngineException("Template project " + tplVersion + " compatibility required");
}
} else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
}
if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
String tplVersion = com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.getTplRequired(object);
throw new EngineException("Template project " + tplVersion + " compatibility required");
}
}
// Verify if a child object with same name exist
boolean bContinue = true;
boolean bIncName = false;
String dboName = object.getName();
while (bContinue) {
try {
if (bIncName) {
dboName = DatabaseObject.incrementName(dboName);
object.setName(dboName);
}
new WalkHelper() {
boolean root = true;
boolean find = false;
@Override
protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
boolean isInstance = dboClass.isInstance(object);
find |= isInstance;
return isInstance;
}
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
if (root) {
root = false;
if (databaseObject instanceof Project) {
if (object instanceof Connector && ((Connector) object).isDefault) {
throw new EngineException("You cannot cut the default connector to another project");
}
} else if (databaseObject instanceof Connector) {
if (object instanceof ScreenClass) {
throw new EngineException("You cannot cut the default screen class to another connector");
} else if (object instanceof Transaction && ((Transaction) object).isDefault) {
throw new EngineException("You cannot cut the default transaction to another connector");
}
} else if (databaseObject instanceof ScreenClass) {
if (object instanceof Criteria && databaseObject.getParent() instanceof Connector) {
throw new EngineException("You cannot cut the criterion of default screen class");
}
} else if (databaseObject instanceof MobileObject) {
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) {
if (object instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
com.twinsoft.convertigo.beans.mobile.components.PageComponent pc = GenericUtils.cast(object);
if (pc.isRoot) {
throw new EngineException("You cannot cut the root page to another application");
}
}
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) {
if (object instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
com.twinsoft.convertigo.beans.ngx.components.PageComponent pc = GenericUtils.cast(object);
if (pc.isRoot) {
throw new EngineException("You cannot cut the root page to another application");
}
}
}
}
super.walk(databaseObject);
if (!find) {
throw new EngineException("You cannot cut and paste to a " + databaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
}
} else {
if (object != databaseObject && object.getName().equalsIgnoreCase(databaseObject.getName())) {
throw new ObjectWithSameNameException("Unable to cut the object because an object with the same name already exists in target.");
}
}
}
}.init(parentDatabaseObject);
bContinue = false;
} catch (ObjectWithSameNameException e) {
bIncName = true;
} catch (EngineException e) {
throw e;
} catch (Exception e) {
throw new EngineException("Exception in cutAndPaste", e);
}
}
move(object, parentDatabaseObject);
}
use of com.twinsoft.convertigo.beans.core.Criteria in project convertigo by convertigo.
the class SiteClipperScreenClass method getNumberOfLocalCriterias.
@Override
public int getNumberOfLocalCriterias() {
// If we are in REQUEST mode, return the number of request criteria.
Shuttle shuttle = getConnector().getShuttle();
if (shuttle != null && shuttle.getProcessState() == ProcessState.request) {
List<Criteria> localCriteria = getLocalCriterias();
int nRequestLocalCriteria = 0;
for (Criteria criteria : localCriteria) {
if (criteria instanceof ISiteClipperRequestCriteria)
nRequestLocalCriteria++;
}
return nRequestLocalCriteria;
}
// return the total number of local criteria.
return super.getNumberOfLocalCriterias();
}
Aggregations