Search in sources :

Example 1 with Variable

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());
}
Also used : HistoryElement(org.intellij.plugins.xpathView.HistoryElement) Variable(org.intellij.plugins.xpathView.util.Variable) Namespace(org.intellij.plugins.xpathView.util.Namespace)

Example 2 with Variable

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));
            }
        }
    }
}
Also used : Variable(org.intellij.plugins.xpathView.util.Variable) Element(org.jdom.Element) ArrayList(java.util.ArrayList) Namespace(org.intellij.plugins.xpathView.util.Namespace)

Example 3 with Variable

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);
        }
    }
}
Also used : Variable(org.intellij.plugins.xpathView.util.Variable) Element(org.jdom.Element) Namespace(org.intellij.plugins.xpathView.util.Namespace)

Example 4 with Variable

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();
}
Also used : HistoryElement(org.intellij.plugins.xpathView.HistoryElement) Variable(org.intellij.plugins.xpathView.util.Variable) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Editor(com.intellij.openapi.editor.Editor) Namespace(org.intellij.plugins.xpathView.util.Namespace) Pair(com.intellij.openapi.util.Pair)

Aggregations

Namespace (org.intellij.plugins.xpathView.util.Namespace)4 Variable (org.intellij.plugins.xpathView.util.Variable)4 HistoryElement (org.intellij.plugins.xpathView.HistoryElement)2 Element (org.jdom.Element)2 Editor (com.intellij.openapi.editor.Editor)1 Pair (com.intellij.openapi.util.Pair)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1