Example usage for org.eclipse.jface.fieldassist FieldDecorationRegistry DEC_CONTENT_PROPOSAL

List of usage examples for org.eclipse.jface.fieldassist FieldDecorationRegistry DEC_CONTENT_PROPOSAL

Introduction

In this page you can find the example usage for org.eclipse.jface.fieldassist FieldDecorationRegistry DEC_CONTENT_PROPOSAL.

Prototype

String DEC_CONTENT_PROPOSAL

To view the source code for org.eclipse.jface.fieldassist FieldDecorationRegistry DEC_CONTENT_PROPOSAL.

Click Source Link

Document

Decoration id for the decoration that should be used to cue the user that content proposals are available.

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;//  w  w  w.  j  a v  a  2 s.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 {//  w ww.j av  a2s .co m
        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 {/*  w w w  . j a va 2 s.  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 {/*from w  w w .  java 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  ww  w  .  j av  a  2 s  . 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:codemirror.eclipse.swt.search.FindReplaceDialog.java

License:Open Source License

/**
 * Adds enough space in the control's layout data margin for the content assist
 * decoration./* ww w. jav  a 2 s.co m*/
 * @param control the control that needs a margin
 * @since 3.3
 */
private void addDecorationMargin(Control control) {
    Object layoutData = control.getLayoutData();
    if (!(layoutData instanceof GridData))
        return;
    GridData gd = (GridData) layoutData;
    FieldDecoration dec = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
    gd.horizontalIndent = dec.getImage().getBounds().width;
}

From source file:com.aptana.git.ui.dialogs.CompareWithDialog.java

License:Open Source License

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

    // The explanatory message
    Label description = new Label(composite, SWT.WRAP);
    description.setText(Messages.CompareWithDialog_Message);
    description.setLayoutData(GridDataFactory.fillDefaults().hint(250, 70).create());

    // A label and combo with CA for choosing the ref to compare with
    Composite group = new Composite(composite, SWT.NONE);
    group.setLayout(new GridLayout(2, false));
    group.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).hint(250, 30).create());

    Label label = new Label(group, SWT.NONE);
    label.setText(Messages.CompareWithDialog_Ref_label);

    refText = new Combo(group, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN);
    refText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    refText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            refValue = refText.getText();

            // In case they picked a commit, grab only the SHA (shortened)
            int index = refValue.indexOf(' ');
            if (index != -1) {
                refValue = refValue.substring(0, index);
            }/*from www.  ja  v a  2s  .  co m*/
            validate();
        }
    });

    // populate possible common values: HEAD, branches, tags, commits
    refText.add(GitRepository.HEAD);
    for (GitRef ref : simpleRefs) {
        refText.add(ref.shortName());
    }
    for (GitCommit commit : commits) {
        refText.add(commitMessage(commit));
    }
    // set default value of HEAD
    refText.setText(refValue = GitRepository.HEAD);

    SearchingContentProposalProvider proposalProvider = new SearchingContentProposalProvider();
    ContentProposalAdapter adapter = new ContentProposalAdapter(refText, new ComboContentAdapter(),
            proposalProvider, KeyStroke.getInstance(SWT.CONTROL, ' '), null);
    adapter.setPropagateKeys(true);
    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

    ControlDecoration decoration = new ControlDecoration(refText, SWT.LEFT);
    decoration.setImage(FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL).getImage());

    updateStatus(Status.OK_STATUS);
    return composite;
}

From source file:com.aptana.git.ui.dialogs.CreateBranchDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    // Add an advanced section so users can specify a start point ref (so they can create a branch that
    // tracks a remote branch!)
    Composite composite = (Composite) super.createDialogArea(parent);

    // TODO Add a minimize/maximize button for the advanced section
    Group group = new Group(composite, SWT.DEFAULT);
    group.setText(Messages.CreateBranchDialog_AdvancedOptions_label);
    group.setLayout(new GridLayout(1, false));
    group.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));

    Label label = new Label(group, SWT.NONE);
    label.setText(Messages.CreateBranchDialog_StartPoint_label);

    startPointText = new Text(group, getInputTextStyle());
    startPointText.setText(repo.headRef().simpleRef().shortName());
    startPointText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    startPointText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            startPoint = startPointText.getText();
            // TODO Validate the start point. Must be branch name, commit id or tag ref

            if (startPoint.indexOf('/') != -1 && autoTrack) {
                // If name is a remote branch, turn on track by default?
                for (String remoteName : repo.remotes()) {
                    if (startPoint.startsWith(remoteName + '/')) {
                        trackButton.setSelection(true);
                        track = true;// w ww  .  j av  a2 s.  c  o m
                        break;
                    }
                }
            }
        }
    });

    Set<String> simpleRefs = repo.allSimpleRefs();
    String[] proposals = simpleRefs.toArray(new String[simpleRefs.size()]);

    new AutoCompleteField(startPointText, new TextContentAdapter(), proposals);

    // Have CTRL+SPACE also trigger content assist
    SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(proposals);
    proposalProvider.setFiltering(true);
    ContentProposalAdapter adapter = new ContentProposalAdapter(startPointText, new TextContentAdapter(),
            proposalProvider, KeyStroke.getInstance(SWT.CONTROL, ' '), null);
    adapter.setPropagateKeys(true);
    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

    ControlDecoration decoration = new ControlDecoration(startPointText, SWT.LEFT);
    decoration.setImage(FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL).getImage());

    trackButton = new Button(group, SWT.CHECK);
    trackButton.setText(Messages.CreateBranchDialog_Track_label);
    trackButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            track = trackButton.getSelection();
            autoTrack = false; // don't change the value since user modified it here.
        }
    });
    return composite;
}

From source file:com.aptana.git.ui.dialogs.CreateTagDialog.java

License:Open Source License

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

    Label tagNameLabel = new Label(composite, SWT.NONE);
    tagNameLabel.setText(Messages.CreateTagDialog_Message);

    tagNameText = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
    tagNameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, 100).create());
    tagNameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            tagName = tagNameText.getText();
            validate();//from  ww w.ja v a2  s . co  m
        }
    });

    Label tagMessageLabel = new Label(composite, SWT.NONE);
    tagMessageLabel.setText(Messages.CreateTagDialog_Message_label);

    messageText = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
    messageText.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, 100).create());
    messageText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            message = messageText.getText();
            validate();
        }
    });

    // TODO Add a minimize/maximize button for the advanced section
    Group group = new Group(composite, SWT.DEFAULT);
    group.setText(Messages.CreateTagDialog_AdvancedOptions_label);
    group.setLayout(new GridLayout(1, false));
    group.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));

    Label tagRevLabel = new Label(group, SWT.NONE);
    tagRevLabel.setText(Messages.CreateTagDialog_StartPoint_label);

    startPointText = new Combo(group, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN);
    startPointText.setText(startPoint = GitRepository.HEAD);
    startPointText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    startPointText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            startPoint = startPointText.getText();
            // In case they picked a commit, grab only the SHA (shortened)
            int index = startPoint.indexOf(' ');
            if (index != -1) {
                startPoint = startPoint.substring(0, index);
            }
            validate();
        }
    });

    for (GitCommit commit : commits) {
        startPointText.add(commitMessage(commit));
    }

    SearchingContentProposalProvider proposalProvider = new SearchingContentProposalProvider(commits);
    ContentProposalAdapter adapter = new ContentProposalAdapter(startPointText, new ComboContentAdapter(),
            proposalProvider, KeyStroke.getInstance(SWT.CONTROL, ' '), null);
    adapter.setPropagateKeys(true);
    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

    ControlDecoration decoration = new ControlDecoration(startPointText, SWT.LEFT);
    decoration.setImage(FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL).getImage());

    return composite;
}

From source file:com.aptana.ruby.debug.ui.breakpoints.RubyBreakpointConditionEditor.java

License:Open Source License

/**
 * Creates the condition editor widgets and returns the top level control.
 * /*from w ww  .  j a v a2 s .  c  o  m*/
 * @param parent
 *            composite to embed the editor controls in
 * @return top level control
 */
public Control createControl(Composite parent) {
    Composite controls = SWTFactory.createComposite(parent, parent.getFont(), 2, 1, GridData.FILL_HORIZONTAL, 0,
            0);
    fConditional = new Button(controls, SWT.CHECK);
    fConditional.setText(processMnemonics(PropertyPageMessages.RubyBreakpointConditionEditor_0));
    fConditional.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    fConditional.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            boolean checked = fConditional.getSelection();
            setEnabled(checked, true);
            setDirty(PROP_CONDITION_ENABLED);
        }
    });

    fViewer = new SourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.LEFT_TO_RIGHT);
    fViewer.setEditable(false);
    ControlDecoration decoration = new ControlDecoration(fViewer.getControl(), SWT.TOP | SWT.LEFT);
    decoration.setShowOnlyOnFocus(true);
    FieldDecoration dec = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
    decoration.setImage(dec.getImage());
    decoration.setDescriptionText(dec.getDescription());
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    // set height/width hints based on font
    GC gc = new GC(fViewer.getTextWidget());
    gc.setFont(fViewer.getTextWidget().getFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    // gd.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 10);
    gd.widthHint = Dialog.convertWidthInCharsToPixels(fontMetrics, 40);
    gc.dispose();
    fViewer.getControl().setLayoutData(gd);

    parent.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            dispose();
        }
    });
    return parent;
}