Example usage for org.eclipse.jface.viewers ColumnWeightData ColumnWeightData

List of usage examples for org.eclipse.jface.viewers ColumnWeightData ColumnWeightData

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ColumnWeightData ColumnWeightData.

Prototype

public ColumnWeightData(int weight) 

Source Link

Document

Creates a resizable column width with the given weight and a default minimum width.

Usage

From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.editors.JFXBuildConfigurationEditor.java

License:Open Source License

private void createPageOverview(final AntTask task) {
    Composite composite = new Composite(getContainer(), SWT.NONE);
    FillLayout layout = new FillLayout();
    composite.setLayout(layout);//from   w w  w.  java2s .c om
    PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
            JavaFXUIPlugin.PLUGIN_ID + ".JFXBuildConfigurationEditor_overview");

    bean.setValue(task);

    toolkit = new FormToolkit(composite.getDisplay());

    final Form form = toolkit.createForm(composite);
    form.setText("FX Build Configuration");
    form.setImage(getTitleImage());
    form.getBody().setLayout(new FillLayout());
    toolkit.decorateFormHeading(form);

    initToolbar(form);

    ScrolledForm scrolledForm = toolkit.createScrolledForm(form.getBody());
    scrolledForm.getBody().setLayout(new GridLayout(2, false));
    Composite sectionParent = scrolledForm.getBody();

    dbc = new DataBindingContext();
    IWidgetValueProperty textModify = WidgetProperties.text(SWT.Modify);
    IWidgetValueProperty selChange = WidgetProperties.selection();

    {
        Section section = toolkit.createSection(sectionParent,
                Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
        section.setText("Build && Package Properties");
        section.setDescription("The following properties are needed to build the JavaFX-Application");
        section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        Composite sectionClient = toolkit.createComposite(section);
        sectionClient.setLayout(new GridLayout(4, false));

        {
            toolkit.createLabel(sectionClient, "Build Directory*:");
            final Text t = toolkit.createText(sectionClient, "", SWT.BORDER);
            t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            toolkit.createButton(sectionClient, "Filesystem ...", SWT.PUSH)
                    .addSelectionListener(new SelectionAdapter() {
                        @Override
                        public void widgetSelected(final SelectionEvent e) {
                            String dir = handleBuildFilesystemDirectorySelection(t.getShell());
                            if (dir != null) {
                                t.setText(dir);
                            }
                        }
                    });
            toolkit.createButton(sectionClient, "Workspace ...", SWT.PUSH)
                    .addSelectionListener(new SelectionAdapter() {
                        @Override
                        public void widgetSelected(final SelectionEvent e) {
                            String dir = handleBuildWorkbenchDirectorySelection(t.getShell());
                            if (dir != null) {
                                t.setText(dir);
                            }
                        }
                    });
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain, ANT_TASK__BUILD_DIRECTORY);
            dbc.bindValue(textModify.observeDelayed(DELAY, t), prop.observeDetail(bean));
        }

        {
            toolkit.createLabel(sectionClient, "Vendor name*:");
            Text t = toolkit.createText(sectionClient, "", SWT.BORDER);
            t.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 3, 1));
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__INFO, INFO__VENDOR));
            dbc.bindValue(textModify.observeDelayed(DELAY, t), prop.observeDetail(bean));
        }

        {
            toolkit.createLabel(sectionClient, "Application title*:");
            Text t = toolkit.createText(sectionClient, "", SWT.BORDER);
            t.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 3, 1));
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__APPLICATION, APPLICATION__NAME));
            dbc.bindValue(textModify.observeDelayed(DELAY, t), prop.observeDetail(bean));
        }

        {
            toolkit.createLabel(sectionClient, "Application version*:");
            Text t = toolkit.createText(sectionClient, "", SWT.BORDER);
            t.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 3, 1));
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__APPLICATION, APPLICATION__VERSION));
            dbc.bindValue(textModify.observeDelayed(DELAY, t), prop.observeDetail(bean));
        }

        {
            toolkit.createLabel(sectionClient, "Application class*:");
            final Text t = toolkit.createText(sectionClient, "", SWT.BORDER);
            t.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
            Button b = toolkit.createButton(sectionClient, "Browse ...", SWT.PUSH);
            b.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    String name = handleRootclassSelection(t.getShell());
                    if (name != null) {
                        t.setText(name);
                    }
                }
            });
            b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__APPLICATION, APPLICATION__MAINCLASS));
            dbc.bindValue(textModify.observeDelayed(DELAY, t), prop.observeDetail(bean));
        }

        {
            toolkit.createLabel(sectionClient, "Preloader class:");
            final Text t = toolkit.createText(sectionClient, "", SWT.BORDER);
            t.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
            Button b = toolkit.createButton(sectionClient, "Browse ...", SWT.PUSH);
            b.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    String name = handlePreloaderclassSelection(t.getShell());
                    if (name != null) {
                        t.setText(name);
                    }
                }
            });
            b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__APPLICATION, APPLICATION__PRELOADERCLASS));
            dbc.bindValue(textModify.observeDelayed(DELAY, t), prop.observeDetail(bean));
        }

        {
            toolkit.createLabel(sectionClient, "Splash:");
            final Text t = toolkit.createText(sectionClient, "", SWT.BORDER);
            t.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
            Button b = toolkit.createButton(sectionClient, "Browse ...", SWT.PUSH);
            b.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    String name = handleSplashImage(t.getShell());
                    if (name != null) {
                        t.setText(name);
                    }
                }
            });
            b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
            IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                    FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__SPLASH_IMAGE));
            dbc.bindValue(textModify.observeDelayed(DELAY, t), prop.observeDetail(bean));
        }

        {
            toolkit.createLabel(sectionClient, "Manifest-Attributes:")
                    .setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
            Composite container = toolkit.createComposite(sectionClient);
            GridLayout gl = new GridLayout(2, false);
            gl.marginBottom = gl.marginHeight = gl.marginLeft = gl.marginRight = gl.marginTop = gl.marginWidth = 0;
            container.setLayout(gl);
            GridData gdContainer = new GridData(GridData.FILL_HORIZONTAL);
            gdContainer.horizontalSpan = 2;
            container.setLayoutData(gdContainer);

            Composite tableContainer = toolkit.createComposite(container);
            Table t = toolkit.createTable(tableContainer,
                    SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
            t.setHeaderVisible(true);
            t.setLinesVisible(true);

            GridData gdTable = new GridData(GridData.FILL_HORIZONTAL);
            gdTable.heightHint = t.getHeaderHeight() + t.getItemHeight() * 5;
            tableContainer.setLayoutData(gdTable);

            TableColumnLayout tablelayout = new TableColumnLayout();
            final TableViewer v = new TableViewer(t);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.heightHint = t.getHeaderHeight() + t.getItemHeight() * 5;
            v.getControl().setLayoutData(gd);
            v.setContentProvider(ArrayContentProvider.getInstance());

            {
                TableViewerColumn c = new TableViewerColumn(v, SWT.NONE);
                c.setLabelProvider(new ColumnLabelProvider() {
                    @Override
                    public String getText(final Object element) {
                        return ((Param) element).getName();
                    }
                });
                tablelayout.setColumnData(c.getColumn(), new ColumnWeightData(33));
                c.getColumn().setText("Name");
            }

            {
                TableViewerColumn c = new TableViewerColumn(v, SWT.NONE);
                c.setLabelProvider(new ColumnLabelProvider() {
                    @Override
                    public String getText(final Object element) {
                        return ((Param) element).getValue();
                    }
                });
                tablelayout.setColumnData(c.getColumn(), new ColumnWeightData(67));
                c.getColumn().setText("Value");
            }
            tableContainer.setLayout(tablelayout);
            v.setInput(task.getManifestEntries());

            Composite buttonComp = toolkit.createComposite(sectionClient);
            buttonComp.setLayoutData(new GridData(GridData.BEGINNING, GridData.END, false, false));
            buttonComp.setLayout(new GridLayout());

            {
                Button b = toolkit.createButton(buttonComp, "Add ...", SWT.PUSH);
                b.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));
                b.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(final SelectionEvent e) {
                        if (handleAddManifestAttr(getSite().getShell())) {
                            v.setInput(task.getManifestEntries());
                            v.setSelection(new StructuredSelection(
                                    task.getManifestEntries().get(task.getManifestEntries().size() - 1)));
                        }
                    }
                });
            }

            {
                Button b = toolkit.createButton(buttonComp, "Remove", SWT.PUSH);
                b.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));
                b.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(final SelectionEvent e) {
                        Param value = (Param) ((IStructuredSelection) v.getSelection()).getFirstElement();
                        if (value != null) {
                            if (handleRemoveManifestAttr(value)) {
                                v.setInput(task.getManifestEntries());
                            }
                        } else {
                            MessageDialog.openWarning(getSite().getShell(), "Warning",
                                    "Please select an entry");
                        }
                    }
                });
            }
            {
                toolkit.createLabel(sectionClient, "Toolkit Type:")
                        .setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
                ComboViewer c = new ComboViewer(sectionClient);
                c.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 3, 1));
                c.setContentProvider(new ArrayContentProvider());
                c.setInput(ApplicationToolkitType.VALUES);
                IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                        FeaturePath.fromList(ANT_TASK__DEPLOY, DEPLOY__APPLICATION, APPLICATION__TOOLKIT));
                dbc.bindValue(selChange.observe(c.getCombo()), prop.observeDetail(bean));
            }
            {
                Button b = toolkit.createButton(sectionClient, "Convert CSS into binary form", SWT.CHECK);
                b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 4, 1));
                IEMFValueProperty prop = EMFEditProperties.value(editingDomain,
                        FeaturePath.fromList(ANT_TASK__CSS_TO_BIN));
                dbc.bindValue(selChange.observe(b), prop.observeDetail(bean));
            }
        }

        section.setClient(sectionClient);
    }

    {
        Section section = toolkit.createSection(sectionParent,
                Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
        section.setText("Building & Exporting");
        section.setLayoutData(new GridData(GridData.FILL, GridData.FILL, false, true, 1, 2));

        Composite sectionClient = toolkit.createComposite(section);
        sectionClient.setLayout(new GridLayout(1, false));

        {
            FormText text = toolkit.createFormText(sectionClient, false);
            text.setText(
                    "<p>To generate build instructions and export the project: <li style=\"bullet\" bindent=\"1\">Generate <a href=\"generateAnt\">ant build.xml</a> only</li><li style=\"bullet\" bindent=\"2\">Generate <a href=\"generateAndRun\">ant build.xml and run</a></li>&#160;</p>",
                    true, false);
            text.addHyperlinkListener(new IHyperlinkListener() {

                @Override
                public void linkExited(final HyperlinkEvent e) {

                }

                @Override
                public void linkEntered(HyperlinkEvent e) {
                }

                @Override
                public void linkActivated(HyperlinkEvent e) {
                    try {
                        if ("generateAndRun".equals(e.getHref())) {
                            executeExport();
                        } else {
                            executeGenerateAnt();
                        }
                    } catch (Exception e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }
            });
        }

        section.setClient(sectionClient);
    }

    int index = addPage(composite);
    setPageText(index, "Overview");
}

From source file:at.medevit.elexis.gdt.ui.table.util.ColumnBuilder.java

License:Open Source License

/**
 * Builds the column and returns the TableViewerColumn
 *///from ww  w  . ja v  a 2  s  . c o  m
public TableViewerColumn build() {
    // create column
    TableViewerColumn viewerColumn = new TableViewerColumn(viewer, align);
    TableColumn column = viewerColumn.getColumn();
    column.setText(columnHeaderText);

    // set label provider
    if (customLabelProvider != null) {
        if (cellFormatter != null) {
            throw new RuntimeException("If you specify a custom label provider, it is not allowed "
                    + "to specify a cell formatter. You need to do the formatting in your labelprovider!");
        }
        viewerColumn.setLabelProvider(customLabelProvider);
    } else {
        viewerColumn
                .setLabelProvider(new PropertyCellLabelProvider(valueHandler, valueFormatter, cellFormatter));
    }

    // activate column sorting
    if (sortBy == null) {
        sortBy = valueHandler;
    }
    if (sortBy != null) {
        column.setData(SortColumnComparator.SORT_BY, sortBy);
        column.addSelectionListener(new ColumnSortSelectionListener(viewer));
        if (defaultSort) {
            viewer.getTable().setSortColumn(column);
            viewer.getTable().setSortDirection(SWT.UP);
        }
    }

    // set column layout data
    if (widthPixel != null && widthPercent != null) {
        throw new RuntimeException("You can specify a width in pixel OR in percent, but not both!");
    }
    if (widthPercent == null) {
        // default width of 100px if nothing specified
        ((TableColumnLayout) viewer.getTable().getParent().getLayout()).setColumnData(column,
                new ColumnPixelData(widthPixel == null ? 100 : widthPixel));
    } else {
        ((TableColumnLayout) viewer.getTable().getParent().getLayout()).setColumnData(column,
                new ColumnWeightData(widthPercent));
    }

    // set editing support
    if (editor != null) {
        if (valueHandler == null) {
            throw new RuntimeException(
                    "makeEditable() requires that the column is bound to some value using bindTo...()");
        }

        viewerColumn.setEditingSupport(new PropertyEditingSupport(viewer, valueHandler, editorFormat, editor));
    }

    return viewerColumn;
}

From source file:au.gov.ga.earthsci.bookmark.part.BookmarksPart.java

License:Apache License

private void initList(Composite parent) {
    Composite tableHolder = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;/*w ww.  ja v  a  2s .co m*/
    gd.horizontalAlignment = GridData.FILL;
    tableHolder.setLayoutData(gd);

    TableColumnLayout layout = new TableColumnLayout();
    tableHolder.setLayout(layout);

    bookmarkListTableViewer = new TableViewer(tableHolder,
            SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    bookmarkListTableViewer.getTable().setHeaderVisible(false);
    bookmarkListTableViewer.getTable().setLinesVisible(false);

    bookmarkListTableViewer.getTable().setLayoutData(gd);

    ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    bookmarkListTableViewer.setContentProvider(contentProvider);

    IObservableMap labelMap = BeanProperties.value("name").observeDetail(contentProvider.getKnownElements()); //$NON-NLS-1$

    TableViewerColumn column = new TableViewerColumn(bookmarkListTableViewer, SWT.LEFT);
    column.setEditingSupport(new BookmarkNameEditingSupport(bookmarkListTableViewer));
    column.setLabelProvider(new ObservableMapCellLabelProvider(labelMap) {
        @Override
        public void update(ViewerCell cell) {
            super.update(cell);
            cell.setText(" " + ((IBookmark) cell.getElement()).getName()); //$NON-NLS-1$
            cell.setImage(ImageRegistry.getInstance().get(ImageRegistry.ICON_BOOKMARKS));
        }
    });
    ColumnLayoutData cld = new ColumnWeightData(12);
    layout.setColumnData(column.getColumn(), cld);

    // Allow edit (rename) only via programmatic access (rename command) 
    ColumnViewerEditorActivationStrategy activationStrategy = new ColumnViewerEditorActivationStrategy(
            bookmarkListTableViewer) {
        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };
    TableViewerEditor.create(bookmarkListTableViewer, activationStrategy,
            ColumnViewerEditor.KEYBOARD_ACTIVATION);

    // Populate the current selection with the actual bookmark items
    bookmarkListTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) bookmarkListTableViewer.getSelection();
            List<?> list = selection.toList();
            selectionService.setSelection(list.toArray(new IBookmark[list.size()]));
        }
    });

    // Apply the bookmark on double click
    bookmarkListTableViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            controller.apply((IBookmark) ((IStructuredSelection) event.getSelection()).getFirstElement());
        }
    });

    // Deselect when clicking outside a valid row
    bookmarkListTableViewer.getTable().addMouseListener(new MouseAdapter() {
        @Override
        public void mouseUp(MouseEvent e) {
            if (bookmarkListTableViewer.getTable().getItem(new Point(e.x, e.y)) == null) {
                bookmarkListTableViewer.setSelection(null);
            }
        }
    });

}

From source file:au.gov.ga.earthsci.bookmark.ui.BookmarksPart.java

License:Apache License

private void initList(Composite parent) {
    Composite tableHolder = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;// www  .j a  v  a 2 s . co m
    gd.horizontalAlignment = GridData.FILL;
    tableHolder.setLayoutData(gd);

    TableColumnLayout layout = new TableColumnLayout();
    tableHolder.setLayout(layout);

    bookmarkListTableViewer = new TableViewer(tableHolder,
            SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    bookmarkListTableViewer.getTable().setHeaderVisible(false);
    bookmarkListTableViewer.getTable().setLinesVisible(false);

    bookmarkListTableViewer.getTable().setLayoutData(gd);

    ObservableListContentProvider<IBookmark> contentProvider = new ObservableListContentProvider<IBookmark>(
            IBookmark.class);
    bookmarkListTableViewer.setContentProvider(contentProvider);

    IObservableSet<IBookmark> knownElements = contentProvider.getKnownElements();
    IObservableMap<IBookmark, String> nameMap = BeanProperties.value(IBookmark.class, "name", String.class) //$NON-NLS-1$
            .observeDetail(knownElements);

    TableViewerColumn column = new TableViewerColumn(bookmarkListTableViewer, SWT.LEFT);
    column.setEditingSupport(new BookmarkNameEditingSupport(bookmarkListTableViewer));
    column.setLabelProvider(new ObservableMapCellLabelProvider<IBookmark, String>(nameMap) {
        @Override
        public void update(ViewerCell cell) {
            super.update(cell);
            cell.setText(" " + ((IBookmark) cell.getElement()).getName()); //$NON-NLS-1$
            cell.setImage(ImageRegistry.getInstance().get(ImageRegistry.ICON_BOOKMARKS));
        }
    });
    ColumnLayoutData cld = new ColumnWeightData(12);
    layout.setColumnData(column.getColumn(), cld);

    // Allow edit (rename) only via programmatic access (rename command)
    ColumnViewerEditorActivationStrategy activationStrategy = new ColumnViewerEditorActivationStrategy(
            bookmarkListTableViewer) {
        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };
    TableViewerEditor.create(bookmarkListTableViewer, activationStrategy,
            ColumnViewerEditor.KEYBOARD_ACTIVATION);

    // Populate the current selection with the actual bookmark items
    bookmarkListTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) bookmarkListTableViewer.getSelection();
            List<?> list = selection.toList();
            selectionService.setSelection(list.toArray(new IBookmark[list.size()]));
        }
    });

    // Apply the bookmark on double click
    bookmarkListTableViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            controller.apply((IBookmark) ((IStructuredSelection) event.getSelection()).getFirstElement());
        }
    });

    // Deselect when clicking outside a valid row
    bookmarkListTableViewer.getTable().addMouseListener(new MouseAdapter() {
        @Override
        public void mouseUp(MouseEvent e) {
            if (bookmarkListTableViewer.getTable().getItem(new Point(e.x, e.y)) == null) {
                bookmarkListTableViewer.setSelection(null);
            }
        }
    });

}

From source file:au.gov.ga.earthsci.common.ui.dialogs.SpatialReferenceSelectorDialog.java

License:Apache License

private void addReferencesTableViewer(Composite container) {
    Composite tableContainer = new Composite(container, SWT.NONE);
    tableContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
    TableColumnLayout tableColumnLayout = new TableColumnLayout();
    tableContainer.setLayout(tableColumnLayout);

    referencesView = new TableViewer(tableContainer,
            SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.SINGLE | SWT.VIRTUAL | SWT.FULL_SELECTION);
    referencesView.setContentProvider(ArrayContentProvider.getInstance());
    referencesView.setInput(SpatialReferences.get());
    referencesView.getTable().setLinesVisible(true);
    referencesView.getTable().setHeaderVisible(true);

    TableViewerColumn epsgColumn = new TableViewerColumn(referencesView, SWT.NONE);
    epsgColumn.getColumn().setText(Messages.getString("SpatialReferenceSelectorDialog.CodeColumnTitle")); //$NON-NLS-1$
    tableColumnLayout.setColumnData(epsgColumn.getColumn(), new ColumnPixelData(80));
    epsgColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override//from   w  w  w  . ja va2s. c o m
        public String getText(Object element) {
            return ((SpatialReferenceSummary) element).getEpsg();
        }
    });

    TableViewerColumn nameColumn = new TableViewerColumn(referencesView, SWT.NONE);
    nameColumn.getColumn().setText(Messages.getString("SpatialReferenceSelectorDialog.NameColumnTitle")); //$NON-NLS-1$
    tableColumnLayout.setColumnData(nameColumn.getColumn(), new ColumnWeightData(100));
    nameColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            return ((SpatialReferenceSummary) element).getName();
        }
    });
}

From source file:cc.xuloo.rcputils.tables.ColumnBuilder.java

License:Open Source License

/**
 * Builds the column and returns the TableViewerColumn
 *///w w w.  j  av a 2  s  .c om
public TableViewerColumn build() {
    // create column
    TableViewerColumn viewerColumn = new TableViewerColumn(builder.getTableViewer(), align);
    TableColumn column = viewerColumn.getColumn();
    column.setText(columnHeaderText);

    // set label provider
    if (customLabelProvider != null) {
        if (cellFormatter != null) {
            throw new RuntimeException("If you specify a custom label provider, it is not allowed "
                    + "to specify a cell formatter. You need to do the formatting in your labelprovider!");
        }
        viewerColumn.setLabelProvider(customLabelProvider);
    } else {
        viewerColumn
                .setLabelProvider(new PropertyCellLabelProvider(valueHandler, valueFormatter, cellFormatter));
    }

    // activate column sorting
    if (sortBy == null) {
        sortBy = valueHandler;
    }
    if (sortBy != null) {
        column.setData(SortColumnComparator.SORT_BY, sortBy);
        column.addSelectionListener(builder.getSortSelectionListener());
        if (defaultSort) {
            builder.getTable().setSortColumn(column);
            builder.getTable().setSortDirection(SWT.DOWN);
        }
    }

    // set column layout data
    if (widthPixel != null && widthPercent != null) {
        throw new RuntimeException("You can specify a width in pixel OR in percent, but not both!");
    }
    if (widthPercent == null) {
        // default width of 100px if nothing specified
        builder.getTableLayout().setColumnData(column,
                new ColumnPixelData(widthPixel == null ? 100 : widthPixel));
    } else {
        builder.getTableLayout().setColumnData(column, new ColumnWeightData(widthPercent));
    }

    // set editing support
    if (editor != null) {
        if (valueHandler == null) {
            throw new RuntimeException(
                    "makeEditable() requires that the column is bound to some value using bindTo...()");
        }

        viewerColumn.setEditingSupport(
                new PropertyEditingSupport(builder.getTableViewer(), valueHandler, editorFormat, editor));
    }

    return viewerColumn;
}

From source file:ch.unibe.iam.scg.archie.controller.TableFactory.java

License:Open Source License

/**
 * Creates all columns in this table. This method sets a weight to each
 * column so that all columns are layed out equally in their container.
 * /*from  www  .  j  a  v  a  2 s.  com*/
 * @param table
 *            The table to perform column operations on.
 * @param provider
 *            A data provider.
 * @param layout
 *            Layout to use for the columns.
 */
private void createColumns(final Table table, final DataSet dataset, TableColumnLayout layout) {
    int i = 0;
    List<String> headings = dataset.getHeadings();

    for (String text : headings) {
        TableColumn column = new TableColumn(table, SWT.NONE);

        column.setMoveable(true);
        column.setText(text);
        column.pack();

        // computes the weight for each column based on the total number of
        // columns and sets the columndata in the layout accordingly
        int weight = Math.round((100 / headings.size()));
        layout.setColumnData(column, new ColumnWeightData(weight));

        i++;
    }
}

From source file:com.amazonaws.eclipse.codedeploy.explorer.editor.table.DeploymentsTableView.java

License:Apache License

private void createColumns(TreeColumnLayout tableColumnLayout, Tree tree) {

    TreeColumn column = new TreeColumn(tree, SWT.NONE);
    column.setText("Deployment ID");
    ColumnWeightData cwd_column = new ColumnWeightData(10);
    cwd_column.minimumWidth = 1;/*from  w w w  .j ava 2  s. co  m*/
    tableColumnLayout.setColumnData(column, cwd_column);

    TreeColumn column_1 = new TreeColumn(tree, SWT.NONE);
    column_1.setText("EC2 Instance");
    tableColumnLayout.setColumnData(column_1, new ColumnWeightData(10));

    TreeColumn column_2 = new TreeColumn(tree, SWT.NONE);
    column_2.setText("Lifecycle Event");
    tableColumnLayout.setColumnData(column_2, new ColumnWeightData(8));

    TreeColumn column_3 = new TreeColumn(tree, SWT.NONE);
    column_3.setText("Status");
    tableColumnLayout.setColumnData(column_3, new ColumnWeightData(6));

    TreeColumn column_4 = new TreeColumn(tree, SWT.NONE);
    column_4.setText("Start Time");
    tableColumnLayout.setColumnData(column_4, new ColumnWeightData(12));

    TreeColumn column_5 = new TreeColumn(tree, SWT.NONE);
    column_5.setText("End Time");
    tableColumnLayout.setColumnData(column_5, new ColumnWeightData(12));

    TreeColumn column_6 = new TreeColumn(tree, SWT.NONE);
    column_6.setText("Revision");
    tableColumnLayout.setColumnData(column_6, new ColumnWeightData(20));

    TreeColumn column_7 = new TreeColumn(tree, SWT.NONE);
    column_7.setText("Logs");
    tableColumnLayout.setColumnData(column_7, new ColumnWeightData(15));
}

From source file:com.amazonaws.eclipse.core.ui.MultiValueEditorDialog.java

License:Apache License

@Override
protected Control createDialogArea(final Composite parent) {

    Composite composite = new Composite(parent, SWT.None);
    GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(composite);

    TableColumnLayout layout = new TableColumnLayout();
    composite.setLayout(layout);//from  w w w.  j a  v  a2s  .  co  m

    this.tableViewer = new TableViewer(composite);
    this.tableViewer.getTable().setHeaderVisible(true);
    TableColumn tableColumn = new TableColumn(this.tableViewer.getTable(), SWT.NONE);
    tableColumn.setText(columnText);
    layout.setColumnData(tableColumn, new ColumnWeightData(100));

    this.tableViewer.setContentProvider(new AbstractTableContentProvider() {

        @Override
        public Object[] getElements(final Object inputElement) {
            Object[] rowsPlusNew = new Object[MultiValueEditorDialog.this.values.size() + 1];
            MultiValueEditorDialog.this.values.toArray(rowsPlusNew);
            rowsPlusNew[rowsPlusNew.length - 1] = NEW_VALUE;
            return rowsPlusNew;
        }
    });

    this.tableViewer.setLabelProvider(new AbstractTableLabelProvider() {

        @Override
        public String getColumnText(final Object element, final int columnIndex) {
            return (String) element;
        }
    });

    final Table table = this.tableViewer.getTable();
    final TableEditor editor = new TableEditor(table);
    editor.horizontalAlignment = SWT.LEFT;
    editor.grabHorizontal = true;
    table.addListener(SWT.MouseUp, new Listener() {

        public void handleEvent(final Event event) {
            Rectangle clientArea = table.getClientArea();
            Point pt = new Point(event.x, event.y);
            int index = table.getTopIndex();
            while (index < table.getItemCount()) {
                boolean visible = false;
                final TableItem item = table.getItem(index);

                // Only one column, but loop is here for completeness
                for (int i = 0; i < table.getColumnCount(); i++) {
                    Rectangle rect = item.getBounds(i);
                    if (rect.contains(pt)) {
                        final int column = i;
                        final Text text = new Text(table, SWT.NONE);
                        final int idx = index;
                        if (isRowUneditable(idx)) {
                            return;
                        }
                        Listener textListener = new Listener() {

                            public void handleEvent(final Event e) {
                                if (e.type == SWT.Traverse && e.detail == SWT.TRAVERSE_ESCAPE) {
                                    /* Skip data validation and dispose the text editor */
                                    text.dispose();
                                    e.doit = false;
                                    return;
                                } else if (e.type == SWT.Traverse && e.detail != SWT.TRAVERSE_RETURN) {
                                    /* No-op for keys other than escape or return. */
                                    return;
                                } else {
                                    /* For all other events, we first validate the data */
                                    if (!validateAttributeValue(text.getText())) {
                                        lockTableEditor(idx);
                                        return;
                                    }
                                    /* First unlock everything */
                                    unlockTableEditor();
                                    /* Then we handle different events */
                                    if (e.type == SWT.FocusOut) {
                                        modifyValue(item, column, idx, text);
                                        text.dispose();
                                    } else if (e.type == SWT.Traverse && e.detail == SWT.TRAVERSE_RETURN) {
                                        modifyValue(item, column, idx, text);
                                    } else if (e.type == SWT.Modify) {
                                        /* No-op */
                                    }
                                }
                            }
                        };

                        text.addListener(SWT.FocusOut, textListener);
                        text.addListener(SWT.Traverse, textListener);
                        text.addListener(SWT.Modify, textListener);
                        editor.setEditor(text, item, i);
                        text.setText(item.getText(i));

                        text.selectAll();
                        text.setFocus();
                        return;
                    }
                    if (!visible && rect.intersects(clientArea)) {
                        visible = true;
                    }
                }
                if (!visible) {
                    return;
                }
                index++;
            }
        }
    });

    /* Suppress changing to other table rows when the editor is locked. */
    this.tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        private boolean update = true;
        private ISelection lastSelection;

        public void selectionChanged(SelectionChangedEvent event) {
            if (update && isLocked()) {
                update = false; // avoid infinite loop
                tableViewer.setSelection(lastSelection);
                update = true;
            } else if (!isLocked()) {
                lastSelection = event.getSelection();
            }
        }

    });

    this.tableViewer.setInput(values.size());
    this.tableViewer.getTable().getItem(this.values.size())
            .setForeground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY));

    return composite;
}

From source file:com.amazonaws.eclipse.datatools.enablement.simpledb.ui.editor.MultiValueEditorDialog.java

License:Apache License

@Override
protected Control createDialogArea(final Composite parent) {

    Composite composite = new Composite(parent, SWT.None);
    GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(composite);

    TableColumnLayout layout = new TableColumnLayout();
    composite.setLayout(layout);/*from w w  w  .ja  v a  2 s.  c o m*/

    this.tableViewer = new TableViewer(composite);
    this.tableViewer.getTable().setHeaderVisible(true);
    TableColumn tableColumn = new TableColumn(this.tableViewer.getTable(), SWT.NONE);
    tableColumn.setText("Attributes");
    layout.setColumnData(tableColumn, new ColumnWeightData(100));

    this.tableViewer.setContentProvider(new AbstractTableContentProvider() {

        @Override
        public Object[] getElements(final Object inputElement) {
            Object[] rowsPlusNew = new Object[MultiValueEditorDialog.this.attributeValues.size() + 1];
            MultiValueEditorDialog.this.attributeValues.toArray(rowsPlusNew);
            rowsPlusNew[rowsPlusNew.length - 1] = NEW_VALUE;
            return rowsPlusNew;
        }
    });

    this.tableViewer.setLabelProvider(new AbstractTableLabelProvider() {

        @Override
        public String getColumnText(final Object element, final int columnIndex) {
            return (String) element;
        }
    });

    final Table table = this.tableViewer.getTable();
    final TableEditor editor = new TableEditor(table);
    editor.horizontalAlignment = SWT.LEFT;
    editor.grabHorizontal = true;
    table.addListener(SWT.MouseUp, new Listener() {

        public void handleEvent(final Event event) {
            Rectangle clientArea = table.getClientArea();
            Point pt = new Point(event.x, event.y);
            int index = table.getTopIndex();
            while (index < table.getItemCount()) {
                boolean visible = false;
                final TableItem item = table.getItem(index);

                // Only one column, but loop is here for completeness
                for (int i = 0; i < table.getColumnCount(); i++) {
                    Rectangle rect = item.getBounds(i);
                    if (rect.contains(pt)) {
                        final int column = i;
                        final Text text = new Text(table, SWT.NONE);
                        final int idx = index;

                        Listener textListener = new Listener() {

                            public void handleEvent(final Event e) {
                                switch (e.type) {
                                case SWT.FocusOut:
                                    modifyValue(item, column, idx, text);
                                    text.dispose();
                                    break;
                                case SWT.Traverse:
                                    switch (e.detail) {
                                    case SWT.TRAVERSE_RETURN:
                                        modifyValue(item, column, idx, text);
                                        // FALL THROUGH
                                    case SWT.TRAVERSE_ESCAPE:
                                        text.dispose();
                                        e.doit = false;
                                    }
                                    break;
                                }
                            }
                        };

                        text.addListener(SWT.FocusOut, textListener);
                        text.addListener(SWT.Traverse, textListener);
                        editor.setEditor(text, item, i);
                        text.setText(item.getText(i));

                        text.selectAll();
                        text.setFocus();
                        return;
                    }
                    if (!visible && rect.intersects(clientArea)) {
                        visible = true;
                    }
                }
                if (!visible) {
                    return;
                }
                index++;
            }
        }
    });

    this.tableViewer.setInput(this.item);
    this.tableViewer.getTable().getItem(this.attributeValues.size())
            .setForeground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY));

    return composite;
}