use of org.jboss.ide.eclipse.freemarker.model.Item in project liferay-ide by liferay.
the class OutlinePage method doubleClick.
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
Item item = (Item) selection.getFirstElement();
if (null != item) {
fEditor.select(item);
}
}
use of org.jboss.ide.eclipse.freemarker.model.Item in project liferay-ide by liferay.
the class CompletionProcessor method computeCompletionProposals.
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
try {
ItemSet directiveSet = editor.getItemSet();
Map context = new HashMap();
ContextValue[] values = ConfigurationManager.getInstance(editor.getProject()).getContextValues(editor.getFile(), true);
for (int i = 0; i < values.length; i++) {
context.put(values[i].name, values[i].objClass);
}
Item directive = directiveSet.getSelectedItem(offset);
if (null != directive) {
return directive.getCompletionProposals(offset, context);
} else {
// we might be starting something
Item item = editor.getItemSet().getPreviousItem(offset);
int topOffset = 0;
if (null != item)
topOffset = item.getRegion().getOffset() + item.getRegion().getLength();
// check for directives and macro calls
try {
for (int i = offset - 1; i >= topOffset; i--) {
char c = editor.getDocument().getChar(i);
if (c == '>' || c == ']')
break;
if (c == '<' || c == '[') {
if (editor.getDocument().getLength() > i) {
char c2 = editor.getDocument().getChar(i + 1);
if (c2 == '#') {
CompletionDirective completionDirective = new CompletionDirective(i, offset - i, editor.getItemSet(), (ISourceViewer) viewer, (IResource) editor.getFile());
completionDirective.setItemSet(editor.getItemSet());
return completionDirective.getCompletionProposals(offset, context);
} else if (c2 == '@') {
CompletionMacroInstance completionMacroInstance = new CompletionMacroInstance(editor.getDocument().get(i, offset - i), i, editor.getItemSet(), editor.getFile());
completionMacroInstance.setItemSet(editor.getItemSet());
return completionMacroInstance.getCompletionProposals(offset, context);
} else if (c2 == '/') {
if (editor.getDocument().getLength() < i + 3 || editor.getDocument().getChar(i + 2) == ' ' || editor.getDocument().getChar(i + 2) == '\r' || editor.getDocument().getChar(i + 2) == '\n') {
Item stackItem = editor.getItemSet().getPreviousStartItem(offset);
StringBuffer value = new StringBuffer();
if (null != stackItem && stackItem instanceof MacroInstance)
// $NON-NLS-1$
value.append("@");
else
// $NON-NLS-1$
value.append("#");
String name = null;
if (null != stackItem)
name = stackItem.getFirstToken();
if (null != name)
value.append(name);
if (c == '<')
value.append('>');
else
value.append(']');
ICompletionProposal completionProposal = new CompletionProposal(value.toString(), offset, 0, offset + value.toString().length());
return new ICompletionProposal[] { completionProposal };
}
} else {
return NO_COMPLETIONS;
}
}
}
}
} catch (BadLocationException e) {
return NO_COMPLETIONS;
}
// check for interpolations
try {
for (int i = offset - 1; i >= topOffset; i--) {
char c = editor.getDocument().getChar(i);
if (c == '\n')
break;
else if (c == '$') {
if (editor.getDocument().getLength() > i) {
char c2 = editor.getDocument().getChar(i + 1);
if (c2 == '{') {
int j = offset;
while (editor.getDocument().getLength() > j) {
char c3 = editor.getDocument().getChar(j);
if (Character.isWhitespace(c3) || c3 == '(' || c3 == '.' || c3 == ')' || c3 == '}' || c3 == '?') {
// j = j-1;
break;
}
j++;
}
CompletionInterpolation interpolation = new CompletionInterpolation(editor.getDocument().get(i, j - i), i, editor.getItemSet(), editor.getFile());
interpolation.setParentItem(editor.getItemSet().getPreviousStartItem(offset));
return interpolation.getCompletionProposals(offset, context);
}
}
}
}
} catch (BadLocationException e) {
return NO_COMPLETIONS;
}
}
} catch (Exception e) {
Plugin.log(e);
}
return NO_COMPLETIONS;
}
use of org.jboss.ide.eclipse.freemarker.model.Item in project liferay-ide by liferay.
the class Editor method handleCursorPositionChanged.
protected void handleCursorPositionChanged() {
super.handleCursorPositionChanged();
if (!mouseDown) {
int offset = getCaretOffset();
Item item = getItemSet().getSelectedItem(offset);
if (null == item && offset > 0)
item = getItemSet().getSelectedItem(offset - 1);
if (Plugin.getInstance().getPreferenceStore().getBoolean(Constants.HIGHLIGHT_RELATED_ITEMS)) {
if (null != item && null != item.getRelatedItems() && item.getRelatedItems().length > 0) {
highlightRelatedRegions(item.getRelatedItems(), item);
} else {
highlightRelatedRegions(null, item);
}
}
if (null == item) {
item = getItemSet().getContextItem(getCaretOffset());
}
if (null != fOutlinePage)
fOutlinePage.update(item);
}
}
use of org.jboss.ide.eclipse.freemarker.model.Item in project liferay-ide by liferay.
the class Editor method getSelectedItem.
public Item getSelectedItem(boolean allowFudge) {
int caretOffset = getCaretOffset();
Item item = getItemSet().getSelectedItem(getCaretOffset());
if (null == item && caretOffset > 0)
item = getItemSet().getSelectedItem(caretOffset - 1);
return item;
}
use of org.jboss.ide.eclipse.freemarker.model.Item in project liferay-ide by liferay.
the class Editor method keyReleased.
public void keyReleased(KeyEvent e) {
if (e.keyCode == SWT.CTRL) {
ctrlDown = false;
} else if (e.keyCode == SWT.SHIFT) {
shiftDown = false;
}
try {
if (shiftDown && (e.keyCode == '3' || e.keyCode == '2')) {
int offset = getCaretOffset();
char c = getSourceViewer().getDocument().getChar(offset - 2);
if (c == '[' || c == '<') {
// directive
char endChar = Character.MIN_VALUE;
if (c == '[')
endChar = ']';
else
endChar = '>';
if (getSourceViewer().getDocument().getLength() > offset) {
if (offset > 0) {
for (int i = offset + 1; i < getSourceViewer().getDocument().getLength(); i++) {
char c2 = getSourceViewer().getDocument().getChar(i);
if (i == endChar)
return;
else if (i == '\n')
break;
}
getSourceViewer().getDocument().replace(offset, 0, new String(new char[] { endChar }));
}
} else {
getSourceViewer().getDocument().replace(offset, 0, new String(new char[] { endChar }));
}
}
} else if (shiftDown && e.keyCode == '[') {
int offset = getCaretOffset();
char c = getSourceViewer().getDocument().getChar(offset - 2);
if (c == '$') {
// interpolation
if (getSourceViewer().getDocument().getLength() > offset) {
if (offset > 0) {
for (int i = offset + 1; i < getSourceViewer().getDocument().getLength(); i++) {
char c2 = getSourceViewer().getDocument().getChar(i);
if (i == '}')
return;
else if (i == '\n')
break;
}
// $NON-NLS-1$
getSourceViewer().getDocument().replace(offset, 0, "}");
}
} else {
// $NON-NLS-1$
getSourceViewer().getDocument().replace(offset, 0, "}");
}
}
}
} catch (BadLocationException exc) {
// do nothing
}
boolean stale = false;
if (e.keyCode == SWT.DEL || e.keyCode == SWT.BS) {
stale = true;
} else if (null != getSelectedItem(true)) {
stale = true;
} else {
char c = (char) e.keyCode;
for (int j = 0; j < VALIDATION_TOKENS.length; j++) {
if (c == VALIDATION_TOKENS[j]) {
stale = true;
break;
}
}
if (ctrlDown && (e.keyCode == 'v' || e.keyCode == 'x')) {
stale = true;
}
}
if (stale) {
int offset = getCaretOffset();
Item item = getItemSet().getSelectedItem(offset);
if (null == item && offset > 0)
item = getItemSet().getSelectedItem(offset - 1);
if (Plugin.getInstance().getPreferenceStore().getBoolean(Constants.HIGHLIGHT_RELATED_ITEMS)) {
if (null != item && null != item.getRelatedItems() && item.getRelatedItems().length > 0) {
highlightRelatedRegions(item.getRelatedItems(), item);
} else {
highlightRelatedRegions(null, item);
}
}
clearCache();
validateContents();
if (null != fOutlinePage)
fOutlinePage.update(getSelectedItem());
}
}
Aggregations