Search in sources :

Example 1 with IMenuItemInfo

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;
}
Also used : IMenuItemInfo(org.eclipse.wb.internal.core.model.menu.IMenuItemInfo)

Example 2 with IMenuItemInfo

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;
}
Also used : IMenuItemInfo(org.eclipse.wb.internal.core.model.menu.IMenuItemInfo) ComponentInfo(org.eclipse.wb.internal.swing.model.component.ComponentInfo)

Example 3 with IMenuItemInfo

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);
}
Also used : IMenuItemInfo(org.eclipse.wb.internal.core.model.menu.IMenuItemInfo)

Example 4 with IMenuItemInfo

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());
    }
}
Also used : MenuItemInfo(org.eclipse.wb.internal.xwt.model.widgets.menu.MenuItemInfo) IMenuItemInfo(org.eclipse.wb.internal.core.model.menu.IMenuItemInfo) MenuInfo(org.eclipse.wb.internal.xwt.model.widgets.menu.MenuInfo) IMenuItemInfo(org.eclipse.wb.internal.core.model.menu.IMenuItemInfo) List(java.util.List)

Example 5 with IMenuItemInfo

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>");
}
Also used : IMenuPolicy(org.eclipse.wb.internal.core.model.menu.IMenuPolicy) MenuItemInfo(org.eclipse.wb.internal.xwt.model.widgets.menu.MenuItemInfo) IMenuItemInfo(org.eclipse.wb.internal.core.model.menu.IMenuItemInfo) MenuInfo(org.eclipse.wb.internal.xwt.model.widgets.menu.MenuInfo) IMenuItemInfo(org.eclipse.wb.internal.core.model.menu.IMenuItemInfo) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx)

Aggregations

IMenuItemInfo (org.eclipse.wb.internal.core.model.menu.IMenuItemInfo)34 IMenuInfo (org.eclipse.wb.internal.core.model.menu.IMenuInfo)21 IMenuPolicy (org.eclipse.wb.internal.core.model.menu.IMenuPolicy)12 List (java.util.List)11 ContainerInfo (org.eclipse.wb.internal.swing.model.component.ContainerInfo)7 CompositeInfo (org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)7 MenuInfo (org.eclipse.wb.internal.swt.model.widgets.menu.MenuInfo)7 MenuItemInfo (org.eclipse.wb.internal.swt.model.widgets.menu.MenuItemInfo)7 MenuInfo (org.eclipse.wb.internal.xwt.model.widgets.menu.MenuInfo)7 MenuItemInfo (org.eclipse.wb.internal.xwt.model.widgets.menu.MenuItemInfo)7 IMocksControl (org.easymock.IMocksControl)6 JMenuItemInfo (org.eclipse.wb.internal.swing.model.component.menu.JMenuItemInfo)6 Rectangle (org.eclipse.wb.draw2d.geometry.Rectangle)4 ComponentInfo (org.eclipse.wb.internal.swing.model.component.ComponentInfo)4 JMenuBarInfo (org.eclipse.wb.internal.swing.model.component.menu.JMenuBarInfo)4 JMenuInfo (org.eclipse.wb.internal.swing.model.component.menu.JMenuInfo)4 ImmutableList (com.google.common.collect.ImmutableList)3 IAdaptable (org.eclipse.wb.internal.core.utils.IAdaptable)3 ApplicationWindowInfo (org.eclipse.wb.internal.rcp.model.jface.ApplicationWindowInfo)3 MenuManagerInfo (org.eclipse.wb.internal.rcp.model.jface.action.MenuManagerInfo)3