use of com.android.tools.idea.gradle.structure.model.PsModel in project android by JetBrains.
the class AbstractPsNodeTreeBuilder method getMatchingSelection.
@NotNull
public <T extends AbstractPsModelNode<PsModel>> List<T> getMatchingSelection(@NotNull Class<T> nodeType) {
Set<T> selection = getSelectedElements(nodeType);
if (!selection.isEmpty()) {
T first = getFirstItem(selection);
assert first != null;
PsModel model = first.getFirstModel();
List<T> matchingSelection = Lists.newArrayList();
for (T node : selection) {
if (!node.matches(model)) {
return Collections.emptyList();
}
matchingSelection.add(node);
}
return matchingSelection;
}
return Collections.emptyList();
}
use of com.android.tools.idea.gradle.structure.model.PsModel in project android by JetBrains.
the class AndroidDependencyScopesPanel method deduceScopes.
@NotNull
private static List<String> deduceScopes(@NotNull List<? extends PsModel> models, @NotNull String prefix, @NotNull String suffix) {
List<String> configurationNames = Lists.newArrayList();
for (PsModel model : models) {
StringBuilder buffer = new StringBuilder();
if (prefix.isEmpty()) {
buffer.append(model.getName());
} else {
buffer.append(prefix).append(capitalize(model.getName()));
}
buffer.append(suffix);
configurationNames.add(buffer.toString());
}
return configurationNames;
}
use of com.android.tools.idea.gradle.structure.model.PsModel in project android by JetBrains.
the class NodeHyperlinkSupport method addHyperlinkBehaviorToSupportedNodes.
private void addHyperlinkBehaviorToSupportedNodes() {
myTree.setCellRenderer(new NodeRenderer() {
@NotNull
@Override
protected SimpleTextAttributes getSimpleTextAttributes(@NotNull PresentationData presentation, Color color, @NotNull Object node) {
List<PsIssue> issues = Collections.emptyList();
if (myShowIssues && node instanceof AbstractPsModelNode) {
AbstractPsModelNode<? extends PsModel> modelNode = (AbstractPsModelNode<? extends PsModel>) node;
issues = findIssues(modelNode, IssuesByTypeAndTextComparator.INSTANCE);
presentation.setTooltip(getTooltipText(issues, false));
}
if (myHoveredNode != null && myHoveredNode == node) {
return LINK_ATTRIBUTES;
}
SimpleTextAttributes textAttributes = super.getSimpleTextAttributes(presentation, color, node);
if (!issues.isEmpty()) {
PsIssue issue = issues.get(0);
Color waveColor = issue.getSeverity().getColor();
textAttributes = textAttributes.derive(STYLE_WAVED, null, null, waveColor);
}
return textAttributes;
}
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (myShowIssues) {
AbstractPsModelNode<? extends PsModel> modelNode = findModelNode(value);
if (modelNode != null) {
List<PsIssue> issues = findIssues(modelNode, null);
if (!issues.isEmpty()) {
// Force color change of the node.
modelNode.getPresentation().clearText();
}
}
}
super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
if (userObject instanceof CellAppearanceEx) {
((CellAppearanceEx) userObject).customize(this);
}
}
@Nullable
private AbstractPsModelNode<? extends PsModel> findModelNode(@Nullable Object value) {
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object userObject = node.getUserObject();
if (userObject instanceof AbstractPsModelNode) {
return (AbstractPsModelNode<? extends PsModel>) userObject;
}
}
return null;
}
});
MouseAdapter mouseListener = new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
Cursor cursor = getDefaultCursor();
T node = getIfHyperlink(e);
if (node != null) {
cursor = getPredefinedCursor(HAND_CURSOR);
}
setHoveredNode(node);
myTree.setCursor(cursor);
}
};
myTree.addMouseMotionListener(mouseListener);
// Make the cursor change to 'hand' if the mouse pointer is over a supported node and the user presses Ctrl or Cmd.
myKeyEventDispatcher = e -> {
T node = null;
if (e.getID() == KEY_PRESSED) {
Cursor cursor = getDefaultCursor();
if (isMetaOrCtrlKeyPressed(e)) {
node = getNodeUnderMousePointer();
if (node != null) {
cursor = getPredefinedCursor(HAND_CURSOR);
}
}
setHoveredNode(node);
myTree.setCursor(cursor);
} else if (e.getID() == KEY_RELEASED) {
if (isMetaOrCtrlKeyPressed(e)) {
setHoveredNode(null);
}
myTree.setCursor(getDefaultCursor());
}
return false;
};
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(myKeyEventDispatcher);
}
use of com.android.tools.idea.gradle.structure.model.PsModel in project android by JetBrains.
the class NodeHyperlinkSupport method findIssues.
@NotNull
private List<PsIssue> findIssues(@NotNull AbstractPsModelNode<? extends PsModel> modelNode, @Nullable Comparator<PsIssue> comparator) {
List<PsIssue> issues = Lists.newArrayList();
PsIssueCollection issueCollection = myContext.getAnalyzerDaemon().getIssues();
for (PsModel model : modelNode.getModels()) {
issues.addAll(issueCollection.findIssues(model, null));
}
if (comparator != null && issues.size() > 1) {
Collections.sort(issues, comparator);
}
return issues;
}
Aggregations