protected void setUp() throws Exception {
    super.setUp();

    List children = getTestFixture().getDiagramEditPart().getChildren();
    if (children.isEmpty()) assertFalse(true);

    EditPart firstEP = (EditPart) children.get(0);
    if (firstEP instanceof CircuitEditPart) {
      CircuitEditPart circuitEditPart = (CircuitEditPart) firstEP;

      IElementType typeLED = ElementTypeRegistry.getInstance().getType("logic.led"); // $NON-NLS-1$
      Point pos = circuitEditPart.getFigure().getBounds().getBottomRight();
      circuitEditPart.getFigure().translateToAbsolute(pos);
      pos.translate(100, 100);
      LEDEditPart ledEP2 =
          (LEDEditPart)
              getLogicTestFixture().createShapeUsingTool(typeLED, pos, getDiagramEditPart());

      Terminal term1 =
          (Terminal)
              ((Circuit) circuitEditPart.getNotationView().getElement())
                  .getOutputTerminals()
                  .get(0);
      TerminalEditPart tep1 = null;
      ListIterator li = circuitEditPart.getChildren().listIterator();
      while (li.hasNext()) {
        IGraphicalEditPart gep = (IGraphicalEditPart) li.next();
        if (gep.getNotationView().getElement().equals(term1)) tep1 = (TerminalEditPart) gep;
      }

      Terminal term2 =
          (Terminal) ((LED) ledEP2.getNotationView().getElement()).getInputTerminals().get(0);
      TerminalEditPart tep2 = null;
      li = ledEP2.getChildren().listIterator();
      while (li.hasNext()) {
        IGraphicalEditPart gep = (IGraphicalEditPart) li.next();
        if (gep.getNotationView().getElement().equals(term2)) tep2 = (TerminalEditPart) gep;
      }

      IElementType typeWire =
          ElementTypeRegistry.getInstance().getType("logic.wire"); // $NON-NLS-1$

      getLogicTestFixture().createConnectorUsingTool(tep1, tep2, typeWire);

      IGraphicalEditPart logicCompartment =
          circuitEditPart.getChildBySemanticHint(LogicConstants.LOGIC_SHAPE_COMPARTMENT);

      Rectangle rect = new Rectangle(logicCompartment.getFigure().getBounds());
      logicCompartment.getFigure().translateToAbsolute(rect);

      CreateRequest request = getLogicTestFixture().getCreationRequest(typeLED);
      request.setLocation(rect.getCenter());
      Command cmd = logicCompartment.getCommand(request);

      getCommandStack().execute(cmd);

      assertEquals(
          "Unexpected LED count.", 1, logicCompartment.getChildren().size()); // $NON-NLS-1$
    }
  }
  /** 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$
  }