I need to add a pulldown button to a view's toolbar in an Eclipse plugin.
Actually buttons in the toolbar are added like that :
<extension point="org.eclipse.ui.viewActions">
<viewContribution id="..." targetId="$MyViewId$">
<action id="..."
toolbarPath="action1"
class="Class extending Action and implementing IViewActionDelegate">
</action>
</viewContribution>
</extension>
I've figured it out. Two ways: one using org.eclipse.ui.viewActions extension, the other with org.eclipse.ui.menus
Using org.eclipse.ui.viewActions extension (eclipse >= 3.5)
action's style must set to pulldown
<extension point="org.eclipse.ui.viewActions">
<viewContribution id="..." targetId="$MyViewId$">
<action id="..."
toolbarPath="action1"
class="xxx.MyAction"
style="pulldown">
</action>
</viewContribution>
</extension>
action class must implement IViewActionDelegate (required for an action contributing to a view toolbar) and IMenuCreator (defines the menu behavior).
public class RetrieveViolationsViewActionDelegate implements IViewActionDelegate, IMenuCreator
{
private IAction action;
private Menu menu;
// IViewActionDelegate methods
...
// IMenuCreator methods
public void selectionChanged(IAction action, ISelection selection)
{
if (action != this.action)
{
action.setMenuCreator(this);
this.action = action;
}
}
public void dispose()
{
if (menu != null)
{
menu.dispose();
}
}
public Menu getMenu(Control parent)
{
Menu menu = new Menu(parent);
addActionToMenu(menu, new ClassImplemententingIAction());
return menu;
}
public Menu getMenu(Menu parent)
{
// Not use
return null;
}
private void addActionToMenu(Menu menu, IAction action)
{
ActionContributionItem item= new ActionContributionItem(action);
item.fill(menu, -1);
}
}
Using org.eclipse.ui.menus (eclipse >= 3.3)
Add a new menucontribution to the org.eclipse.ui.menus extension point.
Set the location URI to toolbar:IdOfYourView
Add a toolbar to this extension and a new command to this new toolbar.
Change the command style to pulldown
Create a new menucontribution and set the locationURI to menu:IdOfThePullDownCommand
Add commands to this menu.
More info
Related
I have a eclipse application which contributes to "org.eclipse.ui.menus" to add toolbar menu items dynamically in org.eclipse.ui.main.toolbar.
it was working fine with 3.8
Recently I migrated my application to eclipse 4.6. After migration toolbar menus are not visible and what I observed is class specified in extension point in not getting invoked.
Is there any other way to achieve same functionality?
following is code I am using :
public class ToolbarProvider extends ExtensionContributionFactory
{
public ToolbarProvider()
{
}
#Override
public void createContributionItems( IServiceLocator serviceLocator, IContributionRoot additions )
{
ToolBarContributionItem toolbar = new ToolBarContributionItem( );
additions.addContributionItem( toolbar, null );
CommandContributionItemParameter p = new CommandContributionItemParameter( serviceLocator, "", "org.eclipse.ui.file.exit",
SWT.PUSH );
p.label = "Exit";
p.icon = Activator.getImageDescriptor( "icons/alt_window_16.gif" );
CommandContributionItem item = new CommandContributionItem( p );
item.setVisible( true );
toolbar.getToolBarManager().add( item );
}
}
code in plugin.xml :
<extension point="org.eclipse.ui.menus">
<menuContribution
class="server.ui.ToolbarContributionFactory"
locationURI="toolbar:org.eclipse.ui.main.toolbar"
</menuContribution>
</extension>
I realised that storyboard only working with silverlight Wp 8.1 apps. So what about non-silverlight? I've want to make an animation of smooth appearing elements of listview after page transition. How can i make it? I check VisualStateGroup, but to make animation like that i should make a code behind. Is it possible to make only by XAML?
If you want to use XAML you can use the built in transitions which you can choose from already predefined ones. One drawback is that you can't create your own transitions this way.
To change the item transitions change the ItemContainerTransitions property on your ListView:
<ListView x:Name="MyListView">
<ListView.ItemContainerTransitions>
<TransitionCollection>
<!--<ContentThemeTransition HorizontalOffset="0"/>-->
<!--<EntranceThemeTransition />-->
<!-- <AddDeleteThemeTransition /> -->
<!-- <RepositionThemeTransition/> -->
<!-- <ReorderThemeTransition /> -->
<!-- <PopupThemeTransition/> -->
<!-- <EdgeUIThemeTransition Edge="Top"/> -->
</TransitionCollection>
</ListView.ItemContainerTransitions>
</ListView>
You can combine them if you want. Just uncomment any of the above code and use which suits you best.
You can create custom item animations when you extend ListView and override the GetContainerForItemOverride or PrepareContainerForItemOverride methods. You can use XAML if you want for example a Storyboard defined in as a StaticResource. Here is an example:
public class MyListView : ListView
{
protected override DependencyObject GetContainerForItemOverride()
{
var container = base.GetContainerForItemOverride();
var da = new DoubleAnimation();
// init da...
var sb = new Storyboard();
// initi sb with container
sb.Begin();
return container;
}
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
base.PrepareContainerForItemOverride(element, item);
var da = new DoubleAnimation();
// init da...
var sb = new Storyboard();
// initi sb with element
sb.Begin();
}
}
I am using WizardNewFileCreationPage to create a New File
public void addPages() {
mainPage = new WizardNewFileCreationPage("FILE", getSelection());
mainPage.setTitle("New File");
mainPage.setDescription("Add new file");
addPage(mainPage);
}
I want to add some Radio Buttons to it representing file extensions in this wizard so that users can select one of them as a file extension.
The WizardNewFileCreationPage is not meant to be extended with custom controls. From its JavaDoc:
Subclasses may override
getInitialContents
getNewFileLabel
Subclasses may extend
handleEvent
If you still want to add the radio buttons 'at your own risk', you can try to override createAdvancedControls and append you controls to the parent after calling super.
protected void createAdvancedControls(Composite parent) {
super.createAdvancedControls( parent );
Button radioButton = new Button( parent, SWT.RADIO );
// ...
}
Note that the layout of parent (currently) is a single-columned GridLayout, set the layout data accordingly.
I am trying to use toggle menu option but probably doing some mistake. Following code created toggle menu item and When I click this option for the first time after loading, it works fine but when I click again to toggle it back to old state, I get following error:
org.eclipse.core.commands.NotHandledException: There is no handler to execute for command my.commands.compileAutomatically
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:485)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
....
Menu:
<command
commandId="my.commands.compileAutomatically"
label="Compile Automatically"
style="toggle">
</command>
Command:
<command
defaultHandler="my.handlers.CompileAutomaticallyHandler"
id="my.commands.compileAutomatically"
name="Compile Automatically">
<state
class="org.eclipse.ui.handlers.RegistryToggleState:true"
id="org.eclipse.ui.commands.toggleState">
</state>
</command>
Handler:
public class CompileAutomaticallyHandler extends AbstractHandler {
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Command command = event.getCommand();
boolean oldValue = HandlerUtil.toggleCommandState(command);
System.out.println(oldValue);
return null;
}
}
Could somebody help me understand what is wrong with my code that it finds handler only once regardless of current menu state?
thanks
Try to override isHandled() and return false in CompileAutomaticallyHandler.
I'm extending Eclipse using the Eclipse plugin infrastructure, and I've come into a problem:
I created a text editor and I would like to add actions to the Eclipse toolbar when my editor is open and has focus. For example:
textViewer.getTextWidget().addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e) {
/* add actions */
}
public void focusLost(FocusEvent e) {
/* remove actions */
}
});
The following example of extensionPoint: ActionSet, add the action button to the toolbar permanently:
<action
class="MyActionClass"
id="MyActionID"
label="MyActionLabel"
menubarPath="MyActionMenuBarPath"
toolbarPath="MyActionToolBarPath" <-- this property
...
</action>
how to make this dynamically?
Thank you for your response, I found a simple way to do this, simply add the following extension point if the buttons are ActionSet:
<extension
point="org.eclipse.ui.actionSetPartAssociations">
<actionSetPartAssociation
targetID="myActionSetId">
<part
id="myEditorId">
</part>
</actionSetPartAssociation>
You could look at the Eclipse implementation of similar dynamic toolbar updates.
For example, the Breadcrumb bare can only be activated for Java Editor, and the toolbar "Toggle Breadcrumb" button will not be visible for any other type of editors.
alt text http://img109.imageshack.us/img109/359/eclipsetoolbarupdate.png
That is a ToggleBreadcrumbAction, declared in plugin.xml as
<actionSet
label="%javaEditorPresentationActionSet.label"
visible="false"
id="org.eclipse.jdt.ui.text.java.actionSet.presentation">
<action
allowLabelUpdate="true"
style="toggle"
toolbarPath="org.eclipse.ui.edit.text.actionSet.presentation/Presentation"
id="org.eclipse.jdt.ui.edit.text.java.toggleMarkOccurrences"
definitionId="org.eclipse.jdt.ui.edit.text.java.toggleMarkOccurrences"
disabledIcon="$nl$/icons/full/dtool16/mark_occurrences.gif"
icon="$nl$/icons/full/etool16/mark_occurrences.gif"
helpContextId="toggle_mark_occurrences_action_context"
label="%toggleMarkOccurrences.label"
retarget="true"
tooltip="%toggleMarkOccurrences.tooltip">
</action>
<action
allowLabelUpdate="true"
style="toggle"
toolbarPath="org.eclipse.ui.edit.text.actionSet.presentation/Presentation"
id="org.eclipse.jdt.ui.edit.text.java.toggleBreadcrumb"
definitionId="org.eclipse.jdt.ui.edit.text.java.toggleBreadcrumb"
disabledIcon="$nl$/icons/full/dtool16/toggle_breadcrumb.gif"
icon="$nl$/icons/full/etool16/toggle_breadcrumb.gif"
helpContextId="toggle_mini_browser_action_context"
label="%toggleBreadcrumb.label"
retarget="true"
tooltip="%toggleBreadcrumb.tooltip">
</action>
</actionSet>
You can try the same kind of definition.