Eclipse Plugin Development : Eclipse Capabilities
Presently I am working on eclipse plugin development and I have come across interesting feature available in Eclipse IDE, that is Capabilities.
Internally Eclipse capabilities feature is known as Activities. Activities are designed to solve scaling problem when large no of plug-ins are used together.
Eclipse Activities address following functionalities
- Grouping of functionalities
- Enabling/Disabling group of functionalities (Categories) or individual (Activity).
- Filter Mechanisms for managing large set of UI features
- User Roll based features managements
Category: A category is simply a container for one or more activities. It allows to group set of related activities together.
Activity: Activity represent functionality (may represent group of functionalities). An activity-pattern binding associates an activity with a regular expression that is used to match identifiers. When an activity is enabled, all functionality that matches the identifier patterns associated with that activity will be visible.
For example: By default eclipse define few categories as well as activities, which are available under Window>>Preferences>> General>>Capabilities option
Plugin developer can also introduce capabilities for their plugins by extending “org.eclipse.ui.activities”.
Lets create plugins, contributes to menu bar and toolbar and introduce capability for each of plugins to explain how it can be done.
Create plugin project and introduced menu item and toolbar item. Here is the plugin.xml for both projects
plugin.xml for com.ydtech.plugin1
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.commands">
<command
categoryId="com.ydtech.plugin1.category1"
defaultHandler="com.ydtech.plugin1.Handler1"
description="Command 1"
id="com.ydtech.plugin1.command1"
name="Command 1">
</command>
<category
description="Plugin 1"
id="com.ydtech.plugin1.category1"
name="plugin1">
</category>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
id="com.ydtech.plgin1.menu.plugin1"
label="Plugin 1"
tooltip="Plugin 1">
<command
commandId="com.ydtech.plugin1.command1"
icon="icons/sample.gif"
id="com.ydtech.plugin1.menu.plugin1.command1"
style="push">
</command>
</menu>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="com.ydtech.plugin1.toolbar.plugin1">
<command
commandId="com.ydtech.plugin1.command1"
icon="icons/sample.gif"
label="Command 1"
style="push">
</command>
</toolbar>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="com.ydtech.plugin1.command1"
contextId="org.eclipse.ui.contexts.window"
schemeId="com.ydtech.plugin1.key1"
sequence="Ctrl+Shift+1">
</key>
</extension>
<extension
point="org.eclipse.ui.activities">
<category
description="PLugin 1 Contribution"
id="com.ydtech.plugin1.activities.category1"
name="Plugin 1">
</category>
<activity
id="com.ydtech.plugin1.activity1"
name="Plugin1 Devlopment">
</activity>
<activityPatternBinding
activityId="com.ydtech.plugin1.activity1"
isEqualityPattern="true"
pattern="com.ydtech.plugin1.*">
</activityPatternBinding>
<categoryActivityBinding
activityId="com.ydtech.plugin1.activity1"
categoryId="com.ydtech.plugin1.activities.category1">
</categoryActivityBinding>
</extension>
</plugin>
Here I have extended org.eclipse.ui.activities extension-point to define Category & Activity corresponding to com.ydtech.plugin1 contributions.
Here I have given simple implementation for Command Handler
package com.ydtech.plugin1;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.handlers.HandlerUtil;
public class Handler1 implements IHandler {
@Override
public void addHandlerListener(IHandlerListener handlerListener) {
}
@Override
public void dispose() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// TODO Auto-generated method stub
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Infomration", "Command 1 is Selected.");
return null;
}
@Override
public boolean isEnabled() {
return true;
}
@Override
public boolean isHandled() {
return true;
}
@Override
public void removeHandlerListener(IHandlerListener handlerListener) {
}
}
plugin.xml for com.ydtech.plugin2
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.actionSets">
<actionSet
description="Action Set 1"
id="com.ydtech.plugin2.actionSet1"
label="Plugin 2 ActionSet"
visible="true">
<menu
id="com.ydtech.plugin2.menu.menu1"
label="Plugin 2"
path="menu:org.eclipse.ui.main.menu">
<separator
name="additions">
</separator>
<groupMarker
name="content">
</groupMarker>
</menu>
<action
class="com.ydtech.plugin2.Action1"
id="com.ydtech.plugin2.action1"
label="Action 1"
menubarPath="com.ydtech.plugin2.menu.menu1/content"
style="push"
toolbarPath="Normal/additions">
</action>
</actionSet>
</extension>
<extension
point="org.eclipse.ui.activities">
<category
id="com.ydtech.plugin2.activities.category2"
name="Plugin 2 Contribution">
</category>
<activity
id="com.ydtech.plugin2.activity1"
name="Plugin 2 Development">
</activity>
<activityPatternBinding
activityId="com.ydtech.plugin2.activity1"
isEqualityPattern="true"
pattern="com.ydtech.plugin2.*">
</activityPatternBinding>
<categoryActivityBinding
activityId="com.ydtech.plugin2.activity1"
categoryId="com.ydtech.plugin2.activities.category2">
</categoryActivityBinding>
</extension>
</plugin>
Similar to previous plugin.xml, Category and Activity has been defined for com.ydtech.plugin2 plugin.
Here is the simple implementation for ActionDelegates
package com.ydtech.plugin2;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
public class Action1 implements IWorkbenchWindowActionDelegate {
private IWorkbenchWindow window ;
@Override
public void run(IAction action) {
MessageDialog.openInformation(window.getShell(), "Infomration", "Action 1 is Selected.");
}
@Override
public void selectionChanged(IAction action, ISelection selection) {
}
@Override
public void dispose() {
}
@Override
public void init(IWorkbenchWindow window) {
this.window = window;
}
}
Following figure shows mapping between Category and Activity
Try Plugin1 & Plugin 2 capabilities unselected , al contributions from these plugins will be disappeared from UI
Dear one! You simply rock!
ReplyDelete:)
ReplyDeleteWow great information about toolbar development. Hire toolbar developer exhaustive analysis is capable of reshaping toolbar solutions with accuracy and precision. Here, cutting-edge technology in collaboration with cost-efficient methods is the stand-out corner for toolbar developer.
ReplyDelete