use of com.intellij.util.xml.DomFileElement in project intellij-community by JetBrains.
the class BasicDomElementComponent method bindProperties.
protected final void bindProperties(final DomElement domElement) {
if (domElement == null)
return;
DomElementAnnotationsManager.getInstance(domElement.getManager().getProject()).addHighlightingListener(new DomElementAnnotationsManager.DomHighlightingListener() {
@Override
public void highlightingFinished(@NotNull final DomFileElement element) {
ApplicationManager.getApplication().invokeLater(() -> {
if (getComponent().isShowing() && element.isValid()) {
updateHighlighting();
}
});
}
}, this);
for (final AbstractDomChildrenDescription description : domElement.getGenericInfo().getChildrenDescriptions()) {
final JComponent boundComponent = getBoundComponent(description);
if (boundComponent != null) {
if (description instanceof DomFixedChildDescription && DomUtil.isGenericValueType(description.getType())) {
if ((description.getValues(domElement)).size() == 1) {
final GenericDomValue element = domElement.getManager().createStableValue(() -> domElement.isValid() ? (GenericDomValue) description.getValues(domElement).get(0) : null);
doBind(DomUIFactory.createControl(element, commitOnEveryChange(element)), boundComponent);
} else {
//todo not bound
}
} else if (description instanceof DomCollectionChildDescription) {
doBind(DomUIFactory.getDomUIFactory().createCollectionControl(domElement, (DomCollectionChildDescription) description), boundComponent);
}
}
}
reset();
}
use of com.intellij.util.xml.DomFileElement in project intellij-community by JetBrains.
the class MavenModulePsiReference method getVariants.
@NotNull
public Object[] getVariants() {
List<DomFileElement<MavenDomProjectModel>> files = MavenDomUtil.collectProjectModels(getProject());
List<Object> result = new ArrayList<>();
for (DomFileElement<MavenDomProjectModel> eachDomFile : files) {
VirtualFile eachVFile = eachDomFile.getOriginalFile().getVirtualFile();
if (Comparing.equal(eachVFile, myVirtualFile))
continue;
PsiFile psiFile = eachDomFile.getFile();
String modulePath = calcRelativeModulePath(myVirtualFile, eachVFile);
result.add(LookupElementBuilder.create(psiFile, modulePath).withPresentableText(modulePath));
}
return result.toArray();
}
use of com.intellij.util.xml.DomFileElement in project intellij-community by JetBrains.
the class PluginDescriptorChooser method show.
public static void show(final Project project, final Editor editor, final PsiFile file, final Consumer<DomFileElement<IdeaPlugin>> consumer) {
final Module module = ModuleUtilCore.findModuleForPsiElement(file);
assert module != null;
List<DomFileElement<IdeaPlugin>> elements = DomService.getInstance().getFileElements(IdeaPlugin.class, project, module.getModuleWithDependentsScope());
elements = ContainerUtil.filter(elements, element -> {
VirtualFile virtualFile = element.getFile().getVirtualFile();
return virtualFile != null && ProjectRootManager.getInstance(project).getFileIndex().isInContent(virtualFile);
});
elements = findAppropriateIntelliJModule(module.getName(), elements);
if (elements.isEmpty()) {
HintManager.getInstance().showErrorHint(editor, "Cannot find plugin descriptor");
return;
}
if (elements.size() == 1) {
consumer.consume(elements.get(0));
return;
}
final BaseListPopupStep<PluginDescriptorCandidate> popupStep = new BaseListPopupStep<PluginDescriptorCandidate>("Choose Plugin Descriptor", createCandidates(module, elements)) {
@Override
public boolean isSpeedSearchEnabled() {
return true;
}
@Override
public Icon getIconFor(PluginDescriptorCandidate candidate) {
return candidate.getIcon();
}
@NotNull
@Override
public String getTextFor(PluginDescriptorCandidate candidate) {
return candidate.getText();
}
@Nullable
@Override
public ListSeparator getSeparatorAbove(PluginDescriptorCandidate candidate) {
final String separatorText = candidate.getSeparatorText();
if (separatorText != null) {
return new ListSeparator(separatorText);
}
return null;
}
@Override
public PopupStep onChosen(PluginDescriptorCandidate selectedValue, boolean finalChoice) {
consumer.consume(selectedValue.myDomFileElement);
return FINAL_CHOICE;
}
};
JBPopupFactory.getInstance().createListPopup(popupStep).showInBestPositionFor(editor);
}
use of com.intellij.util.xml.DomFileElement in project intellij-community by JetBrains.
the class PluginDescriptorChooser method createCandidates.
private static List<PluginDescriptorCandidate> createCandidates(final Module currentModule, List<DomFileElement<IdeaPlugin>> elements) {
ModuleGrouper grouper = ModuleGrouper.instanceFor(currentModule.getProject());
final List<String> groupPath = grouper.getGroupPath(currentModule);
elements.sort((o1, o2) -> {
// current module = first group
final Module module1 = o1.getModule();
final Module module2 = o2.getModule();
if (currentModule.equals(module1))
return -1;
if (currentModule.equals(module2))
return 1;
if (module1 != null && module2 != null) {
int groupComparison = Comparing.compare(groupMatchLevel(groupPath, grouper.getGroupPath(module2)), groupMatchLevel(groupPath, grouper.getGroupPath(module1)));
if (groupComparison != 0) {
return groupComparison;
}
}
return ModulesAlphaComparator.INSTANCE.compare(module1, module2);
});
elements.sort((o1, o2) -> {
if (!Comparing.equal(o1.getModule(), o2.getModule()))
return 0;
String pluginId1 = o1.getRootElement().getPluginId();
String pluginId2 = o2.getRootElement().getPluginId();
if (pluginId1 == null && pluginId2 == null) {
return o1.getFile().getName().compareTo(o2.getFile().getName());
}
if (pluginId1 == null)
return 1;
if (pluginId2 == null)
return -1;
return Comparing.compare(pluginId1, pluginId2);
});
return ContainerUtil.map(elements, new Function<DomFileElement<IdeaPlugin>, PluginDescriptorCandidate>() {
private Module myLastModule = currentModule;
@Override
public PluginDescriptorCandidate fun(DomFileElement<IdeaPlugin> element) {
final Module module = element.getModule();
boolean startsNewGroup = !myLastModule.equals(module);
myLastModule = module;
return new PluginDescriptorCandidate(element, startsNewGroup);
}
});
}
use of com.intellij.util.xml.DomFileElement in project intellij-plugins by JetBrains.
the class StrutsConstantManagerImpl method getStringValue.
/**
* Returns the plain String value for the given constant.
*
* @param context Current context.
* @param strutsModel StrutsModel.
* @param name Name of constant.
* @return {@code null} if no value could be resolved.
*/
@Nullable
private static String getStringValue(@NotNull final PsiFile context, @NotNull final StrutsModel strutsModel, @NotNull @NonNls final String name) {
final Project project = context.getProject();
final Module module = ModuleUtilCore.findModuleForPsiElement(context);
assert module != null : context;
// collect all properties with matching key
final List<IProperty> properties = PropertiesImplUtil.findPropertiesByKey(project, name);
String value = null;
// 1. default.properties from struts2-core.jar
final IProperty strutsDefaultProperty = ContainerUtil.find(properties, property -> {
final VirtualFile virtualFile = property.getPropertiesFile().getVirtualFile();
return virtualFile != null && virtualFile.getFileSystem() instanceof JarFileSystem && StringUtil.endsWith(virtualFile.getPath(), STRUTS_DEFAULT_PROPERTIES) && ModuleUtilCore.moduleContainsFile(module, virtualFile, true);
});
if (strutsDefaultProperty != null) {
value = strutsDefaultProperty.getValue();
}
// 2. <constant> from StrutsModel
final Condition<Constant> constantNameCondition = constant -> Comparing.equal(constant.getName().getStringValue(), name);
final List<DomFileElement<StrutsRoot>> domFileElements = new ArrayList<>();
collectStrutsXmls(domFileElements, strutsModel, "struts-default.xml", true);
collectStrutsXmls(domFileElements, strutsModel, "struts-plugin.xml", true);
collectStrutsXmls(domFileElements, strutsModel, "struts.xml", false);
for (final DomFileElement<StrutsRoot> domFileElement : domFileElements) {
final Constant constant = ContainerUtil.find(domFileElement.getRootElement().getConstants(), constantNameCondition);
final String strutsXmlValue = constant != null ? constant.getValue().getStringValue() : null;
if (strutsXmlValue != null) {
value = strutsXmlValue;
}
}
// 3. struts.properties in current module
final IProperty strutsProperty = ContainerUtil.find(properties, property -> {
final VirtualFile virtualFile = property.getPropertiesFile().getVirtualFile();
return virtualFile != null && Comparing.equal(virtualFile.getName(), STRUTS_PROPERTIES_FILENAME) && ModuleUtilCore.moduleContainsFile(module, virtualFile, false);
});
if (strutsProperty != null) {
value = strutsProperty.getValue();
}
// 4. web.xml
final WebFacet webFacet = WebUtil.getWebFacet(context);
if (webFacet == null) {
// should not happen in real projects..
return value;
}
final WebApp webApp = webFacet.getRoot();
if (webApp == null) {
// no web.xml
return value;
}
final Filter filter = ContainerUtil.find(webApp.getFilters(), WEB_XML_STRUTS_FILTER_CONDITION);
if (filter != null) {
final ParamValue initParam = ContainerUtil.find(filter.getInitParams(), (Condition<ParamValue>) paramValue -> Comparing.equal(paramValue.getParamName().getStringValue(), name));
if (initParam != null) {
value = initParam.getParamValue().getStringValue();
}
}
return value;
}
Aggregations