diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/gbl/GridBagLayoutSelectionActionsTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/gbl/GridBagLayoutSelectionActionsTest.java index 2ac36c0d1..78a159f63 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/gbl/GridBagLayoutSelectionActionsTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/gbl/GridBagLayoutSelectionActionsTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -19,7 +19,6 @@ import org.eclipse.jface.action.IAction; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.util.ArrayList; @@ -36,7 +35,6 @@ public class GridBagLayoutSelectionActionsTest extends AbstractGridBagLayoutTest // Tests // //////////////////////////////////////////////////////////////////////////// - @Disabled @Test public void test_selectionActions() throws Exception { ContainerInfo panel = parseContainer(""" diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/gbl/GridBagLayoutTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/gbl/GridBagLayoutTest.java index b535499c9..7f9cabe93 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/gbl/GridBagLayoutTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/gbl/GridBagLayoutTest.java @@ -40,7 +40,6 @@ import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.awt.Component; @@ -2355,7 +2354,6 @@ public Test() { /** * We should not change alignments when paste existing panel. */ - @Disabled @Test public void test_clipboard_disableAutoAlignment() throws Exception { ContainerInfo panel = parseContainer(""" @@ -2416,28 +2414,28 @@ public Test() { } } { - JPanel panel = new JPanel(); - add(panel); + JPanel inner = new JPanel(); + add(inner); GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{0, 0, 0}; gridBagLayout.rowHeights = new int[]{0, 0}; gridBagLayout.columnWeights = new double[]{0.0, 0.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE}; - panel.setLayout(gridBagLayout); + inner.setLayout(gridBagLayout); { JLabel label = new JLabel(); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 0, 5); gbc.gridx = 0; gbc.gridy = 0; - panel.add(label, gbc); + inner.add(label, gbc); } { JTextField textField = new JTextField(); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 0; - panel.add(textField, gbc); + inner.add(textField, gbc); } } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/BeanPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/BeanPropertyEditorTest.java index dd7fa6924..b4999754e 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/BeanPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/BeanPropertyEditorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -54,13 +54,12 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_ignore_SunBeansEditors() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new JButton());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new JButton()); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // check java.awt.Color type property "background" @@ -76,21 +75,18 @@ public void test_ignore_SunBeansEditors() throws Exception { */ @Test public void test_editorForEditor() throws Exception { - setFileContentSrc( - "test/MyEditor.java", - getTestSource( - "import java.beans.PropertyEditorSupport;", - "public class MyEditor extends PropertyEditorSupport {", - "}")); + setFileContentSrc("test/MyEditor.java", getTestSource(""" + import java.beans.PropertyEditorSupport; + public class MyEditor extends PropertyEditorSupport { + }""")); waitForAutoBuild(); // create panel - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); panel.refresh(); waitForAutoBuild(); // check wrapper for bean editor @@ -102,84 +98,75 @@ public void test_editorForEditor() throws Exception { @Test public void test_editorForEditor_beanInfo() throws Exception { // create "value" editor - setFileContentSrc( - "test/MyIntEditor.java", - getTestSource( - "import java.beans.PropertyEditorSupport;", - "public class MyIntEditor extends PropertyEditorSupport {", - "}")); + setFileContentSrc("test/MyIntEditor.java", getTestSource(""" + import java.beans.PropertyEditorSupport; + public class MyIntEditor extends PropertyEditorSupport { + }""")); // create "value2" editor - setFileContentSrc( - "test/MyComboEditor.java", - getTestSource( - "import java.beans.PropertyEditorSupport;", - "public class MyComboEditor extends PropertyEditorSupport {", - " private String[] m_items = {'111', '222', '333'};", - " public String[] getTags() {", - " return m_items;", - " }", - " public boolean supportsCustomEditor() {", - " return true;", - " }", - "}")); + setFileContentSrc("test/MyComboEditor.java", getTestSource(""" + import java.beans.PropertyEditorSupport; + public class MyComboEditor extends PropertyEditorSupport { + private String[] m_items = {"111", "222", "333"}; + public String[] getTags() { + return m_items; + } + public boolean supportsCustomEditor() { + return true; + } + }""")); // create test bean - setFileContentSrc( - "test/MyBean.java", - getTestSource( - "public class MyBean extends JButton {", - " private Object m_value;", - " private String m_value2;", - " public Object getValue() {", - " return m_value;", - " }", - " public void setValue(Object value) {", - " m_value = value;", - " }", - " public String getValue2() {", - " return m_value2;", - " }", - " public void setValue2(String value) {", - " m_value2 = value;", - " }", - "}")); + setFileContentSrc("test/MyBean.java", getTestSource(""" + public class MyBean extends JButton { + private Object m_value; + private String m_value2; + public Object getValue() { + return m_value; + } + public void setValue(Object value) { + m_value = value; + } + public String getValue2() { + return m_value2; + } + public void setValue2(String value) { + m_value2 = value; + } + }""")); waitForAutoBuild(); // create test bean info - setFileContentSrc( - "test/MyBeanBeanInfo.java", - getTestSource( - "import java.beans.BeanInfo;", - "import java.beans.Introspector;", - "import java.beans.SimpleBeanInfo;", - "import java.beans.PropertyDescriptor;", - "public class MyBeanBeanInfo extends SimpleBeanInfo {", - " private PropertyDescriptor[] m_descriptors;", - " public MyBeanBeanInfo() {", - " try {", - " BeanInfo info = Introspector.getBeanInfo(JButton.class);", - " PropertyDescriptor[] descriptors = info.getPropertyDescriptors();", - " m_descriptors = new PropertyDescriptor[descriptors.length + 2];", - " System.arraycopy(descriptors, 0, m_descriptors, 0, descriptors.length);", - " m_descriptors[descriptors.length] = new PropertyDescriptor('value', MyBean.class, 'getValue', 'setValue');", - " m_descriptors[descriptors.length].setPropertyEditorClass(MyIntEditor.class);", - " m_descriptors[descriptors.length + 1] = new PropertyDescriptor('value2', MyBean.class, 'getValue2', 'setValue2');", - " m_descriptors[descriptors.length + 1].setPropertyEditorClass(MyComboEditor.class);", - " } catch (Throwable e) {", - " }", - " }", - " public PropertyDescriptor[] getPropertyDescriptors() {", - " return m_descriptors;", - " }", - "}")); + setFileContentSrc("test/MyBeanBeanInfo.java", getTestSource(""" + import java.beans.BeanInfo; + import java.beans.Introspector; + import java.beans.SimpleBeanInfo; + import java.beans.PropertyDescriptor; + public class MyBeanBeanInfo extends SimpleBeanInfo { + private PropertyDescriptor[] m_descriptors; + public MyBeanBeanInfo() { + try { + BeanInfo info = Introspector.getBeanInfo(JButton.class); + PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); + m_descriptors = new PropertyDescriptor[descriptors.length + 2]; + System.arraycopy(descriptors, 0, m_descriptors, 0, descriptors.length); + m_descriptors[descriptors.length] = new PropertyDescriptor("value", MyBean.class, "getValue", "setValue"); + m_descriptors[descriptors.length].setPropertyEditorClass(MyIntEditor.class); + m_descriptors[descriptors.length + 1] = new PropertyDescriptor("value2", MyBean.class, "getValue2", "setValue2"); + m_descriptors[descriptors.length + 1].setPropertyEditorClass(MyComboEditor.class); + } catch (Throwable e) { + } + } + public PropertyDescriptor[] getPropertyDescriptors() { + return m_descriptors; + } + }""")); waitForAutoBuild(); // create panel - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyBean bean = new MyBean();", - " add(bean);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyBean bean = new MyBean(); + add(bean); + } + }"""); panel.refresh(); ComponentInfo bean = panel.getChildrenComponents().get(0); // check text property "value" @@ -205,51 +192,44 @@ public void test_editorForEditor_beanInfo() throws Exception { */ @Test public void test_EditorForType_exceptionDuringLoadingEditor() throws Exception { - setFileContentSrc( - "test/MyEditor.java", - getTestSource( - "import java.beans.PropertyEditorSupport;", - "public class MyEditor extends PropertyEditorSupport {", - " public MyEditor() {", - " throw new IllegalStateException('actual');", - " }", - "}")); - setFileContentSrc( - "test/MyBean.java", - getTestSource( - "public class MyBean extends JButton {", - " public void setValue(Object value) {", - " }", - "}")); - setFileContentSrc( - "test/MyBeanBeanInfo.java", - getTestSource( - "import java.beans.*;", - "public class MyBeanBeanInfo extends SimpleBeanInfo {", - " private PropertyDescriptor[] m_descriptors;", - " public MyBeanBeanInfo() {", - " try {", - " BeanInfo info = Introspector.getBeanInfo(JButton.class);", - " m_descriptors = new PropertyDescriptor[1];", - " m_descriptors[0] = new PropertyDescriptor('value', MyBean.class, null, 'setValue');", - " m_descriptors[0].setPropertyEditorClass(MyEditor.class);", - " } catch (Throwable e) {", - " }", - " }", - " public PropertyDescriptor[] getPropertyDescriptors() {", - " return m_descriptors;", - " }", - "}")); + setFileContentSrc("test/MyEditor.java", getTestSource(""" + import java.beans.PropertyEditorSupport; + public class MyEditor extends PropertyEditorSupport { + public MyEditor() { + throw new IllegalStateException("actual"); + } + }""")); + setFileContentSrc("test/MyBean.java", getTestSource(""" + public class MyBean extends JButton { + public void setValue(Object value) { + } + }""")); + setFileContentSrc("test/MyBeanBeanInfo.java",getTestSource(""" + import java.beans.*; + public class MyBeanBeanInfo extends SimpleBeanInfo { + private PropertyDescriptor[] m_descriptors; + public MyBeanBeanInfo() { + try { + BeanInfo info = Introspector.getBeanInfo(JButton.class); + m_descriptors = new PropertyDescriptor[1]; + m_descriptors[0] = new PropertyDescriptor("value", MyBean.class, null, "setValue"); + m_descriptors[0].setPropertyEditorClass(MyEditor.class); + } catch (Throwable e) { + } + } + public PropertyDescriptor[] getPropertyDescriptors() { + return m_descriptors; + } + }""")); waitForAutoBuild(); // create panel - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyBean bean = new MyBean();", - " add(bean);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyBean bean = new MyBean(); + add(bean); + } + }"""); ComponentInfo bean = panel.getChildrenComponents().get(0); // "MyEditor" throws exception, so it is ignored and default "Object" editor used Property property = bean.getPropertyByTitle("value"); @@ -262,28 +242,24 @@ public void test_EditorForType_exceptionDuringLoadingEditor() throws Exception { */ @Test public void test_getEditorForType() throws Exception { - setFileContentSrc( - "test/MyBean.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class MyBean {", - " // filler", - "}")); - setFileContentSrc( - "test/MyBeanEditor.java", - getTestSource( - "import java.beans.PropertyEditorSupport;", - "public class MyBeanEditor extends PropertyEditorSupport {", - "}")); + setFileContentSrc("test/MyBean.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class MyBean { + // filler + }""")); + setFileContentSrc("test/MyBeanEditor.java",getTestSource(""" + import java.beans.PropertyEditorSupport; + public class MyBeanEditor extends PropertyEditorSupport { + }""")); waitForAutoBuild(); // parse to access class loader - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); // check property editor Class beanType = m_lastLoader.loadClass("test.MyBean"); PropertyEditor propertyEditor = DescriptionPropertiesHelper.getEditorForType(beanType); @@ -295,36 +271,29 @@ public void test_getEditorForType() throws Exception { */ @Test public void test_getEditorForType_whenParsing() throws Exception { - setFileContentSrc( - "test/MyBean.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "// filler filler filler", - "public class MyBean {", - "}")); - setFileContentSrc( - "test/MyBeanEditor.java", - getTestSource( - "import java.beans.PropertyEditorSupport;", - "public class MyBeanEditor extends PropertyEditorSupport {", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setMyBean(MyBean bean) {", - " }", - "}")); + setFileContentSrc("test/MyBean.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + // filler filler filler + public class MyBean { + }""")); + setFileContentSrc("test/MyBeanEditor.java", getTestSource(""" + import java.beans.PropertyEditorSupport; + public class MyBeanEditor extends PropertyEditorSupport { + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setMyBean(MyBean bean) { + } + }""")); waitForAutoBuild(); // parse to access class loader - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // check "myBean" property Property property = panel.getPropertyByTitle("myBean"); assertNotNull(property); @@ -339,14 +308,13 @@ public void test_getEditorForType_whenParsing() throws Exception { @Test public void test_getAsText_setAsText() throws Exception { prepare_TextPropertyEditor(); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyBean button = new MyBean();", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyBean button = new MyBean(); + add(button); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // check text property "value" @@ -364,14 +332,14 @@ public void test_getAsText_setAsText() throws Exception { String.class, property, "abc"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " MyBean button = new MyBean();", - " button.setValue(new MyWrapper('abc'));", - " add(button);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + MyBean button = new MyBean(); + button.setValue(new MyWrapper("abc")); + add(button); + } + }"""); assertEquals("abc", getPropertyText(property)); // set empty text, so remove value ReflectionUtils.invokeMethod2( @@ -381,13 +349,13 @@ public void test_getAsText_setAsText() throws Exception { String.class, property, ""); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " MyBean button = new MyBean();", - " add(button);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + MyBean button = new MyBean(); + add(button); + } + }"""); assertEquals(null, getPropertyText(property)); } @@ -396,27 +364,25 @@ public void test_getAsText_setAsText() throws Exception { * {@link TextPropertyEditor}. */ private void prepare_TextPropertyEditor() throws Exception { - setFileContentSrc( - "test/MyEditor.java", - getTestSource( - "import java.beans.PropertyEditorSupport;", - "public class MyEditor extends PropertyEditorSupport {", - " public String getAsText() {", - " if (getValue() == null) {", - " return null;", - " }", - " return ((MyWrapper)getValue()).getText();", - " }", - " public void setAsText(String value) {", - " setValue(new MyWrapper(value));", - " }", - " public String getJavaInitializationString() {", - " if (this.getAsText().length() > 0) {", - " return 'new test.MyWrapper(\\'' + getAsText() + '\\')';", - " }", - " return null;", - " }", - "}")); + setFileContentSrc("test/MyEditor.java", getTestSource(""" + import java.beans.PropertyEditorSupport; + public class MyEditor extends PropertyEditorSupport { + public String getAsText() { + if (getValue() == null) { + return null; + } + return ((MyWrapper)getValue()).getText(); + } + public void setAsText(String value) { + setValue(new MyWrapper(value)); + } + public String getJavaInitializationString() { + if (this.getAsText().length() > 0) { + return "new test.MyWrapper(\\"" + getAsText() + "\\")"; + } + return null; + } + }""")); prepare_MyWrapper_MyBean(); } @@ -425,84 +391,76 @@ private void prepare_TextPropertyEditor() throws Exception { * {@link ComboPropertyEditor}, with items "111", "222", "333". */ private void prepare_ComboPropertyEditor() throws Exception { - setFileContentSrc( - "test/MyEditor.java", - getTestSource( - "import java.beans.PropertyEditorSupport;", - "public class MyEditor extends PropertyEditorSupport {", - " public String getAsText() {", - " if (getValue() == null) {", - " return null;", - " }", - " return ((MyWrapper)getValue()).getText();", - " }", - " public void setAsText(String value) {", - " setValue(new MyWrapper(value));", - " }", - " public String getJavaInitializationString() {", - " if (this.getAsText().length() > 0) {", - " return 'new test.MyWrapper(\\'' + getAsText() + '\\')';", - " }", - " return null;", - " }", - " private String[] m_items = {'111', '222', '333'};", - " public String[] getTags() {", - " return m_items;", - " }", - "}")); + setFileContentSrc("test/MyEditor.java", getTestSource(""" + import java.beans.PropertyEditorSupport; + public class MyEditor extends PropertyEditorSupport { + public String getAsText() { + if (getValue() == null) { + return null; + } + return ((MyWrapper)getValue()).getText(); + } + public void setAsText(String value) { + setValue(new MyWrapper(value)); + } + public String getJavaInitializationString() { + if (this.getAsText().length() > 0) { + return "new test.MyWrapper(\\"" + getAsText() + "\\")"; + } + return null; + } + private String[] m_items = {"111", "222", "333"}; + public String[] getTags() { + return m_items; + } + }""")); prepare_MyWrapper_MyBean(); } private void prepare_MyWrapper_MyBean() throws Exception { - setFileContentSrc( - "test/MyWrapper.java", - getTestSource( - "public class MyWrapper {", - " private final String m_text;", - " public MyWrapper(String text) {", - " m_text = text;", - " }", - " public String getText() {", - " return m_text;", - " }", - "}")); - setFileContentSrc( - "test/MyBean.java", - getTestSource( - "public class MyBean extends JButton {", - " private Object m_value;", - " public Object getValue() {", - " return m_value;", - " }", - " public void setValue(Object value) {", - " m_value = value;", - " }", - "}")); + setFileContentSrc("test/MyWrapper.java", getTestSource(""" + public class MyWrapper { + private final String m_text; + public MyWrapper(String text) { + m_text = text; + } + public String getText() { + return m_text; + } + }""")); + setFileContentSrc("test/MyBean.java", getTestSource(""" + public class MyBean extends JButton { + private Object m_value; + public Object getValue() { + return m_value; + } + public void setValue(Object value) { + m_value = value; + } + }""")); // create test BeanInfo - setFileContentSrc( - "test/MyBeanBeanInfo.java", - getTestSource( - "import java.beans.BeanInfo;", - "import java.beans.Introspector;", - "import java.beans.SimpleBeanInfo;", - "import java.beans.PropertyDescriptor;", - "public class MyBeanBeanInfo extends SimpleBeanInfo {", - " private PropertyDescriptor[] m_descriptors;", - " public MyBeanBeanInfo() {", - " try {", - " BeanInfo info = Introspector.getBeanInfo(JButton.class);", - " PropertyDescriptor[] descriptors = info.getPropertyDescriptors();", - " m_descriptors = new PropertyDescriptor[descriptors.length + 1];", - " System.arraycopy(descriptors, 0, m_descriptors, 0, descriptors.length);", - " m_descriptors[descriptors.length] = new PropertyDescriptor('value', MyBean.class, 'getValue', 'setValue');", - " m_descriptors[descriptors.length].setPropertyEditorClass(MyEditor.class);", - " } catch (Throwable e) {", - " }", - " }", - " public PropertyDescriptor[] getPropertyDescriptors() {", - " return m_descriptors;", - " }", - "}")); + setFileContentSrc("test/MyBeanBeanInfo.java", getTestSource(""" + import java.beans.BeanInfo; + import java.beans.Introspector; + import java.beans.SimpleBeanInfo; + import java.beans.PropertyDescriptor; + public class MyBeanBeanInfo extends SimpleBeanInfo { + private PropertyDescriptor[] m_descriptors; + public MyBeanBeanInfo() { + try { + BeanInfo info = Introspector.getBeanInfo(JButton.class); + PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); + m_descriptors = new PropertyDescriptor[descriptors.length + 1]; + System.arraycopy(descriptors, 0, m_descriptors, 0, descriptors.length); + m_descriptors[descriptors.length] = new PropertyDescriptor("value", MyBean.class, "getValue", "setValue"); + m_descriptors[descriptors.length].setPropertyEditorClass(MyEditor.class); + } catch (Throwable e) { + } + } + public PropertyDescriptor[] getPropertyDescriptors() { + return m_descriptors; + } + }""")); waitForAutoBuild(); } @@ -524,14 +482,13 @@ private Object createMyWrapper(String value) throws Exception { @Test public void test_IValueSourcePropertyEditor_TextPropertyEditor() throws Exception { prepare_TextPropertyEditor(); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyBean button = new MyBean();", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyBean button = new MyBean(); + add(button); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); Property property = button.getPropertyByTitle("value"); @@ -542,14 +499,14 @@ public void test_IValueSourcePropertyEditor_TextPropertyEditor() throws Exceptio assertEquals("new test.MyWrapper(\"myValue\")", propertyEditor.getValueSource(wrapper)); // set value, IValueSourcePropertyEditor should be used property.setValue(wrapper); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " MyBean button = new MyBean();", - " button.setValue(new MyWrapper('myValue'));", - " add(button);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + MyBean button = new MyBean(); + button.setValue(new MyWrapper("myValue")); + add(button); + } + }"""); assertEquals("myValue", getPropertyText(property)); } @@ -560,14 +517,13 @@ public void test_IValueSourcePropertyEditor_TextPropertyEditor() throws Exceptio @Test public void test_IValueSourcePropertyEditor_ComboPropertyEditor() throws Exception { prepare_ComboPropertyEditor(); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyBean button = new MyBean();", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyBean button = new MyBean(); + add(button); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); Property property = button.getPropertyByTitle("value"); @@ -578,14 +534,14 @@ public void test_IValueSourcePropertyEditor_ComboPropertyEditor() throws Excepti assertEquals("new test.MyWrapper(\"222\")", propertyEditor.getValueSource(wrapper)); // set value, IValueSourcePropertyEditor should be used property.setValue(wrapper); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " MyBean button = new MyBean();", - " button.setValue(new MyWrapper('222'));", - " add(button);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + MyBean button = new MyBean(); + button.setValue(new MyWrapper("222")); + add(button); + } + }"""); assertEquals("222", getPropertyText(property)); } @@ -601,20 +557,19 @@ public void test_IValueSourcePropertyEditor_ComboPropertyEditor() throws Excepti @Test public void test_PropertyEditorSupport_setSource_1() throws Exception { configure_PropertyEditorSupport_setSource_forText(); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " {", - " MyBean bean = new MyBean(1);", - " add(bean);", - " }", - " {", - " MyBean bean = new MyBean(2);", - " add(bean);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + { + MyBean bean = new MyBean(1); + add(bean); + } + { + MyBean bean = new MyBean(2); + add(bean); + } + } + }"""); panel.refresh(); // "foo" for button "1" { @@ -637,16 +592,15 @@ public void test_PropertyEditorSupport_setSource_1() throws Exception { @Test public void test_PropertyEditorSupport_setSource_2() throws Exception { configure_PropertyEditorSupport_setSource_forText(); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " {", - " MyBean bean = new MyBean(5);", - " add(bean);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + { + MyBean bean = new MyBean(5); + add(bean); + } + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); Property property = button.getPropertyByTitle("foo"); @@ -658,16 +612,16 @@ public void test_PropertyEditorSupport_setSource_2() throws Exception { String.class, property, "000"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " {", - " MyBean bean = new MyBean(5);", - " bean.setFoo(5);", - " add(bean);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + { + MyBean bean = new MyBean(5); + bean.setFoo(5); + add(bean); + } + } + }"""); assertEquals("5", getPropertyText(property)); } @@ -677,31 +631,28 @@ public void test_PropertyEditorSupport_setSource_2() throws Exception { */ @Test public void test_PropertyEditorSupport_setSource_forCombo() throws Exception { - setFileContentSrc( - "test/MyEditor.java", - getTestSource( - "import java.beans.PropertyEditorSupport;", - "public class MyEditor extends PropertyEditorSupport {", - " public String[] getTags() {", - " if (getSource() instanceof MyBean) {", - " int value = ((MyBean) getSource()).m_value;", - " return new String[] {'' + (value + 0), '' + (value + 1)};", - " }", - " return new String[] {};", - " }", - "}")); + setFileContentSrc("test/MyEditor.java", getTestSource(""" + import java.beans.PropertyEditorSupport; + public class MyEditor extends PropertyEditorSupport { + public String[] getTags() { + if (getSource() instanceof MyBean) { + int value = ((MyBean) getSource()).m_value; + return new String[] {"" + (value + 0), "" + (value + 1)}; + } + return new String[] {}; + } + }""")); configure_PropertyEditorSupport_setSource_justBean(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " {", - " MyBean bean = new MyBean(5);", - " add(bean);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + { + MyBean bean = new MyBean(5); + add(bean); + } + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); Property property = button.getPropertyByTitle("foo"); @@ -717,62 +668,56 @@ public void test_PropertyEditorSupport_setSource_forCombo() throws Exception { } private void configure_PropertyEditorSupport_setSource_forText() throws Exception { - setFileContentSrc( - "test/MyEditor.java", - getTestSource( - "import java.beans.PropertyEditorSupport;", - "public class MyEditor extends PropertyEditorSupport {", - " public String getAsText() {", - " return '' + ((MyBean) getSource()).m_value;", - " }", - " public void setAsText(String text) {", - " // do nothing", - " }", - " public String getJavaInitializationString() {", - " return '' + ((MyBean) getSource()).m_value;", - " }", - "}")); + setFileContentSrc("test/MyEditor.java", getTestSource(""" + import java.beans.PropertyEditorSupport; + public class MyEditor extends PropertyEditorSupport { + public String getAsText() { + return "" + ((MyBean) getSource()).m_value; + } + public void setAsText(String text) { + // do nothing + } + public String getJavaInitializationString() { + return "" + ((MyBean) getSource()).m_value; + } + }""")); configure_PropertyEditorSupport_setSource_justBean(); } private void configure_PropertyEditorSupport_setSource_justBean() throws Exception { - setFileContentSrc( - "test/MyBean.java", - getTestSource( - "public class MyBean extends JButton {", - " int m_value;", - " private int m_foo;", - " public MyBean(int value) {", - " m_value = value;", - " }", - " public int getFoo() {", - " return m_foo;", - " }", - " public void setFoo(int foo) {", - " m_foo = foo;", - " }", - "}")); - setFileContentSrc( - "test/MyBeanBeanInfo.java", - getTestSource( - "import java.beans.*;", - "public class MyBeanBeanInfo extends SimpleBeanInfo {", - " private PropertyDescriptor[] m_descriptors;", - " public MyBeanBeanInfo() {", - " try {", - " BeanInfo info = Introspector.getBeanInfo(JButton.class);", - " PropertyDescriptor[] descriptors = info.getPropertyDescriptors();", - " m_descriptors = new PropertyDescriptor[descriptors.length + 1];", - " System.arraycopy(descriptors, 0, m_descriptors, 0, descriptors.length);", - " m_descriptors[descriptors.length] = new PropertyDescriptor('foo', MyBean.class, 'getFoo', 'setFoo');", - " m_descriptors[descriptors.length].setPropertyEditorClass(MyEditor.class);", - " } catch (Throwable e) {", - " }", - " }", - " public PropertyDescriptor[] getPropertyDescriptors() {", - " return m_descriptors;", - " }", - "}")); + setFileContentSrc("test/MyBean.java", getTestSource(""" + public class MyBean extends JButton { + int m_value; + private int m_foo; + public MyBean(int value) { + m_value = value; + } + public int getFoo() { + return m_foo; + } + public void setFoo(int foo) { + m_foo = foo; + } + }""")); + setFileContentSrc("test/MyBeanBeanInfo.java", getTestSource(""" + import java.beans.*; + public class MyBeanBeanInfo extends SimpleBeanInfo { + private PropertyDescriptor[] m_descriptors; + public MyBeanBeanInfo() { + try { + BeanInfo info = Introspector.getBeanInfo(JButton.class); + PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); + m_descriptors = new PropertyDescriptor[descriptors.length + 1]; + System.arraycopy(descriptors, 0, m_descriptors, 0, descriptors.length); + m_descriptors[descriptors.length] = new PropertyDescriptor("foo", MyBean.class, "getFoo", "setFoo"); + m_descriptors[descriptors.length].setPropertyEditorClass(MyEditor.class); + } catch (Throwable e) { + } + } + public PropertyDescriptor[] getPropertyDescriptors() { + return m_descriptors; + } + }""")); waitForAutoBuild(); } } \ No newline at end of file diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/FontPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/FontPropertyEditorTest.java index 1309acdcd..0e3652855 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/FontPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/FontPropertyEditorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -648,16 +648,15 @@ private void assertFont(String fontSource, String expectedText) throws Exception private void assertFont(String fontSource, String expectedText, String expectedClipboard) throws Exception { - String fontLine = fontSource != null ? " button.setFont(" + fontSource + ");" : ""; - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - fontLine, - " add(button);", - " }", - "}"); + String fontLine = fontSource != null ? "button.setFont(" + fontSource + ");" : ""; + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + %s + add(button); + } + }""".formatted(fontLine)); ComponentInfo button = panel.getChildrenComponents().get(0); // property Property property = button.getPropertyByTitle("font"); @@ -697,18 +696,17 @@ public void test_copyPaste_derived() throws Exception { } private void check_copyPaste(String originalSource, String expectedSource) throws Exception { - String[] lines1 = - { - "public class Test extends JPanel {", - " public Test() {", - " {", - " JLabel myLabel = new JLabel();", - " myLabel.setFont(" + originalSource + ");", - " add(myLabel);", - " }", - " }", - "}"}; - ContainerInfo panel = parseContainer(lines1); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + { + JLabel myLabel = new JLabel(); + myLabel.setFont(%s); + add(myLabel); + } + } + } + """.formatted(originalSource)); panel.refresh(); ComponentInfo label = panel.getChildrenComponents().get(0); // @@ -718,22 +716,21 @@ private void check_copyPaste(String originalSource, String expectedSource) throw ((FlowLayoutInfo) panel.getLayout()).add(newLabel, null); memento.apply(); } - String[] lines = - { - "public class Test extends JPanel {", - " public Test() {", - " {", - " JLabel myLabel = new JLabel();", - " myLabel.setFont(" + originalSource + ");", - " add(myLabel);", - " }", - " {", - " JLabel myLabel = new JLabel();", - " myLabel.setFont(" + expectedSource + ");", - " add(myLabel);", - " }", - " }", - "}"}; - assertEditor(lines); + assertEditor(""" + public class Test extends JPanel { + public Test() { + { + JLabel myLabel = new JLabel(); + myLabel.setFont(%s); + add(myLabel); + } + { + JLabel myLabel = new JLabel(); + myLabel.setFont(%s); + add(myLabel); + } + } + } + """.formatted(originalSource, expectedSource)); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/IconPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/IconPropertyEditorTest.java index 4706ab06a..a4ad1be1b 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/IconPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/IconPropertyEditorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -36,25 +36,25 @@ public class IconPropertyEditorTest extends SwingModelTest { //////////////////////////////////////////////////////////////////////////// @Test public void test_getText_noIcon() throws Exception { - assertIconPropertyText(null, new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " add(button);", - " }", - "}"}); + assertIconPropertyText(null, """ + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + add(button); + } + }"""); } @Test public void test_getText_null() throws Exception { - assertIconPropertyText("(null)", new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " button.setIcon(null);", - " add(button);", - " }", - "}"}); + assertIconPropertyText("(null)", """ + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + button.setIcon(null); + add(button); + } + }"""); } @Test @@ -62,14 +62,14 @@ public void test_getText_fromFile_1() throws Exception { IFile imageFile = TestUtils.createImagePNG(m_testProject, "1.png", 10, 10); try { String absoluteImagePath = imageFile.getLocation().toPortableString(); - assertIconPropertyText("File: " + absoluteImagePath, new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " button.setIcon(new ImageIcon(\"" + absoluteImagePath + "\"));", - " add(button);", - " }", - "}"}); + assertIconPropertyText("File: " + absoluteImagePath, """ + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + button.setIcon(new ImageIcon("%s")); + add(button); + } + }""".formatted(absoluteImagePath)); } finally { forceDeleteResource(imageFile); } @@ -80,18 +80,14 @@ public void test_getText_fromFile_2() throws Exception { IFile imageFile = TestUtils.createImagePNG(m_testProject, "1.png", 10, 10); try { String absoluteImagePath = imageFile.getLocation().toPortableString(); - assertIconPropertyText( - "File: " + absoluteImagePath, - new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " button.setIcon(new ImageIcon(\"" - + absoluteImagePath - + "\", \"some description\"));", - " add(button);", - " }", - "}"}); + assertIconPropertyText("File: " + absoluteImagePath, """ + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + button.setIcon(new ImageIcon("%s", "some description")); + add(button); + } + }""".formatted(absoluteImagePath)); } finally { forceDeleteResource(imageFile); } @@ -100,69 +96,59 @@ public void test_getText_fromFile_2() throws Exception { @Test public void test_getText_Class_getResource_1() throws Exception { setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1)); - assertIconPropertyText( - "Classpath: /Test.png", - new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " button.setIcon(new ImageIcon(Test.class.getResource(\"/Test.png\")));", - " add(button);", - " }", - "}"}); + assertIconPropertyText("Classpath: /Test.png", """ + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + button.setIcon(new ImageIcon(Test.class.getResource("/Test.png"))); + add(button); + } + }"""); } @Test public void test_getText_Class_getResource_2() throws Exception { setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1)); - assertIconPropertyText( - "Classpath: /Test.png", - new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " button.setIcon(" - + " new ImageIcon(Test.class.getResource(\"/Test.png\"), " - + " \"Some description\"));", - " add(button);", - " }", - "}"}); + assertIconPropertyText("Classpath: /Test.png", """ + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + button.setIcon(new ImageIcon(Test.class.getResource("/Test.png"), "Some description")); + add(button); + } + }"""); } @Test public void test_getText_Class_getResource_3() throws Exception { setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1)); - assertIconPropertyText( - "Classpath: /Test.png", - new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " Icon icon = new ImageIcon(Test.class.getResource(\"/Test.png\"));", - " button.setIcon(icon);", - " add(button);", - " }", - "}"}); + assertIconPropertyText("Classpath: /Test.png", """ + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + Icon icon = new ImageIcon(Test.class.getResource("/Test.png")); + button.setIcon(icon); + add(button); + } + }"""); } @Test public void test_getText_Class_getResource_4() throws Exception { setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1)); - assertIconPropertyText( - "Classpath: /Test.png", - new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " java.net.URL url = Test.class.getResource(\"/Test.png\");", - " Icon icon = new ImageIcon(url);", - " button.setIcon(icon);", - " add(button);", - " }", - "}"}); + assertIconPropertyText("Classpath: /Test.png", """ + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + java.net.URL url = Test.class.getResource("/Test.png"); + Icon icon = new ImageIcon(url); + button.setIcon(icon); + add(button); + } + }"""); } - private void assertIconPropertyText(String expectedText, String[] lines) throws Exception { + private void assertIconPropertyText(String expectedText, String lines) throws Exception { ContainerInfo panel = parseContainer(lines); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/ImagePropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/ImagePropertyEditorTest.java index f1a28507f..63e66c41e 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/ImagePropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/ImagePropertyEditorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -35,21 +35,21 @@ public class ImagePropertyEditorTest extends SwingModelTest { //////////////////////////////////////////////////////////////////////////// @Test public void test_getText_noIimage() throws Exception { - assertImagePropertyText(null, new String[]{ - "public class Test extends JFrame {", - " public Test() {", - " }", - "}"}); + assertImagePropertyText(null, """ + public class Test extends JFrame { + public Test() { + } + }"""); } @Test public void test_getText_null() throws Exception { - assertImagePropertyText("(null)", new String[]{ - "public class Test extends JFrame {", - " public Test() {", - " setIconImage(null);", - " }", - "}"}); + assertImagePropertyText("(null)", """ + public class Test extends JFrame { + public Test() { + setIconImage(null); + } + }"""); } @Test @@ -57,12 +57,12 @@ public void test_getText_fromFile() throws Exception { IFile imageFile = TestUtils.createImagePNG(m_testProject, "1.png", 10, 10); try { String absoluteImagePath = imageFile.getLocation().toPortableString(); - assertImagePropertyText("File: " + absoluteImagePath, new String[]{ - "public class Test extends JFrame {", - " public Test() {", - " setIconImage(Toolkit.getDefaultToolkit().getImage(\"" + absoluteImagePath + "\"));", - " }", - "}"}); + assertImagePropertyText("File: " + absoluteImagePath, """ + public class Test extends JFrame { + public Test() { + setIconImage(Toolkit.getDefaultToolkit().getImage("%s")); + } + }""".formatted(absoluteImagePath)); } finally { imageFile.delete(true, null); } @@ -71,46 +71,40 @@ public void test_getText_fromFile() throws Exception { @Test public void test_getText_Class_getResource_1() throws Exception { setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1)); - assertImagePropertyText( - "Classpath: /Test.png", - new String[]{ - "public class Test extends JFrame {", - " public Test() {", - " setIconImage(Toolkit.getDefaultToolkit().getImage(Test.class.getResource(\"/Test.png\")));", - " }", - "}"}); + assertImagePropertyText("Classpath: /Test.png", """ + public class Test extends JFrame { + public Test() { + setIconImage(Toolkit.getDefaultToolkit().getImage(Test.class.getResource("/Test.png"))); + } + }"""); } @Test public void test_getText_Class_getResource_2() throws Exception { setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1)); - assertImagePropertyText( - "Classpath: /Test.png", - new String[]{ - "public class Test extends JFrame {", - " public Test() {", - " Image icon = Toolkit.getDefaultToolkit().getImage(Test.class.getResource(\"/Test.png\"));", - " setIconImage(icon);", - " }", - "}"}); + assertImagePropertyText("Classpath: /Test.png", """ + public class Test extends JFrame { + public Test() { + Image icon = Toolkit.getDefaultToolkit().getImage(Test.class.getResource("/Test.png")); + setIconImage(icon); + } + }"""); } @Test public void test_getText_Class_getResource_3() throws Exception { setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1)); - assertImagePropertyText( - "Classpath: /Test.png", - new String[]{ - "public class Test extends JFrame {", - " public Test() {", - " java.net.URL url = Test.class.getResource(\"/Test.png\");", - " Image icon = Toolkit.getDefaultToolkit().getImage(url);", - " setIconImage(icon);", - " }", - "}"}); + assertImagePropertyText("Classpath: /Test.png", """ + public class Test extends JFrame { + public Test() { + java.net.URL url = Test.class.getResource("/Test.png"); + Image icon = Toolkit.getDefaultToolkit().getImage(url); + setIconImage(icon); + } + }"""); } - private void assertImagePropertyText(String expectedText, String[] lines) throws Exception { + private void assertImagePropertyText(String expectedText, String lines) throws Exception { m_waitForAutoBuild = true; JFrameInfo frame = (JFrameInfo) parseContainer(lines); frame.refresh(); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/TabOrderPropertyTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/TabOrderPropertyTest.java index de90464e4..4335d04e8 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/TabOrderPropertyTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/TabOrderPropertyTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2023 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -72,13 +72,12 @@ public void _test_exit() throws Exception { @Test public void test_common() throws Exception { // create panel - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); panel.refresh(); // property TabOrderProperty property = (TabOrderProperty) panel.getPropertyByTitle("tab order"); @@ -97,18 +96,17 @@ public void test_common() throws Exception { @Test public void test_getValue_noValue() throws Exception { // create panel - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton('Button');", - " add(button);", - " JPanel panel = new JPanel();", - " add(panel);", - " JLabel label = new JLabel('Label');", - " panel.add(label);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + JButton button = new JButton("Button"); + add(button); + JPanel panel = new JPanel(); + add(panel); + JLabel label = new JLabel("Label"); + panel.add(label); + } + }"""); panel.refresh(); // property TabOrderProperty property = (TabOrderProperty) panel.getPropertyByTitle("tab order"); @@ -133,17 +131,16 @@ public void test_getValue_noValue() throws Exception { @Test public void test_getValue() throws Exception { // create panel - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton('Button');", - " add(button);", - " JComboBox combo = new JComboBox();", - " add(combo);", - " setFocusTraversalPolicy(new org.eclipse.wb.swing.FocusTraversalOnArray(new Component[]{button}));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + JButton button = new JButton("Button"); + add(button); + JComboBox combo = new JComboBox(); + add(combo); + setFocusTraversalPolicy(new org.eclipse.wb.swing.FocusTraversalOnArray(new Component[]{button})); + } + }"""); panel.refresh(); // property TabOrderProperty property = (TabOrderProperty) panel.getPropertyByTitle("tab order"); @@ -164,55 +161,49 @@ public void test_getValue() throws Exception { @Test public void test_setValue_UNKNOWN_VALUE() throws Exception { - test_setValue( - new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton('Button');", - " add(button);", - " JComboBox combo = new JComboBox();", - " add(combo);", - " setFocusTraversalPolicy(new org.eclipse.wb.swing.FocusTraversalOnArray(new Component[]{button}));", - " }", - "}"}, - Property.UNKNOWN_VALUE, - new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton('Button');", - " add(button);", - " JComboBox combo = new JComboBox();", - " add(combo);", - " }", - "}"}); + test_setValue(""" + public class Test extends JPanel { + public Test() { + JButton button = new JButton("Button"); + add(button); + JComboBox combo = new JComboBox(); + add(combo); + setFocusTraversalPolicy(new org.eclipse.wb.swing.FocusTraversalOnArray(new Component[]{button})); + } + }""", Property.UNKNOWN_VALUE, """ + public class Test extends JPanel { + public Test() { + JButton button = new JButton("Button"); + add(button); + JComboBox combo = new JComboBox(); + add(combo); + } + }"""); } @Test public void test_setValue_noValue() throws Exception { - test_setValue( - new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton('Button');", - " add(button);", - " JComboBox combo = new JComboBox();", - " add(combo);", - " setFocusTraversalPolicy(new org.eclipse.wb.swing.FocusTraversalOnArray(new Component[]{button}));", - " }", - "}"}, - new TabOrderInfo(), - new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton('Button');", - " add(button);", - " JComboBox combo = new JComboBox();", - " add(combo);", - " }", - "}"}); + test_setValue(""" + public class Test extends JPanel { + public Test() { + JButton button = new JButton("Button"); + add(button); + JComboBox combo = new JComboBox(); + add(combo); + setFocusTraversalPolicy(new org.eclipse.wb.swing.FocusTraversalOnArray(new Component[]{button})); + } + }""", new TabOrderInfo(), """ + public class Test extends JPanel { + public Test() { + JButton button = new JButton("Button"); + add(button); + JComboBox combo = new JComboBox(); + add(combo); + } + }"""); } - private void test_setValue(String[] startSource, Object value, String[] newSource) + private void test_setValue(String startSource, Object value, String newSource) throws Exception { // create panel ContainerInfo container = parseContainer(startSource); @@ -226,22 +217,21 @@ private void test_setValue(String[] startSource, Object value, String[] newSourc @Test public void test_setValue_noExisting() throws Exception { - ContainerInfo container = - parseContainer( - "public class Test extends JPanel {", - " private JButton button_1;", - " private JButton button_2;", - " public Test() {", - " {", - " button_1 = new JButton();", - " add(button_1);", - " }", - " {", - " button_2 = new JButton();", - " add(button_2);", - " }", - " }", - "}"); + ContainerInfo container = parseContainer(""" + public class Test extends JPanel { + private JButton button_1; + private JButton button_2; + public Test() { + { + button_1 = new JButton(); + add(button_1); + } + { + button_2 = new JButton(); + add(button_2); + } + } + }"""); container.refresh(); ComponentInfo button_1 = getJavaInfoByName("button_1"); TabOrderProperty property = (TabOrderProperty) container.getPropertyByTitle("tab order"); @@ -251,23 +241,23 @@ public void test_setValue_noExisting() throws Exception { newValue.addOrderedInfo(button_1); property.setValue(newValue); } - assertEditor( - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JPanel {", - " private JButton button_1;", - " private JButton button_2;", - " public Test() {", - " {", - " button_1 = new JButton();", - " add(button_1);", - " }", - " {", - " button_2 = new JButton();", - " add(button_2);", - " }", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button_1}));", - " }", - "}"); + assertEditor(""" + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JPanel { + private JButton button_1; + private JButton button_2; + public Test() { + { + button_1 = new JButton(); + add(button_1); + } + { + button_2 = new JButton(); + add(button_2); + } + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button_1})); + } + }"""); } /** @@ -276,24 +266,23 @@ public void test_setValue_noExisting() throws Exception { */ @Test public void test_setValue_hasExisting() throws Exception { - ContainerInfo container = - parseContainer( - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JPanel {", - " private JButton button_1;", - " private JButton button_2;", - " public Test() {", - " {", - " button_1 = new JButton();", - " add(button_1);", - " }", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button_1}));", - " {", - " button_2 = new JButton();", - " add(button_2);", - " }", - " }", - "}"); + ContainerInfo container = parseContainer(""" + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JPanel { + private JButton button_1; + private JButton button_2; + public Test() { + { + button_1 = new JButton(); + add(button_1); + } + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button_1})); + { + button_2 = new JButton(); + add(button_2); + } + } + }"""); container.refresh(); ComponentInfo button_1 = getJavaInfoByName("button_1"); ComponentInfo button_2 = getJavaInfoByName("button_2"); @@ -305,23 +294,23 @@ public void test_setValue_hasExisting() throws Exception { newValue.addOrderedInfo(button_2); property.setValue(newValue); } - assertEditor( - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JPanel {", - " private JButton button_1;", - " private JButton button_2;", - " public Test() {", - " {", - " button_1 = new JButton();", - " add(button_1);", - " }", - " {", - " button_2 = new JButton();", - " add(button_2);", - " }", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button_1, button_2}));", - " }", - "}"); + assertEditor(""" + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JPanel { + private JButton button_1; + private JButton button_2; + public Test() { + { + button_1 = new JButton(); + add(button_1); + } + { + button_2 = new JButton(); + add(button_2); + } + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button_1, button_2})); + } + }"""); } /** @@ -330,34 +319,33 @@ public void test_setValue_hasExisting() throws Exception { */ @Test public void test_noValue_addNewComponent() throws Exception { - ContainerInfo container = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button_1 = new JButton();", - " add(button_1);", - " }", - " }", - "}"); + ContainerInfo container = parseContainer(""" + public class Test extends JPanel { + public Test() { + { + JButton button_1 = new JButton(); + add(button_1); + } + } + }"""); container.refresh(); // add new JButton ComponentInfo newButton = createJButton(); ((FlowLayoutInfo) container.getLayout()).add(newButton, null); // - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button_1 = new JButton();", - " add(button_1);", - " }", - " {", - " JButton button = new JButton();", - " add(button);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + { + JButton button_1 = new JButton(); + add(button_1); + } + { + JButton button = new JButton(); + add(button); + } + } + }"""); } /** @@ -369,175 +357,172 @@ public void test_noValue_addNewComponent() throws Exception { */ @Test public void test_hasValue_addNewComponent() throws Exception { - ContainerInfo container = - parseContainer( - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JPanel {", - " private JButton button_1;", - " private JButton button_2;", - " public Test() {", - " {", - " button_1 = new JButton();", - " add(button_1);", - " }", - " {", - " button_2 = new JButton();", - " add(button_2);", - " }", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button_1}));", - " }", - "}"); + ContainerInfo container = parseContainer(""" + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JPanel { + private JButton button_1; + private JButton button_2; + public Test() { + { + button_1 = new JButton(); + add(button_1); + } + { + button_2 = new JButton(); + add(button_2); + } + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button_1})); + } + }"""); container.refresh(); // add new JButton { ComponentInfo newButton = createJButton(); ((FlowLayoutInfo) container.getLayout()).add(newButton, null); } - assertEditor( - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JPanel {", - " private JButton button_1;", - " private JButton button_2;", - " private JButton button;", - " public Test() {", - " {", - " button_1 = new JButton();", - " add(button_1);", - " }", - " {", - " button_2 = new JButton();", - " add(button_2);", - " }", - " {", - " button = new JButton();", - " add(button);", - " }", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button_1, button}));", - " }", - "}"); + assertEditor(""" + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JPanel { + private JButton button_1; + private JButton button_2; + private JButton button; + public Test() { + { + button_1 = new JButton(); + add(button_1); + } + { + button_2 = new JButton(); + add(button_2); + } + { + button = new JButton(); + add(button); + } + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button_1, button})); + } + }"""); } @Test public void test_delete_JPanel() throws Exception { - ContainerInfo panel = - parseContainer( - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JPanel {", - " private JButton button;", - " private JComboBox combo;", - " public Test() {", - " setLayout(new FlowLayout());", - " button = new JButton('Button');", - " add(button);", - " combo = new JComboBox();", - " add(combo);", - " JTextField text = new JTextField();", - " add(text);", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button, combo}));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JPanel { + private JButton button; + private JComboBox combo; + public Test() { + setLayout(new FlowLayout()); + button = new JButton("Button"); + add(button); + combo = new JComboBox(); + add(combo); + JTextField text = new JTextField(); + add(text); + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button, combo})); + } + }"""); panel.refresh(); - test_delete(panel, new String[]{ - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JPanel {", - " private JButton button;", - " private JComboBox combo;", - " public Test() {", - " setLayout(new FlowLayout());", - " button = new JButton('Button');", - " add(button);", - " combo = new JComboBox();", - " add(combo);", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button, combo}));", - " }", - "}"}, new String[]{ - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JPanel {", - " private JButton button;", - " public Test() {", - " setLayout(new FlowLayout());", - " button = new JButton('Button');", - " add(button);", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button}));", - " }", - "}"}, new String[]{ - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new FlowLayout());", - " }", - "}"}, panel.getChildrenComponents()); + test_delete(panel, """ + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JPanel { + private JButton button; + private JComboBox combo; + public Test() { + setLayout(new FlowLayout()); + button = new JButton("Button"); + add(button); + combo = new JComboBox(); + add(combo); + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button, combo})); + } + }""", """ + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JPanel { + private JButton button; + public Test() { + setLayout(new FlowLayout()); + button = new JButton("Button"); + add(button); + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button})); + } + }""", """ + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JPanel { + public Test() { + setLayout(new FlowLayout()); + } + }""", panel.getChildrenComponents()); } @Test public void test_delete_JFrame() throws Exception { - ContainerInfo frame = - parseContainer( - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JFrame {", - " private JPanel m_contentPane;", - " private JButton button;", - " private JComboBox combo;", - " public Test() {", - " m_contentPane = new JPanel();", - " m_contentPane.setLayout(new FlowLayout());", - " setContentPane(m_contentPane);", - " button = new JButton('Button');", - " m_contentPane.add(button);", - " combo = new JComboBox();", - " m_contentPane.add(combo);", - " JTextField text = new JTextField();", - " m_contentPane.add(text);", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button, combo}));", - " }", - "}"); + ContainerInfo frame = parseContainer(""" + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JFrame { + private JPanel m_contentPane; + private JButton button; + private JComboBox combo; + public Test() { + m_contentPane = new JPanel(); + m_contentPane.setLayout(new FlowLayout()); + setContentPane(m_contentPane); + button = new JButton("Button"); + m_contentPane.add(button); + combo = new JComboBox(); + m_contentPane.add(combo); + JTextField text = new JTextField(); + m_contentPane.add(text); + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button, combo})); + } + }"""); frame.refresh(); ContainerInfo contentPane = (ContainerInfo) frame.getChildrenComponents().get(0); - test_delete(frame, new String[]{ - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JFrame {", - " private JPanel m_contentPane;", - " private JButton button;", - " private JComboBox combo;", - " public Test() {", - " m_contentPane = new JPanel();", - " m_contentPane.setLayout(new FlowLayout());", - " setContentPane(m_contentPane);", - " button = new JButton('Button');", - " m_contentPane.add(button);", - " combo = new JComboBox();", - " m_contentPane.add(combo);", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button, combo}));", - " }", - "}"}, new String[]{ - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JFrame {", - " private JPanel m_contentPane;", - " private JButton button;", - " public Test() {", - " m_contentPane = new JPanel();", - " m_contentPane.setLayout(new FlowLayout());", - " setContentPane(m_contentPane);", - " button = new JButton('Button');", - " m_contentPane.add(button);", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button}));", - " }", - "}"}, new String[]{ - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JFrame {", - " private JPanel m_contentPane;", - " public Test() {", - " m_contentPane = new JPanel();", - " m_contentPane.setLayout(new FlowLayout());", - " setContentPane(m_contentPane);", - " }", - "}"}, contentPane.getChildrenComponents()); + test_delete(frame, """ + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JFrame { + private JPanel m_contentPane; + private JButton button; + private JComboBox combo; + public Test() { + m_contentPane = new JPanel(); + m_contentPane.setLayout(new FlowLayout()); + setContentPane(m_contentPane); + button = new JButton("Button"); + m_contentPane.add(button); + combo = new JComboBox(); + m_contentPane.add(combo); + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button, combo})); + } + }""", """ + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JFrame { + private JPanel m_contentPane; + private JButton button; + public Test() { + m_contentPane = new JPanel(); + m_contentPane.setLayout(new FlowLayout()); + setContentPane(m_contentPane); + button = new JButton("Button"); + m_contentPane.add(button); + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{button})); + } + }""", """ + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JFrame { + private JPanel m_contentPane; + public Test() { + m_contentPane = new JPanel(); + m_contentPane.setLayout(new FlowLayout()); + setContentPane(m_contentPane); + } + }""", contentPane.getChildrenComponents()); } private void test_delete(ContainerInfo container, - String[] start, - String[] middle, - String[] end, + String start, + String middle, + String end, List components) throws Exception { // property TabOrderProperty property = (TabOrderProperty) container.getPropertyByTitle("tab order"); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/TabOrderPropertyValueTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/TabOrderPropertyValueTest.java index 4a80e6cf8..b34e19a97 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/TabOrderPropertyValueTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/TabOrderPropertyValueTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -23,7 +23,6 @@ import org.eclipse.jdt.core.IJavaProject; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.util.List; @@ -65,17 +64,16 @@ public void _test_exit() throws Exception { @Test public void test_getValue_1() throws Exception { // create panel - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new FlowLayout());", - " JButton button = new JButton('Button');", - " add(button);", - " JComboBox combo = new JComboBox();", - " add(combo);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new FlowLayout()); + JButton button = new JButton("Button"); + add(button); + JComboBox combo = new JComboBox(); + add(combo); + } + }"""); panel.refresh(); // property TabOrderProperty property = (TabOrderProperty) panel.getPropertyByTitle("tab order"); @@ -97,7 +95,6 @@ public void test_getValue_1() throws Exception { assertSame(components.get(1), tabOrderInfo.getOrderedInfos().get(1)); } - @Disabled @Test public void test_getValue_2() throws Exception { ProjectUtils.ensureResourceType( @@ -105,19 +102,18 @@ public void test_getValue_2() throws Exception { org.eclipse.wb.internal.swing.Activator.getDefault().getBundle(), "org.eclipse.wb.swing.FocusTraversalOnArray"); // create panel - ContainerInfo panel = - parseContainer( - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new FlowLayout());", - " JButton button = new JButton('Button');", - " add(button);", - " JComboBox combo = new JComboBox();", - " add(combo);", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{combo}));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JPanel { + public Test() { + setLayout(new FlowLayout()); + JButton button = new JButton("Button"); + add(button); + JComboBox combo = new JComboBox(); + add(combo); + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{combo})); + } + }"""); panel.refresh(); // property TabOrderProperty property = (TabOrderProperty) panel.getPropertyByTitle("tab order"); @@ -138,21 +134,19 @@ public void test_getValue_2() throws Exception { assertSame(components.get(1), tabOrderInfo.getOrderedInfos().get(0)); } - @Disabled @Test public void test_setValue() throws Exception { // create panel - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new FlowLayout());", - " JButton button = new JButton('Button');", - " add(button);", - " JComboBox combo = new JComboBox();", - " add(combo);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new FlowLayout()); + JButton button = new JButton("Button"); + add(button); + JComboBox combo = new JComboBox(); + add(combo); + } + }"""); panel.refresh(); // property TabOrderProperty property = (TabOrderProperty) panel.getPropertyByTitle("tab order"); @@ -167,39 +161,40 @@ public void test_setValue() throws Exception { property.setValue(newValue); assertTrue(javaProject.findType("org.eclipse.wb.swing.FocusTraversalOnArray") != null); // check source - assertEditor( - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new FlowLayout());", - " JButton button = new JButton('Button');", - " add(button);", - " JComboBox combo = new JComboBox();", - " add(combo);", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{combo}));", - " }", - "}"); + assertEditor(""" + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JPanel { + public Test() { + setLayout(new FlowLayout()); + JButton button = new JButton("Button"); + add(button); + JComboBox combo = new JComboBox(); + add(combo); + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{combo})); + } + }"""); assertTrue(property.isModified()); // add new component FlowLayoutInfo layout = (FlowLayoutInfo) panel.getLayout(); ComponentInfo newComponent = createComponent(JLabel.class); layout.add(newComponent, null); // check source - assertEditor( - "import org.eclipse.wb.swing.FocusTraversalOnArray;", - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new FlowLayout());", - " JButton button = new JButton('Button');", - " add(button);", - " JComboBox combo = new JComboBox();", - " add(combo);", - " {", - " JLabel label = new JLabel('New label');", - " add(label);", - " }", - " setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{combo}));", - " }", - "}"); + assertEditor(""" + import org.eclipse.wb.swing.FocusTraversalOnArray; + public class Test extends JPanel { + private JLabel label; + public Test() { + setLayout(new FlowLayout()); + JButton button = new JButton("Button"); + add(button); + JComboBox combo = new JComboBox(); + add(combo); + { + label = new JLabel("New label"); + add(label); + } + setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{combo, label})); + } + }"""); } } \ No newline at end of file diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/top/JFrameTopBoundsTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/top/JFrameTopBoundsTest.java index 9ee36504f..78ecc2799 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/top/JFrameTopBoundsTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/top/JFrameTopBoundsTest.java @@ -22,7 +22,6 @@ import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.jdt.core.ICompilationUnit; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.awt.Window; @@ -160,13 +159,12 @@ public MyBigFrame() { /** * Using {@link JFrame#pack()}. */ - @Disabled @Test public void test_resize_pack() throws Exception { - Dimension packSize = new Dimension(132, 89); + Dimension packSize = new Dimension(130, 60); Dimension resizeSize = new Dimension(450, 300); ICompilationUnit unit = - check_resize("// no size", "pack();", packSize, resizeSize, packSize, "// no size"); + check_resize("setUndecorated(true);", "pack();", packSize, resizeSize, packSize, "setUndecorated(true);"); assert_sameSizeAfterReparse(unit, packSize); } @@ -275,8 +273,16 @@ private ICompilationUnit check_resize(String superClassName, public class Test extends %s { public Test() { %s - getContentPane().add(new JButton("Swing JButton"), BorderLayout.NORTH); - getContentPane().add(new Button("AWT Button"), BorderLayout.WEST); + { + JButton button = new JButton("Swing JButton"); + button.setPreferredSize(new Dimension(130, 30)); + getContentPane().add(button, BorderLayout.NORTH); + } + { + Button button = new Button("AWT Button"); + button.setPreferredSize(new Dimension(130, 30)); + getContentPane().add(button, BorderLayout.WEST); + } %s } }""".formatted(superClassName, oldSizeLine, addSizeString)); @@ -294,8 +300,16 @@ public Test() { public class Test extends %s { public Test() { %s - getContentPane().add(new JButton("Swing JButton"), BorderLayout.NORTH); - getContentPane().add(new Button("AWT Button"), BorderLayout.WEST); + { + JButton button = new JButton("Swing JButton"); + button.setPreferredSize(new Dimension(130, 30)); + getContentPane().add(button, BorderLayout.NORTH); + } + { + Button button = new Button("AWT Button"); + button.setPreferredSize(new Dimension(130, 30)); + getContentPane().add(button, BorderLayout.WEST); + } %s } }""".formatted(superClassName, newSizeLine, addSizeString));