Skip to content

Commit

Permalink
REDDEER-1851 Implement getContextMenu in controls
Browse files Browse the repository at this point in the history
Signed-off-by: Lukáš Valach <lvalach@redhat.com>
  • Loading branch information
luvalach authored and rawagner committed Feb 28, 2018
1 parent 820e8f1 commit 00d3f60
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
Expand Up @@ -48,4 +48,10 @@ public interface Control<T extends org.eclipse.swt.widgets.Control> extends Widg
*/
String getToolTipText();

/**
* Returns a context menu associated to the control.
*
* @return Context menu associated to the control
*/
Menu getContextMenu();
}
Expand Up @@ -10,10 +10,13 @@
*******************************************************************************/
package org.eclipse.reddeer.swt.widgets;

import org.hamcrest.Matcher;
import org.eclipse.reddeer.core.handler.ControlHandler;
import org.eclipse.reddeer.core.lookup.MenuLookup;
import org.eclipse.reddeer.core.reference.ReferencedComposite;
import org.eclipse.reddeer.swt.api.Control;
import org.eclipse.reddeer.swt.api.Menu;
import org.eclipse.reddeer.swt.impl.menu.DefaultMenu;
import org.hamcrest.Matcher;

/**
* Abstract class for all control
Expand Down Expand Up @@ -79,4 +82,14 @@ public boolean isFocusControl(){
public String getToolTipText(){
return ControlHandler.getInstance().getToolTipText(swtWidget);
}

/**
* Returns a context menu associated to the control.
*
* @return Context menu associated to the control
*/
@Override
public Menu getContextMenu() {
return new DefaultMenu(MenuLookup.getInstance().getControlMenu(this.getSWTWidget()));
}
}
Expand Up @@ -91,7 +91,7 @@ public void restore() {
* requirements you can change it by overriding
* {{@link #getRegisteredControl()}}.
*
* @return Context menu associated to the editor
* @return Context menu associated to the workbench
*/
@Override
public Menu getContextMenu() {
Expand Down
Expand Up @@ -11,11 +11,12 @@
package org.eclipse.reddeer.swt.test.impl.styledtext;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import org.eclipse.swt.SWT;
import org.eclipse.reddeer.swt.api.StyledText;
import org.eclipse.reddeer.swt.impl.styledtext.DefaultStyledText;
import org.eclipse.reddeer.swt.test.SWTLayerTestCase;
import org.eclipse.swt.SWT;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -29,7 +30,9 @@ public void prepareStyledText(){

@Override
protected void createControls(org.eclipse.swt.widgets.Shell shell) {
new org.eclipse.swt.custom.StyledText(shell, SWT.FULL_SELECTION);
org.eclipse.swt.custom.StyledText t = new org.eclipse.swt.custom.StyledText(shell, SWT.FULL_SELECTION);
org.eclipse.swt.widgets.Menu menu = new org.eclipse.swt.widgets.Menu(t);
t.setMenu(menu);
}

@Test
Expand All @@ -46,6 +49,13 @@ public void selectPosition(){
assertEquals("st", t.getSelectionText());
}



@Test
public void openContextMenu() {
DefaultStyledText t = new DefaultStyledText();
try {
t.getContextMenu();
} catch (Exception e) {
fail("Can't open context menu.\n" + e.toString());
}
}
}

0 comments on commit 00d3f60

Please sign in to comment.