Search in sources :

Example 21 with ITextualEntityPart

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

the class CutHandler method execute.

@Override
@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    if (bm.wIsSet("viewer") && ClipboardUtils.hasTextSeletion((IEntityPartViewer) bm.wGetValue("viewer"))) {
        HandlersBehavior.copy(bm);
        IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
        IEntity focusEntity = bm.wGet("focusEntity");
        ITextualEntityPart focusPart = (ITextualEntityPart) viewer.getEditPartRegistry().get(focusEntity);
        Command command = focusPart.getCommand(TextualRequest.createDeleteRequest());
        command.setLabel(getLabel(bm) + " text");
        CommandStack commandStack = viewer.getEditDomain().getCommandStack();
        commandStack.execute(command);
        return;
    }
    super.execute(bm);
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) Command(org.eclipse.gef.commands.Command) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 22 with ITextualEntityPart

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

the class AbstractModelTextAction method calculateEnabled.

protected boolean calculateEnabled(IBindingManager bm) {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    if (!Tools.TEXTUAL.isActive(viewer) || !(ModelObserver.getObserver(bm.wGet("focusEntity"), viewer.getEditPartRegistry()) instanceof ITextualEntityPart))
        return false;
    IEclipseContext context = (IEclipseContext) bm.wGetValue("eclipse#eclipseContext");
    ISynchronizableRunnable runnable = new FunctionRunnable(context, bm, getText(), getEnablementUri());
    IEntity result = runnable.syncExec(3000).getResult();
    return result != null && result.wBooleanValue();
}
Also used : ISynchronizableRunnable(org.whole.lang.e4.ui.jobs.ISynchronizableRunnable) ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) FunctionRunnable(org.whole.lang.e4.ui.jobs.FunctionRunnable) TextualFunctionRunnable(org.whole.lang.e4.ui.jobs.TextualFunctionRunnable) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 23 with ITextualEntityPart

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

the class ClipboardUtils method hasTextSeletion.

public static boolean hasTextSeletion(EditPartViewer viewer, ISelection selection) {
    List<EditPart> selectedParts = getSelectedEditParts(selection);
    if (selectedParts.size() != 1)
        return false;
    EditPart selectedPart = selectedParts.get(0);
    return Tools.TEXTUAL.isActive(viewer) && selectedPart instanceof ITextualEntityPart && ((ITextualEntityPart) selectedPart).hasSelectionRange();
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) RootEditPart(org.eclipse.gef.RootEditPart) EditPart(org.eclipse.gef.EditPart)

Example 24 with ITextualEntityPart

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

the class CaretUpdater method record.

public static CaretUpdater record(EditPartViewer viewer) {
    ITextualEntityPart focusPart = getFocusedTextualPart(viewer);
    if (focusPart == null)
        return NULL_UPDATER;
    int start, end;
    if (focusPart.hasSelectionRange()) {
        start = focusPart.getSelectionStart();
        end = focusPart.getSelectionEnd();
    } else
        start = end = focusPart.getCaretPosition();
    return createCU(viewer, focusPart.getModelEntity(), start, end);
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) Point(org.eclipse.draw2d.geometry.Point)

Example 25 with ITextualEntityPart

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

the class CaretUpdater method updateCaret.

@SuppressWarnings("unchecked")
private static void updateCaret(final EditPart entityPart, EditPartViewer viewer, int start, int end, Point location, boolean deselectAll) {
    if (entityPart instanceof ITextualEntityPart) {
        List<EditPart> selectedParts = viewer.getSelectedEditParts();
        if (deselectAll && !selectedParts.isEmpty())
            viewer.deselectAll();
        viewer.setFocus(entityPart);
        ITextualEntityPart caretPart = ((ITextualEntityPart) entityPart);
        if (start != -1 && end != -1) {
            caretPart.setCaretPosition(end);
            if (start != end) {
                caretPart.setSelectionRange(start, end);
                viewer.appendSelection(caretPart);
            }
        } else if (location != null)
            caretPart.updateCaret(location);
    }
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) EditPart(org.eclipse.gef.EditPart)

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