Search in sources :

Example 1 with HistoryElement

use of org.intellij.plugins.xpathView.HistoryElement 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 HistoryElement

use of org.intellij.plugins.xpathView.HistoryElement in project intellij-community by JetBrains.

the class InputExpressionDialog method prepareShow.

@SuppressWarnings({ "unchecked" })
private void prepareShow(XmlElement contextElement) {
    final NamespaceCollector.CollectedInfo collectedInfo;
    if (contextElement != null) {
        collectedInfo = NamespaceCollector.collectInfo((XmlFile) contextElement.getContainingFile());
        myNamespaceCache = collectedInfo.namespaces;
    } else {
        collectedInfo = NamespaceCollector.empty();
        myNamespaceCache = null;
    }
    myContextProvider = new InteractiveContextProvider(contextElement, collectedInfo, myModel);
    myContextProvider.attachTo(myXPathFile);
    final HistoryElement historyElement = myModel.getSelectedItem();
    if (historyElement != null) {
        myContextProvider.getNamespaceContext().setMap(asMap(historyElement.namespaces));
    } else {
        myContextProvider.getNamespaceContext().setMap(asMap(null));
    }
    updateOkAction();
}
Also used : HistoryElement(org.intellij.plugins.xpathView.HistoryElement) NamespaceCollector(org.intellij.plugins.xpathView.util.NamespaceCollector) XmlFile(com.intellij.psi.xml.XmlFile)

Example 3 with HistoryElement

use of org.intellij.plugins.xpathView.HistoryElement in project intellij-community by JetBrains.

the class HistoryModel method setSelectedItem.

public void setSelectedItem(Object object) {
    if (object instanceof String) {
        for (HistoryElement element : history) {
            if (object.equals(element.expression)) {
                object = element;
                break;
            }
        }
    }
    if (object instanceof String) {
        object = selectedItem.changeExpression((String) object);
    }
    if (selectedItem != null && selectedItem != object || selectedItem == null && object != null) {
        selectedItem = (HistoryElement) object;
        fireContentsChanged(this, -1, -1);
    }
}
Also used : HistoryElement(org.intellij.plugins.xpathView.HistoryElement)

Example 4 with HistoryElement

use of org.intellij.plugins.xpathView.HistoryElement 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)

Example 5 with HistoryElement

use of org.intellij.plugins.xpathView.HistoryElement in project intellij-community by JetBrains.

the class InputExpressionDialog method updateContext.

void updateContext(Collection<Namespace> namespaces, Collection<Variable> variables) {
    final HistoryElement selectedItem = myModel.getSelectedItem();
    final HistoryElement newElement;
    if (selectedItem != null) {
        newElement = selectedItem.changeContext(namespaces, variables);
    } else {
        newElement = new HistoryElement(myDocument.getText(), variables, namespaces);
    }
    myModel.setSelectedItem(newElement);
    // FIXME
    if (myNamespaceCache == null) {
        myContextProvider.getNamespaceContext().setMap(asMap(namespaces));
    }
    final DaemonCodeAnalyzer analyzer = DaemonCodeAnalyzer.getInstance(myProject);
    analyzer.restart(myXPathFile);
}
Also used : HistoryElement(org.intellij.plugins.xpathView.HistoryElement) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)

Aggregations

HistoryElement (org.intellij.plugins.xpathView.HistoryElement)5 Namespace (org.intellij.plugins.xpathView.util.Namespace)2 Variable (org.intellij.plugins.xpathView.util.Variable)2 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 Editor (com.intellij.openapi.editor.Editor)1 Pair (com.intellij.openapi.util.Pair)1 XmlFile (com.intellij.psi.xml.XmlFile)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 NamespaceCollector (org.intellij.plugins.xpathView.util.NamespaceCollector)1