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;
}
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()) : "";
}
});
}
}
}
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);
}
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);
}
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;
}
Aggregations