diff options
| author | Benjamin Grouhan | 2015-04-03 16:20:38 +0000 |
|---|---|---|
| committer | Pierre-Charles David | 2015-04-09 12:27:40 +0000 |
| commit | df4adcc82a9fdca8eb13e1b4b19011455454430c (patch) | |
| tree | 32791006f9263a1ecfd4820dc6e72c2a26959667 | |
| parent | 675d9ba0452582adef2e559079379d962b63664c (diff) | |
| download | org.eclipse.sirius-df4adcc82a9fdca8eb13e1b4b19011455454430c.tar.gz org.eclipse.sirius-df4adcc82a9fdca8eb13e1b4b19011455454430c.tar.xz org.eclipse.sirius-df4adcc82a9fdca8eb13e1b4b19011455454430c.zip | |
[463456] Add a dialog for a text area with content proposal.
Also add the method bindPluginsCompletionProcessors in
TypeContentProposalProvider (works similarly as bindCompletionProcessor,
but with the completion processors available in plugins).
Change-Id: If74ea6abd63d1b2da1b865836af287ccc50f8073
Signed-off-by: Benjamin Grouhan <benjamin.grouhan@obeo.fr>
4 files changed, 151 insertions, 0 deletions
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html index a831280b96..a541b2a592 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html @@ -290,6 +290,15 @@ <code>org.eclipse.sirius.ecore.extender.IllegalURIException</code> has been removed. It was not actually thrown anywhere in the code. </li> </ul> + <h4 id="Changesinorg.eclipse.sirius.editor">Changes in + <code>org.eclipse.sirius.editor</code> + </h4> + <ul> + <li>The static method + <code>org.eclipse.sirius.editor.tools.api.assist.TypeContentProposalProvider.bindPluginsCompletionProcessors(AbstractPropertySection, Text)</code> has been added. This method is very similar to + <code>org.eclipse.sirius.editor.tools.api.assist.TypeContentProposalProvider.bindCompletionProcessor(AbstractPropertySection, Text)</code>, the difference is that it binds the completion processors available in plugins to the text. + </li> + </ul> <h4 id="Changesinorg.eclipse.sirius.table">Changes in <code>org.eclipse.sirius.table</code> </h4> diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile index 46665476fe..f272253e18 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile @@ -83,6 +83,10 @@ h4. Changes in @org.eclipse.sirius.ecore.extender@ * The method @org.eclipse.sirius.ecore.extender.business.api.accessor.CompositeMetamodelExtender.eRemoveInverseCrossReferences()@ has been changed to return the list of changed objects by the inverse cross references removal. * The exception @org.eclipse.sirius.ecore.extender.IllegalURIException@ has been removed. It was not actually thrown anywhere in the code. +h4. Changes in @org.eclipse.sirius.editor@ + +* The static method @org.eclipse.sirius.editor.tools.api.assist.TypeContentProposalProvider.bindPluginsCompletionProcessors(AbstractPropertySection, Text)@ has been added. This method is very similar to @org.eclipse.sirius.editor.tools.api.assist.TypeContentProposalProvider.bindCompletionProcessor(AbstractPropertySection, Text)@, the difference is that it binds the completion processors available in plugins to the text. + h4. Changes in @org.eclipse.sirius.table@ * The methods @org.eclipse.sirius.table.business.api.helper.TableHelper.getColumn()@ have been removed because they are not useful, @TableHelper.getColumn(DLine, int)@ can be replaced by @DTable.getColumns().get(int)@ and @TableHelper.getColumn(DTable, String)@ should not be used as we can have several columns with a same featureName. diff --git a/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/api/assist/TypeContentProposalProvider.java b/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/api/assist/TypeContentProposalProvider.java index 5853660f7b..430908974a 100644 --- a/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/api/assist/TypeContentProposalProvider.java +++ b/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/api/assist/TypeContentProposalProvider.java @@ -21,10 +21,13 @@ import org.eclipse.jface.fieldassist.IContentProposal; import org.eclipse.jface.fieldassist.IContentProposalListener2; import org.eclipse.jface.fieldassist.IContentProposalProvider; import org.eclipse.jface.fieldassist.TextContentAdapter; +import org.eclipse.sirius.common.tools.api.util.EclipseUtil; import org.eclipse.sirius.editor.editorPlugin.SiriusEditorPlugin; import org.eclipse.sirius.editor.properties.sections.common.ModelViewBinding; import org.eclipse.sirius.editor.tools.internal.assist.TypeAssistant; import org.eclipse.sirius.editor.tools.internal.assist.TypeContentProposal; +import org.eclipse.sirius.ui.tools.api.assist.IAssistContentProvider; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.keys.IBindingService; @@ -104,6 +107,42 @@ public class TypeContentProposalProvider implements IContentProposalProvider { } } + /** + * Bind the completion processors available in plugins to a given text + * element. + * + * @param section + * the property section where the text element come from. + * @param text + * text to bind a completion processors to. + */ + public static void bindPluginsCompletionProcessors(final AbstractPropertySection section, final Text text) { + List<IAssistContentProvider> extension = EclipseUtil.getExtensionPlugins(IAssistContentProvider.class, IAssistContentProvider.ID, IAssistContentProvider.CLASS_ATTRIBUTE); + if (!(extension.size() == 0)) { + IAssistContentProvider contentProposalAdapter = extension.get(0); + contentProposalAdapter.setView(section); + IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); // gives + // the + // user + // content + // assist + // binding + TriggerSequence[] activeBindinds = bindingService.getActiveBindingsFor(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + if (activeBindinds != null && activeBindinds.length > 0) { + TriggerSequence sequence = activeBindinds[0]; + KeyStroke keyStroke = getKeyStroke(sequence); + + TextContentAdapter textContentAdapter = new TextContentAdapter(); + ContentProposalAdapter adapter = new ContentProposalAdapter(text, textContentAdapter, contentProposalAdapter, keyStroke, IAssistContentProvider.AUTO_ACTIVATION_CHARACTERS); + adapter.setPopupSize(new Point(300, 100)); // set content + // proposal popup + // size + adapter.addContentProposalListener(contentProposalAdapter); // close + // popup + } + } + } + private static KeyStroke getKeyStroke(TriggerSequence sequence) { for (Trigger trigger : sequence.getTriggers()) { if (trigger instanceof KeyStroke) { diff --git a/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/internal/presentation/TextWithContentProposalDialog.java b/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/internal/presentation/TextWithContentProposalDialog.java new file mode 100644 index 0000000000..7f09dff087 --- /dev/null +++ b/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/internal/presentation/TextWithContentProposalDialog.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.editor.tools.internal.presentation; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.sirius.editor.editorPlugin.SiriusEditor; +import org.eclipse.sirius.editor.tools.api.assist.TypeContentProposalProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; + +/** + * A dialog containing a text field with content proposal from plugins. + * + * @author bgrouhan + * + */ +public class TextWithContentProposalDialog extends Dialog { + + /** + * The text that will be returned. + */ + private String resultText; + + /** + * The background color of the text area. + */ + private AbstractPropertySection section; + + /** + * The text area of the dialog. + */ + private Text textArea; + + /** + * Constructor without background color for the text area. + * + * @param parentShell + * the parent shell. + * @param propertySection + * the property section where this dialog is created. + * @param initialText + * the initial text. + */ + public TextWithContentProposalDialog(Shell parentShell, AbstractPropertySection propertySection, String initialText) { + super(parentShell); + resultText = initialText; + section = propertySection; + } + + /** + * Method to get the resulting text. + * + * @return the text in the Text control if the "Ok" button was pressed, the + * previous text otherwise. + */ + public String getResult() { + return resultText; + } + + @Override + protected Control createDialogArea(Composite parent) { + final Composite contents = (Composite) super.createDialogArea(parent); + textArea = new Text(contents, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP); + final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.heightHint = 200; + data.widthHint = 600; + textArea.setLayoutData(data); + textArea.setBackground(SiriusEditor.getColorRegistry().get("yellow")); + TypeContentProposalProvider.bindPluginsCompletionProcessors(section, textArea); + textArea.setText(resultText); + return contents; + } + + @Override + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText("Type your expression"); + } + + @Override + protected void okPressed() { + resultText = textArea.getText().replaceAll("\n", "").replaceAll("\t", ""); + super.okPressed(); + } +} |
