Search in sources :

Example 1 with IFieldFigure

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);
        }
    }
}
Also used : Label(org.eclipse.draw2d.Label) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.draw2d.geometry.Point) IFieldFigure(org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure) Point(org.eclipse.draw2d.geometry.Point) BaseFieldEditPart(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.BaseFieldEditPart)

Example 2 with IFieldFigure

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();
}
Also used : IFieldFigure(org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure) IField(org.eclipse.wst.xsd.ui.internal.adt.facade.IField)

Example 3 with IFieldFigure

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;
}
Also used : IFieldFigure(org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure)

Example 4 with IFieldFigure

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();
        }
    }
}
Also used : ElementReferenceDirectEditManager(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.ElementReferenceDirectEditManager) LabelEditManager(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.LabelEditManager) XSDAttributeDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeDeclarationAdapter) LabelCellEditorLocator(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.LabelCellEditorLocator) IFieldFigure(org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure) IField(org.eclipse.wst.xsd.ui.internal.adt.facade.IField) AttributeReferenceDirectEditManager(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.AttributeReferenceDirectEditManager) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter) AttributeReferenceDirectEditManager(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.AttributeReferenceDirectEditManager) ReferenceDirectEditManager(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.ReferenceDirectEditManager) ElementReferenceDirectEditManager(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.ElementReferenceDirectEditManager)

Example 5 with IFieldFigure

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));
        }
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IFieldFigure(org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure) Image(org.eclipse.swt.graphics.Image)

Aggregations

IFieldFigure (org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure)9 IField (org.eclipse.wst.xsd.ui.internal.adt.facade.IField)4 Point (org.eclipse.draw2d.geometry.Point)2 ElementReferenceDirectEditManager (org.eclipse.wst.xsd.ui.internal.adt.design.directedit.ElementReferenceDirectEditManager)2 LabelCellEditorLocator (org.eclipse.wst.xsd.ui.internal.adt.design.directedit.LabelCellEditorLocator)2 LabelEditManager (org.eclipse.wst.xsd.ui.internal.adt.design.directedit.LabelEditManager)2 IADTObject (org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject)2 Label (org.eclipse.draw2d.Label)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 LocationRequest (org.eclipse.gef.requests.LocationRequest)1 Image (org.eclipse.swt.graphics.Image)1 Text (org.eclipse.swt.widgets.Text)1 XSDAttributeDeclarationAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeDeclarationAdapter)1 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)1 XSDElementDeclarationAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter)1 IAnnotationProvider (org.eclipse.wst.xsd.ui.internal.adt.design.IAnnotationProvider)1 AttributeReferenceDirectEditManager (org.eclipse.wst.xsd.ui.internal.adt.design.directedit.AttributeReferenceDirectEditManager)1 ReferenceDirectEditManager (org.eclipse.wst.xsd.ui.internal.adt.design.directedit.ReferenceDirectEditManager)1 TypeReferenceDirectEditManager (org.eclipse.wst.xsd.ui.internal.adt.design.directedit.TypeReferenceDirectEditManager)1