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

#1652 Check selected attributes in join


Former-commit-id: a4c41917
上级 056d0708
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.figures.NoteFigure;
import org.jkiss.dbeaver.ext.erd.part.AttributePart;
/**
* Change attribute checked state
*/
public class AttributeCheckCommand extends Command {
private AttributePart attr;
private boolean newValue;
private boolean oldValue;
public AttributeCheckCommand(AttributePart attr, boolean newValue) {
super("Set note text");
this.attr = attr;
this.oldValue = this.attr.getAttribute().isChecked();
this.newValue = newValue;
}
@Override
public void execute() {
attr.getAttribute().setChecked(newValue);
attr.getFigure().getCheckBox().setSelected(newValue);
}
@Override
public void undo() {
attr.getAttribute().setChecked(oldValue);
attr.getFigure().getCheckBox().setSelected(oldValue);
}
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ package org.jkiss.dbeaver.ext.erd.figures;
import org.eclipse.draw2d.*;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.ext.erd.command.AttributeCheckCommand;
import org.jkiss.dbeaver.ext.erd.editor.ERDViewStyle;
import org.jkiss.dbeaver.ext.erd.model.ERDDecorator;
import org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute;
......@@ -48,6 +49,8 @@ public class AttributeItemFigure extends Figure
super();
this.part = part;
ERDEntityAttribute attribute = part.getAttribute();
ToolbarLayout layout = new ToolbarLayout(true);
setLayoutManager(layout);
......@@ -57,9 +60,18 @@ public class AttributeItemFigure extends Figure
boolean showCheckboxes = diagram.getDecorator().showCheckboxes();
if (showCheckboxes) {
CustomCheckBoxFigure attrCheckbox = new CustomCheckBoxFigure();
attrCheckbox.setSelected(attribute.isChecked());
attrCheckbox.addChangeListener(changeEvent -> {
boolean oldChecked = attribute.isChecked();
boolean newChecked = attrCheckbox.isSelected();
if (oldChecked != newChecked) {
part.getDiagramPart().getViewer().getEditDomain().getCommandStack().execute(
new AttributeCheckCommand(part, attrCheckbox.isSelected())
);
}
});
add(attrCheckbox);
}
ERDEntityAttribute attribute = part.getAttribute();
String attributeLabel = ERDUtils.getAttributeLabel(diagram, attribute);
......
......@@ -23,8 +23,8 @@ public final class CustomCheckBoxFigure extends Toggle {
}
public CustomCheckBoxFigure(String text) {
this.label = null;
this.setContents(this.label = new Label(text, UNCHECKED));
this.label = new Label(text, UNCHECKED);
this.setContents(this.label);
}
protected void handleSelectionChanged() {
......@@ -38,13 +38,11 @@ public final class CustomCheckBoxFigure extends Toggle {
protected void init() {
super.init();
this.addChangeListener(new ChangeListener() {
public void handleStateChanged(ChangeEvent changeEvent) {
if (changeEvent.getPropertyName().equals("selected")) {
CustomCheckBoxFigure.this.handleSelectionChanged();
}
this.addChangeListener(changeEvent -> {
if (changeEvent.getPropertyName().equals("selected")) {
CustomCheckBoxFigure.this.handleSelectionChanged();
}
});
}
}
......@@ -30,8 +30,10 @@ import org.jkiss.dbeaver.model.struct.DBSEntityAttribute;
* @author Serge Rider
*/
public class ERDEntityAttribute extends ERDObject<DBSEntityAttribute> {
private boolean isChecked;
private boolean inPrimaryKey;
private boolean inForeignKey;
private String alias;
public ERDEntityAttribute(DBSEntityAttribute attribute, boolean inPrimaryKey) {
super(attribute);
......@@ -46,6 +48,22 @@ public class ERDEntityAttribute extends ERDObject<DBSEntityAttribute> {
return DBValueFormatting.getObjectImage(object);
}
public boolean isChecked() {
return isChecked;
}
public void setChecked(boolean checked) {
isChecked = checked;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public boolean isInPrimaryKey() {
return inPrimaryKey;
}
......
......@@ -38,6 +38,7 @@ import org.jkiss.dbeaver.ext.erd.editor.ERDGraphicalViewer;
import org.jkiss.dbeaver.ext.erd.figures.AttributeItemFigure;
import org.jkiss.dbeaver.ext.erd.figures.EditableLabel;
import org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute;
import org.jkiss.dbeaver.ext.erd.model.ERDObject;
import org.jkiss.dbeaver.ext.erd.model.ERDUtils;
import java.beans.PropertyChangeEvent;
......@@ -49,7 +50,10 @@ import java.beans.PropertyChangeEvent;
*/
public class AttributePart extends PropertyAwarePart {
protected DirectEditManager manager;
public static final String PROP_CHECKED = "NAME";
public AttributePart() {
}
@Override
public boolean isSelectable() {
......@@ -112,17 +116,16 @@ public class AttributePart extends PropertyAwarePart {
}
protected void performDirectEdit() {
if (manager == null) {
ERDGraphicalViewer viewer = (ERDGraphicalViewer) getViewer();
ValidationMessageHandler handler = viewer.getValidationHandler();
ERDGraphicalViewer viewer = (ERDGraphicalViewer) getViewer();
ValidationMessageHandler handler = viewer.getValidationHandler();
Label l = getFigure().getLabel();
ColumnNameTypeCellEditorValidator columnNameTypeCellEditorValidator = new ColumnNameTypeCellEditorValidator(
handler);
Label l = getFigure().getLabel();
ColumnNameTypeCellEditorValidator columnNameTypeCellEditorValidator = new ColumnNameTypeCellEditorValidator(
handler);
DirectEditManager manager = new ExtendedDirectEditManager(this, TextCellEditor.class, new LabelCellEditorLocator(l), l,
columnNameTypeCellEditorValidator);
manager = new ExtendedDirectEditManager(this, TextCellEditor.class, new LabelCellEditorLocator(l), l,
columnNameTypeCellEditorValidator);
}
manager.show();
}
......
......@@ -54,9 +54,6 @@ public class ColumnDirectEditPolicy extends DirectEditPolicy
return null;
}
/**
* @see DirectEditPolicy#showCurrentEditValue(org.eclipse.gef.requests.DirectEditRequest)
*/
@Override
protected void showCurrentEditValue(DirectEditRequest request)
{
......@@ -65,10 +62,6 @@ public class ColumnDirectEditPolicy extends DirectEditPolicy
attributePart.handleNameChange(value);
}
/**
* @param to
* Revert request
*/
@Override
protected void storeOldEditValue(DirectEditRequest request)
{
......@@ -76,9 +69,6 @@ public class ColumnDirectEditPolicy extends DirectEditPolicy
oldValue = (String) cellEditor.getValue();
}
/**
* @param request
*/
@Override
protected void revertOldEditValue(DirectEditRequest request)
{
......
......@@ -27,22 +27,17 @@ import org.jkiss.dbeaver.ext.erd.part.EntityPart;
/**
* EditPolicy for the direct editing of table names
*
*
* @author Serge Rider
*/
public class EntityDirectEditPolicy extends DirectEditPolicy
{
public class EntityDirectEditPolicy extends DirectEditPolicy {
private String oldValue;
private String oldValue;
/**
* @see DirectEditPolicy#getDirectEditCommand(org.eclipse.gef.requests.DirectEditRequest)
*/
@Override
protected Command getDirectEditCommand(DirectEditRequest request)
{
@Override
protected Command getDirectEditCommand(DirectEditRequest request) {
/*
EntityRenameCommand cmd = new EntityRenameCommand();
EntityRenameCommand cmd = new EntityRenameCommand();
ERDEntity table = (ERDEntity) getHost().getModel();
cmd.setTable(table);
cmd.setOldName(table.getName());
......@@ -51,36 +46,26 @@ public class EntityDirectEditPolicy extends DirectEditPolicy
return cmd;
*/
return null;
}
}
/**
* @see DirectEditPolicy#showCurrentEditValue(org.eclipse.gef.requests.DirectEditRequest)
*/
@Override
protected void showCurrentEditValue(DirectEditRequest request)
{
String value = (String) request.getCellEditor().getValue();
EntityPart entityPart = (EntityPart) getHost();
entityPart.handleNameChange(value);
}
@Override
protected void showCurrentEditValue(DirectEditRequest request) {
String value = (String) request.getCellEditor().getValue();
EntityPart entityPart = (EntityPart) getHost();
entityPart.handleNameChange(value);
}
@Override
protected void storeOldEditValue(DirectEditRequest request)
{
CellEditor cellEditor = request.getCellEditor();
oldValue = (String) cellEditor.getValue();
}
@Override
protected void storeOldEditValue(DirectEditRequest request) {
CellEditor cellEditor = request.getCellEditor();
oldValue = (String) cellEditor.getValue();
}
/**
* @param request
*/
@Override
protected void revertOldEditValue(DirectEditRequest request)
{
CellEditor cellEditor = request.getCellEditor();
cellEditor.setValue(oldValue);
EntityPart entityPart = (EntityPart) getHost();
entityPart.revertNameChange();
}
@Override
protected void revertOldEditValue(DirectEditRequest request) {
CellEditor cellEditor = request.getCellEditor();
cellEditor.setValue(oldValue);
EntityPart entityPart = (EntityPart) getHost();
entityPart.revertNameChange();
}
}
\ No newline at end of file
......@@ -57,9 +57,6 @@ public class NoteDirectEditPolicy extends DirectEditPolicy {
oldValue = (String) cellEditor.getValue();
}
/**
* @param request
*/
@Override
protected void revertOldEditValue(DirectEditRequest request) {
CellEditor cellEditor = request.getCellEditor();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册