use of com.twinsoft.convertigo.beans.core.ScreenClass in project convertigo by convertigo.
the class StatementTreeObject method treeObjectRemoved.
@Override
public void treeObjectRemoved(TreeObjectEvent treeObjectEvent) {
super.treeObjectRemoved(treeObjectEvent);
// Avoid the cast between "UnloadedProjectTreeObject" and "DatabaseObjectTreeObject
if (!(treeObjectEvent.getSource() instanceof UnloadedProjectTreeObject)) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
Statement statement = getObject();
boolean change = false;
// Case this is a screen class
if (databaseObject instanceof ScreenClass) {
ScreenClassTreeObject sto = (ScreenClassTreeObject) treeObjectEvent.getSource();
String screenClassName = StringUtils.normalize(databaseObject.getName());
// ScreenClass and Statement must have the same connector!
if (statement.getConnector().equals(sto.getConnectorTreeObject().getObject())) {
if (statement instanceof ITriggerOwner) {
ITriggerOwner ito = (ITriggerOwner) statement;
AbstractTrigger atrigger = ito.getTrigger().getTrigger();
if (atrigger instanceof ScreenClassTrigger) {
ScreenClassTrigger sct = (ScreenClassTrigger) atrigger;
List<String> screenClasses = sct.getScreenClasses();
for (int i = 0; i < screenClasses.size(); i++) {
if (screenClasses.get(i).equals(screenClassName)) {
screenClasses.remove(i);
change = true;
}
}
// Add default root screen class if all have been removed
if (screenClasses.isEmpty()) {
IScreenClassContainer<?> iscc = (IScreenClassContainer<?>) sto.getConnectorTreeObject().getObject();
String defaultScreenClassName = StringUtils.normalize(iscc.getDefaultScreenClass().getName());
screenClasses.add(defaultScreenClassName);
change = true;
}
if (change)
ito.setTrigger(new TriggerXMLizer(sct));
}
}
}
}
if (change)
try {
hasBeenModified(true);
getProjectExplorerView().refreshTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not refresh in tree ScHandlerStatement \"" + statement.getName() + "\" !");
}
}
}
use of com.twinsoft.convertigo.beans.core.ScreenClass in project convertigo by convertigo.
the class StatementTreeObject method handlesBeanNameChanged.
protected void handlesBeanNameChanged(TreeObjectEvent treeObjectEvent) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
Statement statement = getObject();
boolean change = false;
if (databaseObject instanceof ScreenClass) {
String oldScreenClassName = StringUtils.normalize((String) oldValue);
String newScreenClassName = StringUtils.normalize((String) newValue);
// ScreenClass and Statement must have the same connector!
if (statement.getConnector().equals(databaseObject.getConnector())) {
// Modify screenclass handlers name
if (statement instanceof ScHandlerStatement) {
ScHandlerStatement scHandlerStatement = (ScHandlerStatement) statement;
if (scHandlerStatement.getNormalizedScreenClassName().equals(oldScreenClassName)) {
String handlerType = scHandlerStatement.getHandlerType();
String beanName = "on" + newScreenClassName + handlerType;
try {
scHandlerStatement.setName(beanName);
scHandlerStatement.setNormalizedScreenClassName(newScreenClassName);
change = true;
} catch (EngineException e) {
ConvertigoPlugin.logWarning(e, "Could not rename ScHandlerStatement from \"" + scHandlerStatement.getName() + "\" to \"" + beanName + "\" !");
}
}
}
if (statement instanceof ITriggerOwner) {
ITriggerOwner ito = (ITriggerOwner) statement;
AbstractTrigger atrigger = ito.getTrigger().getTrigger();
if (atrigger instanceof ScreenClassTrigger) {
ScreenClassTrigger sct = (ScreenClassTrigger) atrigger;
List<String> screenClasses = sct.getScreenClasses();
for (int i = 0; i < screenClasses.size(); i++) if (screenClasses.get(i).equals(oldScreenClassName) && (change = true))
screenClasses.set(i, newScreenClassName);
if (change)
ito.setTrigger(new TriggerXMLizer(sct));
}
}
}
} else // Case of connector rename
if (databaseObject instanceof SiteClipperConnector) {
if (statement instanceof ContinueWithSiteClipperStatement) {
boolean isLocalProject = statement.getProject().equals(databaseObject.getProject());
boolean isSameValue = ((ContinueWithSiteClipperStatement) statement).getSiteClipperConnectorName().equals(oldValue);
if (isSameValue && isLocalProject) {
((ContinueWithSiteClipperStatement) statement).setSiteClipperConnectorName((String) newValue);
hasBeenModified(true);
viewer.refresh();
// refresh editors (e.g labels in combobox)
getDescriptors();
}
}
}
if (statement instanceof CallFunctionStatement && databaseObject.getClass().equals(FunctionStatement.class) && ((FunctionStatement) databaseObject).getParentTransaction().equals(statement.getParentTransaction())) {
CallFunctionStatement callfunction = (CallFunctionStatement) statement;
if (callfunction.getFunctionName().equals(oldValue) && (change = true))
callfunction.setFunctionName(newValue.toString());
}
if (change)
try {
hasBeenModified(true);
getProjectExplorerView().refreshTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not refresh in tree ScHandlerStatement \"" + statement.getName() + "\" !");
}
}
use of com.twinsoft.convertigo.beans.core.ScreenClass in project convertigo by convertigo.
the class TransactionTreeObject method handlesBeanNameChanged.
protected void handlesBeanNameChanged(TreeObjectEvent treeObjectEvent) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
if (databaseObject instanceof ScreenClass) {
String oldName = StringUtils.normalize((String) oldValue);
String newName = StringUtils.normalize((String) newValue);
Transaction transaction = getObject();
// Modify Screenclass name in Transaction handlers
if (!(transaction instanceof HtmlTransaction)) {
// ScreenClass and Transaction must have the same connector!
if (transaction.getConnector().equals(databaseObject.getConnector())) {
String oldHandlerPrefix = "on" + StringUtils.normalize(oldName);
String newHandlerPrefix = "on" + StringUtils.normalize(newName);
if (transaction.handlers.indexOf(oldHandlerPrefix) != -1) {
StringEx sx = new StringEx(transaction.handlers);
// Updating comments
sx.replaceAll("handler for screen class \"" + oldName + "\"", "handler for screen class \"" + newName + "\"");
// Updating functions def & calls
sx.replaceAll(oldHandlerPrefix + "Entry", newHandlerPrefix + "Entry");
sx.replaceAll(oldHandlerPrefix + "Exit", newHandlerPrefix + "Exit");
String newHandlers = sx.toString();
if (!newHandlers.equals(transaction.handlers)) {
transaction.handlers = newHandlers;
hasBeenModified(true);
}
// Update the opened handlers editor if any
JScriptEditorInput jsinput = ConvertigoPlugin.getDefault().getJScriptEditorInput(transaction);
if (jsinput != null) {
jsinput.reload();
}
try {
getProjectExplorerView().reloadTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
}
}
}
}
}
if (databaseObject instanceof Variable) {
String oldVariableName = oldValue.toString();
String newVariableName = newValue.toString();
// A variable of this transaction has been renamed
if (getObject().equals(databaseObject.getParent())) {
if (getObject() instanceof AbstractHttpTransaction) {
AbstractHttpTransaction httpTransaction = (AbstractHttpTransaction) getObject();
try {
// Check for variables to be renamed in SubDir property
String transactionSubDir = httpTransaction.getSubDir();
List<String> pathVariableList = AbstractHttpTransaction.getPathVariableList(transactionSubDir);
if (pathVariableList.contains(oldVariableName)) {
transactionSubDir = transactionSubDir.replaceAll("\\{" + oldVariableName + "\\}", "{" + newVariableName + "}");
httpTransaction.setSubDir(transactionSubDir);
httpTransaction.hasChanged = true;
}
getProjectExplorerView().refreshTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
}
}
}
}
// Case of this transaction rename : update transaction's schema
if (treeObject.equals(this)) {
String path = Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME + "/" + getConnectorTreeObject().getName();
String oldPath = path + "/" + (String) oldValue + ".xsd";
String newPath = path + "/" + (String) newValue + ".xsd";
IFile file = getProjectTreeObject().getFile(oldPath);
try {
file.getParent().refreshLocal(IResource.DEPTH_ONE, null);
if (file.exists()) {
// rename file (xsd/internal/connector/transaction.xsd)
file.move(new Path((String) newValue + ".xsd"), true, null);
// make replacements in schema files
List<Replacement> replacements = new ArrayList<Replacement>();
replacements.add(new Replacement("__" + (String) oldValue, "__" + (String) newValue));
IFile newFile = file.getParent().getFile(new Path((String) newValue + ".xsd"));
String newFilePath = newFile.getLocation().makeAbsolute().toString();
try {
ProjectUtils.makeReplacementsInFile(replacements, newFilePath);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not rename \"" + oldValue + "\" to \"" + newValue + "\" in schema file \"" + newPath + "\" !");
}
// refresh file
file.refreshLocal(IResource.DEPTH_ZERO, null);
Engine.theApp.schemaManager.clearCache(getProjectTreeObject().getName());
}
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not rename schema file from \"" + oldPath + "\" to \"" + newPath + "\" !");
}
}
}
use of com.twinsoft.convertigo.beans.core.ScreenClass in project convertigo by convertigo.
the class DatabaseObjectDeleteAction method delete.
private void delete(DatabaseObject databaseObject, boolean deleteProjectOnDisk) throws EngineException, CoreException {
if (databaseObject instanceof Connector) {
if (((Connector) databaseObject).isDefault) {
throw new EngineException("Cannot delete the default connector!");
}
String dirPath, projectName;
File dir;
projectName = databaseObject.getParent().getName();
MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
messageBox.setText("Also delete linked resources?");
// Delete soap templates for this connector
dirPath = Engine.projectDir(projectName) + "/soap-templates/" + databaseObject.getName();
dir = new File(dirPath);
if (dir.exists()) {
messageBox.setMessage("Some resources are linked to the deleted connector.\n\n" + "Do you also want to delete folder:\n\n\"" + dirPath + "\"");
if (messageBox.open() == SWT.YES) {
try {
DatabaseObjectsManager.deleteDir(dir);
} catch (IOException e) {
ConvertigoPlugin.logDebug("Unable to delete directory \"" + dirPath + "\"!");
}
}
}
// Delete directory corresponding to connector under Traces directory
dirPath = Engine.projectDir(projectName) + "/Traces/" + databaseObject.getName();
dir = new File(dirPath);
if (dir.exists()) {
messageBox.setMessage("Some resources are linked to the deleted connector.\n\n" + "Do you also want to delete folder:\n\n\"" + dirPath + "\"");
if (messageBox.open() == SWT.YES) {
try {
DatabaseObjectsManager.deleteDir(dir);
} catch (IOException e) {
ConvertigoPlugin.logDebug("Unable to delete directory \"" + dirPath + "\"!");
}
}
}
} else if (databaseObject instanceof Transaction) {
if (((Transaction) databaseObject).isDefault) {
throw new EngineException("Cannot delete the default transaction!");
}
} else if (databaseObject instanceof ScreenClass) {
if ((databaseObject.getParent()) instanceof Project) {
throw new EngineException("Cannot delete the root screen class!");
}
} else if (databaseObject instanceof Statement) {
if ((databaseObject instanceof ThenStatement) || (databaseObject instanceof ElseStatement)) {
throw new EngineException("Cannot delete this statement!");
}
} else if (databaseObject instanceof Step) {
if ((databaseObject instanceof ThenStep) || (databaseObject instanceof ElseStep)) {
throw new EngineException("Cannot delete this step!");
}
} else if (databaseObject instanceof MobilePlatform) {
MobilePlatform mobilePlatform = (MobilePlatform) databaseObject;
File resourceFolder = mobilePlatform.getResourceFolder();
if (resourceFolder.exists()) {
MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
messageBox.setMessage("Do you want to delete the whole resource folder \"" + mobilePlatform.getRelativeResourcePath() + "\"?");
messageBox.setText("Delete the \"" + resourceFolder.getName() + "\" folder?");
if (messageBox.open() == SWT.YES) {
FileUtils.deleteQuietly(resourceFolder);
}
}
} else if (databaseObject instanceof PageComponent) {
if (((PageComponent) databaseObject).isRoot) {
throw new EngineException("Cannot delete the root page!");
}
}
String dboQName = databaseObject.getQName();
if (databaseObject instanceof Project) {
// Engine.theApp.databaseObjectsManager.deleteProject(databaseObject.getName());
if (deleteProjectOnDisk) {
Engine.theApp.databaseObjectsManager.deleteProjectAndCar(databaseObject.getName(), DeleteProjectOption.unloadOnly);
} else {
Engine.theApp.databaseObjectsManager.deleteProject(databaseObject.getName(), DeleteProjectOption.unloadOnly);
}
ConvertigoPlugin.getDefault().deleteProjectPluginResource(deleteProjectOnDisk, databaseObject.getName());
} else {
databaseObject.delete();
}
if (databaseObject instanceof CouchDbConnector) {
CouchDbConnector couchDbConnector = (CouchDbConnector) databaseObject;
String db = couchDbConnector.getDatabaseName();
if (!db.isEmpty()) {
MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
messageBox.setMessage("Do you want to delete the \"" + db + "\" database from the CouchDb server?");
messageBox.setText("Delete the database?");
if (messageBox.open() == SWT.YES) {
couchDbConnector.getCouchClient().deleteDatabase(db);
}
}
}
ConvertigoPlugin.logDebug("The object \"" + dboQName + "\" has been deleted from the database repository!");
}
use of com.twinsoft.convertigo.beans.core.ScreenClass 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);
}
}
}
Aggregations