How to get a Close-button in an own Usage View?
Here's the code I'm using to open a new Usage View with custom content that refers to
PsiElements:
final List l = new ArrayList]]>(result.size());
for (Object o : result) {
if (o instanceof PsiElement) {
l.add(new UsageInfo2UsageAdapter(new UsageInfo(((PsiElement)o))));
}
}
final UsageView usageView = UsageViewManager.getInstance(project).createUsageView(
new UsageTarget[]{ new MyUsageTarget(input.expression) },
l.toArray(new Usage[l.size()]), presentation);
com.intellij.usageView.UsageViewManager.getInstance(project).addContent("XPath", true,
usageView.getComponent(), true, true);
This works quite well, except that there's no Close-button for the new Usage View-tab. How
to get/add one? How to get a "Re-Run" button? Does this require to use the much more
sophisticated methods UsageViewManager.searchAndShowUsages(...)?
Thanks,
Sascha
PS: This Usage View stuff is a really good candidate for some documentation and/or
refactoring because this is scattered across two similarly named packages with two
identically named Managers. Very confusing...
Attachment(s):
missing-close.png
Please sign in to leave a comment.
Hello Sascha,
SW> Here's the code I'm using to open a new Usage View with custom
SW> content that refers to PsiElements:
SW>
SW> final List l = new ArrayList(result.size()); SW> for (Object o : result) { SW> if (o instanceof PsiElement) { SW> l.add(new UsageInfo2UsageAdapter(new SW> UsageInfo(((PsiElement)o)))); SW> } SW> } SW> final UsageView usageView = SW> UsageViewManager.getInstance(project).createUsageView( SW> new UsageTarget[]{ new MyUsageTarget(input.expression) }, SW> l.toArray(new Usage[l.size()]), presentation); SW> com.intellij.usageView.UsageViewManager.getInstance(project).addCont SW> ent("XPath", true, usageView.getComponent(), true, true); SW> SW> This works quite well, except that there's no Close-button for the SW> new Usage View-tab. How to get/add one? How to get a "Re-Run" SW> button? Does this require to use the much more sophisticated methods SW> UsageViewManager.searchAndShowUsages(...)? In fact, the entire com.intellij.usageView API package is deprecated - you should use the classes from com.intellij.usages instead. With those classes, the addContent() method ensures that you will get a correct Close button. In order to get the "Re-Run" button, you need to pass a correct searcherFactory to UsageViewManager.searchAndShowUsages(). SW>]]> PS: This Usage View stuff is a really good candidate for some
SW> documentation and/or refactoring because this is scattered across
SW> two similarly named packages with two identically named Managers.
SW> Very confusing...
It's not really scattered, it's leftover deprecated classes... but I hear
you, and I'll put the usage view documentation high on my priority list.
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"
Dmitry Jemerov (JetBrains) wrote:
Well, I did use com.intellij.usages.UsageViewManager to get a
com.intellij.usages.UsageView instance, but I found no way to actually display it. What do
I do with it or the JComponent instance to add it to the Find-ToolWindow? I found no other
addContent() method than the one from - the deprecated -
com.intellij.usageView.UsageViewManager.
I attached the result of a SS for addContent() across the OpenAPI. Is the addContent()
you're talking about the one in UsageViewManagerImpl? Unfortunately it is private and I
shouldn't have to use a *Impl class when using the plain OpenAPI...
Sascha
Attachment(s):
addContent.PNG
Ah, I think com.intellij.usages.UsageViewManager.showUsages() is what I'm looking for.
Sascha
Sascha Weinreuter wrote:
Yep, that's working as expected. It was just in front of my nose ;)
Another question: After a quick glance, it doesn't seem possible to add custom usage types
to group by. I'd like to get rid of this "unclassified usage" node and provide my own
types (XML element, attribute, text, comment, pi). Maybe those could be added to the
existing UsageTypes? It doesn't seem possible to get rid of this whole grouping rule and
to replace it with a custom one either.
Sascha
Hello Sascha,
SW> Another question: After a quick glance, it doesn't seem possible to
SW> add custom usage types to group by. I'd like to get rid of this
SW> "unclassified usage" node and provide my own types (XML element,
SW> attribute, text, comment, pi). Maybe those could be added to the
SW> existing UsageTypes? It doesn't seem possible to get rid of this
SW> whole grouping rule and to replace it with a custom one either.
You can register an ApplicationComponent which implements the UsageGroupingRuleProvider
interface, and return your own implementation of grouping rules. They will
work in addition to the standard IDEA rules, so the user will need to turn
off the standard rules manually in order to get sensible results.
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"
Dmitry Jemerov (JetBrains) wrote:
Yes, I found that one...
... but I think the usability of this is severely limited, especially because the Usage
View remembers the settings of those rules across invocations. Without the ability to turn
off/filter useless standard grouping rules, this would be too confusing. I'm gonna file an
issue about this.
Sascha
Ok, this stuff is harder to understand than one would expect:
UsageViewPresentation.setCodeUsages(false);
does not indicate that I only want to have Code Usages displayed, but it specifies the
mode the Usage View is displaying all my usages in. If this is set to false, all
buttons for in my case useless grouping rules disappear. Good. However, even though not
shown, the rules are still applied to the results with the settings that were in use from
e.g. a previous "normal" Find Usages invocation. I believe this is a bug, isn't it?
The problem seems to be the difference between createGroupingActions() and
getActiveRules() in UsageGroupProvider(Impl). While the action-creation knows the context
(the UsageView parameter), the query for the active rules doesn't. IMHO that's wrong and
both methods should be provided with the UsageView instance and filter according to the
setting of UsageViewPresentation.isCodeUsages().
The API would be even better if it didn't allow inconsistent Action/Rule combinations.
This could be done by moving the Action-creation into UsageGroupingRule.
Sascha
Attachment(s):
after.PNG
before.PNG
Just filed http://www.jetbrains.net/jira/browse/IDEA-4292