public void testCopyToImageActionEnablement() throws Exception {

    getTestFixture().openDiagram();

    List children = getTestFixture().getDiagramEditPart().getChildren();

    CircuitEditPart circuitEP = null;
    ListIterator li = children.listIterator();
    while (li.hasNext()) {
      Object ep = li.next();
      if (ep instanceof CircuitEditPart) {
        circuitEP = (CircuitEditPart) ep;
      }
    }

    assertNotNull(circuitEP);

    CopyToImageAction action = new CopyToImageAction(getWorkbenchPage());
    action.init();
    EditPartViewer viewer = getDiagramEditPart().getRoot().getViewer();
    viewer.deselectAll();
    viewer.select(getDiagramEditPart());
    flushEventQueue();
    assertTrue(action.isEnabled());

    viewer.deselectAll();
    viewer.select(circuitEP);
    flushEventQueue();
    assertTrue(action.isEnabled());
  }
  /** 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$
  }