use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject in project convertigo by convertigo.
the class SequenceImportFromXsdAction 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) {
DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
DatabaseObject databaseObject = databaseObjectTreeObject.getObject();
SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) ((databaseObject instanceof Sequence) ? databaseObjectTreeObject : databaseObjectTreeObject.getParentDatabaseObjectTreeObject());
Sequence sequence = (databaseObject instanceof Sequence) ? (Sequence) databaseObject : ((StepWithExpressions) databaseObject).getSequence();
FileDialog fileDialog = new FileDialog(shell, SWT.PRIMARY_MODAL | SWT.SAVE);
fileDialog.setText("Import schema file");
fileDialog.setFilterExtensions(new String[] { "*.xsd" });
fileDialog.setFilterNames(new String[] { "Schema files" });
fileDialog.setFilterPath(Engine.PROJECTS_PATH);
String filePath = fileDialog.open();
if (filePath != null) {
filePath = filePath.replaceAll("\\\\", "/");
XmlSchemaCollection collection = new XmlSchemaCollection();
collection.setBaseUri(filePath);
XmlSchema xmlSchema = SchemaUtils.loadSchema(new File(filePath), collection);
SchemaMeta.setCollection(xmlSchema, collection);
SchemaObjectsDialog dlg = new SchemaObjectsDialog(shell, sequence, xmlSchema);
if (dlg.open() == Window.OK) {
if (dlg.result instanceof Throwable) {
throw (Throwable) dlg.result;
} else {
Step step = (Step) dlg.result;
if (step != null) {
if (databaseObject instanceof Sequence) {
sequence.addStep(step);
sequence.hasChanged = true;
} else {
StepWithExpressions swe = (StepWithExpressions) databaseObject;
swe.addStep(step);
swe.hasChanged = true;
}
sequence.hasChanged = true;
// Reload sequence in tree without updating its schema for faster reload
ConvertigoPlugin.logDebug("Reload sequence: start");
explorerView.reloadTreeObject(sequenceTreeObject);
ConvertigoPlugin.logDebug("Reload sequence: end");
// Select target dbo in tree
explorerView.objectSelected(new CompositeEvent(databaseObject));
}
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to import step from xsd!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject in project convertigo by convertigo.
the class AbstractStubAction method run.
@Override
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();
if ((treeObject != null) && (treeObject instanceof SequenceTreeObject)) {
SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) treeObject;
Sequence sequence = sequenceTreeObject.getObject();
File stubDir = new File(sequence.getProject().getDirPath() + "/stubs");
stubDir.mkdirs();
File stubFile = new File(stubDir, sequence.getName() + ".xml");
Document dom = getXML(treeObject);
writeStub(dom, stubFile);
} else if ((treeObject != null) && (treeObject instanceof TransactionTreeObject)) {
TransactionTreeObject transactionTreeObject = (TransactionTreeObject) treeObject;
Transaction transaction = transactionTreeObject.getObject();
File stubDir = new File(transaction.getProject().getDirPath() + "/stubs");
stubDir.mkdirs();
File stubFile = new File(stubDir, transaction.getParent().getName() + "." + transaction.getName() + ".xml");
Document dom = getXML(treeObject);
writeStub(dom, stubFile);
}
}
} catch (NoSuchElementException e) {
ConvertigoPlugin.logException(e, "No previous XML file found");
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to execute the selected sequence!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject in project convertigo by convertigo.
the class SequenceImportFromXmlAction 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) {
DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
DatabaseObject databaseObject = databaseObjectTreeObject.getObject();
SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) ((databaseObject instanceof Sequence) ? databaseObjectTreeObject : databaseObjectTreeObject.getParentDatabaseObjectTreeObject());
Sequence sequence = (databaseObject instanceof Sequence) ? (Sequence) databaseObject : ((StepWithExpressions) databaseObject).getSequence();
// Open a file dialog to search a XML file
FileDialog fileDialog = new FileDialog(shell, SWT.PRIMARY_MODAL | SWT.SAVE);
fileDialog.setText("Import XML file");
fileDialog.setFilterExtensions(new String[] { "*.xml" });
fileDialog.setFilterNames(new String[] { "XML" });
fileDialog.setFilterPath(Engine.PROJECTS_PATH);
String filePath = fileDialog.open();
if (filePath != null) {
// Get XML content from the file
File xmlFile = new File(filePath);
Charset charset = XMLUtils.getEncoding(xmlFile);
String xmlContent = FileUtils.readFileToString(xmlFile, charset.name());
// Open and add XML content to the dialog area
XmlStructureDialog dlg = new XmlStructureDialog(shell, sequence, xmlContent);
if (dlg.open() == Window.OK) {
if (dlg.result instanceof Throwable) {
throw (Throwable) dlg.result;
} else {
Step step = (Step) dlg.result;
if (step != null) {
if (databaseObject instanceof Sequence) {
sequence.addStep(step);
} else {
StepWithExpressions swe = (StepWithExpressions) databaseObject;
swe.addStep(step);
}
sequence.hasChanged = true;
// Reload sequence in tree without updating its schema for faster reload
ConvertigoPlugin.logDebug("Reload sequence: start");
explorerView.reloadTreeObject(sequenceTreeObject);
ConvertigoPlugin.logDebug("Reload sequence: end");
// Select target dbo in tree
explorerView.objectSelected(new CompositeEvent(databaseObject));
}
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to import step from xml!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject in project convertigo by convertigo.
the class ReferencesView method handleSequenceSelection.
private void handleSequenceSelection(Object firstElement) {
SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) firstElement;
Sequence sequenceSelected = sequenceTreeObject.getObject();
String sequenceSelectedName = sequenceSelected.getName();
// String sequenceProjectName = sequenceSelected.getProject().getName();
List<String> projectNames = Engine.theApp.databaseObjectsManager.getAllProjectNamesList();
ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
treeViewer.setInput(null);
// Get the referencing sequence steps
List<String> referencingSequence = new ArrayList<String>();
RootNode root = new RootNode();
SequenceNode sequenceFolder = new SequenceNode(root, sequenceSelectedName, sequenceSelected);
root.addChild(sequenceFolder);
IsUsedByNode isUsedByNode = new IsUsedByNode(sequenceFolder, "Is used by");
// Searching all objects that reference the selected sequence
for (String projectName : projectNames) {
Project project = getProject(projectName, projectExplorerView);
if (project != null) {
ProjectNode projectFolder = null;
projectFolder = new ProjectNode(isUsedByNode, project.getName(), project);
List<Sequence> sequences = project.getSequencesList();
referencingSequence.clear();
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(projectName + "." + sequenceSelectedName)) {
MappingOperationNode operationNode = new MappingOperationNode(pathNode, operation.getName(), operation);
pathNode.addChild(operationNode);
}
}
if (pathNode.hasChildren()) {
mapperNode.addChild(pathNode);
}
}
if (mapperNode.hasChildren()) {
projectFolder.addChild(mapperNode);
}
}
for (Sequence sequence : sequences) {
List<Step> steps = sequence.getSteps();
for (Step step : steps) {
SequenceNode sequenceNode = new SequenceNode(projectFolder, sequence.getName(), sequence);
getSequenceReferencingIsUsedBy(step, sequenceSelected, sequenceNode);
if (sequenceNode.hasChildren()) {
projectFolder.addChild(sequenceNode);
}
}
}
if (projectFolder.hasChildren()) {
isUsedByNode.addChild(projectFolder);
}
}
}
List<Step> steps = sequenceSelected.getSteps();
RequiresNode requiresNode = new RequiresNode(root, "Requires");
// Searching all objects that are referenced by the selected sequence
List<String> transactionList = new ArrayList<String>();
List<String> sequenceList = new ArrayList<String>();
for (Step step : steps) {
getSequenceReferencingRequires(step, sequenceSelected, projectExplorerView, requiresNode, transactionList, sequenceList);
}
if (requiresNode.hasChildren()) {
sequenceFolder.addChild(requiresNode);
}
if (isUsedByNode.hasChildren()) {
sequenceFolder.addChild(isUsedByNode);
}
if (!sequenceFolder.hasChildren()) {
sequenceFolder.addChild(new InformationNode(sequenceFolder, "This sequence is not used in any sequence"));
}
treeViewer.setInput(root);
treeViewer.expandAll();
}
use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject in project convertigo by convertigo.
the class DatabaseObjectDeleteAction method run.
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
treeNodesToUpdate = new ArrayList<>();
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject[] selectedTreeObjects = explorerView.getSelectedTreeObjects();
if (selectedTreeObjects != null) {
Collection<DatabaseObjectTreeObject> treeObjects = new HashSet<>(selectedTreeObjects.length);
for (TreeObject t : Arrays.asList(selectedTreeObjects)) {
if (t instanceof DatabaseObjectTreeObject) {
treeObjects.add((DatabaseObjectTreeObject) t);
}
}
;
if (treeObjects.size() > 1) {
for (DatabaseObjectTreeObject t : new ArrayList<>(treeObjects)) {
TreeObject parent = t.getParent();
while (parent != null) {
if (treeObjects.contains(parent)) {
treeObjects.remove(t);
parent = null;
} else {
parent = parent.getParent();
}
}
}
;
}
if (treeObjects.size() > 1) {
List<DatabaseObjectTreeObject> list = new ArrayList<>(treeObjects);
Collections.sort(list, new Comparator<DatabaseObjectTreeObject>() {
@Override
public int compare(DatabaseObjectTreeObject o1, DatabaseObjectTreeObject o2) {
if (o1 instanceof ProjectTreeObject) {
if (o2 instanceof ProjectTreeObject) {
return o1.getName().compareTo(o2.getName());
}
return -1;
} else if (o2 instanceof ProjectTreeObject) {
return 1;
}
return o1.getName().compareTo(o2.getName());
}
});
treeObjects = list;
}
MultipleDeletionDialog dialog = new MultipleDeletionDialog(shell, "Object Deletion", treeObjects.size() != 1);
for (DatabaseObjectTreeObject treeObject : treeObjects) {
String message = java.text.MessageFormat.format("Do you really want to delete the {0} \"{1}\" and all its sub-objects?", treeObject instanceof ProjectTreeObject ? "project" : "object", treeObject.getName());
if (treeObject instanceof ProjectTreeObject) {
message += "\nProject location: " + ((Project) treeObject.getObject()).getDirPath();
dialog.setToggle("Delete project content on disk (cannot be undone)", false);
} else {
dialog.removeToggle();
}
if (!dialog.shouldBeDeleted(message)) {
continue;
}
try {
if (treeObject instanceof ProjectTreeObject) {
((ProjectTreeObject) treeObject).closeAllEditors();
} else if (treeObject instanceof SequenceTreeObject) {
((ProjectTreeObject) ((SequenceTreeObject) treeObject).getParent().getParent()).closeSequenceEditors((Sequence) treeObject.getObject());
} else if (treeObject instanceof ConnectorTreeObject) {
((ProjectTreeObject) ((ConnectorTreeObject) treeObject).getParent().getParent()).closeConnectorEditors((Connector) treeObject.getObject());
} else if (treeObject instanceof StepTreeObject) {
// We close the editor linked with the SimpleStep (=SequenceJsStep)
if (treeObject.getObject() instanceof SimpleStep) {
boolean find = false;
SimpleStep simpleStep = (SimpleStep) treeObject.getObject();
IWorkbenchPage page = this.getActivePage();
IEditorReference[] editors = page.getEditorReferences();
int _i = 0;
while (find != true && _i < editors.length) {
IEditorReference editor = editors[_i];
IEditorInput input = editor.getEditorInput();
if (input instanceof JScriptEditorInput) {
if (simpleStep.equals(((JScriptEditorInput) input).getDatabaseObject())) {
find = true;
IEditorPart editorPart = page.findEditor(input);
if (editorPart != null) {
page.activate(editorPart);
page.closeEditor(editorPart, false);
}
}
}
++_i;
}
}
} else if (treeObject instanceof MobileComponentTreeObject) {
((MobileComponentTreeObject) treeObject).closeAllEditors(false);
}
if (treeObject instanceof ProjectTreeObject) {
explorerView.removeProjectTreeObject(treeObject);
final Project project = (Project) treeObject.getObject();
Job rmProject = new Job("Remove '" + project.getName() + "' project") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
delete(project, dialog.getToggleState());
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Unable to delete the '" + project.getName() + "' project.");
return new MultiStatus(ConvertigoPlugin.PLUGIN_UNIQUE_ID, IStatus.ERROR, "Failed to remove the '" + project.getName() + "' project.", e);
}
return Status.OK_STATUS;
}
};
rmProject.schedule();
} else {
delete(treeObject);
// prevents treeObject and its childs to receive further TreeObjectEvents
if (treeObject instanceof TreeObjectListener) {
explorerView.removeTreeObjectListener(treeObject);
}
treeObject.removeAllChildren();
}
explorerView.fireTreeObjectRemoved(new TreeObjectEvent(treeObject));
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Unable to delete the current selected object.");
}
}
;
// Updating the tree and the properties panel
Enumeration<DatabaseObjectTreeObject> enumeration = Collections.enumeration(treeNodesToUpdate);
DatabaseObjectTreeObject parentTreeObject;
while (enumeration.hasMoreElements()) {
parentTreeObject = enumeration.nextElement();
if (parentTreeObject != null) {
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(parentTreeObject);
}
}
// Refresh tree to show potential 'broken' steps
explorerView.refreshTree();
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to delete object!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations