use of com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput 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 {
ConvertigoPlugin.getDefault().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;
}
ConvertigoPlugin.getDefault().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.eclipse.editors.jscript.JScriptEditorInput in project convertigo by convertigo.
the class ConvertigoPlugin method getJScriptEditorInput.
public JScriptEditorInput getJScriptEditorInput(Transaction transaction) {
JScriptEditorInput jScriptEditorInput = null;
IWorkbenchPage activePage = getActivePage();
if (activePage != null && transaction != null) {
for (IEditorReference editorRef : activePage.getEditorReferences()) {
try {
IEditorInput editorInput = editorRef.getEditorInput();
if (editorInput != null && editorInput instanceof JScriptEditorInput) {
if (((JScriptEditorInput) editorInput).is(transaction)) {
jScriptEditorInput = (JScriptEditorInput) editorInput;
break;
}
}
} catch (PartInitException e) {
// ConvertigoPlugin.logException(e, "Error while retrieving the jscript transaction editor '" + editorRef.getName() + "'");
}
}
}
return jScriptEditorInput;
}
use of com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput in project convertigo by convertigo.
the class TransactionCreateHandlerAction method run.
@Override
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
Statement lastStatement = null;
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
if (treeObject != null) {
Transaction transaction = null;
if (treeObject instanceof TransactionTreeObject) {
transaction = (Transaction) treeObject.getObject();
} else if (treeObject instanceof ObjectsFolderTreeObject) {
transaction = (Transaction) treeObject.getParent().getObject();
}
if (transaction != null) {
CreateHandlerDialog createHandlerDialog = new CreateHandlerDialog(shell, transaction);
createHandlerDialog.open();
if (createHandlerDialog.getReturnCode() != Window.CANCEL) {
List<?> result = createHandlerDialog.result;
if (result != null) {
int len = result.size();
if (len > 0) {
if (transaction instanceof HtmlTransaction) {
HtmlTransaction htmlTransaction = (HtmlTransaction) transaction;
Statement statement = null;
for (int i = 0; i < len; i++) {
statement = (Statement) result.get(i);
htmlTransaction.addStatement(statement);
}
lastStatement = statement;
} else {
String handler = null;
for (int i = 0; i < len; i++) {
handler = (String) result.get(i);
transaction.handlers += handler;
transaction.hasChanged = true;
}
// Update the opened handlers editor if any
JScriptEditorInput jsinput = ConvertigoPlugin.getDefault().getJScriptEditorInput(transaction);
if (jsinput != null) {
jsinput.reload();
}
}
// Reload transaction in tree and select last created Statement.
try {
ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
projectExplorerView.reloadDatabaseObject(transaction);
if (transaction instanceof HtmlTransaction) {
if (lastStatement != null) {
projectExplorerView.objectSelected(new CompositeEvent(lastStatement));
}
} else {
projectExplorerView.objectSelected(new CompositeEvent(transaction));
}
} catch (IOException e) {
}
}
}
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to create new handler for transaction!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput in project convertigo by convertigo.
the class DesignDocumentFunctionTreeObject method closeAllEditors.
public void closeAllEditors(boolean save) {
DesignDocument ddoc = getDesignDocumentTreeObject().getObject();
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (activePage != null) {
IEditorReference[] editorRefs = activePage.getEditorReferences();
for (int i = 0; i < editorRefs.length; i++) {
IEditorReference editorRef = (IEditorReference) editorRefs[i];
try {
IEditorInput editorInput = editorRef.getEditorInput();
if (editorInput != null && editorInput instanceof JScriptEditorInput) {
if (((JScriptEditorInput) editorInput).is(ddoc)) {
activePage.closeEditor(editorRef.getEditor(false), save);
}
}
} catch (Exception e) {
}
}
}
}
use of com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput in project convertigo by convertigo.
the class MyAbstractAction method getJscriptTransactionEditor.
public IEditorPart getJscriptTransactionEditor(Transaction transaction) {
IEditorPart editorPart = null;
IWorkbenchPage activePage = getActivePage();
if (activePage != null) {
if (transaction != null) {
IEditorReference[] editorRefs = activePage.getEditorReferences();
for (int i = 0; i < editorRefs.length; i++) {
IEditorReference editorRef = (IEditorReference) editorRefs[i];
try {
IEditorInput editorInput = editorRef.getEditorInput();
if ((editorInput != null) && (editorInput instanceof JScriptEditorInput)) {
if (transaction.equals(((JScriptEditorInput) editorInput).getDatabaseObject())) {
editorPart = editorRef.getEditor(false);
break;
}
}
} catch (PartInitException e) {
// ConvertigoPlugin.logException(e, "Error while retrieving the jscript transaction editor '" + editorRef.getName() + "'");
}
}
}
}
return editorPart;
}
Aggregations