Search in sources :

Example 96 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class TableWrapLayoutTest method test_columnAccess.

// //////////////////////////////////////////////////////////////////////////
// 
// Dimension operations
// 
// //////////////////////////////////////////////////////////////////////////
public void test_columnAccess() throws Exception {
    CompositeInfo shell = parseComposite("class Test extends Shell {", "  Test() {", "    {", "      TableWrapLayout layout = new TableWrapLayout();", "      layout.numColumns = 2;", "      setLayout(layout);", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('0 x 0');", "    }", "    new Label(this, SWT.NONE);", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('0 x 1');", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('1 x 1');", "    }", "  }", "}");
    shell.refresh();
    TableWrapLayoutInfo layout = (TableWrapLayoutInfo) shell.getLayout();
    final TableWrapColumnInfo<?> column = layout.getColumns().get(0);
    // check initial values
    assertEquals(0, column.getIndex());
    assertEquals("left", column.getTitle());
    assertFalse(column.getGrab());
    assertEquals(TableWrapData.LEFT, column.getAlignment().intValue());
    // flip grab
    column.flipGrab();
    assertEditor("class Test extends Shell {", "  Test() {", "    {", "      TableWrapLayout layout = new TableWrapLayout();", "      layout.numColumns = 2;", "      setLayout(layout);", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      {", "        TableWrapData tableWrapData = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);", "        tableWrapData.grabHorizontal = true;", "        button.setLayoutData(tableWrapData);", "      }", "      button.setText('0 x 0');", "    }", "    new Label(this, SWT.NONE);", "    {", "      Button button = new Button(this, SWT.NONE);", "      {", "        TableWrapData tableWrapData = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);", "        tableWrapData.grabHorizontal = true;", "        button.setLayoutData(tableWrapData);", "      }", "      button.setText('0 x 1');", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('1 x 1');", "    }", "  }", "}");
    assertEquals("left, grab", column.getTitle());
    // set alignment
    ExecutionUtils.run(shell, new RunnableEx() {

        @Override
        public void run() throws Exception {
            column.setAlignment(TableWrapData.FILL);
        }
    });
    assertEditor("class Test extends Shell {", "  Test() {", "    {", "      TableWrapLayout layout = new TableWrapLayout();", "      layout.numColumns = 2;", "      setLayout(layout);", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP, 1, 1));", "      button.setText('0 x 0');", "    }", "    new Label(this, SWT.NONE);", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP, 1, 1));", "      button.setText('0 x 1');", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('1 x 1');", "    }", "  }", "}");
    assertEquals("fill, grab", column.getTitle());
    // set different alignment for "0 x 1" button
    {
        ControlInfo button = shell.getChildrenControls().get(2);
        layout.getTableWrapData(button).setHorizontalAlignment(TableWrapData.RIGHT);
        assertNull(column.getAlignment());
    }
    // check other alignments
    {
        column.setAlignment(TableWrapData.CENTER);
        assertEquals("center, grab", column.getTitle());
        // 
        column.setAlignment(TableWrapData.RIGHT);
        assertEquals("right, grab", column.getTitle());
    }
    // delete
    column.delete();
    assertEditor("class Test extends Shell {", "  Test() {", "    {", "      TableWrapLayout layout = new TableWrapLayout();", "      setLayout(layout);", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('1 x 1');", "    }", "  }", "}");
}
Also used : TableWrapLayoutInfo(org.eclipse.wb.internal.rcp.model.forms.layout.table.TableWrapLayoutInfo) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx) ControlInfo(org.eclipse.wb.internal.swt.model.widgets.ControlInfo) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)

Example 97 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class TableWrapLayoutTest method test_rowAccess.

public void test_rowAccess() throws Exception {
    CompositeInfo shell = parseComposite("class Test extends Shell {", "  Test() {", "    {", "      TableWrapLayout layout = new TableWrapLayout();", "      layout.numColumns = 2;", "      setLayout(layout);", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('0 x 0');", "    }", "    new Label(this, SWT.NONE);", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('0 x 1');", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('1 x 1');", "    }", "  }", "}");
    shell.refresh();
    TableWrapLayoutInfo layout = (TableWrapLayoutInfo) shell.getLayout();
    final TableWrapRowInfo<?> row = layout.getRows().get(1);
    // check initial values
    assertEquals(1, row.getIndex());
    assertEquals("top", row.getTitle());
    assertFalse(row.getGrab());
    assertEquals(TableWrapData.TOP, row.getAlignment().intValue());
    // flip grab
    row.flipGrab();
    assertEditor("class Test extends Shell {", "  Test() {", "    {", "      TableWrapLayout layout = new TableWrapLayout();", "      layout.numColumns = 2;", "      setLayout(layout);", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('0 x 0');", "    }", "    new Label(this, SWT.NONE);", "    {", "      Button button = new Button(this, SWT.NONE);", "      {", "        TableWrapData tableWrapData = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);", "        tableWrapData.grabVertical = true;", "        button.setLayoutData(tableWrapData);", "      }", "      button.setText('0 x 1');", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      {", "        TableWrapData tableWrapData = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);", "        tableWrapData.grabVertical = true;", "        button.setLayoutData(tableWrapData);", "      }", "      button.setText('1 x 1');", "    }", "  }", "}");
    assertEquals("top, grab", row.getTitle());
    // set alignment
    ExecutionUtils.run(shell, new RunnableEx() {

        @Override
        public void run() throws Exception {
            row.setAlignment(TableWrapData.FILL);
        }
    });
    assertEditor("class Test extends Shell {", "  Test() {", "    {", "      TableWrapLayout layout = new TableWrapLayout();", "      layout.numColumns = 2;", "      setLayout(layout);", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('0 x 0');", "    }", "    new Label(this, SWT.NONE);", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.FILL_GRAB, 1, 1));", "      button.setText('0 x 1');", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.FILL_GRAB, 1, 1));", "      button.setText('1 x 1');", "    }", "  }", "}");
    assertEquals("fill, grab", row.getTitle());
    // set different alignment for "0 x 1" button
    {
        ControlInfo button = shell.getChildrenControls().get(2);
        layout.getTableWrapData(button).setVerticalAlignment(TableWrapData.BOTTOM);
        assertNull(row.getAlignment());
    }
    // check other alignments
    {
        row.setAlignment(TableWrapData.TOP);
        assertEquals("top, grab", row.getTitle());
        // 
        row.setAlignment(TableWrapData.MIDDLE);
        assertEquals("middle, grab", row.getTitle());
        // 
        row.setAlignment(TableWrapData.BOTTOM);
        assertEquals("bottom, grab", row.getTitle());
    }
    // delete
    row.delete();
    assertEditor("class Test extends Shell {", "  Test() {", "    {", "      TableWrapLayout layout = new TableWrapLayout();", "      setLayout(layout);", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('0 x 0');", "    }", "  }", "}");
}
Also used : TableWrapLayoutInfo(org.eclipse.wb.internal.rcp.model.forms.layout.table.TableWrapLayoutInfo) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx) ControlInfo(org.eclipse.wb.internal.swt.model.widgets.ControlInfo) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)

Example 98 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class GridLayoutTest method test_columnAccess.

// //////////////////////////////////////////////////////////////////////////
// 
// Dimension operations
// 
// //////////////////////////////////////////////////////////////////////////
public void test_columnAccess() throws Exception {
    CompositeInfo shell = parseComposite("class Test extends Shell {", "  Test() {", "    setLayout(new GridLayout(2, false));", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('0 x 0');", "    }", "    new Label(this, SWT.NONE);", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('0 x 1');", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('1 x 1');", "    }", "  }", "}");
    shell.refresh();
    final GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout();
    final GridColumnInfo<ControlInfo> column = layout.getColumns().get(0);
    // check initial values
    assertEquals(0, column.getIndex());
    assertEquals("left", column.getTitle());
    assertFalse(column.getGrab());
    assertEquals(SWT.LEFT, column.getAlignment().intValue());
    // flip grab
    column.flipGrab();
    assertEditor("class Test extends Shell {", "  Test() {", "    setLayout(new GridLayout(2, false));", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));", "      button.setText('0 x 0');", "    }", "    new Label(this, SWT.NONE);", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));", "      button.setText('0 x 1');", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('1 x 1');", "    }", "  }", "}");
    assertEquals("left, grab", column.getTitle());
    // set alignment
    column.setAlignment(SWT.FILL);
    assertEditor("class Test extends Shell {", "  Test() {", "    setLayout(new GridLayout(2, false));", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));", "      button.setText('0 x 0');", "    }", "    new Label(this, SWT.NONE);", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));", "      button.setText('0 x 1');", "    }", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('1 x 1');", "    }", "  }", "}");
    assertEquals("fill, grab", column.getTitle());
    // set different alignment for "0 x 1" button
    {
        ControlInfo button = shell.getChildrenControls().get(2);
        GridLayoutInfo.getGridData(button).setHorizontalAlignment(SWT.RIGHT);
        assertNull(column.getAlignment());
    }
    // check other alignments
    {
        column.setAlignment(SWT.CENTER);
        assertEquals("center, grab", column.getTitle());
        // 
        column.setAlignment(SWT.RIGHT);
        assertEquals("right, grab", column.getTitle());
    }
    // delete
    ExecutionUtils.run(shell, new RunnableEx() {

        @Override
        public void run() throws Exception {
            column.delete();
        }
    });
    assertEditor("class Test extends Shell {", "  Test() {", "    setLayout(new GridLayout(1, false));", "    new Label(this, SWT.NONE);", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setText('1 x 1');", "    }", "  }", "}");
}
Also used : GridLayoutInfo(org.eclipse.wb.internal.swt.model.layout.grid.GridLayoutInfo) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx) ControlInfo(org.eclipse.wb.internal.swt.model.widgets.ControlInfo) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)

Example 99 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class FontPreviewCanvas method setFontInfo.

// //////////////////////////////////////////////////////////////////////////
// 
// Access
// 
// //////////////////////////////////////////////////////////////////////////
/**
 * Sets the {@link Font} to display.
 */
public void setFontInfo(final FontInfo fontInfo) {
    if (m_image != null) {
        m_image.dispose();
        m_image = null;
    }
    if (fontInfo != null) {
        ExecutionUtils.runLog(new RunnableEx() {

            public void run() throws Exception {
                m_image = FontSupport.getFontPreview(fontInfo.getFont());
            }
        });
    }
    redraw();
}
Also used : RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx)

Example 100 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class TableWrapDataTest method test_verticalFillGrab_2.

/**
 * Precondition: constructor with alignment, vertical grab is <code>true</code> in field.<br>
 * Action: change vertical alignment to {@link TableWrapData#FILL} and back to
 * {@link TableWrapData#TOP}. <br>
 * Result: use/not {@link TableWrapData#FILL_GRAB} in constructor.
 */
public void test_verticalFillGrab_2() throws Exception {
    CompositeInfo shell = parseComposite("class Test extends Shell {", "  Test() {", "    setLayout(new TableWrapLayout());", "    {", "      Button button = new Button(this, SWT.NONE);", "      {", "        TableWrapData tableWrapData = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP);", "        tableWrapData.grabVertical = true;", "        button.setLayoutData(tableWrapData);", "      }", "    }", "  }", "}");
    shell.refresh();
    TableWrapLayoutInfo layout = (TableWrapLayoutInfo) shell.getLayout();
    ControlInfo button = shell.getChildrenControls().get(0);
    final TableWrapDataInfo tableWrapData = layout.getTableWrapData(button);
    // initial state
    assertEquals(TableWrapData.TOP, tableWrapData.getVerticalAlignment());
    assertTrue(tableWrapData.getVerticalGrab());
    // alignment := FILL
    ExecutionUtils.run(shell, new RunnableEx() {

        @Override
        public void run() throws Exception {
            tableWrapData.setVerticalAlignment(TableWrapData.FILL);
        }
    });
    assertEquals(TableWrapData.FILL, tableWrapData.getVerticalAlignment());
    assertTrue(tableWrapData.getVerticalGrab());
    assertEditor("class Test extends Shell {", "  Test() {", "    setLayout(new TableWrapLayout());", "    {", "      Button button = new Button(this, SWT.NONE);", "      button.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.FILL_GRAB));", "    }", "  }", "}");
    // alignment := TOP
    ExecutionUtils.run(shell, new RunnableEx() {

        @Override
        public void run() throws Exception {
            tableWrapData.setVerticalAlignment(TableWrapData.TOP);
        }
    });
    assertEquals(TableWrapData.TOP, tableWrapData.getVerticalAlignment());
    assertTrue(tableWrapData.getVerticalGrab());
    assertEditor("class Test extends Shell {", "  Test() {", "    setLayout(new TableWrapLayout());", "    {", "      Button button = new Button(this, SWT.NONE);", "      {", "        TableWrapData tableWrapData = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP);", "        tableWrapData.grabVertical = true;", "        button.setLayoutData(tableWrapData);", "      }", "    }", "  }", "}");
}
Also used : TableWrapLayoutInfo(org.eclipse.wb.internal.rcp.model.forms.layout.table.TableWrapLayoutInfo) TableWrapDataInfo(org.eclipse.wb.internal.rcp.model.forms.layout.table.TableWrapDataInfo) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx) ControlInfo(org.eclipse.wb.internal.swt.model.widgets.ControlInfo) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)

Aggregations

RunnableEx (org.eclipse.wb.internal.core.utils.execution.RunnableEx)259 ContainerInfo (org.eclipse.wb.internal.swing.model.component.ContainerInfo)57 ComponentInfo (org.eclipse.wb.internal.swing.model.component.ComponentInfo)55 GridBagLayoutInfo (org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo)42 AbstractGridBagLayoutInfo (org.eclipse.wb.internal.swing.model.layout.gbl.AbstractGridBagLayoutInfo)22 ObjectInfo (org.eclipse.wb.core.model.ObjectInfo)14 List (java.util.List)12 Expression (org.eclipse.jdt.core.dom.Expression)11 IAction (org.eclipse.jface.action.IAction)11 CompositeInfo (org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)11 ControlInfo (org.eclipse.wb.internal.swt.model.widgets.ControlInfo)11 FormLayoutInfo (org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo)10 JavaInfo (org.eclipse.wb.core.model.JavaInfo)9 IMenuItemInfo (org.eclipse.wb.internal.core.model.menu.IMenuItemInfo)9 GridLayoutInfo (org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo)9 MenuItemInfo (org.eclipse.wb.internal.xwt.model.widgets.menu.MenuItemInfo)9 JavaInfoMemento (org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento)8 AstEditor (org.eclipse.wb.internal.core.utils.ast.AstEditor)8 ControlInfo (org.eclipse.wb.internal.xwt.model.widgets.ControlInfo)8 JTextField (javax.swing.JTextField)7