Search in sources :

Example 1 with KeyStroke

use of org.eclipse.jface.bindings.keys.KeyStroke in project tdi-studio-se by Talend.

the class PigExpressionComposite method createEditorProposal.

/**
     * Creates proposal for editor.
     */
private void createEditorProposal() {
    try {
        // create KeyStroke use Ctrl+Space as default
        KeyStroke keyStroke = HotKeyUtil.getHotKey(HotKeyUtil.contentAssist);
        IControlContentAdapter controlContentAdapter = new StyledTextContentAdapter();
        // TDI-25309 :expression builder UDF autocompletion need add the inputTable node
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IPigMapService.class)) {
            final IPigMapService service = (IPigMapService) GlobalServiceRegister.getDefault().getService(IPigMapService.class);
            ContentProposalAdapterExtended proposalAdaptor = ProposalUtils.getCommonProposal(textControl, service.createExpressionProposalProvider(dataBean));
            new ContentProposalAdapter(textControl, controlContentAdapter, service.createExpressionProposalProvider(dataBean), keyStroke, new char[] { ' ', '.' });
        }
    } catch (Exception e) {
    //
    }
}
Also used : ContentProposalAdapterExtended(org.talend.commons.ui.swt.proposal.ContentProposalAdapterExtended) IControlContentAdapter(org.eclipse.jface.fieldassist.IControlContentAdapter) KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) StyledTextContentAdapter(org.talend.commons.ui.swt.proposal.StyledTextContentAdapter) IPigMapService(org.talend.core.service.IPigMapService) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter)

Example 2 with KeyStroke

use of org.eclipse.jface.bindings.keys.KeyStroke in project tdi-studio-se by Talend.

the class SqlEditDialog method createEditorProposal.

/**
     * Creates proposal for editor.
     */
private void createEditorProposal() {
    try {
        // create KeyStroke use Ctrl+Space as default
        KeyStroke keyStroke = HotKeyUtil.getHotKey(HotKeyUtil.contentAssist);
        IControlContentAdapter controlContentAdapter = new StyledTextContentAdapter();
        IContentProposalProvider contentProposalProvider = new SQLEditorProposalProvider(repositoryNode, language);
        SQLEditorProposalAdapter contentProposalAdapter = new SQLEditorProposalAdapter(colorText, controlContentAdapter, contentProposalProvider, keyStroke, new char[] { ' ', '.' });
        contentProposalAdapter.setPropagateKeys(true);
        contentProposalAdapter.setFilterStyle(ContentProposalAdapter.FILTER_CUMULATIVE);
        contentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
        contentProposalAdapter.setLabelProvider(new SQLEditorLabelProvider());
        contentProposalAdapter.setAutoActivationDelay(10);
        contentProposalAdapter.setPopupSize(new Point(300, 200));
    } catch (Exception e) {
        //$NON-NLS-1$
        SqlBuilderPlugin.log(Messages.getString("SQLBuilderEditorComposite.logMessage"), e);
    }
}
Also used : IContentProposalProvider(org.eclipse.jface.fieldassist.IContentProposalProvider) SQLEditorLabelProvider(org.talend.sqlbuilder.ui.proposal.SQLEditorLabelProvider) SQLEditorProposalAdapter(org.talend.sqlbuilder.ui.proposal.SQLEditorProposalAdapter) IControlContentAdapter(org.eclipse.jface.fieldassist.IControlContentAdapter) KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) StyledTextContentAdapter(org.talend.commons.ui.swt.proposal.StyledTextContentAdapter) Point(org.eclipse.swt.graphics.Point) SQLEditorProposalProvider(org.talend.sqlbuilder.ui.proposal.SQLEditorProposalProvider)

Example 3 with KeyStroke

use of org.eclipse.jface.bindings.keys.KeyStroke in project bndtools by bndtools.

the class GeneralInfoPart method createSection.

private void createSection(Section section, FormToolkit toolkit) {
    section.setText("Basic Information");
    KeyStroke assistKeyStroke = null;
    try {
        assistKeyStroke = KeyStroke.getInstance("Ctrl+Space");
    } catch (ParseException x) {
    // Ignore
    }
    FieldDecoration contentAssistDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    toolkit.createLabel(composite, "Version:");
    txtVersion = toolkit.createText(composite, "", SWT.BORDER);
    ToolTips.setupMessageAndToolTipFromSyntax(txtVersion, Constants.BUNDLE_VERSION);
    Hyperlink linkActivator = toolkit.createHyperlink(composite, "Activator:", SWT.NONE);
    txtActivator = toolkit.createText(composite, "", SWT.BORDER);
    ToolTips.setupMessageAndToolTipFromSyntax(txtActivator, Constants.BUNDLE_ACTIVATOR);
    toolkit.createLabel(composite, "Declarative Services:");
    cmbComponents = new Combo(composite, SWT.READ_ONLY);
    // Content Proposal for the Activator field
    ContentProposalAdapter activatorProposalAdapter = null;
    ActivatorClassProposalProvider proposalProvider = new ActivatorClassProposalProvider();
    activatorProposalAdapter = new ContentProposalAdapter(txtActivator, new TextContentAdapter(), proposalProvider, assistKeyStroke, UIConstants.autoActivationCharacters());
    activatorProposalAdapter.addContentProposalListener(proposalProvider);
    activatorProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    activatorProposalAdapter.setLabelProvider(new JavaContentProposalLabelProvider());
    activatorProposalAdapter.setAutoActivationDelay(1000);
    // Decorator for the Activator field
    ControlDecoration decorActivator = new ControlDecoration(txtActivator, SWT.LEFT | SWT.CENTER, composite);
    decorActivator.setImage(contentAssistDecoration.getImage());
    decorActivator.setMarginWidth(3);
    if (assistKeyStroke == null) {
        decorActivator.setDescriptionText("Content Assist is available. Start typing to activate");
    } else {
        decorActivator.setDescriptionText(MessageFormat.format("Content Assist is available. Press {0} or start typing to activate", assistKeyStroke.format()));
    }
    decorActivator.setShowOnlyOnFocus(true);
    decorActivator.setShowHover(true);
    // Decorator for the Components combo
    ControlDecoration decorComponents = new ControlDecoration(cmbComponents, SWT.LEFT | SWT.CENTER, composite);
    decorComponents.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
    decorComponents.setMarginWidth(3);
    decorComponents.setDescriptionText("Use Java annotations to detect Declarative Service Components.");
    decorComponents.setShowOnlyOnFocus(false);
    decorComponents.setShowHover(true);
    // Listeners
    txtVersion.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            lock.ifNotModifying(new Runnable() {

                @Override
                public void run() {
                    addDirtyProperty(Constants.BUNDLE_VERSION);
                }
            });
        }
    });
    cmbComponents.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            lock.ifNotModifying(new Runnable() {

                @Override
                public void run() {
                    ComponentChoice old = componentChoice;
                    int index = cmbComponents.getSelectionIndex();
                    if (index >= 0 && index < ComponentChoice.values().length) {
                        componentChoice = ComponentChoice.values()[cmbComponents.getSelectionIndex()];
                        if (old != componentChoice) {
                            addDirtyProperty(aQute.bnd.osgi.Constants.SERVICE_COMPONENT);
                            addDirtyProperty(aQute.bnd.osgi.Constants.DSANNOTATIONS);
                            if (old == null) {
                                cmbComponents.remove(ComponentChoice.values().length);
                            }
                        }
                    }
                }
            });
        }
    });
    txtActivator.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent ev) {
            lock.ifNotModifying(new Runnable() {

                @Override
                public void run() {
                    addDirtyProperty(Constants.BUNDLE_ACTIVATOR);
                }
            });
        }
    });
    linkActivator.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        public void linkActivated(HyperlinkEvent ev) {
            String activatorClassName = txtActivator.getText();
            if (activatorClassName != null && activatorClassName.length() > 0) {
                try {
                    IJavaProject javaProject = getJavaProject();
                    if (javaProject == null)
                        return;
                    IType activatorType = javaProject.findType(activatorClassName);
                    if (activatorType != null) {
                        JavaUI.openInEditor(activatorType, true, true);
                    }
                } catch (PartInitException e) {
                    ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening an editor for activator class '{0}'.", activatorClassName), e));
                } catch (JavaModelException e) {
                    ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error searching for activator class '{0}'.", activatorClassName), e));
                }
            }
        }
    });
    activatorProposalAdapter.addContentProposalListener(new IContentProposalListener() {

        @Override
        public void proposalAccepted(IContentProposal proposal) {
            if (proposal instanceof JavaContentProposal) {
                String selectedPackageName = ((JavaContentProposal) proposal).getPackageName();
                if (!model.isIncludedPackage(selectedPackageName)) {
                    model.addPrivatePackage(selectedPackageName);
                }
            }
        }
    });
    // Layout
    GridLayout layout = new GridLayout(2, false);
    layout.horizontalSpacing = 15;
    composite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false);
    txtVersion.setLayoutData(gd);
    txtActivator.setLayoutData(gd);
    cmbComponents.setLayoutData(gd);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) Combo(org.eclipse.swt.widgets.Combo) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) IType(org.eclipse.jdt.core.IType) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) JavaContentProposal(bndtools.utils.JavaContentProposal) PartInitException(org.eclipse.ui.PartInitException) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) JavaContentProposalLabelProvider(bndtools.utils.JavaContentProposalLabelProvider) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) IJavaProject(org.eclipse.jdt.core.IJavaProject) KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) GridData(org.eclipse.swt.layout.GridData) IContentProposalListener(org.eclipse.jface.fieldassist.IContentProposalListener) ParseException(org.eclipse.jface.bindings.keys.ParseException) Hyperlink(org.eclipse.ui.forms.widgets.Hyperlink) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 4 with KeyStroke

use of org.eclipse.jface.bindings.keys.KeyStroke in project dbeaver by serge-rider.

the class UIUtils method installContentProposal.

public static void installContentProposal(Control control, IControlContentAdapter contentAdapter, IContentProposalProvider provider, boolean autoActivation) {
    try {
        KeyStroke keyStroke = autoActivation ? null : KeyStroke.getInstance("Ctrl+Space");
        final ContentProposalAdapter proposalAdapter = new ContentProposalAdapter(control, contentAdapter, provider, keyStroke, autoActivation ? ".abcdefghijklmnopqrstuvwxyz_$(".toCharArray() : ".(".toCharArray());
        proposalAdapter.setPopupSize(new Point(300, 200));
    } catch (ParseException e) {
        log.error("Error installing filters content assistant");
    }
}
Also used : KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) ParseException(org.eclipse.jface.bindings.keys.ParseException) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter)

Example 5 with KeyStroke

use of org.eclipse.jface.bindings.keys.KeyStroke in project tdi-studio-se by Talend.

the class ReconcilerViewer method handleVerifyKeyPressed.

private void handleVerifyKeyPressed(VerifyEvent event) {
    if (!event.doit) {
        return;
    }
    try {
        KeyStroke triggerKeyStroke = HotKeyUtil.getHotKey(HotKeyUtil.contentAssist);
        if (triggerKeyStroke != null) {
            // check the character field...
            if ((triggerKeyStroke.getModifierKeys() == KeyStroke.NO_KEY && triggerKeyStroke.getNaturalKey() == event.character) || // keycode and state must match
            (((triggerKeyStroke.getNaturalKey() == event.keyCode) || (Character.toLowerCase(triggerKeyStroke.getNaturalKey()) == event.keyCode) || (Character.toUpperCase(triggerKeyStroke.getNaturalKey()) == event.keyCode)) && ((triggerKeyStroke.getModifierKeys() & event.stateMask) == triggerKeyStroke.getModifierKeys()))) {
                // We never propagate the keystroke for an explicit
                // keystroke invocation of the popup
                doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
                event.doit = false;
                return;
            }
        }
    } catch (ParseException e) {
        org.talend.commons.exception.ExceptionHandler.process(e);
    }
    if (event.stateMask != SWT.CTRL) {
        return;
    }
    switch(event.character) {
        case ' ':
            doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
            event.doit = false;
            break;
        case '.':
            doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
            event.doit = false;
            break;
        // CTRL-Y
        case 'y' - 'a' + 1:
            doOperation(ITextOperationTarget.REDO);
            event.doit = false;
            break;
        // CTRL-Z
        case 'z' - 'a' + 1:
            doOperation(ITextOperationTarget.UNDO);
            event.doit = false;
            break;
        default:
    }
}
Also used : KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) ParseException(org.eclipse.jface.bindings.keys.ParseException)

Aggregations

KeyStroke (org.eclipse.jface.bindings.keys.KeyStroke)7 ContentProposalAdapter (org.eclipse.jface.fieldassist.ContentProposalAdapter)4 IControlContentAdapter (org.eclipse.jface.fieldassist.IControlContentAdapter)4 StyledTextContentAdapter (org.talend.commons.ui.swt.proposal.StyledTextContentAdapter)4 ParseException (org.eclipse.jface.bindings.keys.ParseException)3 IContentProposalProvider (org.eclipse.jface.fieldassist.IContentProposalProvider)2 Point (org.eclipse.swt.graphics.Point)2 ContentProposalAdapterExtended (org.talend.commons.ui.swt.proposal.ContentProposalAdapterExtended)2 IPigMapService (org.talend.core.service.IPigMapService)2 SQLEditorLabelProvider (org.talend.sqlbuilder.ui.proposal.SQLEditorLabelProvider)2 SQLEditorProposalAdapter (org.talend.sqlbuilder.ui.proposal.SQLEditorProposalAdapter)2 SQLEditorProposalProvider (org.talend.sqlbuilder.ui.proposal.SQLEditorProposalProvider)2 JavaContentProposal (bndtools.utils.JavaContentProposal)1 JavaContentProposalLabelProvider (bndtools.utils.JavaContentProposalLabelProvider)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IType (org.eclipse.jdt.core.IType)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 ControlDecoration (org.eclipse.jface.fieldassist.ControlDecoration)1