use of com.twinsoft.convertigo.beans.core.MobileObject 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
try {
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.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);
} 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.MobileObject in project convertigo by convertigo.
the class ClipboardManager method paste.
public void paste(String xmlData, Object parentObject, boolean bChangeName) throws EngineException, SAXException, IOException {
Document document = XMLUtils.getDefaultDocumentBuilder().parse(new InputSource(new StringReader(xmlData)));
Element rootElement = document.getDocumentElement();
NodeList nodeList = rootElement.getChildNodes();
int len = nodeList.getLength();
Node node;
pastedSteps.clear();
pastedComponents.clear();
pastedObjects = new Object[] {};
if (len > 0) {
pastedObjects = new Object[len];
}
Object object = null;
for (int i = 0; i < len; i++) {
node = (Node) nodeList.item(i);
if (node.getNodeType() != Node.TEXT_NODE) {
if (parentObject instanceof IPropertyTreeObject) {
object = paste(node, (IPropertyTreeObject) parentObject, bChangeName);
} else if (parentObject instanceof IDesignTreeObject) {
object = paste(node, (IDesignTreeObject) parentObject, bChangeName);
} else {
object = paste(node, (DatabaseObject) parentObject, bChangeName);
}
pastedObjects[i] = object;
}
}
for (Entry<String, Step> entry : pastedSteps.entrySet()) {
Step step = entry.getValue();
step.getSequence().fireStepCopied(new StepEvent(step, entry.getKey()));
}
for (Object ob : pastedObjects) {
// MOBILE COMPONENTS
if (ob instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
if (ob instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
com.twinsoft.convertigo.beans.mobile.components.PageComponent page = GenericUtils.cast(ob);
for (Entry<String, MobileObject> entry : pastedComponents.entrySet()) {
if (page.updateSmartSources(entry.getKey(), String.valueOf(entry.getValue().priority))) {
page.markPageAsDirty();
}
}
} else if (ob instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
com.twinsoft.convertigo.beans.mobile.components.UIComponent uic = GenericUtils.cast(ob);
for (Entry<String, MobileObject> entry : pastedComponents.entrySet()) {
if (uic.updateSmartSources(entry.getKey(), String.valueOf(entry.getValue().priority))) {
uic.markAsDirty();
}
}
}
}
// NGX COMPONENTS
if (ob instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
if (ob instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
com.twinsoft.convertigo.beans.ngx.components.PageComponent page = GenericUtils.cast(ob);
for (Entry<String, MobileObject> entry : pastedComponents.entrySet()) {
if (page.updateSmartSources(entry.getKey(), String.valueOf(entry.getValue().priority))) {
page.markPageAsDirty();
}
}
} else if (ob instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
com.twinsoft.convertigo.beans.ngx.components.UIComponent uic = GenericUtils.cast(ob);
for (Entry<String, MobileObject> entry : pastedComponents.entrySet()) {
if (uic.updateSmartSources(entry.getKey(), String.valueOf(entry.getValue().priority))) {
uic.markAsDirty();
}
}
}
}
}
}
Aggregations