Search in sources :

Example 1 with JPanelInfo

use of org.eclipse.wb.internal.swing.model.component.JPanelInfo in project windowbuilder by eclipse.

the class WrapperInfoTest method DISABLE_test_clipboard.

public void DISABLE_test_clipboard() throws Exception {
    configureWrapperContents();
    ContainerInfo container = parseContainer("public class Test extends JPanel {", "  public Test() {", "    {", "      JPanel panel_1 = new JPanel();", "      add(panel_1);", "      TestWrapper wrapper = new TestWrapper(panel_1);", "      JButton button = wrapper.getControl();", "    }", "    {", "      JPanel panel_2 = new JPanel();", "      add(panel_2);", "    }", "  }", "}");
    container.refresh();
    // panels
    JPanelInfo panel_1 = container.getChildren(JPanelInfo.class).get(0);
    ContainerInfo wrappedComponent = panel_1.getChildren(ContainerInfo.class).get(0);
    JPanelInfo panel_2 = container.getChildren(JPanelInfo.class).get(1);
    // create memento
    JavaInfoMemento memento = JavaInfoMemento.createMemento(wrappedComponent);
    // restore from memento
    ComponentInfo newComponent = (ComponentInfo) memento.create(container);
    JavaInfoUtils.add(newComponent, null, panel_2, null);
    memento.apply();
    // check source
    assertEditor("public class Test extends JPanel {", "  public Test() {", "    {", "      JPanel panel_1 = new JPanel();", "      add(panel_1);", "      TestWrapper wrapper = new TestWrapper(panel_1);", "      JButton button = wrapper.getControl();", "    }", "    {", "      JPanel panel_2 = new JPanel();", "      add(panel_2);", "      {", "        TestWrapper testWrapper = new TestWrapper(panel_2);", "        JButton button = testWrapper.getControl();", "      }", "    }", "  }", "}");
}
Also used : JPanelInfo(org.eclipse.wb.internal.swing.model.component.JPanelInfo) JavaInfoMemento(org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo) ComponentInfo(org.eclipse.wb.internal.swing.model.component.ComponentInfo)

Example 2 with JPanelInfo

use of org.eclipse.wb.internal.swing.model.component.JPanelInfo in project windowbuilder by eclipse.

the class LazyTest method test_convert_children.

public void test_convert_children() throws Exception {
    ContainerInfo testPanel = parseContainer("class Test extends JPanel {", "  public Test() {", "    setLayout(null);", "    JPanel panel = new JPanel();", "    panel.setBounds(42, 40, 270, 160);", "    add(panel);", "    JTextField textField = new JTextField();", "    panel.add(textField);", "    textField.setColumns(10);", "    JButton button = new JButton('New button');", "    panel.add(button);", "  }", "}");
    JPanelInfo panel = testPanel.getChildren(JPanelInfo.class).get(0);
    assertThat(panel.getChildren(ComponentInfo.class).size()).isEqualTo(2);
    // 
    assertThat(LazyVariableSupportUtils.canConvert(panel)).isTrue();
    LazyVariableSupportUtils.convert(panel);
    // check
    assertEditor("class Test extends JPanel {", "  private JPanel panel;", "  public Test() {", "    setLayout(null);", "    add(getPanel());", "  }", "  private JPanel getPanel() {", "    if (panel == null) {", "      panel = new JPanel();", "      panel.setBounds(42, 40, 270, 160);", "      JTextField textField = new JTextField();", "      panel.add(textField);", "      textField.setColumns(10);", "      JButton button = new JButton('New button');", "      panel.add(button);", "    }", "    return panel;", "  }", "}");
}
Also used : JPanelInfo(org.eclipse.wb.internal.swing.model.component.JPanelInfo) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo) ComponentInfo(org.eclipse.wb.internal.swing.model.component.ComponentInfo)

Example 3 with JPanelInfo

use of org.eclipse.wb.internal.swing.model.component.JPanelInfo in project windowbuilder by eclipse.

the class LoadResourcesTest method test_CREATE.

/**
 * Tests that <code>ResourceMap.injectComponents(Component)</code> is terminate statement for
 * children.
 */
public void test_CREATE() throws Exception {
    m_waitForAutoBuild = true;
    JPanelInfo panel = parseJavaInfo("import org.jdesktop.application.*;", "public class Test extends JPanel {", "  public Test() {", "    {", "      JLabel label = new JLabel();", "      add(label);", "    }", "    Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);", "  }", "}");
    refresh();
    // 
    {
        ComponentInfo newButton = createComponent("javax.swing.JButton");
        FlowLayoutInfo layout = (FlowLayoutInfo) panel.getLayout();
        layout.add(newButton, null);
    }
    assertEditor("import org.jdesktop.application.*;", "public class Test extends JPanel {", "  public Test() {", "    {", "      JLabel label = new JLabel();", "      add(label);", "    }", "    {", "      JButton button = new JButton('New button');", "      add(button);", "    }", "    Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);", "  }", "}");
}
Also used : JPanelInfo(org.eclipse.wb.internal.swing.model.component.JPanelInfo) ComponentInfo(org.eclipse.wb.internal.swing.model.component.ComponentInfo) FlowLayoutInfo(org.eclipse.wb.internal.swing.model.layout.FlowLayoutInfo)

Example 4 with JPanelInfo

use of org.eclipse.wb.internal.swing.model.component.JPanelInfo in project windowbuilder by eclipse.

the class WrapperInfoTest method test_MOVE_noControl.

public void test_MOVE_noControl() throws Exception {
    configureWrapperContents();
    ContainerInfo container = parseContainer("public class Test extends JPanel {", "  public Test() {", "    TestWrapper wrapper = new TestWrapper(this);", "    {", "      JPanel panel = new JPanel();", "      add(panel);", "    }", "  }", "}");
    // wrapper
    ContainerInfo wrappedComponent = container.getChildren(ContainerInfo.class).get(0);
    WrapperMethodInfo wrapper = wrappedComponent.getChildren(WrapperMethodInfo.class).get(0);
    // another panel
    JPanelInfo panel = container.getChildren(JPanelInfo.class).get(0);
    // move
    JavaInfoUtils.move(wrapper, null, panel, null);
    // check editor
    assertEditor("public class Test extends JPanel {", "  public Test() {", "    {", "      JPanel panel = new JPanel();", "      add(panel);", "      TestWrapper wrapper = new TestWrapper(panel);", "    }", "  }", "}");
}
Also used : WrapperMethodInfo(org.eclipse.wb.core.model.WrapperMethodInfo) JPanelInfo(org.eclipse.wb.internal.swing.model.component.JPanelInfo) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo)

Example 5 with JPanelInfo

use of org.eclipse.wb.internal.swing.model.component.JPanelInfo in project windowbuilder by eclipse.

the class WrapperInfoTest method test_MOVE_withControl.

public void test_MOVE_withControl() throws Exception {
    configureWrapperContents();
    ContainerInfo container = parseContainer("public class Test extends JPanel {", "  public Test() {", "    TestWrapper wrapper = new TestWrapper(this);", "    JButton button = wrapper.getControl();", "    {", "      JPanel panel = new JPanel();", "      add(panel);", "    }", "  }", "}");
    // wrapper
    ContainerInfo wrappedComponent = container.getChildren(ContainerInfo.class).get(0);
    WrapperMethodInfo wrapper = wrappedComponent.getChildren(WrapperMethodInfo.class).get(0);
    // another panel
    JPanelInfo panel = container.getChildren(JPanelInfo.class).get(0);
    // move
    JavaInfoUtils.move(wrapper, null, panel, null);
    // check editor
    assertEditor("public class Test extends JPanel {", "  public Test() {", "    {", "      JPanel panel = new JPanel();", "      add(panel);", "      TestWrapper wrapper = new TestWrapper(panel);", "      JButton button = wrapper.getControl();", "    }", "  }", "}");
}
Also used : WrapperMethodInfo(org.eclipse.wb.core.model.WrapperMethodInfo) JPanelInfo(org.eclipse.wb.internal.swing.model.component.JPanelInfo) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo)

Aggregations

JPanelInfo (org.eclipse.wb.internal.swing.model.component.JPanelInfo)8 ComponentInfo (org.eclipse.wb.internal.swing.model.component.ComponentInfo)4 ContainerInfo (org.eclipse.wb.internal.swing.model.component.ContainerInfo)4 WrapperMethodInfo (org.eclipse.wb.core.model.WrapperMethodInfo)2 DatabindingsProvider (org.eclipse.wb.internal.swing.databinding.DatabindingsProvider)2 JLabel (javax.swing.JLabel)1 IBindingInfo (org.eclipse.wb.internal.core.databinding.model.IBindingInfo)1 IObserveInfo (org.eclipse.wb.internal.core.databinding.model.IObserveInfo)1 JavaInfoMemento (org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento)1 FieldBeanObserveInfo (org.eclipse.wb.internal.swing.databinding.model.beans.FieldBeanObserveInfo)1 AutoBindingInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.AutoBindingInfo)1 UpdateStrategyInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.UpdateStrategyInfo)1 GenericTypeContainer (org.eclipse.wb.internal.swing.databinding.model.generic.GenericTypeContainer)1 IGenericType (org.eclipse.wb.internal.swing.databinding.model.generic.IGenericType)1 FlowLayoutInfo (org.eclipse.wb.internal.swing.model.layout.FlowLayoutInfo)1