Hello I am trying to add button the main toolbar in elipse for my plug in.
I successfully add the button to the toolbar,But I fail in connecting this button to function that will open a property page.
This is my code in the xml:
<plugin>
<extension
point="org.eclipse.ui.commands">
<category
name="Sample Category"
id="FirstTextHoverTry.commands.category">
</category>
<command
name="Sample Command"
categoryId="FirstTextHoverTry.commands.category"
id="FirstTextHoverTry.commands.sampleCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="FirstTextHoverTry.commands.sampleCommand"
class="FirstTextHoverTry.SettingPage">
</handler>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="opr.toolbars.sampleToolbar">
<command
commandId="FirstTextHoverTry.Settings.SettingPage.execute"
icon="icons/sample.gif"
tooltip="Say hello world"
id="FirstTextHoverTry.Settings.execute">
</command>
</toolbar>
</menuContribution>
</extension>
</plugin>
The problem is probably in the commandId and id.
I have a "package" call Settings, that includes one class call SettingPage in here is my code of this class: package Settings;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.jface.dialogs.MessageDialog;
public class SettingPage extends AbstractHandler {
public SettingPage() {
}
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openInformation(
window.getShell(),
"hi",
"Need Somthing else probably");
return null;
}
}
Your org.eclipse.ui.handlers
extension point says your handler class is FirstTextHoverTry.SettingPage
- so a class called SettingPage
in the FirstTextHoverTry
package, not the Settings
package. So fix the package name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.