Search in sources :

Example 11 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project org.csstudio.display.builder by kasemir.

the class SearchView method createSearchSash.

/**
 * Create the 'lower' sash for searching archives
 *  @param sashform
 */
private void createSearchSash(final SashForm sashform) {
    final Composite parent = new Composite(sashform, SWT.BORDER);
    final GridLayout layout = new GridLayout(3, false);
    parent.setLayout(layout);
    // Pattern:  ___pattern___ [x] [search]
    Label l = new Label(parent, 0);
    l.setText(Messages.SearchPattern);
    l.setLayoutData(new GridData());
    // On OS X, a 'search' box might look a little better:
    // pattern = new Text(parent, SWT.SEARCH | SWT.ICON_CANCEL);
    // ... except:
    // a) only takes effect on OS X
    // b) doesn't support drop-down for recent searches
    pattern = new Text(parent, SWT.BORDER);
    pattern.setToolTipText(Messages.SearchPatternTT);
    pattern.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    pattern.setEnabled(false);
    pattern.addListener(SWT.DefaultSelection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            searchForChannels();
        }
    });
    AutoCompleteWidget acw = new AutoCompleteWidget(pattern, AutoCompleteTypes.PV);
    search = new Button(parent, SWT.PUSH);
    search.setText(Messages.Search);
    search.setToolTipText(Messages.SearchTT);
    search.setLayoutData(new GridData());
    search.setEnabled(false);
    AutoCompleteUIHelper.handleSelectEvent(search, acw);
    // ( ) Add  (*) Replace   [ ] Reg.Exp.
    final Button result_append = new Button(parent, SWT.RADIO);
    result_append.setText(Messages.AppendSearchResults);
    result_append.setToolTipText(Messages.AppendSearchResultsTT);
    result_append.setLayoutData(new GridData());
    result_replace = new Button(parent, SWT.RADIO);
    result_replace.setText(Messages.ReplaceSearchResults);
    result_replace.setToolTipText(Messages.ReplaceSearchResultsTT);
    result_replace.setLayoutData(new GridData(SWT.LEFT, 0, true, false));
    result_replace.setSelection(true);
    regex = new Button(parent, SWT.CHECK);
    regex.setText(Messages.RegularExpression);
    regex.setToolTipText(Messages.RegularExpressionTT);
    regex.setLayoutData(new GridData());
    // Table for channel names, displaying array of ChannelInfo entries
    // TableColumnLayout requires table in its own composite
    final Composite table_parent = new Composite(parent, 0);
    final TableColumnLayout table_layout = new MinSizeTableColumnLayout(10);
    table_parent.setLayout(table_layout);
    table_parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));
    channel_table = new TableViewer(table_parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    channel_table.setContentProvider(new ArrayContentProvider());
    TableViewerColumn col = TableHelper.createColumn(table_layout, channel_table, Messages.PVName, 200, 100);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ChannelInfo channel = (ChannelInfo) cell.getElement();
            cell.setText(channel.getProcessVariable().getName());
        }
    });
    new TableColumnSortHelper<ChannelInfo>(channel_table, col) {

        @Override
        public int compare(final ChannelInfo item1, final ChannelInfo item2) {
            return item1.getProcessVariable().getName().compareTo(item2.getProcessVariable().getName());
        }
    };
    col = TableHelper.createColumn(table_layout, channel_table, Messages.ArchiveName, 50, 100);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ChannelInfo channel = (ChannelInfo) cell.getElement();
            cell.setText(channel.getArchiveDataSource().getName());
        }
    });
    new TableColumnSortHelper<ChannelInfo>(channel_table, col) {

        @Override
        public int compare(final ChannelInfo item1, final ChannelInfo item2) {
            return item1.getArchiveDataSource().getName().compareTo(item2.getArchiveDataSource().getName());
        }
    };
    final Table table = channel_table.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    // searchForChannels() relies on non-null content
    channel_table.setInput(new ChannelInfo[0]);
    // Restore settings from memento
    if (memento != null) {
        if (memento.getBoolean(TAG_REGEX) != null)
            regex.setSelection(memento.getBoolean(TAG_REGEX));
        if (memento.getBoolean(TAG_REPLACE) != null) {
            final boolean replace = memento.getBoolean(TAG_REPLACE);
            result_append.setSelection(!replace);
            result_replace.setSelection(replace);
        }
    }
}
Also used : MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Listener(org.eclipse.swt.widgets.Listener) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridLayout(org.eclipse.swt.layout.GridLayout) MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) AutoCompleteWidget(org.csstudio.autocomplete.ui.AutoCompleteWidget) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableColumnSortHelper(org.csstudio.apputil.ui.swt.TableColumnSortHelper) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider)

Example 12 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project org.csstudio.display.builder by kasemir.

the class TraceTableHandler method createColumns.

/**
 * Create table columns: Auto-sizable, with label provider and editor
 *  @param table_layout
 *  @param operations_manager
 *  @param table_viewer
 */
public void createColumns(final TableColumnLayout table_layout, final UndoableActionManager operations_manager, final TableViewer table_viewer) {
    color_registry = new LocalResourceManager(JFaceResources.getResources(), table_viewer.getTable());
    final Shell shell = table_viewer.getTable().getShell();
    // Visible Column ----------
    TableViewerColumn view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.TraceVisibility, 45, 1);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setImage(item.isVisible() ? Activator.getDefault().getImage(Activator.ICON_CHECKED) : Activator.getDefault().getImage(Activator.ICON_UNCHECKED));
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.TraceVisibilityTT;
        }
    });
    new TableColumnSortHelper<ModelItem>(table_viewer, view_col) {

        @Override
        public int compare(final ModelItem item1, final ModelItem item2) {
            final int v1 = item1.isVisible() ? 1 : 0;
            final int v2 = item2.isVisible() ? 1 : 0;
            final int cmp = v1 - v2;
            if (cmp != 0)
                return cmp;
            return item1.getName().compareTo(item2.getName());
        }
    };
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            editing = true;
            return new CheckboxCellEditor(((TableViewer) getViewer()).getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((ModelItem) element).isVisible();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final ModelItem item = (ModelItem) element;
            final boolean visible = ((Boolean) value).booleanValue();
            if (!visible && prompt_for_not_visible) {
                if (!MessageDialog.openQuestion(shell, Messages.HideTraceWarning, Messages.HideTraceWarningDetail))
                    return;
                prompt_for_not_visible = false;
            }
            new ChangeVisibilityCommand(operations_manager, item, visible);
            editing = false;
        }
    });
    // Trace PV/Formula Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.ItemName, 70, 70);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(item.getName());
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.ItemNameTT;
        }
    });
    new TableColumnSortHelper<ModelItem>(table_viewer, view_col) {

        @Override
        public int compare(final ModelItem item1, final ModelItem item2) {
            return item1.getName().compareTo(item2.getName());
        }
    };
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected Object getValue(final Object element) {
            return ((ModelItem) element).getName();
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final String new_name = value.toString().trim();
            final ModelItem item = (ModelItem) element;
            if (new_name.equals(item.getName()))
                return;
            new ChangeNameCommand(shell, operations_manager, item, new_name);
            editing = false;
        }
    });
    // Display Name Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.TraceDisplayName, 70, 70);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(item.getDisplayName());
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.TraceDisplayNameTT;
        }
    });
    new TableColumnSortHelper<ModelItem>(table_viewer, view_col) {

        @Override
        public int compare(final ModelItem item1, final ModelItem item2) {
            return item1.getDisplayName().compareTo(item2.getDisplayName());
        }
    };
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected Object getValue(final Object element) {
            return ((ModelItem) element).getDisplayName();
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final String new_name = value.toString().trim();
            final ModelItem item = (ModelItem) element;
            if (new_name.equals(item.getDisplayName()))
                return;
            new ChangeDisplayNameCommand(operations_manager, item, new_name);
            editing = false;
        }
    });
    // Color Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.Color, 40, 10);
    view_col.setLabelProvider(new ColorCellLabelProvider<ModelItem>() {

        @Override
        protected Color getColor(ModelItem item) {
            return color_registry.createColor(SWTMediaPool.getRGB(item.getPaintColor()));
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            editing = true;
            return new RGBCellEditor(table_viewer.getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((ModelItem) element).getRGBColor();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            new ChangeColorCommand(operations_manager, (ModelItem) element, SWTMediaPool.getJFX((RGB) value));
            editing = false;
        }
    });
    // Selected sample time stamp and value
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.CursorTimestamp, 150, 30);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            final Optional<PlotDataItem<Instant>> sample = item.getSelectedSample();
            if (sample.isPresent())
                cell.setText(TimeHelper.format(sample.get().getPosition()));
            else
                cell.setText(Messages.NotApplicable);
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.CursorTimestampTT;
        }
    });
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.CursorValue, 40, 30);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            final Optional<PlotDataItem<Instant>> sample = item.getSelectedSample();
            if (sample.isPresent()) {
                final PlotSample plot_sample = (PlotSample) sample.get();
                String text = DefaultVTypeFormat.get().format(plot_sample.getVType());
                final String units = item.getUnits();
                if (units != null)
                    // $NON-NLS-1$
                    text += " " + units;
                cell.setText(text);
            } else
                cell.setText(Messages.NotApplicable);
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.CursorValueTT;
        }
    });
    // Scan Period Column (only applies to PVItems) ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.ScanPeriod, 70, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            if (item instanceof PVItem)
                cell.setText(Double.toString(((PVItem) item).getScanPeriod()));
            else
                cell.setText(Messages.NotApplicable);
        }

        @Override
        public String getToolTipText(final Object element) {
            if (!(element instanceof PVItem))
                return null;
            return Messages.ScanPeriodTT;
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

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

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected Object getValue(final Object element) {
            if (element instanceof PVItem)
                return Double.toString(((PVItem) element).getScanPeriod());
            else
                return Messages.NotApplicable;
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            if (!(element instanceof PVItem))
                return;
            final PVItem pv = (PVItem) element;
            try {
                final double period = Double.parseDouble(value.toString().trim());
                if (period != pv.getScanPeriod())
                    new ChangeSamplePeriodCommand(shell, operations_manager, pv, period);
                editing = false;
            } catch (NumberFormatException ex) {
                // Display will revert to original value
                return;
            }
        }
    });
    // Buffer size Column (only applies to PVItems) ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.LiveSampleBufferSize, 70, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            if (item instanceof PVItem)
                cell.setText(Integer.toString(((PVItem) item).getLiveCapacity()));
            else
                cell.setText(Messages.NotApplicable);
        }

        @Override
        public String getToolTipText(final Object element) {
            if (!(element instanceof PVItem))
                return null;
            final PVItem pv = (PVItem) element;
            return NLS.bind(Messages.LiveBufferSizeInfoFmt, pv.getLiveCapacity(), new RelativeTime(pv.getLiveCapacity()).toString());
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

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

        @Override
        protected Object getValue(final Object element) {
            if (element instanceof PVItem)
                return Integer.toString(((PVItem) element).getLiveCapacity());
            else
                return Messages.NotApplicable;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            if (!(element instanceof PVItem))
                return;
            final PVItem pv = (PVItem) element;
            try {
                final int size = Integer.parseInt(value.toString().trim());
                if (size != pv.getLiveCapacity())
                    new ChangeLiveCapacityCommand(shell, operations_manager, pv, size);
                editing = false;
            } catch (NumberFormatException ex) {
                // Display will revert to original value
                return;
            }
        }
    });
    // Axis Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.Axis, 60, 30);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(item.getAxis().getName());
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.AxisTT;
        }
    });
    new TableColumnSortHelper<ModelItem>(table_viewer, view_col) {

        @Override
        public int compare(final ModelItem item1, final ModelItem item2) {
            final int cmp = item1.getAxis().getName().compareTo(item2.getAxis().getName());
            if (cmp != 0)
                return cmp;
            return item1.getDisplayName().compareTo(item2.getDisplayName());
        }
    };
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        // Thread-safe copy of model axes as this editor is invoked
        final List<AxisConfig> axes = new ArrayList<>();

        @Override
        protected CellEditor getCellEditor(final Object element) {
            editing = true;
            final List<String> axis_names = new ArrayList<>();
            axes.clear();
            for (AxisConfig axis : model.getAxes()) {
                axes.add(axis);
                axis_names.add(axis.getName());
            }
            final ComboBoxCellEditor combo = new ComboBoxCellEditor(table_viewer.getTable(), axis_names.toArray(new String[axis_names.size()]), SWT.READ_ONLY);
            combo.setValue(getValue(element));
            return combo;
        }

        @Override
        protected Object getValue(final Object element) {
            return model.getAxisIndex(((ModelItem) element).getAxis());
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final int axis_index = ((Integer) value).intValue();
            final AxisConfig axis = axes.get(axis_index);
            final ModelItem item = (ModelItem) element;
            if (axis != item.getAxis())
                new ChangeAxisCommand(operations_manager, item, axis);
            editing = false;
        }
    });
    // Trace Type Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.TraceType, 75, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(item.getTraceType().toString());
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.TraceTypeTT;
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            editing = true;
            final ComboBoxCellEditor combo = new ComboBoxCellEditor(table_viewer.getTable(), TraceType.getDisplayNames(), SWT.READ_ONLY);
            combo.setValue(getValue(element));
            return combo;
        }

        @Override
        protected Object getValue(final Object element) {
            return ((ModelItem) element).getTraceType().ordinal();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final TraceType trace_type = TraceType.values()[(((Integer) value).intValue())];
            final ModelItem item = (ModelItem) element;
            if (trace_type != item.getTraceType())
                new ChangeTraceTypeCommand(operations_manager, item, trace_type);
            editing = false;
        }
    });
    // Line Width Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.TraceLineWidth, 40, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(Integer.toString(item.getLineWidth()));
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.TraceLineWidthTT;
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected Object getValue(final Object element) {
            return Integer.toString(((ModelItem) element).getLineWidth());
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            int width;
            try {
                width = Integer.parseInt(value.toString().trim());
            } catch (NumberFormatException ex) {
                width = 0;
            }
            final ModelItem item = (ModelItem) element;
            if (width != item.getLineWidth())
                new ChangeLineWidthCommand(operations_manager, item, width);
            editing = false;
        }
    });
    // Point Type Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.PointType, 75, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(item.getPointType().toString());
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.PointTypeTT;
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            editing = true;
            final ComboBoxCellEditor combo = new ComboBoxCellEditor(table_viewer.getTable(), PointType.getDisplayNames(), SWT.READ_ONLY);
            combo.setValue(getValue(element));
            return combo;
        }

        @Override
        protected Object getValue(final Object element) {
            return ((ModelItem) element).getPointType().ordinal();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final PointType point_type = PointType.values()[((Integer) value).intValue()];
            final ModelItem item = (ModelItem) element;
            if (point_type != item.getPointType())
                new ChangePointTypeCommand(operations_manager, item, point_type);
            editing = false;
        }
    });
    // Point Size Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.PointSize, 40, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(Integer.toString(item.getPointSize()));
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.PointSizeTT;
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected Object getValue(final Object element) {
            return Integer.toString(((ModelItem) element).getPointSize());
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            int size;
            try {
                size = Integer.parseInt(value.toString().trim());
            } catch (NumberFormatException ex) {
                size = 0;
            }
            final ModelItem item = (ModelItem) element;
            if (size != item.getPointSize())
                new ChangePointSizeCommand(operations_manager, item, size);
            editing = false;
        }
    });
    // Request Type Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.RequestType, 75, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            if (item instanceof PVItem)
                cell.setText(((PVItem) item).getRequestType().toString());
            else
                cell.setText(Messages.NotApplicable);
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.RequestTypeTT;
        }
    });
    // Edit as boolean: Raw == false,  Optimized == true
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected boolean canEdit(final Object element) {
            return element instanceof PVItem;
        }

        @Override
        protected CellEditor getCellEditor(final Object element) {
            editing = true;
            return new CheckboxCellEditor(((TableViewer) getViewer()).getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((PVItem) element).getRequestType() == RequestType.OPTIMIZED;
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final PVItem item = (PVItem) element;
            final RequestType request_type = ((Boolean) value).booleanValue() ? RequestType.OPTIMIZED : RequestType.RAW;
            if (request_type == RequestType.RAW && prompt_for_raw_data_request) {
                if (!MessageDialog.openQuestion(shell, Messages.RequestTypeWarning, Messages.RequestTypeWarningDetail))
                    return;
                prompt_for_raw_data_request = false;
            }
            new ChangeRequestTypeCommand(operations_manager, item, request_type);
            editing = false;
        }
    });
    // Waveform Index Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.WaveformIndexCol, 40, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(Integer.toString(item.getWaveformIndex()));
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.WaveformIndexColTT;
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected Object getValue(final Object element) {
            return Integer.toString(((ModelItem) element).getWaveformIndex());
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            int index;
            try {
                index = Integer.parseInt(value.toString().trim());
                if (index < 0)
                    return;
                final ModelItem item = (ModelItem) element;
                if (index != item.getWaveformIndex())
                    new ChangeWaveformIndexCommand(operations_manager, item, index);
            } catch (NumberFormatException ex) {
                return;
            } finally {
                editing = false;
            }
        }
    });
    ColumnViewerToolTipSupport.enableFor(table_viewer);
}
Also used : CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) ArrayList(java.util.ArrayList) RelativeTime(org.csstudio.apputil.time.RelativeTime) Shell(org.eclipse.swt.widgets.Shell) ArrayList(java.util.ArrayList) List(java.util.List) TableColumnSortHelper(org.csstudio.apputil.ui.swt.TableColumnSortHelper) PVItem(org.csstudio.trends.databrowser3.model.PVItem) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) TraceType(org.csstudio.javafx.rtplot.TraceType) Optional(java.util.Optional) Color(org.eclipse.swt.graphics.Color) Instant(java.time.Instant) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) ViewerCell(org.eclipse.jface.viewers.ViewerCell) PlotSample(org.csstudio.trends.databrowser3.model.PlotSample) PointType(org.csstudio.javafx.rtplot.PointType) TableViewer(org.eclipse.jface.viewers.TableViewer) RequestType(org.csstudio.trends.databrowser3.model.RequestType)

Example 13 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project org.csstudio.display.builder by kasemir.

the class AxesTableHandler method createColumns.

/**
 * Create table columns: Auto-sizable, with label provider and editor
 *  @param table_layout
 */
private void createColumns(TableColumnLayout table_layout) {
    TableViewerColumn col;
    // Visible? Column ----------
    col = TableHelper.createColumn(table_layout, axes_table, Messages.AxisVisibility, 45, 10);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final AxisConfig axis = (AxisConfig) cell.getElement();
            if (axis.isVisible())
                cell.setImage(Activator.getDefault().getImage(Activator.ICON_CHECKED));
            else
                cell.setImage(Activator.getDefault().getImage(Activator.ICON_UNCHECKED));
        }
    });
    col.setEditingSupport(new EditSupportBase(axes_table) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            return new CheckboxCellEditor(((TableViewer) getViewer()).getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((AxisConfig) element).isVisible();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final AxisConfig axis = (AxisConfig) element;
            final ChangeAxisConfigCommand command = new ChangeAxisConfigCommand(operations_manager, axis);
            axis.setVisible(((Boolean) value).booleanValue());
            command.rememberNewConfig();
        }
    });
    // Axis Name Column ----------
    col = TableHelper.createColumn(table_layout, axes_table, Messages.ValueAxisName, 100, 100);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final AxisConfig axis = (AxisConfig) cell.getElement();
            cell.setText(axis.getName());
        }
    });
    col.setEditingSupport(new EditSupportBase(axes_table) {

        @Override
        protected Object getValue(final Object element) {
            return ((AxisConfig) element).getName();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final AxisConfig axis = (AxisConfig) element;
            final String name = value.toString().trim();
            if (name.equals(axis.getName()))
                return;
            final ChangeAxisConfigCommand config = new ChangeAxisConfigCommand(operations_manager, axis);
            axis.setName(name);
            config.rememberNewConfig();
        }
    });
    // Use Axis Name ----------
    col = TableHelper.createColumn(table_layout, axes_table, Messages.UseAxisName, 95, 10);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final AxisConfig axis = (AxisConfig) cell.getElement();
            if (axis.isUsingAxisName())
                cell.setImage(Activator.getDefault().getImage(Activator.ICON_CHECKED));
            else
                cell.setImage(Activator.getDefault().getImage(Activator.ICON_UNCHECKED));
        }
    });
    col.setEditingSupport(new EditSupportBase(axes_table) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            return new CheckboxCellEditor(((TableViewer) getViewer()).getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((AxisConfig) element).isUsingAxisName();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final AxisConfig axis = (AxisConfig) element;
            final ChangeAxisConfigCommand command = new ChangeAxisConfigCommand(operations_manager, axis);
            axis.useAxisName(((Boolean) value).booleanValue());
            command.rememberNewConfig();
        }
    });
    // Use Trace Names ----------
    col = TableHelper.createColumn(table_layout, axes_table, Messages.UseTraceNames, 110, 10);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final AxisConfig axis = (AxisConfig) cell.getElement();
            if (axis.isUsingTraceNames())
                cell.setImage(Activator.getDefault().getImage(Activator.ICON_CHECKED));
            else
                cell.setImage(Activator.getDefault().getImage(Activator.ICON_UNCHECKED));
        }
    });
    col.setEditingSupport(new EditSupportBase(axes_table) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            return new CheckboxCellEditor(((TableViewer) getViewer()).getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((AxisConfig) element).isUsingTraceNames();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final AxisConfig axis = (AxisConfig) element;
            final ChangeAxisConfigCommand command = new ChangeAxisConfigCommand(operations_manager, axis);
            axis.useTraceNames(((Boolean) value).booleanValue());
            command.rememberNewConfig();
        }
    });
    // Show Grid? ----------
    col = TableHelper.createColumn(table_layout, axes_table, Messages.Grid, 50, 5);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final AxisConfig axis = (AxisConfig) cell.getElement();
            if (axis.isGridVisible())
                cell.setImage(Activator.getDefault().getImage(Activator.ICON_CHECKED));
            else
                cell.setImage(Activator.getDefault().getImage(Activator.ICON_UNCHECKED));
        }
    });
    col.setEditingSupport(new EditSupportBase(axes_table) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            return new CheckboxCellEditor(((TableViewer) getViewer()).getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((AxisConfig) element).isGridVisible();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final AxisConfig axis = (AxisConfig) element;
            final ChangeAxisConfigCommand command = new ChangeAxisConfigCommand(operations_manager, axis);
            axis.setGridVisible(((Boolean) value).booleanValue());
            command.rememberNewConfig();
        }
    });
    // Use Right Side? ----------
    col = TableHelper.createColumn(table_layout, axes_table, Messages.AxisOnRight, 80, 10);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final AxisConfig axis = (AxisConfig) cell.getElement();
            if (axis.isOnRight())
                cell.setImage(Activator.getDefault().getImage(Activator.ICON_CHECKED));
            else
                cell.setImage(Activator.getDefault().getImage(Activator.ICON_UNCHECKED));
        }
    });
    col.setEditingSupport(new EditSupportBase(axes_table) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            return new CheckboxCellEditor(((TableViewer) getViewer()).getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((AxisConfig) element).isOnRight();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final AxisConfig axis = (AxisConfig) element;
            final ChangeAxisConfigCommand command = new ChangeAxisConfigCommand(operations_manager, axis);
            axis.setOnRight(((Boolean) value).booleanValue());
            command.rememberNewConfig();
        }
    });
    // Color Column ----------
    col = TableHelper.createColumn(table_layout, axes_table, Messages.Color, 40, 5);
    col.setLabelProvider(new ColorCellLabelProvider<AxisConfig>() {

        @Override
        protected Color getColor(final AxisConfig axis) {
            return color_registry.createColor(axis.getRGBColor());
        }
    });
    col.setEditingSupport(new EditSupportBase(axes_table) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            return new RGBCellEditor(axes_table.getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((AxisConfig) element).getRGBColor();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final AxisConfig axis = (AxisConfig) element;
            final ChangeAxisConfigCommand command = new ChangeAxisConfigCommand(operations_manager, axis);
            axis.setColor((RGB) value);
            command.rememberNewConfig();
        }
    });
    // Minimum value Column ----------
    col = TableHelper.createColumn(table_layout, axes_table, Messages.AxisMin, 70, 50);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final AxisConfig axis = (AxisConfig) cell.getElement();
            cell.setText(Double.toString(axis.getMin()));
        }
    });
    col.setEditingSupport(new EditSupportBase(axes_table) {

        @Override
        protected Object getValue(final Object element) {
            return Double.toString(((AxisConfig) element).getMin());
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            try {
                final AxisConfig axis = (AxisConfig) element;
                final double limit = Double.parseDouble(value.toString().trim());
                if (limit == axis.getMin())
                    return;
                final ChangeAxisConfigCommand command = new ChangeAxisConfigCommand(operations_manager, axis);
                axis.setRange(limit, axis.getMax());
                command.rememberNewConfig();
            } catch (NumberFormatException ex) {
            // NOP, leave as is
            }
        }
    });
    // Maximum value Column ----------
    col = TableHelper.createColumn(table_layout, axes_table, Messages.AxisMax, 70, 50);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final AxisConfig axis = (AxisConfig) cell.getElement();
            cell.setText(Double.toString(axis.getMax()));
        }
    });
    col.setEditingSupport(new EditSupportBase(axes_table) {

        @Override
        protected Object getValue(final Object element) {
            return Double.toString(((AxisConfig) element).getMax());
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            try {
                final AxisConfig axis = (AxisConfig) element;
                final double limit = Double.parseDouble(value.toString().trim());
                if (limit == axis.getMax())
                    return;
                final ChangeAxisConfigCommand command = new ChangeAxisConfigCommand(operations_manager, axis);
                axis.setRange(axis.getMin(), limit);
                command.rememberNewConfig();
            } catch (NumberFormatException ex) {
            // NOP, leave as is
            }
        }
    });
    // Auto scale Column ----------
    col = TableHelper.createColumn(table_layout, axes_table, Messages.AutoScale, 80, 10);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final AxisConfig axis = (AxisConfig) cell.getElement();
            if (axis.isAutoScale())
                cell.setImage(Activator.getDefault().getImage(Activator.ICON_CHECKED));
            else
                cell.setImage(Activator.getDefault().getImage(Activator.ICON_UNCHECKED));
        }
    });
    col.setEditingSupport(new EditSupportBase(axes_table) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            return new CheckboxCellEditor(((TableViewer) getViewer()).getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((AxisConfig) element).isAutoScale();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final AxisConfig axis = (AxisConfig) element;
            final ChangeAxisConfigCommand command = new ChangeAxisConfigCommand(operations_manager, axis);
            axis.setAutoScale(((Boolean) value).booleanValue());
            command.rememberNewConfig();
        }
    });
    // Log scale Column ----------
    col = TableHelper.createColumn(table_layout, axes_table, Messages.LinLogScaleType, 80, 10);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final AxisConfig axis = (AxisConfig) cell.getElement();
            if (axis.isLogScale())
                cell.setText(Messages.LogScale);
            else
                cell.setText(Messages.LinacScale);
        }
    });
    col.setEditingSupport(new EditSupportBase(axes_table) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            return new CheckboxCellEditor(((TableViewer) getViewer()).getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((AxisConfig) element).isLogScale();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final AxisConfig axis = (AxisConfig) element;
            final ChangeAxisConfigCommand command = new ChangeAxisConfigCommand(operations_manager, axis);
            axis.setLogScale(((Boolean) value).booleanValue());
            command.rememberNewConfig();
        }
    });
}
Also used : CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) Color(org.eclipse.swt.graphics.Color) RGB(org.eclipse.swt.graphics.RGB) ViewerCell(org.eclipse.jface.viewers.ViewerCell) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider)

Example 14 with ViewerCell

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

the class CommitGraphTableHoverManager method computeInformation.

@Override
protected void computeInformation() {
    MouseEvent e = getHoverEvent();
    Information information = null;
    ViewerCell cell = tableViewer.getCell(new Point(e.x, e.y));
    if (cell != null) {
        SWTCommit commit = (SWTCommit) cell.getElement();
        if (commit != null)
            information = computeInformationForCommit(commit, cell, e);
    }
    // computeInformation must setInformation in all cases
    if (information != null)
        setInformation(information.information, information.subjectArea);
    else
        setInformation(null, null);
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Point(org.eclipse.swt.graphics.Point) ViewerCell(org.eclipse.jface.viewers.ViewerCell)

Example 15 with ViewerCell

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

the class StagingViewTooltips method isSelected.

private boolean isSelected(Event event) {
    ViewerCell currentCell = getToolTipArea(event);
    if (currentCell == null) {
        return false;
    }
    Object item = currentCell.getElement();
    if (!(item instanceof StagingEntry) && !(item instanceof StagingFolderEntry)) {
        return false;
    }
    ISelection selection = viewer.getSelection();
    if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
        return false;
    }
    Iterator<?> selectedObjects = ((IStructuredSelection) selection).iterator();
    while (selectedObjects.hasNext()) {
        if (item == selectedObjects.next()) {
            return true;
        }
    }
    return false;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ViewerCell(org.eclipse.jface.viewers.ViewerCell)

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