TextProperty extends StringProperty implements DocumentListener, PropertyChangeListener,
                                                                  com.intellij.openapi.editor.event.DocumentListener { @NotNull @Override public String get() { if (myComponent instanceof JTextComponent) { return ((JTextComponent)myComponent).getText(); } else if (myComponent instanceof AbstractButton) { return ((AbstractButton)myComponent).getText(); } else if (myComponent instanceof JLabel) { return ((JLabel)myComponent).getText(); } else if (myComponent instanceof LabelWithEditButton) { return ((LabelWithEditButton)myComponent).getText(); } else if (myComponent instanceof EditorComboBox) { return ((EditorComboBox)myComponent).getText(); } else if (myComponent instanceof EditorTextField) { return ((EditorTextField)myComponent).getText(); } else { throw new IllegalStateException("Unexpected text component type: " + myComponent.getClass().getSimpleName()); } } TextProperty(@NotNull JTextComponent textComponent);  TextProperty(@NotNull AbstractButton button);  TextProperty(@NotNull JLabel label);  TextProperty(@NotNull LabelWithEditButton editLabel);  TextProperty(@NotNull EditorComboBox editorComboBox);  TextProperty(@NotNull EditorTextField editorTextField); @Override void insertUpdate(DocumentEvent documentEvent); @Override void removeUpdate(DocumentEvent documentEvent); @Override void changedUpdate(DocumentEvent documentEvent); @Override void propertyChange(PropertyChangeEvent propertyChangeEvent); @Override void beforeDocumentChange(@NotNull com.intellij.openapi.editor.event.DocumentEvent event); @Override void documentChanged(@NotNull com.intellij.openapi.editor.event.DocumentEvent event); @NotNull @Override String get();  }
@Test public void textPropertyCanWrapLabel() { JLabel label = new JLabel("New Label"); TextProperty textProperty = new TextProperty(label); CountListener listener = new CountListener(); textProperty.addListener(listener); assertThat(textProperty.get()).isEqualTo("New Label"); assertThat(listener.getCount()).isEqualTo(0); label.setText("Label text updated directly"); assertThat(textProperty.get()).isEqualTo("Label text updated directly"); assertThat(listener.getCount()).isEqualTo(1); textProperty.set("Label text updated via property"); assertThat(label.getText()).isEqualTo("Label text updated via property"); assertThat(listener.getCount()).isEqualTo(2); }
@Test public void textPropertyCanWrapButton() { JButton button = new JButton("New Button"); TextProperty textProperty = new TextProperty(button); CountListener listener = new CountListener(); textProperty.addListener(listener); assertThat(textProperty.get()).isEqualTo("New Button"); assertThat(listener.getCount()).isEqualTo(0); button.setText("Button text updated directly"); assertThat(textProperty.get()).isEqualTo("Button text updated directly"); assertThat(listener.getCount()).isEqualTo(1); textProperty.set("Button text updated via property"); assertThat(button.getText()).isEqualTo("Button text updated via property"); assertThat(listener.getCount()).isEqualTo(2); }
@Test public void textPropertyCanWrapTextField() { JTextField field = new JTextField("New Field"); TextProperty textProperty = new TextProperty(field); CountListener listener = new CountListener(); textProperty.addListener(listener); assertThat(textProperty.get()).isEqualTo("New Field"); assertThat(listener.getCount()).isEqualTo(0); field.setText("Field text updated directly"); assertThat(textProperty.get()).isEqualTo("Field text updated directly"); assertThat(listener.getCount()).isEqualTo(2); textProperty.set("Field text updated via property"); assertThat(field.getText()).isEqualTo("Field text updated via property"); assertThat(listener.getCount()).isEqualTo(3); }
@Test public void textPropertyCanWrapLabelWithEditLink() { LabelWithEditButton editLabel = new LabelWithEditButton(); TextProperty textProperty = new TextProperty(editLabel); CountListener listener = new CountListener(); textProperty.addListener(listener); assertThat(textProperty.get()).isEqualTo(""); assertThat(listener.getCount()).isEqualTo(0); editLabel.setText("Edit label set directly"); assertThat(textProperty.get()).isEqualTo("Edit label set directly"); assertThat(listener.getCount()).isEqualTo(1); textProperty.set("Edit label updated via property"); assertThat(editLabel.getText()).isEqualTo("Edit label updated via property"); assertThat(listener.getCount()).isEqualTo(2); }