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

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

Introduction

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

Prototype

public void setProposalAcceptanceStyle(int acceptance) 

Source Link

Document

Set the integer style that indicates how an accepted proposal affects the control's content.

Usage

From source file:at.medevit.elexis.impfplan.ui.dialogs.SupplementVaccinationDialog.java

License:Open Source License

/**
 * Create contents of the dialog./* w w  w  .  j  ava  2  s  .  com*/
 * 
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    setTitle("Impfung nachtragen");
    setTitleImage(
            ResourceManager.getPluginImage("at.medevit.elexis.impfplan.ui", "rsc/icons/vaccination_logo.png"));

    Patient selectedPatient = ElexisEventDispatcher.getSelectedPatient();
    setMessage(pat.getLabel());

    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    Group mainGroup = new Group(container, SWT.NONE);
    mainGroup.setFont(SWTResourceManager.getFont("Noto Sans", 9, SWT.BOLD));
    mainGroup.setText("Pflicht Angaben");
    GridLayout gd_MainGroup = new GridLayout(2, false);
    mainGroup.setLayout(gd_MainGroup);
    mainGroup.setLayoutData(new GridData(GridData.FILL_BOTH));

    Label lblVerabreichungsdatum = new Label(mainGroup, SWT.NONE);
    lblVerabreichungsdatum.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblVerabreichungsdatum.setText("Datum");

    dateOfAdministration = new DateTime(mainGroup, SWT.BORDER | SWT.DROP_DOWN);
    dateOfAdministration.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            selDate.set(dateOfAdministration.getYear(), dateOfAdministration.getMonth(),
                    dateOfAdministration.getDay());

            if (selDate.isBefore(patBDay)) {
                SWTHelper.showInfo("Patient noch nicht geboren",
                        "Das von Ihnen gewhlte Datum liegt vor der Geburt des Patienten.");
                dateOfAdministration.setYear(patBDay.get(TimeTool.YEAR));
                dateOfAdministration.setMonth(patBDay.get(TimeTool.MONTH));
                dateOfAdministration.setDay(patBDay.get(TimeTool.DAY_OF_MONTH));
            }
        }
    });

    { // article name
        Label lblArtikelname = new Label(mainGroup, SWT.NONE);
        lblArtikelname.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblArtikelname.setText("Artikelname");

        txtArticleName = new Text(mainGroup, SWT.BORDER);
        txtArticleName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        txtArticleName.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                articleString = txtArticleName.getText();
            }
        });

        PersistentObjectProposalProvider<ArtikelstammItem> aopp = new PersistentObjectProposalProvider<>(
                ArtikelstammItem.class, ArtikelstammItem.FLD_ATC, Query.LIKE, "J07%");
        ContentProposalAdapter articleProposalAdapter = new ContentProposalAdapter(txtArticleName,
                new TextContentAdapter(), aopp, null, null);
        articleProposalAdapter.addContentProposalListener(new IContentProposalListener() {

            @SuppressWarnings("unchecked")
            @Override
            public void proposalAccepted(IContentProposal proposal) {
                PersistentObjectContentProposal<ArtikelstammItem> prop = (PersistentObjectContentProposal<ArtikelstammItem>) proposal;
                txtArticleName.setText(prop.getLabel());
                articleString = prop.getPersistentObject().storeToString();

                /**
                 * could be useful to define vacc. against at some point, but not needed in the
                 * current version
                 */
                // txtArticleEAN.setText(prop.getPersistentObject().getEAN());
                // txtAtcCode.setText(prop.getPersistentObject().getATCCode());
            }
        });
    }
    new Label(container, SWT.NONE);

    Group optionalGroup = new Group(container, SWT.NONE);
    optionalGroup.setFont(SWTResourceManager.getFont("Noto Sans", 9, SWT.BOLD));
    optionalGroup.setText("Optionale Angaben");
    optionalGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    optionalGroup.setLayout(new GridLayout(2, false));

    { // administrating contact
        Label lblAdministratingContact = new Label(optionalGroup, SWT.NONE);
        lblAdministratingContact.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblAdministratingContact.setText("Nachtrag von");

        txtAdministrator = new Text(optionalGroup, SWT.BORDER);
        administratorString = mandant.storeToString();
        txtAdministrator.setText(mandant.getMandantLabel());
        txtAdministrator.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                administratorString = txtAdministrator.getText();
            }
        });
        txtAdministrator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        PersistentObjectProposalProvider<Mandant> mopp = new PersistentObjectProposalProvider<Mandant>(
                Mandant.class) {
            @Override
            public String getLabelForObject(Mandant a) {
                return a.getMandantLabel();
            }
        };

        ContentProposalAdapter mandatorProposalAdapter = new ContentProposalAdapter(txtAdministrator,
                new TextContentAdapter(), mopp, null, null);
        mandatorProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
        mandatorProposalAdapter.addContentProposalListener(new IContentProposalListener() {

            @Override
            public void proposalAccepted(IContentProposal proposal) {
                PersistentObjectContentProposal<Mandant> prop = (PersistentObjectContentProposal<Mandant>) proposal;
                administratorString = prop.getPersistentObject().storeToString();
            }
        });

        Label lblLotNo = new Label(optionalGroup, SWT.NONE);
        lblLotNo.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblLotNo.setText("Lot-Nr");

        txtLotNo = new Text(optionalGroup, SWT.BORDER);
        txtLotNo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    }

    /**
     * could be useful to define vacc. against at some point, but not needed in the current
     * version
     */
    // Label lblArtikelEan = new Label(optionalGroup, SWT.NONE);
    // lblArtikelEan.setSize(60, 15);
    // lblArtikelEan.setText("Artikel EAN");
    //
    // txtArticleEAN = new Text(optionalGroup, SWT.BORDER);
    // txtArticleEAN.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    // txtArticleEAN.setSize(348, 21);
    //
    // Label lblAtccode = new Label(optionalGroup, SWT.NONE);
    // lblAtccode.setSize(56, 15);
    // lblAtccode.setText("ATC-Code");
    //
    // txtAtcCode = new Text(optionalGroup, SWT.BORDER);
    // txtAtcCode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    // txtAtcCode.setSize(314, 21);

    Group expiredGroup = new Group(container, SWT.NONE);
    expiredGroup.setFont(SWTResourceManager.getFont("Noto Sans", 9, SWT.BOLD));
    expiredGroup.setText("Bei nicht mehr erhltlichen Impfstoffen");
    expiredGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    expiredGroup.setLayout(new GridLayout(2, false));
    {
        Label lblVaccAgainst = new Label(expiredGroup, SWT.NONE);
        lblVaccAgainst.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
        lblVaccAgainst.setText("Impfung gegen Krankheit(en)");

        vect = new VaccinationEffectCheckboxTreeViewer(container, SWT.BORDER, vaccAgainst);
    }
    return area;
}

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;// www .  j a v  a2s .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.ComponentSvcRefWizardPage.java

License:Open Source License

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

    KeyStroke assistKeyStroke = null;
    try {//  w  w  w .j a  va 2s .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 .java2  s .  co  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.jav 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  . ja 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);
}

From source file:ch.elexis.core.ui.contacts.controls.StammDatenComposite.java

License:Open Source License

public StammDatenComposite(Composite parent, int style) {
    super(parent, style);
    decorator = PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator();
    tdlp = new TableDecoratingLabelProvider(
            new ContactSelectorObservableMapLabelProvider(new ObservableMap[] {}), decorator);

    setLayout(new GridLayout(6, false));

    { // HEADER/*from w w w  . j  av  a2s .c om*/
        compositeHeader = new Composite(this, SWT.NONE);
        compositeHeader.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 6, 1));
        compositeHeader.setLayout(new GridLayout(3, false));

        lblContactType = new Label(compositeHeader, SWT.NONE);

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

        lblCode = new Label(compositeHeader, SWT.NONE);
        GridData gd_lblCode = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
        gd_lblCode.widthHint = 40;
        lblCode.setLayoutData(gd_lblCode);
    }

    { // TYPE_PERSON - Title prefix
        txtTitleFront = new Text(this, SWT.BORDER);
        gd_txtTitleFront = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
        gd_txtTitleFront.widthHint = 60;
        txtTitleFront.setLayoutData(gd_txtTitleFront);
        txtTitleFront.setMessage("Titel");
        ContentProposalAdapter cpaTitleFront = new ContentProposalAdapter(txtTitleFront,
                new TextContentAdapter(),
                new TitleProposalProvider(TitleProposalProvider.TITLE_POSITION_PREFIX), null, null);
        cpaTitleFront.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    }

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

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

    { // TYPE_PERSON - Title back
        txtTitleBack = new Text(this, SWT.BORDER);
        gd_txtTitleBack = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
        gd_txtTitleBack.widthHint = 60;
        txtTitleBack.setLayoutData(gd_txtTitleBack);
        txtTitleBack.setMessage("Titel");
        ContentProposalAdapter cpaTitleBack = new ContentProposalAdapter(txtTitleBack, new TextContentAdapter(),
                new TitleProposalProvider(TitleProposalProvider.TITLE_POSITION_SUFFIX), null, null);
        cpaTitleBack.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    }

    { // TYPE_PERSON - Sex
        comboViewerSex = new ComboViewer(this, SWT.NONE);
        gd_comboSex = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
        comboViewerSex.getCombo().setLayoutData(gd_comboSex);
        comboViewerSex.setContentProvider(ArrayContentProvider.getInstance());
        comboViewerSex.setLabelProvider(new LabelProvider() {
            @Override
            public String getText(Object element) {
                switch ((ContactGender) element) {
                case FEMALE:
                    return "W";
                case MALE:
                    return "M";
                case UNDEFINED:
                    return "X";
                default:
                    return "?";
                }
            }
        });
        comboViewerSex.setInput(ContactGender.values());
    }
    { // TYPE_PERSON - Birthday
        dateTimeDob = new DateTime(this, SWT.BORDER | SWT.LONG);
        gd_dateTimeDob = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
        dateTimeDob.setLayoutData(gd_dateTimeDob);
    }

    Group grpAddress = new Group(this, SWT.NONE);
    grpAddress.setLayout(new GridLayout(3, false));
    grpAddress.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 7, 1));
    grpAddress.setText("Adresse");
    {
        // TODO: Default selection according to current Mandant's country
        comboViewerCountry = new ComboViewer(grpAddress, SWT.NONE);
        GridData gd_combo_1 = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
        gd_combo_1.widthHint = 55;
        comboViewerCountry.getCombo().setLayoutData(gd_combo_1);
        comboViewerCountry.setContentProvider(ArrayContentProvider.getInstance());
        comboViewerCountry.setInput(Country.values());
        comboViewerCountry.addSelectionChangedListener(new ISelectionChangedListener() {
            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                Country selCountry = (Country) ((StructuredSelection) event.getSelection()).getFirstElement();
                if (selCountry == Country.NDF) {
                    comboViewerCountry.getCombo()
                            .setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
                    ContactGeonames.setCountry(null);
                } else {
                    comboViewerCountry.getCombo()
                            .setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
                    ContactGeonames.setCountry(selCountry);
                }

            }
        });
    }
    {
        txtCity = new Text(grpAddress, SWT.BORDER);
        txtCity.setMessage("Ortschaft");
        txtCity.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

        ContentProposalAdapter cpaCity = new ContentProposalAdapter(txtCity, new TextContentAdapter(), cityIP,
                null, null);
        cpaCity.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
        cpaCity.addContentProposalListener(new IContentProposalListener() {
            @Override
            public void proposalAccepted(IContentProposal proposal) {
                txtZIP.setText(cityIP.findZipForCityName(proposal.getContent()));
            }
        });
    }
    { // ZIP
        txtZIP = new Text(grpAddress, SWT.BORDER);
        txtZIP.setMessage("PLZ");
        txtZIP.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
        txtZIP.addModifyListener(new ModifyListener() {
            @Override
            public void modifyText(ModifyEvent e) {
                String currZip = ((Text) e.widget).getText();
                if (currZip == null || currZip.length() < 4)
                    return;
                streetIP.setZip(currZip);
            }
        });

        ContentProposalAdapter cpaZip = new ContentProposalAdapter(txtZIP, new TextContentAdapter(), zipIP,
                null, null);
        cpaZip.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
        cpaZip.addContentProposalListener(new IContentProposalListener() {
            @Override
            public void proposalAccepted(IContentProposal proposal) {
                txtCity.setText(zipIP.findCityNameForZip(proposal.getContent()));
            }
        });
    }

    Label lblImageCountry = new Label(grpAddress, SWT.NONE);
    GridData gd_lblImageCountry = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_lblImageCountry.widthHint = 55;
    lblImageCountry.setLayoutData(gd_lblImageCountry);

    {
        txtStreet = new Text(grpAddress, SWT.BORDER);
        txtStreet.setMessage("Strasse, Hausnummer");
        txtStreet.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

        ContentProposalAdapter cpaStreet = new ContentProposalAdapter(txtStreet, new TextContentAdapter(),
                streetIP, null, null);
        cpaStreet.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    }

    Group grpKontaktdaten = new Group(this, SWT.NONE);
    grpKontaktdaten.setText("Kontaktdaten");
    grpKontaktdaten.setLayout(new GridLayout(4, false));
    grpKontaktdaten.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 7, 1));

    Label lblImgPhone = new Label(grpKontaktdaten, SWT.NONE);
    lblImgPhone.setImage(Images.IMG_TELEPHONE.getImage());
    lblImgPhone.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    txtTelefon = new Text(grpKontaktdaten, SWT.BORDER);
    txtTelefon.setMessage("Telefon-Nummer");
    txtTelefon.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    txtTelefon.addFocusListener(preDialFocuListener);

    Label lblImgePhone2 = new Label(grpKontaktdaten, SWT.NONE);
    lblImgePhone2.setImage(Images.IMG_TELEPHONE.getImage());
    lblImgePhone2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    txtTelefon2 = new Text(grpKontaktdaten, SWT.BORDER);
    txtTelefon2.setMessage("Telefon-Nummer");
    txtTelefon2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    txtTelefon2.addFocusListener(preDialFocuListener);

    Label lblImgMobilePhone = new Label(grpKontaktdaten, SWT.NONE);
    lblImgMobilePhone.setImage(Images.IMG_MOBILEPHONE.getImage());
    lblImgMobilePhone.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    txtMobil = new Text(grpKontaktdaten, SWT.BORDER);
    txtMobil.setMessage("Handy-Nummer");
    txtMobil.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    txtMobil.addFocusListener(preDialFocuListener);

    Label lblImgFax = new Label(grpKontaktdaten, SWT.NONE);
    lblImgFax.setImage(Images.IMG_FAX.getImage());
    lblImgFax.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    txtFax = new Text(grpKontaktdaten, SWT.BORDER);
    txtFax.setMessage("Fax-Nummer");
    txtFax.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    txtFax.addFocusListener(preDialFocuListener);

    btnEmail = new Button(grpKontaktdaten, SWT.FLAT);
    btnEmail.setImage(Images.IMG_MAIL.getImage());
    btnEmail.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    btnEmail.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                URI uriMailTo = new URI("mailto", txtEmail.getText(), null);
                Desktop.getDesktop().mail(uriMailTo);
            } catch (URISyntaxException | IOException ex) {
                log.warn("Error opening URI", ex);
            }
        }
    });

    txtEmail = new Text(grpKontaktdaten, SWT.BORDER);
    txtEmail.setMessage("E-Mail Adresse");
    txtEmail.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    btnWebsite = new Button(grpKontaktdaten, SWT.FLAT);
    btnWebsite.setImage(Images.IMG_WEB.getImage());
    btnWebsite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    btnWebsite.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                URI uriURL = new URI(txtWebsite.getText());
                if (!uriURL.isAbsolute()) {
                    uriURL = new URI("http://" + txtWebsite.getText());
                }
                Desktop.getDesktop().browse(uriURL);
            } catch (URISyntaxException | IOException ex) {
                log.warn("Error opening URI", ex);
            }
        }
    });

    txtWebsite = new Text(grpKontaktdaten, SWT.BORDER);
    txtWebsite.setMessage("Webseite");
    txtWebsite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    { // Notes
        Group grpNotes = new Group(this, SWT.NONE);
        grpNotes.setLayout(new GridLayout(1, false));
        grpNotes.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 7, 1));
        grpNotes.setText("Notizen");
        txtNotes = new Text(grpNotes, SWT.V_SCROLL | SWT.WRAP);
        GridData gd_txtNotes = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
        gd_txtNotes.heightHint = (int) (5 * txtNotes.getFont().getFontData()[0].height);
        txtNotes.setLayoutData(gd_txtNotes);
    }

    initDataBindings();
}

From source file:com.android.traceview.ProblemView.java

License:Apache License

public ProblemView(Composite parent, TraceReader reader, ContextLogReader logReader,
        SelectionController selectController, Shell shell) {
    super(parent, SWT.NONE);
    parentShell = shell;/*from  w w  w.j  a  v  a  2 s. c o  m*/
    setLayout(new GridLayout(2, true));
    this.mSelectionController = selectController;

    mCombinedReader = new CombinedReader(reader, logReader);
    mReaders.add(mCombinedReader);

    Display display = getDisplay();

    mLogMap = logReader.getLogMap();

    mTraceRecords = reader.getThreadTimeRecords();

    // Add container holding the problem definition form
    Composite formComposite = new Composite(this, SWT.NONE);
    formComposite.setLayout(new FillLayout(SWT.VERTICAL));
    formComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Add a label for the problem definer
    Label problemLabel = new Label(formComposite, SWT.NONE);
    problemLabel.setText("Problem:");

    // Add radio button for BRB option
    BRBButton = new Button(formComposite, SWT.RADIO);
    BRBButton.setText("BigRedButton");

    // Add radio button for own problem definition option
    problemDefButton = new Button(formComposite, SWT.RADIO);
    problemDefButton.setText("Function call + constraint");

    Composite composite = new Composite(formComposite, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));
    // composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Add a text box for searching for method names
    Label callLabel = new Label(composite, SWT.NONE);
    callLabel.setText("Function:");

    // Add a text box for searching for method names
    mProblemBox = new Text(composite, SWT.BORDER);
    mProblemBox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    mProblemBox.setEnabled(false);

    mColorNoMatch = new Color(display, 255, 200, 200);
    mColorMatch = mProblemBox.getBackground();

    ContentProposalAdapter adapter = null;
    mScp = new SimpleContentProposalProvider(new String[0]);

    adapter = new ContentProposalAdapter(mProblemBox, new TextContentAdapter(), mScp, null, null);
    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

    final Composite constraintHolderComposite = new Composite(formComposite, SWT.NONE);
    constraintHolderComposite.setLayout(new FormLayout());

    // composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Composite mConstraintComposite = new Composite(constraintHolderComposite, SWT.NONE);
    RowLayout constraintLayout = new RowLayout();
    constraintLayout.pack = true;
    constraintLayout.type = SWT.HORIZONTAL;
    mConstraintComposite.setLayout(constraintLayout);

    Label constraintLabel = new Label(mConstraintComposite, SWT.NONE);
    constraintLabel.setText("Constraint:");

    logTypeCombo = new Combo(mConstraintComposite, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
    for (Entry<Integer, ContextLogData> ld : mLogMap.entrySet()) {
        logTypeCombo.add(ld.getValue().getName(), ld.getKey());
        //System.out.println(ld.getValue().getName() + " " + ld.getKey());
    }
    logTypeCombo.setEnabled(false);

    final FormData hide = new FormData();
    hide.top = new FormAttachment(0);
    hide.bottom = new FormAttachment(0);
    hide.left = new FormAttachment(0);
    hide.right = new FormAttachment(0);

    final FormData show = new FormData();
    show.top = new FormAttachment(0);
    show.bottom = new FormAttachment(100, -4);
    show.left = new FormAttachment(mConstraintComposite, 0, 4);
    show.right = new FormAttachment(100);

    // Composite holding controls for int type logs
    final Composite mIntComposite = new Composite(constraintHolderComposite, SWT.NONE);
    mIntComposite.setLayout(new FillLayout());

    intRelationCombo = new Combo(mIntComposite, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
    intRelationCombo.add("<");
    intRelationCombo.add("<=");
    intRelationCombo.add("=");
    intRelationCombo.add(">=");
    intRelationCombo.add(">");

    mIntValueBox = new Text(mIntComposite, SWT.BORDER);

    // Composite holding controls for float type logs
    final Composite mFloatComposite = new Composite(constraintHolderComposite, SWT.NONE);
    mFloatComposite.setLayout(new FillLayout());

    floatRelationCombo = new Combo(mFloatComposite, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
    floatRelationCombo.add("<");
    floatRelationCombo.add(">");

    mFloatValueBox = new Text(mFloatComposite, SWT.BORDER);

    // Composite holding controls for float type logs
    final Composite mStringComposite = new Composite(constraintHolderComposite, SWT.NONE);
    mStringComposite.setLayout(new FillLayout());

    stringRelationCombo = new Combo(mStringComposite, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
    stringRelationCombo.add("=");
    stringRelationCombo.add("<>");
    stringValueCombo = new Combo(mStringComposite, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);

    mIntComposite.setLayoutData(hide);
    mFloatComposite.setLayoutData(hide);
    mStringComposite.setLayoutData(hide);

    // Add result text field to the right side

    mResultBox = new Text(this, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    mResultBox.setLayoutData(new GridData(GridData.FILL_BOTH));
    mResultBox.setEditable(false);

    final Button addProblems = new Button(formComposite, SWT.PUSH);
    addProblems.setText("Add more input");
    addProblems.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            System.out.println("OK");
            FileDialog fd = new FileDialog(parentShell, SWT.OPEN);
            fd.setText("Open context log files");
            //            fd.setFilterPath("./");
            fd.setFilterExtensions(new String[] { "*.clog" });
            String selected = fd.open();
            if (selected != null) {
                addReaders(fd.getFilterPath(), fd.getFileNames());
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
            System.out.println("KO");
        }
    });

    openedReadersList = new org.eclipse.swt.widgets.List(this, SWT.SINGLE);
    openedReadersList.add("main");

    logTypeCombo.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            int index = logTypeCombo.getSelectionIndex();
            System.out.println(index);
            mSelectedLog1 = mLogMap.get(index);
            if (mSelectedLog1 == null) {
                mLogname = null;
                System.out.println("null");
                return;
            }
            mLogname = mSelectedLog1.getName();
            switch (mSelectedLog1.getType()) {
            case INT:
            case LONG:
                System.out.println("i");
                mIntComposite.setLayoutData(show);
                mFloatComposite.setLayoutData(hide);
                mStringComposite.setLayoutData(hide);
                mIntValueBox.setText("");
                break;
            case FLOAT:
            case DOUBLE:
                System.out.println("f");
                mIntComposite.setLayoutData(hide);
                mFloatComposite.setLayoutData(show);
                mStringComposite.setLayoutData(hide);
                mFloatValueBox.setText("");
                break;
            case STRING:
                System.out.println("s");
                stringValueCombo.removeAll();
                for (String s : mSelectedLog1.getStringDataMap().values()) {
                    stringValueCombo.add(s);
                }
                mIntComposite.setLayoutData(hide);
                mFloatComposite.setLayoutData(hide);
                mStringComposite.setLayoutData(show);
                break;
            }
            updateProblems();
            constraintHolderComposite.pack();
            updateStatistics();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {

        }
    });

    intRelationCombo.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {

        }

        @Override
        public void widgetSelected(SelectionEvent arg0) {

            try {
                String relationStr = intRelationCombo.getText();
                Relation rel = Relation.value(relationStr);
                mProblemConstraint = new ProblemConstraint(rel, LogType.LONG,
                        Long.valueOf(mIntValueBox.getText()));
                updateProblems();
                //               updateIntervals(rel, Long.valueOf(mIntValueBox.getText()));
                updateStatistics();
            } catch (NumberFormatException e) {
                // boo
                System.out.println("boo1");
                mProblemConstraint = null;
                updateProblems();
                //               mIntervals.clear();
                //               mSelectionController.changeIntervals(mIntervals, "ProblemView");
            } catch (IllegalArgumentException e) {
                // foo
                System.out.println("foo1");
                mProblemConstraint = null;
                updateProblems();
                //               mIntervals.clear();
                //               mSelectionController.changeIntervals(mIntervals,
                //                     "ProblemView");
            }
        }

    });

    mIntValueBox.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent arg0) {
            try {
                String relationStr = intRelationCombo.getText();
                Relation rel = Relation.value(relationStr);
                mProblemConstraint = new ProblemConstraint(rel, LogType.LONG,
                        Long.valueOf(mIntValueBox.getText()));
                updateProblems();
                //               updateIntervals(rel, Long.valueOf(mIntValueBox.getText()));
                updateStatistics();
            } catch (NumberFormatException e) {
                // boo
                System.out.println("boo2");
                mProblemConstraint = null;
                updateProblems();
                //               mIntervals.clear();
                //               mSelectionController.changeIntervals(mIntervals,
                //                     "ProblemView");
            } catch (IllegalArgumentException e) {
                // foo
                System.out.println("foo2");
                mProblemConstraint = null;
                updateProblems();
                //               mIntervals.clear();
                //               mSelectionController.changeIntervals(mIntervals,
                //                     "ProblemView");
            }
        }
    });

    floatRelationCombo.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void widgetSelected(SelectionEvent arg0) {

            try {
                String relationStr = floatRelationCombo.getText();
                Relation rel = Relation.value(relationStr);
                mProblemConstraint = new ProblemConstraint(rel, LogType.FLOAT,
                        Double.valueOf(mFloatValueBox.getText()));
                updateProblems();
                //               updateIntervals(rel,
                //                     Double.valueOf(mFloatValueBox.getText()));
                updateStatistics();
            } catch (NumberFormatException e) {
                // boo
                System.out.println("boo3");
                mProblemConstraint = null;
                updateProblems();
                //               mIntervals.clear();
                //               mSelectionController.changeIntervals(mIntervals,
                //                     "ProblemView");
            } catch (IllegalArgumentException e) {
                // foo
                System.out.println("foo3");
                mProblemConstraint = null;
                updateProblems();
                //               mIntervals.clear();
                //               mSelectionController.changeIntervals(mIntervals,
                //                     "ProblemView");
            }
        }

    });

    mFloatValueBox.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent arg0) {
            try {
                String relationStr = floatRelationCombo.getText();
                Relation rel = Relation.value(relationStr);
                mProblemConstraint = new ProblemConstraint(rel, LogType.FLOAT,
                        Double.valueOf(mFloatValueBox.getText()));
                updateProblems();
                //               updateIntervals(rel,
                //                     Double.valueOf(mFloatValueBox.getText()));
                updateStatistics();
            } catch (NumberFormatException e) {
                // boo
                System.out.println("boo4");
                mProblemConstraint = null;
                updateProblems();
                //               mIntervals.clear();
                //               mSelectionController.changeIntervals(mIntervals,
                //                     "ProblemView");
            } catch (IllegalArgumentException e) {
                // foo
                System.out.println("foo4");
                mProblemConstraint = null;
                updateProblems();
                //               mIntervals.clear();
                //               mSelectionController.changeIntervals(mIntervals,
                //                     "ProblemView");
            }
        }
    });

    stringRelationCombo.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void widgetSelected(SelectionEvent arg0) {

            try {
                String relationStr = stringRelationCombo.getText();
                Relation rel = Relation.value(relationStr);
                mProblemConstraint = new ProblemConstraint(rel, LogType.STRING, stringValueCombo.getText());
                updateProblems();
                //               updateIntervals(rel, stringValueCombo.getText());
                updateStatistics();
            } catch (NumberFormatException e) {
                // boo
                System.out.println("boo5");
                mProblemConstraint = null;
                updateProblems();
                //               mIntervals.clear();
                //               mSelectionController.changeIntervals(mIntervals,
                //                     "ProblemView");
            } catch (IllegalArgumentException e) {
                // foo
                System.out.println("foo5");
                mProblemConstraint = null;
                updateProblems();
                //               mIntervals.clear();
                //               mSelectionController.changeIntervals(mIntervals,
                //                     "ProblemView");
            }
        }
    });

    stringValueCombo.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void widgetSelected(SelectionEvent arg0) {

            try {
                String relationStr = stringRelationCombo.getText();
                Relation rel = Relation.value(relationStr);
                mProblemConstraint = new ProblemConstraint(rel, LogType.STRING, stringValueCombo.getText());
                updateProblems();
                //               updateIntervals(rel, stringValueCombo.getText());
                updateStatistics();
            } catch (NumberFormatException e) {
                // boo
                System.out.println("boo6");
                mProblemConstraint = null;
                updateProblems();
                //               mIntervals.clear();
                //               mSelectionController.changeIntervals(mIntervals,
                //                     "ProblemView");
            } catch (IllegalArgumentException e) {
                // foo
                System.out.println("foo6");
                mProblemConstraint = null;
                updateProblems();
                //               mIntervals.clear();
                //               mSelectionController.changeIntervals(mIntervals,
                //                     "ProblemView");
            }
        }
    });

    problemDefButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            if (problemDefButton.getSelection()) {
                mProblemConstraint = null;
                mFunctionName = null;

                mProblemBox.setEnabled(true);
                logTypeCombo.setEnabled(true);
                mIntValueBox.setEnabled(true);
                mFloatValueBox.setEnabled(true);
                stringValueCombo.setEnabled(true);
                intRelationCombo.setEnabled(true);
                floatRelationCombo.setEnabled(true);
                stringRelationCombo.setEnabled(true);

                mProblemBox.setText("");

                updateProblems();
                //               mIntervals.clear();
                //               updateTimeStamps(null);
                updateStatistics();
            }
        }
    });

    BRBButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            if (BRBButton.getSelection()) {
                mFunctionName = ProblemDefinition.BRB_FUNCTION_NAME;
                //               mProblemBox.setText("");
                mProblemBox.setEnabled(false);
                logTypeCombo.setEnabled(false);
                mIntValueBox.setEnabled(false);
                mFloatValueBox.setEnabled(false);
                stringValueCombo.setEnabled(false);
                intRelationCombo.setEnabled(false);
                floatRelationCombo.setEnabled(false);
                stringRelationCombo.setEnabled(false);

                mProblemConstraint = null;

                //               mIntervals.clear();
                //               mSelectionController.changeIntervals(mIntervals,
                //                     "ProblemView");
                //               updateTimeStamps(BRBMethodData);
                updateProblems();
                updateStatistics();
            }
        }
    });

    mProblemBox.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent ev) {
            String query = mProblemBox.getText();
            if (query.length() < 4) {
                mScp.setProposals(new String[0]);
                mProblemBox.setBackground(mColorMatch);

                //TODO: make empty problem
                mFunctionName = null;
                updateProblems();

                //               updateTimeStamps(null);
                return;
            }
            MethodData[] matchingMD = mCombinedReader.findAllMethodDataByName(query);

            if (matchingMD.length == 0) {
                mProblemBox.setBackground(mColorNoMatch);
            } else {
                mProblemBox.setBackground(mColorMatch);
            }
            List<String> proposals = new ArrayList<String>();

            for (MethodData md : matchingMD) {
                StringBuilder proposal = new StringBuilder(md.getName());

                proposals.add(proposal.toString());
            }
            // TODO: get matching call names
            mScp.setProposals(proposals.toArray(new String[0]));

            if (matchingMD.length == 1) {
                mFunctionName = matchingMD[0].getName();
                updateProblems();
                //               updateTimeStamps(matchingMD[0]);
                updateStatistics();
            }
        }
    });

}

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 . j  a v  a 2s .  c o  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;/*www  .  j av  a  2s .com*/
                        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;
}