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());
}
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();
}
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);
}
}
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();
}
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);
}
Aggregations