Search in sources :

Example 1 with ERDContentProviderDecorated

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;
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) IFolder(org.eclipse.core.resources.IFolder) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ERDContentProviderDecorated(org.jkiss.dbeaver.erd.ui.model.ERDContentProviderDecorated) CoreException(org.eclipse.core.runtime.CoreException) NotNull(org.jkiss.code.NotNull) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) IProject(org.eclipse.core.resources.IProject) ByteArrayInputStream(java.io.ByteArrayInputStream) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IFile(org.eclipse.core.resources.IFile) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) ERDEditorStandalone(org.jkiss.dbeaver.erd.ui.editor.ERDEditorStandalone) DiagramLoader(org.jkiss.dbeaver.erd.ui.model.DiagramLoader) CommonUtils(org.jkiss.utils.CommonUtils) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ContentUtils(org.jkiss.dbeaver.utils.ContentUtils) EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) StandardCharsets(java.nio.charset.StandardCharsets) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) AbstractResourceHandler(org.jkiss.dbeaver.ui.resources.AbstractResourceHandler) RuntimeUtils(org.jkiss.dbeaver.utils.RuntimeUtils) DBException(org.jkiss.dbeaver.DBException) IResource(org.eclipse.core.resources.IResource) ERDDecoratorDefault(org.jkiss.dbeaver.erd.ui.model.ERDDecoratorDefault) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) InputStream(java.io.InputStream) DBException(org.jkiss.dbeaver.DBException) EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ERDContentProviderDecorated(org.jkiss.dbeaver.erd.ui.model.ERDContentProviderDecorated) ERDDecoratorDefault(org.jkiss.dbeaver.erd.ui.model.ERDDecoratorDefault) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)

Example 2 with ERDContentProviderDecorated

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;
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) IFolder(org.eclipse.core.resources.IFolder) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ERDContentProviderDecorated(org.jkiss.dbeaver.erd.ui.model.ERDContentProviderDecorated) CoreException(org.eclipse.core.runtime.CoreException) NotNull(org.jkiss.code.NotNull) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) IProject(org.eclipse.core.resources.IProject) ByteArrayInputStream(java.io.ByteArrayInputStream) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IFile(org.eclipse.core.resources.IFile) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) ERDEditorStandalone(org.jkiss.dbeaver.erd.ui.editor.ERDEditorStandalone) DiagramLoader(org.jkiss.dbeaver.erd.ui.model.DiagramLoader) CommonUtils(org.jkiss.utils.CommonUtils) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ContentUtils(org.jkiss.dbeaver.utils.ContentUtils) EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) StandardCharsets(java.nio.charset.StandardCharsets) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) AbstractResourceHandler(org.jkiss.dbeaver.ui.resources.AbstractResourceHandler) RuntimeUtils(org.jkiss.dbeaver.utils.RuntimeUtils) DBException(org.jkiss.dbeaver.DBException) IResource(org.eclipse.core.resources.IResource) ERDDecoratorDefault(org.jkiss.dbeaver.erd.ui.model.ERDDecoratorDefault) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) InputStream(java.io.InputStream) DBException(org.jkiss.dbeaver.DBException) EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ERDContentProviderDecorated(org.jkiss.dbeaver.erd.ui.model.ERDContentProviderDecorated) ERDDecoratorDefault(org.jkiss.dbeaver.erd.ui.model.ERDDecoratorDefault) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 StandardCharsets (java.nio.charset.StandardCharsets)2 List (java.util.List)2 IFile (org.eclipse.core.resources.IFile)2 IFolder (org.eclipse.core.resources.IFolder)2 IProject (org.eclipse.core.resources.IProject)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 FileEditorInput (org.eclipse.ui.part.FileEditorInput)2 NotNull (org.jkiss.code.NotNull)2 DBException (org.jkiss.dbeaver.DBException)2 Log (org.jkiss.dbeaver.Log)2 ERDEditorStandalone (org.jkiss.dbeaver.erd.ui.editor.ERDEditorStandalone)2 DiagramLoader (org.jkiss.dbeaver.erd.ui.model.DiagramLoader)2 ERDContentProviderDecorated (org.jkiss.dbeaver.erd.ui.model.ERDContentProviderDecorated)2 ERDDecoratorDefault (org.jkiss.dbeaver.erd.ui.model.ERDDecoratorDefault)2 EntityDiagram (org.jkiss.dbeaver.erd.ui.model.EntityDiagram)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2