Search in sources :

Example 1 with AutoCompleteWidget

use of org.csstudio.autocomplete.ui.AutoCompleteWidget 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 2 with AutoCompleteWidget

use of org.csstudio.autocomplete.ui.AutoCompleteWidget in project org.csstudio.display.builder by kasemir.

the class AddPVDialog method createDialogArea.

/**
 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
 */
@Override
protected Control createDialogArea(final Composite parent_widget) {
    final Composite parent_composite = (Composite) super.createDialogArea(parent_widget);
    // Title & Image
    setTitle(formula ? Messages.AddFormula : Messages.AddPV);
    setMessage(formula ? Messages.AddFormulaMsg : Messages.AddPVMsg);
    // $NON-NLS-1$
    setTitleImage(Activator.getDefault().getImage("icons/config_image.png"));
    // Scroll pane for the box
    final ScrolledComposite scroll = new ScrolledComposite(parent_composite, SWT.H_SCROLL | SWT.V_SCROLL);
    scroll.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    scroll.setExpandHorizontal(true);
    scroll.setExpandVertical(true);
    scroll.setLayout(new FillLayout());
    // Create box for widgets we're about to add
    final Composite box = new Composite(scroll, 0);
    box.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    final GridLayout layout = new GridLayout(3, false);
    box.setLayout(layout);
    final ModifyListener update_on_modify = (e) -> updateAndValidate();
    for (int i = 0; i < name.length; ++i) {
        if (i > 0) {
            Label sep = new Label(box, SWT.SEPARATOR | SWT.HORIZONTAL);
            sep.setLayoutData(new GridData(SWT.FILL, 0, true, false, layout.numColumns, 1));
        }
        // PV Name              : _____________________
        Label l = new Label(box, 0);
        l.setText(Messages.Name);
        l.setLayoutData(new GridData());
        txt_name[i] = new Text(box, SWT.BORDER);
        txt_name[i].setToolTipText(formula ? Messages.AddFormula_NameTT : Messages.AddPV_NameTT);
        txt_name[i].setLayoutData(new GridData(SWT.FILL, 0, true, false, layout.numColumns - 1, 1));
        autoCompleteWidget[i] = new AutoCompleteWidget(txt_name[i], AutoCompleteTypes.PV);
        if (!formula) {
            // Scan Period [seconds]: _____   [x] on change
            l = new Label(box, 0);
            l.setText(Messages.AddPV_Period);
            l.setLayoutData(new GridData());
            txt_period[i] = new Text(box, SWT.BORDER);
            txt_period[i].setToolTipText(Messages.AddPV_PeriodTT);
            txt_period[i].setLayoutData(new GridData(SWT.FILL, 0, true, false));
            btn_monitor[i] = new Button(box, SWT.CHECK);
            btn_monitor[i].setText(Messages.AddPV_OnChange);
            btn_monitor[i].setToolTipText(Messages.AddPV_OnChangeTT);
            btn_monitor[i].setLayoutData(new GridData());
            // Initialize to default period
            final double period = Preferences.getScanPeriod();
            if (period > 0.0)
                txt_period[i].setText(Double.toString(period));
            else {
                // 'monitor'
                // $NON-NLS-1$
                txt_period[i].setText("1.0");
                txt_period[i].setEnabled(false);
                btn_monitor[i].setSelection(true);
            }
            // Hook listener after initial value has been set
            txt_period[i].addModifyListener(update_on_modify);
            // In 'monitor' mode, the period entry is disabled
            final int index = i;
            btn_monitor[i].addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    txt_period[index].setEnabled(!btn_monitor[index].getSelection());
                    updateAndValidate();
                }
            });
        }
        // Value Axis:            _____
        // If there are axes to select, add related GUI
        l = new Label(box, 0);
        l.setText(Messages.AddPV_Axis);
        l.setLayoutData(new GridData());
        axis[i] = new Combo(box, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
        axis[i].setToolTipText(Messages.AddPV_AxisTT);
        axis[i].setLayoutData(new GridData(SWT.FILL, 0, true, false));
        // First entry is 'new axis', rest actual axis names
        axis[i].add(Messages.AddPV_NewOrEmptyAxis);
        for (String name : axes) axis[i].add(name);
        // Suggest multiple PVs are all placed on the same axis, the last one
        if (name.length > 1) {
            axis[i].select(axes.size());
            axis_index[i] = axes.size() - 1;
        } else {
            axis[i].select(0);
            axis_index[i] = -1;
        }
        // Empty label to fill last column
        l = new Label(box, 0);
        l.setLayoutData(new GridData());
        // Set initial text
        if (name[i] != null)
            txt_name[i].setText(name[i]);
        // and _then_ connect modify listener so it's not called for initial text
        txt_name[i].addModifyListener(update_on_modify);
    }
    scroll.setContent(box);
    scroll.setMinSize(box.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    // Perform initial validation
    updateAndValidate();
    return parent_composite;
}
Also used : Preferences(org.csstudio.trends.databrowser3.preferences.Preferences) ArrayList(java.util.ArrayList) AutoCompleteTypes(org.csstudio.autocomplete.ui.AutoCompleteTypes) HashSet(java.util.HashSet) IMessageProvider(org.eclipse.jface.dialogs.IMessageProvider) Messages(org.csstudio.trends.databrowser3.Messages) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Model(org.csstudio.trends.databrowser3.model.Model) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) NLS(org.eclipse.osgi.util.NLS) Set(java.util.Set) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) List(java.util.List) AutoCompleteWidget(org.csstudio.autocomplete.ui.AutoCompleteWidget) TitleAreaDialog(org.eclipse.jface.dialogs.TitleAreaDialog) ModifyListener(org.eclipse.swt.events.ModifyListener) SWT(org.eclipse.swt.SWT) Activator(org.csstudio.trends.databrowser3.Activator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) FillLayout(org.eclipse.swt.layout.FillLayout) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) AutoCompleteWidget(org.csstudio.autocomplete.ui.AutoCompleteWidget) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite)

Aggregations

AutoCompleteWidget (org.csstudio.autocomplete.ui.AutoCompleteWidget)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 Text (org.eclipse.swt.widgets.Text)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 TableColumnSortHelper (org.csstudio.apputil.ui.swt.TableColumnSortHelper)1 AutoCompleteTypes (org.csstudio.autocomplete.ui.AutoCompleteTypes)1 Activator (org.csstudio.trends.databrowser3.Activator)1 Messages (org.csstudio.trends.databrowser3.Messages)1 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)1 ChannelInfo (org.csstudio.trends.databrowser3.model.ChannelInfo)1 Model (org.csstudio.trends.databrowser3.model.Model)1 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)1