use of org.jkiss.dbeaver.erd.ui.model.EntityDiagram in project dbeaver by serge-rider.
the class ERDEditorPart method restoreVisualSettings.
private boolean restoreVisualSettings(DiagramPart oldDiagram, EntityDiagram newDiagram) {
boolean hasChanges = false;
// Collect visual settings from old diagram and apply them to the new one
for (ERDEntity newEntity : newDiagram.getEntities()) {
NodePart oldEntity = oldDiagram.getChildByObject(newEntity.getObject());
if (oldEntity instanceof EntityPart) {
EntityDiagram.NodeVisualInfo vi = new EntityDiagram.NodeVisualInfo(oldEntity);
newDiagram.addVisualInfo(newEntity.getObject(), vi);
hasChanges = true;
}
}
for (ERDNote newNote : newDiagram.getNotes()) {
NodePart oldNotePart = oldDiagram.getChildByObject(newNote.getObject());
if (oldNotePart instanceof NotePart) {
EntityDiagram.NodeVisualInfo vi = new EntityDiagram.NodeVisualInfo(oldNotePart);
vi.initBounds = oldNotePart.getBounds();
newDiagram.addVisualInfo(newNote, vi);
hasChanges = true;
}
}
return hasChanges;
}
use of org.jkiss.dbeaver.erd.ui.model.EntityDiagram in project dbeaver by serge-rider.
the class ERDEditorPart method createGraphicalViewer.
/**
* Creates a new <code>GraphicalViewer</code>, configures, registers and
* initializes it.
*
* @param parent the parent composite
*/
@Override
protected void createGraphicalViewer(Composite parent) {
GraphicalViewer viewer = createViewer(parent);
// hook the viewer into the EditDomain
setGraphicalViewer(viewer);
configureGraphicalViewer();
hookGraphicalViewer();
initializeGraphicalViewer();
// Set initial (empty) contents
viewer.setContents(new EntityDiagram(null, "empty", getContentProvider(), getDecorator()));
// Set context menu
ContextMenuProvider provider = new ERDEditorContextMenuProvider(this);
viewer.setContextMenu(provider);
IWorkbenchPartSite site = getSite();
if (site instanceof IEditorSite) {
((IEditorSite) site).registerContextMenu(ERDEditorPart.class.getName() + ".EditorContext", provider, viewer, false);
} else {
site.registerContextMenu(ERDEditorPart.class.getName() + ".EditorContext", provider, viewer);
}
}
use of org.jkiss.dbeaver.erd.ui.model.EntityDiagram 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;
}
use of org.jkiss.dbeaver.erd.ui.model.EntityDiagram in project dbeaver by serge-rider.
the class NoteEditPolicy method createDeleteCommand.
@Override
protected Command createDeleteCommand(GroupRequest request) {
NotePart notePart = (NotePart) getHost();
Rectangle bounds = notePart.getFigure().getBounds().getCopy();
EntityDiagram parent = (EntityDiagram) (notePart.getParent().getModel());
return new NoteDeleteCommand(parent, notePart, bounds);
}
use of org.jkiss.dbeaver.erd.ui.model.EntityDiagram in project dbeaver by serge-rider.
the class EntityPart method createFigure.
// ******************* Layout related methods *********************/
/**
* Creates a figure which represents the table
*/
@Override
protected EntityFigure createFigure() {
final EntityDiagram diagram = getDiagram();
final EntityFigure figure = createFigureImpl();
EntityDiagram.NodeVisualInfo visualInfo = diagram.getVisualInfo(getEntity().getObject());
if (visualInfo != null) {
if (visualInfo.initBounds != null) {
figure.setLocation(visualInfo.initBounds.getLocation());
}
if (visualInfo.bgColor != null) {
figure.setBackgroundColor(visualInfo.bgColor);
}
if (getEntity().getAttributeVisibility() == null && visualInfo.attributeVisibility != null) {
getEntity().setAttributeVisibility(visualInfo.attributeVisibility);
}
}
return figure;
}
Aggregations