use of org.jkiss.dbeaver.erd.ui.model.ERDContentProviderDecorated in project dbeaver by dbeaver.
the class ERDResourceHandler method createDiagram.
public static IFile createDiagram(final EntityDiagram copyFrom, final String title, IFolder folder, DBRProgressMonitor monitor) throws DBException {
if (folder == null) {
try {
folder = getDiagramsFolder(DBWorkbench.getPlatform().getWorkspace().getActiveProject(), true);
} catch (CoreException e) {
throw new DBException("Can't obtain folder for diagram", e);
}
}
if (folder == null) {
throw new DBException("Can't detect folder for diagram");
}
ContentUtils.checkFolderExists(folder, monitor);
final IFile file = ContentUtils.getUniqueFile(folder, CommonUtils.escapeFileName(title), ERD_EXT);
try {
DBRRunnableWithProgress runnable = monitor1 -> {
try {
EntityDiagram newDiagram = copyFrom == null ? new EntityDiagram(null, "<Diagram>", new ERDContentProviderDecorated(), new ERDDecoratorDefault()) : copyFrom.copy();
newDiagram.setName(title);
newDiagram.setLayoutManualAllowed(true);
newDiagram.setLayoutManualDesired(true);
String diagramState = DiagramLoader.serializeDiagram(monitor1, null, newDiagram, false, false);
InputStream data = new ByteArrayInputStream(diagramState.getBytes(StandardCharsets.UTF_8));
file.create(data, true, RuntimeUtils.getNestedMonitor(monitor1));
} catch (Exception e) {
throw new InvocationTargetException(e);
}
};
if (monitor == null) {
UIUtils.runInProgressService(runnable);
} else {
runnable.run(monitor);
}
} catch (InvocationTargetException e) {
throw new DBException("Error creating diagram", e.getTargetException());
} catch (InterruptedException e) {
// interrupted
}
return file;
}
use of org.jkiss.dbeaver.erd.ui.model.ERDContentProviderDecorated in project dbeaver by serge-rider.
the class ERDResourceHandler method createDiagram.
public static IFile createDiagram(final EntityDiagram copyFrom, final String title, IFolder folder, DBRProgressMonitor monitor) throws DBException {
if (folder == null) {
try {
folder = getDiagramsFolder(DBWorkbench.getPlatform().getWorkspace().getActiveProject(), true);
} catch (CoreException e) {
throw new DBException("Can't obtain folder for diagram", e);
}
}
if (folder == null) {
throw new DBException("Can't detect folder for diagram");
}
ContentUtils.checkFolderExists(folder, monitor);
final IFile file = ContentUtils.getUniqueFile(folder, CommonUtils.escapeFileName(title), ERD_EXT);
try {
DBRRunnableWithProgress runnable = monitor1 -> {
try {
EntityDiagram newDiagram = copyFrom == null ? new EntityDiagram(null, "<Diagram>", new ERDContentProviderDecorated(), new ERDDecoratorDefault()) : copyFrom.copy();
newDiagram.setName(title);
newDiagram.setLayoutManualAllowed(true);
newDiagram.setLayoutManualDesired(true);
String diagramState = DiagramLoader.serializeDiagram(monitor1, null, newDiagram, false, false);
InputStream data = new ByteArrayInputStream(diagramState.getBytes(StandardCharsets.UTF_8));
file.create(data, true, RuntimeUtils.getNestedMonitor(monitor1));
} catch (Exception e) {
throw new InvocationTargetException(e);
}
};
if (monitor == null) {
UIUtils.runInProgressService(runnable);
} else {
runnable.run(monitor);
}
} catch (InvocationTargetException e) {
throw new DBException("Error creating diagram", e.getTargetException());
} catch (InterruptedException e) {
// interrupted
}
return file;
}
Aggregations