Search in sources :

Example 1 with ContentAssistCommandAdapter

use of org.eclipse.ui.fieldassist.ContentAssistCommandAdapter in project eclipse.platform.text by eclipse.

the class ReplaceConfigurationPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite result = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    result.setLayout(layout);
    Label description = new Label(result, SWT.NONE);
    int numberOfMatches = fReplaceRefactoring.getNumberOfMatches();
    int numberOfFiles = fReplaceRefactoring.getNumberOfFiles();
    String[] arguments = { String.valueOf(numberOfMatches), String.valueOf(numberOfFiles) };
    if (numberOfMatches > 1 && numberOfFiles > 1) {
        description.setText(Messages.format(SearchMessages.ReplaceConfigurationPage_description_many_in_many, arguments));
    } else if (numberOfMatches == 1) {
        description.setText(SearchMessages.ReplaceConfigurationPage_description_one_in_one);
    } else {
        description.setText(Messages.format(SearchMessages.ReplaceConfigurationPage_description_many_in_one, arguments));
    }
    description.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 2, 1));
    FileSearchQuery query = fReplaceRefactoring.getQuery();
    Label label1 = new Label(result, SWT.NONE);
    label1.setText(SearchMessages.ReplaceConfigurationPage_replace_label);
    Text clabel = new Text(result, SWT.BORDER | SWT.READ_ONLY);
    clabel.setText(query.getSearchString());
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = convertWidthInCharsToPixels(50);
    clabel.setLayoutData(gd);
    Label label2 = new Label(result, SWT.NONE);
    label2.setText(SearchMessages.ReplaceConfigurationPage_with_label);
    fTextField = new Combo(result, SWT.DROP_DOWN);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = convertWidthInCharsToPixels(50);
    fTextField.setLayoutData(gd);
    fTextField.setFocus();
    fTextField.addModifyListener(e -> updateOKStatus());
    IDialogSettings settings = SearchPlugin.getDefault().getDialogSettings().getSection(SETTINGS_GROUP);
    if (settings != null) {
        String[] previousReplaceWith = settings.getArray(SETTINGS_REPLACE_WITH);
        if (previousReplaceWith != null) {
            fTextField.setItems(previousReplaceWith);
            fTextField.select(0);
        }
    }
    ComboContentAdapter contentAdapter = new ComboContentAdapter();
    FindReplaceDocumentAdapterContentProposalProvider replaceProposer = new FindReplaceDocumentAdapterContentProposalProvider(false);
    fTextFieldContentAssist = new ContentAssistCommandAdapter(fTextField, contentAdapter, replaceProposer, ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[0], true);
    new Label(result, SWT.NONE);
    fReplaceWithRegex = new Button(result, SWT.CHECK);
    fReplaceWithRegex.setText(SearchMessages.ReplaceConfigurationPage_isRegex_label);
    fReplaceWithRegex.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setContentAssistsEnablement(fReplaceWithRegex.getSelection());
        }
    });
    if (query.isRegexSearch()) {
        fReplaceWithRegex.setSelection(true);
    } else {
        fReplaceWithRegex.setSelection(false);
        fReplaceWithRegex.setEnabled(false);
    }
    fStatusLabel = new Label(result, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.verticalAlignment = SWT.BOTTOM;
    gd.horizontalSpan = 2;
    fStatusLabel.setLayoutData(gd);
    setContentAssistsEnablement(fReplaceWithRegex.getSelection());
    setControl(result);
    Dialog.applyDialogFont(result);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), ISearchHelpContextIds.REPLACE_DIALOG);
}
Also used : ComboContentAdapter(org.eclipse.jface.fieldassist.ComboContentAdapter) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) FindReplaceDocumentAdapterContentProposalProvider(org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider) GridLayout(org.eclipse.swt.layout.GridLayout) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ContentAssistCommandAdapter(org.eclipse.ui.fieldassist.ContentAssistCommandAdapter)

Example 2 with ContentAssistCommandAdapter

use of org.eclipse.ui.fieldassist.ContentAssistCommandAdapter in project eclipse.platform.text by eclipse.

the class FindReplaceDialog method createInputPanel.

/**
 * Creates the panel where the user specifies the text to search
 * for and the optional replacement text.
 *
 * @param parent the parent composite
 * @return the input panel
 */
private Composite createInputPanel(Composite parent) {
    ModifyListener listener = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            updateButtonState();
        }
    };
    Composite panel = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    panel.setLayout(layout);
    Label findLabel = new Label(panel, SWT.LEFT);
    findLabel.setText(EditorMessages.FindReplace_Find_label);
    setGridData(findLabel, SWT.LEFT, false, SWT.CENTER, false);
    // Create the find content assist field
    ComboContentAdapter contentAdapter = new ComboContentAdapter();
    FindReplaceDocumentAdapterContentProposalProvider findProposer = new FindReplaceDocumentAdapterContentProposalProvider(true);
    fFindField = new Combo(panel, SWT.DROP_DOWN | SWT.BORDER);
    fContentAssistFindField = new ContentAssistCommandAdapter(fFindField, contentAdapter, findProposer, ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[0], true);
    setGridData(fFindField, SWT.FILL, true, SWT.CENTER, false);
    addDecorationMargin(fFindField);
    fFindField.addModifyListener(fFindModifyListener);
    fReplaceLabel = new Label(panel, SWT.LEFT);
    fReplaceLabel.setText(EditorMessages.FindReplace_Replace_label);
    setGridData(fReplaceLabel, SWT.LEFT, false, SWT.CENTER, false);
    // Create the replace content assist field
    FindReplaceDocumentAdapterContentProposalProvider replaceProposer = new FindReplaceDocumentAdapterContentProposalProvider(false);
    fReplaceField = new Combo(panel, SWT.DROP_DOWN | SWT.BORDER);
    fContentAssistReplaceField = new ContentAssistCommandAdapter(fReplaceField, contentAdapter, replaceProposer, ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[0], true);
    setGridData(fReplaceField, SWT.FILL, true, SWT.CENTER, false);
    addDecorationMargin(fReplaceField);
    fReplaceField.addModifyListener(listener);
    return panel;
}
Also used : ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ComboContentAdapter(org.eclipse.jface.fieldassist.ComboContentAdapter) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) ContentAssistCommandAdapter(org.eclipse.ui.fieldassist.ContentAssistCommandAdapter) FindReplaceDocumentAdapterContentProposalProvider(org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider)

Example 3 with ContentAssistCommandAdapter

use of org.eclipse.ui.fieldassist.ContentAssistCommandAdapter in project eclipse.platform.text by eclipse.

the class TextSearchPage method addTextPatternControls.

private void addTextPatternControls(Composite group) {
    // grid layout with 2 columns
    // Info text
    Label label = new Label(group, SWT.LEAD);
    label.setText(SearchMessages.SearchPage_containingText_text);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    label.setFont(group.getFont());
    // Pattern combo
    fPattern = new Combo(group, SWT.SINGLE | SWT.BORDER);
    // Not done here to prevent page from resizing
    // fPattern.setItems(getPreviousSearchPatterns());
    fPattern.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            handleWidgetSelected();
            updateOKStatus();
        }
    });
    // add some listeners for regex syntax checking
    fPattern.addModifyListener(e -> updateOKStatus());
    fPattern.setFont(group.getFont());
    GridData data = new GridData(GridData.FILL, GridData.FILL, true, false, 1, 2);
    data.widthHint = convertWidthInCharsToPixels(50);
    fPattern.setLayoutData(data);
    ComboContentAdapter contentAdapter = new ComboContentAdapter();
    FindReplaceDocumentAdapterContentProposalProvider findProposer = new FindReplaceDocumentAdapterContentProposalProvider(true);
    fPatterFieldContentAssist = new ContentAssistCommandAdapter(fPattern, contentAdapter, findProposer, ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[0], true);
    fPatterFieldContentAssist.setEnabled(fIsRegExSearch);
    fIsCaseSensitiveCheckbox = new Button(group, SWT.CHECK);
    fIsCaseSensitiveCheckbox.setText(SearchMessages.SearchPage_caseSensitive);
    fIsCaseSensitiveCheckbox.setSelection(fIsCaseSensitive);
    fIsCaseSensitiveCheckbox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            fIsCaseSensitive = fIsCaseSensitiveCheckbox.getSelection();
        }
    });
    fIsCaseSensitiveCheckbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    fIsCaseSensitiveCheckbox.setFont(group.getFont());
    // RegEx checkbox
    fIsRegExCheckbox = new Button(group, SWT.CHECK);
    fIsRegExCheckbox.setText(SearchMessages.SearchPage_regularExpression);
    fIsRegExCheckbox.setSelection(fIsRegExSearch);
    fIsRegExCheckbox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            fIsRegExSearch = fIsRegExCheckbox.getSelection();
            updateOKStatus();
            writeConfiguration();
            fPatterFieldContentAssist.setEnabled(fIsRegExSearch);
            fIsWholeWordCheckbox.setEnabled(!fIsRegExSearch);
        }
    });
    fIsRegExCheckbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 2));
    fIsRegExCheckbox.setFont(group.getFont());
    // Text line which explains the special characters
    fStatusLabel = new CLabel(group, SWT.LEAD);
    fStatusLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 2));
    fStatusLabel.setFont(group.getFont());
    fStatusLabel.setAlignment(SWT.LEFT);
    fStatusLabel.setText(SearchMessages.SearchPage_containingText_hint);
    // Whole Word checkbox
    fIsWholeWordCheckbox = new Button(group, SWT.CHECK);
    fIsWholeWordCheckbox.setText(SearchMessages.SearchPage_wholeWord);
    fIsWholeWordCheckbox.setSelection(fIsWholeWord);
    fIsWholeWordCheckbox.setEnabled(!fIsRegExSearch);
    fIsWholeWordCheckbox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            fIsWholeWord = fIsWholeWordCheckbox.getSelection();
        }
    });
    fIsWholeWordCheckbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    fIsWholeWordCheckbox.setFont(group.getFont());
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) ComboContentAdapter(org.eclipse.jface.fieldassist.ComboContentAdapter) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CLabel(org.eclipse.swt.custom.CLabel) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Combo(org.eclipse.swt.widgets.Combo) ContentAssistCommandAdapter(org.eclipse.ui.fieldassist.ContentAssistCommandAdapter) FindReplaceDocumentAdapterContentProposalProvider(org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider)

Aggregations

ComboContentAdapter (org.eclipse.jface.fieldassist.ComboContentAdapter)3 FindReplaceDocumentAdapterContentProposalProvider (org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider)3 Combo (org.eclipse.swt.widgets.Combo)3 Label (org.eclipse.swt.widgets.Label)3 ContentAssistCommandAdapter (org.eclipse.ui.fieldassist.ContentAssistCommandAdapter)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)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 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 CLabel (org.eclipse.swt.custom.CLabel)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 Text (org.eclipse.swt.widgets.Text)1