While switching to windows classic theme combo contribution item shirnks - eclipse

I do have a problem with IToolbarManager. I have added a combo & spinner ot toolbar of a view like this
IToolbarManager mgr = getViewSite().getActionBars().getToolBarManager();
mgr.add(spinnerCntrAction);
spinnerCntrAction = new ControContribution(){
public Control createControl(){
//Creates composite
//Create a spinner and add that to composite
//return composite
}
};
In windows XP/Vista themes this spinner is shown correctly. But when program is run under windows classic theme , the spinner is shrinked and not shown correctly.
Is this a known problem ? Do you know any workaround/patch for this ?
Thanks
Jijoy

This is a bug in SWT. See http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg44671.html
Here is a workaround:
mgr.add(new DummyAction());
private static class DummyAction extends Action {
DummyAction() {
setEnabled(false);
setText(" ");
}
}
...
mgr.add(spinnerCntrAction);
This will cause the toolbar manager to make all control contributions the same size as the Action, so adjust the number of spaces in the Action text to get the desired result.

Related

SmartGwt - Removing one tab clears the canvas

I've built a GUI with a SmartGWT TabSet with Tabs that can be dynamically added and removed.
The Tabs share the same canvas which is moved from Tab to Tab at each tab selection like this:
myTabSet.addTabSelectedHandler(new TabSelectedHandler() {
public void onTabSelected(TabSelectedEvent event) {
[...]
myTabs[myTabSet.getSelectedTabNumber()].setPane(myCanvas);
// Then I fill the contained widgets with the tab-specific data
}
}
This works, but when I try to remove a Tab with
myTabSet.removeTab(iToBeDeletedTab);
The tab is removed but the remaining tabs have a blank pane, I can get the content back only by reloading the page. I found that I have to prevent pane destruction with calls to :
myTabSet.setDestroyPanes(false);
and
myTabSet.updateTab(iToBeDeletedTab, null);
//called right before
myTabSet.removeTab(iToBeDeletedTab);
I understand that the canvas/pane is still destroyed, but I cannot figure out how to prevent this.
Has anyone any hint?
Thank you!
Have you tried to call the redraw() method after removing a tab? This usually helps me when loading/reloading data with smartGWT widgets.
Your calls are correct, but now what you've got is the pane completely unnassociated from the TabSet and not drawn (check the Watch Tab in the Developer Console and you'll see this). Now, call updateTab(someOtherTab, pane) to connect the pane to one of the other tabs where it should be showing.
Ok, I've made some test and got the same as you but had some success with the following code:
1°) in the Javadoc I found:
***public void setPane(Canvas pane)
Specifies the pane associated with this tab. You can change the pane associated with a given tab after the TabSet has been created by calling TabSet.updateTab(int, com.smartgwt.client.widgets.Canvas)***
I tried without setting to null the pane of tab1 , it didn't work.
I think it could be arranged in better way but anyway the point is to use the updatePadmethod
public static void testTabDelete(){
final Canvas theCanvas = new Canvas();
final TabSet theTabs = new TabSet();
theTabs.setWidth("80%");
theTabs.setHeight("80%");
final Tab tab1 = new Tab("Tab1");
final Tab tab2 = new Tab("Tab2");
final Tab tab3 = new Tab("Tab3");
IButton btn1 = new IButton("Btn1");
btn1.setLeft(10);
btn1.setTop(100);
btn1.setWidth(80);
theCanvas.addChild(btn1);
IButton btn2 = new IButton("Delete");
btn2.setLeft(100);
btn2.setTop(100);
btn2.setWidth(80);
btn2.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
#Override
public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
theTabs.updateTab(0, null);
theTabs.updateTab(1, theCanvas);
theTabs.selectTab(tab2);
theTabs.removeTab(tab1);
}
});
theCanvas.addChild(btn2);
theTabs.addTab(tab1);
theTabs.addTab(tab2);
theTabs.addTab(tab3);
tab1.setPane(theCanvas);
RootPanel.get("container").add(theTabs);
}

Remove "File, edit,...etc" menus from Eclipse RCP application

I want to remove the File, edit, Source, Refactor, etc. menus from my RCP application
Can I use hideActionSet() ? or what should I do ?
That's right; in your ApplicationWorkbenchWindowAdvisor, override postWindowOpen().
The tricky bit is usually figuring out the names of the actionsets that you want to remove, but you can use the old standby ALT-SHIFT-F2 (the default keybinding for 'Plugin-in Menu Spy') and click on one of the menu items that you want to remove.
Note that if the menu item is disabled, the spy won't give you any info on it.
public void postWindowOpen() {
runApplicationWorkbenchDelegate();
// remove unwanted UI contributions that eclipse makes by default
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for (int i = 0; i < windows.length; ++i) {
IWorkbenchPage page = windows[i].getActivePage();
if (page != null) {
// hide generic 'File' commands
page.hideActionSet("org.eclipse.ui.actionSet.openFiles");
// hide 'Convert Line Delimiters To...'
page.hideActionSet("org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo");
// hide 'Search' commands
page.hideActionSet("org.eclipse.search.searchActionSet");
// hide 'Annotation' commands
page.hideActionSet("org.eclipse.ui.edit.text.actionSet.annotationNavigation");
// hide 'Forward/Back' type navigation commands
page.hideActionSet("org.eclipse.ui.edit.text.actionSet.navigation");
}
}
}
Although the question is old:
Lars Vogel's tutorial about Eclipse Activities shows how to hide entire menus in an RCP application rather than removing single menu-entries.
EDIT:
Alternatively you can use the MenuManager attached to the workbench window to show or hide Menus/Contributions.
Try the following code to hide all menus:
WorkbenchWindow workbenchWin = (WorkbenchWindow)PlatformUI.getWorkbench().getActiveWorkbenchWindow();
MenuManager menuManager = workbenchWin.getMenuManager();
IContributionItem[] items = menuManager.getItems();
for(IContributionItem item : items) {
item.setVisible(false);
}

Add dropdown menu in a view's ToolBarManager

I want to add several dynamically created actions to a view. This works to add them to the View Menu in the top right corner:
private void fillActionBars() {
IActionBars bars = getViewSite().getActionBars();
IMenuManager manager = bars.getMenuManager();
IMenuManager myMenu = new MenuManager("Menu title", MY_MENU_ID);
// add actions to myMenu
manager.add(myMenu);
bars.updateActionBars();
}
This works fine. However, I want to add the actions to a dropdown menu in the toolbar instead (so the user can see them immediately). If I replace the third line with
IToolbarManager manager = bars.getToolBarManager();
the menu doesn't show up.
You're right, this doesn't work. A workaround that works fine, not using a MenuManager but a drop down action and a menu creator:
IActionBars bars = getViewSite().getActionBars();
IToolbarManager manager = bars.getToolBarManager();
Action act=new Action("Menu title",SWT.DROP_DOWN){};
act.setMenuCreator(new MyMenuCreator());
manager.add(act);
class MyMenuCreator implements IMenuCreator{
public Menu getMenu(Control ctrl){
...
}
}
You need to use IToolbarManager.add(IContributionItem) with a class that implements IContributionItem. See org.eclipse.ui.internal.FastViewBarContextMenuContribution as an example.

GWT, disable autoclose MenuBar when clicking on MenuItem?

I want to if it is possible to disable the auto-close MenuBar when I click on a MenuItem?
I have several MenuItem that are like checkboxes, so I can check more than one MenuItem and don't want my menu close everytime I checked one.
Thanks.
I was facing same problem and I will share with you my solution:
1) Create new class MyMenuItemWithCheckBox that extends the MenuItem.
In the constructor set element ID to (forexample) menuItemWIthCheckBox + Unique text.
this.getElement().setId("menuItemWithCheckBox_" + menuItemLabel);
2) Create new class MyMenuBar that extends the MenuBar.
Override the onBrowserEvent method by following:
Override
public void onBrowserEvent(Event event) {
if (DOM.eventGetType(event) == Event.ONCLICK && getSelectedItem().getElement().getId().contains("CheckBox")) {
Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() {
#Override
public void execute() {
getSelectedItem().getScheduledCommand().execute();
}
});
event.stopPropagation();
} else {
super.onBrowserEvent(event);
}
}
Now scheduled command of MenuItem is always called, but in the case of your
menu checkBox item there is no close of a menubar.
I hope this help you, I spend more than day to create this solution. :-)
First, directly it's not possible because the popup-panel which displays the submenu is private in the MenuBar class.
Buuut, there is a way to do so ...
Simpley fetch the current MenuBar.java code out of googles code repository and include it in your eclipse gwt-project.
You don't have to change anything e.g. package deklaration or something. Just put your source in your project and it will simply replace the original MenuBar-class from the gwt-sdk during compilation (works also with hosted development mode).
Then you can simply set the property autoHide of the popup-Panel to false and the popup shouldn't disappear after clicking.
You can set hideOnClick to false on the menuItems
See here.

TabLayoutPanel disable a Tab GWT

How can i disable a tab (i.e the user cannot open the tab when he clicks on it) in the TabLayoutPanel?I searched online but was not able to find a solution
Thanks
Use a BeforeSelectionHandler:
TabLayoutPanel myPanel = new TabLayoutPanel();
// Add children...
myPanel.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
#Override
public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
// Simple if statement - your test for whether the tab should be disabled
// will probably be more complicated
if (event.getItem() == 1) {
// Canceling the event prevents the tab from being selected.
event.cancel();
}
}
});
If you want to style the disabled tab differently than enabled tabs, you can use TabLayoutPanel#getTabWidget to get the tab widget and add a style name to it.
For anyone who comes across this later:
As of GWT version 1.6, disabling/enabling tabs is built into GWT.
The TabBar class has a method setTabEnabled(int index, boolean enabled) that enables/disables the tab at a given index.
For example, to disable all the tabs in a TabPanel:
TabPanel myTabPanel = new TabPanel();
// Add children
TabBar tabBar = myTabPanel.getTabBar();
for(int i=0; i<tabBar.getTabCount(); i++) {
tabBar.setTabEnabled(i, false);
}
See the GWT javadoc for more info.
To style disabled tabs differently (which GWT does automatically, but if you wanted to change the style): disabled tabBarItem divs are given another CSS class: gwt-TabBarItem-disabled.
You can access tab style by casting class Tab to Widget
TabPanel tabPanel = new TabPanel();
((Widget)tabPanel().getTabBar().getTab(tabsToDisable.iterator().next())).addStyleName("disabled");