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

Entity figure model refactoring


Former-commit-id: 500fb316
上级 01abdb2e
......@@ -16,7 +16,10 @@
*/
package org.jkiss.dbeaver.ext.erd.figures;
import org.eclipse.draw2d.*;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.jkiss.code.NotNull;
......@@ -38,7 +41,7 @@ import java.util.List;
public class AttributeItemFigure extends Figure
{
protected final AttributePart part;
private EditableLabel rightLabel;
private IFigure rightPanel;
public AttributeItemFigure(AttributePart part)
{
......@@ -108,17 +111,18 @@ public class AttributeItemFigure extends Figure
return (EditableLabel) children.get(children.size() == 1 ? 0 : 1);
}
public EditableLabel getRightLabel() {
return rightLabel;
public IFigure getRightPanel() {
return rightPanel;
}
void setRightLabel(EditableLabel attrExtra) {
this.rightLabel = attrExtra;
void setRightPanel(IFigure attrExtra) {
this.rightPanel = attrExtra;
}
public void updateLabels() {
getLabel().setText(part.getAttributeLabel());
if (rightLabel != null) {
if (rightPanel instanceof Label) {
String rightText = "";
if (part.getDiagram().hasAttributeStyle(ERDViewStyle.TYPES)) {
rightText = part.getAttribute().getObject().getFullTypeName();
......@@ -128,7 +132,7 @@ public class AttributeItemFigure extends Figure
rightText += " NOT NULL";
}
}
rightLabel.setText(rightText);
((Label)rightPanel).setText(rightText);
}
}
}
......@@ -23,7 +23,9 @@ import org.eclipse.draw2d.*;
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.swt.graphics.Image;
import org.jkiss.dbeaver.ext.erd.ERDConstants;
import org.jkiss.dbeaver.ext.erd.editor.ERDViewStyle;
import org.jkiss.dbeaver.ext.erd.model.ERDEntity;
import org.jkiss.dbeaver.ext.erd.part.EntityPart;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.struct.DBSEntityType;
......@@ -37,19 +39,23 @@ import org.jkiss.dbeaver.ui.UIUtils;
*/
public class EntityFigure extends Figure {
private final ERDEntity entity;
private final EntityPart part;
private AttributeListFigure keyFigure;
private AttributeListFigure attributeFigure;
private EditableLabel nameLabel;
public EntityFigure(ERDEntity entity, boolean useFQN)
public EntityFigure(EntityPart part)
{
this.entity = entity;
this.part = part;
ERDEntity entity = part.getEntity();
boolean useFQN = part.getDiagram().hasAttributeStyle(ERDViewStyle.ENTITY_FQN);
Image tableImage = DBeaverIcons.getImage(entity.getObject().getEntityType().getIcon());
keyFigure = new AttributeListFigure(entity, true);
attributeFigure = new AttributeListFigure(entity, false);
nameLabel = new EditableLabel(
useFQN ?
DBUtils.getObjectFullName(entity.getObject(), DBPEvaluationContext.DDL) :
......@@ -92,9 +98,9 @@ public class EntityFigure extends Figure {
public void refreshColors() {
ColorRegistry colorRegistry = UIUtils.getColorRegistry();
if (entity.isPrimary()) {
if (part.getEntity().isPrimary()) {
setBackgroundColor(colorRegistry.get(ERDConstants.COLOR_ERD_ENTITY_PRIMARY_BACKGROUND));
} else if (entity.getObject().getEntityType() == DBSEntityType.ASSOCIATION) {
} else if (part.getEntity().getObject().getEntityType() == DBSEntityType.ASSOCIATION) {
setBackgroundColor(colorRegistry.get(ERDConstants.COLOR_ERD_ENTITY_ASSOCIATION_BACKGROUND));
} else {
setBackgroundColor(colorRegistry.get(ERDConstants.COLOR_ERD_ENTITY_REGULAR_BACKGROUND));
......@@ -127,7 +133,7 @@ public class EntityFigure extends Figure {
}
/**
* @return the figure containing the column lables
* @return the figure containing the column labels
*/
public AttributeListFigure getColumnsFigure()
{
......@@ -141,12 +147,10 @@ public class EntityFigure extends Figure {
figure.setForegroundColor(colorRegistry.get(ERDConstants.COLOR_ERD_ATTR_FOREGROUND));
figure.setBackgroundColor(colorRegistry.get(ERDConstants.COLOR_ERD_ATTR_BACKGROUND));
EditableLabel attrExtra = new EditableLabel("");
//attrExtra.setBorder(new LineBorder(1));
attrExtra.setTextAlignment(PositionConstants.RIGHT);
IFigure attrExtra = createRightPanel();
AttributeItemFigure attributeItemFigure = (AttributeItemFigure) figure;
attributeItemFigure.setRightLabel(attrExtra);
attributeItemFigure.setRightPanel(attrExtra);
if (attributeItemFigure.getAttribute().isInPrimaryKey()) {
keyFigure.add(figure, new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_BEGINNING, true, false));
keyFigure.add(attrExtra, new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_BEGINNING));
......@@ -159,4 +163,12 @@ public class EntityFigure extends Figure {
super.add(figure, constraint, index);
}
}
protected IFigure createRightPanel() {
EditableLabel label = new EditableLabel("");
//attrExtra.setBorder(new LineBorder(1));
label.setTextAlignment(PositionConstants.RIGHT);
return label;
}
}
\ No newline at end of file
......@@ -163,10 +163,10 @@ public class AttributePart extends PropertyAwarePart {
*/
@Override
protected void commitNameChange(PropertyChangeEvent evt) {
AttributeItemFigure label = getFigure();
label.updateLabels();
AttributeItemFigure figure = getFigure();
figure.updateLabels();
setSelected(EditPart.SELECTED_PRIMARY);
label.revalidate();
figure.revalidate();
}
......@@ -174,10 +174,10 @@ public class AttributePart extends PropertyAwarePart {
* Reverts state back to prior edit state
*/
public void revertNameChange(String oldValue) {
AttributeItemFigure label = getFigure();
label.setVisible(true);
AttributeItemFigure figure = getFigure();
figure.setVisible(true);
setSelected(EditPart.SELECTED_PRIMARY);
label.revalidate();
figure.revalidate();
}
/**
......
......@@ -31,7 +31,6 @@ import org.jkiss.dbeaver.ext.erd.directedit.LabelCellEditorLocator;
import org.jkiss.dbeaver.ext.erd.directedit.TableNameCellEditorValidator;
import org.jkiss.dbeaver.ext.erd.directedit.ValidationMessageHandler;
import org.jkiss.dbeaver.ext.erd.editor.ERDGraphicalViewer;
import org.jkiss.dbeaver.ext.erd.editor.ERDViewStyle;
import org.jkiss.dbeaver.ext.erd.figures.EditableLabel;
import org.jkiss.dbeaver.ext.erd.figures.EntityFigure;
import org.jkiss.dbeaver.ext.erd.model.*;
......@@ -185,9 +184,8 @@ public class EntityPart extends NodePart {
@Override
protected EntityFigure createFigure() {
final EntityDiagram diagram = getDiagram();
boolean useFQN = diagram.hasAttributeStyle(ERDViewStyle.ENTITY_FQN);
final EntityFigure figure = new EntityFigure(getEntity(), useFQN);
final EntityFigure figure = createFigureImpl();
EntityDiagram.NodeVisualInfo visualInfo = diagram.getVisualInfo(getEntity());
if (visualInfo != null) {
......@@ -203,6 +201,10 @@ public class EntityPart extends NodePart {
return figure;
}
protected EntityFigure createFigureImpl() {
return new EntityFigure(this);
}
@Override
public EntityFigure getFigure() {
return (EntityFigure) super.getFigure();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册