use of com.intellij.psi.SmartPsiElementPointer in project intellij-community by JetBrains.
the class DocumentationComponent method setData.
public void setData(PsiElement _element, String text, final boolean clearHistory, String effectiveExternalUrl, String ref) {
if (myElement != null) {
myBackStack.push(saveContext());
myForwardStack.clear();
}
myEffectiveExternalUrl = effectiveExternalUrl;
final SmartPsiElementPointer element = _element != null && _element.isValid() ? SmartPointerManager.getInstance(_element.getProject()).createSmartPsiElementPointer(_element) : null;
if (element != null) {
setElement(element);
}
myIsEmpty = false;
updateControlState();
setDataInternal(element, text, new Rectangle(0, 0), ref);
if (clearHistory)
clearHistory();
}
use of com.intellij.psi.SmartPsiElementPointer in project intellij-community by JetBrains.
the class FavoritesPanel method setupDnD.
private void setupDnD() {
DnDSupport.createBuilder(myTree).setBeanProvider(info -> {
final TreePath path = myTree.getPathForLocation(info.getPoint().x, info.getPoint().y);
if (path != null && path.getPathCount() == 3) {
Object o = path.getLastPathComponent();
if (o instanceof DefaultMutableTreeNode) {
o = ((DefaultMutableTreeNode) o).getUserObject();
if (o instanceof FavoritesTreeNodeDescriptor) {
FavoritesTreeNodeDescriptor root = ((FavoritesTreeNodeDescriptor) o).getFavoritesRoot();
if (root != null && root != o) {
o = root.getElement();
if (o instanceof FavoritesListNode && ((FavoritesListNode) o).getProvider() == null) {
return new DnDDragStartBean(path);
}
}
}
}
}
if (path != null && path.getPathCount() == 2) {
Object o = path.getLastPathComponent();
if (o instanceof DefaultMutableTreeNode) {
o = ((DefaultMutableTreeNode) o).getUserObject();
if (o instanceof FavoritesTreeNodeDescriptor) {
FavoritesTreeNodeDescriptor root = ((FavoritesTreeNodeDescriptor) o).getFavoritesRoot();
if (root == o) {
return new DnDDragStartBean(path);
}
}
}
}
return new DnDDragStartBean("") {
@Override
public boolean isEmpty() {
return true;
}
};
}).setTargetChecker(new DnDTargetChecker() {
@Override
public boolean update(DnDEvent event) {
final Object obj = event.getAttachedObject();
if ("".equals(obj)) {
event.setDropPossible(false);
return false;
}
int pathCount = 0;
if (obj instanceof TreePath) {
pathCount = ((TreePath) obj).getPathCount();
if (pathCount < 2) {
event.setDropPossible(false);
return true;
}
}
FavoritesListNode node = myViewPanel.findFavoritesListNode(event.getPoint());
if ((obj instanceof TreePath && pathCount == 3 && myViewPanel.myTree.getPath(node).isDescendant((TreePath) obj)) || (node != null && node.getProvider() != null)) {
event.setDropPossible(false);
return false;
}
highlight(node, event);
if (obj instanceof TreePath && pathCount == 2 && node != null && node.getProvider() == null) {
event.setDropPossible(true);
return true;
}
if (node != null) {
event.setDropPossible(true);
return true;
}
event.setDropPossible(false);
return false;
}
}).setDropHandler(new DnDDropHandler() {
@Override
public void drop(DnDEvent event) {
final FavoritesListNode node = myViewPanel.findFavoritesListNode(event.getPoint());
final FavoritesManager mgr = FavoritesManager.getInstance(myProject);
if (node == null)
return;
final String listTo = node.getValue();
final Object obj = event.getAttachedObject();
if (obj instanceof TreePath) {
final TreePath path = (TreePath) obj;
final String listFrom = FavoritesTreeViewPanel.getListNodeFromPath(path).getValue();
if (listTo.equals(listFrom))
return;
if (path.getPathCount() == 3) {
final AbstractTreeNode abstractTreeNode = ((FavoritesTreeNodeDescriptor) ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject()).getElement();
Object element = abstractTreeNode.getValue();
mgr.removeRoot(listFrom, Collections.singletonList(abstractTreeNode));
if (element instanceof SmartPsiElementPointer) {
element = ((SmartPsiElementPointer) element).getElement();
}
mgr.addRoots(listTo, null, element);
}
if (path.getPathCount() == 2) {
//favorites lists manual sorting
Rectangle bounds = myTree.getPathBounds(myTree.getPath(node));
if (bounds != null) {
mgr.setOrder(listFrom, listTo, event.getPoint().y < bounds.y + bounds.height / 2);
}
}
} else if (obj instanceof TransferableWrapper) {
myViewPanel.dropPsiElements(mgr, node, ((TransferableWrapper) obj).getPsiElements());
} else if (obj instanceof DnDNativeTarget.EventInfo) {
myViewPanel.dropPsiElements(mgr, node, getPsiFiles(FileCopyPasteUtil.getFileList(((DnDNativeTarget.EventInfo) obj).getTransferable())));
}
}
}).setImageProvider(info -> new DnDImage(myFavoritesImage, new Point(-myFavoritesImage.getWidth(null) / 2, -myFavoritesImage.getHeight(null) / 2))).enableAsNativeTarget().setDisposableParent(myProject).install();
}
use of com.intellij.psi.SmartPsiElementPointer in project intellij-community by JetBrains.
the class FavoritesTreeStructure method getChildElements.
@Override
public Object[] getChildElements(Object element) {
if (!(element instanceof AbstractTreeNode)) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final AbstractTreeNode favTreeElement = (AbstractTreeNode) element;
try {
if (!(element instanceof FavoritesListNode)) {
Object[] elements = super.getChildElements(favTreeElement);
if (elements.length > 0)
return elements;
ViewSettings settings = favTreeElement instanceof SettingsProvider ? ((SettingsProvider) favTreeElement).getSettings() : ViewSettings.DEFAULT;
return ArrayUtil.toObjectArray(myNonProjectProvider.modify(favTreeElement, new ArrayList<>(), settings));
}
final List<AbstractTreeNode> result = new ArrayList<>();
final FavoritesListNode listNode = (FavoritesListNode) element;
if (listNode.getProvider() != null) {
return ArrayUtil.toObjectArray(listNode.getChildren());
}
final Collection<AbstractTreeNode> roots = FavoritesListNode.getFavoritesRoots(myProject, listNode.getName(), listNode);
for (AbstractTreeNode<?> abstractTreeNode : roots) {
final Object value = abstractTreeNode.getValue();
if (value == null)
continue;
if (value instanceof PsiElement && !((PsiElement) value).isValid())
continue;
if (value instanceof SmartPsiElementPointer && ((SmartPsiElementPointer) value).getElement() == null)
continue;
boolean invalid = false;
for (FavoriteNodeProvider nodeProvider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, myProject)) {
if (nodeProvider.isInvalidElement(value)) {
invalid = true;
break;
}
}
if (invalid)
continue;
result.add(abstractTreeNode);
}
//}
return ArrayUtil.toObjectArray(result);
} catch (Exception e) {
LOGGER.error(e);
}
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
use of com.intellij.psi.SmartPsiElementPointer in project intellij-community by JetBrains.
the class FavoritesViewTreeBuilder method findSmartFirstLevelNodeByElement.
@Nullable
DefaultMutableTreeNode findSmartFirstLevelNodeByElement(final Object element) {
for (Object child : getRoot().getChildren()) {
AbstractTreeNode favorite = (AbstractTreeNode) child;
Object currentValue = favorite.getValue();
if (currentValue instanceof SmartPsiElementPointer) {
currentValue = ((SmartPsiElementPointer) favorite.getValue()).getElement();
}
/*else if (currentValue instanceof PsiJavaFile) {
final PsiClass[] classes = ((PsiJavaFile)currentValue).getClasses();
if (classes.length > 0) {
currentValue = classes[0];
}
}*/
if (Comparing.equal(element, currentValue)) {
final DefaultMutableTreeNode nodeWithObject = findFirstLevelNodeWithObject((DefaultMutableTreeNode) getTree().getModel().getRoot(), favorite);
if (nodeWithObject != null) {
return nodeWithObject;
}
}
}
return null;
}
use of com.intellij.psi.SmartPsiElementPointer in project intellij-plugins by JetBrains.
the class AngularUiRouterDiagramProvider method getExtras.
@NotNull
@Override
public DiagramExtras<DiagramObject> getExtras() {
return new DiagramExtras<DiagramObject>() {
@Override
public List<AnAction> getExtraActions() {
return Collections.singletonList(new MyEditSourceAction());
}
@Nullable
@Override
public Object getData(String dataId, List<DiagramNode<DiagramObject>> list, DiagramBuilder builder) {
if (CommonDataKeys.PSI_ELEMENT.is(dataId) && list.size() == 1) {
final SmartPsiElementPointer target = list.get(0).getIdentifyingElement().getNavigationTarget();
return target == null ? null : target.getElement();
} else if (JSModulesDiagramUtils.DIAGRAM_BUILDER.is(dataId)) {
return builder;
}
return null;
}
@Nullable
@Override
public Layouter getCustomLayouter(Graph2D graph, Project project) {
final GraphSettingsProvider settingsProvider = GraphSettingsProvider.getInstance(project);
final GraphSettings settings = settingsProvider.getSettings(graph);
final SmartOrganicLayouter layouter = settings.getOrganicLayouter();
layouter.setNodeEdgeOverlapAvoided(true);
layouter.setNodeSizeAware(true);
layouter.setMinimalNodeDistance(60);
layouter.setNodeOverlapsAllowed(false);
layouter.setSmartComponentLayoutEnabled(true);
layouter.setConsiderNodeLabelsEnabled(true);
layouter.setDeterministic(true);
final List<CanonicMultiStageLayouter> list = new ArrayList<>();
list.add(layouter);
list.add(settings.getBalloonLayouter());
list.add(settings.getCircularLayouter());
list.add(settings.getDirectedOrthogonalLayouter());
//list.add(settings.getGroupLayouter());
list.add(settings.getHVTreeLayouter());
list.add(settings.getOrthogonalLayouter());
for (CanonicMultiStageLayouter current : list) {
final ParallelEdgeLayouter parallelEdgeLayouter = GraphManager.getGraphManager().createParallelEdgeLayouter();
parallelEdgeLayouter.setLineDistance(40);
parallelEdgeLayouter.setUsingAdaptiveLineDistances(false);
current.appendStage(parallelEdgeLayouter);
current.setParallelEdgeLayouterEnabled(false);
}
return layouter;
}
@NotNull
@Override
public JComponent createNodeComponent(DiagramNode<DiagramObject> node, DiagramBuilder builder, Point basePoint, JPanel wrapper) {
final DiagramNodeContainer container = new DiagramNodeContainer(node, builder, basePoint);
if (!GraphViewUtil.isPrintMode()) {
if (!node.getIdentifyingElement().getErrors().isEmpty()) {
container.setBorder(ERROR_BORDER);
} else if (!node.getIdentifyingElement().getWarnings().isEmpty()) {
container.setBorder(WARNING_BORDER);
} else {
container.setBorder(NORMAL_BORDER);
}
}
if (!node.getIdentifyingElement().getChildrenList().isEmpty())
container.getHeader().setBorder(JBUI.Borders.customLine(Gray._190, 0, 0, 1, 0));
return container;
}
};
}
Aggregations