Search in sources :

Example 26 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project cubrid-manager by CUBRID.

the class CommonUITool method createCheckBoxTableViewer.

/**
	 *
	 * Create the common checkbox table viewer that can be sorted by
	 * TableViewerSorter object,this viewer's input object must be
	 * List<Map<String,Object>> and Map's key must be column index,Map's value
	 * of the column must be String.
	 *
	 * @param parent the parent composite
	 * @param sorter the table sorter
	 * @param columnNameArr the column name array
	 * @param gridData the gridData layout object
	 * @return the TableViewer object
	 */
public static TableViewer createCheckBoxTableViewer(Composite parent, ViewerSorter sorter, final String[] columnNameArr, GridData gridData) {
    final CheckboxTableViewer tableViewer = CheckboxTableViewer.newCheckList(parent, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION);
    tableViewer.setContentProvider(new TableContentProvider());
    tableViewer.setLabelProvider(new TableLabelProvider());
    if (sorter != null) {
        tableViewer.setSorter(sorter);
    }
    tableViewer.getTable().setLinesVisible(true);
    tableViewer.getTable().setHeaderVisible(true);
    tableViewer.getTable().setLayoutData(gridData);
    for (int i = 0; i < columnNameArr.length; i++) {
        final TableColumn tblColumn = new TableColumn(tableViewer.getTable(), SWT.LEFT);
        tblColumn.setText(columnNameArr[i]);
        if (sorter != null) {
            tblColumn.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent event) {
                    TableColumn column = (TableColumn) event.widget;
                    int j = 0;
                    for (j = 0; j < columnNameArr.length; j++) {
                        if (column.getText().equals(columnNameArr[j])) {
                            break;
                        }
                    }
                    TableViewerSorter sorter = ((TableViewerSorter) tableViewer.getSorter());
                    if (sorter == null) {
                        return;
                    }
                    sorter.doSort(j);
                    tableViewer.getTable().setSortColumn(column);
                    tableViewer.getTable().setSortDirection(sorter.isAsc() ? SWT.UP : SWT.DOWN);
                    tableViewer.refresh();
                    packTable(tableViewer);
                }
            });
        }
        tblColumn.pack();
    }
    return tableViewer;
}
Also used : TableViewerSorter(com.cubrid.common.ui.spi.TableViewerSorter) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableContentProvider(com.cubrid.common.ui.spi.TableContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableLabelProvider(com.cubrid.common.ui.spi.TableLabelProvider) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point)

Example 27 with CheckboxTableViewer

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

the class HyperlinkDetectorsConfigurationBlock method createControl.

@Override
public Control createControl(Composite parent) {
    PixelConverter pixelConverter = new PixelConverter(parent);
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    addFiller(composite, 2);
    String label = TextEditorMessages.HyperlinksEnabled_label;
    fHyperlinksEnabledCheckBox = addCheckBox(composite, label, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED, 0);
    fHyperlinksEnabledCheckBox.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean state = fHyperlinksEnabledCheckBox.getSelection();
            fHyperlinkDefaultKeyModifierText.setEnabled(state);
            fHyperlinkKeyModifierText.setEnabled(state && getSelectedItem() != null);
            fHyperlinkDetectorsViewer.getTable().setEnabled(state);
            handleHyperlinkKeyModifierModified();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    // Text field for default modifier string
    label = TextEditorMessages.HyperlinkDefaultKeyModifier_label;
    fHyperlinkDefaultKeyModifierText = (Text) addTextField(composite, label, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_KEY_MODIFIER, 15, 20, pixelConverter)[1];
    fHyperlinkDefaultKeyModifierText.addKeyListener(new KeyListener() {

        private boolean isModifierCandidate;

        @Override
        public void keyPressed(KeyEvent e) {
            isModifierCandidate = e.keyCode > 0 && e.character == 0 && e.stateMask == 0;
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask && e.character == 0) {
                // && e.time -time < 1000) {
                String modifierString = fHyperlinkDefaultKeyModifierText.getText();
                Point selection = fHyperlinkDefaultKeyModifierText.getSelection();
                int i = selection.x - 1;
                while (i > -1 && Character.isWhitespace(modifierString.charAt(i))) {
                    i--;
                }
                boolean needsPrefixDelimiter = i > -1 && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
                i = selection.y;
                while (i < modifierString.length() && Character.isWhitespace(modifierString.charAt(i))) {
                    i++;
                }
                boolean needsPostfixDelimiter = i < modifierString.length() && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
                String insertString;
                if (needsPrefixDelimiter && needsPostfixDelimiter)
                    insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifierAndDelimiter, Action.findModifierString(e.stateMask));
                else if (needsPrefixDelimiter)
                    insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifier, Action.findModifierString(e.stateMask));
                else if (needsPostfixDelimiter)
                    insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertModifierAndDelimiter, Action.findModifierString(e.stateMask));
                else
                    insertString = Action.findModifierString(e.stateMask);
                fHyperlinkDefaultKeyModifierText.insert(insertString);
            }
        }
    });
    fHyperlinkDefaultKeyModifierText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            handleHyperlinkDefaultKeyModifierModified();
        }
    });
    addFiller(composite, 2);
    Composite editorComposite = new Composite(composite, SWT.NONE);
    GridData gd;
    gd = new GridData(SWT.FILL, SWT.TOP, true, false);
    gd.horizontalSpan = 2;
    gd.horizontalIndent = 20;
    editorComposite.setLayoutData(gd);
    TableColumnLayout tableColumnlayout = new TableColumnLayout();
    editorComposite.setLayout(tableColumnlayout);
    // Hyperlink detector table
    Table hyperlinkDetectorTable = new Table(editorComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION | SWT.CHECK);
    hyperlinkDetectorTable.setHeaderVisible(true);
    hyperlinkDetectorTable.setLinesVisible(true);
    hyperlinkDetectorTable.setFont(parent.getFont());
    hyperlinkDetectorTable.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            handleListSelection();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    ColumnLayoutData columnLayoutData = new ColumnWeightData(1);
    TableColumn nameColumn = new TableColumn(hyperlinkDetectorTable, SWT.NONE, 0);
    nameColumn.setText(TextEditorMessages.HyperlinkDetectorTable_nameColumn);
    tableColumnlayout.setColumnData(nameColumn, columnLayoutData);
    TableColumn modifierKeysColumn = new TableColumn(hyperlinkDetectorTable, SWT.NONE, 1);
    modifierKeysColumn.setText(TextEditorMessages.HyperlinkDetectorTable_modifierKeysColumn);
    tableColumnlayout.setColumnData(modifierKeysColumn, columnLayoutData);
    TableColumn targetNameColumn = new TableColumn(hyperlinkDetectorTable, SWT.NONE, 2);
    targetNameColumn.setText(TextEditorMessages.HyperlinkDetectorTable_targetNameColumn);
    tableColumnlayout.setColumnData(targetNameColumn, columnLayoutData);
    fHyperlinkDetectorsViewer = new CheckboxTableViewer(hyperlinkDetectorTable);
    fHyperlinkDetectorsViewer.setUseHashlookup(true);
    fHyperlinkDetectorsViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            String id = ((ListItem) event.getElement()).id;
            if (id == null)
                return;
            fStore.setValue(id, !event.getChecked());
        }
    });
    fHyperlinkDetectorsViewer.setLabelProvider(new ItemLabelProvider());
    fHyperlinkDetectorsViewer.setContentProvider(new ItemContentProvider());
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    gd.heightHint = pixelConverter.convertHeightInCharsToPixels(10);
    fHyperlinkDetectorsViewer.getControl().setLayoutData(gd);
    // addFiller(composite, 2);
    // Text field for modifier string
    label = TextEditorMessages.HyperlinkKeyModifier_label;
    fHyperlinkKeyModifierText = (Text) addTextField(composite, label, null, 15, 20, pixelConverter)[1];
    fHyperlinkKeyModifierText.addKeyListener(new KeyListener() {

        private boolean isModifierCandidate;

        @Override
        public void keyPressed(KeyEvent e) {
            isModifierCandidate = e.keyCode > 0 && e.character == 0 && e.stateMask == 0;
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask && e.character == 0) {
                // && e.time -time < 1000) {
                String modifierString = fHyperlinkKeyModifierText.getText();
                Point selection = fHyperlinkKeyModifierText.getSelection();
                int i = selection.x - 1;
                while (i > -1 && Character.isWhitespace(modifierString.charAt(i))) {
                    i--;
                }
                boolean needsPrefixDelimiter = i > -1 && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
                i = selection.y;
                while (i < modifierString.length() && Character.isWhitespace(modifierString.charAt(i))) {
                    i++;
                }
                boolean needsPostfixDelimiter = i < modifierString.length() && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
                String insertString;
                if (needsPrefixDelimiter && needsPostfixDelimiter)
                    insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifierAndDelimiter, Action.findModifierString(e.stateMask));
                else if (needsPrefixDelimiter)
                    insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifier, Action.findModifierString(e.stateMask));
                else if (needsPostfixDelimiter)
                    insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertModifierAndDelimiter, Action.findModifierString(e.stateMask));
                else
                    insertString = Action.findModifierString(e.stateMask);
                fHyperlinkKeyModifierText.insert(insertString);
            }
        }
    });
    fHyperlinkKeyModifierText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            handleHyperlinkKeyModifierModified();
        }
    });
    return composite;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Point(org.eclipse.swt.graphics.Point) TableColumn(org.eclipse.swt.widgets.TableColumn) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) PixelConverter(org.eclipse.jface.layout.PixelConverter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) ColumnLayoutData(org.eclipse.jface.viewers.ColumnLayoutData) KeyListener(org.eclipse.swt.events.KeyListener) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 28 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project linuxtools by eclipse.

the class RunImageVolumesTab method createVolumesTable.

private CheckboxTableViewer createVolumesTable(final Composite container) {
    final Table table = new Table(container, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
    final CheckboxTableViewer tableViewer = new CheckboxTableViewer(table);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    addTableViewerColumn(tableViewer, WizardMessages.getString(// $NON-NLS-1$
    "ImageRunResourceVolVarPage.containerPathColumn"), 150);
    addTableViewerColumn(tableViewer, WizardMessages.getString(// $NON-NLS-1$
    "ImageRunResourceVolVarPage.mountColumn"), 150);
    addTableViewerColumn(tableViewer, WizardMessages.getString(// $NON-NLS-1$
    "ImageRunResourceVolVarPage.readonlyColumn"), 60);
    return tableViewer;
}
Also used : Table(org.eclipse.swt.widgets.Table) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer)

Example 29 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project linuxtools by eclipse.

the class ImageRunResourceVolumesVariablesPage method createVolumeSettingsContainer.

private void createVolumeSettingsContainer(final Composite container) {
    final Label volumesLabel = new Label(container, SWT.NONE);
    volumesLabel.setText(WizardMessages.getString(// $NON-NLS-1$
    "ImageRunResourceVolVarPage.dataVolumesLabel"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(COLUMNS, 1).applyTo(volumesLabel);
    final CheckboxTableViewer dataVolumesTableViewer = createVolumesTable(container);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).hint(200, 100).applyTo(dataVolumesTableViewer.getTable());
    // buttons
    final Composite buttonsContainers = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(false, false).applyTo(buttonsContainers);
    GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(SWT.DEFAULT, 0).applyTo(buttonsContainers);
    final Button addButton = new Button(buttonsContainers, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(addButton);
    addButton.setText(WizardMessages.getString(// $NON-NLS-1$
    "ImageRunResourceVolVarPage.addButton"));
    addButton.addSelectionListener(onAddDataVolume(dataVolumesTableViewer));
    final Button editButton = new Button(buttonsContainers, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(editButton);
    editButton.setText(WizardMessages.getString(// $NON-NLS-1$
    "ImageRunResourceVolVarPage.editButton"));
    editButton.addSelectionListener(onEditDataVolume(dataVolumesTableViewer));
    editButton.setEnabled(false);
    final Button removeButton = new Button(buttonsContainers, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(removeButton);
    removeButton.setText(WizardMessages.getString(// $NON-NLS-1$
    "ImageRunResourceVolVarPage.removeButton"));
    removeButton.addSelectionListener(onRemoveDataVolumes(dataVolumesTableViewer));
    removeButton.setEnabled(false);
    // update table content when selected image changes
    bind(dataVolumesTableViewer, model.getDataVolumes(), BeanProperties.values(DataVolumeModel.class, DataVolumeModel.CONTAINER_PATH, DataVolumeModel.MOUNT, DataVolumeModel.READ_ONLY_VOLUME));
    dbc.bindSet(ViewersObservables.observeCheckedElements(dataVolumesTableViewer, DataVolumeModel.class), BeanProperties.set(ImageRunResourceVolumesVariablesModel.SELECTED_DATA_VOLUMES).observe(model));
    // disable the edit and removeButton if the table is empty
    dataVolumesTableViewer.addSelectionChangedListener(onSelectionChanged(editButton, removeButton));
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label)

Example 30 with CheckboxTableViewer

use of org.eclipse.jface.viewers.CheckboxTableViewer in project linuxtools by eclipse.

the class ImageRunResourceVolumesVariablesPage method createVolumesTable.

private CheckboxTableViewer createVolumesTable(final Composite container) {
    final Table table = new Table(container, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
    final CheckboxTableViewer tableViewer = new CheckboxTableViewer(table);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    dbc.bindSet(ViewersObservables.observeCheckedElements(tableViewer, DataVolumeModel.class), BeanProperties.set(ImageRunResourceVolumesVariablesModel.SELECTED_DATA_VOLUMES).observe(model));
    addTableViewerColum(tableViewer, WizardMessages.getString(// $NON-NLS-1$
    "ImageRunResourceVolVarPage.containerPathColumn"), 150);
    addTableViewerColum(tableViewer, WizardMessages.getString(// $NON-NLS-1$
    "ImageRunResourceVolVarPage.mountColumn"), 150);
    addTableViewerColum(tableViewer, WizardMessages.getString(// $NON-NLS-1$
    "ImageRunResourceVolVarPage.readonlyColumn"), 60);
    return tableViewer;
}
Also used : Table(org.eclipse.swt.widgets.Table) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer)

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