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