[oXygen-sdk] Custom action for results in search window

Alex Jitianu alex_jitianu at sync.ro
Wed Jan 22 09:30:00 CST 2014


Hi Nathan,

There might be an workaround for you... Using the plugin API you can get 
access to the "Open/Find Resource" view and from there on you can locate 
the JList used to present the results and take a look inside it's model. 
I don't think you can contribute an action to the contextual menu (maybe 
you could remove the mouse listener we use to show the menu and install 
your own instead). Instead, it would be easier to add a new toolbar and 
put an action in it. The code below can be put on the 
applicationStarted() method of an Workspace Access plugin. Hopefully the 
information you can get from the model of the list is enough for what 
your action need to do. Since the method used to get to that information 
is not API I also can't guarantee that the information structure wont 
change in a future Oxygen release.

If you need more information about plugins you can find it starting at: 
http://oxygenxml.com/oxygen_sdk.html#Developer_Plugins

   /**
    * @see 
ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension#applicationStarted(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace)
    */
   @Override
   public void applicationStarted(final StandalonePluginWorkspace 
pluginWorkspaceAccess) {
     pluginWorkspaceAccess.addViewComponentCustomizer(new 
ViewComponentCustomizer() {
       @Override
       public void customizeView(ViewInfo viewInfo) {
         if 
(MainFrameComponentProvider.OPEN_FIND_RESOURCE.equals(viewInfo.getViewID())) 
{
           JPanel component = (JPanel) viewInfo.getComponent();

           // Search for the list.
           final JList list = searchForList(component);

           JPanel newPanel = new JPanel(new BorderLayout());
           newPanel.add(component, BorderLayout.CENTER);
           JPanel northPanel = new JPanel();
           JButton button = new JButton("Process Selection");
           button.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
               int[] selectedIndices = list.getSelectedIndices();
               for (int i = 0; i < selectedIndices.length; i++) {
                 int index = selectedIndices[i];
                 org.apache.lucene.document.Document selValue = 
(org.apache.lucene.document.Document) list.getModel().getElementAt(index);
                   // All the information is located in these fields
                 List<org.apache.lucene.index.IndexableField> fields = 
selValue.getFields();
                 for (Iterator<org.apache.lucene.index.IndexableField> 
iterator = fields.iterator(); iterator.hasNext();) {
                   org.apache.lucene.index.IndexableField indexableField 
= iterator.next();
                   String text = selValue.get(indexableField.name());

                   System.out.println(indexableField.name() + " - " + text);
                 }
               }
             }
           });

           northPanel.add(button);
           newPanel.add(northPanel, BorderLayout.NORTH);

           viewInfo.setComponent(newPanel);
         }
       }

       private JList searchForList(JComponent component) {
         JList list = null;
         if (component instanceof JList) {
           list = (JList) component;
         } else {
           int componentCount = component.getComponentCount();
           for (int i = 0; i < componentCount; i++) {
             Component childComponent = component.getComponent(i);
             if (childComponent instanceof JComponent) {
               list = searchForList((JComponent) childComponent);
               if (list != null) {
                 break;
               }
             }
           }
         }

         return list;
       }
     });
}

Best regards,
Alex
-- 
Alex Jitianu
<oXygen/>  XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

On 20-Jan-14 11:11 PM, Nathan wrote:
> Hi Alex,
>    I am looking to perform this action on the results of the 
> "Open/Find Resource" view. So, if a particular "Open/Find Resource" 
> operation retrieved 5 results in the "Open/Find Resource" results and 
> I am interested in 3 out of the 5 results, I would like to select 3 
> out of the 5 and provide a custom action on right click.
>    It looked like there was no way to access to the "Open/Find 
> Resource" search results from the API so I wanted to check.
>
> Regards,
> Nathan
>
>
> _______________________________________________
> oXygen-sdk mailing list
> oXygen-sdk at oxygenxml.com
> http://www.oxygenxml.com/mailman/listinfo/oxygen-sdk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.oxygenxml.com/pipermail/oxygen-sdk/attachments/20140122/59ce0441/attachment.html>


More information about the oXygen-sdk mailing list