提交 c71ad509 编写于 作者: S serge-rider

dbeaver/dbeaver-ee#587 ERD model: rename support


Former-commit-id: 3a7a2ff7
上级 271026d0
......@@ -119,6 +119,18 @@ public class ERDEntity extends ERDElement<DBSEntity> {
return CommonUtils.safeList(attributes);
}
public ERDEntityAttribute getAttribute(DBSEntityAttribute attribute) {
if (attribute == null) {
return null;
}
for (ERDEntityAttribute attr : attributes) {
if (attr.getObject() == attribute) {
return attr;
}
}
return null;
}
@NotNull
public List<ERDEntityAttribute> getCheckedAttributes() {
List<ERDEntityAttribute> result = new ArrayList<>();
......
......@@ -21,7 +21,6 @@ package org.jkiss.dbeaver.erd.ui.directedit;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.commands.Command;
......@@ -32,8 +31,6 @@ import org.eclipse.jface.viewers.ICellEditorValidator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Text;
......@@ -45,7 +42,6 @@ import org.jkiss.dbeaver.erd.ui.figures.NoteFigure;
*/
public class ExtendedDirectEditManager extends DirectEditManager {
private Font figureFont;
private VerifyListener verifyListener;
private IFigure figure;
private String originalValue;
......@@ -77,21 +73,6 @@ public class ExtendedDirectEditManager extends DirectEditManager {
}
}
/**
* @see org.eclipse.gef.tools.DirectEditManager#bringDown()
*/
@Override
protected void bringDown() {
Font disposeFont = figureFont;
figureFont = null;
super.bringDown();
if (disposeFont != null)
disposeFont.dispose();
}
/**
* @see org.eclipse.gef.tools.DirectEditManager#initCellEditor()
*/
@Override
protected void initCellEditor() {
......@@ -132,21 +113,8 @@ public class ExtendedDirectEditManager extends DirectEditManager {
//set the initial value of the
originalValue = getFigureText(this.figure);
getCellEditor().setValue(originalValue);
//calculate the font size of the underlying
figureFont = figure.getFont();
FontData data = figureFont.getFontData()[0];
Dimension fontSize = new Dimension(0, data.getHeight());
//set the font to be used
this.figure.translateToAbsolute(fontSize);
data.setHeight(fontSize.height);
figureFont = new Font(null, data);
//set the validator for the CellEditor
getCellEditor().setValidator(validator);
text.setFont(figureFont);
text.selectAll();
}
......
......@@ -44,6 +44,10 @@ public class ERDEditorViewer extends Viewer
this.editorPart = editorPart;
}
public ERDEditorPart getEditorPart() {
return editorPart;
}
@Override
public Control getControl() {
return editorPart.getGraphicalViewer().getControl();
......
......@@ -39,6 +39,7 @@ import org.eclipse.ui.themes.ITheme;
import org.eclipse.ui.themes.IThemeManager;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.erd.model.ERDEntity;
import org.jkiss.dbeaver.erd.model.ERDEntityAttribute;
import org.jkiss.dbeaver.erd.ui.ERDUIConstants;
import org.jkiss.dbeaver.erd.ui.directedit.ValidationMessageHandler;
import org.jkiss.dbeaver.erd.ui.part.DiagramPart;
......@@ -338,21 +339,31 @@ public class ERDGraphicalViewer extends ScrollingGraphicalViewer implements IPro
if (action == DBPEvent.Action.OBJECT_SELECT || !usedDataSources.containsKey(object.getDataSource().getContainer())) {
return;
}
DBSEntity entity = null;
DBSEntity entity;
DBSEntityAttribute entityAttribute;
if (object instanceof DBSEntityAttribute) {
entity = ((DBSEntityAttribute) object).getParentObject();
entityAttribute = (DBSEntityAttribute) object;
entity = entityAttribute.getParentObject();
} else if (object instanceof DBSEntity) {
entityAttribute = null;
entity = (DBSEntity) object;
} else {
return;
}
if (entity != null) {
ERDEntity erdEntity = editor.getDiagram().getEntity(entity);
if (erdEntity != null) {
UIUtils.asyncExec(() -> {
ERDEntity erdEntity = editor.getDiagram().getEntity(entity);
if (erdEntity != null) {
UIUtils.asyncExec(() -> {
if (entityAttribute == null) {
erdEntity.reloadAttributes(editor.getDiagram());
erdEntity.firePropertyChange(ERDEntity.PROP_CONTENTS, null, null);
});
}
} else {
ERDEntityAttribute erdAttribute = erdEntity.getAttribute(entityAttribute);
if (erdAttribute != null) {
erdAttribute.firePropertyChange(ERDEntityAttribute.PROP_NAME, entityAttribute.getName(), entityAttribute.getName());
}
}
});
}
}
......
......@@ -115,11 +115,15 @@ public class AttributePart extends PropertyAwarePart {
columnLabel.repaint();
}
public void handleNameChange(String textValue) {
EditableLabel label = getFigure().getLabel();
label.setText(textValue);
public void handleNameChange() {
AttributeItemFigure figure = getFigure();
figure.updateLabels();
setSelected(EditPart.SELECTED_NONE);
label.revalidate();
figure.revalidate();
//EditableLabel label = getFigure().getLabel();
//label.setText(textValue);
//setSelected(EditPart.SELECTED_NONE);
//label.revalidate();
}
/**
......@@ -133,17 +137,6 @@ public class AttributePart extends PropertyAwarePart {
figure.revalidate();
}
/**
* Reverts state back to prior edit state
*/
public void revertNameChange(String oldValue) {
AttributeItemFigure figure = getFigure();
figure.setVisible(true);
setSelected(EditPart.SELECTED_PRIMARY);
figure.revalidate();
}
/**
* We don't need to explicitly handle refresh visuals because the times when
* this needs to be done it is handled by the table e.g. handleNameChange()
......
......@@ -21,10 +21,16 @@ import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.ui.IEditorInput;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.erd.model.ERDObject;
import org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart;
import org.jkiss.dbeaver.erd.ui.editor.ERDGraphicalViewer;
import org.jkiss.dbeaver.erd.ui.model.EntityDiagram;
import org.jkiss.dbeaver.model.DBPNamedObject;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
......@@ -60,6 +66,21 @@ public abstract class PropertyAwarePart extends AbstractGraphicalEditPart implem
return getDiagramPart().getDiagram();
}
@NotNull
public ERDEditorPart getEditor() {
return ((ERDGraphicalViewer)getViewer()).getEditor();
}
@Nullable
public DBECommandContext getCommandContext() {
ERDEditorPart editor = getEditor();
IEditorInput editorInput = editor.getEditorInput();
if (editorInput instanceof IDatabaseEditorInput) {
return ((IDatabaseEditorInput) editorInput).getCommandContext();
}
return null;
}
protected boolean isEditEnabled() {
return getDiagram().isEditEnabled();
}
......
......@@ -437,6 +437,9 @@ public abstract class SQLObjectEditor<OBJECT_TYPE extends DBSObject, CONTAINER_T
@Override
public DBEPersistAction[] getPersistActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, Map<String, Object> options) {
if (CommonUtils.equalObjects(oldName, newName)) {
return new DBEPersistAction[0];
}
List<DBEPersistAction> actions = new ArrayList<>();
addObjectRenameActions(monitor, executionContext, actions, this, options);
return actions.toArray(new DBEPersistAction[0]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册