Example usage for org.eclipse.jface.fieldassist ContentProposalAdapter setAutoActivationDelay

List of usage examples for org.eclipse.jface.fieldassist ContentProposalAdapter setAutoActivationDelay

Introduction

In this page you can find the example usage for org.eclipse.jface.fieldassist ContentProposalAdapter setAutoActivationDelay.

Prototype

public void setAutoActivationDelay(int delay) 

Source Link

Document

Set the delay, in milliseconds, used before autoactivation is triggered.

Usage

From source file:bndtools.editor.components.ComponentDetailsPage.java

License:Open Source License

void fillMainSection(FormToolkit toolkit, Section section) {
    FieldDecoration contentProposalDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
    ControlDecoration decor;//ww w .j  a  v a 2s.  c o m

    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);

    Hyperlink lnkName = toolkit.createHyperlink(composite, "Name:", SWT.NONE);
    txtName = toolkit.createText(composite, "", SWT.BORDER);
    decor = new ControlDecoration(txtName, SWT.LEFT | SWT.TOP, composite);
    decor.setImage(contentProposalDecoration.getImage());
    decor.setDescriptionText("Content assist available"); // TODO: keystrokes
    decor.setShowHover(true);
    decor.setShowOnlyOnFocus(true);

    KeyStroke assistKeyStroke = null;
    try {
        assistKeyStroke = KeyStroke.getInstance("Ctrl+Space");
    } catch (ParseException x) {
        // Ignore
    }
    ComponentNameProposalProvider proposalProvider = new ComponentNameProposalProvider(
            new FormPartJavaSearchContext(this));
    ContentProposalAdapter proposalAdapter = new ContentProposalAdapter(txtName, new TextContentAdapter(),
            proposalProvider, assistKeyStroke, UIConstants.autoActivationCharacters());
    proposalAdapter.addContentProposalListener(proposalProvider);
    proposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    proposalAdapter.setAutoActivationDelay(1500);
    proposalAdapter.setLabelProvider(ComponentNameProposalProvider.createLabelProvider());

    toolkit.createLabel(composite, ""); // Spacer
    btnEnabled = toolkit.createButton(composite, "Enabled", SWT.CHECK);

    // Listeners
    lnkName.addHyperlinkListener(new HyperlinkAdapter() {
        @Override
        public void linkActivated(HyperlinkEvent e) {
            listPart.doOpenComponent(selected.getName());
        }
    });
    txtName.addListener(SWT.Modify, new Listener() {
        public void handleEvent(Event event) {
            if (refreshers.get() == 0) {
                String oldName = selected.getName();
                String newName = txtName.getText();
                selected.setName(newName);

                listPart.updateLabel(oldName, newName);
                markDirty(PROP_COMPONENT_NAME);
                updateVisibility();
            }
        }
    });
    btnEnabled.addListener(SWT.Modify, new MarkDirtyListener(ServiceComponent.COMPONENT_ENABLED));

    // Layout
    GridData gd;
    composite.setLayout(new GridLayout(2, false));

    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalIndent = 5;
    txtName.setLayoutData(gd);

    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalIndent = 5;
    txtName.setLayoutData(gd);
}

From source file:bndtools.editor.components.ComponentSvcRefWizardPage.java

License:Open Source License

public void createControl(Composite parent) {
    setTitle("Edit Service Reference");

    KeyStroke assistKeyStroke = null;
    try {//from  ww w  .j  av  a2  s.c om
        assistKeyStroke = KeyStroke.getInstance("Ctrl+Space");
    } catch (ParseException x) {
        // Ignore
    }
    FieldDecoration assistDecor = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);

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

    new Label(composite, SWT.NONE).setText("Name:");
    txtName = new Text(composite, SWT.BORDER);

    new Label(composite, SWT.NONE).setText("Interface:");
    txtInterface = new Text(composite, SWT.BORDER);
    ControlDecoration decorInterface = new ControlDecoration(txtInterface, SWT.LEFT | SWT.TOP, composite);
    decorInterface.setImage(assistDecor.getImage());
    decorInterface.setDescriptionText("Content assist available");
    decorInterface.setShowHover(true);
    decorInterface.setShowOnlyOnFocus(true);

    // Add content proposal to svc interface field
    SvcInterfaceProposalProvider proposalProvider = new SvcInterfaceProposalProvider(searchContext);
    ContentProposalAdapter interfaceProposalAdapter = new ContentProposalAdapter(txtInterface,
            new TextContentAdapter(), proposalProvider, assistKeyStroke,
            UIConstants.autoActivationCharacters());
    interfaceProposalAdapter.addContentProposalListener(proposalProvider);
    interfaceProposalAdapter.setAutoActivationDelay(1500);
    interfaceProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    interfaceProposalAdapter.setLabelProvider(new JavaContentProposalLabelProvider());

    new Label(composite, SWT.NONE).setText("Bind:");
    txtBind = new Text(composite, SWT.BORDER);
    ControlDecoration decorBind = new ControlDecoration(txtBind, SWT.LEFT | SWT.TOP, composite);
    decorBind.setImage(assistDecor.getImage());
    decorBind.setDescriptionText("Content assist available");
    decorBind.setShowHover(true);
    decorBind.setShowOnlyOnFocus(true);

    MethodProposalProvider bindProposalProvider = new MethodProposalProvider(searchContext);
    ContentProposalAdapter bindProposalAdapter = new ContentProposalAdapter(txtBind, new TextContentAdapter(),
            bindProposalProvider, assistKeyStroke, UIConstants.autoActivationCharacters());
    bindProposalAdapter.addContentProposalListener(bindProposalProvider);
    bindProposalAdapter.setAutoActivationDelay(1500);
    bindProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    bindProposalAdapter.setLabelProvider(new MethodProposalLabelProvider());

    new Label(composite, SWT.NONE).setText("Unbind:");
    txtUnbind = new Text(composite, SWT.BORDER);
    ControlDecoration decorUnbind = new ControlDecoration(txtUnbind, SWT.LEFT | SWT.TOP, composite);
    decorUnbind.setImage(assistDecor.getImage());
    decorUnbind.setDescriptionText("Content assist available");
    decorUnbind.setShowHover(true);
    decorUnbind.setShowOnlyOnFocus(true);
    ContentProposalAdapter unbindProposalAdapter = new ContentProposalAdapter(txtUnbind,
            new TextContentAdapter(), bindProposalProvider, assistKeyStroke,
            UIConstants.autoActivationCharacters());
    unbindProposalAdapter.addContentProposalListener(bindProposalProvider);
    unbindProposalAdapter.setAutoActivationDelay(1500);
    unbindProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    unbindProposalAdapter.setLabelProvider(new MethodProposalLabelProvider());

    new Label(composite, SWT.NONE); // Spacer
    Composite pnlButtons = new Composite(composite, SWT.NONE);
    btnOptional = new Button(pnlButtons, SWT.CHECK);
    btnOptional.setText("Optional");
    btnMultiple = new Button(pnlButtons, SWT.CHECK);
    btnMultiple.setText("Multiple");
    btnDynamic = new Button(pnlButtons, SWT.CHECK);
    btnDynamic.setText("Dynamic");

    new Label(composite, SWT.NONE).setText("Target Filter:");
    txtTargetFilter = new Text(composite, SWT.BORDER);

    // Initialise
    initialiseFields();
    validate();

    // Listeners
    ModifyListener nameAndInterfaceModifyListener = new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            String name = emptyToNull(txtName.getText());
            String clazz = emptyToNull(txtInterface.getText());
            if (name == null)
                name = clazz;

            serviceReference.setName(name);
            serviceReference.setServiceClass(clazz);
            validate();
        }
    };
    txtName.addModifyListener(nameAndInterfaceModifyListener);
    txtInterface.addModifyListener(nameAndInterfaceModifyListener);
    txtBind.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            serviceReference.setBind(emptyToNull(txtBind.getText()));
            validate();
        }
    });
    txtUnbind.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            serviceReference.setUnbind(emptyToNull(txtUnbind.getText()));
            validate();
        }
    });
    btnOptional.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            serviceReference.setOptional(btnOptional.getSelection());
            validate();
        }
    });
    btnMultiple.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            serviceReference.setMultiple(btnMultiple.getSelection());
            validate();
        }
    });
    btnDynamic.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            serviceReference.setDynamic(btnDynamic.getSelection());
            validate();
        }
    });
    txtTargetFilter.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            serviceReference.setTargetFilter(emptyToNull(txtTargetFilter.getText()));
        }
    });

    // Layout
    GridLayout layout;

    layout = new GridLayout(4, false);
    composite.setLayout(layout);
    txtName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1));
    txtInterface.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1));
    txtBind.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    txtUnbind.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    txtTargetFilter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1));

    pnlButtons.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 3, 1));
    layout = new GridLayout(1, true);
    //      layout.horizontalSpacing = 0;
    //      layout.verticalSpacing = 0;
    //      layout.marginHeight = 0;
    //      layout.marginWidth = 0;
    pnlButtons.setLayout(layout);

    setControl(composite);
}

From source file:bndtools.editor.components.SvcInterfaceSelectionDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Control dialogArea = super.createDialogArea(parent);

    FieldDecoration proposalDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);

    KeyStroke assistKeyStroke = null;
    try {/*from   w w  w .j  av  a 2s. c o m*/
        assistKeyStroke = KeyStroke.getInstance("Ctrl+Space");
    } catch (ParseException x) {
        // Ignore
    }

    Text textField = getText();
    ControlDecoration decor = new ControlDecoration(textField, SWT.LEFT | SWT.TOP);
    decor.setImage(proposalDecoration.getImage());
    decor.setDescriptionText(MessageFormat.format(
            "Content Assist is available. Press {0} or start typing to activate", assistKeyStroke.format()));
    decor.setShowHover(true);
    decor.setShowOnlyOnFocus(true);

    SvcInterfaceProposalProvider proposalProvider = new SvcInterfaceProposalProvider(searchContext);
    ContentProposalAdapter proposalAdapter = new ContentProposalAdapter(textField, new TextContentAdapter(),
            proposalProvider, assistKeyStroke, UIConstants.autoActivationCharacters());
    proposalAdapter.addContentProposalListener(proposalProvider);
    proposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    proposalAdapter.setLabelProvider(new JavaContentProposalLabelProvider());
    proposalAdapter.setAutoActivationDelay(1500);

    return dialogArea;
}

From source file:bndtools.editor.contents.GeneralInfoPart.java

License:Open Source License

private void createSection(Section section, FormToolkit toolkit) {
    section.setText("Basic Information");

    KeyStroke assistKeyStroke = null;
    try {// w w w. j av a  2  s .c  om
        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);
}

From source file:bndtools.editor.pkgpatterns.PkgPatternsDetailsPage.java

License:Open Source License

public void createContents(Composite parent) {
    FormToolkit toolkit = getManagedForm().getToolkit();

    FieldDecoration assistDecor = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
    KeyStroke assistKeyStroke = null;
    try {//from w  w  w .  ja va  2s .co m
        assistKeyStroke = KeyStroke.getInstance("Ctrl+Space");
    } catch (ParseException x) {
        // Ignore
    }

    Section mainSection = toolkit.createSection(parent, Section.TITLE_BAR);
    mainSection.setText(title);

    mainComposite = toolkit.createComposite(mainSection);
    mainSection.setClient(mainComposite);

    toolkit.createLabel(mainComposite, "Pattern:");
    txtName = toolkit.createText(mainComposite, "", SWT.BORDER);
    ControlDecoration decPattern = new ControlDecoration(txtName, SWT.LEFT | SWT.TOP, mainComposite);
    decPattern.setImage(assistDecor.getImage());
    decPattern.setDescriptionText(MessageFormat.format(
            "Content assist is available. Press {0} or start typing to activate", assistKeyStroke.format()));
    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);
            txtName.insert(toInsert);
            txtName.setSelection(patternProposal.getCursorPosition());
        }
    });

    toolkit.createLabel(mainComposite, "Version:");
    txtVersion = toolkit.createText(mainComposite, "", SWT.BORDER);

    /*
     * Section attribsSection = toolkit.createSection(parent, Section.TITLE_BAR | Section.TWISTIE);
     * attribsSection.setText("Extra Attributes"); Composite attribsComposite =
     * toolkit.createComposite(attribsSection);
     */

    // Listeners
    txtName.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if (!modifyLock.isUnderModification()) {
                if (selectedClauses.size() == 1) {
                    selectedClauses.get(0).setName(txtName.getText());
                    if (listPart != null) {
                        listPart.updateLabels(selectedClauses);
                        listPart.validate();
                    }
                    markDirty();
                }
            }
        }
    });
    txtVersion.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if (!modifyLock.isUnderModification()) {
                String text = txtVersion.getText();
                if (text.length() == 0)
                    text = null;

                for (HeaderClause clause : selectedClauses) {
                    clause.getAttribs().put(Constants.VERSION_ATTRIBUTE, text);
                }
                if (listPart != null) {
                    listPart.updateLabels(selectedClauses);
                    listPart.validate();
                }
                markDirty();
            }
        }
    });

    // Layout
    GridData gd;

    parent.setLayout(new GridLayout());
    mainSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    mainComposite.setLayout(new GridLayout(2, false));

    gd = new GridData(SWT.FILL, SWT.TOP, true, false);
    gd.horizontalIndent = 5;
    gd.widthHint = 100;
    txtName.setLayoutData(gd);

    gd = new GridData(SWT.FILL, SWT.TOP, true, false);
    gd.horizontalIndent = 5;
    gd.widthHint = 100;
    txtVersion.setLayoutData(gd);
}

From source file:de.ovgu.featureide.fm.ui.editors.ConstraintDialog.java

License:Open Source License

/**
 * initializes the Text containing the constraint
 */// w  w w  .  j  a  v  a  2s. c o  m
private void initConstraintText() {
    constraintTextComposite = new Composite(shell, SWT.NONE);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);

    constraintTextComposite.setLayoutData(gridData);
    FormLayout constraintTextLayout = new FormLayout();
    constraintTextComposite.setLayout(constraintTextLayout);
    constraintText = new Text(constraintTextComposite, SWT.SINGLE | SWT.BORDER);

    ContentProposalAdapter adapter = new ContentProposalAdapter(constraintText, new ConstraintContentAdapter(),
            new ConstraintContentProposalProvider(featureModel.getFeatureNames()), null, null);

    adapter.setAutoActivationDelay(500);
    adapter.setPopupSize(new Point(250, 85));
    adapter.setLabelProvider(new ConstraintProposalLabelProvider());
    FormData formDataConstraintText = new FormData();
    formDataConstraintText.right = new FormAttachment(100, -5);
    formDataConstraintText.left = new FormAttachment(0, 5);
    constraintText.setLayoutData(formDataConstraintText);
    constraintText.setText(initialConstraint);
    constraintText.addListener(SWT.FocusOut, new Listener() {

        @Override
        public void handleEvent(Event event) {

            x = constraintText.getSelection().x;
            y = constraintText.getSelection().y;

        }

    });

    constraintText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            validate();

        }

    });

}

From source file:eu.esdihumboldt.hale.io.jdbc.ui.SQLSchemaPage.java

License:Open Source License

@Override
protected void createContent(Composite page) {
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(page);

    GridDataFactory labelFactory = GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER);

    // type name/*  ww  w. j av  a  2  s  .  c om*/
    Label typeLabel = new Label(page, SWT.NONE);
    labelFactory.applyTo(typeLabel);
    typeLabel.setText("Query name:");

    typeName = new Text(page, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(typeName);
    typeName.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            updateState(false);
        }
    });

    // SQL query
    Label sqlLabel = new Label(page, SWT.NONE);
    labelFactory.applyTo(sqlLabel);
    sqlLabel.setText("SQL query:");

    sqlQuery = new Text(page, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(sqlQuery);
    sqlQuery.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            updateState(false);
        }
    });

    ContentProposalAdapter adapter = new ContentProposalAdapter(sqlQuery, new TextContentAdapter(),
            contentProposalProvider, ProjectVariablesContentProposalProvider.CTRL_SPACE, new char[] { '{' });
    adapter.setAutoActivationDelay(0);

    final ControlDecoration infoDeco = new ControlDecoration(sqlQuery, SWT.TOP | SWT.LEFT);
    infoDeco.setDescriptionText("Type Ctrl+Space for project variable content assistance");
    infoDeco.setImage(FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
    infoDeco.setShowOnlyOnFocus(true);

    // button for testing query
    Button button = new Button(page, SWT.BORDER | SWT.FLAT);
    GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).span(2, 1).applyTo(button);
    button.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_PLAY));
    button.setText("Test query");
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateState(true);
        }
    });

    updateState(false);
}

From source file:fr.esrf.icat.manager.core.part.EntityEditDialog.java

License:Apache License

@Override
protected Control createDialogArea(final Composite parent) {
    final Composite container = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout(3, false);
    layout.marginRight = 5;//from w w w. j av a  2s .  c o m
    layout.marginLeft = 10;
    container.setLayout(layout);
    comboMapping = new HashMap<>();
    fieldValues = new HashMap<>();
    // we are sure we have at least one entity, use the 1st one for anything general (field types, etc.)
    final WrappedEntityBean firstEntity = entities.get(0);
    for (final String field : firstEntity.getMutableFields()) {
        Label lblAuthn = new Label(container, SWT.NONE);
        lblAuthn.setText(StringUtils.capitalize(field) + ":");
        final Button checkEdit = new Button(container, SWT.CHECK);
        checkEdit.setEnabled(false);
        checkEdit.setVisible(false);
        final Class<?> clazz = firstEntity.getReturnType(field);
        Object initialValue = null;
        boolean notSet = true;
        for (WrappedEntityBean entity : entities) {
            try {
                Object value = entity.get(field);
                if (notSet) {
                    initialValue = value;
                    notSet = false;
                } else if ((null == value && null != initialValue)
                        || (null != value && !value.equals(initialValue))) {
                    initialValue = null;
                    checkEdit.setImage(MULTI_IMAGE);
                    checkEdit.setSelection(false);
                    checkEdit.setEnabled(true);
                    checkEdit.setVisible(true);
                    break;
                }
            } catch (Exception e) {
                LOG.error("Error getting initial value for " + field, e);
            }
        }
        final boolean hasInitialValue = initialValue != null;
        if (firstEntity.isEntity(field)) {
            final Combo combo = new Combo(container, SWT.DROP_DOWN | SWT.BORDER);
            new Label(container, SWT.NONE); //empty left label
            final Label label = new Label(container, SWT.RIGHT);
            label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
            label.setImage(WARNING_IMAGE);
            final Label warningLabel = new Label(container, SWT.LEFT);
            warningLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
            combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
            final EntityListProposalContentProvider proposalProvider = new EntityListProposalContentProvider(
                    client, firstEntity.getReturnType(field).getSimpleName(), initialValue, label, warningLabel,
                    container);
            warningLabel.setText(proposalProvider.getCurrentFilter());
            final ContentProposalAdapter contentProposalAdapter = new ContentProposalAdapter(combo,
                    new ComboContentAdapter(), proposalProvider, DEFAULT_KEYSTROKE, DEFAULT_ACTIVATION_CHARS);
            contentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
            contentProposalAdapter.setPropagateKeys(true);
            contentProposalAdapter.setAutoActivationDelay(1000);
            contentProposalAdapter.addContentProposalListener(new IContentProposalListener2() {
                @Override
                public void proposalPopupOpened(ContentProposalAdapter adapter) {
                }

                @Override
                public void proposalPopupClosed(ContentProposalAdapter adapter) {
                    // when the proposal popup closes we set the content of the combo to the proposals
                    final String[] currentItems = proposalProvider.getCurrentItems();
                    if (currentItems != null && currentItems.length > 0) {
                        combo.setItems(currentItems);
                    }
                    final String currentText = proposalProvider.getCurrentText();
                    final int caretPosition = proposalProvider.getCaretPosition();
                    combo.setText(currentText);
                    combo.setSelection(new Point(caretPosition, caretPosition));
                }
            });
            combo.setItems(proposalProvider.getInitialItems());
            if (hasInitialValue) {
                combo.select(0);
            }
            comboMapping.put(field,
                    new ImmutablePair<Object[], Combo>(new Object[] { proposalProvider }, combo));
            if (checkEdit.isEnabled()) {
                combo.setEnabled(false);
                checkEdit.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        combo.setEnabled(checkEdit.getSelection());
                    }
                });
            }

        } else if (Enum.class.isAssignableFrom(clazz)) {
            final Combo combo = new Combo(container, SWT.DROP_DOWN | SWT.BORDER);
            final Object[] c = clazz.getEnumConstants();
            final String[] s = new String[c.length];
            int selected = -1;
            for (int i = 0; i < c.length; i++) {
                s[i] = c[i].toString();
                if (initialValue != null && c[i].equals(initialValue)) {
                    selected = i;
                }
            }
            // replacement for AutocompleteComboSelector to avoid selecting the 1st value in the combo when
            // no proposal is accepted (or field is emptied)
            new AutocompleteCombo(combo) {
                @Override
                protected AutocompleteContentProposalProvider getContentProposalProvider(String[] proposals) {
                    return new AutocompleteSelectorContentProposalProvider(proposals, this.combo);
                }

            };
            combo.setItems(s);
            if (selected >= 0) {
                combo.select(selected);
            }
            combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
            comboMapping.put(field, new ImmutablePair<Object[], Combo>(c, combo));
            if (checkEdit.isEnabled()) {
                combo.setEnabled(false);
                checkEdit.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        combo.setEnabled(checkEdit.getSelection());
                    }
                });
            }

        } else if (clazz.equals(Boolean.class) || clazz.equals(boolean.class)) {
            final Button btn = new Button(container, SWT.CHECK);
            btn.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
            if (null == initialValue) {
                if (isSingle) {
                    try {
                        firstEntity.set(field, Boolean.FALSE);
                    } catch (Exception e) {
                        LOG.error("Error setting " + field + " to " + Boolean.FALSE);
                    }
                }
            } else {
                btn.setSelection((Boolean) initialValue);
            }
            btn.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    boolean value = btn.getSelection();
                    fieldValues.put(field, value);
                }
            });
            if (checkEdit.isEnabled()) {
                btn.setEnabled(false);
                checkEdit.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        final boolean selected = checkEdit.getSelection();
                        btn.setEnabled(selected);
                        if (selected) {
                            fieldValues.put(field, btn.getSelection());
                        } else {
                            fieldValues.remove(field);
                        }
                    }
                });
            }

        } else if (Calendar.class.isAssignableFrom(clazz) || Date.class.isAssignableFrom(clazz)
                || XMLGregorianCalendar.class.isAssignableFrom(clazz)) {

            final CDateTime cdt = new CDateTime(container,
                    CDT.BORDER | CDT.SPINNER | CDT.TAB_FIELDS | CDT.DATE_MEDIUM | CDT.TIME_MEDIUM);
            cdt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
            if (null != initialValue) {
                Date initialDate = null;
                if (initialValue instanceof Calendar) {
                    initialDate = ((Calendar) initialValue).getTime();
                } else if (initialValue instanceof XMLGregorianCalendar) {
                    initialDate = ((XMLGregorianCalendar) initialValue).toGregorianCalendar().getTime();
                } else if (initialValue instanceof Date) {
                    initialDate = (Date) initialValue;
                }
                cdt.setSelection(initialDate);
            }

            cdt.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    fieldValues.put(field, makeCorrectDateValue(clazz, cdt.getSelection()));
                }
            });
            if (checkEdit.isEnabled()) {
                cdt.setEnabled(false);
                checkEdit.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        final boolean selected = checkEdit.getSelection();
                        cdt.setEnabled(selected);
                        if (selected) {
                            fieldValues.put(field, makeCorrectDateValue(clazz, cdt.getSelection()));
                        } else {
                            fieldValues.remove(field);
                        }
                    }
                });
            }

        } else if (Number.class.isAssignableFrom(clazz)) {
            final Text text = new Text(container, SWT.BORDER);
            text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
            if (null != initialValue) {
                text.setText(initialValue.toString());
            }
            final Color original = text.getForeground();
            text.addModifyListener(new ModifyListener() {
                @Override
                public void modifyText(ModifyEvent e) {
                    text.setForeground(original);
                    String value = text.getText();
                    if (null == value) {
                        value = ICATEntity.EMPTY_STRING;
                    }
                    final Object numVal = makeCorrectNumericValue(clazz, value);
                    if (null == numVal) {
                        text.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
                    } else {
                        fieldValues.put(field, numVal);
                    }
                }
            });
            if (checkEdit.isEnabled()) {
                text.setEnabled(false);
                checkEdit.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        final boolean selected = checkEdit.getSelection();
                        text.setEnabled(selected);
                        if (selected) {
                            fieldValues.put(field, makeCorrectNumericValue(clazz, text.getText()));
                        } else {
                            fieldValues.remove(field);
                        }
                    }
                });
            }

        } else { // Assumes String
            final Text text = new Text(container, SWT.BORDER);
            text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
            if (null == initialValue) {
                if (isSingle) {
                    try {
                        firstEntity.set(field, ICATEntity.EMPTY_STRING);
                    } catch (Exception e) {
                        LOG.error("Error setting " + field + " to EMPTY_STRING");
                    }
                }
            } else {
                text.setText(initialValue.toString());
            }
            text.addModifyListener(new ModifyListener() {
                @Override
                public void modifyText(ModifyEvent e) {
                    String value = text.getText();
                    if (null == value) {
                        value = ICATEntity.EMPTY_STRING;
                    }
                    fieldValues.put(field, value);
                }
            });
            if (checkEdit.isEnabled()) {
                text.setEnabled(false);
                checkEdit.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        final boolean selected = checkEdit.getSelection();
                        text.setEnabled(selected);
                        if (selected) {
                            fieldValues.put(field, text.getText());
                        } else {
                            fieldValues.remove(field);
                        }
                    }
                });
            }
        }
    }
    return container;
}

From source file:gda.rcp.views.AutoCompleter.java

License:Open Source License

private void setupContentPropoasalAdapter(ContentProposalAdapter cpa) {
    boolean propagate = true;
    int autoActivationDelay = 0;
    cpa.setInfoPopupRequired(false);/* ww w. ja va  2  s . co m*/
    cpa.addContentProposalListener(contentProposalListener);
    cpa.setLabelProvider(prv);
    cpa.setAutoActivationDelay(autoActivationDelay);
    cpa.setPropagateKeys(propagate);
    cpa.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_IGNORE);
}

From source file:net.enilink.komma.edit.ui.util.SearchWidget.java

License:Open Source License

/**
 * Creates the search text and adds listeners. This method calls
 * {@link #doCreateSearchText(Composite)} to create the text control.
 * Subclasses should override {@link #doCreateSearchText(Composite)} instead
 * of overriding this method./*  w  ww .  j  a  v a 2 s.  co m*/
 * 
 * @param parent
 *            <code>Composite</code> of the search text
 */
protected void createSearchText(Composite parent) {
    searchText = doCreateSearchText(parent);
    searchText.addFocusListener(new FocusAdapter() {
        /*
         * (non-Javadoc)
         * 
         * @see
         * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt
         * .events.FocusEvent)
         */
        public void focusGained(FocusEvent e) {
            /*
             * Running in an asyncExec because the selectAll() does not
             * appear to work when using mouse to give focus to text.
             */
            Display display = searchText.getDisplay();
            display.asyncExec(new Runnable() {
                public void run() {
                    if (!searchText.isDisposed()) {
                        if (getInitialText().equals(searchText.getText().trim())) {
                            searchText.selectAll();
                        }
                    }
                }
            });
        }
    });

    searchText.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            doSearch(searchText.getText());
        }
    });
    searchText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    // content proposals for searching
    class ObjectProposal extends ContentProposal {
        Object object;

        ObjectProposal(Object object) {
            super("");
            this.object = object;
        }
    }

    ContentProposalAdapter proposalAdapter = new ContentProposalAdapter(searchText, new TextContentAdapter(),
            new IContentProposalProvider() {
                @Override
                public IContentProposal[] getProposals(String contents, int position) {
                    Collection<Object> results = findElements(contents);
                    List<IContentProposal> proposals = new ArrayList<IContentProposal>();
                    for (Object result : results) {
                        proposals.add(new ObjectProposal(result));
                    }
                    return proposals.toArray(new IContentProposal[proposals.size()]);
                }
            }, null, null);
    proposalAdapter.setAutoActivationDelay(750);
    proposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_IGNORE);
    proposalAdapter.addContentProposalListener(new IContentProposalListener() {
        @Override
        public void proposalAccepted(IContentProposal proposal) {
            viewer.setSelection(new StructuredSelection(((ObjectProposal) proposal).object), true);
        }
    });

    proposalAdapter.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            ILabelProvider labelProvider = getLabelProvider();
            return labelProvider != null ? labelProvider.getText(((ObjectProposal) element).object)
                    : super.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            ILabelProvider labelProvider = getLabelProvider();
            return labelProvider != null ? labelProvider.getImage(((ObjectProposal) element).object)
                    : super.getImage(element);
        }
    });
}