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