use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class ExternalSystemNotificationManager method addMessage.
private void addMessage(@NotNull final Notification notification, @NotNull final ProjectSystemId externalSystemId, @NotNull final NotificationData notificationData) {
final VirtualFile virtualFile = notificationData.getFilePath() != null ? ExternalSystemUtil.findLocalFileByPath(notificationData.getFilePath()) : null;
final String groupName = virtualFile != null ? virtualFile.getPresentableUrl() : notificationData.getTitle();
myMessageCounter.increment(groupName, notificationData.getNotificationSource(), notificationData.getNotificationCategory(), externalSystemId);
int line = notificationData.getLine() - 1;
int column = notificationData.getColumn() - 1;
if (virtualFile == null)
line = column = -1;
final int guiLine = line < 0 ? -1 : line + 1;
final int guiColumn = column < 0 ? 0 : column + 1;
final Navigatable navigatable = notificationData.getNavigatable() != null ? notificationData.getNavigatable() : virtualFile != null ? new OpenFileDescriptor(myProject, virtualFile, line, column) : NonNavigatable.INSTANCE;
final ErrorTreeElementKind kind = ErrorTreeElementKind.convertMessageFromCompilerErrorType(notificationData.getNotificationCategory().getMessageCategory());
final String[] message = notificationData.getMessage().split("\n");
final String exportPrefix = NewErrorTreeViewPanel.createExportPrefix(guiLine);
final String rendererPrefix = NewErrorTreeViewPanel.createRendererPrefix(guiLine, guiColumn);
UIUtil.invokeLaterIfNeeded(() -> {
boolean activate = notificationData.getNotificationCategory() == NotificationCategory.ERROR || notificationData.getNotificationCategory() == NotificationCategory.WARNING;
final NewErrorTreeViewPanel errorTreeView = prepareMessagesView(externalSystemId, notificationData.getNotificationSource(), activate);
final GroupingElement groupingElement = errorTreeView.getErrorViewStructure().getGroupingElement(groupName, null, virtualFile);
final NavigatableMessageElement navigatableMessageElement;
if (notificationData.hasLinks()) {
navigatableMessageElement = new EditableNotificationMessageElement(notification, kind, groupingElement, message, navigatable, exportPrefix, rendererPrefix);
} else {
navigatableMessageElement = new NotificationMessageElement(kind, groupingElement, message, navigatable, exportPrefix, rendererPrefix);
}
errorTreeView.getErrorViewStructure().addNavigatableMessage(groupName, navigatableMessageElement);
errorTreeView.updateTree();
});
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class TreeView method createPanel.
private JPanel createPanel() {
createModel();
myTree = new MyTree();
myTree.setLineStyleAngled();
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
myTree.updateUI();
myTree.setLargeModel(true);
myTree.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
OpenSourceUtil.openSourcesFrom(DataManager.getInstance().getDataContext(myTree), false);
}
}
});
myTree.addMouseListener(new PopupHandler() {
public void invokePopup(Component comp, int x, int y) {
popupInvoked(comp, x, y);
}
});
EditSourceOnDoubleClickHandler.install(myTree);
myAutoScrollToSourceHandler.install(myTree);
myOccurenceNavigatorSupport = new OccurenceNavigatorSupport(myTree) {
protected Navigatable createDescriptorForNode(DefaultMutableTreeNode node) {
if (!(node instanceof MessageNode)) {
return null;
}
MessageNode messageNode = (MessageNode) node;
AntBuildMessageView.MessageType type = messageNode.getType();
if (type != AntBuildMessageView.MessageType.MESSAGE && type != AntBuildMessageView.MessageType.ERROR) {
return null;
}
if (!isValid(messageNode.getFile())) {
return null;
}
return new OpenFileDescriptor(myProject, messageNode.getFile(), messageNode.getOffset());
}
@Nullable
public String getNextOccurenceActionName() {
return AntBundle.message("ant.execution.next.error.warning.action.name");
}
@Nullable
public String getPreviousOccurenceActionName() {
return AntBundle.message("ant.execution.previous.error.warning.action.name");
}
};
return JBUI.Panels.simplePanel(MessageTreeRenderer.install(myTree));
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class AntCreatePropertyFix method applyFix.
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
final PsiFile containingFile = psiElement.getContainingFile();
final FileModificationService modificationService = FileModificationService.getInstance();
Navigatable result = null;
if (myPropFile != null) {
final VirtualFile vFile = myPropFile.getVirtualFile();
boolean canModify = true;
if (myPropFile instanceof PsiFile) {
canModify = modificationService.prepareFileForWrite((PsiFile) myPropFile);
} else if (vFile != null) {
canModify = modificationService.prepareVirtualFilesForWrite(project, Collections.singleton(vFile));
}
if (canModify) {
final IProperty generatedProperty = myPropFile.addProperty(myCanonicalText, "");
result = vFile != null ? new OpenFileDescriptor(project, vFile, generatedProperty.getPsiElement().getTextRange().getEndOffset()) : generatedProperty;
}
} else {
if (containingFile instanceof XmlFile) {
final XmlFile xmlFile = (XmlFile) containingFile;
final XmlTag rootTag = xmlFile.getRootTag();
if (rootTag != null && modificationService.prepareFileForWrite(xmlFile)) {
final XmlTag propTag = rootTag.createChildTag(PROPERTY, rootTag.getNamespace(), null, false);
propTag.setAttribute(NAME_ATTR, myCanonicalText);
propTag.setAttribute(VALUE_ATTR, "");
final DomElement contextElement = DomUtil.getDomElement(descriptor.getPsiElement());
PsiElement generated;
if (contextElement == null) {
generated = rootTag.addSubTag(propTag, true);
} else {
final AntDomTarget containingTarget = contextElement.getParentOfType(AntDomTarget.class, false);
final DomElement anchor = containingTarget != null ? containingTarget : contextElement;
final XmlTag tag = anchor.getXmlTag();
if (!rootTag.equals(tag)) {
generated = tag.getParent().addBefore(propTag, tag);
} else {
generated = rootTag.addSubTag(propTag, true);
}
}
if (generated instanceof XmlTag) {
final XmlAttribute valueAttrib = ((XmlTag) generated).getAttribute(VALUE_ATTR);
if (valueAttrib != null) {
final XmlAttributeValue valueElement = valueAttrib.getValueElement();
if (valueElement instanceof Navigatable) {
result = (Navigatable) valueElement;
}
}
}
if (result == null && generated instanceof Navigatable) {
result = (Navigatable) generated;
}
}
}
}
if (result != null) {
result.navigate(true);
}
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class UnifiedDiffViewer method getNavigatable.
@CalledInAwt
@Nullable
protected Navigatable getNavigatable(@NotNull LineCol position) {
Pair<int[], Side> pair = transferLineFromOneside(position.line);
int line1 = pair.first[0];
int line2 = pair.first[1];
Navigatable navigatable1 = getContent1().getNavigatable(new LineCol(line1, position.column));
Navigatable navigatable2 = getContent2().getNavigatable(new LineCol(line2, position.column));
if (navigatable1 == null)
return navigatable2;
if (navigatable2 == null)
return navigatable1;
return pair.second.select(navigatable1, navigatable2);
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class OpenInEditorAction method openEditor.
public void openEditor(@NotNull Project project, @NotNull Navigatable[] navigatables) {
boolean success = false;
for (Navigatable navigatable : navigatables) {
if (navigatable.canNavigate()) {
navigatable.navigate(true);
success = true;
}
}
if (success && myAfterRunnable != null)
myAfterRunnable.run();
}
Aggregations