Search in sources :

Example 21 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project netxms by netxms.

the class CellSelectionManager method handleSelection.

/**
 * @param event
 */
private void handleSelection(Event event) {
    if ((event.detail & SWT.CHECK) == 0 && focusCell != null && focusCell.getItem() != event.item && event.item != null && !event.item.isDisposed()) {
        ViewerRow row = viewer.getViewerRowFromItem(event.item);
        // $NON-NLS-1$
        Assert.isNotNull(row, "Internal Structure invalid. Row item has no row ViewerRow assigned");
        ViewerCell tmp = row.getCell(focusCell.getColumnIndex());
        if (!focusCell.equals(tmp)) {
            setFocusCell(tmp, true);
        }
    }
}
Also used : ViewerRow(org.eclipse.jface.viewers.ViewerRow) ViewerCell(org.eclipse.jface.viewers.ViewerCell)

Example 22 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project eclipse-integration-commons by spring-projects.

the class SwtConnect method boldMatchedElements.

/**
 * Decorate a basic LabelProvider so that it bolds matched elements based on a text-based filter applied to its labels.
 */
public static StyledCellLabelProvider boldMatchedElements(Stylers stylers, ILabelProvider baseLabels, Filter<String> filter) {
    return new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            Object element = cell.getElement();
            // image
            cell.setImage(baseLabels.getImage(element));
            // styled label
            String label = baseLabels.getText(element);
            StyledString styledLabel = new StyledString(label);
            if (filter.accept(label)) {
                Styler bold = stylers.bold();
                for (IRegion r : filter.getHighlights(label)) {
                    styledLabel.setStyle(r.getOffset(), r.getLength(), bold);
                }
            }
            cell.setStyleRanges(styledLabel.getStyleRanges());
            cell.setText(styledLabel.getString());
            cell.getControl().redraw();
        // ^^^ Sigh... Yes, this is needed. It seems SWT/Jface isn't smart enough to itself figure out that if
        // the styleranges change a redraw is needed to make the change visible.
        }
    };
}
Also used : StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Styler(org.eclipse.jface.viewers.StyledString.Styler) ViewerCell(org.eclipse.jface.viewers.ViewerCell) IRegion(org.eclipse.jface.text.IRegion)

Example 23 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project webtools.sourceediting by eclipse.

the class OutputPropertiesBlock method createControl.

public void createControl(Composite parent) {
    TabItem item = new TabItem((TabFolder) parent, SWT.NONE);
    // $NON-NLS-1$
    item.setText(Messages.getString("OutputPropertiesBlock_0"));
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginBottom = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    item.setControl(composite);
    table = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.MULTI);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.character == SWT.DEL && event.stateMask == 0) {
                performRemove();
            }
        }
    });
    TableColumn tc1 = new TableColumn(table, SWT.NONE);
    // $NON-NLS-1$
    tc1.setText(Messages.getString("OutputPropertiesBlock_1"));
    tc1.setWidth(350);
    tc1.setResizable(true);
    TableColumn tc2 = new TableColumn(table, SWT.NONE);
    // $NON-NLS-1$
    tc2.setText(Messages.getString("OutputPropertiesBlock_2"));
    tc2.setWidth(50);
    tc2.setResizable(true);
    Composite buttonComp = new Composite(composite, SWT.FILL);
    buttonComp.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    GridLayout gl = new GridLayout();
    gl.marginWidth = 0;
    buttonComp.setLayout(gl);
    Button addButton = new Button(buttonComp, SWT.PUSH);
    // $NON-NLS-1$
    addButton.setText(Messages.getString("OutputPropertiesBlock_3"));
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    addButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            OutputPropertyDialog dialog = new OutputPropertyDialog(getShell(), properties);
            if (dialog.open() == Window.OK) {
                List<IOutputProperty> newProperties = dialog.getOutpuProperties();
                String first = null;
                for (IOutputProperty property : newProperties) {
                    String att = property.getURI();
                    if (first == null)
                        first = att;
                    properties.setProperty(property.getURI(), null);
                }
                if (newProperties.size() > 0) {
                    tViewer.refresh();
                    tViewer.setSelection(new StructuredSelection(first), true);
                    tViewer.editElement(first, 1);
                    updateLaunchConfigurationDialog();
                }
            }
        }
    });
    removeButton = new Button(buttonComp, SWT.PUSH);
    // $NON-NLS-1$
    removeButton.setText(Messages.getString("OutputPropertiesBlock_4"));
    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    removeButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            performRemove();
        }
    });
    setControl(table);
    tViewer = new TableViewer(table);
    tViewer.setContentProvider(new IStructuredContentProvider() {

        public Object[] getElements(Object inputElement) {
            return properties.getProperties().keySet().toArray(new String[0]);
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    tViewer.setSorter(new ViewerSorter());
    tViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            updateRemoveButton();
        }
    });
    TableViewerColumn tvc1 = new TableViewerColumn(tViewer, tc1);
    tvc1.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            String tv = (String) cell.getElement();
            cell.setText(tv);
        }

        @Override
        public int getToolTipTimeDisplayed(Object object) {
            return 5000;
        }

        @Override
        public String getToolTipText(Object element) {
            String tv = (String) element;
            return propertyUris.get(tv).getDescription();
        }
    });
    // ColumnViewerToolTipSupport.enableFor(tViewer);
    TableViewerColumn tvc2 = new TableViewerColumn(tViewer, tc2);
    tvc2.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            String tv = (String) cell.getElement();
            String val = properties.getProperty(tv);
            // $NON-NLS-1$
            cell.setText(val == null ? "" : val);
        }
    });
    tvc2.setEditingSupport(new EditingSupport(tViewer) {

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            return new TextCellEditor(table);
        }

        @Override
        protected Object getValue(Object element) {
            String tv = (String) element;
            String val = properties.getProperty(tv);
            // $NON-NLS-1$
            return val == null ? "" : val;
        }

        @Override
        protected void setValue(Object element, Object value) {
            String tv = (String) element;
            properties.setProperty(tv, (String) value);
            updateLaunchConfigurationDialog();
            tViewer.update(tv, null);
        }
    });
    restoreColumnSettings();
}
Also used : CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) KeyAdapter(org.eclipse.swt.events.KeyAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) EditingSupport(org.eclipse.jface.viewers.EditingSupport) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableColumn(org.eclipse.swt.widgets.TableColumn) ViewerCell(org.eclipse.jface.viewers.ViewerCell) TabItem(org.eclipse.swt.widgets.TabItem) IOutputProperty(org.eclipse.wst.xsl.jaxp.launching.IOutputProperty) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 24 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project bndtools by bndtools.

the class RunBundlesPart method getLabelProvider.

@Override
protected IBaseLabelProvider getLabelProvider() {
    return new VersionedClauseLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            Object element = cell.getElement();
            if (element instanceof String) {
                String builder = (String) element;
                StyledString label = new StyledString(builder, StyledString.QUALIFIER_STYLER);
                cell.setText(label.getString());
                cell.setStyleRanges(label.getStyleRanges());
                cell.setImage(projectImg);
            } else {
                super.update(cell);
            }
        }
    };
}
Also used : VersionedClauseLabelProvider(bndtools.model.clauses.VersionedClauseLabelProvider) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) ViewerCell(org.eclipse.jface.viewers.ViewerCell)

Example 25 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project bndtools by bndtools.

the class WorkspacePreviewPage method createControl.

@Override
public void createControl(Composite parent) {
    setTitle("Preview Changes");
    // $NON-NLS-1$
    setImageDescriptor(Plugin.imageDescriptorFromPlugin("icons/bndtools-wizban.png"));
    imgAdded = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/incoming.gif").createImage(parent.getDisplay());
    imgOverwrite = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/conflict.gif").createImage(parent.getDisplay());
    imgError = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/error_obj.gif").createImage(parent.getDisplay());
    int columns = 4;
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(columns, false);
    composite.setLayout(layout);
    setControl(composite);
    Label lblTitle = new Label(composite, SWT.NONE);
    lblTitle.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, columns, 1));
    // Table
    tblOutputs = new Table(composite, SWT.BORDER | SWT.CHECK);
    tblOutputs.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, columns, 1));
    vwrOutputs = new CheckboxTableViewer(tblOutputs);
    vwrOutputs.setContentProvider(ArrayContentProvider.getInstance());
    vwrOutputs.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            StyledString label;
            Image icon;
            String path = (String) cell.getElement();
            String error = resourceErrors.get(path);
            if (error != null) {
                label = new StyledString(path, ItalicStyler.INSTANCE_ERROR);
                icon = imgError;
            } else {
                label = new StyledString(path);
                icon = existingFiles.contains(path) ? imgOverwrite : imgAdded;
            }
            cell.setText(path);
            cell.setStyleRanges(label.getStyleRanges());
            cell.setImage(icon);
        }
    });
    vwrOutputs.setSorter(new ViewerSorter(Collator.getInstance()));
    // Details display
    final Label lblDetails = new Label(composite, SWT.NONE);
    lblDetails.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, columns, 1));
    lblDetails.setText(MSG_NOTHING_SELECTED);
    // Button Panel
    Label spacer1 = new Label(composite, SWT.NONE);
    spacer1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Button btnSelectNonConflict = new Button(composite, SWT.PUSH);
    btnSelectNonConflict.setText("Select Non-Conflicting");
    btnSelectNonConflict.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            modifyLock.modifyOperation(new Runnable() {

                @Override
                public void run() {
                    checkedPaths.clear();
                    for (Entry<String, Resource> entry : templateOutputs.entries()) {
                        String path = entry.getKey();
                        if (!existingFiles.contains(path))
                            checkedPaths.add(path);
                    }
                    vwrOutputs.setCheckedElements(checkedPaths.toArray());
                }
            });
        }
    });
    Button btnSelectAll = new Button(composite, SWT.PUSH);
    btnSelectAll.setText("Select All");
    btnSelectAll.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            vwrOutputs.setAllChecked(true);
        }
    });
    Button btnSelectNone = new Button(composite, SWT.PUSH);
    btnSelectNone.setText("Select None");
    btnSelectNone.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            vwrOutputs.setAllChecked(false);
        }
    });
    // Listeners
    vwrOutputs.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) vwrOutputs.getSelection();
            if (sel.isEmpty()) {
                lblDetails.setText(MSG_NOTHING_SELECTED);
            } else {
                String path = (String) sel.getFirstElement();
                String resourceError = resourceErrors.get(path);
                if (resourceError != null) {
                    lblDetails.setText(resourceError);
                } else if (existingFiles.contains(path)) {
                    lblDetails.setText("This file already exists and will be overwritten");
                } else {
                    lblDetails.setText("This file will be created");
                }
            }
        }
    });
    vwrOutputs.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            modifyLock.ifNotModifying(new Runnable() {

                @Override
                public void run() {
                    final String updatedPath = (String) event.getElement();
                    if (event.getChecked()) {
                        checkedPaths.add(updatedPath);
                        // Check any directories that are parents of this path
                        modifyLock.modifyOperation(new Runnable() {

                            @Override
                            public void run() {
                                for (Entry<String, Resource> entry : templateOutputs.entries()) {
                                    String path = entry.getKey();
                                    if (path.endsWith("/") && updatedPath.startsWith(path)) {
                                        checkedPaths.add(path);
                                        vwrOutputs.setChecked(path, true);
                                    }
                                }
                            }
                        });
                    } else {
                        checkedPaths.remove(updatedPath);
                        // Uncheck any paths that are descendants of this path
                        if (updatedPath.endsWith("/")) {
                            modifyLock.modifyOperation(new Runnable() {

                                @Override
                                public void run() {
                                    for (Entry<String, Resource> entry : templateOutputs.entries()) {
                                        String path = entry.getKey();
                                        if (path.startsWith(updatedPath)) {
                                            checkedPaths.remove(path);
                                            vwrOutputs.setChecked(path, false);
                                        }
                                    }
                                }
                            });
                        }
                    }
                }
            });
        }
    });
}
Also used : CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Label(org.eclipse.swt.widgets.Label) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) StyledString(org.eclipse.jface.viewers.StyledString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Resource(org.bndtools.templating.Resource) StyledString(org.eclipse.jface.viewers.StyledString) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridData(org.eclipse.swt.layout.GridData) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Aggregations

ViewerCell (org.eclipse.jface.viewers.ViewerCell)54 TableViewer (org.eclipse.jface.viewers.TableViewer)21 Composite (org.eclipse.swt.widgets.Composite)21 CellLabelProvider (org.eclipse.jface.viewers.CellLabelProvider)18 GridData (org.eclipse.swt.layout.GridData)18 Table (org.eclipse.swt.widgets.Table)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 Button (org.eclipse.swt.widgets.Button)12 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)11 StyledCellLabelProvider (org.eclipse.jface.viewers.StyledCellLabelProvider)11 Label (org.eclipse.swt.widgets.Label)11 StyledString (org.eclipse.jface.viewers.StyledString)10 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 Point (org.eclipse.swt.graphics.Point)9 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)8 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)8