List of usage examples for org.eclipse.jface.fieldassist IContentProposal getContent
public String getContent();
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//ww w . j av a 2s . 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.amalto.workbench.proposal.ContentProposalAdapterExtended.java
License:Open Source License
private void proposalAccepted(IContentProposal proposal) { // In all cases, notify listeners of an accepted proposal. final Object[] listenerArray = proposalListeners.getListeners(); for (int i = 0; i < listenerArray.length; i++) { if (listenerArray[i] instanceof IContentProposalExtendedListener) { ((IContentProposalExtendedListener) listenerArray[i]).proposalBeforeModifyControl(proposal); }// w w w .j a va 2 s. c o m } if (controlContentAdapter instanceof IControlContentAdapterExtended) { ((IControlContentAdapterExtended) controlContentAdapter).setUsedFilterValue(filterText); } switch (proposalAcceptanceStyle) { case (PROPOSAL_REPLACE): setControlContent(proposal.getContent(), proposal.getCursorPosition()); break; case (PROPOSAL_INSERT): insertControlContent(proposal.getContent(), proposal.getCursorPosition()); break; default: // do nothing. Typically a listener is installed to handle this in // a custom way. break; } // In all cases, notify listeners of an accepted proposal. for (int i = 0; i < listenerArray.length; i++) { ((IContentProposalListener) listenerArray[i]).proposalAccepted(proposal); } }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.properties.ValueCompleterTest.java
License:Open Source License
private void checkCompletion(String text, int offset, String property, EnumSet<Format> formats, String[] values, List<String> expected) { assertTrue(text.length() >= offset); TestAttributeInfo info = new TestAttributeInfo(property, formats, "unittest", values, values, null); TestValueCompleter completer = new TestValueCompleter(new TestTextAttributeDescriptor(property, info)); IContentProposal[] proposals = completer.getProposals(text, offset); List<String> actual = new ArrayList<String>(); for (IContentProposal proposal : proposals) { String content = proposal.getContent(); actual.add(content);//from w w w .jav a2 s . c o m } assertEquals(expected.toString(), actual.toString()); }
From source file:com.siteview.mde.internal.ui.editor.contentassist.TypeContentProposalProvider.java
License:Open Source License
private ArrayList filterContentProposals(String currentContent) { String lowerCaseCurrentContent = currentContent.toLowerCase(); ListIterator iterator = fInitialContentProposals.listIterator(); // Maintain a list of filtered search results ArrayList filteredContentProposals = new ArrayList(); // Iterate over the initial search results while (iterator.hasNext()) { Object object = iterator.next(); IContentProposal proposal = (IContentProposal) object; String compareString = null; if (lowerCaseCurrentContent.indexOf(F_DOT) == -1) { // Use only the type name compareString = proposal.getLabel().toLowerCase(); } else {/*from w w w .j ava 2 s . c om*/ // Use the fully qualified type name compareString = proposal.getContent().toLowerCase(); } // Filter out any proposal not matching the current contents // except for the edge case where the proposal is identical to the // current contents if (compareString.startsWith(lowerCaseCurrentContent, 0)) { filteredContentProposals.add(proposal); } } return filteredContentProposals; }
From source file:com.vectrace.MercurialEclipse.dialogs.RevisionChooserPanel.java
License:Open Source License
/** * Adds field assistance to the revision text field. *///from ww w . ja va 2 s . c o m private void setupRevisionFieldAssistance() { contentAssist = new ContentAssistCommandAdapter(text, new TextContentAdapter(), new RevisionContentProposalProvider(dataLoader), null, null, true); contentAssist.setAutoActivationDelay(300); contentAssist.setPopupSize(new Point(320, 240)); contentAssist.setPropagateKeys(true); contentAssist.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); contentAssist.addContentProposalListener(new IContentProposalListener() { public void proposalAccepted(IContentProposal proposal) { tag = null; branch = null; bookmark = null; String changeSetId = proposal.getContent().split(" ", 2)[0]; //$NON-NLS-1$ try { data.changeSet = LocalChangesetCache.getInstance().get(dataLoader.getHgRoot(), changeSetId); } catch (HgException e) { data.changeSet = null; String message = Messages.getString("RevisionChooserDialog.error.loadChangeset1", changeSetId); //$NON-NLS-1$ logError(message, e); } } }); }
From source file:com.vectrace.MercurialEclipse.history.MercurialHistoryPage.java
License:Open Source License
/** * Adds field assistance to the revision text field. *//* w w w. j a va 2 s .c o m*/ private void setupRevisionFieldAssistance() { proposalProvider = new HistoryContentProposalProvider(this); ContentAssistCommandAdapter contentAssist = new ContentAssistCommandAdapter(gotoText, new TextContentAdapter(), proposalProvider, null, null, true); // uncomment to open popup immediately on typing first character into the text field // contentAssist.setAutoActivationCharacters(null); contentAssist.setAutoActivationDelay(300); contentAssist.setPropagateKeys(true); contentAssist.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); contentAssist.addContentProposalListener(new IContentProposalListener2() { public void proposalPopupOpened(ContentProposalAdapter adapter) { fetchEntireHistory(true); } public void proposalPopupClosed(ContentProposalAdapter adapter) { fetchEntireHistory(false); } }); contentAssist.addContentProposalListener(new IContentProposalListener() { public void proposalAccepted(IContentProposal proposal) { if (proposal instanceof RevisionContentProposal) { selectProposal(proposal); } else { // try to find something guessAndSelectVersion(proposal.getContent()); } } }); }
From source file:custom.jface.widgets.ContentProposalAdapterPlus.java
License:Open Source License
private void proposalAccepted(IContentProposal proposal) { switch (proposalAcceptanceStyle) { case (PROPOSAL_REPLACE): setControlContent(proposal.getContent(), proposal.getCursorPosition()); break;/*from w w w .j av a 2s .c o m*/ case (PROPOSAL_INSERT): insertControlContent(proposal.getContent(), proposal.getCursorPosition()); break; default: // do nothing. Typically a listener is installed to handle this in // a custom way. break; } // In all cases, notify listeners of an accepted proposal. notifyProposalAccepted(proposal); }
From source file:net.sf.wickedshell.ui.shell.viewer.text.TextShellViewer.java
License:Open Source License
/** * Initializes the field assist which provides command completion. *///from w ww . ja va 2 s . co m private void initFieldAssist() { KeyStroke keyStroke = KeyStroke.getInstance(SWT.CTRL, ' '); adapter = new ContentProposalAdapter(shellDisplayControl, new TextContentAdapter(), new ShellContentProposalProvider(this), keyStroke, new char[] { SWT.TAB }); adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_IGNORE); adapter.addContentProposalListener(new IContentProposalListener() { /** * @see org.eclipse.jface.fieldassist.IContentProposalListener#proposalAccepted(org.eclipse.jface.fieldassist.IContentProposal) */ public void proposalAccepted(IContentProposal proposal) { setCurrentCommand(proposal.getContent()); } }); adapter.setLabelProvider(new LabelProvider() { /** * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) */ public String getText(Object element) { Completion completion = (Completion) element; return completion.getLabel(); } /** * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) */ public Image getImage(Object element) { Completion completion = (Completion) element; if (completion.getImagePath() != null && completion.getImagePath().length() > 1) { return ResourceManager.getPluginImage(ShellPlugin.getDefault(), completion.getImagePath()); } return ResourceManager.getPluginImage(ShellPlugin.getDefault(), "img/staticCompletion.gif"); } }); }
From source file:net.sourceforge.eclipseccase.autocomplete.ccviewer.AutoCompleteComboViewer.java
License:Open Source License
public AutoCompleteComboViewer(ComboViewer aCombo) { this.combo = aCombo.getCombo(); if (combo != null) { this.combo.addFocusListener(new ProposalUpdateFocusListener()); provider = getContentProposalProvider(combo.getItems()); adapter = new ContentProposalAdapter(combo, new ComboContentAdapter(), provider, getActivationKeystroke(), getAutoactivationChars()); adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); //This is called when using autocomplete. adapter.addContentProposalListener(new IContentProposalListener() { public void proposalAccepted(IContentProposal proposal) { MergeWizardPage.setSelectedBranch(proposal.getContent()); }/*from www . j a va 2s . c om*/ }); } }
From source file:org.apache.felix.sigil.eclipse.ui.util.ExclusionContentProposalProvider.java
License:Apache License
public IContentProposal[] getProposals(String contents, int position) { String matchString = contents.substring(0, position); Pattern pattern = GlobCompiler.compile(matchString); // Get a snapshot of the elements T[] elementArray;//from w ww. ja va 2 s. c o m synchronized (elements) { @SuppressWarnings("unchecked") T[] temp = (T[]) elements.toArray(); elementArray = temp; } List<IContentProposal> result = new ArrayList<IContentProposal>(); for (T element : elementArray) { if (filter == null || filter.select(element)) { IContentProposal proposal = WrappedContentProposal.newInstance(element, descriptor); Matcher matcher = pattern.matcher(proposal.getContent()); if (matcher.find()) { result.add(proposal); } } } return result.toArray(new IContentProposal[result.size()]); }