use of org.whole.lang.ui.editparts.ITextualEntityPart in project whole by wholeplatform.
the class BackspaceTextCommand method execute.
public void execute() {
ITextualEntityPart caretPart = getSourcePart();
int end = caretPart.getCaretPosition();
int start = end - length;
this.initialRange = new Range(start, end);
String value = DataTypeUtils.getAsPresentationString(entity);
value = value.substring(0, start) + value.substring(end);
this.finalRange = new Range(start, start);
setNewValue(DataTypeUtils.getDataTypeParser(entity, DataTypeParsers.PRESENTATION).parse(entity.wGetEntityDescriptor(), value));
CaretUpdater.createCU(getViewer(), entity, start).sheduleSyncUpdate();
super.execute();
}
use of org.whole.lang.ui.editparts.ITextualEntityPart in project whole by wholeplatform.
the class OverwriteTextCommand method execute.
public void execute() {
ITextualEntityPart caretPart = getSourcePart();
int start = caretPart.getCaretPosition();
int end = start + length;
this.initialRange = new Range(start, end);
String value = DataTypeUtils.getAsPresentationString(entity);
value = value.substring(0, start) + data + value.substring(end);
this.finalRange = new Range(start, end);
setNewValue(DataTypeUtils.getDataTypeParser(entity, DataTypeParsers.PRESENTATION).parse(entity.wGetEntityDescriptor(), value));
CaretUpdater.createCU(getViewer(), entity, end).sheduleSyncUpdate();
super.execute();
}
use of org.whole.lang.ui.editparts.ITextualEntityPart in project whole by wholeplatform.
the class DeleteTextCommand method execute.
public void execute() {
ITextualEntityPart caretPart = getSourcePart();
int start = caretPart.getCaretPosition();
int end = start + length;
this.initialRange = new Range(start, end);
String value = DataTypeUtils.getAsPresentationString(entity);
value = value.substring(0, start) + value.substring(end);
this.finalRange = new Range(start, start);
setNewValue(DataTypeUtils.getDataTypeParser(entity, DataTypeParsers.PRESENTATION).parse(entity.wGetEntityDescriptor(), value));
CaretUpdater.createCU(getViewer(), entity, start).sheduleSyncUpdate();
super.execute();
}
use of org.whole.lang.ui.editparts.ITextualEntityPart 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.editparts.ITextualEntityPart in project whole by wholeplatform.
the class CaretUtils method getCaretPositions.
public static int getCaretPositions(IEntityPartViewer viewer, IEntity entity) {
IEntityPart entityPart = viewer.getEditPartRegistry().get(entity);
if (!(entityPart instanceof ITextualEntityPart))
throw new IllegalArgumentException("the entity part is not textual");
ITextualEntityPart targetPart = (ITextualEntityPart) entityPart;
return targetPart.getCaretPositions();
}
Aggregations