use of org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure in project webtools.sourceediting by eclipse.
the class LabelCellEditorLocator method relocate.
public void relocate(CellEditor celleditor) {
Text text = (Text) celleditor.getControl();
Label label = namedEditPart.getNameLabelFigure();
if (text.getBounds().x <= 0) {
int widthToRemove = 0;
// HACK
if (namedEditPart instanceof BaseFieldEditPart) {
BaseFieldEditPart field = (BaseFieldEditPart) namedEditPart;
IFieldFigure fieldFigure = field.getFieldFigure();
widthToRemove = fieldFigure.getTypeLabel().getBounds().width;
// TODO: !! perhaps the IFieldFigure should just have a method to compute this?
// Label typeAnnotationLabel = ((FieldFigure) field.getFigure()).getTypeAnnotationLabel();
// Label nameAnnotationLabel = ((FieldFigure) field.getFigure()).getNameAnnotationLabel();
// widthToRemove = typeLabel.getBounds().width + typeAnnotationLabel.getBounds().width + nameAnnotationLabel.getBounds().width;
}
Rectangle boundingRect = label.getTextBounds();
// Reduce the width by the amount we shifted along the x-axis
int delta = Math.abs(boundingRect.x - label.getParent().getBounds().x);
label.getParent().translateToAbsolute(boundingRect);
org.eclipse.swt.graphics.Rectangle trim = text.computeTrim(0, 0, 0, 0);
boundingRect.translate(trim.x, trim.y);
boundingRect.height = boundingRect.height - trim.y;
boundingRect.width = label.getParent().getBounds().width - delta - widthToRemove;
text.setBounds(boundingRect.x, boundingRect.y, boundingRect.width, boundingRect.height);
// Translate point
if (cursorLocation != null) {
Point translatedPoint = new Point(cursorLocation.x - boundingRect.x, cursorLocation.y - boundingRect.y);
// Calculate text offset corresponding to the translated point
text.setSelection(0, 0);
int xCaret = text.getCaretLocation().x;
int offset = text.getCaretPosition();
while (xCaret < translatedPoint.x) {
text.setSelection(offset + 1, offset + 1);
xCaret = text.getCaretLocation().x;
int newOffset = text.getCaretPosition();
if (newOffset == offset) {
break;
}
offset++;
}
text.setSelection(offset, offset);
}
}
}
use of org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure in project webtools.sourceediting by eclipse.
the class BaseFieldEditPart method refreshVisuals.
protected void refreshVisuals() {
super.refreshVisuals();
IFieldFigure figure = getFieldFigure();
IField field = (IField) getModel();
figure.getNameLabel().setText(field.getName());
figure.getTypeLabel().setText(field.getTypeName());
figure.refreshVisuals(getModel());
figure.recomputeLayout();
((GraphicalEditPart) getRoot()).getFigure().invalidateTree();
}
use of org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure in project webtools.sourceediting by eclipse.
the class BaseFieldEditPart method getReaderText.
public String getReaderText() {
IFieldFigure fieldFigure = getFieldFigure();
String name = "";
if (fieldFigure.getNameLabel() != null && fieldFigure.getNameLabel().getText().trim().length() > 0)
name += fieldFigure.getNameLabel().getText();
if (fieldFigure.getNameAnnotationLabel() != null && fieldFigure.getNameAnnotationLabel().getText().trim().length() > 0)
name += " " + fieldFigure.getNameAnnotationLabel().getText();
if (fieldFigure.getTypeLabel() != null && fieldFigure.getTypeLabel().getText().trim().length() > 0)
name += " type " + fieldFigure.getTypeLabel().getText();
if (fieldFigure.getTypeAnnotationLabel() != null && fieldFigure.getTypeAnnotationLabel().getText().trim().length() > 0)
name += " " + fieldFigure.getTypeAnnotationLabel().getText();
return name;
}
use of org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure in project webtools.sourceediting by eclipse.
the class XSDBaseFieldEditPart method directEditNameField.
protected void directEditNameField() {
Object model = getModel();
IFieldFigure fieldFigure = getFieldFigure();
if (model instanceof IField) {
IField field = (IField) model;
if (field.isReference()) {
ReferenceDirectEditManager manager = null;
if (field instanceof XSDElementDeclarationAdapter) {
manager = new ElementReferenceDirectEditManager((IField) model, this, fieldFigure.getNameLabel());
} else if (field instanceof XSDAttributeDeclarationAdapter) {
manager = new AttributeReferenceDirectEditManager((IField) model, this, fieldFigure.getNameLabel());
}
if (manager != null) {
ReferenceUpdateCommand elementUpdateCommand = new ReferenceUpdateCommand();
elementUpdateCommand.setDelegate(manager);
adtDirectEditPolicy.setUpdateCommand(elementUpdateCommand);
manager.show();
}
} else {
LabelEditManager manager = new LabelEditManager(this, new LabelCellEditorLocator(this, null));
NameUpdateCommandWrapper wrapper = new NameUpdateCommandWrapper();
adtDirectEditPolicy.setUpdateCommand(wrapper);
manager.show();
}
}
}
use of org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure in project webtools.sourceediting by eclipse.
the class XSDBaseFieldEditPart method refreshIcon.
protected void refreshIcon() {
IFieldFigure figure = getFieldFigure();
// our model implements ITreeElement
if (getModel() instanceof XSDBaseAdapter) {
Image image = ((XSDBaseAdapter) getModel()).getImage();
boolean isReadOnly = ((XSDBaseAdapter) getModel()).isReadOnly();
figure.getNameLabel().setIcon(image);
if (image != null) {
XSDConcreteComponent comp = (XSDConcreteComponent) ((XSDBaseAdapter) getModel()).getTarget();
figure.getNameLabel().setIcon(XSDCommonUIUtils.getUpdatedImage(comp, image, isReadOnly));
}
}
}
Aggregations