/
MenuBarRenderer.java
58 lines (49 loc) · 1.88 KB
/
MenuBarRenderer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*******************************************************************************
* Copyright (c) 2012 Rushan R. Gilmullin and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Rushan R. Gilmullin - initial API and implementation
*******************************************************************************/
package org.semanticsoft.vaaclipse.presentation.renderers;
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.MUILabel;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.MenuItem;
@SuppressWarnings("restriction")
public class MenuBarRenderer extends GenericVaadinRenderer
{
@Override
public void createWidget(MUIElement element, MElementContainer<MUIElement> parent)
{
if (!(element instanceof MMenu))
return;
if (MWindow.class.isAssignableFrom(parent.getClass()))
{
MenuBar menuBar = new MenuBar();
element.setWidget(menuBar);
}
else
{
String text = ((MUILabel) element).getLocalizedLabel();
text = text.replaceAll("&", "");
MenuItem item = null;
if (parent.getWidget() instanceof MenuBar)
item = ((MenuBar)parent.getWidget()).addItem(text, null, null);
else if (parent.getWidget() instanceof MenuItem)
item = ((MenuItem)parent.getWidget()).addItem(text, null, null);
element.setWidget(item);
}
}
@Override
public void processContents(MElementContainer<MUIElement> container)
{
//the child menu items already attached when created - vaadin API issue
}
}