Search in sources :

Example 1 with ITextualEntityPart

use of org.whole.lang.ui.editparts.ITextualEntityPart in project whole by wholeplatform.

the class BackspaceTextCommand method execute.

public void execute() {
    ITextualEntityPart caretPart = getSourcePart();
    int end = caretPart.getCaretPosition();
    int start = end - length;
    this.initialRange = new Range(start, end);
    String value = DataTypeUtils.getAsPresentationString(entity);
    value = value.substring(0, start) + value.substring(end);
    this.finalRange = new Range(start, start);
    setNewValue(DataTypeUtils.getDataTypeParser(entity, DataTypeParsers.PRESENTATION).parse(entity.wGetEntityDescriptor(), value));
    CaretUpdater.createCU(getViewer(), entity, start).sheduleSyncUpdate();
    super.execute();
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart)

Example 2 with ITextualEntityPart

use of org.whole.lang.ui.editparts.ITextualEntityPart in project whole by wholeplatform.

the class OverwriteTextCommand method execute.

public void execute() {
    ITextualEntityPart caretPart = getSourcePart();
    int start = caretPart.getCaretPosition();
    int end = start + length;
    this.initialRange = new Range(start, end);
    String value = DataTypeUtils.getAsPresentationString(entity);
    value = value.substring(0, start) + data + value.substring(end);
    this.finalRange = new Range(start, end);
    setNewValue(DataTypeUtils.getDataTypeParser(entity, DataTypeParsers.PRESENTATION).parse(entity.wGetEntityDescriptor(), value));
    CaretUpdater.createCU(getViewer(), entity, end).sheduleSyncUpdate();
    super.execute();
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart)

Example 3 with ITextualEntityPart

use of org.whole.lang.ui.editparts.ITextualEntityPart in project whole by wholeplatform.

the class DeleteTextCommand method execute.

public void execute() {
    ITextualEntityPart caretPart = getSourcePart();
    int start = caretPart.getCaretPosition();
    int end = start + length;
    this.initialRange = new Range(start, end);
    String value = DataTypeUtils.getAsPresentationString(entity);
    value = value.substring(0, start) + value.substring(end);
    this.finalRange = new Range(start, start);
    setNewValue(DataTypeUtils.getDataTypeParser(entity, DataTypeParsers.PRESENTATION).parse(entity.wGetEntityDescriptor(), value));
    CaretUpdater.createCU(getViewer(), entity, start).sheduleSyncUpdate();
    super.execute();
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart)

Example 4 with ITextualEntityPart

use of org.whole.lang.ui.editparts.ITextualEntityPart in project whole by wholeplatform.

the class TextualKeyHandler method calculateDoubleClickSelection.

public IWholeSelection calculateDoubleClickSelection(EditPoint editPoint) {
    ITextualEntityPart targetPart = (ITextualEntityPart) editPoint.focus;
    IEntity targetEntity = targetPart.getModelEntity();
    int endPosition = -1, startPosition = -1;
    if (enableSmartSelection(targetEntity)) {
        String text = targetEntity.wStringValue();
        int position = targetPart.getCaretPosition();
        int positions = targetPart.getCaretPositions();
        Matcher matcher;
        if (position == 0) {
            matcher = RIGHT_PATTERN.matcher(text);
            if (matcher.find()) {
                startPosition = 0;
                endPosition = matcher.end();
            }
        } else if (position == positions) {
            matcher = LEFT_PATTERN.matcher(text);
            if (matcher.find()) {
                startPosition = matcher.start();
                endPosition = positions;
            }
        } else {
            if (Character.isLetterOrDigit(text.charAt(position))) {
                if (Character.isLetterOrDigit(text.charAt(position - 1))) {
                    // XX
                    String substring = text.substring(0, position);
                    matcher = LEFT_PATTERN.matcher(substring);
                    if (matcher.find())
                        startPosition = matcher.start();
                    matcher = RIGHT_PATTERN.matcher(text.substring(position));
                    if (matcher.find())
                        endPosition = position + matcher.end();
                } else {
                    // .X
                    matcher = RIGHT_PATTERN.matcher(text.substring(position));
                    if (matcher.find()) {
                        startPosition = position + matcher.start();
                        endPosition = position + matcher.end();
                    }
                }
            } else {
                if (Character.isLetterOrDigit(text.charAt(position - 1))) {
                    // X.
                    matcher = LEFT_PATTERN.matcher(text.substring(0, position));
                    if (matcher.find()) {
                        startPosition = matcher.start();
                        endPosition = position;
                    }
                } else {
                    // ..
                    startPosition = position - 1;
                    endPosition = position;
                }
            }
        }
    }
    if (endPosition >= 0 && startPosition >= 0)
        return new SelectionRange(editPoint.focus, startPosition, endPosition);
    else
        return super.calculateDoubleClickSelection(editPoint);
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) Matcher(java.util.regex.Matcher) SelectionRange(org.whole.lang.ui.tools.SelectionRange) EditPoint(org.whole.lang.ui.tools.EditPoint)

Example 5 with ITextualEntityPart

use of org.whole.lang.ui.editparts.ITextualEntityPart in project whole by wholeplatform.

the class CaretUtils method getCaretPositions.

public static int getCaretPositions(IEntityPartViewer viewer, IEntity entity) {
    IEntityPart entityPart = viewer.getEditPartRegistry().get(entity);
    if (!(entityPart instanceof ITextualEntityPart))
        throw new IllegalArgumentException("the entity part is not textual");
    ITextualEntityPart targetPart = (ITextualEntityPart) entityPart;
    return targetPart.getCaretPositions();
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Aggregations

ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)29 Point (org.eclipse.draw2d.geometry.Point)8 IEntity (org.whole.lang.model.IEntity)8 Command (org.eclipse.gef.commands.Command)6 ITextCommand (org.whole.lang.ui.commands.ITextCommand)5 TextTransactionCommand (org.whole.lang.ui.commands.TextTransactionCommand)5 IEntityPart (org.whole.lang.ui.editparts.IEntityPart)5 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)5 EditPart (org.eclipse.gef.EditPart)4 BackspaceTextCommand (org.whole.lang.ui.commands.BackspaceTextCommand)4 DeleteTextCommand (org.whole.lang.ui.commands.DeleteTextCommand)4 InsertTextCommand (org.whole.lang.ui.commands.InsertTextCommand)4 OverwriteTextCommand (org.whole.lang.ui.commands.OverwriteTextCommand)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 IGEFEditorKit (org.whole.lang.ui.editor.IGEFEditorKit)3 ITextualFigure (org.whole.lang.ui.figures.ITextualFigure)3 IKeyHandler (org.whole.lang.ui.keys.IKeyHandler)3 EditPoint (org.whole.lang.ui.tools.EditPoint)3 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)2 Execute (org.eclipse.e4.core.di.annotations.Execute)2