use of org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedDataImpl in project che by eclipse.
the class LinkedCorrectionProposal method performChange.
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.text.correction.ChangeCorrectionProposal#performChange(org.eclipse.jface.text.IDocument, org.eclipse.ui.IEditorPart)
*/
@Override
protected void performChange(/*IEditorPart part,*/
IDocument document) throws CoreException {
// try {
super.performChange(/*part,*/
document);
//
if (fLinkedProposalModel != null) {
if (fLinkedProposalModel.hasLinkedPositions()) {
// enter linked mode
// ITextViewer viewer= ((JavaEditor) part).getViewer();
// new LinkedProposalModelPresenter().enterLinkedMode(viewer, part, didOpenEditor(), fLinkedProposalModel);
boolean added = false;
LinkedModeModelImpl model = new LinkedModeModelImpl();
Iterator<LinkedProposalPositionGroup> iterator = fLinkedProposalModel.getPositionGroupIterator();
while (iterator.hasNext()) {
LinkedProposalPositionGroup curr = iterator.next();
LinkedPositionGroupImpl group = new LinkedPositionGroupImpl();
LinkedProposalPositionGroup.PositionInformation[] positions = curr.getPositions();
if (positions.length > 0) {
LinkedProposalPositionGroup.Proposal[] linkedModeProposals = curr.getProposals();
if (linkedModeProposals.length <= 1) {
for (int i = 0; i < positions.length; i++) {
LinkedProposalPositionGroup.PositionInformation pos = positions[i];
if (pos.getOffset() != -1) {
RegionImpl position = new RegionImpl();
position.setOffset(pos.getOffset());
position.setLength(pos.getLength());
// group.addPositions(
// new LinkedPosition(document, pos.getOffset(), pos.getLength(), pos.getSequenceRank()));
group.addPositions(position);
}
}
} else {
// LinkedPositionProposalImpl[] proposalImpls= new LinkedPositionProposalImpl[linkedModeProposals.length];
LinkedDataImpl data = new LinkedDataImpl();
for (int i = 0; i < linkedModeProposals.length; i++) {
// proposalImpls[i] = new LinkedPositionProposalImpl(linkedModeProposals[i], model);
data.addValues(linkedModeProposals[i].getDisplayString());
}
group.setData(data);
for (int i = 0; i < positions.length; i++) {
LinkedProposalPositionGroup.PositionInformation pos = positions[i];
if (pos.getOffset() != -1) {
// group.addPosition(
// new ProposalPosition(document, pos.getOffset(), pos.getLength(), pos.getSequenceRank(),
// proposalImpls));
RegionImpl position = new RegionImpl();
position.setOffset(pos.getOffset());
position.setLength(pos.getLength());
group.addPositions(position);
}
}
}
model.addGroups(group);
added = true;
}
}
if (added) {
LinkedProposalPositionGroup.PositionInformation endPosition = fLinkedProposalModel.getEndPosition();
if (endPosition != null && endPosition.getOffset() != -1) {
model.setEscapePosition(endPosition.getOffset() + endPosition.getLength());
}
this.linkedModel = model;
}
}
// else if (part instanceof ITextEditor) {
// LinkedProposalPositionGroup.PositionInformation endPosition= fLinkedProposalModel.getEndPosition();
// if (endPosition != null) {
// // select a result
// int pos= endPosition.getOffset() + endPosition.getLength();
// ((ITextEditor) part).selectAndReveal(pos, 0);
// }
// }
}
// } catch (BadLocationException e) {
// throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e));
// }
}
use of org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedDataImpl in project che by eclipse.
the class TemplateProposal method apply.
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, char, int, int)
*/
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
IDocument document = viewer.getDocument();
try {
fContext.setReadOnly(false);
int start;
TemplateBuffer templateBuffer;
try {
beginCompoundChange(viewer);
int oldReplaceOffset = getReplaceOffset();
try {
// this may already modify the document (e.g. add imports)
templateBuffer = fContext.evaluate(fTemplate);
} catch (TemplateException e1) {
fSelectedRegion = fRegion;
return;
}
start = getReplaceOffset();
int shift = start - oldReplaceOffset;
int end = Math.max(getReplaceEndOffset(), offset + shift);
// insert template string
if (end > document.getLength())
end = offset;
String templateString = templateBuffer.getString();
document.replace(start, end - start, templateString);
} finally {
endCompoundChange(viewer);
}
// translate positions
LinkedModeModelImpl model = new LinkedModeModelImpl();
TemplateVariable[] variables = templateBuffer.getVariables();
MultiVariableGuess guess = fContext instanceof CompilationUnitContext ? ((CompilationUnitContext) fContext).getMultiVariableGuess() : null;
boolean hasPositions = false;
for (int i = 0; i != variables.length; i++) {
TemplateVariable variable = variables[i];
if (variable.isUnambiguous())
continue;
LinkedPositionGroupImpl group = new LinkedPositionGroupImpl();
int[] offsets = variable.getOffsets();
int length = variable.getLength();
LinkedPosition first;
if (guess != null && variable instanceof MultiVariable) {
first = new VariablePosition(document, offsets[0] + start, length, guess, (MultiVariable) variable);
guess.addSlave((VariablePosition) first);
} else {
String[] values = variable.getValues();
ICompletionProposal[] proposals = new ICompletionProposal[values.length];
for (int j = 0; j < values.length; j++) {
// ensurePositionCategoryInstalled(document, model);
Position pos = new Position(offsets[0] + start, length);
// document.addPosition(getCategory(), pos);
proposals[j] = new PositionBasedCompletionProposal(values[j], pos, length);
}
if (proposals.length > 1)
first = new ProposalPosition(document, offsets[0] + start, length, proposals);
else
first = new LinkedPosition(document, offsets[0] + start, length);
}
for (int j = 0; j != offsets.length; j++) if (j == 0) {
if (first instanceof ProposalPosition) {
RegionImpl region = new RegionImpl();
region.setLength(first.getLength());
region.setOffset(first.getOffset());
LinkedDataImpl data = new LinkedDataImpl();
ICompletionProposal[] choices = ((ProposalPosition) first).getChoices();
if (choices != null) {
for (ICompletionProposal choice : choices) {
data.addValues(choice.getDisplayString());
}
group.setData(data);
}
group.addPositions(region);
} else {
RegionImpl region = new RegionImpl();
region.setLength(first.getLength());
region.setOffset(first.getOffset());
group.addPositions(region);
}
} else {
RegionImpl region = new RegionImpl();
region.setLength(length);
region.setOffset(offsets[j] + start);
group.addPositions(region);
}
model.addGroups(group);
hasPositions = true;
}
if (hasPositions) {
model.setEscapePosition(getCaretOffset(templateBuffer) + start);
this.linkedModeModel = model;
// model.forceInstall();
// JavaEditor editor= getJavaEditor();
// if (editor != null) {
// model.addLinkingListener(new EditorHighlightingSynchronizer(editor));
// }
//
// LinkedModeUI ui= new EditorLinkedModeUI(model, viewer);
// ui.setExitPosition(viewer, getCaretOffset(templateBuffer) + start, 0, Integer.MAX_VALUE);
// ui.enter();
//ui.getSelectedRegion();
fSelectedRegion = fRegion;
} else {
fSelectedRegion = new Region(getCaretOffset(templateBuffer) + start, 0);
}
} catch (BadLocationException e) {
JavaPlugin.log(e);
// openErrorDialog(viewer.getTextWidget().getShell(), e);
fSelectedRegion = fRegion;
}
}
use of org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedDataImpl in project che by eclipse.
the class ParameterGuessingProposal method apply.
/*
* @see ICompletionProposalExtension#apply(IDocument, char)
*/
@Override
public void apply(final IDocument document, char trigger, int offset) {
super.apply(document, trigger, offset);
int baseOffset = getReplacementOffset();
String replacement = getReplacementString();
if (fPositions != null && getTextViewer() != null) {
LinkedModeModelImpl model = new LinkedModeModelImpl();
for (int i = 0; i < fPositions.length; i++) {
LinkedPositionGroupImpl group = new LinkedPositionGroupImpl();
int positionOffset = fPositions[i].getOffset();
int positionLength = fPositions[i].getLength();
if (fChoices[i].length < 2) {
RegionImpl region = new RegionImpl();
region.setOffset(positionOffset);
region.setLength(positionLength);
// group.addPositions(new LinkedPosition(document, positionOffset, positionLength, LinkedPositionGroup.NO_STOP));
group.addPositions(region);
} else {
// ensurePositionCategoryInstalled(document, model);
// document.addPosition(getCategory(), fPositions[i]);
RegionImpl region = new RegionImpl();
region.setOffset(positionOffset);
region.setLength(positionLength);
// group.addPositions(
// new ProposalPosition(document, positionOffset, positionLength, LinkedPositionGroup.NO_STOP, fChoices[i]));
group.addPositions(region);
LinkedDataImpl data = new LinkedDataImpl();
for (ICompletionProposal proposal : fChoices[i]) {
data.addValues(proposal.getDisplayString());
}
group.setData(data);
}
model.addGroups(group);
}
model.setEscapePosition(baseOffset + replacement.length());
this.linkedModel = model;
// model.forceInstall();
// JavaEditor editor = getJavaEditor();
// if (editor != null) {
// model.addLinkingListener(new EditorHighlightingSynchronizer(editor));
// }
// LinkedModeUI ui = new EditorLinkedModeUI(model, getTextViewer());
// ui.setExitPosition(getTextViewer(), baseOffset + replacement.length(), 0, Integer.MAX_VALUE);
// // exit character can be either ')' or ';'
// final char exitChar = replacement.charAt(replacement.length() - 1);
// ui.setExitPolicy(new ExitPolicy(exitChar, document) {
// @Override
// public ExitFlags doExit(LinkedModeModel model2, VerifyEvent event, int offset2, int length) {
// if (event.character == ',') {
// for (int i = 0; i < fPositions.length - 1; i++) { // not for the last one
// Position position = fPositions[i];
// if (position.offset <= offset2 && offset2 + length <= position.offset + position.length) {
// try {
// ITypedRegion partition = TextUtilities
// .getPartition(document, IJavaPartitions.JAVA_PARTITIONING, offset2 + length, false);
// if (IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
// || offset2 + length == partition.getOffset() + partition.getLength()) {
// event.character = '\t';
// event.keyCode = SWT.TAB;
// return null;
// }
// } catch (BadLocationException e) {
// // continue; not serious enough to log
// }
// }
// }
// } else if (event.character == ')' && exitChar != ')') {
// // exit from link mode when user is in the last ')' position.
// Position position = fPositions[fPositions.length - 1];
// if (position.offset <= offset2 && offset2 + length <= position.offset + position.length) {
// return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
// }
// }
// return super.doExit(model2, event, offset2, length);
// }
// });
// ui.setCyclingMode(LinkedModeUI.CYCLE_WHEN_NO_PARENT);
// ui.setDoContextInfo(true);
// ui.enter();
fSelectedRegion = new Region(baseOffset + replacement.length(), 0);
} else {
fSelectedRegion = new Region(baseOffset + replacement.length(), 0);
}
}
Aggregations