public void handleEvent(final Event event) { // only go further if the event has a new time stamp if (mayScroll() && acceptEvent(event)) { lastEventTime = event.time; final Rectangle navigationComponentBounds = getNavigationComponent().getBounds(); // convert navigation bounds relative to display final Point navigationPtAtDisplay = getNavigationComponent().toDisplay(0, 0); navigationComponentBounds.x = navigationPtAtDisplay.x; navigationComponentBounds.y = navigationPtAtDisplay.y; if (event.widget instanceof Control) { final Control widget = (Control) event.widget; // convert widget event point relative to display final Point evtPt = widget.toDisplay(event.getBounds().x, event.getBounds().y); // now check if inside navigation if (navigationComponentBounds.contains(evtPt.x, evtPt.y)) { if (event.count > 0) { scrollUp(SCROLLING_STEP); } else { scrollDown(SCROLLING_STEP); } } } } }
public Event createEvent(Widget w) { Event e = new Event(); e.widget = w; e.display = display; e.time = (int) System.currentTimeMillis(); return e; }
private void esc() { Event e = new Event(); e.type = SWT.KeyDown; e.character = SWT.ESC; Display.getDefault().post(e); readAndDispatch(); }
public void testChartCallback() throws Exception { ILaunchConfiguration config = createConfiguration(proj.getProject()); doLaunch(config, "testChartCallback"); // $NON-NLS-1$ ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView(); IAction chartAction = getChartAction(view); assertNotNull(chartAction); chartAction.run(); IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); if (part instanceof ChartEditor) { ChartControl control = ((ChartEditor) part).getControl(); Event event = new Event(); event.button = 1; event.count = 1; event.widget = control; MouseEvent mEvent = new MouseEvent(event); DataPointHints source = new DataPointHints( null, null, null, null, null, null, null, null, null, 4, null, 0, null); control.callback(mEvent, new WrappedStructureSource(source), null); TableViewer viewer = ((MassifViewPart) view.getDynamicView()).getTableViewer(); MassifSnapshot[] snapshots = (MassifSnapshot[]) viewer.getInput(); MassifSnapshot snapshot = (MassifSnapshot) ((StructuredSelection) viewer.getSelection()).getFirstElement(); assertEquals(4, Arrays.asList(snapshots).indexOf(snapshot)); } else { fail(); } }
public void testAddDoubleClickListener() { final TableRidget ridget = getRidget(); final Table control = getWidget(); try { ridget.addDoubleClickListener(null); fail(); } catch (final RuntimeException npe) { ok(); } final FTActionListener listener1 = new FTActionListener(); ridget.addDoubleClickListener(listener1); final FTActionListener listener2 = new FTActionListener(); ridget.addDoubleClickListener(listener2); ridget.addDoubleClickListener(listener2); final Event doubleClick = new Event(); doubleClick.widget = control; doubleClick.type = SWT.MouseDoubleClick; control.notifyListeners(SWT.MouseDoubleClick, doubleClick); assertEquals(1, listener1.getCount()); assertEquals(1, listener2.getCount()); ridget.removeDoubleClickListener(listener1); control.notifyListeners(SWT.MouseDoubleClick, doubleClick); assertEquals(1, listener1.getCount()); }
public void notifyListeners(String eventName, JsonObject properties) { JsonValue value = properties.get("value"); Event event = new Event(); event.type = stringToTypeEvent(eventName); event.text = (value != null && value.isString() ? value.asString() : ""); event.data = properties; listener.handleEvent(event); }
@Override public void testAddClickListener() { final TableRidget ridget = getRidget(); ridget.updateFromModel(); final Table control = getWidget(); control.getColumn(0).setWidth(100); control.getColumn(1).setWidth(100); try { ridget.addClickListener(null); fail(); } catch (final RuntimeException npe) { ok(); } final FTClickListener listener1 = new FTClickListener(); ridget.addClickListener(listener1); final FTClickListener listener2 = new FTClickListener(); ridget.addClickListener(listener2); ridget.addClickListener(listener2); final Event mdEvent = new Event(); mdEvent.widget = control; mdEvent.type = SWT.MouseDown; mdEvent.button = 2; final TableItem row2 = control.getItem(2); mdEvent.item = row2; mdEvent.x = row2.getBounds().x + 1; mdEvent.y = row2.getBounds().y + 1; control.notifyListeners(SWT.MouseDown, mdEvent); assertEquals(0, listener1.getCount()); assertEquals(0, listener2.getCount()); mdEvent.type = SWT.MouseUp; control.notifyListeners(SWT.MouseUp, mdEvent); assertEquals(1, listener1.getCount()); assertEquals(1, listener2.getCount()); final ClickEvent event = listener2.getEvent(); assertEquals(ridget, event.getSource()); assertEquals(2, event.getButton()); assertEquals(0, event.getColumnIndex()); assertEquals(row2.getData(), event.getRow()); ridget.removeClickListener(listener1); mdEvent.type = SWT.MouseDown; control.notifyListeners(SWT.MouseDown, mdEvent); mdEvent.type = SWT.MouseUp; control.notifyListeners(SWT.MouseUp, mdEvent); assertEquals(1, listener1.getCount()); }
@Test public void testHandleVerifyEvent() { Event event = new Event(); event.widget = new Button(new Shell(), SWT.NONE); VerifyEvent verifyEvent = new VerifyEvent(event); verifyEvent.text = "blahblah"; verifyEvent.doit = true; testTextViewer.handleVerifyEvent(verifyEvent); Assert.assertEquals("blahblah", sentInput); Assert.assertFalse(verifyEvent.doit); }
public void testBasicContribution() throws Exception { IAction a = new Action() { @Override public void run() { System.out.println("Hello action"); } }; final MenuManager manager = new MenuManager(); final ActionContributionItem item = new ActionContributionItem(a); final Expression activeContextExpr = new ActiveContextExpression( MenuContributionHarness.CONTEXT_TEST1_ID, new String[] {ISources.ACTIVE_CONTEXT_NAME}); AbstractContributionFactory factory = new AbstractContributionFactory(LOCATION, TestPlugin.PLUGIN_ID) { @Override public void createContributionItems( IServiceLocator menuService, IContributionRoot additions) { additions.addContributionItem(item, activeContextExpr); } }; menuService.addContributionFactory(factory); menuService.populateContributionManager(manager, LOCATION); Shell shell = window.getShell(); // Test the initial menu creation final Menu menuBar = manager.createContextMenu(shell); Event e = new Event(); e.type = SWT.Show; e.widget = menuBar; menuBar.notifyListeners(SWT.Show, e); assertFalse("starting state", item.isVisible()); activeContext = contextService.activateContext(MenuContributionHarness.CONTEXT_TEST1_ID); menuBar.notifyListeners(SWT.Show, e); assertTrue("active context", item.isVisible()); contextService.deactivateContext(activeContext); activeContext = null; menuBar.notifyListeners(SWT.Show, e); assertFalse("after deactivation", item.isVisible()); menuService.releaseContributions(manager); menuService.removeContributionFactory(factory); manager.dispose(); }
@Test public void testUntypedEventConstructor() { Event event = new Event(); event.display = display; event.widget = mock(Widget.class); event.time = 9; event.data = new Object(); TestTypedEvent typedEvent = new TestTypedEvent(event); assertSame(event.widget, typedEvent.getSource()); EventTestHelper.assertFieldsEqual(typedEvent, event); }
public Object execute(ExecutionEvent event) throws ExecutionException { XtextEditor editor = EditorUtils.getActiveXtextEditor(event); if (editor != null) { // Hack, would be nicer with document edits, but this way we don't loose auto edit StyledText textWidget = editor.getInternalSourceViewer().getTextWidget(); Event e = new Event(); e.character = replaceChar; e.type = SWT.KeyDown; e.doit = true; textWidget.notifyListeners(SWT.KeyDown, e); } return null; }
public Event sendEvent(final Widget w, final Widget item, final int event) { try { Event e = createEvent(w); e.item = item; sendEventRaw(event, e); return e; } catch (SecurityException e) { TeslaCore.log(e); } catch (IllegalArgumentException e) { TeslaCore.log(e); } return null; }
private void doEventBasedSelection(int item, int stateMask, int button) { Table t = table.getViewer().getTable(); t.setSelection(item); while (Display.getCurrent().readAndDispatch()) ; Rectangle bounds = t.getItem(item).getBounds(); Event event = new Event(); event.button = button; event.stateMask = stateMask; event.x = bounds.x + 1; event.y = bounds.y + 1; t.notifyListeners(SWT.MouseUp, event); while (Display.getCurrent().readAndDispatch()) ; }
public Event sendEvent(final Widget w, final Widget item, final Event event) { if (w.isDisposed() || (item != null && item.isDisposed())) { return null; } try { event.widget = w; event.item = item; sendEventRaw(event.type, event); return event; } catch (Exception e) { TeslaCore.log(e); return null; } }
/** Tests the CTRL-D keystroke which initiates a delete from model action. See Bugzilla 115108. */ public void testDeleteFromModel() throws Exception { getTestFixture().openDiagram(); LEDEditPart editPartToDelete = (LEDEditPart) getLogicTestFixture() .createShapeUsingTool(LogicSemanticType.LED, new Point(0, 0), getDiagramEditPart()); List primaryEditParts = getDiagramEditPart().getPrimaryEditParts(); assertTrue(primaryEditParts.contains(editPartToDelete)); EObject semanticElement = (EObject) editPartToDelete.getAdapter(EObject.class); EObject semanticContainer = semanticElement.eContainer(); // Select the edit part to be deleted. EditPartViewer rootViewer = getDiagramEditPart().getRoot().getViewer(); rootViewer.deselectAll(); rootViewer.select(editPartToDelete); // Set the preference to not confirm the element deletion. ((IPreferenceStore) getDiagramEditPart().getDiagramPreferencesHint().getPreferenceStore()) .setValue(IPreferenceConstants.PREF_PROMPT_ON_DEL_FROM_MODEL, false); // Create the CTRL-D event Event e = new Event(); e.character = (char) 0x4; e.keyCode = 100; e.stateMask = SWT.CTRL; e.widget = editPartToDelete.getViewer().getControl(); // Simulate the CTRL-D keystroke SelectionTool tool = new SelectionTool(); tool.setEditDomain((EditDomain) getDiagramWorkbenchPart().getDiagramEditDomain()); tool.activate(); tool.keyDown(new KeyEvent(e), rootViewer); // Verify that the edit part and the semantic element have been deleted. primaryEditParts = getDiagramEditPart().getPrimaryEditParts(); assertFalse( "Primary edit part not deleted.", primaryEditParts.contains(editPartToDelete)); // $NON-NLS-1$ assertFalse( "Semantic element not deleted.", semanticContainer.eContents().contains(semanticElement)); // $NON-NLS-1$ }
private static void click(final MenuItem menuItem) { final Event event = new Event(); event.time = (int) System.currentTimeMillis(); event.widget = menuItem; event.display = menuItem.getDisplay(); event.type = SWT.Selection; UIThreadRunnable.asyncExec( menuItem.getDisplay(), new VoidResult() { public void run() { menuItem.notifyListeners(SWT.Selection, event); } }); }
public Event sendEvent(final Widget w, final int event, int x, int y, int button) { try { Event e = createEvent(w); e.x = x; e.y = y; e.button = button; e.type = event; sendEventRaw(event, e); return e; } catch (SecurityException e) { TeslaCore.log(e); } catch (IllegalArgumentException e) { TeslaCore.log(e); } return null; }
/** * Handles dispose event * * @param event */ void handleDispose(Event event) { removeListener(SWT.Dispose, listener); notifyListeners(SWT.Dispose, event); event.type = SWT.None; text = null; listener = null; }
public Event createMouseEvent( Display display, Widget widget, int x, int y, int button, int stateMask, int count) { Event event = new Event(); event.time = (int) System.currentTimeMillis(); event.widget = widget; event.display = display; event.x = x; event.y = y; event.button = button; event.stateMask = stateMask; event.count = count; return event; }
protected void measureEvent(Event event) { // System.out.println("OES Listner MI"); try { event.height = (int) (event.gc.getFontMetrics().getHeight() * OES.TABLEITEM_HEIGHT_FACTOR); } catch (NullPointerException e) { } }
/** * Zooms the given viewer. * * @see MouseWheelHandler#handleMouseWheel(Event, EditPartViewer) */ public void handleMouseWheel(Event event, EditPartViewer viewer) { ZoomManager zoomMgr = (ZoomManager) viewer.getProperty(ZoomManager.class.toString()); if (zoomMgr != null) { if (event.count > 0) zoomMgr.zoomIn(); else zoomMgr.zoomOut(); event.doit = false; } }
@Test public void testUntypedEventConstructor() { Event event = new Event(); event.display = display; event.widget = mock(Widget.class); event.item = mock(Item.class); event.x = 1; event.y = 2; event.width = 3; event.height = 4; event.doit = true; event.data = new Object(); CTabFolderEvent selectionEvent = new CTabFolderEvent(event); EventTestHelper.assertFieldsEqual(selectionEvent, event); }
@Test public void test_addPaintListenerLorg_eclipse_swt_events_PaintListener() { PaintListener listener = new PaintListener() { public void paintControl(PaintEvent e) { eventOccurred = true; } }; control.addPaintListener(listener); eventOccurred = false; Event event = new Event(); GC gc = event.gc = new GC(control); control.notifyListeners(SWT.Paint, event); gc.dispose(); assertTrue(eventOccurred); control.removePaintListener(listener); }
public void handleEvent(Event event) { TableItem item = (TableItem) event.item; int index = event.index; item.setText( 0, app.hostManager.get(index).hostname + ":" + app.hostManager.get(index).port); item.setText(1, app.hostManager.get(index).credentials.getUsername()); item.setText(2, app.hostManager.get(index).credentials.getPrivateKeyPath()); event.detail &= ~SWT.FOCUSED; }
protected void handleAllSelectionChange(boolean state) { ArrayList arrayList = (ArrayList) tableViewer.getInput(); if (!state) { selector.getSelectedModels().removeAll(arrayList); } else { selector.getSelectedModels().addAll(arrayList); } tableViewer.setAllChecked(state); // fire an event so the parent can update its controls if (listener != null) { Event changeEvent = new Event(); changeEvent.type = SWT.Selection; changeEvent.widget = tableViewer.getTable(); listener.handleEvent(changeEvent); } updateCountLabel(); }
public Event sendEvent(final SWTUIElement w, final int event, int x, int y) { if (PlayerWrapUtils.unwrapWidget(w).isDisposed()) { return null; } try { Event e = createEvent(w); e.x = x; e.y = y; e.type = event; sendEventRaw(event, e); return e; } catch (SecurityException e) { TeslaCore.log(e); } catch (IllegalArgumentException e) { TeslaCore.log(e); } return null; }
private void fireItemSelectionChanged(int button) { Event event = new Event(); event.button = button; event.x = 0; event.y = 0; event.width = -1; event.height = -1; event.item = selectedAnnotation; event.data = (selectedAnnotation != null) ? selectedAnnotation.getData() : null; notifyListeners(SWT.Selection, event); }
@Override public void handleTreeCollapse(TreeEvent event) { super.handleTreeCollapse(event); for (SynchronizedTreeViewer viewer : synchronizedViewers) { TreeItem otherItem = getMatchingItem(event.item.getData(), viewer); if (otherItem != null) { if (otherItem.getExpanded()) { Event rawEvent = new Event(); rawEvent.doit = true; rawEvent.widget = viewer.getTree(); rawEvent.display = event.display; TreeEvent otherEvent = new TreeEvent(rawEvent); otherEvent.item = otherItem; viewer.internalHandleTreeCollapse(otherEvent); viewer.setExpanded(otherItem, false); } viewer.getTree().redraw(); } } }
public void sendEventRaw(final int event, Event e) { // Update timestamp if last was the same. if (e.time == 0) { e.time = (int) System.currentTimeMillis(); } if (e.time == lastStamp) { e.time++; } lastStamp = e.time; e.widget.notifyListeners(event, e); }
/* * (non-Javadoc) * * @see * org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands * .ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchPart part = HandlerUtil.getActivePart(event); if (part != null) { IWorkbenchPartSite site = part.getSite(); if (site instanceof PartSite) { final MPart model = ((PartSite) site).getModel(); Composite partContainer = (Composite) model.getWidget(); if (partContainer != null) { Composite parent = partContainer.getParent(); while (parent != null && parent instanceof Composite) { if (parent instanceof CTabFolder) { CTabFolder ctf = (CTabFolder) parent; final Control topRight = ctf.getTopRight(); if (topRight instanceof Composite) { for (Control child : ((Composite) topRight).getChildren()) { if (child instanceof ToolBar && "ViewMenu".equals(child.getData())) { // $NON-NLS-1$ ToolBar tb = (ToolBar) child; ToolItem ti = tb.getItem(0); Event sevent = new Event(); sevent.type = SWT.Selection; sevent.widget = ti; ti.notifyListeners(SWT.Selection, sevent); } } } return null; } parent = parent.getParent(); } MMenu menuModel = StackRenderer.getViewMenu(model); if (menuModel != null) { showStandaloneViewMenu(event, model, menuModel, partContainer); } } } } return null; }