I'm having a slight problem with an Eclipse Plug-In in development.
There is a view which is comparabe to a roster. There is a list of users in there. My problem is, that I'd like to add an context menu.
The idea is to perform a right-click on a user and the menu should pop up. So far so good... but the problem is that I don't want a single menu. I'd like to have an entry "set status" to that context menu and when one hovers over this entry the menu should be extended to show stuff like "away" "busy" "invisible" and so on...
Could anyone help me out to achieve this?
I have already implemented the corresponding action and made the addition to the MenuManager.
public SessionViewContextMenu(ViewPart sessionView, TableViewer viewer,
final Action action) {
MenuManager manager = new MenuManager("#PopupMenu");
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
manager.add(action);
}
});
The correspodning action looks like this:
public Action(...) {
super(provider, "Bla Bla");
// some fancy picture
setImageDescriptor(...);
// setId(ACTION_ID);
setToolTipText("Bla Bla");
update();
}
Everything is working fine (at least the context menu shows the entry). Now I'd like to extend the menu when one hovers over / selects the corresponding action. So the menu should extend and show some more possibilites here...
Any help on how to create a recursive context menu is highly appreciated!
Hope, you understand the problem and don't hesitate to ask dor clarification!
Just create a sub-menu and add the actions to this sub-menu.
Here is a quick snippet which should clarify the usage:
// submenu for a specific user
MenuManager subMenu = new MenuManager("Change Status", null);
// Actions for the sub menu
subMenu.add(someAction);
// add the action to the submenu
manager.add(subMenu);
Hope that helps!
Put together:
public SessionViewContextMenu(ViewPart sessionView, TableViewer viewer,
final Action action) {
MenuManager manager = new MenuManager("#PopupMenu");
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
manager.add(action);
// submenu for a specific user
MenuManager subMenu = new MenuManager("Change Status", null);
// Actions for the sub menu
subMenu.add(someAction);
// add the action to the submenu
manager.add(subMenu);
}
});
Related
I am porting my Android app by means of Codename One.
Now I am porting the Dialogs in my app.
I am able to create similar dialogs in the Codename project, adding ActionListeners to the buttons and so on, but I am not able to find the event listener for cancel/dismiss/tap outside event.
The dispose() method has not a corresponding listener, that would be useful.
This is the simplest Dialog, but I have more complex ones too:
public static void openAlertDialog( String s1, String s2)
{
Dialog alertDialog=new Dialog(s1);
Button okButton=new Button("ok");
alertDialog.setLayout(BoxLayout.y());
Container c1=new Container(); //not so useful here but when there are more buttons
c1.setLayout(BoxLayout.x());
alertDialog.add(new SpanLabel(s2, "DialogBody"));
c1.add(okButton);
alertDialog.add(c1);
alertDialog.show();
}
How to have the chance of executing some code when the dialog is dismissed but no buttons were pressed?
You don't even need event listeners for Codename One dialogs. E.g. this code can be written like that:
Dialog alertDialog=new Dialog(s1);
Command ok = new Command("ok");
Button okButton=new Button(ok);
alertDialog.setLayout(BoxLayout.y());
Container c1=new Container(); //not so useful here but when there are more buttons
c1.setLayout(BoxLayout.x());
alertDialog.add(new SpanLabel(s2, "DialogBody"));
c1.add(okButton);
alertDialog.add(c1);
alertDialog.setDisposeWhenPointerOutOfBounds(true);
if(alertDialog.showDialog() == ok) {
// user pressed OK. You can test against other commands than ok as well
} else {
// canceled or clicked outside
}
What I just want is when I clicked the Hamburger then it shows menus list. Now I want when I clicked any menu then my drawerstack and drawser should be hide.
I know how to triggers button likedoClick() but I wanna do know for go through API but didn't successful to find any suitable answer. Could you please share your exprience how I can trigger a Hamburger in javafx.
HamburgerSlideCloseTransition transition = new HamburgerSlideCloseTransition(hamburger);
transition.setRate(-1);
hamburger.addEventHandler(MouseEvent.MOUSE_CLICKED, (e) -> {
transition.setRate(transition.getRate() * -1);
transition.play();
borderpane.setRight(drawersStack);
drawersStack.toggle(rightDrawer);
});
thank you!
As I suggested in the comments, you could make all the buttons from the drawers from a custom class and feature the event handling there, e.g.
class drawerButton extends Button{
public drawerButton(){
addEventHandler(MouseEvent.MOUSE_CLICKED, (e) -> {
//open desired pane (pdf, favorites, etc)
//close the drawer
}
}
}
I need to crate a dynamic list from a String List and use the List-items as a MenuItem Entry. Is this possible like with a loop over the complete list and then
new MenuItem(list-entry, new Command(){} )
After that i want to select it like a checkbox (just the usage not an actual checkbox).
Is my thinking progress reasonable or do i need to rethink everything? grateful for any help, thanks :)
Yes you can loop on it
MenuBar mymenubar = new MenuBar(true);
for(final String string : myListOfStrings){
MenuItem menuItem = new MenuItem(string , new Command() {
#Override
public void execute() {
//Do some thing on each menu
}
});
mymenubar .addItem(menuItem);
}
Selecting like a checkbox(on menu items) is not a good idea.In menu you can select one menu item only at a time.
I need to create a context menu for a TreeViewer in an Eclipse plugin project. But, the menu should not contain constant items, they should vary depending on the type of the node that is selected. For example, my treeViewer has the following hierarchy:
Node A
|
--Node B
|
--Node C
For node A - I want to show a menu with an action, but for nodes B and C I don't want to show anything (no menu).
I managed to create the menu for node A, but then I can't get rid of it when some other type of node is selected. My code looks like:
treeViewer.addSelectionChangedListener(
new ISelectionChangedListener(){
public void selectionChanged(SelectionChangedEvent event) {
if(event.getSelection() instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection)event.getSelection();
Object o = selection.getFirstElement();
MenuManager menuMgr = new MenuManager();
if (o instanceof NodeA){
Menu menu = menuMgr.createContextMenu(treeViewer.getControl());
treeViewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, treeViewer);
menuMgr.add(new SomeAction());
}else {
//what ?
}
}
}
}
);
On the else branch I tried to call dispose(),removeAll() on the MenuManager...nothing works!
Any help is appreciated, thanks.
As #jeeeyul mentioned, you should only create one MenuManager to use within your view.
You can use New>Plug-in Project and the view template to get an example of a context menu in a view using a viewer, but basically in your createPartControl(Composite) method you would hook up your context manager.
MenuManager menuMgr = new MenuManager();
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
SampleView.this.fillContextMenu(manager);
}
});
Menu menu = menuMgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, viewer);
Your fillContextMenu(MenuManager) method will have access to your viewer, so you can get the current selection from that. You can add whatever actions you want, even re-add actions after updating them with the current selection.
The registerContextMenu(*) call allows extension points like org.eclipse.ui.popupMenus and org.eclipse.ui.menus to contribute items to your context menu.
Just use single Menu Manager.
Do not make Menu Manager dynamically.
in theory, It's possible you tried, but it's inefficient and it's not general way.
Just make a Menu Manager and add all actions which you needs.
when selection has been changed, call Action#setVisible(true|false)to hide or show menu items.
You can also use Action#setEnable to enable/disable menu item.
ps.
Menu Manager is not a menu GUI(likes TreeViewer is a not tree)
It contributes Actions(business logic) to Menu(SWT). And It also manage visibility and enablement. We call this Contribution Manager. We can create a SWT menu very easy with this. (even we don't know about SWT, we just have to know only our business logic:Action) It's fundamental idea in JFace.
When you add an action into manu manager, action will be wrapped with ActionContributionItem. It hooks action's state to update UI(visibility, enablement for menu, button, toolbar and so on). It also hooks UI to launch action when it pressed.
If you are new to eclipse, It is easy to confuse role of SWT and JFace.
Thats the way I do it:
MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(viewer.getControl());
menuMgr.addMenuListener(new IMenuListener() {
#Override
public void menuAboutToShow(IMenuManager manager) {
// IWorkbench wb = PlatformUI.getWorkbench();
// IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
if (viewer.getSelection().isEmpty()) {
return;
}
if (viewer.getSelection() instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
Node object = (Node)selection.getFirstElement();
if (object.getModel() instanceof NodeA) {
manager.add(new Action();
} else if (object.getModel() instanceof NodeB) {
manager.add(new OtherAction());
}
}
}
});
menuMgr.setRemoveAllWhenShown(true);
viewer.getControl().setMenu(menu);
I hope this helps ;)
It is important to set removeAllWhenShown property of menu manager to false, in order to hide all the other nodes actions ;)
Suppose that you know how to create Action and you are only interested in context menu following example worked for me hope this bunch of code will help you
private void hookContextMenu() {
MenuManager contextMenu = new MenuManager();
contextMenu.setRemoveAllWhenShown(true);
contextMenu.addMenuListener(new IMenuListener() {
#Override
public void menuAboutToShow(IMenuManager manager) {
IStructuredSelection sSelection = (IStructuredSelection) treeViewer.getSelection();
}
if(selectedObject instanceof A){
manager.add(action);
}
}
});
When a user clicks a 'Add Node' button above a tree and the program adds a tree item below the selected node, I would like to insert the new tree item with the text highlight and ready for editing by the user... like labels in GMail. Any ideas?
--Kirt
Are you using the GWT default TreeItem? If so, when you add the node, you could add the TreeItem with a Widget which you write which contains a TextBox and a Button to save.
When the save button is clicked, it calls setText() on the tree item with the text box's text, thus removing the widgets from the tree item.
It may be an even better idea to subclass TreeItem to encapsulate this logic and provide more functionality.
edit: Here, just because I'm feeling generous...
public class EditableTreeItem extends TreeItem {
public EditableTreeItem() {
super();
TextBox textBox = new TextBox();
Button saveButton = new Button("Save");
saveButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent e) {
if (!textBox.getText().isEmpty()) {
EditableTreeItem.this.setText(textBox.getText());
}
}
});
}
}