Search in sources :

Example 21 with ControlAdapter

use of org.eclipse.swt.events.ControlAdapter in project MonjaDB by Kanatoko.

the class MDocumentEditor method init2.

//--------------------------------------------------------------------------------
public void init2() {
    parent.setLayout(new FormLayout());
    sashForm = new SashForm(parent, SWT.SMOOTH | SWT.VERTICAL);
    FormData fd_sashForm1 = new FormData();
    fd_sashForm1.top = new FormAttachment(0, 1);
    fd_sashForm1.left = new FormAttachment(0, 1);
    fd_sashForm1.right = new FormAttachment(100, -1);
    fd_sashForm1.bottom = new FormAttachment(100, -1);
    sashForm.setLayoutData(fd_sashForm1);
    tree = new Tree(sashForm, SWT.BORDER | SWT.FULL_SELECTION);
    tree.setHeaderVisible(true);
    FormData d1 = new FormData();
    d1.top = new FormAttachment(0, 1);
    d1.left = new FormAttachment(0, 1);
    d1.right = new FormAttachment(100, -1);
    d1.bottom = new FormAttachment(100, -1);
    tree.setLayoutData(d1);
    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
    column2.setText("Data Type");
    editorComposite = new Composite(sashForm, SWT.BORDER);
    editorComposite.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            onSashResize();
        }
    });
    FormData fd_composite1 = new FormData();
    fd_composite1.top = new FormAttachment(0, 1);
    fd_composite1.bottom = new FormAttachment(0, 35);
    fd_composite1.right = new FormAttachment(100, -1);
    fd_composite1.left = new FormAttachment(0, 1);
    editorComposite.setLayoutData(fd_composite1);
    editorComposite.setLayout(new FormLayout());
    Label nameLabel = new Label(editorComposite, SWT.NONE);
    FormData fd_nameLabel = new FormData();
    fd_nameLabel.right = new FormAttachment(0, 66);
    fd_nameLabel.bottom = new FormAttachment(0, 32);
    fd_nameLabel.top = new FormAttachment(0, 12);
    fd_nameLabel.left = new FormAttachment(0, 10);
    nameLabel.setLayoutData(fd_nameLabel);
    nameLabel.setText("Name :");
    Label valueLabel = new Label(editorComposite, SWT.NONE);
    FormData fd_valueLabel = new FormData();
    fd_valueLabel.top = new FormAttachment(nameLabel, 15);
    fd_valueLabel.left = new FormAttachment(0, 10);
    fd_valueLabel.bottom = new FormAttachment(nameLabel, 34, SWT.BOTTOM);
    fd_valueLabel.right = new FormAttachment(nameLabel, 0, SWT.RIGHT);
    valueLabel.setLayoutData(fd_valueLabel);
    valueLabel.setText("Value :");
    valueText = new Text(editorComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
    valueText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            verifyData();
        }
    });
    valueText.setEnabled(false);
    valueText.setEditable(false);
    FormData fd_valueText = new FormData();
    fd_valueText.top = new FormAttachment(nameLabel, 5);
    fd_valueText.bottom = new FormAttachment(100, -80);
    fd_valueText.right = new FormAttachment(100, -20);
    fd_valueText.left = new FormAttachment(valueLabel, 0, SWT.RIGHT);
    valueText.setLayoutData(fd_valueText);
    updateButton = new Button(editorComposite, SWT.NONE);
    updateButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            onUpdateButtonSelect();
        }
    });
    updateButton.setEnabled(false);
    FormData fd_updateButton = new FormData();
    fd_updateButton.left = new FormAttachment(100, -120);
    fd_updateButton.right = new FormAttachment(valueText, 0, SWT.RIGHT);
    updateButton.setLayoutData(fd_updateButton);
    updateButton.setText("Update");
    typeCombo = new Combo(editorComposite, SWT.READ_ONLY);
    fd_updateButton.top = new FormAttachment(typeCombo, 10);
    typeCombo.setEnabled(false);
    FormData fd_typeList = new FormData();
    fd_typeList.left = new FormAttachment(valueText, 0, SWT.LEFT);
    fd_typeList.top = new FormAttachment(valueText, 5, SWT.BOTTOM);
    //fd_typeList.bottom = new FormAttachment(valueText, 30, SWT.BOTTOM);
    fd_typeList.right = new FormAttachment(valueText, 170, SWT.LEFT);
    typeCombo.setLayoutData(fd_typeList);
    typeCombo.add("Double");
    typeCombo.add("Integer");
    typeCombo.add("Long");
    typeCombo.add("String");
    typeCombo.add("List (BasicDBList)");
    typeCombo.add("Map (BasicDBObject)");
    typeCombo.add("Date");
    typeCombo.add("ObjectId");
    typeCombo.add("JavaScript code");
    typeCombo.add("Binary data");
    typeCombo.add("Boolean");
    typeCombo.add("Null");
    typeCombo.add("Regular expression");
    typeCombo.add("Symbol");
    typeCombo.add("JavaScript code with scope");
    typeCombo.add("Timestamp");
    typeCombo.add("Min key");
    typeCombo.add("Max key");
    typeCombo.addListener(SWT.Selection, this);
    typeComboIndexMap.put(Double.class, new Integer(0));
    typeComboIndexMap.put(Integer.class, new Integer(1));
    typeComboIndexMap.put(Long.class, new Integer(2));
    typeComboIndexMap.put(String.class, new Integer(3));
    typeComboIndexMap.put(com.mongodb.BasicDBList.class, new Integer(4));
    typeComboIndexMap.put(com.mongodb.BasicDBObject.class, new Integer(5));
    typeComboIndexMap.put(java.util.Date.class, new Integer(6));
    typeComboIndexMap.put(org.bson.types.ObjectId.class, new Integer(7));
    typeComboIndexMap.put(org.bson.types.Code.class, new Integer(8));
    typeComboIndexMap.put(byte[].class, new Integer(9));
    typeComboIndexMap.put(Boolean.class, new Integer(10));
    typeComboIndexMap.put(java.util.regex.Pattern.class, new Integer(12));
    typeComboIndexMap.put(org.bson.types.Symbol.class, new Integer(13));
    typeComboIndexMap.put(org.bson.types.CodeWScope.class, new Integer(14));
    typeComboIndexMap.put(org.bson.types.BSONTimestamp.class, new Integer(15));
    typeComboIndexMap.put(org.bson.types.MinKey.class, new Integer(16));
    typeComboIndexMap.put(org.bson.types.MaxKey.class, new Integer(17));
    Label typeLabel = new Label(editorComposite, SWT.NONE);
    FormData fd_typeLabel = new FormData();
    fd_typeLabel.top = new FormAttachment(typeCombo, 3, SWT.TOP);
    fd_typeLabel.left = new FormAttachment(nameLabel, 0, SWT.LEFT);
    typeLabel.setLayoutData(fd_typeLabel);
    typeLabel.setText("Type :");
    nameText = new Text(editorComposite, SWT.READ_ONLY);
    nameText.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
    FormData fd_nameText = new FormData();
    fd_nameText.top = new FormAttachment(nameLabel, -2, SWT.TOP);
    fd_nameText.left = new FormAttachment(valueText, 0, SWT.LEFT);
    fd_nameText.right = new FormAttachment(valueText, 0, SWT.RIGHT);
    nameText.setLayoutData(fd_nameText);
    MSwtUtil.getTreeColumnWidthFromProperties("documentTree", tree, prop, new int[] { 150, 150 });
    //listeners
    tree.addListener(SWT.MouseDoubleClick, this);
    tree.addListener(SWT.Selection, this);
    tree.addListener(SWT.KeyDown, this);
    MSwtUtil.addListenerToTreeColumns2(tree, this);
    documentImage = MUtil.getImage(parent.getShell().getDisplay(), "table.png");
    oidImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_star.png");
    intImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_blue.png");
    longImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_red.png");
    doubleImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_orange.png");
    stringImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_green.png");
    dateImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_white.png");
    boolImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_yellow.png");
    listImage = MUtil.getImage(parent.getShell().getDisplay(), "stop_blue.png");
    mapImage = MUtil.getImage(parent.getShell().getDisplay(), "stop_green.png");
    nullImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_black.png");
    jsImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_right.png");
    if (prop.containsKey(DOCUMENT_COMPOSITE_WEIGHT)) {
        (new Thread() {

            public void run() {
                //System.out.println( "e" );
                MSystemUtil.sleep(0);
                //System.out.println( "a" );
                shell.getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        //----
                        //debug( "--" + prop.getIntArrayProperty( DOCUMENT_COMPOSITE_WEIGHT )[ 0 ] );
                        sashForm.setWeights(prop.getIntArrayProperty(DOCUMENT_COMPOSITE_WEIGHT));
                    }
                });
            //----
            }
        }).start();
    } else {
        sashForm.setWeights(new int[] { 70, 30 });
    }
    initializedTime = System.currentTimeMillis();
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) com.mongodb(com.mongodb) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) SashForm(org.eclipse.swt.custom.SashForm) java.util(java.util) net.jumperz.util(net.jumperz.util) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 22 with ControlAdapter

use of org.eclipse.swt.events.ControlAdapter in project tdi-studio-se by Talend.

the class PromptDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new FillLayout());
    final ScrolledComposite sc = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
    final Composite child = new Composite(sc, SWT.NONE);
    child.setLayout(new GridLayout(1, false));
    // Prompt for context values ?
    for (final IContextParameter parameter : context.getContextParameterList()) {
        if (parameter.isPromptNeeded()) {
            if (DefaultCellEditorFactory.isBoolean(parameter.getType())) {
                final Composite composite2 = new Composite(child, SWT.NONE);
                final GridLayout gridLayout = new GridLayout(2, false);
                gridLayout.horizontalSpacing = 5;
                gridLayout.marginBottom = 0;
                gridLayout.marginHeight = 0;
                gridLayout.marginLeft = 0;
                gridLayout.marginRight = 0;
                gridLayout.marginTop = 0;
                gridLayout.marginWidth = 0;
                composite2.setLayout(gridLayout);
                composite2.setLayoutData(new GridData(GridData.BEGINNING));
                Label label = new Label(composite2, SWT.NONE);
                label.setText(parameter.getPrompt());
                label.setAlignment(SWT.LEFT);
                GridData data = new GridData(GridData.FILL_HORIZONTAL);
                data.minimumWidth = MINIMUM_WIDTH;
                label.setLayoutData(data);
                final Button button = new Button(composite2, SWT.CHECK);
                button.setSelection(Boolean.parseBoolean(parameter.getValue()));
                button.addSelectionListener(new SelectionAdapter() {

                    /*
                         * (non-Javadoc)
                         * 
                         * @see
                         * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
                         */
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        parameter.setValue((new Boolean(button.getSelection())).toString());
                    }
                });
            } else {
                Label label = new Label(child, SWT.NONE);
                label.setText(parameter.getPrompt());
                label.setAlignment(SWT.LEFT);
                GridData data = new GridData(GridData.FILL_HORIZONTAL);
                data.minimumWidth = MINIMUM_WIDTH;
                label.setLayoutData(data);
                createParameterComposite(child, parameter, label);
            }
        }
    }
    sc.setContent(child);
    // Set the minimum size
    // sc.setMinSize(400, 400);
    // Expand both horizontally and vertically
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    sc.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            Rectangle r = sc.getClientArea();
            sc.setMinSize(child.computeSize(r.width, SWT.DEFAULT));
        }
    });
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Rectangle(org.eclipse.swt.graphics.Rectangle) FillLayout(org.eclipse.swt.layout.FillLayout) IContextParameter(org.talend.core.model.process.IContextParameter) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 23 with ControlAdapter

use of org.eclipse.swt.events.ControlAdapter in project tdi-studio-se by Talend.

the class MavenVersionManagementProjectSettingPage method createItemTableColumns.

@Override
protected void createItemTableColumns() {
    TableColumn itemColumn = new TableColumn(itemTable, SWT.CENTER);
    //$NON-NLS-1$
    itemColumn.setText(Messages.getString("VersionManagementDialog.Items"));
    itemColumn.setWidth(100);
    TableColumn oldVersionColumn = new TableColumn(itemTable, SWT.CENTER);
    //$NON-NLS-1$
    oldVersionColumn.setText(Messages.getString("VersionManagementDialog.Version"));
    oldVersionColumn.setWidth(100);
    TableColumn versionColumn = new TableColumn(itemTable, SWT.CENTER);
    //$NON-NLS-1$
    versionColumn.setText(Messages.getString("VersionManagementDialog.NewVersion"));
    versionColumn.setWidth(100);
    final TableColumn delColumn = new TableColumn(itemTable, SWT.CENTER);
    //$NON-NLS-1$
    delColumn.setText("");
    delColumn.setWidth(26);
    delColumn.setResizable(false);
    versionColumn.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            if (eachVersionButton.getSelection()) {
                refreshTableItems();
            }
        }
    });
    itemTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkButtonsState();
        }
    });
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) TableColumn(org.eclipse.swt.widgets.TableColumn)

Example 24 with ControlAdapter

use of org.eclipse.swt.events.ControlAdapter in project eclipse.platform.swt by eclipse.

the class MJ_Table method bug51079_setWidth_getWidth.

/**
 * Last column should be big enough so that text inside it can be read.
 * Notion that getWidth() when called after setWidth() returns a different size.
 */
@Test
public void bug51079_setWidth_getWidth() {
    Shell shell = mkShell("column SetGet Width : Make shell smaller and bigger. If you don't see COL_SIZE_ERROR in console, all is well.");
    shell.setSize(SWIDTH, SHEIGHT);
    shell.setLayout(new FillLayout());
    StringBuffer sbBuffer = new StringBuffer();
    final Composite comp = new Composite(shell, SWT.NONE);
    final Table table = new Table(comp, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    final TableColumn column1 = new TableColumn(table, SWT.NONE);
    column1.setText("Column 1");
    column1.setResizable(false);
    final TableColumn column2 = new TableColumn(table, SWT.NONE);
    column2.setText("Column 2");
    column2.setResizable(false);
    for (int i = 0; i < 60; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        sbBuffer.append("M");
        item.setText(new String[] { "item 0 " + sbBuffer.toString() + " " + i, "item 1 " + i });
    }
    Consumer<Integer> setColumnWidths = (width) -> {
        int c1w = (int) (width * 0.9);
        column1.setWidth(c1w);
        int c1wPost = column1.getWidth();
        if (c1w != c1wPost)
            System.err.println("COL_SIZE_ERROR 1 Expected:" + c1w + " actual:" + c1wPost);
        int c2w = width - column1.getWidth();
        column2.setWidth(c2w);
        int c2wPost = column2.getWidth();
        if (c2w != c2wPost)
            System.err.println("COL_SIZE_ERROR 2 Expected:" + c2w + " actual:" + column2.getWidth());
    };
    comp.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            Rectangle area = table.getParent().getClientArea();
            Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            int width = area.width - 2 * table.getBorderWidth();
            if (preferredSize.y > area.height) {
                // Subtract the scrollbar width from the total column width
                // if a vertical scrollbar will be required
                Point vBarSize = table.getVerticalBar().getSize();
                width -= vBarSize.x;
            }
            Point oldSize = table.getSize();
            if (oldSize.x > area.width) {
                // table is getting smaller so make the columns
                // smaller first and then resize the table to
                // match the client area width
                setColumnWidths.accept(width);
                table.setSize(area.width, area.height);
            } else {
                // table is getting bigger so make the table
                // bigger first and then make the columns wider
                // to match the client area width
                table.setSize(area.width, area.height);
                setColumnWidths.accept(width);
            }
        }
    });
    shell.open();
    mainLoop(shell);
}
Also used : TableEditor(org.eclipse.swt.custom.TableEditor) MethodSorters(org.junit.runners.MethodSorters) Arrays(java.util.Arrays) BiFunction(java.util.function.BiFunction) TableColumn(org.eclipse.swt.widgets.TableColumn) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FontMetrics(org.eclipse.swt.graphics.FontMetrics) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) Random(java.util.Random) ControlListener(org.eclipse.swt.events.ControlListener) TextLayout(org.eclipse.swt.graphics.TextLayout) TextStyle(org.eclipse.swt.graphics.TextStyle) Table(org.eclipse.swt.widgets.Table) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) Locale(java.util.Locale) Composite(org.eclipse.swt.widgets.Composite) Listener(org.eclipse.swt.widgets.Listener) BiConsumer(java.util.function.BiConsumer) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) RowData(org.eclipse.swt.layout.RowData) Collator(java.text.Collator) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) ShellEvent(org.eclipse.swt.events.ShellEvent) Test(org.junit.Test) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Consumer(java.util.function.Consumer) RowLayout(org.eclipse.swt.layout.RowLayout) Color(org.eclipse.swt.graphics.Color) ControlAdapter(org.eclipse.swt.events.ControlAdapter) SWT(org.eclipse.swt.SWT) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrollBar(org.eclipse.swt.widgets.ScrollBar) FixMethodOrder(org.junit.FixMethodOrder) Label(org.eclipse.swt.widgets.Label) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point) Shell(org.eclipse.swt.widgets.Shell) ControlEvent(org.eclipse.swt.events.ControlEvent) Test(org.junit.Test)

Example 25 with ControlAdapter

use of org.eclipse.swt.events.ControlAdapter in project eclipse.platform.swt by eclipse.

the class MJ_Tree method bug51079_setWidth_getWidth.

/**
 * Last column should be big enough so that text inside it can be read.
 * Notion that getWidth() when called after setWidth() returns a different size.
 */
@Test
public void bug51079_setWidth_getWidth() {
    Shell shell = mkShell("column SetGet Width : Make shell smaller and bigger. If you don't see COL_SIZE_ERROR in console, all is well.");
    shell.setSize(SWIDTH, SHEIGHT);
    shell.setLayout(new FillLayout());
    StringBuffer sbBuffer = new StringBuffer();
    final Composite comp = new Composite(shell, SWT.NONE);
    final Tree tree = new Tree(comp, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    final TreeColumn column1 = new TreeColumn(tree, SWT.NONE);
    column1.setText("Column 1");
    column1.setResizable(false);
    final TreeColumn column2 = new TreeColumn(tree, SWT.NONE);
    column2.setText("Column 2");
    column2.setResizable(false);
    for (int i = 0; i < 60; i++) {
        TreeItem item = new TreeItem(tree, SWT.NONE);
        sbBuffer.append("M");
        item.setText(new String[] { "item 0 " + sbBuffer.toString() + " " + i, "item 1 " + i });
    }
    Consumer<Integer> setColumnWidths = (width) -> {
        int c1w = (int) (width * 0.9);
        column1.setWidth(c1w);
        int c1wPost = column1.getWidth();
        if (c1w != c1wPost)
            System.err.println("COL_SIZE_ERROR 1 Expected:" + c1w + " actual:" + c1wPost);
        int c2w = width - column1.getWidth();
        column2.setWidth(c2w);
        int c2wPost = column2.getWidth();
        if (c2w != c2wPost)
            System.err.println("COL_SIZE_ERROR 2 Expected:" + c2w + " actual:" + column2.getWidth());
    };
    comp.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            Rectangle area = tree.getParent().getClientArea();
            Point preferredSize = tree.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            int width = area.width - 2 * tree.getBorderWidth();
            if (preferredSize.y > area.height) {
                // Subtract the scrollbar width from the total column width
                // if a vertical scrollbar will be required
                Point vBarSize = tree.getVerticalBar().getSize();
                width -= vBarSize.x;
            }
            Point oldSize = tree.getSize();
            if (oldSize.x > area.width) {
                // tree is getting smaller so make the columns
                // smaller first and then resize the tree to
                // match the client area width
                setColumnWidths.accept(width);
                tree.setSize(area.width, area.height);
            } else {
                // tree is getting bigger so make the tree
                // bigger first and then make the columns wider
                // to match the client area width
                tree.setSize(area.width, area.height);
                setColumnWidths.accept(width);
            }
        }
    });
    shell.open();
    mainLoop(shell);
}
Also used : MethodSorters(org.junit.runners.MethodSorters) Shell(org.eclipse.swt.widgets.Shell) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Rectangle(org.eclipse.swt.graphics.Rectangle) Test(org.junit.Test) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) TreeItem(org.eclipse.swt.widgets.TreeItem) ControlEvent(org.eclipse.swt.events.ControlEvent) Consumer(java.util.function.Consumer) Color(org.eclipse.swt.graphics.Color) Tree(org.eclipse.swt.widgets.Tree) ControlAdapter(org.eclipse.swt.events.ControlAdapter) Composite(org.eclipse.swt.widgets.Composite) Listener(org.eclipse.swt.widgets.Listener) SWT(org.eclipse.swt.SWT) BiConsumer(java.util.function.BiConsumer) FillLayout(org.eclipse.swt.layout.FillLayout) FixMethodOrder(org.junit.FixMethodOrder) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TreeItem(org.eclipse.swt.widgets.TreeItem) Rectangle(org.eclipse.swt.graphics.Rectangle) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Shell(org.eclipse.swt.widgets.Shell) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) ControlEvent(org.eclipse.swt.events.ControlEvent) Test(org.junit.Test)

Aggregations

ControlAdapter (org.eclipse.swt.events.ControlAdapter)28 ControlEvent (org.eclipse.swt.events.ControlEvent)28 Composite (org.eclipse.swt.widgets.Composite)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)12 GridLayout (org.eclipse.swt.layout.GridLayout)11 Point (org.eclipse.swt.graphics.Point)9 GridData (org.eclipse.swt.layout.GridData)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 Rectangle (org.eclipse.swt.graphics.Rectangle)7 TableColumn (org.eclipse.swt.widgets.TableColumn)7 ModifyEvent (org.eclipse.swt.events.ModifyEvent)6 Button (org.eclipse.swt.widgets.Button)6 ModifyListener (org.eclipse.swt.events.ModifyListener)5 FillLayout (org.eclipse.swt.layout.FillLayout)5 Label (org.eclipse.swt.widgets.Label)5 Table (org.eclipse.swt.widgets.Table)5 SashForm (org.eclipse.swt.custom.SashForm)4 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)4 Event (org.eclipse.swt.widgets.Event)4 Listener (org.eclipse.swt.widgets.Listener)4