Package org.eclipse.jface.fieldassist

Examples of org.eclipse.jface.fieldassist.ContentProposalAdapter


        return super.getProposals(contents, position);
      }
    };
    proposalProvider.setFiltering(true);
    final ContentProposalAdapter adapter = new ContentProposalAdapter(control, contentAdapter, proposalProvider, activationKey, null);
    adapter.setPropagateKeys(true);
    adapter.setAutoActivationDelay(500);
    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_INSERT);

    /* Apply Proposals */
    if (values != null)
      applyAutoCompleteProposals(values, proposalProvider, adapter);

    /*
     * TODO: This is a hack but there doesnt seem to be any API to set the size
     * of the popup to match the actual size of the Text widget being used.
     */
    control.getDisplay().timerExec(100, new Runnable() {
      public void run() {
        if (!control.isDisposed()) {
          adapter.setPopupSize(new Point(control.getSize().x, large ? 90 : 50));
        }
      }
    });

    return Pair.create(proposalProvider, adapter);
View Full Code Here


    KeyStroke activationKey = KeyStroke.getInstance(SWT.ARROW_DOWN);

    /* Create Content Proposal Adapter */
    SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(new String[0]);
    proposalProvider.setFiltering(true);
    final ContentProposalAdapter adapter = new ContentProposalAdapter(text, new TextContentAdapter(), proposalProvider, activationKey, null);
    adapter.setPropagateKeys(true);
    adapter.setAutoActivationDelay(500);
    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

    /* Apply Proposals */
    if (values != null)
      applyProposals(values, proposalProvider, adapter);

    /*
     * TODO: This is a hack but there doesnt seem to be any API to set the size
     * of the popup to match the actual size of the Text widget being used.
     */
    text.getDisplay().timerExec(100, new Runnable() {
      public void run() {
        if (!text.isDisposed()) {
          adapter.setPopupSize(new Point(text.getSize().x, 100));
        }
      }
    });

    return Pair.create(proposalProvider, adapter);
View Full Code Here

    KeyStroke activationKey = KeyStroke.getInstance(SWT.ARROW_DOWN);

    /* Create Content Proposal Adapter */
    SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(new String[0]);
    proposalProvider.setFiltering(true);
    final ContentProposalAdapter adapter = new ContentProposalAdapter(text, new TextContentAdapter(), proposalProvider, activationKey, null);
    adapter.setPropagateKeys(true);
    adapter.setAutoActivationDelay(500);
    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

    /* Apply Proposals */
    if (values != null)
      applyProposals(values, proposalProvider, adapter);

    /*
     * TODO: This is a hack but there doesnt seem to be any API to set the size
     * of the popup to match the actual size of the Text widget being used.
     */
    text.getDisplay().timerExec(100, new Runnable() {
      public void run() {
        if (!text.isDisposed()) {
          adapter.setPopupSize(new Point(text.getSize().x, 100));
        }
      }
    });

    return Pair.create(proposalProvider, adapter);
View Full Code Here

        }
        decPattern.setShowHover(true);
        decPattern.setShowOnlyOnFocus(true);

        PkgPatternsProposalProvider proposalProvider = new PkgPatternsProposalProvider(new FormPartJavaSearchContext(this));
        ContentProposalAdapter patternProposalAdapter = new ContentProposalAdapter(txtName, new TextContentAdapter(), proposalProvider, assistKeyStroke, UIConstants.autoActivationCharacters());
        patternProposalAdapter.addContentProposalListener(proposalProvider);
        patternProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_IGNORE);
        patternProposalAdapter.setAutoActivationDelay(1000);
        patternProposalAdapter.setLabelProvider(new PkgPatternProposalLabelProvider());
        patternProposalAdapter.addContentProposalListener(new IContentProposalListener() {
            public void proposalAccepted(IContentProposal proposal) {
                PkgPatternProposal patternProposal = (PkgPatternProposal) proposal;
                String toInsert = patternProposal.getContent();
                int currentPos = txtName.getCaretPosition();
                txtName.setSelection(patternProposal.getReplaceFromPos(), currentPos);
View Full Code Here

        toolkit.createLabel(composite, "Declarative Services:");
        cmbComponents = new Combo(composite, SWT.READ_ONLY);
        cmbComponents.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

        // 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());
        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.setDescriptionText("Use Java annotations to detect Declarative Service Components.");
        decorComponents.setShowOnlyOnFocus(false);
        decorComponents.setShowHover(true);

        // Listeners
        txtVersion.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                lock.ifNotModifying(new Runnable() {
                    public void run() {
                        addDirtyProperty(Constants.BUNDLE_VERSION);
                    }
                });
            }
        });
        cmbComponents.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                lock.ifNotModifying(new Runnable() {
                    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() {
            public void modifyText(ModifyEvent ev) {
                lock.ifNotModifying(new Runnable() {
                    public void run() {
                        addDirtyProperty(Constants.BUNDLE_ACTIVATOR);
                    }
                });
                IMessageManager msgs = getManagedForm().getMessageManager();
                String activatorError = null;
                int activatorErrorLevel = IMessageProvider.ERROR;

                String activatorClassName = txtActivator.getText();
                if (activatorClassName != null && activatorClassName.length() > 0) {
                    try {
                        IJavaProject javaProject = getJavaProject();
                        if (javaProject == null) {
                            activatorError = "Cannot validate activator class name, the bnd file is not in a Java project.";
                            activatorErrorLevel = IMessageProvider.WARNING;
                        } else {
                            IType activatorType = javaProject.findType(activatorClassName);
                            if (activatorType == null) {
                                activatorError = "The activator class name is not known in this project.";
                                activatorErrorLevel = IMessageProvider.ERROR;
                            }
                        }
                    } catch (JavaModelException e) {
                        logger.logError("Error looking up activator class name: " + activatorClassName, e);
                    }
                }

                if (activatorError != null) {
                    msgs.addMessage(UNKNOWN_ACTIVATOR_ERROR_KEY, activatorError, null, activatorErrorLevel, txtActivator);
                } else {
                    msgs.removeMessage(UNKNOWN_ACTIVATOR_ERROR_KEY, txtActivator);
                }

                checkActivatorIncluded();
            }
        });
        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() {
            public void proposalAccepted(IContentProposal proposal) {
                if (proposal instanceof JavaContentProposal) {
                    String selectedPackageName = ((JavaContentProposal) proposal).getPackageName();
                    if (!model.isIncludedPackage(selectedPackageName)) {
                        model.addPrivatePackage(selectedPackageName);
View Full Code Here

                        }
                        try {
                            Collection<String> types = ntManager.getAllowedPrimaryChildNodeTypes(getNode().getParent().getPrimaryType());
                            SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(types.toArray(new String[0]));
                            proposalProvider.setFiltering(true);
                            ContentProposalAdapter adapter = new ContentProposalAdapter(text, new TextContentAdapter(),
                                    proposalProvider, null, null);
                            adapter.setPropagateKeys(true);
                            adapter
                                    .setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
                            return text;
                        } catch (RepositoryException e) {
                            return text;
                        }
View Full Code Here

        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)) {
View Full Code Here

            props = getProposals().subList(0, props.length).toArray(props);
           
            SimpleContentProposalProvider provider = new SimpleContentProposalProvider(props);
            provider.setFiltering(true);
           
            ContentProposalAdapter adapter = new ContentProposalAdapter(text,
                new TextContentAdapter(),
                provider,
                KeyStroke.getInstance("ARROW_DOWN"), null);
           
            adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
           
            composite.pack();
            adapter.setPopupSize(new Point(text.getBounds().width, 100));
          } catch (ParseException e) {
            e.printStackTrace();
          }
        }
       
View Full Code Here

        Composite container = (Composite) super.createDialogArea(parent);
        Composite composite = new Composite(container, SWT.NONE);

        new Label(composite, SWT.NONE).setText(selectionLabel);

        ContentProposalAdapter proposalAdapter = null;
        Text txtSelection = null;

        Table table = null;
        if (multi)
        {
            table = new Table(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
            viewer = new TableViewer(table);
            viewer.setContentProvider(new ArrayContentProvider());
            viewer.addFilter(new ViewerFilter()
            {
                public boolean select(Viewer viewer, Object parentElement, Object element)
                {
                    @SuppressWarnings("unchecked")
                    E castedElement = (E) element;
                    return filter == null || filter.select(castedElement);
                }
            });
            if (comparator != null)
            {
                viewer.setSorter(new ViewerSorter()
                {
                    @Override
                    public int compare(Viewer viewer, Object o1, Object o2)
                    {
                        @SuppressWarnings("unchecked")
                        E e1 = (E) o1;
                        @SuppressWarnings("unchecked")
                        E e2 = (E) o2;
                        return comparator.compare(e1, e2);
                    }
                });
            }
            synchronized (elements)
            {
                viewer.setInput(elements);
            }

            if (labelProvider != null)
            {
                viewer.setLabelProvider(labelProvider);
            }
        }
        else
        {
            txtSelection = new Text(composite, SWT.BORDER);
            ControlDecoration selectionDecor = new ControlDecoration(txtSelection,
                SWT.LEFT | SWT.TOP);
            FieldDecoration proposalDecor = FieldDecorationRegistry.getDefault().getFieldDecoration(
                FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
            selectionDecor.setImage(proposalDecor.getImage());
            selectionDecor.setDescriptionText(proposalDecor.getDescription());

            ExclusionContentProposalProvider<E> proposalProvider = new ExclusionContentProposalProvider<E>(
                elements, filter, descriptor);

            proposalAdapter = new ContentProposalAdapter(txtSelection,
                new TextContentAdapter(), proposalProvider, null, null);
            proposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
            if (labelProvider != null)
            {
                proposalAdapter.setLabelProvider(labelProvider);
            }

            if (selectedName != null)
            {
                txtSelection.setText(selectedName);
            }
        }
        updateSelection();
        updateButtons();

        // Hookup listeners
        if (proposalAdapter != null)
        {
            proposalAdapter.addContentProposalListener(new IContentProposalListener()
            {
                public void proposalAccepted(IContentProposal proposal)
                {
                    @SuppressWarnings("unchecked")
                    WrappedContentProposal<E> valueProposal = (org.apache.felix.sigil.eclipse.ui.util.WrappedContentProposal<E>) proposal;
View Full Code Here

            }
           
           
        };
        // this variant opens auto-complete on each character
        proposalAdapter = new ContentProposalAdapter(combo, controlContentAdapter, proposalProvider, null, null);
        // this variant opens auto-complete only when invoking the auto-complete hotkey
        if (allowedChildren!=null && allowedChildren.size()==1) {
            combo.setText(allowedChildren.iterator().next());
        } else if (allowedChildren!=null) {
            if (allowedChildren.contains(lastChosenNodeType)) {
View Full Code Here

TOP

Related Classes of org.eclipse.jface.fieldassist.ContentProposalAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.