use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class CollectionElementInvocationHandler method undefineInternal.
@Override
public final void undefineInternal() {
final DomElement parent = getParent();
final XmlTag tag = getXmlTag();
if (tag == null)
return;
getManager().cacheHandler(getCacheKey(), tag, null);
setXmlElement(null);
deleteTag(tag);
getManager().fireEvent(new DomEvent(parent, false));
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class DomTemplateRunnerImpl method runTemplate.
public <T extends DomElement> void runTemplate(final T t, final Editor editor, @Nullable final Template template, Map<String, String> predefinedVars) {
if (template != null) {
DomElement copy = t.createStableCopy();
PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(editor.getDocument());
XmlTag tag = copy.getXmlTag();
assert tag != null;
editor.getCaretModel().moveToOffset(tag.getTextRange().getStartOffset());
copy.undefine();
PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(editor.getDocument());
template.setToReformat(true);
TemplateManager.getInstance(myProject).startTemplate(editor, template, true, predefinedVars, null);
}
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class DeleteDomElement method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e, DomModelTreeView treeView) {
final SimpleNode selectedNode = treeView.getTree().getSelectedNode();
if (selectedNode instanceof BaseDomElementNode) {
if (selectedNode instanceof DomFileElementNode) {
e.getPresentation().setVisible(false);
return;
}
final DomElement domElement = ((BaseDomElementNode) selectedNode).getDomElement();
final int ret = Messages.showOkCancelDialog(getPresentationText(selectedNode, "Remove") + "?", "Remove", Messages.getQuestionIcon());
if (ret == Messages.OK) {
new WriteCommandAction(domElement.getManager().getProject(), DomUtil.getFile(domElement)) {
@Override
protected void run(@NotNull final Result result) throws Throwable {
domElement.undefine();
}
}.execute();
}
}
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class DeleteDomElement method update.
@Override
public void update(AnActionEvent e, DomModelTreeView treeView) {
final SimpleNode selectedNode = treeView.getTree().getSelectedNode();
if (selectedNode instanceof DomFileElementNode) {
e.getPresentation().setVisible(false);
return;
}
boolean enabled = false;
if (selectedNode instanceof BaseDomElementNode) {
final DomElement domElement = ((BaseDomElementNode) selectedNode).getDomElement();
if (domElement.isValid() && DomUtil.hasXml(domElement) && !(domElement.getParent() instanceof DomFileElement)) {
enabled = true;
}
}
e.getPresentation().setEnabled(enabled);
if (enabled) {
e.getPresentation().setText(getPresentationText(selectedNode, ApplicationBundle.message("action.remove")));
} else {
e.getPresentation().setText(ApplicationBundle.message("action.remove"));
}
e.getPresentation().setIcon(AllIcons.General.Remove);
}
use of com.intellij.util.xml.DomElement in project intellij-plugins by JetBrains.
the class ActionNameCustomReferenceConverter method createReferences.
@NotNull
@Override
public PsiReference[] createReferences(final GenericDomValue<String> genericDomValue, final PsiElement psiElement, final ConvertContext convertContext) {
final PsiReferenceBase<PsiElement> ref = new PsiReferenceBase<PsiElement>(psiElement) {
@SuppressWarnings({ "ConstantConditions" })
public PsiElement resolve() {
return genericDomValue.getParent().getXmlTag();
}
public boolean isSoft() {
return true;
}
// do nothing. the element will be renamed via PsiMetaData
public PsiElement handleElementRename(final String newElementName) throws IncorrectOperationException {
return getElement();
}
@NotNull
public Object[] getVariants() {
final DomElement invocationElement = convertContext.getInvocationElement();
final Action action = invocationElement.getParentOfType(Action.class, true);
assert action != null;
final PsiClass psiClass = action.searchActionClass();
if (psiClass == null) {
return EMPTY_ARRAY;
}
final Project project = psiClass.getProject();
final PsiClassType classType = PsiTypesUtil.getClassType(psiClass);
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
final SuggestedNameInfo info = codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, null, classType);
final Set<String> variants = new HashSet<>(Arrays.asList(info.names));
variants.remove(ACTION_SUFFIX);
// remove existing action-names
final List<Action> actions = action.getStrutsPackage().getActions();
ContainerUtil.process(actions, action1 -> {
variants.remove(action1.getName().getStringValue());
return true;
});
return ContainerUtil.map2Array(variants, ACTION_NAME_FUNCTION);
}
};
return new PsiReference[] { ref };
}
Aggregations