I'm building a plugin that display images with some exclusive style.
Think something like you've got an colour image, and you can choose style "Black and white" or "Sepia" etc..
My plugin is like this:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.commands">
<command
categoryId="fr.comp.app.category"
defaultHandler="fr.comp.common.styles.impl.DefaultStyle"
id="fr.comp.common.styles.defaultStyle"
name="Default Style">
<state
class="org.eclipse.ui.handlers.RadioState"
id="org.eclipse.ui.commands.radioState">
</state>
</command>
<command
categoryId="fr.comp.app.category"
defaultHandler="fr.comp.common.styles.impl.SepiaStyle"
id="fr.comp.common.styles.SepiaStyle"
name="Print Style">
<state
class="org.eclipse.ui.handlers.RadioState"
id="org.eclipse.ui.commands.radioState">
</state>
</command>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="fr.comp.common.styles.defaultStyle"
contextId="org.eclipse.ui.contexts.window"
schemeId="fr.comp.app.scheme"
sequence="F1">
</key>
<key
commandId="fr.comp.common.styles.SepiaStyle"
contextId="org.eclipse.ui.contexts.window"
schemeId="fr.comp.app.scheme"
sequence="F6">
</key>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="fr.comp.app.style.toolbar">
<command
commandId="fr.comp.common.styles.defaultStyle"
icon="resources/default.png"
style="radio">
</command>
<command
commandId="fr.comp.common.styles.SepiaStyle"
icon="resources/sepia.png"
style="radio">
</command>
</toolbar>
</menuContribution>
</extension>
</plugin>
My Handlers execute look like this:
public Object execute(ExecutionEvent event) throws ExecutionException {
// blabla change the style
final IStyleManager styleManager = MagicHub.getService(IStyleManager.class);
// ... end blabla
// change the state of the org.eclipse.ui.commands.radioState of the cmd
Command command = event.getCommand();
State state = command.getState(RadioState.STATE_ID);
state.setValue(Boolean.TRUE);
return null;
}
Ok, now I've got a nice toolbar, that display my commands.
I can click them, and the style apply.
I can use my keybinding too, and the style apply too.
But, when I use keybinding, radios button is not toggle properly.
What am I doing wrong ?
BTW: my target platform is Kepler.
Related
in my custom editor I want that the handler is only activated when it it is executed within the editor.
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.editors">
<editor
id="testingpluginproject.editors.XMLEditor"
name="Sample XML Editor"
icon="icons/sample.png"
extensions="xxml"
class="testingpluginproject.editors.XMLEditor"
contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor">
</editor>
</extension>
<extension
point="org.eclipse.ui.contexts">
<context
id="com.my.ui.definition.activatedEditorContext"
name="Editor Context"
parentId="org.eclipse.ui.textEditorScope">
</context>
</extension>
<extension point="org.eclipse.ui.commands">
<command id="com.my.handler" name="Hello"/>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler commandId="com.my.handler" class="com.my.handler.HelloHandler"/>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="com.my.handler"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="com.my.ui.definition.activatedEditorContext"
sequence="Ctrl+7">
</key>
</extension>
</plugin>
Here is the activation in the editor.
public XMLEditor() {
colorManager = new ColorManager();
setSourceViewerConfiguration(new XMLConfiguration(colorManager));
setDocumentProvider(new XMLDocumentProvider());
IContextService contextService = (IContextService) PlatformUI
.getWorkbench().getService(IContextService.class);
contextService.activateContext("com.my.ui.definition.activatedEditorContext");
}
So I think antyhing went wrong in the configuration of the plugin.xml.
In a text editor you don't use the context service for this. Instead you override AbstractDecoratedTextEditor#initializeKeyBindingScopes and set the key binding scope:
/*
* #see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeKeyBindingScopes()
*/
#Override
protected void initializeKeyBindingScopes() {
setKeyBindingScopes(new String[] { "com.my.ui.definition.activatedEditorContext" });
}
Which ends up using IKeyBindingService
I have a plug-in with two views. Currently if I want to add the views I go to Window -> Show View -> Other.
The problem is, the two view show under separate folders (ImageView and MemoryView). How do I get them to display under the same folder?
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<category
name="ImageView"
id="ImageView">
</category>
<view
name="ImageView"
icon="icons/sample.gif"
category="ImageView"
class="imageplugin.views.ImageView"
id="imageplugin.views.ImageView">
</view>
</extension>
<extension
point="org.eclipse.ui.views">
<category
name="MemoryView"
id="MemoryView">
</category>
<view
name="MemoryView"
icon="icons/sample.gif"
category="MemoryView"
class="imageplugin.views.MemoryView"
id="imageplugin.views.MemoryView">
</view>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="org.eclipse.jdt.ui.JavaPerspective">
<view
ratio="0.5"
relative="org.eclipse.ui.views.ProblemView"
relationship="right"
id="imageplugin.views.ImageView">
</view>
<view
ratio="0.5"
relative="org.eclipse.ui.views.ProblemView"
relationship="right"
id="imageplugin.views.MemoryView">
</view>
</perspectiveExtension>
</extension>
<extension
point="org.eclipse.help.contexts">
<contexts
file="contexts.xml">
</contexts>
</extension>
</plugin>
Your view org.eclipse.ui.views definitions have asked for the views to be in different categories by defining two different category entries. Just use a single category for both views to show them together, you do not have a define a separate category for each view:
<extension
point="org.eclipse.ui.views">
<category
name="My Category"
id="my.view.category">
</category>
<view
name="ImageView"
icon="icons/sample.gif"
category="my.view.category"
class="imageplugin.views.ImageView"
id="imageplugin.views.ImageView">
</view>
<view
name="MemoryView"
icon="icons/sample.gif"
category="my.view.category"
class="imageplugin.views.MemoryView"
id="imageplugin.views.MemoryView">
</view>
</extension>
In my current project, I have created popup menus using eclipse plugin. Following is the code of plugin.xml.
<?xml version="1.0" encoding="windows-1252"?>
<?eclipse version="3.0"?>
<plugin>
<extension point="org.eclipse.emf.ecore.generated_package">
<package
uri = "http://www.xtext.org/example/mydsl/MyDsl"
class = "org.xtext.example.mydsl.myDsl.MyDslPackage"
genModel = "model/generated/MyDsl.genmodel" />
</extension>
<extension
point="org.eclipse.ui.popupMenus">
<objectContribution
id="org.xtext.example.mydsl.contribution1"
objectClass="org.eclipse.core.resources.IFile">
<menu
id="org.xtext.example.mydsl.menu1"
label="IoTSuite Compilation"
path="additions">
<separator
name="group1">
</separator>
</menu>
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<test
property="org.eclipse.core.resources.IFile"
value="vocab.mydsl">
<action
class="org.xtext.example.mydsl.popup.actions.CompileVocabSpec"
enablesFor="1"
id="org.xtext.example.mydsl.newAction"
label="Compile Vocab.mydsl"
menubarPath="org.xtext.example.mydsl.menu1/group1">
</action>
</test>
</iterate>
</visibleWhen>
<action
class="org.xtext.example.mydsl.popup.actions.CompileArchSpec"
enablesFor="1"
id="org.xtext.example.mydsl.newAction"
label="Compile Arch.mydsl"
menubarPath="org.xtext.example.mydsl.menu1/group1">
</action>
<action
class="org.xtext.example.mydsl.popup.actions.CompileInteractionSpec"
enablesFor="1"
id="org.xtext.example.mydsl.newAction"
label="Compile Interaction.mydsl"
menubarPath="org.xtext.example.mydsl.menu1/group1">
</action>
<action
class="org.xtext.example.mydsl.popup.actions.CompileDeploySpec"
enablesFor="1"
id="org.xtext.example.mydsl.newAction"
label="Compile Deploy.mydsl"
menubarPath="org.xtext.example.mydsl.menu1/group1">
</action>
</objectContribution>
When I run above eclipse plugin application, it displays popup-menu as follows.Click here for image. The problem is, as shown in image I have four files vocab.mydsl, arch.mydsl, userinteraction.mydsl and deploy.mydsl and also four actions (Compile Vocab.mydsl, Compile Arch.mydsl, Compile Interaction.mydsl and Compile Deploy.mydsl ) under a popup menu. Now I want to customize action in such way that, when I click on vocab.mydsl then it should display only Compile Vocab.mydsl as an action in popup menu similarly when I click in arch.mydsl than it should display only Compile Arch.mydsl etc. I have made changes as per suggestion, but it display error like MESSAGE Plugin org.xtext.example.mydsl, extension org.eclipse.ui.popupMenus: Unknown extension tag found: visibleWhen. Am I missing something ??
Edit
Finally partial problem is solved using comment. Content of updated plugin.xml file is as below:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu">
<command
commandId="org.xtext.example.mydsl.popup.actions.CompileVocabSpec"
defaultHandler="org.xtext.example.mydsl.popup.actions.CompileVocabSpec"
label="Compile Vocab"
style="push">
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<test
property="org.eclipse.core.resources.name"
value="vocab.mydsl">
</test>
</iterate>
</visibleWhen>
</command>
<command
commandId="org.xtext.example.mydsl.popup.actions.CompileArchSpec"
defaultHandler="org.xtext.example.mydsl.popup.actions.CompileArchSpec"
label="Compile Arch"
style="push">
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<test
property="org.eclipse.core.resources.name"
value="arch.mydsl">
</test>
</iterate>
</visibleWhen>
</command>
</menuContribution>
</extension>
</plugin>
I am very new to this eclipse plugin development. When I fired Compile Vocab command than it should performed action mentioned in CompileVocabSpec.java. The content of CompileVocabSpec.java is as below:
package org.xtext.example.mydsl.popup.actions;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
public class CompileVocabSpec implements IObjectActionDelegate {
private Shell shell;
/**
* Constructor for Action1.
*/
public CompileVocabSpec() {
super();
}
/**
* #see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
#Override
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
shell = targetPart.getSite().getShell();
}
/**
* #see IActionDelegate#run(IAction)
*/
#Override
public void run(IAction action) {
String[] args = new String[3];
args[0] = "compile-vocab-spec";
args[1] = "C:/Template/";
// Call to Main method in ToolSuite
try {
// Main.main(args);
System.out.println("Compilation of Vocab");
} catch (Exception e) {
e.printStackTrace();
}
;
}
/**
* #see IActionDelegate#selectionChanged(IAction, ISelection)
*/
#Override
public void selectionChanged(IAction action, ISelection selection) {
}
}
Here when I fired Compile Vocab command it doesn't performed any action. Am I missing something ??
The org.eclipse.ui.popupMenus is deprecated and has been for a long time. You can only set visibility for the entire objectContribution and I don't think you can specify a single file name.
The org.eclipse.ui.menus extension point allows visibility of individual commands to be controlled.
For example:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any">
<command
commandId="test.command"
label="Command Vocab"
style="push">
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<test
property="org.eclipse.core.resources.name"
value="vocab.mydsl">
</test>
</iterate>
</visibleWhen>
</command>
</menuContribution>
The visibleWhen element is restricting the visibility to just the 'vocab.mydsl' file.
I am looking for a solution of "link with editor" but for FormEditor instead of ViewPart as described in http://murygin.wordpress.com/2012/06/13/link-eclipse-view-to-editor/
I try to do similar. But the "link with editor" does not fire any action.
Thanks for help!
I found out that I could use "Navigator Link Helper":
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_ui_navigator_linkHelper.html
Hier is my code in plugin.xml:
<extension point="org.eclipse.ui.navigator.viewer">
...
<viewerContentBinding ...>
<includes>
<contentExtension pattern="my.ui.navigator.linkHelper.myExplorer"/>
</includes>
</viewerContentBinding>
...
</extension>
<extension point="org.eclipse.ui.navigator.linkHelper">
<linkHelper
class="my.ui.navigator.MyExplorerLinkHelper"
id="my.ui.navigator.linkHelper.myExplorer">
<selectionEnablement>
<or>
<adapt type="org.eclipse.core.resources.IProject"/>
<instanceof value="org.eclipse.core.resources.IProject"/>
</or>
</selectionEnablement>
<editorInputEnablement>
<or>
<adapt type="org.eclipse.core.resources.IProject"/>
<instanceof value="org.eclipse.core.resources.IProject"/>
</or>
</editorInputEnablement>
</linkHelper>
</extension>
I implemented the class:
public class MyExplorerLinkHelper implements ILinkHelper {
#Override
public IStructuredSelection findSelection(IEditorInput anInput) {
...
}
#Override
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
...
}
}
So i have a class like this:
public class A {
...
public static class B {
...
}
}
And i have a handler in my rcp application defined like this:
<extension
point="org.eclipse.ui.handlers">
<handler
class="HandlerClass"
commandId="commandId">
<activeWhen>
<with
variable="selection">
<iterate
ifEmpty="false">
<instanceof
value="A.B">
</instanceof>
</iterate>
<count
value="1">
</count>
</with>
</activeWhen>
</handler>
</extension>
The instanceof part doesnt work. What i want to do is to check if the items in the selection variable are of type B. Is this possible?
You can use Property Testers, to check programmatically if a handler is active.
Check this blog entry: Me, myself and Property Testers