Search in sources :

Example 1 with ArmListener

use of org.eclipse.swt.events.ArmListener in project archi by archimatetool.

the class MagicConnectionCreationTool method addElementAction.

private MenuItem addElementAction(Menu menu, final EClass type) {
    final MenuItem item = new MenuItem(menu, SWT.CASCADE);
    item.setText(ArchiLabelProvider.INSTANCE.getDefaultName(type));
    item.setImage(ArchiLabelProvider.INSTANCE.getImage(type));
    // Add arm listener to notify Hints View and also set element if elements first
    item.addArmListener(new ArmListener() {

        @Override
        public void widgetArmed(ArmEvent e) {
            if (!fSetRelationshipTypeWhenHoveringOnConnectionMenuItem) {
                // User will hover over element, then connection
                getFactory().setElementType(type);
            }
            ComponentSelectionManager.INSTANCE.fireSelectionEvent(item, type);
        }
    });
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            getFactory().setElementType(type);
        }
    });
    return item;
}
Also used : ArmListener(org.eclipse.swt.events.ArmListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArmEvent(org.eclipse.swt.events.ArmEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem)

Example 2 with ArmListener

use of org.eclipse.swt.events.ArmListener in project archi by archimatetool.

the class MagicConnectionCreationTool method addConnectionAction.

/**
 * Add a Connection Action with a relationship type
 */
private MenuItem addConnectionAction(Menu menu, final EClass relationshipType, final boolean reverseDirection) {
    final MenuItem item = new MenuItem(menu, SWT.CASCADE);
    item.setText(ArchiLabelProvider.INSTANCE.getRelationshipPhrase(relationshipType, reverseDirection));
    item.setImage(ArchiLabelProvider.INSTANCE.getImage(relationshipType));
    // Add arm listener to notify Hints View
    item.addArmListener(new ArmListener() {

        @Override
        public void widgetArmed(ArmEvent e) {
            if (fSetRelationshipTypeWhenHoveringOnConnectionMenuItem) {
                // User will hover over connection, then element
                getFactory().setRelationshipType(relationshipType);
            }
            ComponentSelectionManager.INSTANCE.fireSelectionEvent(item, relationshipType);
        }
    });
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            getFactory().setRelationshipType(relationshipType);
            getFactory().setSwapSourceAndTarget(reverseDirection);
        }
    });
    return item;
}
Also used : ArmListener(org.eclipse.swt.events.ArmListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArmEvent(org.eclipse.swt.events.ArmEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem)

Example 3 with ArmListener

use of org.eclipse.swt.events.ArmListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_MenuItem method test_addArmListenerLorg_eclipse_swt_events_ArmListener.

@Test
public void test_addArmListenerLorg_eclipse_swt_events_ArmListener() {
    listenerCalled = false;
    ArmListener listener = e -> listenerCalled = true;
    try {
        menuItem.addArmListener(null);
        fail("No exception thrown for addArmListener with null argument");
    } catch (IllegalArgumentException e) {
    }
    menuItem.addArmListener(listener);
    menuItem.notifyListeners(SWT.Arm, new Event());
    assertTrue(listenerCalled);
    try {
        menuItem.removeArmListener(null);
        fail("No exception thrown for removeArmListener with null argument");
    } catch (IllegalArgumentException e) {
    }
    listenerCalled = false;
    menuItem.removeArmListener(listener);
    menuItem.notifyListeners(SWT.Arm, new Event());
    assertFalse(listenerCalled);
}
Also used : ArmListener(org.eclipse.swt.events.ArmListener) HelpListener(org.eclipse.swt.events.HelpListener) Assert.assertNotNull(org.junit.Assert.assertNotNull) ArmListener(org.eclipse.swt.events.ArmListener) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Event(org.eclipse.swt.widgets.Event) Assert.assertNull(org.junit.Assert.assertNull) MenuItem(org.eclipse.swt.widgets.MenuItem) Assert.assertFalse(org.junit.Assert.assertFalse) SWT(org.eclipse.swt.SWT) Assert.fail(org.junit.Assert.fail) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Assert.assertEquals(org.junit.Assert.assertEquals) SelectionListener(org.eclipse.swt.events.SelectionListener) Before(org.junit.Before) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Test(org.junit.Test)

Aggregations

ArmListener (org.eclipse.swt.events.ArmListener)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 MenuItem (org.eclipse.swt.widgets.MenuItem)3 ArmEvent (org.eclipse.swt.events.ArmEvent)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SWT (org.eclipse.swt.SWT)1 HelpListener (org.eclipse.swt.events.HelpListener)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Event (org.eclipse.swt.widgets.Event)1 Menu (org.eclipse.swt.widgets.Menu)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertNull (org.junit.Assert.assertNull)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1 Before (org.junit.Before)1 Test (org.junit.Test)1