Search in sources :

Example 1 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project translationstudio8 by heartsome.

the class ConfigureColumnsAction method createColumnControlPanel.

/**
     * Create the dialog area. TODO can be done much nicer ... but works for the first draft
     * 
     * @param parent parent composite
     * @return initialized control
     */
private Control createColumnControlPanel(Composite parent) {
    Composite panel = new Composite(parent, SWT.NULL);
    panel.setLayout(new RowLayout());
    Label l = new Label(panel, SWT.NULL);
    l.setText("Configure the columns");
    Table table = new Table(parent, SWT.CHECK | SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL);
    _chkBoxViewer = new CheckboxTableViewer(table);
    _chkBoxViewer.setContentProvider(new ColTableContentProvider());
    _chkBoxViewer.setLabelProvider(new ColTableLabelProvider());
    TableColumn column = new TableColumn(_chkBoxViewer.getTable(), SWT.LEFT);
    column.setText("Column");
    column.setWidth(100);
    _chkBoxViewer.getTable().setHeaderVisible(true);
    _chkBoxViewer.setInput("x");
    final int firstColIdx = _allowFixedColumns ? 0 : _table.getFixedColumns();
    for (int i = 0; i < _table.getTableModel().getColumnCount(); i++) {
        IColumn col = _table.getTableModel().getColumn(i);
        _chkBoxViewer.setChecked(col, _tvs.getColumnVisible(col));
    }
    table.getColumn(0).pack();
    table.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            if (event.detail == SWT.CHECK) {
                TableItem item = (TableItem) event.item;
                IColumn col = (IColumn) item.getData();
                int idx = _tvs.getSortedColumns().indexOf(col);
                if (_allowFixedColumns || idx >= _table.getFixedColumns()) {
                    _tvs.setColumnVisible(col, item.getChecked());
                } else {
                    _chkBoxViewer.setChecked(col, _tvs.getColumnVisible(col));
                }
            }
        }
    });
    Button upButton = new Button(panel, SWT.PUSH);
    upButton.setText("up");
    upButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent arg0) {
            if (_chkBoxViewer.getTable().getSelectionCount() > 0) {
                TableItem item = _chkBoxViewer.getTable().getItem(_chkBoxViewer.getTable().getSelectionIndex());
                IColumn col = (IColumn) item.getData();
                int idx = _tvs.getSortedColumns().indexOf(col);
                if (idx > firstColIdx) {
                    _tvs.getSortedColumns().remove(col);
                    _tvs.getSortedColumns().add(idx - 1, col);
                    _table.updateColumnList();
                    _table.redraw();
                    _chkBoxViewer.refresh();
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    Button downButton = new Button(panel, SWT.PUSH);
    downButton.setText("down");
    downButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent arg0) {
            if (_chkBoxViewer.getTable().getSelectionCount() > 0) {
                TableItem item = _chkBoxViewer.getTable().getItem(_chkBoxViewer.getTable().getSelectionIndex());
                IColumn col = (IColumn) item.getData();
                int idx = _tvs.getSortedColumns().indexOf(col);
                if (idx < _tvs.getSortedColumns().size() - 1) {
                    _tvs.getSortedColumns().remove(col);
                    _tvs.getSortedColumns().add(idx + 1, col);
                    _table.updateColumnList();
                    _table.redraw();
                    _chkBoxViewer.refresh();
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    return panel;
}
Also used : Table(org.eclipse.swt.widgets.Table) JaretTable(de.jaret.util.ui.table.JaretTable) Listener(org.eclipse.swt.widgets.Listener) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) SelectionListener(org.eclipse.swt.events.SelectionListener) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) TableColumn(org.eclipse.swt.widgets.TableColumn) IColumn(de.jaret.util.ui.table.model.IColumn) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project archi by archimatetool.

the class ConnectionsPreferencePage method createRelationsTable.

private CheckboxTableViewer createRelationsTable(Composite parent) {
    final CheckboxTableViewer viewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint = 80;
    viewer.getTable().setLayoutData(gd);
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ArchiLabelProvider.INSTANCE.getDefaultName((EClass) element);
        }

        @Override
        public Image getImage(Object element) {
            return ArchiLabelProvider.INSTANCE.getImage(element);
        }
    });
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return ConnectionPreferences.RELATION_KEYMAP.keySet().toArray();
        }
    });
    viewer.setCheckStateProvider(new ICheckStateProvider() {

        @Override
        public boolean isGrayed(Object element) {
            return false;
        }

        @Override
        public boolean isChecked(Object element) {
            int value = (Integer) viewer.getInput();
            return (value & ConnectionPreferences.RELATION_KEYMAP.get(element)) != 0;
        }
    });
    return viewer;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) Image(org.eclipse.swt.graphics.Image) ArchiLabelProvider(com.archimatetool.editor.ui.ArchiLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 3 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project sling by apache.

the class ConvertProjectsPage method createControl.

public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 5;
    container.setLayout(layout);
    Table table = new Table(container, SWT.MULTI | SWT.CHECK | SWT.BORDER);
    GridData gd = new GridData(GridData.FILL_BOTH);
    table.setLayoutData(gd);
    ctv = new CheckboxTableViewer(table);
    ctv.setLabelProvider(new ProjectLabelProvider());
    ctv.add(projects.toArray());
    ctv.setCheckedElements(initialSelection);
    setControl(container);
    Dialog.applyDialogFont(container);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) GridData(org.eclipse.swt.layout.GridData)

Example 4 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project eclipse.platform.text by eclipse.

the class SearchDialog method handleCustomizePressed.

private void handleCustomizePressed() {
    List<SearchPageDescriptor> input = SearchPlugin.getDefault().getSearchPageDescriptors();
    input = filterByActivities(input);
    final ArrayList<Image> createdImages = new ArrayList<>(input.size());
    ILabelProvider labelProvider = new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof SearchPageDescriptor)
                return LegacyActionTools.removeMnemonics(((SearchPageDescriptor) element).getLabel());
            return null;
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof SearchPageDescriptor) {
                ImageDescriptor imageDesc = ((SearchPageDescriptor) element).getImage();
                if (imageDesc == null)
                    return null;
                Image image = imageDesc.createImage();
                if (image != null)
                    createdImages.add(image);
                return image;
            }
            return null;
        }
    };
    String message = SearchMessages.SearchPageSelectionDialog_message;
    ListSelectionDialog dialog = new ListSelectionDialog(getShell(), input, new ArrayContentProvider(), labelProvider, message) {

        Button fLastUsedPageButton;

        @Override
        public void create() {
            super.create();
            final CheckboxTableViewer viewer = getViewer();
            final Button okButton = this.getOkButton();
            viewer.addCheckStateListener(event -> okButton.setEnabled(viewer.getCheckedElements().length > 0));
            SelectionListener listener = new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    okButton.setEnabled(viewer.getCheckedElements().length > 0);
                }
            };
            this.getButton(IDialogConstants.SELECT_ALL_ID).addSelectionListener(listener);
            this.getButton(IDialogConstants.DESELECT_ALL_ID).addSelectionListener(listener);
        }

        @Override
        protected Control createDialogArea(Composite parent) {
            Composite control = (Composite) super.createDialogArea(parent);
            fLastUsedPageButton = new Button(control, SWT.CHECK);
            fLastUsedPageButton.setText(SearchMessages.SearchPageSelectionDialog_rememberLastUsedPage_message);
            fLastUsedPageButton.setSelection(fDialogSettings.getBoolean(STORE_IS_OPEN_PREVIOUS_PAGE));
            return control;
        }

        @Override
        protected void okPressed() {
            fDialogSettings.put(STORE_IS_OPEN_PREVIOUS_PAGE, fLastUsedPageButton.getSelection());
            super.okPressed();
        }
    };
    dialog.setTitle(SearchMessages.SearchPageSelectionDialog_title);
    dialog.setInitialSelections(SearchPlugin.getDefault().getEnabledSearchPageDescriptors(fInitialPageId).toArray());
    if (dialog.open() == Window.OK) {
        SearchPageDescriptor.setEnabled(dialog.getResult());
        Display display = getShell().getDisplay();
        close();
        if (display != null && !display.isDisposed()) {
            display.asyncExec(() -> new OpenSearchDialogAction().run());
        }
    }
    destroyImages(createdImages);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Image(org.eclipse.swt.graphics.Image) Button(org.eclipse.swt.widgets.Button) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ListSelectionDialog(org.eclipse.ui.dialogs.ListSelectionDialog) SelectionListener(org.eclipse.swt.events.SelectionListener) Display(org.eclipse.swt.widgets.Display)

Example 5 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project eclipse.platform.text by eclipse.

the class MatchFilterSelectionDialog method createMatchFilterControls.

private void createMatchFilterControls(Composite parent) {
    // Create list viewer
    Label l = new Label(parent, SWT.NONE);
    l.setFont(parent.getFont());
    l.setText(SearchMessages.MatchFilterSelectionDialog_filter_description);
    Table table = new Table(parent, SWT.CHECK | SWT.BORDER);
    table.setFont(parent.getFont());
    fListViewer = new CheckboxTableViewer(table);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.minimumHeight = convertHeightInCharsToPixels(8);
    table.setLayoutData(data);
    class ListenerAndLabelProvider extends LabelProvider implements ISelectionChangedListener, ICheckStateListener {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            performFilterListSelectionChanged();
        }

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            performFilterListCheckStateChanged();
        }

        @Override
        public String getText(Object element) {
            return ((MatchFilter) element).getName();
        }
    }
    ListenerAndLabelProvider listenerAndLP = new ListenerAndLabelProvider();
    fListViewer.setLabelProvider(listenerAndLP);
    fListViewer.setContentProvider(new ArrayContentProvider());
    fListViewer.addSelectionChangedListener(listenerAndLP);
    fListViewer.addCheckStateListener(listenerAndLP);
    fListViewer.setInput(fAllFilters);
    fListViewer.setCheckedElements(fEnabledFilters);
    l = new Label(parent, SWT.NONE);
    l.setFont(parent.getFont());
    l.setText(SearchMessages.MatchFilterSelectionDialog_description_label);
    fDescription = new Text(parent, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL);
    fDescription.setFont(parent.getFont());
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = convertHeightInCharsToPixels(3);
    fDescription.setLayoutData(data);
}
Also used : Table(org.eclipse.swt.widgets.Table) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Text(org.eclipse.swt.widgets.Text) MatchFilter(org.eclipse.search.ui.text.MatchFilter) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)45 Composite (org.eclipse.swt.widgets.Composite)29 Table (org.eclipse.swt.widgets.Table)28 GridData (org.eclipse.swt.layout.GridData)24 GridLayout (org.eclipse.swt.layout.GridLayout)21 Label (org.eclipse.swt.widgets.Label)20 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)19 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)19 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 TableColumn (org.eclipse.swt.widgets.TableColumn)17 Button (org.eclipse.swt.widgets.Button)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)10 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)8 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)8 SelectionListener (org.eclipse.swt.events.SelectionListener)7 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)6 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)6 Viewer (org.eclipse.jface.viewers.Viewer)6 Event (org.eclipse.swt.widgets.Event)6