use of org.eclipse.wb.internal.core.model.menu.IMenuItemInfo in project windowbuilder by eclipse.
the class MenuManagerAdaptableFactory method getAdapter.
// //////////////////////////////////////////////////////////////////////////
//
// IAdaptableFactory
//
// //////////////////////////////////////////////////////////////////////////
@Override
public <T> T getAdapter(Object object, Class<T> adapter) {
if (adapter.isAssignableFrom(IMenuItemInfo.class) && object instanceof ContributionItemInfo) {
ContributionItemInfo item = (ContributionItemInfo) object;
IMenuItemInfo itemObject = (IMenuItemInfo) item.getArbitraryValue(KEY_MENU_ITEM_OBJECT);
if (itemObject == null) {
itemObject = new ContributionItemImpl(item);
item.putArbitraryValue(KEY_MENU_ITEM_OBJECT, itemObject);
}
return adapter.cast(itemObject);
}
// can not adapt
return null;
}
use of org.eclipse.wb.internal.core.model.menu.IMenuItemInfo in project windowbuilder by eclipse.
the class MenuUtils method getItems.
/**
* @param container
* some menu container, {@link JMenuInfo} or {@link JPopupMenuInfo}.
*
* @return the {@link IMenuItemInfo}'s of given menu container.
*/
public static List<IMenuItemInfo> getItems(ContainerInfo container) {
List<IMenuItemInfo> items = Lists.newArrayList();
for (ComponentInfo component : container.getChildrenComponents()) {
IMenuItemInfo item = getMenuItem(component);
items.add(item);
}
return items;
}
use of org.eclipse.wb.internal.core.model.menu.IMenuItemInfo in project windowbuilder by eclipse.
the class MenuUtils method setSelectingItem.
/**
* Sets {@link ComponentInfo} which is menu item and should be selected (and expanded) during
* refresh.
*/
public static void setSelectingItem(ComponentInfo component) {
IMenuItemInfo item = getMenuItem(component);
MenuObjectInfoUtils.setSelectingObject(item);
}
use of org.eclipse.wb.internal.core.model.menu.IMenuItemInfo in project windowbuilder by eclipse.
the class MenuItemTest method test_impl.
// //////////////////////////////////////////////////////////////////////////
//
// Impl
//
// //////////////////////////////////////////////////////////////////////////
/**
* Test that {@link MenuItemInfo} can be adapted to {@link IMenuItemInfo}.
*/
public void test_impl() throws Exception {
parse("// filler filler filler filler filler", "// filler filler filler filler filler", "<Shell>", " <Shell.menuBar>", " <Menu x:style='BAR'>", " <MenuItem wbp:name='item' x:Style='CASCADE'>", " <MenuItem.menu>", " <Menu wbp:name='subMenu'/>", " </MenuItem.menu>", " </MenuItem>", " </Menu>", " </Shell.menuBar>", "</Shell>");
refresh();
// prepare models
MenuItemInfo itemInfo = getObjectByName("item");
MenuInfo menuInfo = itemInfo.getSubMenu();
// no adapter for random Class
assertNull(itemInfo.getAdapter(List.class));
// check "impl"
{
IMenuItemInfo itemObject = itemInfo.getAdapter(IMenuItemInfo.class);
// IMenuItemInfo
assertSame(itemInfo, itemObject.getModel());
assertSame(MenuObjectInfoUtils.getMenuInfo(menuInfo), itemObject.getMenu());
// presentation
assertSame(itemInfo.getImage(), itemObject.getImage());
assertSame(itemInfo.getBounds(), itemObject.getBounds());
}
}
use of org.eclipse.wb.internal.core.model.menu.IMenuItemInfo in project windowbuilder by eclipse.
the class MenuItemTest method test_IMenuItemInfo_move.
/**
* {@link MenuInfo} can be moved on {@link MenuItemInfo}.
*/
public void test_IMenuItemInfo_move() throws Exception {
parse("// filler filler filler filler filler", "// filler filler filler filler filler", "<Shell>", " <Shell.menuBar>", " <Menu wbp:name='bar' x:style='BAR'>", " <MenuItem wbp:name='item_1' x:Style='CHECK'/>", " <MenuItem wbp:name='item_2' x:Style='CASCADE'>", " <MenuItem.menu>", " <Menu wbp:name='subMenu'/>", " </MenuItem.menu>", " </MenuItem>", " </Menu>", " </Shell.menuBar>", "</Shell>");
refresh();
// prepare models
MenuInfo barInfo = getObjectByName("bar");
MenuItemInfo itemInfo_1 = getObjectByName("item_1");
MenuItemInfo itemInfo_2 = getObjectByName("item_2");
final MenuInfo subMenuInfo = getObjectByName("subMenu");
// prepare menu objects
final IMenuItemInfo itemObject_1 = MenuObjectInfoUtils.getMenuItemInfo(itemInfo_1);
final IMenuPolicy itemPolicy_1 = itemObject_1.getPolicy();
final IMenuItemInfo itemObject_2 = MenuObjectInfoUtils.getMenuItemInfo(itemInfo_2);
final IMenuPolicy itemPolicy_2 = itemObject_2.getPolicy();
// can not move just random object
assertFalse(itemPolicy_2.validateMove(new Object()));
// can not move "bar" on its own child "item_2"
assertFalse(itemPolicy_2.validateMove(barInfo));
// move "subMenu" from "item_2" to "item_1"
ExecutionUtils.run(m_lastObject, new RunnableEx() {
@Override
public void run() throws Exception {
assertTrue(itemPolicy_1.validateMove(subMenuInfo));
itemPolicy_1.commandMove(subMenuInfo, null);
}
});
assertXML("// filler filler filler filler filler", "// filler filler filler filler filler", "<Shell>", " <Shell.menuBar>", " <Menu wbp:name='bar' x:style='BAR'>", " <MenuItem wbp:name='item_1' x:Style='CASCADE'>", " <MenuItem.menu>", " <Menu wbp:name='subMenu'/>", " </MenuItem.menu>", " </MenuItem>", " <MenuItem wbp:name='item_2'/>", " </Menu>", " </Shell.menuBar>", "</Shell>");
}
Aggregations