use of org.intellij.plugins.xpathView.util.Variable in project intellij-community by JetBrains.
the class InputExpressionDialog method getContext.
@SuppressWarnings({ "unchecked" })
public Context getContext() {
final HistoryElement context = myModel.getSelectedItem();
if (context == null || context.expression == null) {
final Set<Namespace> cache = myNamespaceCache != null ? myNamespaceCache : Collections.<Namespace>emptySet();
return new Context(new HistoryElement(myDocument.getText(), Collections.<Variable>emptySet(), cache), getMode());
}
final Collection<Namespace> namespaces = myNamespaceCache != null ? merge(myNamespaceCache, context.namespaces, false) : context.namespaces;
return new Context(new HistoryElement(context.expression, context.variables, namespaces), getMode());
}
use of org.intellij.plugins.xpathView.util.Variable in project intellij-community by JetBrains.
the class XPathProjectComponent method readHistory.
@SuppressWarnings({ "unchecked" })
private static void readHistory(Element element, String s, LinkedHashMap<String, HistoryElement> hst) {
final Element historyElement = element.getChild(s);
if (historyElement != null) {
final List<Element> entries = historyElement.getChildren(HISTORY_ELEMENT);
for (final Element entry : entries) {
final String expression = entry.getAttributeValue(EXPRESSION);
if (expression != null) {
List<Element> children = entry.getChildren(VARIABLE);
final Collection<Variable> variables = new ArrayList<>(children.size());
for (Element e : children) {
variables.add(new Variable(e.getAttributeValue(NAME), e.getAttributeValue(EXPRESSION)));
}
children = entry.getChildren(NAMESPACE);
final Collection<Namespace> namespaces = new ArrayList<>(children.size());
for (Element namespaceElement : children) {
namespaces.add(new Namespace(namespaceElement.getAttributeValue(PREFIX), namespaceElement.getAttributeValue(URI)));
}
hst.put(expression, new HistoryElement(expression, variables, namespaces));
}
}
}
}
use of org.intellij.plugins.xpathView.util.Variable in project intellij-community by JetBrains.
the class XPathProjectComponent method writeHistory.
private static void writeHistory(Element element, String s, LinkedHashMap<String, HistoryElement> hst) {
final Element historyElement = new Element(s);
element.addContent(historyElement);
for (String key : hst.keySet()) {
final Element entryElement = new Element(HISTORY_ELEMENT);
entryElement.setAttribute(EXPRESSION, key);
historyElement.addContent(entryElement);
final HistoryElement h = hst.get(key);
for (Variable variable : h.variables) {
final Element varElement = new Element(VARIABLE);
varElement.setAttribute(NAME, variable.getName());
varElement.setAttribute(EXPRESSION, variable.getExpression());
entryElement.addContent(varElement);
}
for (Namespace namespace : h.namespaces) {
final Element namespaceElement = new Element(NAMESPACE);
namespaceElement.setAttribute(PREFIX, namespace.getPrefix());
namespaceElement.setAttribute(URI, namespace.getUri());
entryElement.addContent(namespaceElement);
}
}
}
use of org.intellij.plugins.xpathView.util.Variable in project intellij-community by JetBrains.
the class InputExpressionDialog method init.
protected void init() {
myForm.getIcon().setText(null);
myForm.getIcon().setIcon(Messages.getQuestionIcon());
myForm.getEditContextButton().addActionListener(new ActionListener() {
@SuppressWarnings({ "unchecked" })
public void actionPerformed(ActionEvent e) {
final HistoryElement selectedItem = myModel.getSelectedItem();
final Collection<Namespace> n;
final Collection<Variable> v;
if (selectedItem != null) {
n = selectedItem.namespaces;
v = selectedItem.variables;
} else {
n = Collections.emptySet();
v = Collections.emptySet();
}
// FIXME
final Collection<Namespace> namespaces = myNamespaceCache != null ? merge(myNamespaceCache, n, false) : n;
final Set<String> unresolvedPrefixes = findUnresolvedPrefixes();
final EditContextDialog dialog = new EditContextDialog(myProject, unresolvedPrefixes, namespaces, v, myContextProvider);
if (dialog.showAndGet()) {
final Pair<Collection<Namespace>, Collection<Variable>> context = dialog.getContext();
final Collection<Namespace> newNamespaces = context.getFirst();
final Collection<Variable> newVariables = context.getSecond();
updateContext(newNamespaces, newVariables);
SwingUtilities.invokeLater(() -> {
final Editor editor = getEditor();
if (editor != null) {
editor.getContentComponent().grabFocus();
}
});
}
}
});
updateOkAction();
super.init();
}
Aggregations