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;
}
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;
}
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);
}
Aggregations