Package gov.nasa.arc.mct.components

Examples of gov.nasa.arc.mct.components.PropertyDescriptor


            return;
        }
        for (PropertyDescriptor p : fields) {
            assert p.getPropertyEditor() != null : "The Property Editor may not be null.";
           
            final PropertyDescriptor pd = p;
            try {
                JComponent extendedJcomponent = LookAndFeelSettings.getColorProperties().getColorSchemeFor(getInfo().getViewClass().getSimpleName()).callUnderColorScheme( new Callable<JComponent>() {
                    public JComponent call() throws Exception {
                        return makeVisualComponent(pd);               
                    };
View Full Code Here


            @Override
            public void setMutable(boolean mutable) {}
        };
        Mockito.when(comp.getAsset(CustomVisualControl.class)).thenReturn(mockControl);
        PropertyDescriptor lastPropertyDescriptor = mockDescriptors.get(mockDescriptors.size() - 1);       
       
        // Build a new info view
        InfoView infoView = new InfoView(comp, info);
       
        // First, verify that the appropriate get method has been called
        // (this implies that info view was populated with extended descriptors upon instantiation)
        for (PropertyDescriptor mockDescriptor : mockDescriptors) {
            switch (mockDescriptor.getVisualControlDescriptor()) {
            case CheckBox:
            case ComboBox:
                Mockito.verify(mockDescriptor.getPropertyEditor(), Mockito.times(1)).getValue();
                break;
            case Label:
            case TextField:
                Mockito.verify(mockDescriptor.getPropertyEditor(), Mockito.times(1)).getAsText();
                break;
            }
        }
       
        ActionEvent mockEvent = Mockito.mock(ActionEvent.class);
       
        // Act as if user changed a property
        switch (lastPropertyDescriptor.getVisualControlDescriptor()) {
        case CheckBox: {
            JCheckBox checkBox = findLastComponentOfType(infoView, JCheckBox.class);
            checkBox.doClick();
            break;
        }
        case ComboBox: {
            @SuppressWarnings("rawtypes")
            JComboBox comboBox = findLastComponentOfType(infoView, JComboBox.class);
            comboBox.setSelectedItem("other");
            break;           
        }
        case Label: {
            // Non-editable
            break;
        }
        case TextField: {
            JTextField textField = findLastComponentOfType(infoView, JTextField.class);
            textField.setText("changed");
            for (ActionListener listener : textField.getActionListeners()) {
                // Don't invoke listeners related to platform-specific Swing implementation
                // (may lead to inconsistent behavior when running tests on other platforms)
                if (listener.getClass().getName().startsWith("gov.nasa.arc.mct")) {
                    listener.actionPerformed(mockEvent);
                }
            }
            break;
        }
        case TextArea: {
            JTextArea textArea = findLastComponentOfType(infoView, JTextArea.class);
            textArea.setText("changed");
            for (FocusListener listener : textArea.getFocusListeners()) {
                // Don't invoke listeners related to platform-specific Swing implementation
                // (may lead to inconsistent behavior when running tests on other platforms)
                if (listener.getClass().getName().startsWith("gov.nasa.arc.mct")) {
                    listener.focusLost(Mockito.mock(FocusEvent.class));
                }
            }
            break;           
        }
        case Custom: {
            CustomVisualControl control = findLastComponentOfType(infoView, CustomVisualControl.class);
            control.setValue("changed");
            try {
                Method m = CustomVisualControl.class.getDeclaredMethod("fireChange");
                m.setAccessible(true);
                m.invoke(control);
            } catch (Exception e) {
                Assert.fail("Could not fire property change", e);
            }
            break;
        }
        }
       
        // Verify that some get method has been called on the OTHER mock
        // (this implies that changes to one field cause others to be refreshed)
        // Since labels cannot be edited, we don't expect this to occur
        // if the property in the last position was a label. In that case,
        // it is expected that get methods have not been called again.
        int expectedTimes = (lastPropertyDescriptor.getVisualControlDescriptor() == VisualControlDescriptor.Label) ?
                1 : 2;
        PropertyDescriptor mockDescriptor = mockDescriptors.get(0);
        switch (mockDescriptor.getVisualControlDescriptor()) {
        case CheckBox:
            Mockito.verify(mockDescriptor.getPropertyEditor(), Mockito.times(expectedTimes)).getValue();
            break;
        case ComboBox:
            Mockito.verify(mockDescriptor.getPropertyEditor(), Mockito.times(expectedTimes)).getValue();
            break;
        case Label:
            Mockito.verify(mockDescriptor.getPropertyEditor(), Mockito.times(expectedTimes)).getAsText();
            break;
        case TextField:
            Mockito.verify(mockDescriptor.getPropertyEditor(), Mockito.times(expectedTimes)).getAsText();
            break;
        case TextArea:
            Mockito.verify(mockDescriptor.getPropertyEditor(), Mockito.times(expectedTimes)).getAsText();
            break;           
        }
           
       
       
View Full Code Here

        return testCases;
    }
   
    @SuppressWarnings({ "rawtypes", "unchecked" })
    private PropertyDescriptor buildMockDescriptor(VisualControlDescriptor vcd) {
        PropertyDescriptor mockDescriptor = Mockito.mock(PropertyDescriptor.class);
        PropertyEditor mockEditor = Mockito.mock(PropertyEditor.class);
       
        Mockito.when(mockDescriptor.getShortDescription()).thenReturn("mock");
        Mockito.when(mockDescriptor.getVisualControlDescriptor()).thenReturn(vcd);
        Mockito.when(mockDescriptor.getPropertyEditor()).thenReturn(mockEditor);
        Mockito.when(mockDescriptor.isFieldMutable()).thenReturn(true);
       
        // Change the result of get() method, to trigger refresh
        Mockito.when(mockEditor.getTags()).thenReturn(Arrays.asList("mock", "other"));
        Mockito.when(mockEditor.getAsText()).thenReturn("mock");
        Mockito.when(mockEditor.getValue()).thenReturn(vcd != VisualControlDescriptor.CheckBox ? "mock" : Boolean.TRUE);      
View Full Code Here

    }

    @Override
    public List<PropertyDescriptor> getFieldDescriptors() {
        return Arrays.asList(
                new PropertyDescriptor(groupName, new PropertyEditor<String>() {
                    @Override
                    public String getAsText() {
                        return group.get();
                    }
View Full Code Here

  }
 
  @Override
  public List<PropertyDescriptor> getFieldDescriptors()  {

        PropertyDescriptor p = new PropertyDescriptor(bundle.getString("EXEC_COMMAND_LABEL"), new ExecutableButtonEditor(this), VisualControlDescriptor.TextField);
        p.setFieldMutable(true);
       
    return Collections.singletonList(p);
  }
View Full Code Here

    List<PropertyDescriptor> fields = new ArrayList<PropertyDescriptor>();

    // Describe the field "dataDescription" in the business class MyData.
    // Here we specify an immutable field, whereby its initial value is specified using a convenience class TextInitializer.
    String labelText = "World Swimming Event";
    PropertyDescriptor swimmingEvent = new PropertyDescriptor(labelText,
        new TextInitializer(getModel().getData().getDataDescription()), VisualControlDescriptor.Label);

    // Describe MyData's field "doubleData".
    // We specify a mutable text field.  The control display's values are maintained in the business model
    // via the PropertyEditor object.  When a new value is to be set, the editor also validates the prospective value.
    PropertyDescriptor swimmingWorldRecord = new PropertyDescriptor("Men's World Record (Rome 2009 Phelps)",
        new TextPropertyEditor(this),  VisualControlDescriptor.TextField);
    swimmingWorldRecord.setFieldMutable(true);

    // Describe MyData's field "genderSelection". Here is a mutabl combo box visual control.  The control's initial value,
    // and its selection states are taken from the business model via the PropertyEditor.
    PropertyDescriptor gender = new PropertyDescriptor("Gender", new EnumerationPropertyEditor(this),  VisualControlDescriptor.ComboBox);
    gender.setFieldMutable(true);

    // Describe MyData's field "verified".  This is a mutable check box visual control.
    PropertyDescriptor verified = new PropertyDescriptor("Verified", new BooleanPropertyEditor(this),  VisualControlDescriptor.CheckBox);
    verified.setFieldMutable(true);
   
    fields.add(swimmingEvent);
    fields.add(swimmingWorldRecord);
    fields.add(gender);
    fields.add(verified);
View Full Code Here

  }
 
  @Override
  public List<PropertyDescriptor> getFieldDescriptors()  {
   
        PropertyDescriptor val = new PropertyDescriptor(bundle.getString("VALUE_LABEL"), new LimitLineEditor(this), VisualControlDescriptor.TextField);
        val.setFieldMutable(true);
       
    return Collections.singletonList(val);
  }
View Full Code Here

TOP

Related Classes of gov.nasa.arc.mct.components.PropertyDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.