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 and ViewPart class below for your reference:
Plugin.xml:
<?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.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.UnparseHandler"
commandId="asher.commands.unparseCommand">
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<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>
ViewPart Class:
public class SampleView extends ViewPart {
/**
* The ID of the view as specified by the extension.
*/
public static final String ID = "asher.views.id.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() {
}
}
I found a solution to my answer. The change I made was to remove the tag from the for the toolbar.
Here is the fixed plugin.xml section:
<menuContribution
allPopups="true"
locationURI="toolbar:asher.views.id.SampleView?after=additions">
<command
commandId="asher.commands.unparseCommand"
icon="icons/daffodil.png"
id="asher.menus.unparseCommand"
mnemonic="S"
tooltip="Unparse">
</command>
</menuContribution>