use of com.intellij.codeInsight.lookup.LookupElementPresentation in project intellij-plugins by JetBrains.
the class FlexCompletionTest method commonFlex3NamespaceInFlex4Context.
private void commonFlex3NamespaceInFlex4Context(final String namespaceToSelect, final String... otherExpectedNamespaces) throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".mxml");
complete();
final String[] expectedNamespaces = ArrayUtil.mergeArrays(new String[] { namespaceToSelect }, otherExpectedNamespaces);
assertEquals(expectedNamespaces.length, myItems.length);
final String[] namespaces = new String[myItems.length];
LookupElement selectedElement = null;
for (int i = 0; i < myItems.length; i++) {
final LookupElement lookupElement = myItems[i];
final LookupElementPresentation presentation = new LookupElementPresentation();
lookupElement.renderElement(presentation);
assertEquals("Accordion", presentation.getItemText());
final String namespace = presentation.getTypeText();
namespaces[i] = namespace;
if (namespace.equals(namespaceToSelect)) {
selectedElement = lookupElement;
}
}
assertSameElements(namespaces, expectedNamespaces);
assertNotNull(selectedElement);
selectItem(selectedElement, Lookup.REPLACE_SELECT_CHAR);
checkResultByFile(BASE_PATH + getTestName(false) + "_after.mxml");
}
use of com.intellij.codeInsight.lookup.LookupElementPresentation in project android by JetBrains.
the class AndroidLayoutDomTest method doTestTagNameIcons.
private void doTestTagNameIcons(String fileName) throws IOException {
VirtualFile file = copyFileToProject(fileName);
myFixture.configureFromExistingVirtualFile(file);
LookupElement[] elements = myFixture.complete(CompletionType.BASIC);
Set<String> elementsToCheck = new HashSet<>(Arrays.asList("view", "include", "requestFocus", "fragment", "Button"));
for (LookupElement element : elements) {
String s = element.getLookupString();
Object obj = element.getObject();
if (elementsToCheck.contains(s)) {
LookupElementPresentation presentation = new LookupElementPresentation();
element.renderElement(presentation);
assertNotNull("no icon for element: " + element, presentation.getIcon());
if ("Button".equals(s)) {
assertInstanceOf(obj, PsiClass.class);
}
}
}
}
use of com.intellij.codeInsight.lookup.LookupElementPresentation in project android by JetBrains.
the class AndroidLayoutDomTest method testDeprecatedAttributeNamesCompletion.
// Deprecated attributes should be crossed out in the completion
// This test specifically checks for "android:editable" attribute on TextView
public void testDeprecatedAttributeNamesCompletion() throws Throwable {
myFixture.configureFromExistingVirtualFile(copyFileToProject("text_view_editable.xml"));
myFixture.complete(CompletionType.BASIC);
// LookupElement that corresponds to "android:editable" attribute
LookupElement editableElement = null;
for (LookupElement element : myFixture.getLookupElements()) {
if ("android:editable".equals(element.getLookupString())) {
editableElement = element;
}
}
assertEquals("android:editable", editableElement.getLookupString());
LookupElementPresentation presentation = new LookupElementPresentation();
editableElement.renderElement(presentation);
assertTrue(presentation.isStrikeout());
}
use of com.intellij.codeInsight.lookup.LookupElementPresentation in project intellij-community by JetBrains.
the class LookupCellRenderer method getListCellRendererComponent.
@Override
public Component getListCellRendererComponent(final JList list, Object value, int index, boolean isSelected, boolean hasFocus) {
boolean nonFocusedSelection = isSelected && myLookup.getFocusDegree() == LookupImpl.FocusDegree.SEMI_FOCUSED;
if (!myLookup.isFocused()) {
isSelected = false;
}
myIsSelected = isSelected;
final LookupElement item = (LookupElement) value;
final Color foreground = getForegroundColor(isSelected);
final Color background = nonFocusedSelection ? SELECTED_NON_FOCUSED_BACKGROUND_COLOR : isSelected ? SELECTED_BACKGROUND_COLOR : BACKGROUND_COLOR;
int allowedWidth = list.getWidth() - calcSpacing(myNameComponent, myEmptyIcon) - calcSpacing(myTailComponent, null) - calcSpacing(myTypeLabel, null);
FontMetrics normalMetrics = getRealFontMetrics(item, false);
FontMetrics boldMetrics = getRealFontMetrics(item, true);
final LookupElementPresentation presentation = new RealLookupElementPresentation(isSelected ? getMaxWidth() : allowedWidth, normalMetrics, boldMetrics, myLookup);
AccessToken token = ReadAction.start();
try {
if (item.isValid()) {
try {
item.renderElement(presentation);
} catch (ProcessCanceledException e) {
LOG.info(e);
presentation.setItemTextForeground(JBColor.RED);
presentation.setItemText("Error occurred, see the log in Help | Show Log");
} catch (Exception | Error e) {
LOG.error(e);
}
} else {
presentation.setItemTextForeground(JBColor.RED);
presentation.setItemText("Invalid");
}
} finally {
token.finish();
}
myNameComponent.clear();
myNameComponent.setBackground(background);
allowedWidth -= setItemTextLabel(item, new JBColor(isSelected ? SELECTED_FOREGROUND_COLOR : presentation.getItemTextForeground(), presentation.getItemTextForeground()), isSelected, presentation, allowedWidth);
Font font = myLookup.getCustomFont(item, false);
if (font == null) {
font = myNormalFont;
}
myTailComponent.setFont(font);
myTypeLabel.setFont(font);
myNameComponent.setIcon(augmentIcon(myLookup.getEditor(), presentation.getIcon(), myEmptyIcon));
myTypeLabel.clear();
if (allowedWidth > 0) {
allowedWidth -= setTypeTextLabel(item, background, foreground, presentation, isSelected ? getMaxWidth() : allowedWidth, isSelected, nonFocusedSelection, normalMetrics);
}
myTailComponent.clear();
myTailComponent.setBackground(background);
if (isSelected || allowedWidth >= 0) {
setTailTextLabel(isSelected, presentation, foreground, isSelected ? getMaxWidth() : allowedWidth, nonFocusedSelection, normalMetrics);
}
if (mySelected.containsKey(index)) {
if (!isSelected && mySelected.get(index)) {
myPanel.setUpdateExtender(true);
}
}
mySelected.put(index, isSelected);
final double w = myNameComponent.getPreferredSize().getWidth() + myTailComponent.getPreferredSize().getWidth() + myTypeLabel.getPreferredSize().getWidth();
boolean useBoxLayout = isSelected && w > list.getWidth() && ((JBList) list).getExpandableItemsHandler().isEnabled();
if (useBoxLayout != myPanel.getLayout() instanceof BoxLayout) {
myPanel.removeAll();
if (useBoxLayout) {
myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.X_AXIS));
myPanel.add(myNameComponent);
myPanel.add(myTailComponent);
myPanel.add(myTypeLabel);
} else {
myPanel.setLayout(new BorderLayout());
myPanel.add(myNameComponent, BorderLayout.WEST);
myPanel.add(myTailComponent, BorderLayout.CENTER);
myPanel.add(myTypeLabel, BorderLayout.EAST);
}
}
AccessibleContextUtil.setCombinedName(myPanel, myNameComponent, "", myTailComponent, " - ", myTypeLabel);
AccessibleContextUtil.setCombinedDescription(myPanel, myNameComponent, "", myTailComponent, " - ", myTypeLabel);
return myPanel;
}
use of com.intellij.codeInsight.lookup.LookupElementPresentation in project intellij-community by JetBrains.
the class SecondSmartTypeCompletionTest method testEmptyMapPresentation.
public void testEmptyMapPresentation() {
configure();
LookupElementPresentation presentation = new LookupElementPresentation();
myItems[0].renderElement(presentation);
assertEquals("Collections.<String, S...>emptyMap", presentation.getItemText());
}
Aggregations