use of org.whole.lang.ui.tools.EditPoint in project whole by wholeplatform.
the class TextualKeyHandler method calculateDoubleClickSelection.
public IWholeSelection calculateDoubleClickSelection(EditPoint editPoint) {
ITextualEntityPart targetPart = (ITextualEntityPart) editPoint.focus;
IEntity targetEntity = targetPart.getModelEntity();
int endPosition = -1, startPosition = -1;
if (enableSmartSelection(targetEntity)) {
String text = targetEntity.wStringValue();
int position = targetPart.getCaretPosition();
int positions = targetPart.getCaretPositions();
Matcher matcher;
if (position == 0) {
matcher = RIGHT_PATTERN.matcher(text);
if (matcher.find()) {
startPosition = 0;
endPosition = matcher.end();
}
} else if (position == positions) {
matcher = LEFT_PATTERN.matcher(text);
if (matcher.find()) {
startPosition = matcher.start();
endPosition = positions;
}
} else {
if (Character.isLetterOrDigit(text.charAt(position))) {
if (Character.isLetterOrDigit(text.charAt(position - 1))) {
// XX
String substring = text.substring(0, position);
matcher = LEFT_PATTERN.matcher(substring);
if (matcher.find())
startPosition = matcher.start();
matcher = RIGHT_PATTERN.matcher(text.substring(position));
if (matcher.find())
endPosition = position + matcher.end();
} else {
// .X
matcher = RIGHT_PATTERN.matcher(text.substring(position));
if (matcher.find()) {
startPosition = position + matcher.start();
endPosition = position + matcher.end();
}
}
} else {
if (Character.isLetterOrDigit(text.charAt(position - 1))) {
// X.
matcher = LEFT_PATTERN.matcher(text.substring(0, position));
if (matcher.find()) {
startPosition = matcher.start();
endPosition = position;
}
} else {
// ..
startPosition = position - 1;
endPosition = position;
}
}
}
}
if (endPosition >= 0 && startPosition >= 0)
return new SelectionRange(editPoint.focus, startPosition, endPosition);
else
return super.calculateDoubleClickSelection(editPoint);
}
use of org.whole.lang.ui.tools.EditPoint in project whole by wholeplatform.
the class E4NavigationKeyHandler method getEditPoint.
public EditPoint getEditPoint() {
if (editPoint == null)
editPoint = new EditPoint((IEntityPart) getFocusEntityPart(), 0);
else {
IEntityPart focusPart = (IEntityPart) getFocusEntityPart();
if (editPoint.focus != focusPart) {
editPoint.focus = focusPart;
editPoint.caret = 0;
}
}
return editPoint;
}
use of org.whole.lang.ui.tools.EditPoint in project whole by wholeplatform.
the class E4NavigationKeyHandler method navigateView.
public boolean navigateView(KeyEvent event, int direction) {
EditPoint focusPoint = getEditPoint();
IGEFEditorKit editorKit = (IGEFEditorKit) focusPoint.focus.getModelEntity().wGetEditorKit();
IKeyHandler keyHandler = editorKit.getKeyHandler();
// FIXME workaround for a bug in navigation actions
if (focusPoint.focus instanceof ITextualEntityPart) {
ITextualEntityPart part = (ITextualEntityPart) focusPoint.focus;
int start = part.getSelectionStart();
int end = part.getSelectionEnd();
if (start != -1 && end != -1) {
CaretUpdater.sheduleSyncUpdate(part.getViewer(), part.getModelTextEntity(), direction == PositionConstants.WEST ? start : end, true);
return true;
} else {
CaretUpdater.sheduleSyncUpdate(part.getViewer(), part.getModelTextEntity(), part.getCaretPosition(), true);
}
}
editPoint = keyHandler.findNeighbour(this, focusPoint, direction);
if (editPoint == null)
return navigateNextSibling(event, direction);
navigateTo(editPoint.focus, event);
return true;
}
use of org.whole.lang.ui.tools.EditPoint in project whole by wholeplatform.
the class GrammarsKeyHandler method findNeighbour.
public EditPoint findNeighbour(IEditPointProvider editPointProvider, EditPoint editPoint, int direction) {
int caret = editPoint.caret;
IEntityPart focusPart = editPoint.focus;
IEntity focusEntity = focusPart.getModelEntity();
switch(focusEntity.wGetEntityOrd()) {
case GrammarsEntityDescriptorEnum.DataTerminal_ord:
case GrammarsEntityDescriptorEnum.LiteralTerminal_ord:
case GrammarsEntityDescriptorEnum.As_ord:
switch(direction) {
case NORTH:
switch(caret) {
case 0:
case 1:
return findInParent(editPointProvider, editPoint, focusEntity, direction);
case 2:
case 3:
return editPoint.caret(caret - 2);
}
case SOUTH:
switch(caret) {
case 2:
case 3:
return findInParent(editPointProvider, editPoint, focusEntity, direction);
case 0:
case 1:
return editPoint.caret(caret + 2);
}
case EAST:
switch(caret) {
case 0:
return findInChild(editPointProvider, editPoint, focusEntity.wGet(0), direction);
case 2:
return findInChild(editPointProvider, editPoint, focusEntity.wGet(1), direction);
case 1:
case 3:
return findInParent(editPointProvider, editPoint, focusEntity, direction);
}
case WEST:
switch(caret) {
case 1:
return findInChild(editPointProvider, editPoint, focusEntity.wGet(0), direction);
case 3:
return findInChild(editPointProvider, editPoint, focusEntity.wGet(1), direction);
case 0:
case 2:
return findInParent(editPointProvider, editPoint, focusEntity, direction);
}
}
}
return null;
}
use of org.whole.lang.ui.tools.EditPoint in project whole by wholeplatform.
the class E4NavigationKeyHandler method navigateModel.
public boolean navigateModel(KeyEvent event, int direction) {
EditPoint focusPoint = getEditPoint();
if (!(focusPoint.focus.getParent() instanceof IEntityPart))
return false;
switch(direction) {
case NORTH:
IEntityPart parentPart = (IEntityPart) focusPoint.focus.getParent();
if (isRootPart(parentPart))
return false;
editPoint.focus = parentPart;
break;
case SOUTH:
List<?> children = focusPoint.focus.getChildren();
if (children.isEmpty())
return false;
editPoint.focus = (IEntityPart) children.get(0);
break;
case EAST:
parentPart = (IEntityPart) focusPoint.focus.getParent();
if (isRootPart(parentPart))
return false;
List<?> siblings = parentPart.getChildren();
int index = siblings.indexOf(editPoint.focus);
if (index < siblings.size() - 1)
editPoint.focus = findModelFirstChild((IEntityPart) siblings.get(index + 1));
else
editPoint.focus = parentPart;
break;
case WEST:
parentPart = (IEntityPart) focusPoint.focus.getParent();
if (isRootPart(parentPart))
return false;
siblings = parentPart.getChildren();
index = siblings.indexOf(editPoint.focus);
if (index > 0)
editPoint.focus = findModelLastChild((IEntityPart) siblings.get(index - 1));
else
editPoint.focus = parentPart;
break;
}
editPoint.caret = 0;
navigateTo(editPoint.focus, event);
return true;
}
Aggregations