use of com.twinsoft.convertigo.eclipse.dialogs.XmlStructureDialog 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();
}
}
Aggregations