<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ADT/Eclipse plug in java development - how to get object selected from outline view of a class in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420525#M1997129</link>
    <description>&lt;P&gt;How exactly does the Adapters.adapt work?&lt;/P&gt;</description>
    <pubDate>Thu, 08 Apr 2021 17:24:24 GMT</pubDate>
    <dc:creator>matt</dc:creator>
    <dc:date>2021-04-08T17:24:24Z</dc:date>
    <item>
      <title>ADT/Eclipse plug in java development - how to get object selected from outline view of a class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420522#M1997126</link>
      <description>&lt;P&gt;I'm developing a plugin that runs on ABAP development objects. It's launched by a run configuration. This is the code that runs when you right click on e.g. a method in a class in the outline view, and select &lt;EM&gt;run as &amp;lt;my_app&amp;gt;&lt;/EM&gt;&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;public class LaunchShortcut implements ILaunchShortcut {
	public void launch(ISelection selection, String mode) {
		new RunAlchemist().run(selection);
	}
}
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;The &lt;EM&gt;run &lt;/EM&gt;method here passes an ISelection instance. I check whether it's an instance of ITreeSelection, as it needs to be cast.&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;ITreeSelection treeSelection = (ITreeSelection) selection;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;ITreeSelection has an interator on it, which I loop over. Each &lt;EM&gt;node &lt;/EM&gt;comes out as type &lt;EM&gt;Object&lt;/EM&gt;. Now, if its real type is IAdtOutlineTreeNode, I can use&lt;EM&gt; node.toString&lt;/EM&gt; to get the name and type (which yields type method and the name of the method), but for the class name, I need the parent node so I can use &lt;EM&gt;parent.toString().&lt;/EM&gt;&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;Object parent = ((IAdtOutlineTreeNode) node).getParent()&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;The problem is that IAdtOutlineTreeNode is &lt;EM&gt;"Discouraged access: The type 'IAdtOutlineTreeNode' is not API"&lt;/EM&gt;&lt;/P&gt;
  &lt;P&gt;Can anyone tell me how I can determine from ISelection the class and method name selected?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 08:06:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420522#M1997126</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2021-04-08T08:06:10Z</dc:date>
    </item>
    <item>
      <title>Re: ADT/Eclipse plug in java development - how to get object selected from outline view of a class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420523#M1997127</link>
      <description>&lt;P&gt;Hi Matthew,&lt;/P&gt;&lt;P&gt;if you want a way where you don't use non API classes you could try the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; ITreeSelection treeSel = (ITreeSelection) sel;

 for (Object node : treeSel) {
   System.out.println("Selected Node info:");
   TreePath[] paths = treeSel.getPathsFor(node);

   for (TreePath path : paths) {
     /*
      * the segments are sorted from top to bottom. the last segment should be the
      * selected node in the tree.
      */
      for (int i = path.getSegmentCount() - 1; i &amp;gt;= 0; i--) {
        Object segment = path.getSegment(i);

        IAdtObjectReference objRef = Adapters.adapt(segment, IAdtObjectReference.class);
        if (objRef != null) {
          System.out.printf("Type: %s, Name: %s\n", objRef.getType(), objRef.getName());
        }
      }
   }
} &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1911513-sybbf.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1911514-9w1vr.png" /&gt;&lt;/P&gt;&lt;P&gt; I hope this helps :).&lt;/P&gt;&lt;P&gt;P.S.: I sometimes have to use non API classes because there was no other way. I don't like it but I think it is better than using something like reflection because in that case you get immediate feedback if you test your coding against an updated version of the used plugin coding.&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;BR /&gt;Ludwig&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 14:06:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420523#M1997127</guid>
      <dc:creator>stockbal</dc:creator>
      <dc:date>2021-04-08T14:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: ADT/Eclipse plug in java development - how to get object selected from outline view of a class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420524#M1997128</link>
      <description>&lt;P&gt;Absolutely perfect.&lt;/P&gt;&lt;P&gt;I'd got to the segments a few hours ago, - one of those things were stepping back a little and looking again at what's being passed to the method - but &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;    IAdtObjectReference objRef = Adapters.adapt(segment, IAdtObjectReference.class);&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;completes it!&lt;/P&gt;&lt;P&gt;Many thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 16:22:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420524#M1997128</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2021-04-08T16:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: ADT/Eclipse plug in java development - how to get object selected from outline view of a class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420525#M1997129</link>
      <description>&lt;P&gt;How exactly does the Adapters.adapt work?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 17:24:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420525#M1997129</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2021-04-08T17:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: ADT/Eclipse plug in java development - how to get object selected from outline view of a class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420526#M1997130</link>
      <description>&lt;P&gt;I will try to explain it on the example i wrote in my answer.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;IAdtObjectReference objRef = Adapters.adapt(segment, IAdtObjectReference.class);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Adaption to the type &lt;STRONG&gt;IAdtObjectReference &lt;/STRONG&gt;is either possible if the type of &lt;STRONG&gt;segment&lt;/STRONG&gt; implements the interface &lt;STRONG&gt;IAdaptable&lt;/STRONG&gt; (prio 1) or if there is an &lt;EM&gt;adapter factory&lt;/EM&gt; (class that implements &lt;STRONG&gt;IAdapterFactory&lt;/STRONG&gt;) for the type &lt;STRONG&gt;IAdtObjectReference.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Adapter factories are registered via extension &lt;STRONG&gt;org.eclipse.core.runtime.adapters&lt;/STRONG&gt; in a plugin&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1912485-adapter-factory-registration.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 18:29:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420526#M1997130</guid>
      <dc:creator>stockbal</dc:creator>
      <dc:date>2021-04-08T18:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: ADT/Eclipse plug in java development - how to get object selected from outline view of a class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420527#M1997131</link>
      <description>&lt;P&gt;Odd. Since I upgraded ADT, I'm getting that use of IAdtObjectReference is discouraged. And that's in the API!&lt;/P&gt;&lt;P&gt;Maybe I just parse the string... (ABAP Favorites plugin does that).&lt;/P&gt;</description>
      <pubDate>Sat, 10 Apr 2021 15:57:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420527#M1997131</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2021-04-10T15:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: ADT/Eclipse plug in java development - how to get object selected from outline view of a class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420528#M1997132</link>
      <description>&lt;P&gt;Oops. Wrong IADTObjectReference. Should be using &lt;/P&gt;&lt;P&gt;com.sap.adt.tools.core.model.adtcore.IAdtObjectReference&lt;/P&gt;</description>
      <pubDate>Tue, 13 Apr 2021 11:19:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/adt-eclipse-plug-in-java-development-how-to-get-object-selected-from/m-p/12420528#M1997132</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2021-04-13T11:19:00Z</dc:date>
    </item>
  </channel>
</rss>

