Search in sources :

Example 26 with ITextualEntityPart

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

the class TextualDragTracker method performSelectionUpdate.

private void performSelectionUpdate(IWholeSelection selection, Point location, boolean caretOnSelectionEnd) {
    EditPartViewer viewer = getCurrentViewer();
    IEntityPart focusPart = null;
    if (selection.size() > 0) {
        IWholeSelection last = selection.get(selection.size() - 1);
        int caretPosition = -1;
        switch(last.getKind()) {
            case RANGE:
                caretPosition = last.getEndPosition();
            case PART:
                IEntityPart lastPart = last.getPart();
                if (lastPart instanceof ITextualEntityPart) {
                    ITextualEntityPart caretPart = (ITextualEntityPart) lastPart;
                    if (caretOnSelectionEnd) {
                        caretPosition = caretPosition < 0 ? caretPart.getCaretPositions() : caretPosition;
                        CaretUpdater.sheduleSyncUpdate(getCurrentViewer(), lastPart.getModelEntity(), caretPosition, true);
                    } else
                        CaretUpdater.sheduleSyncUpdate(getCurrentViewer(), lastPart.getModelEntity(), location != null ? location : getLocation(), true);
                    // update focus only if instance of ICaretEntityPart
                    focusPart = lastPart;
                }
            default:
                break;
        }
    }
    List<IEntityPart> partList = new ArrayList<IEntityPart>();
    for (int i = 0; i < selection.size(); i++) {
        IWholeSelection sel = selection.get(i);
        switch(sel.getKind()) {
            case RANGE:
                ((ITextualEntityPart) sel.getPart()).setSelectionRange(sel.getStartPosition(), sel.getEndPosition());
                partList.add(sel.getPart());
                break;
            case PART:
                IEntityPart part = sel.getPart();
                if (part instanceof ITextualEntityPart)
                    ((ITextualEntityPart) part).setSelectionRange(0, ((ITextualEntityPart) part).getCaretPositions());
                partList.add(sel.getPart());
                break;
            default:
                break;
        }
    }
    viewer.setSelection(new StructuredSelection(partList));
    viewer.setFocus(focusPart);
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) EditPartViewer(org.eclipse.gef.EditPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart) Point(org.eclipse.draw2d.geometry.Point)

Example 27 with ITextualEntityPart

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

the class TextualDragTracker method handleDragInProgress.

@Override
protected boolean handleDragInProgress() {
    EditPartViewer viewer = getCurrentViewer();
    ITextualEntityPart textualEntityPart = getTextualEntityPart();
    if (textualEntityPart == null)
        return false;
    EditPart overPart = viewer.findObjectAt(getLocation());
    if (overPart == endPart) {
        end = textualEntityPart.getCaretPosition();
        if (start <= end)
            performSelectionUpdate(new SelectionRange(textualEntityPart, start, end), false);
        else {
            performSelectionUpdate(new SelectionRange(textualEntityPart, end, start), false);
        }
    } else {
        ITextualFigure textualFigure = textualEntityPart.getTextualFigure();
        Rectangle textBounds = textualFigure.getTextBounds();
        textualFigure.translateToAbsolute(textBounds);
        Point mouseLocation = getLocation();
        mouseLocation.x = Math.max(mouseLocation.x, textBounds.x);
        mouseLocation.x = Math.min(mouseLocation.x, textBounds.right() - 1);
        mouseLocation.y = Math.max(mouseLocation.y, textBounds.y);
        mouseLocation.y = Math.min(mouseLocation.y, textBounds.bottom() - 1);
        textualEntityPart.updateCaret(mouseLocation);
        end = textualEntityPart.getCaretPosition();
        if (start <= end)
            performSelectionUpdate(new SelectionRange(textualEntityPart, start, end), mouseLocation, false);
        else {
            performSelectionUpdate(new SelectionRange(textualEntityPart, end, start), mouseLocation, false);
        }
    }
    return super.handleDragInProgress();
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) EditPart(org.eclipse.gef.EditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) EditPartViewer(org.eclipse.gef.EditPartViewer) Point(org.eclipse.draw2d.geometry.Point) ITextualFigure(org.whole.lang.ui.figures.ITextualFigure)

Example 28 with ITextualEntityPart

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

the class TextualDragTracker method handleDoubleClick.

@Override
protected boolean handleDoubleClick(int button) {
    ITextualEntityPart textualEntityPart = getTextualEntityPart();
    if (button == 1 && textualEntityPart != null) {
        IGEFEditorKit editorkit = (IGEFEditorKit) textualEntityPart.getModelEntity().wGetEditorKit();
        EditPoint editPoint = new EditPoint(textualEntityPart, textualEntityPart.getCaretPosition());
        IKeyHandler keyHandler = editorkit.getKeyHandler();
        IWholeSelection selection = keyHandler.calculateDoubleClickSelection(editPoint);
        performSelectionUpdate(selection, true);
        return true;
    }
    return super.handleDoubleClick(button);
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IGEFEditorKit(org.whole.lang.ui.editor.IGEFEditorKit) IKeyHandler(org.whole.lang.ui.keys.IKeyHandler)

Example 29 with ITextualEntityPart

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

the class InsertTextCommand method execute.

public void execute() {
    ITextualEntityPart caretPart = getSourcePart();
    int start = caretPart.getCaretPosition();
    int end = start + length;
    this.initialRange = new Range(start, start);
    String value = DataTypeUtils.getAsPresentationString(entity);
    value = value.substring(0, start) + data + value.substring(start);
    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)

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