Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Add command button to Eclipse view toolbar without using viewer
Add command button to Eclipse view toolbar without using viewer [message #1830399] Fri, 24 July 2020 20:39 Go to next message
Katya Doersam is currently offline Katya DoersamFriend
Messages: 26
Registered: June 2020
Junior Member
I am trying to create an Eclipse PDE plugin that has a view with a button in the view's tool bar. The view is intended to display text, which will change format when the toolbar button is clicked. I have been trying to work around using a viewer, because none of the viewers match fit my needs. I followed this SO post for reference but have not been able to get the function to work. Is there something wrong with my plugin.xml file? I added the ID of the view as the location URI for the menu contribution, but the plugin is not showing the button in the toolbar as intended.

I have added my plugin.xml, ViewPart class and package structure below for your reference:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         point="org.eclipse.ui.views">
      <category
            name="Sample Category"
            id="asher">
      </category>
      <view
            id="asher.views.id.SampleView"
            name="Sample View"
            icon="icons/daffodil.png"
            class="asher.views.SampleView"
            category="asher"
            inject="true">
      </view>
   </extension>
   <extension
         point="org.eclipse.ui.perspectiveExtensions">
      <perspectiveExtension
            targetID="org.eclipse.jdt.ui.JavaPerspective">
         <view
               id="asher.views.id.SampleView"
               relative="org.eclipse.ui.views.ProblemView"
               relationship="right"
               ratio="0.5">
         </view>
      </perspectiveExtension>
   </extension>
   <extension
         point="org.eclipse.help.contexts">
      <contexts
            file="contexts.xml">
      </contexts>
   </extension>
      <extension
         point="org.eclipse.ui.commands">
      <category
            id="asher.commands.category"
            name="Parse Category">
      </category>
      <command
            categoryId="asher.commands.category"
            name="Parse"
            id="asher.commands.parseCommand">
      </command>
     <category
            id="asher.commands.unparse.category"
            name="Unparse Category">
     </category>
     <command
            categoryId="asher.commands.unparse.category"
            name="UnParse"
            id="asher.commands.unparseCommand">
      </command>
   </extension>
   <extension
         point="org.eclipse.ui.handlers">
      <handler
            class="asher.handlers.ParseHandler"
            commandId="asher.commands.parseCommand">
      </handler>
      <handler
            class="asher.handlers.UnparseHandler"
            commandId="asher.commands.unparseCommand">
      </handler>
   </extension>
    <extension
         point="org.eclipse.ui.bindings">
      <key
            commandId="asher.commands.parseCommand"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            contextId="org.eclipse.ui.contexts.window"
            sequence="M1+6">
      </key>
      <key
            commandId="asher.commands.unparseCommand"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            contextId="org.eclipse.ui.contexts.window"
            sequence="M1+7">
      </key>
      </extension>
     <extension
         point="org.eclipse.ui.menus">
    <menuContribution
          allPopups="true"
          locationURI="toolbar:asher.views.id.SampleView?after=additions">
         <menu
               id="asher.menus.unparseMenu"
               label="Unparse"
               mnemonic="M">
            <command
                  commandId="asher.commands.unparseCommand"
                  icon="icons/daffodil.png"
                  id="asher.menus.unparseCommand"
                  mnemonic="S"
                  tooltip="Unparse">
            </command>
         </menu>
      </menuContribution>
      </extension>
</plugin>



View Part:

public class SampleView extends ViewPart {
    /**
     * The ID of the view as specified by the extension.
     */
    public static final String ID = "asher.views.SampleView";
    @Inject IWorkbench workbench;
     
    @Override
    public void createPartControl(Composite parent) {
        
        Text text = new Text(parent, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
        
         File file = new File("/Users/user/Desktop/install.json");
         Scanner sc;
        
        try {
            sc = new Scanner(file);
            while (sc.hasNextLine()) 
                  text.setText(text.getText()+"\n"+sc.nextLine()); 
            sc.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    @Override
    public void setFocus() {
    }
}


Re: Add command button to Eclipse view toolbar without using viewer [message #1830405 is a reply to message #1830399] Sat, 25 July 2020 06:28 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31608
Registered: July 2009
Senior Member
That's a pretty detailed question...

This from the platform looks similar:

https://git.eclipse.org/c/platform/eclipse.platform.debug.git/tree/org.eclipse.debug.examples.ui/plugin.xml#n459

But here the command is not embedded in a menu...



Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Eclipse wont install
Next Topic:Eclipse dont find JAVA
Goto Forum:
  


Current Time: Fri Nov 27 00:45:57 GMT 2020

Powered by FUDForum. Page generated in 0.04458 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top