use of com.twinsoft.convertigo.beans.transactions.JavelinTransaction in project convertigo by convertigo.
the class ReferencesView method handleTransactionSelection.
private void handleTransactionSelection(Object firstElement) {
TransactionTreeObject transactionTreeObject = (TransactionTreeObject) firstElement;
Transaction transaction = transactionTreeObject.getObject();
String transactionName = transactionTreeObject.getName();
// Get the referencing sequence steps
String transactionProjectName = transaction.getProject().getName();
String transactionConnectorName = transaction.getParent().getName();
try {
Project project = null;
List<String> projectNames = Engine.theApp.databaseObjectsManager.getAllProjectNamesList();
ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
treeViewer.setInput(null);
RootNode root = new RootNode();
TransactionNode transactionFolder = new TransactionNode(root, transactionName, transaction);
root.addChild(transactionFolder);
IsUsedByNode isUsedByNode = new IsUsedByNode(transactionFolder, "Is used by");
RequiresNode requiresNode = new RequiresNode(transactionFolder, "Requires");
ProjectNode projectFolder = null;
// Searching all objects are required transaction selected
Connector connector = transaction.getConnector();
if (connector instanceof HtmlConnector) {
Project proj = ((HtmlConnector) connector).getProject();
ProjectNode projectNode = new ProjectNode(requiresNode, transactionProjectName, proj);
HtmlTransaction htmlTransaction = (HtmlTransaction) transaction;
List<Statement> statements = htmlTransaction.getStatements();
List<ScreenClass> screenClassList = new ArrayList<ScreenClass>();
List<String> siteClipperConnectorNames = new ArrayList<String>();
for (Statement statement : statements) {
if (statement instanceof ScHandlerStatement) {
ScHandlerStatement scHandlerStatement = (ScHandlerStatement) statement;
String screenClassName = scHandlerStatement.getNormalizedScreenClassName();
ScreenClass screenClass = ((HtmlConnector) connector).getScreenClassByName(screenClassName);
if (screenClass != null) {
if (!screenClassList.contains(screenClass)) {
screenClassList.add(screenClass);
requiresNode.addChild(new ScreenClassNode(requiresNode, screenClassName, screenClass));
}
}
}
List<Statement> statementList = ((FunctionStatement) statement).getStatements();
for (Statement st : statementList) {
if (st instanceof ContinueWithSiteClipperStatement) {
ContinueWithSiteClipperStatement continueWithSiteClipperStatement = (ContinueWithSiteClipperStatement) st;
String siteClipperconnectorName = continueWithSiteClipperStatement.getSiteClipperConnectorName();
if (!siteClipperConnectorNames.contains(siteClipperconnectorName)) {
siteClipperConnectorNames.add(siteClipperconnectorName);
Connector siteClipperConnector = proj.getConnectorByName(siteClipperconnectorName);
ConnectorNode connectorSiteClipperNode = new SiteClipperConnectorNode(projectNode, siteClipperconnectorName, siteClipperConnector);
projectNode.addChild(connectorSiteClipperNode);
}
}
}
}
if (projectNode.hasChildren()) {
requiresNode.addChild(projectNode);
}
} else if (connector instanceof JavelinConnector) {
JavelinTransaction javelinTransaction = (JavelinTransaction) transaction;
String handlers = javelinTransaction.handlers;
List<JavelinScreenClass> screenClasses = ((JavelinConnector) connector).getAllScreenClasses();
List<JavelinScreenClass> screenClassList = new ArrayList<JavelinScreenClass>();
for (JavelinScreenClass screenClass : screenClasses) {
if (handlers.indexOf("function on" + screenClass.getName()) != -1) {
if (!screenClassList.contains(screenClass)) {
screenClassList.add(screenClass);
requiresNode.addChild(new ScreenClassNode(requiresNode, screenClass.getName(), screenClass));
}
}
}
}
// Searching all objects are used transaction selected
for (String projectName : projectNames) {
project = getProject(projectName, projectExplorerView);
if (project != null) {
projectFolder = new ProjectNode(isUsedByNode, project.getName(), project);
UrlMapper urlMapper = project.getUrlMapper();
if (urlMapper != null) {
MapperNode mapperNode = new MapperNode(projectFolder, urlMapper.getName(), urlMapper);
List<UrlMapping> mappings = urlMapper.getMappingList();
for (UrlMapping mapping : mappings) {
MappingPathNode pathNode = new MappingPathNode(mapperNode, mapping.getPath(), mapping);
List<UrlMappingOperation> operations = mapping.getOperationList();
for (UrlMappingOperation operation : operations) {
String targetRequestable = operation.getTargetRequestable();
if (targetRequestable.equals(transactionProjectName + "." + transactionConnectorName + "." + transactionName)) {
MappingOperationNode operationNode = new MappingOperationNode(pathNode, operation.getName(), operation);
pathNode.addChild(operationNode);
}
}
if (pathNode.hasChildren()) {
mapperNode.addChild(pathNode);
}
}
if (mapperNode.hasChildren()) {
projectFolder.addChild(mapperNode);
}
}
List<Sequence> sequences = project.getSequencesList();
for (Sequence sequence : sequences) {
List<Step> stepList = sequence.getAllSteps();
SequenceNode sequenceNode = new SequenceNode(projectFolder, sequence.getName(), sequence);
for (Step step : stepList) {
getTransactionReferencing(step, projectExplorerView, sequenceNode, transactionProjectName, transactionConnectorName, transactionName);
}
if (sequenceNode.hasChildren()) {
projectFolder.addChild(sequenceNode);
}
}
if (projectFolder.hasChildren()) {
isUsedByNode.addChild(projectFolder);
}
}
}
if (requiresNode.hasChildren()) {
transactionFolder.addChild(requiresNode);
}
if (isUsedByNode.hasChildren()) {
transactionFolder.addChild(isUsedByNode);
}
if (!transactionFolder.hasChildren()) {
transactionFolder.addChild(new InformationNode(projectFolder, "This transaction is not used in any sequence"));
}
treeViewer.setInput(root);
treeViewer.expandAll();
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "Error while analyzing the projects hierarchy", true);
}
}
use of com.twinsoft.convertigo.beans.transactions.JavelinTransaction in project convertigo by convertigo.
the class ReferencesView method handleScreenClassSelection.
private void handleScreenClassSelection(Object firstElement) {
ScreenClassTreeObject screenClassTreeObject = (ScreenClassTreeObject) firstElement;
ScreenClass screenClass = screenClassTreeObject.getObject();
String screenClassName = screenClassTreeObject.getName();
// Get the referencing transactions
Connector connector = screenClass.getConnector();
List<Transaction> transactions = connector.getTransactionsList();
RootNode root = new RootNode();
ScreenClassNode screenClassFolder = new ScreenClassNode(root, screenClassName, screenClass);
root.addChild(screenClassFolder);
IsUsedByNode isUsedByNode = new IsUsedByNode(screenClassFolder, "Is used by");
EntryHandlerNode entryFolder = new EntryHandlerNode(isUsedByNode, "Transaction entry handlers", null);
ExitHandlerNode exitFolder = new ExitHandlerNode(isUsedByNode, "Transaction exit handlers", null);
if (connector instanceof HtmlConnector) {
for (Transaction transaction : transactions) {
HtmlTransaction htmlTransaction = (HtmlTransaction) transaction;
List<Statement> statements = htmlTransaction.getStatements();
for (Statement statement : statements) {
if (statement instanceof ScHandlerStatement) {
ScHandlerStatement scHandlerStatement = (ScHandlerStatement) statement;
if (scHandlerStatement.getNormalizedScreenClassName().equals(screenClassName)) {
if (scHandlerStatement.getName().endsWith("Entry")) {
entryFolder.addChild(new TransactionNode(entryFolder, transaction.getName(), scHandlerStatement));
} else {
exitFolder.addChild(new TransactionNode(exitFolder, transaction.getName(), scHandlerStatement));
}
}
}
}
}
} else if (connector instanceof JavelinConnector) {
for (Transaction transaction : transactions) {
JavelinTransaction javelinTransaction = (JavelinTransaction) transaction;
if (javelinTransaction.handlers.indexOf("function on" + screenClassName + "Entry()") != -1) {
entryFolder.addChild(new TransactionNode(entryFolder, transaction.getName(), transaction));
}
if (javelinTransaction.handlers.indexOf("function on" + screenClassName + "Exit()") != -1) {
exitFolder.addChild(new TransactionNode(exitFolder, transaction.getName(), transaction));
}
}
}
if (entryFolder.hasChildren()) {
isUsedByNode.addChild(entryFolder);
}
if (exitFolder.hasChildren()) {
isUsedByNode.addChild(exitFolder);
}
if (!isUsedByNode.hasChildren()) {
screenClassFolder.addChild(new InformationNode(screenClassFolder, "This screen class is not used in any transaction"));
} else {
screenClassFolder.addChild(isUsedByNode);
}
// Build the treeviewer model
treeViewer.setInput(null);
treeViewer.setInput(root);
treeViewer.expandAll();
}
use of com.twinsoft.convertigo.beans.transactions.JavelinTransaction in project convertigo by convertigo.
the class JavelinConnector method prepareForTransaction.
@Override
public void prepareForTransaction(Context context) throws EngineException {
String t = context.statistics.start(EngineStatistics.GET_JAVELIN_OBJECT);
try {
// Quick and dirty workaround for ticket #1280
if (!checkKeys())
throw new EngineException("No more key available; check your license keys!");
// if something append during transaction execution
com.twinsoft.api.Session session = Engine.theApp.sessionManager.getSession(context.contextID);
if (session != null)
session.resetSomethingChange();
if (Engine.isStudioMode()) {
if (javelin != null) {
Engine.logBeans.debug("(JavelinConnector) Using the studio Javelin object");
return;
}
throw new EngineException("Studio mode: the Legacy connector must be open in order to execute transactions");
}
Engine.logBeans.debug("(JavelinConnector) Retrieving the Javelin object");
JavelinTransaction javelinTransaction = null;
try {
javelinTransaction = (JavelinTransaction) context.requestedObject;
} catch (ClassCastException e) {
throw new EngineException("Requested object is not a transaction", e);
}
int timeout = javelinTransaction.getTimeoutForDataStable();
int threshold = javelinTransaction.getDataStableThreshold();
Authentication auth = null;
if (context.isRequestFromVic) {
// instance, from a web service call).
if (!context.isTrustedRequest) {
try {
VicApi vicApi = new VicApi();
if (!vicApi.isServiceAuthorized(context.tasUserName, context.tasVirtualServerName, context.tasServiceCode)) {
throw new EngineException("The service '" + context.tasServiceCode + "' is not authorized for the user '" + context.tasUserName);
}
} catch (IOException e) {
throw new EngineException("Unable to retrieve authorization from the VIC database.", e);
}
}
} else {
// Check the Carioca authorizations only if this is a non trusted request
if (context.isTrustedRequest) {
// Nothing to do: all the tas* variables from the context must have been set
// by the caller.
// Means we must not execute the TAS API.
} else {
// Getting Authentication object
context.tasVirtualServerName = getVirtualServer();
try {
String authName = (context.tasSessionKey == null ? context.tasUserName : context.tasSessionKey);
auth = Engine.theApp.getAuthenticationObject(context.tasVirtualServerName, authName);
// Logging to Carioca only if needed
User user = auth.getCurrentUser();
if (user == null) {
// Request from Carioca
if (context.tasSessionKey != null) {
auth.login(context.tasSessionKey);
User currentUser = auth.getCurrentUser();
context.tasUserName = currentUser.getName();
context.tasUserPassword = currentUser.getPassword();
context.tasVirtualServerName = "(SV #" + currentUser.getServerID() + ")";
String message = "Authentication to Carioca with sesskey = '" + context.tasSessionKey + "' => user: \"" + context.tasUserName + "\"";
Engine.logBeans.debug("(JavelinConnector) " + message);
} else // Specific user
if ((context.tasUserName != null) && (context.tasUserPassword != null)) {
auth.login(context.tasUserName, context.tasUserPassword);
String message = "Authentication to Carioca with user = '" + context.tasUserName + "' and password = '" + context.tasUserPassword + "'";
Engine.logBeans.debug("(JavelinConnector) " + message);
} else {
context.tasUserName = EnginePropertiesManager.getProperty(PropertyName.CARIOCA_DEFAULT_USER_NAME);
context.tasUserPassword = EnginePropertiesManager.getProperty(PropertyName.CARIOCA_DEFAULT_USER_PASSWORD);
auth.login(context.tasUserName, context.tasUserPassword);
String message = "Default authentication to Carioca";
Engine.logBeans.debug("(JavelinConnector) " + message);
}
} else {
context.tasUserName = user.getName();
context.tasUserPassword = user.getPassword();
context.tasUserGroup = user.getMainGroupName();
context.tasVirtualServerName = "(#" + Long.toString(user.getServerID()) + ")";
String message = "Already authenticated to Carioca with user = '" + context.tasUserName + "' and password = '" + context.tasUserPassword + "'";
Engine.logBeans.debug("(JavelinConnector) " + message);
}
} catch (Exception e) {
auth = null;
String message = "Unable to authenticate to Carioca.\n" + "Carioca virtual server: " + context.tasVirtualServerName + "\n" + "SessKey: \"" + context.tasSessionKey + "\"\n" + "User: \"" + context.tasUserName + "\"\n" + "Password: \"" + context.tasUserPassword + "\"";
EngineException ee = new EngineException(message, e);
throw ee;
}
}
}
// We retrieve the current project
String javelinServiceCode = context.tasServiceCode;
if (javelinServiceCode == null) {
javelinServiceCode = getServiceCode();
Engine.logBeans.debug("(JavelinConnector) No service code provided; getting the connector service code.");
}
// Analyzes/overrrides service code for device number pooling
javelinServiceCode = analyzeServiceCode(javelinServiceCode);
Engine.logBeans.debug("(JavelinConnector) Service code: " + javelinServiceCode);
session = Engine.theApp.sessionManager.getSession(context.contextID);
if (session == null) {
Engine.logBeans.debug("(JavelinConnector) No session has been found; creation of a new one and ignoring the user request.");
context.inputDocument = null;
try {
if (context.isRequestFromVic) {
session = Engine.theApp.sessionManager.addVicSession(javelinServiceCode, context.tasUserName, context.tasUserGroup + "@" + context.tasVirtualServerName, context.tasDteAddress, context.tasCommDevice, context.contextID);
} else if (context.isTrustedRequest) {
String connectionParameters = getServiceCode();
try {
StringTokenizer st = new StringTokenizer(connectionParameters, ",");
String appType = st.nextToken();
if (appType.equals("vic")) {
javelinServiceCode = st.nextToken();
context.tasDteAddress = st.nextToken();
context.tasCommDevice = st.nextToken();
Engine.logBeans.debug("(JavelinConnector) Trusted request => the connector handles connection parameters : " + connectionParameters);
Engine.logBeans.debug("(JavelinConnector) serviceCode: " + javelinServiceCode);
Engine.logBeans.debug("(JavelinConnector) dteAddress: " + context.tasDteAddress);
Engine.logBeans.debug("(JavelinConnector) commDevice: " + context.tasCommDevice);
Engine.logBeans.debug("(JavelinConnector) user: " + context.tasUserName);
String group = context.tasUserGroup + "@" + context.tasVirtualServerName;
Engine.logBeans.debug("(JavelinConnector) group: " + group);
session = Engine.theApp.sessionManager.addVicSession(javelinServiceCode, context.tasUserName, group, context.tasDteAddress, context.tasCommDevice, context.contextID);
}
} catch (NoSuchElementException e) {
Engine.logBeans.error("(JavelinConnector) Invalid connector connection parameters: " + connectionParameters);
}
} else {
session = Engine.theApp.sessionManager.addSession((int) emulatorID, auth, javelinServiceCode, context.contextID, getJavelinLanguage(), isSslEnabled(), isSslTrustAllServerCertificates(), getIbmTerminalType());
}
} catch (Exception e) {
String message = "Unable to open the Javelin session: serviceCode= '" + javelinServiceCode + "', contextID = '" + context.contextID + "'";
EngineException ee = new EngineException(message, e);
throw ee;
}
if (session == null) {
String message = "Unable to add a new session: the access to the service '" + javelinServiceCode + "' has been forbidden by the Carioca administrator.";
EngineException ee = new EngineException(message);
throw ee;
}
javelin = session.getJavelinObject();
javelin.setLog(new LogWrapper(Engine.logEmulators));
javelin.setDataStableOnCursorOn(false);
javelin.connect(javelinTransaction.getTimeoutForConnect());
boolean isConnected = javelin.isConnected();
Engine.logBeans.debug("(JavelinConnector) isConnected=" + isConnected);
if (!isConnected) {
throw new ConnectionException("Unable to connect the session! See the emulator logs for more details...");
}
executeConnectionSyncCode(javelin, timeout, threshold);
} else {
Engine.logBeans.debug("(JavelinConnector) Using the existing session");
if (context.isNewSession) {
Engine.logBeans.debug("(JavelinConnector) New session required and ignoring the user request");
context.inputDocument = null;
// First, we remove the previous session
Engine.theApp.sessionManager.removeSession(context.contextID);
try {
if (context.isRequestFromVic) {
session = Engine.theApp.sessionManager.addVicSession(javelinServiceCode, context.tasUserName, context.tasUserGroup, context.tasDteAddress, context.tasCommDevice, context.contextID);
} else {
session = Engine.theApp.sessionManager.addSession((int) emulatorID, auth, javelinServiceCode, context.contextID, getJavelinLanguage(), isSslEnabled(), isSslTrustAllServerCertificates(), getIbmTerminalType());
}
} catch (Exception e) {
String message = "Unable to open the Javelin session: serviceCode= '" + javelinServiceCode + "', contextID = '" + context.contextID + "'";
Engine.logBeans.warn("(JavelinConnector) " + message);
EngineException ee = new EngineException(message, e);
throw ee;
}
if (session == null) {
String message = "Unable to add a new session: the access to the service '" + javelinServiceCode + "' has been forbidden by the Carioca administrator.";
Engine.logBeans.warn("(JavelinConnector) " + message);
EngineException ee = new EngineException(message);
throw ee;
}
javelin = session.getJavelinObject();
javelin.setLog(new LogWrapper(Engine.logEmulators));
javelin.setDataStableOnCursorOn(false);
javelin.connect(javelinTransaction.getTimeoutForConnect());
if (!javelin.isConnected()) {
throw new ConnectionException("Unable to connect the session! See the emulator logs for more details...");
}
executeConnectionSyncCode(javelin, timeout, threshold);
} else {
javelin = session.getJavelinObject();
// Reconnect only if the requested transaction is not the end transaction
if ((!context.isDestroying) && (!session.isConnected())) {
javelin.setDataStableOnCursorOn(false);
javelin.connect(javelinTransaction.getTimeoutForConnect());
if (!javelin.isConnected()) {
throw new ConnectionException("Unable to connect the session! See the emulator logs for more details...");
}
executeConnectionSyncCode(javelin, timeout, threshold);
}
}
}
context.isNewSession = false;
} finally {
context.statistics.stop(t);
}
}
use of com.twinsoft.convertigo.beans.transactions.JavelinTransaction in project convertigo by convertigo.
the class TransactionShowVariableAction method run.
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
String variable = (String) ((VariableTreeObject) treeObject).getObject();
JavelinTransaction transaction = (JavelinTransaction) treeObject.getParent().getParent().getObject();
JavelinConnector javelinConnector = (JavelinConnector) transaction.getParent();
IEditorPart wpart = getConnectorEditor(javelinConnector);
if ((wpart != null) && (wpart instanceof ConnectorEditor)) {
getActivePage().activate(wpart);
ConnectorEditor connectorEditor = (ConnectorEditor) wpart;
ConnectorEditorPart connectorEditorPart = connectorEditor.getConnectorEditorPart();
AbstractConnectorComposite connectorComposite = connectorEditorPart.getConnectorComposite();
if ((connectorComposite != null) && (connectorComposite instanceof JavelinConnectorComposite)) {
Javelin javelin = ((JavelinConnectorComposite) connectorComposite).getJavelin();
ScreenClass currentScreenClass = ((JavelinConnector) connectorEditorPart.getConnector()).getCurrentScreenClass();
String normalizedScreenClassName = StringUtils.normalize(currentScreenClass.getName());
int i;
String handlerName = "on" + normalizedScreenClassName + JavelinTransaction.EVENT_ENTRY_HANDLER;
if ((i = transaction.handlers.indexOf(handlerName)) == -1) {
display.beep();
ConvertigoPlugin.logWarning("Unable to show the position of the variable \"" + variable + "\": no handler found for the current screen class!");
} else {
ConvertigoPlugin.logDebug("Found handler: " + handlerName);
// Delimit the function
int bof, eof;
bof = transaction.handlers.indexOf('{', i) + 2;
eof = transaction.handlers.indexOf("function", bof);
if (eof == -1) {
eof = transaction.handlers.lastIndexOf('}') - 1;
} else {
eof = transaction.handlers.lastIndexOf('}', eof) - 1;
}
String function = transaction.handlers.substring(bof, eof);
// Delimit the marker for generated input variables code
int idxMarker = function.indexOf("\t// begin-of-variables");
if (idxMarker == -1) {
// No variable marker, do nothing
display.beep();
ConvertigoPlugin.logWarning("Unable to show the position of the variable \"" + variable + "\": no variable marker found for the handler!");
return;
}
int idxMarker2 = function.indexOf("\t// end-of-variables", idxMarker);
String code = function.substring(idxMarker, idxMarker2);
String line = "\tjavelin.send(" + variable + ");\n";
int idxPosition = code.indexOf(line);
if (idxPosition == -1) {
ConvertigoPlugin.logDebug("No variable '" + variable + "' found into the handler!");
return;
}
idxPosition = code.lastIndexOf("moveCursor(", idxPosition) + 11;
int idxComa = code.indexOf(',', idxPosition);
int idxClosedParenthesis = code.indexOf(')', idxComa);
int x = Integer.parseInt(code.substring(idxPosition, idxComa).trim());
int y = Integer.parseInt(code.substring(idxComa + 1, idxClosedParenthesis).trim());
ConvertigoPlugin.logDebug("Variable position found: " + x + ", " + y);
javelin.moveCursor(x, y);
}
javelin.requestFocus();
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to show variable to Javelin!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.transactions.JavelinTransaction in project convertigo by convertigo.
the class TransactionWriteVariableAction method run.
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
String variable = (String) ((VariableTreeObject) treeObject).getObject();
JavelinTransaction transaction = (JavelinTransaction) treeObject.getParent().getParent().getObject();
JavelinConnector javelinConnector = (JavelinConnector) transaction.getParent();
IEditorPart wpart = getConnectorEditor(javelinConnector);
if ((wpart != null) && (wpart instanceof ConnectorEditor)) {
getActivePage().activate(wpart);
ConnectorEditor connectorEditor = (ConnectorEditor) wpart;
ConnectorEditorPart connectorEditorPart = connectorEditor.getConnectorEditorPart();
AbstractConnectorComposite connectorComposite = connectorEditorPart.getConnectorComposite();
if ((connectorComposite != null) && (connectorComposite instanceof JavelinConnectorComposite)) {
Javelin javelin = ((JavelinConnectorComposite) connectorComposite).getJavelin();
ScreenClass currentScreenClass = ((JavelinConnector) connectorEditorPart.getConnector()).getCurrentScreenClass();
ConvertigoPlugin.logDebug("Analyzing screen class '" + currentScreenClass.getName() + "'...");
String normalizedScreenClassName = StringUtils.normalize(currentScreenClass.getName());
int i;
String handlerName = "on" + normalizedScreenClassName + JavelinTransaction.EVENT_ENTRY_HANDLER;
ConvertigoPlugin.logDebug("Handlers:\n" + transaction.handlers);
ConvertigoPlugin.logDebug("Searching for handler '" + handlerName + "'...");
if ((i = transaction.handlers.indexOf(handlerName)) == -1) {
display.beep();
ConvertigoPlugin.logDebug("No handler found for the current screen class!");
} else {
ConvertigoPlugin.logDebug("Handler found!");
// Delimit the function
int bof, eof;
bof = transaction.handlers.indexOf('{', i) + 1;
eof = transaction.handlers.indexOf("function", bof);
if (eof == -1) {
eof = transaction.handlers.lastIndexOf('}') - 1;
} else {
eof = transaction.handlers.lastIndexOf('}', eof) - 1;
}
String function = transaction.handlers.substring(bof, eof);
int c = javelin.getCurrentColumn();
int l = javelin.getCurrentLine();
String line1 = "\tjavelin.moveCursor(" + c + ", " + l + ");\n";
// We must remove the default value of the variable if any
String variableName = variable.toString();
int ii;
if ((ii = variableName.indexOf(' ')) != -1) {
variableName = variableName.substring(0, ii);
}
String line2 = "\tjavelin.send(" + variableName + ");\n";
// Delimit the marker for generated input variables code
String code = "";
int idxMarker = function.indexOf("\t// begin-of-variables");
if (idxMarker == -1) {
code = "\n\t// begin-of-variables: DO NOT EDIT OR MODIFY\n";
code += line1 + line2;
code += "\t// end-of-variables\n";
function = code + function;
} else {
idxMarker = function.indexOf("\t// end-of-variables");
// Update previous definition if any
int idxPreviousDefinition = function.indexOf(line2);
if (idxPreviousDefinition != -1) {
int i1 = function.lastIndexOf("moveCursor(", idxPreviousDefinition) + 11;
// Search for moveCursor only inside the variables block
if (i1 < idxMarker) {
int i2 = function.indexOf(')', i1);
function = function.substring(0, i1) + c + ", " + l + function.substring(i2);
}
} else // Add definition otherwise
{
code += line1 + line2;
}
function = function.substring(0, idxMarker) + code + function.substring(idxMarker);
}
transaction.handlers = transaction.handlers.substring(0, bof) + function + transaction.handlers.substring(eof);
transaction.hasChanged = true;
ConvertigoPlugin.logDebug("Code added:\n" + code);
explorerView.updateDatabaseObject(transaction);
// Update the opened handlers editor if any
JScriptEditorInput jsinput = ConvertigoPlugin.getDefault().getJScriptEditorInput(transaction);
if (jsinput != null) {
jsinput.reload();
}
}
javelin.requestFocus();
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to write variable from Javelin!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations