/*
   * (non-Javadoc)
   * @see  it.baeyens.avreclipse.ui.editors.targets.AbstractTargetConfigurationEditorPart#createSectionContent
   * (org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit)
   */
  @Override
  protected void createSectionContent(Composite parent, FormToolkit toolkit) {
    GridLayout layout = new GridLayout(2, false);
    layout.horizontalSpacing = 12;
    parent.setLayout(layout);

    //
    // The MCU Combo
    //
    toolkit.createLabel(parent, "MCU type:");
    fMCUcombo = new Combo(parent, SWT.READ_ONLY);
    toolkit.adapt(fMCUcombo, true, true);
    fMCUcombo.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));
    fMCUcombo.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            String mcuid = AVRMCUidConverter.name2id(fMCUcombo.getText());
            getTargetConfiguration().setMCU(mcuid);
            refreshMessages();
            getManagedForm().dirtyStateChanged();
          }
        });

    //
    // The FCPU Combo
    //
    toolkit.createLabel(parent, "MCU clock frequency:");
    fFCPUcombo = new Combo(parent, SWT.NONE);
    toolkit.adapt(fFCPUcombo, true, true);
    fFCPUcombo.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));
    fFCPUcombo.setTextLimit(9); // max. 999 MHz
    fFCPUcombo.setToolTipText("Target Hardware Clock Frequency in Hz");
    fFCPUcombo.setVisibleItemCount(FCPU_VALUES.length);
    fFCPUcombo.setItems(FCPU_VALUES);

    fFCPUcombo.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            getTargetConfiguration().setFCPU(Integer.parseInt(fFCPUcombo.getText()));
            getManagedForm().dirtyStateChanged();
          }
        });

    // The verify listener to restrict the input to integers
    fFCPUcombo.addVerifyListener(
        new VerifyListener() {
          @Override
          public void verifyText(VerifyEvent event) {
            String text = event.text;
            if (!text.matches("[0-9]*")) {
              event.doit = false;
            }
          }
        });
  }
Example #2
0
  @Test
  public void testRenderAddVerifyListener() throws Exception {
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);
    Fixture.preserveWidgets();

    combo.addVerifyListener(
        new VerifyListener() {
          public void verifyText(VerifyEvent event) {}
        });
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertEquals(Boolean.TRUE, message.findListenProperty(combo, "Modify"));
  }
Example #3
0
  @Test
  public void testRenderVerifyListenerUnchanged() throws Exception {
    Fixture.markInitialized(display);
    Fixture.markInitialized(combo);
    Fixture.preserveWidgets();

    combo.addVerifyListener(
        new VerifyListener() {
          public void verifyText(VerifyEvent event) {}
        });
    Fixture.preserveWidgets();
    lca.renderChanges(combo);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findListenOperation(combo, "verify"));
  }
Example #4
0
  @Test
  public void testTextSelectionWithVerifyEvent_ListenerAdjustsSelection() {
    combo.setText("");
    combo.addVerifyListener(
        new VerifyListener() {
          public void verifyText(VerifyEvent event) {
            event.text = "";
          }
        });

    fakeTextAndSelectionParameters("verify me", 1, 0);
    Fixture.executeLifeCycleFromServerThread();

    assertEquals(new Point(0, 0), combo.getSelection());
    assertEquals("", combo.getText());
  }
Example #5
0
  @Test
  public void testTextSelectionWithVerifyEvent_EmptyListener() {
    Fixture.markInitialized(display);
    Fixture.markInitialized(shell);
    Fixture.markInitialized(combo);
    VerifyListener listener = mock(VerifyListener.class);
    combo.addVerifyListener(listener);

    fakeTextAndSelectionParameters("verify me", 1, 0);
    Fixture.executeLifeCycleFromServerThread();

    verify(listener, times(1)).verifyText(any(VerifyEvent.class));
    assertEquals("verify me", combo.getText());
    assertEquals(new Point(1, 1), combo.getSelection());
    Message message = Fixture.getProtocolMessage();
    assertNull(message.findSetOperation(combo, "text"));
    assertNull(message.findSetOperation(combo, "selection"));
  }
Example #6
0
  @Test
  public void testReadText_WithVerifyListener() {
    Fixture.fakePhase(PhaseId.PROCESS_ACTION);
    Fixture.markInitialized(display);
    Fixture.markInitialized(shell);
    Fixture.markInitialized(combo);
    combo.setText("some text");
    VerifyListener listener = mock(VerifyListener.class);
    combo.addVerifyListener(listener);

    Fixture.fakeSetParameter(getId(combo), "text", "verify me");
    Fixture.executeLifeCycleFromServerThread();

    assertEquals("verify me", combo.getText());
    ArgumentCaptor<VerifyEvent> captor = ArgumentCaptor.forClass(VerifyEvent.class);
    verify(listener, times(1)).verifyText(captor.capture());
    VerifyEvent event = captor.getValue();
    assertEquals("verify me", event.text);
    assertEquals(0, event.start);
    assertEquals(9, event.end);
  }