Search in sources :

Example 11 with ITextualEntityPart

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

the class TextualHilightEditPolicy method moveCaretVertically.

public boolean moveCaretVertically(int lines) {
    ITextualEntityPart textualHost = getTextualHost();
    if (!textualHost.hasFocus())
        return false;
    ITextualFigure textualFigure = textualHost.getTextualFigure();
    int position = textualHost.getCaretPosition();
    int newLine = textualFigure.getLineFromPosition(position) + lines;
    if (newLine < 0 || newLine >= textualFigure.getCaretLines())
        return false;
    int dy = lines / Math.abs(lines);
    Rectangle translatedCaret = textualFigure.getCaretBounds().getCopy().translate(0, dy);
    Point newLocation = dy > 0 ? translatedCaret.getBottomLeft() : translatedCaret.getTopLeft();
    CaretUpdater.sheduleSyncUpdate(textualHost.getViewer(), textualHost.getModelEntity(), newLocation, true);
    return true;
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) ITextualFigure(org.whole.lang.ui.figures.ITextualFigure) Point(org.eclipse.draw2d.geometry.Point)

Example 12 with ITextualEntityPart

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

the class E4Utils method defineSelectionBindings.

public static void defineSelectionBindings(IBindingManager bm, List<IEntityPart> selectedEntityParts, IEntityPartViewer viewer) {
    IEntity selectedEntities = BindingManagerFactory.instance.createTuple();
    for (IEntityPart selectedEntityPart : selectedEntityParts) selectedEntities.wAdd(selectedEntityPart.getModelEntity());
    if (viewer != null) {
        bm.wDef("self", EntityUtils.getCompoundRoot(viewer.getEntityContents()));
        bm.wDefValue("viewer", viewer);
        IEntityPart focusEntityPart = viewer.getFocusEntityPart();
        bm.wDef("focusEntity", focusEntityPart.getModelEntity());
    }
    bm.wDef("selectedEntities", selectedEntities);
    IEntityIterator<IEntity> iterator = IteratorFactory.childIterator();
    iterator.reset(selectedEntities);
    if (iterator.hasNext()) {
        IEntity focusEntity = iterator.next();
        bm.wDef("primarySelectedEntity", focusEntity);
        if (!bm.wIsSet("focusEntity"))
            bm.wDef("focusEntity", focusEntity);
        IEntityPart primarySelectedEntityPart = selectedEntityParts.get(0);
        if (primarySelectedEntityPart instanceof IHilightable) {
            final IHilightable hilightable = (IHilightable) primarySelectedEntityPart;
            bm.wDefValue("hilightPosition", -1);
            bm.wGet("hilightPosition").wAddRequestEventHandler(new IdentityRequestEventHandler() {

                public int notifyRequested(IEntity source, FeatureDescriptor feature, int value) {
                    return hilightable.getHilightPosition();
                }
            });
        }
        if (primarySelectedEntityPart instanceof ITextualEntityPart) {
            final ITextualEntityPart textualEntityPart = (ITextualEntityPart) primarySelectedEntityPart;
            bm.wDefValue("selectedText", "");
            bm.wGet("selectedText").wAddRequestEventHandler(new IdentityRequestEventHandler() {

                public String notifyRequested(IEntity source, FeatureDescriptor feature, String value) {
                    return textualEntityPart.hasSelectionRange() ? DataTypeUtils.getAsPresentationString(textualEntityPart.getModelEntity()).substring(textualEntityPart.getSelectionStart(), textualEntityPart.getSelectionEnd()) : "";
                }
            });
        }
    }
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IHilightable(org.whole.lang.ui.editpolicies.IHilightable) IEntityPart(org.whole.lang.ui.editparts.IEntityPart) IdentityRequestEventHandler(org.whole.lang.events.IdentityRequestEventHandler)

Example 13 with ITextualEntityPart

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

the class E4Utils method defineCaretBindings.

public static void defineCaretBindings(IBindingManager bm) {
    IEntity text = bm.wGet("focusEntity");
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    ITextualEntityPart targetPart = (ITextualEntityPart) ModelObserver.getObserver(text, viewer.getEditPartRegistry());
    String textToSplit = DataTypeUtils.getAsPresentationString(targetPart.getModelTextEntity());
    int start = targetPart.getSelectionStart();
    int end = targetPart.getSelectionEnd();
    if (start == -1 || end == -1)
        start = end = targetPart.getCaretPosition();
    String leftText = textToSplit.substring(0, start);
    String selectedText = textToSplit.substring(start, end);
    String rightText = textToSplit.substring(end);
    bm.wDefValue("leftText", leftText);
    bm.wDefValue("selectedText", selectedText);
    bm.wDefValue("rightText", rightText);
    bm.wDefValue("caretPositions", targetPart.getCaretPositions());
    bm.wDefValue("caretPosition", targetPart.getCaretPosition());
    bm.wDefValue("caretPositionStart", start);
    bm.wDefValue("caretPositionEnd", end);
    Rectangle caretBounds = CaretUtils.getAbsoluteCaretBounds(viewer, targetPart);
    bm.wDefValue("caretBounds", caretBounds);
    bm.wDefValue("caretVerticalLocation", caretBounds.y);
    bm.wDefValue("caretHorizontalLocation", caretBounds.x);
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) Rectangle(org.eclipse.draw2d.geometry.Rectangle) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 14 with ITextualEntityPart

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

the class PasteHandler method execute.

@Override
@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    if (bm.wIsSet("viewer") && Clipboard.instance().getInternalOrNativeEntityContents() == null) {
        IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
        if (ClipboardUtils.hasTextFocus(viewer) || ClipboardUtils.hasTextSeletion(viewer)) {
            IEntity focusEntity = bm.wGet("focusEntity");
            ITextualEntityPart focusPart = (ITextualEntityPart) viewer.getEditPartRegistry().get(focusEntity);
            String textContents = Clipboard.instance().getTextContents();
            Command command = focusPart.getCommand(TextualRequest.createInsertRequest(textContents));
            CommandStack commandStack = viewer.getEditDomain().getCommandStack();
            if (command instanceof ITextCommand) {
                TextTransactionCommand transactionCommand = new TextTransactionCommand();
                transactionCommand.setModel(focusEntity);
                transactionCommand.merge((ITextCommand) command);
                transactionCommand.setLabel(getLabel(bm));
                commandStack.execute(transactionCommand);
            } else {
                command.setLabel(getLabel(bm) + " text");
                commandStack.execute(command);
            }
            return;
        }
    }
    super.execute(bm);
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ITextCommand(org.whole.lang.ui.commands.ITextCommand) ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) ITextCommand(org.whole.lang.ui.commands.ITextCommand) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand) Command(org.eclipse.gef.commands.Command) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 15 with ITextualEntityPart

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

the class TextualDirectEditEditPolicy method getOverwriteTextCommand.

private Command getOverwriteTextCommand(TextualRequest request) {
    Command command;
    ITextualEntityPart textualEntityPart = (ITextualEntityPart) getHost();
    String contentToOverwrite = request.getContent();
    if (textualEntityPart.hasSelectionRange()) {
        command = createInsertOverSelectionCommand(textualEntityPart, contentToOverwrite);
    } else {
        OverwriteTextCommand overwrite = new OverwriteTextCommand();
        overwrite.setEntity(textualEntityPart.getModelTextEntity());
        overwrite.setViewer(textualEntityPart.getViewer());
        overwrite.setData(contentToOverwrite);
        command = overwrite;
    }
    return command;
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) DeleteTextCommand(org.whole.lang.ui.commands.DeleteTextCommand) BackspaceTextCommand(org.whole.lang.ui.commands.BackspaceTextCommand) ITextCommand(org.whole.lang.ui.commands.ITextCommand) InsertTextCommand(org.whole.lang.ui.commands.InsertTextCommand) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand) OverwriteTextCommand(org.whole.lang.ui.commands.OverwriteTextCommand) Command(org.eclipse.gef.commands.Command) OverwriteTextCommand(org.whole.lang.ui.commands.OverwriteTextCommand)

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