use of org.jkiss.dbeaver.erd.ui.part.NodePart in project dbeaver by serge-rider.
the class ChangeZOrderAction method createReorderCommand.
private Command createReorderCommand(final Object[] objects) {
return new Command() {
@Override
public void execute() {
for (Object item : objects) {
if (item instanceof NodePart) {
IFigure child = ((NodePart) item).getFigure();
final IFigure parent = child.getParent();
final List children = parent.getChildren();
if (children != null) {
children.remove(child);
if (front) {
children.add(child);
} else {
children.add(0, child);
}
child.repaint();
}
// ((NodePart) item).getDiagram().
}
}
}
@Override
public boolean canUndo() {
return false;
}
};
}
use of org.jkiss.dbeaver.erd.ui.part.NodePart in project dbeaver by serge-rider.
the class EntityConnectionEditPolicy method getConnectionCompleteCommand.
@Override
protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
AssociationCreateCommand cmd = (AssociationCreateCommand) request.getStartCommand();
NodePart part = (NodePart) request.getTargetEditPart();
cmd.setTargetEntity(part.getElement());
return cmd;
}
use of org.jkiss.dbeaver.erd.ui.part.NodePart in project dbeaver by serge-rider.
the class DiagramXYLayoutPolicy method createChangeConstraintCommand.
/**
* Creates command to move table. Does not allow table to be resized
*/
@Override
protected Command createChangeConstraintCommand(EditPart child, Object constraint) {
if (!(child instanceof NodePart))
return null;
if (!(constraint instanceof Rectangle))
return null;
NodePart nodePart = (NodePart) child;
Figure figure = (Figure) nodePart.getFigure();
Rectangle oldBounds = figure.getBounds();
Rectangle newBounds = (Rectangle) constraint;
// Restrict resize for entities
if (!ALLOW_ENTITY_RESIZE && nodePart instanceof EntityPart) {
if (oldBounds.width != newBounds.width && newBounds.width != -1)
return null;
if (oldBounds.height != newBounds.height && newBounds.height != -1)
return null;
}
return new NodeMoveCommand(nodePart, oldBounds.getCopy(), newBounds.getCopy());
}
use of org.jkiss.dbeaver.erd.ui.part.NodePart in project dbeaver by dbeaver.
the class SetPartSettingsAction method createColorCommand.
private Command createColorCommand(final Object[] objects) {
return new Command() {
private ViewSettings newSettings;
private final Map<ICustomizablePart, ViewSettings> oldSettings = new HashMap<>();
@Override
public void execute() {
final Shell shell = UIUtils.createCenteredShell(getWorkbenchPart().getSite().getShell());
try {
NodePart nodePart = null;
boolean hasNotes = false, hasEntities = false;
for (Object item : objects) {
if (item instanceof NodePart) {
if (nodePart == null) {
nodePart = (NodePart) item;
}
if (item instanceof NotePart) {
hasNotes = true;
} else if (item instanceof EntityPart) {
hasEntities = true;
}
}
}
PartSettingsDialog settingsDialog = new PartSettingsDialog(shell, nodePart, hasNotes, hasEntities);
if (settingsDialog.open() != IDialogConstants.OK_ID) {
return;
}
newSettings = settingsDialog.newSettings;
for (Object item : objects) {
if (item instanceof ICustomizablePart) {
ICustomizablePart part = (ICustomizablePart) item;
ViewSettings oldSettings = new ViewSettings();
oldSettings.transparency = part.getCustomTransparency();
oldSettings.background = part.getCustomBackgroundColor();
oldSettings.foreground = part.getCustomForegroundColor();
oldSettings.borderWidth = part.getCustomBorderWidth();
oldSettings.fontInfo = SharedFonts.toString(part.getCustomFont());
this.oldSettings.put(part, oldSettings);
setNodeSettings(part, newSettings);
}
}
} finally {
UIUtils.disposeCenteredShell(shell);
}
}
@Override
public void undo() {
for (Object item : objects) {
if (item instanceof ICustomizablePart) {
ICustomizablePart colorizedPart = (ICustomizablePart) item;
ViewSettings viewSettings = oldSettings.get(colorizedPart);
if (viewSettings != null) {
setNodeSettings(colorizedPart, viewSettings);
}
}
}
}
@Override
public void redo() {
for (Object item : objects) {
if (item instanceof ICustomizablePart) {
setNodeSettings((ICustomizablePart) item, newSettings);
}
}
}
private void setNodeSettings(ICustomizablePart part, ViewSettings settings) {
if (part instanceof NotePart) {
part.setCustomTransparency(settings.transparency);
}
part.setCustomBackgroundColor(settings.background);
if (part instanceof NotePart) {
part.setCustomForegroundColor(settings.foreground);
part.setCustomBorderWidth(settings.borderWidth);
part.setCustomFont(UIUtils.getSharedFonts().getFont(Display.getCurrent(), settings.fontInfo));
}
}
};
}
use of org.jkiss.dbeaver.erd.ui.part.NodePart in project dbeaver by dbeaver.
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;
}
Aggregations