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

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

Introduction

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

Prototype

public static FieldDecorationRegistry getDefault() 

Source Link

Document

Get the default FieldDecorationRegistry.

Usage

From source file:ac.soton.eventb.classdiagrams.diagram.sheet.custom.PropertySectionUtil.java

License:Open Source License

/**
 * Returns new control decorator initialised with message.
 * /*from w w  w. jav a  2  s  . c  o m*/
 * @param control control widget
 * @param message initial message or null if none
 * @param type decorator type constant from FieldDecorationRegistry
 * @param visible is it visible when created
 * @return control decorator
 */
public static ControlDecoration createDecorator(Control control, String message, String type, boolean visible) {
    ControlDecoration controlDecoration = new ControlDecoration(control, SWT.LEFT | SWT.TOP);
    controlDecoration.setDescriptionText(message);
    FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(type);
    controlDecoration.setImage(fieldDecoration.getImage());
    if (!visible)
        controlDecoration.hide();
    return controlDecoration;
}

From source file:ac.soton.multisim.diagram.sheet.custom.common.DecoratedInputValidator.java

License:Open Source License

/**
 * Returns new control decorator initialised with message.
 * /*w w  w.j  av a2  s  . c  o  m*/
 * @param control control widget
 * @param type decorator type constant from FieldDecorationRegistry
 * @param visible is it visible when created
 * @return control decorator
 */
public static ControlDecoration createDecorator(Control control, String type, boolean visible) {
    ControlDecoration controlDecoration = new ControlDecoration(control, SWT.LEFT | SWT.TOP);
    FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(type);
    controlDecoration.setImage(fieldDecoration.getImage());
    if (!visible)
        controlDecoration.hide();
    return controlDecoration;
}

From source file:at.medevit.ch.artikelstamm.ui.DetailComposite.java

License:Open Source License

public DetailComposite(Composite parent, int style, String atcCodeLanguage) {
    super(parent, style);
    setLayout(new GridLayout(1, false));
    setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));

    mainComposite = new Composite(this, SWT.NONE);
    mainComposite.setLayout(new GridLayout(1, false));

    DetailComposite.prefAtcLanguage = atcCodeLanguage;

    Composite headerComposite = new Composite(mainComposite, SWT.NONE);
    headerComposite.setLayout(new GridLayout(4, false));
    headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    lblDSCR = new Label(headerComposite, SWT.NONE);
    lblDSCR.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    lblDSCR.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_DARK_SHADOW));
    lblDSCR.setFont(SWTResourceManager.getFont("Lucida Grande", 16, SWT.BOLD));
    GridData gd_lblDSCR = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
    gd_lblDSCR.widthHint = 435;/*from   w w  w  .  j  a  v  a 2s.c o m*/
    lblDSCR.setLayoutData(gd_lblDSCR);

    Composite topComposite = new Composite(headerComposite, SWT.NONE);
    topComposite.setLayout(new GridLayout(6, false));
    topComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));

    GridData gdd = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gdd.widthHint = 70;
    GridData gdd2 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    Label lblGtin = new Label(topComposite, SWT.NONE);
    lblGtin.setLayoutData(gdd);
    lblGtin.setToolTipText("European Article Number / Global Trade Index Number");
    lblGtin.setText("EAN/GTIN");

    txtGTIN = new Text(topComposite, SWT.READ_ONLY);
    txtGTIN.setLayoutData(gdd2);
    txtGTIN.setBackground(topComposite.getBackground());

    Label lblPhznr = new Label(topComposite, SWT.NONE);
    lblPhznr.setToolTipText("Pharmacode");
    lblPhznr.setLayoutData(gdd);
    lblPhznr.setText("Pharmacode");

    txtPHZNR = new Text(topComposite, SWT.READ_ONLY);
    txtPHZNR.setLayoutData(gdd2);
    txtPHZNR.setBackground(topComposite.getBackground());

    final Label lblProductNr = new Label(topComposite, SWT.NONE);
    lblProductNr.setToolTipText("Produktnummer");
    lblProductNr.setLayoutData(gdd);
    lblProductNr.setText("Produkt Nr");

    txtProductNr = new Text(topComposite, SWT.READ_ONLY);
    txtProductNr.setLayoutData(gdd2);
    txtProductNr.setBackground(topComposite.getBackground());
    txtProductNr.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            lblProductNr.setVisible(!txtProductNr.getText().isEmpty());
        }
    });

    lblAbgabekategorie = new Label(headerComposite, SWT.NONE);
    lblAbgabekategorie.setText("Abgabekategorie");

    txtABGABEKATEGORIE = new Text(headerComposite, SWT.READ_ONLY);
    txtABGABEKATEGORIE.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    txtABGABEKATEGORIE.setBackground(topComposite.getBackground());
    new Label(headerComposite, SWT.NONE);
    new Label(headerComposite, SWT.NONE);

    Group grpPackungsgroessenPreise = new Group(mainComposite, SWT.NONE);
    grpPackungsgroessenPreise.setText("Preis");
    grpPackungsgroessenPreise.setLayout(new GridLayout(7, false));
    grpPackungsgroessenPreise.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label lblExFactoryPreis = new Label(grpPackungsgroessenPreise, SWT.NONE);
    lblExFactoryPreis.setText("Ex-Factory");

    lblEXFACTORYPRICE = new Label(grpPackungsgroessenPreise, SWT.BORDER);
    lblEXFACTORYPRICE.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblPublicPrice = new Label(grpPackungsgroessenPreise, SWT.NONE);
    lblPublicPrice.setText("Publikumspreis");

    txtPUBLICPRICE = new Text(grpPackungsgroessenPreise, SWT.BORDER);
    txtPUBLICPRICE.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    controlDecoIsCalculatedPPUB = new ControlDecoration(txtPUBLICPRICE, SWT.LEFT | SWT.TOP);
    controlDecoIsCalculatedPPUB.setDescriptionText("Preis wurde mittels Marge kalkuliert!");
    FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);
    controlDecoIsCalculatedPPUB.setImage(fieldDecoration.getImage());
    controlDecoIsCalculatedPPUB.hide();

    lblSelbstbehalt = new Label(grpPackungsgroessenPreise, SWT.NONE);
    lblSelbstbehalt.setText("Selbstbehalt (%)");

    lblSELBSTBEHALT = new Text(grpPackungsgroessenPreise, SWT.READ_ONLY);
    lblSELBSTBEHALT.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    btnUserDefinedPrice = new Button(grpPackungsgroessenPreise, SWT.FLAT | SWT.CHECK);
    btnUserDefinedPrice.setToolTipText("Benutzerdefinierter Preis");
    btnUserDefinedPrice.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
    btnUserDefinedPrice.setImage(
            ResourceManager.getPluginImage("at.medevit.ch.artikelstamm.ui", "rsc/icons/money--pencil.png"));
    btnUserDefinedPrice.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            item.getValue().setUserDefinedPrice(btnUserDefinedPrice.getSelection());
            m_bindingContext.updateTargets();
            txtPUBLICPRICE.setFocus();
        }
    });

    Group grepATCCode = new Group(mainComposite, SWT.NONE);
    grepATCCode.setLayout(new GridLayout(1, false));
    grepATCCode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    grepATCCode.setText("ATC-Code");

    treeATC = new Tree(grepATCCode, SWT.BORDER);
    GridData gd_treeATC = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_treeATC.heightHint = 80;
    treeATC.setLayoutData(gd_treeATC);
    treeATC.setBackground(parent.getBackground());

    Group grpMarker = new Group(mainComposite, SWT.None);
    grpMarker.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    grpMarker.setText("Marker");
    grpMarker.setLayout(new GridLayout(2, false));

    btnCheckIsNarcotic = new Button(grpMarker, SWT.CHECK);
    btnCheckIsNarcotic.setText("Betubungsmittel");

    btnLPPVEntry = new Button(grpMarker, SWT.CHECK);
    btnLPPVEntry.setToolTipText(
            "Artikel wird in Liste pharmazeutischer Prparate mit spezieller Verwendung (LPPV) gefhrt");
    btnLPPVEntry.setText("LPPV Eintrag");

    Group grpLimitations = new Group(mainComposite, SWT.None);
    grpLimitations.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    grpLimitations.setText("Einschrnkungen");
    grpLimitations.setLayout(new GridLayout(2, false));

    btnlLimitation = new Button(grpLimitations, SWT.CHECK);
    btnlLimitation.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    btnlLimitation.setText("Limitation");

    lblLimitationspunkte = new Label(grpLimitations, SWT.NONE);
    lblLimitationspunkte.setText("Limitationspunkte");

    txtLIMITATIONPOINTS = new Text(grpLimitations, SWT.READ_ONLY);
    txtLIMITATIONPOINTS.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    txtLIMITATIONPOINTS.setBackground(grpLimitations.getBackground());

    lblLimitationstext = new Label(grpLimitations, SWT.NONE);
    lblLimitationstext.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    lblLimitationstext.setText("Limitationstext");

    GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1);
    gd.widthHint = 450;
    gd.minimumWidth = 450;
    txtLIMITATIONTEXT = new Text(grpLimitations, SWT.WRAP | SWT.MULTI);
    txtLIMITATIONTEXT.setLayoutData(gd);
    txtLIMITATIONTEXT.setBackground(grpLimitations.getBackground());

    Group grpHersteller = new Group(mainComposite, SWT.NONE);
    grpHersteller.setLayout(new GridLayout(1, false));
    grpHersteller.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    grpHersteller.setText("Hersteller");

    lblHERSTELLER = new Label(grpHersteller, SWT.NONE);
    lblHERSTELLER.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    grpDefaultSignature = new Group(mainComposite, SWT.NONE);
    grpDefaultSignature.setLayout(new GridLayout(1, false));
    grpDefaultSignature.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    grpDefaultSignature.setText("Standard Signatur");

    adsc = new ArticleDefaultSignatureComposite(grpDefaultSignature, SWT.NONE);
    adsc.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    adsc.setOnLocationEnabled(false);

    m_bindingContext = initDataBindings();
    adsc.initDataBindings(m_bindingContext);
    adsc.setAutoSave(true);

    this.setContent(mainComposite);
    this.setExpandHorizontal(true);
    this.setExpandVertical(true);

    this.setMinSize(mainComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    this.layout(true, true);
}

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;/*from  w  w w. j  a v a 2s  .  co  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.ComponentDetailsPage.java

License:Open Source License

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

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

    // Create controls
    toolkit.createLabel(composite, "Activate method:");
    txtActivate = toolkit.createText(composite, "", SWT.BORDER);
    toolkit.createLabel(composite, "Deactivate method:");
    txtDeactivate = toolkit.createText(composite, "", SWT.BORDER);
    toolkit.createLabel(composite, "Modified method:");
    txtModified = toolkit.createText(composite, "", SWT.BORDER);

    toolkit.createLabel(composite, ""); // Spacer
    btnImmediate = toolkit.createButton(composite, "Immediate", SWT.CHECK);
    decor = new ControlDecoration(btnImmediate, SWT.RIGHT, composite);
    decor.setImage(infoDecoration.getImage());
    decor.setDescriptionText("The component will be activated immediately,\n"
            + "even when it provides a service and no consumers\n" + "of the service exist.");
    decor.setShowHover(true);

    toolkit.createLabel(composite, ""); // Spacer
    btnSvcFactory = toolkit.createButton(composite, "Service Factory", SWT.CHECK);
    decor = new ControlDecoration(btnSvcFactory, SWT.RIGHT, composite);
    decor.setImage(infoDecoration.getImage());
    decor.setDescriptionText("An instance of the component will be created\nfor each service consumer.");
    decor.setShowHover(true);

    toolkit.createLabel(composite, "Factory ID:");
    txtFactoryId = toolkit.createText(composite, "", SWT.BORDER);
    decor = new ControlDecoration(txtFactoryId, SWT.LEFT | SWT.BOTTOM, composite);
    decor.setImage(infoDecoration.getImage());
    decor.setDescriptionText(
            "Makes the component a 'factory component', published\nunder the ComponentFactory service, with the specified ID.");

    // Listeners
    txtActivate.addListener(SWT.Modify, new MarkDirtyListener(ServiceComponent.COMPONENT_ACTIVATE));
    txtDeactivate.addListener(SWT.Modify, new MarkDirtyListener(ServiceComponent.COMPONENT_DEACTIVATE));
    txtModified.addListener(SWT.Modify, new MarkDirtyListener(ServiceComponent.COMPONENT_MODIFIED));
    txtFactoryId.addListener(SWT.Modify, new MarkDirtyListener(ServiceComponent.COMPONENT_FACTORY));
    btnImmediate.addListener(SWT.Selection, new MarkDirtyListener(ServiceComponent.COMPONENT_IMMEDIATE));
    btnSvcFactory.addListener(SWT.Selection, new MarkDirtyListener(ServiceComponent.COMPONENT_SERVICEFACTORY));

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

    GridData gd;
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalIndent = 5;
    txtActivate.setLayoutData(gd);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalIndent = 5;
    txtDeactivate.setLayoutData(gd);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalIndent = 5;
    txtModified.setLayoutData(gd);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalIndent = 5;
    txtFactoryId.setLayoutData(gd);
}

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

License:Open Source License

void fillConfigPolicySection(FormToolkit toolkit, Section section) {
    FieldDecoration infoDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);
    ControlDecoration decor;/*from   w w  w .  jav  a  2 s.  co  m*/

    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    btnConfigPolicyOptional = toolkit.createButton(composite, "Optional", SWT.RADIO);
    decor = new ControlDecoration(btnConfigPolicyOptional, SWT.RIGHT, composite);
    decor.setImage(infoDecoration.getImage());
    decor.setDescriptionText(
            "The component will be activated whether or not\nmatching configuration data is available.");
    decor.setShowHover(true);
    btnConfigPolicyRequire = toolkit.createButton(composite, "Require", SWT.RADIO);
    decor = new ControlDecoration(btnConfigPolicyRequire, SWT.RIGHT, composite);
    decor.setImage(infoDecoration.getImage());
    decor.setDescriptionText(
            "The component will be activated ONLY if matching\nconfiguration data is available.");
    decor.setShowHover(true);
    btnConfigPolicyIgnore = toolkit.createButton(composite, "Ignore", SWT.RADIO);
    decor = new ControlDecoration(btnConfigPolicyIgnore, SWT.RIGHT, composite);
    decor.setImage(infoDecoration.getImage());
    decor.setDescriptionText("The component will not receive configuration\ndata from Configuration Admin.");
    decor.setShowHover(true);

    // Listeners
    MarkDirtyListener configPolicyDirtyListener = new MarkDirtyListener(
            ServiceComponent.COMPONENT_CONFIGURATION_POLICY);
    btnConfigPolicyOptional.addListener(SWT.Selection, configPolicyDirtyListener);
    btnConfigPolicyRequire.addListener(SWT.Selection, configPolicyDirtyListener);
    btnConfigPolicyIgnore.addListener(SWT.Selection, configPolicyDirtyListener);

    // Layout
    GridLayout layout = new GridLayout(3, false);
    layout.horizontalSpacing = 15;
    composite.setLayout(layout);
}

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 {// ww  w .  ja  v  a  2 s .  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 {/*from  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.j  a v  a 2 s.  c o  m
        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 {//  w w w.  j  a v a  2  s  .  c  om
        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);
}