use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.
the class HtmlTransaction method addStatement.
public void addStatement(Statement statement) throws EngineException {
checkSubLoaded();
// Do not use getChildBeanName here because of ScHandlerStatement!!
String newDatabaseObjectName = statement.getName();
for (Statement st : vStatements) {
if (newDatabaseObjectName.equals(st.getName())) {
throw new ObjectWithSameNameException("Unable to add the statement \"" + newDatabaseObjectName + "\" to the html transaction class because a statement with the same name already exists.");
}
}
vStatements.add(statement);
// do not call super.add otherwise it will generate an exception
statement.setParent(this);
if (statement.priority != 0) {
statement.priority = 0;
statement.hasChanged = true;
}
}
use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.
the class TreeDropAdapter method performDrop.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
*/
@Override
public boolean performDrop(Object data) {
MobileBuilder mb = null;
Engine.logStudio.info("---------------------- Drop started ----------------------");
try {
Object targetObject = getCurrentTarget();
IEditorPart editorPart = ConvertigoPlugin.getDefault().getApplicationComponentEditor();
if (editorPart != null) {
IEditorInput input = editorPart.getEditorInput();
if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
mb = editorInput.getApplication().getProject().getMobileBuilder();
}
if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
mb = editorInput.getApplication().getProject().getMobileBuilder();
}
}
// Handle tree objects reordering with Drag and Drop
if (data instanceof String) {
boolean insertBefore = (feedback & DND.FEEDBACK_INSERT_BEFORE) != 0;
boolean insertAfter = (feedback & DND.FEEDBACK_INSERT_AFTER) != 0;
if (insertBefore || insertAfter) {
Object sourceObject = getSelectedObject();
TreeParent targetTreeParent = ((TreeObject) targetObject).getParent();
List<? extends TreeObject> children = targetTreeParent.getChildren();
int destPosition = children.indexOf(targetObject);
int srcPosition = children.indexOf(sourceObject);
int delta = destPosition - srcPosition;
int count = (delta < 0) ? (insertBefore ? delta : delta + 1) : (insertBefore ? delta - 1 : delta);
if (count != 0) {
if (mb != null) {
mb.prepareBatchBuild();
}
BatchOperationHelper.start();
if (count < 0) {
new DatabaseObjectIncreasePriorityAction(Math.abs(count)).run();
} else {
new DatabaseObjectDecreasePriorityAction(Math.abs(count)).run();
}
BatchOperationHelper.stop();
}
return true;
}
}
// Handle objects copy or move with Drag and drop
if (targetObject instanceof TreeObject) {
TreeObject targetTreeObject = (TreeObject) targetObject;
if (targetTreeObject != null) {
ProjectExplorerView explorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
Document document = null;
try {
Shell shell = Display.getDefault().getActiveShell();
try {
// Try to parse text data into an XML document
String source = data.toString();
document = XMLUtils.getDefaultDocumentBuilder().parse(new InputSource(new StringReader(source)));
if (mb != null) {
mb.prepareBatchBuild();
}
BatchOperationHelper.start();
ClipboardAction.dnd.paste(source, shell, explorerView, targetTreeObject, true);
BatchOperationHelper.stop();
return true;
} catch (SAXException sax) {
BatchOperationHelper.cancel();
if (mb != null) {
mb.prepareBatchBuild();
}
BatchOperationHelper.start();
// Parse failed probably because data was not XML but an XPATH String
// in this case, create DatabaseObjects of the correct Type according to the folder where the XPATH is dropped on
performDrop(data, explorerView, targetTreeObject);
BatchOperationHelper.stop();
return true;
}
} catch (Exception e) {
BatchOperationHelper.cancel();
if (e instanceof ObjectWithSameNameException) {
document = null;
}
if (e instanceof InvalidOperationException) {
document = null;
}
// Case of unauthorized databaseObject paste
if (document != null) {
try {
if (!(targetTreeObject instanceof IPropertyTreeObject)) {
Element rootElement = document.getDocumentElement();
NodeList nodeList = rootElement.getChildNodes();
boolean unauthorized = false;
int len = nodeList.getLength();
Node node;
// case of folder, retrieve owner object
targetTreeObject = explorerView.getFirstSelectedDatabaseObjectTreeObject(targetTreeObject);
if (detail == DND.DROP_COPY) {
for (int i = 0; i < len; i++) {
node = (Node) nodeList.item(i);
if (node.getNodeType() != Node.TEXT_NODE) {
// Special objects paste
if (!paste(node, targetTreeObject)) {
// Real unauthorized databaseObject paste
unauthorized = true;
}
}
}
reloadTreeObject(explorerView, targetTreeObject);
} else if (detail == DND.DROP_MOVE) {
for (int i = 0; i < len; i++) {
node = (Node) nodeList.item(i);
if (node.getNodeType() != Node.TEXT_NODE) {
// Special objects move
if (!move(node, targetTreeObject)) {
// Real unauthorized databaseObject move
unauthorized = true;
}
}
}
reloadTreeObject(explorerView, targetTreeObject);
} else {
// Real unauthorized databaseObject
unauthorized = true;
}
if (unauthorized) {
throw e;
}
return true;
}
} catch (Exception ex) {
ConvertigoPlugin.errorMessageBox(ex.getMessage());
return false;
}
} else {
ConvertigoPlugin.errorMessageBox(e.getMessage());
return false;
}
}
}
}
return false;
} finally {
Engine.logStudio.info("---------------------- Drop ended ----------------------");
BatchOperationHelper.cancel();
}
}
use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.
the class TreeDropAdapter method paste.
public DatabaseObject paste(Node node, DatabaseObject parentDatabaseObject, boolean bChangeName) throws EngineException {
Object object = ConvertigoPlugin.clipboardManagerDND.read(node);
if (object instanceof DatabaseObject) {
DatabaseObject databaseObject = (DatabaseObject) object;
String dboName = databaseObject.getName();
String name = null;
boolean bContinue = true;
int index = 0;
while (bContinue) {
if (bChangeName) {
if (index == 0)
name = dboName;
else
name = dboName + index;
databaseObject.setName(name);
}
databaseObject.hasChanged = true;
databaseObject.bNew = true;
try {
if (parentDatabaseObject != null)
parentDatabaseObject.add(databaseObject);
bContinue = false;
} catch (ObjectWithSameNameException owsne) {
if ((parentDatabaseObject instanceof HtmlTransaction) && (databaseObject instanceof Statement))
throw new EngineException("HtmlTransaction already contains a statement named \"" + name + "\".", owsne);
if ((parentDatabaseObject instanceof Sequence) && (databaseObject instanceof Step))
throw new EngineException("Sequence already contains a step named \"" + name + "\".", owsne);
// Silently ignore
index++;
}
}
NodeList childNodes = node.getChildNodes();
int len = childNodes.getLength();
Node childNode;
String childNodeName;
for (int i = 0; i < len; i++) {
childNode = childNodes.item(i);
if (childNode.getNodeType() != Node.ELEMENT_NODE)
continue;
childNodeName = childNode.getNodeName();
if (!(childNodeName.equalsIgnoreCase("property")) && !(childNodeName.equalsIgnoreCase("handlers")) && !(childNodeName.equalsIgnoreCase("wsdltype")) && !(childNodeName.equalsIgnoreCase("docdata")) && !(childNodeName.equalsIgnoreCase("beandata")) && !(childNodeName.equalsIgnoreCase("dnd"))) {
paste(childNode, databaseObject, bChangeName);
}
}
// needed !
databaseObject.isImporting = false;
databaseObject.isSubLoaded = true;
return databaseObject;
}
return null;
}
use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.
the class StatementInfoWizardPage method dialogChanged.
private void dialogChanged(boolean increment) {
String name = getBeanName();
if (name.length() == 0) {
updateStatus("Name must be specified");
return;
}
if (!StringUtils.isNormalized(name)) {
updateStatus("Name must be normalized.\nDon't start with number and don't use non ASCII caracters.");
return;
}
Matcher m = Pattern.compile("\\d+$").matcher("");
boolean sameName;
do {
sameName = false;
try {
((StatementGeneratorWizardPage) getWizard().getPage("StatementGeneratorWizardPage")).getCreatedBean().setName(name);
} catch (ObjectWithSameNameException e) {
if (!increment) {
updateStatus("Name already used by siblings");
return;
}
sameName = true;
m.reset(name);
if (m.find()) {
name = name.substring(0, m.start()) + (Integer.parseInt(m.group()) + 1);
} else {
name = name + "_1";
}
setBeanName(name);
} catch (EngineException e) {
updateStatus("Name could not be set on bean");
return;
} catch (NullPointerException e) {
updateStatus("New Bean has not been instanciated");
return;
}
} while (sameName);
updateStatus(null);
}
use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.
the class ComponentInfoWizardPage method dialogChanged.
private void dialogChanged(boolean increment) {
DatabaseObject dbo = ((ComponentExplorerWizardPage) getWizard().getPage("ComponentExplorerWizardPage")).getCreatedBean();
if (dbo != null) {
String name = getBeanName();
if (name.length() == 0) {
updateStatus("Name must be specified");
return;
}
if (!StringUtils.isNormalized(name)) {
updateStatus("Name must be normalized.\nDon't start with number and don't use non ASCII caracters.");
return;
}
Matcher m = Pattern.compile("\\d+$").matcher("");
boolean sameName;
do {
sameName = false;
try {
dbo.setName(name);
} catch (ObjectWithSameNameException e) {
if (!increment) {
updateStatus("Name already used by siblings");
return;
}
sameName = true;
m.reset(name);
if (m.find()) {
name = name.substring(0, m.start()) + (Integer.parseInt(m.group()) + 1);
} else {
name = name + "_1";
}
setBeanName(name);
} catch (EngineException e) {
updateStatus("Name could not be set on bean");
return;
} catch (NullPointerException e) {
updateStatus("New Bean has not been instanciated");
return;
}
} while (sameName);
}
updateStatus(null);
}
Aggregations